33#ifndef FL_TEXT_BUFFER_H
34#define FL_TEXT_BUFFER_H
41# define IS_UTF8_ALIGNED(a) if (a && *a) assert(fl_utf8len(*(a))>0);
42# define IS_UTF8_ALIGNED2(a, b) if (b>=0 && b<a->length()) assert(fl_utf8len(a->byte_at(b))>0);
44# define IS_UTF8_ALIGNED(a)
45# define IS_UTF8_ALIGNED2(a, b)
69#define FL_TEXT_MAX_EXP_CHAR_LEN 20
81 friend class Fl_Text_Buffer;
99 void update(
int pos,
int nDeleted,
int nInserted);
130 int includes(
int pos)
const;
138 int position(
int* start,
int* end)
const;
148typedef void (*Fl_Text_Modify_Cb)(
int pos,
int nInserted,
int nDeleted,
149 int nRestyled,
const char* deletedText,
153typedef void (*Fl_Text_Predelete_Cb)(
int pos,
int nDeleted,
void* cbArg);
179 Fl_Text_Buffer(
int requestedSize = 0,
int preferredGapSize = 1024);
204 void text(
const char* text);
216 char* text_range(
int start,
int end)
const;
224 unsigned int char_at(
int pos)
const;
232 char byte_at(
int pos)
const;
255 void insert(
int pos,
const char* text);
268 void remove(
int start,
int end);
276 void replace(
int start,
int end,
const char *text);
285 void copy(
Fl_Text_Buffer* fromBuf,
int fromStart,
int fromEnd,
int toPos);
296 void canUndo(
char flag=1);
309 int insertfile(
const char *file,
int pos,
int buflen = 128*1024);
320 int loadfile(
const char *file,
int buflen = 128*1024)
329 int outputfile(
const char *file,
int start,
int end,
int buflen = 128*1024);
334 int savefile(
const char *file,
int buflen = 128*1024)
346 void tab_distance(
int tabDist);
351 void select(
int start,
int end);
366 int selection_position(
int* start,
int* end);
372 char* selection_text();
377 void remove_selection();
382 void replace_selection(
const char* text);
387 void secondary_select(
int start,
int end);
398 void secondary_unselect();
403 int secondary_selection_position(
int* start,
int* end);
409 char* secondary_selection_text();
414 void remove_secondary_selection();
420 void replace_secondary_selection(
const char* text);
425 void highlight(
int start,
int end);
441 int highlight_position(
int* start,
int* end);
447 char* highlight_text();
459 void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
464 void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
476 void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB,
void* cbArg);
482 void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB,
void* cbArg);
497 char* line_text(
int pos)
const;
504 int line_start(
int pos)
const;
513 int line_end(
int pos)
const;
520 int word_start(
int pos)
const;
527 int word_end(
int pos)
const;
535 int count_displayed_characters(
int lineStartPos,
int targetPos)
const;
545 int skip_displayed_characters(
int lineStartPos,
int nChars);
551 int count_lines(
int startPos,
int endPos)
const;
557 int skip_lines(
int startPos,
int nLines);
564 int rewind_lines(
int startPos,
int nLines);
579 int findchar_forward(
int startPos,
unsigned searchChar,
int* foundPos)
const;
593 int findchar_backward(
int startPos,
unsigned int searchChar,
int* foundPos)
const;
605 int search_forward(
int startPos,
const char* searchString,
int* foundPos,
606 int matchCase = 0)
const;
618 int search_backward(
int startPos,
const char* searchString,
int* foundPos,
619 int matchCase = 0)
const;
645 int prev_char(
int ix)
const;
646 int prev_char_clipped(
int ix)
const;
652 int next_char(
int ix)
const;
653 int next_char_clipped(
int ix)
const;
658 int utf8_align(
int)
const;
688 int nRestyled,
const char* deletedText)
const;
711 void remove_(
int start,
int end);
This class manages unicode displayed in one or more Fl_Text_Display widgets.
Definition Fl_Text_Buffer.H:168
void replace_selection_(Fl_Text_Selection *sel, const char *text)
Replaces the text in selection sel.
Definition Fl_Text_Buffer.cxx:1289
Fl_Text_Selection mSecondary
highlighted areas
Definition Fl_Text_Buffer.H:749
void append(const char *t)
Appends the text string to the end of the buffer.
Definition Fl_Text_Buffer.H:261
void ** mCbArgs
caller arguments for modifyProcs above
Definition Fl_Text_Buffer.H:763
int savefile(const char *file, int buflen=128 *1024)
Saves a text file from the current buffer.
Definition Fl_Text_Buffer.H:334
char * text() const
Get a copy of the entire contents of the text buffer.
Definition Fl_Text_Buffer.cxx:162
char * mBuf
allocated memory where the text is stored
Definition Fl_Text_Buffer.H:754
int insertfile(const char *file, int pos, int buflen=128 *1024)
Inserts a file at the specified position.
Definition Fl_Text_Buffer.cxx:1658
void remove_(int start, int end)
Internal (non-redisplaying) version of BufRemove.
Definition Fl_Text_Buffer.cxx:1167
void insert(int pos, const char *text)
Inserts null-terminated string text at position pos.
Definition Fl_Text_Buffer.cxx:274
int length() const
Returns the number of bytes in the buffer.
Definition Fl_Text_Buffer.H:190
const Fl_Text_Selection * primary_selection() const
Returns the primary selection.
Definition Fl_Text_Buffer.H:624
int secondary_selected()
Returns a non 0 value if text has been selected in the secondary text selection, 0 otherwise.
Definition Fl_Text_Buffer.H:393
const Fl_Text_Selection * secondary_selection() const
Returns the secondary selection.
Definition Fl_Text_Buffer.H:634
void select(int start, int end)
Selects a range of characters in the buffer.
Definition Fl_Text_Buffer.cxx:490
int selected() const
Returns a non 0 value if text has been selected, 0 otherwise.
Definition Fl_Text_Buffer.H:356
int input_file_was_transcoded
true iff the loaded file has been transcoded to UTF-8
Definition Fl_Text_Buffer.H:663
void remove_selection()
Removes the text in the primary selection.
Definition Fl_Text_Buffer.cxx:535
const char * address(int pos) const
Convert a byte offset in buffer into a memory address.
Definition Fl_Text_Buffer.H:239
static const char * file_encoding_warning_message
This message may be displayed using the fl_alert() function when a file which was not UTF-8 encoded i...
Definition Fl_Text_Buffer.H:668
void move_gap(int pos)
Move the gap to start at a new position.
Definition Fl_Text_Buffer.cxx:1393
int mNModifyProcs
number of modify-redisplay procs attached
Definition Fl_Text_Buffer.H:760
const Fl_Text_Selection * highlight_selection() const
Returns the current highlight selection.
Definition Fl_Text_Buffer.H:639
Fl_Text_Buffer(int requestedSize=0, int preferredGapSize=1024)
Create an empty text buffer of a pre-determined size.
Definition Fl_Text_Buffer.cxx:114
int insert_(int pos, const char *text)
Internal (non-redisplaying) version of BufInsert.
Definition Fl_Text_Buffer.cxx:1124
int mGapStart
points to the first character of the gap
Definition Fl_Text_Buffer.H:755
int mCursorPosHint
hint for reasonable cursor position after a buffer modification operation
Definition Fl_Text_Buffer.H:768
int appendfile(const char *file, int buflen=128 *1024)
Appends the named file to the end of the buffer.
Definition Fl_Text_Buffer.H:314
void call_predelete_callbacks()
Calls the stored pre-delete callback procedure(s) for this buffer to update the changed area(s) on th...
Definition Fl_Text_Buffer.H:488
void call_modify_callbacks()
Calls all modify callbacks that have been registered using the add_modify_callback() method.
Definition Fl_Text_Buffer.H:471
Fl_Text_Selection mHighlight
highlighted areas
Definition Fl_Text_Buffer.H:750
int highlight()
Returns the highlighted text.
Definition Fl_Text_Buffer.H:431
void redisplay_selection(Fl_Text_Selection *oldSelection, Fl_Text_Selection *newSelection) const
Calls the stored redisplay procedure(s) for this buffer to update the screen for a change in a select...
Definition Fl_Text_Buffer.cxx:1337
int mGapEnd
points to the first char after the gap
Definition Fl_Text_Buffer.H:756
int outputfile(const char *file, int start, int end, int buflen=128 *1024)
Writes the specified portions of the file to a file.
Definition Fl_Text_Buffer.cxx:1699
Fl_Text_Predelete_Cb * mPredeleteProcs
procedure to call before text is deleted from the buffer; at most one is supported.
Definition Fl_Text_Buffer.H:765
void ** mPredeleteCbArgs
caller argument for pre-delete proc above
Definition Fl_Text_Buffer.H:767
char * address(int pos)
Convert a byte offset in buffer into a memory address.
Definition Fl_Text_Buffer.H:247
Fl_Text_Selection mPrimary
highlighted areas
Definition Fl_Text_Buffer.H:748
Fl_Text_Selection * primary_selection()
Returns the primary selection.
Definition Fl_Text_Buffer.H:629
int mNPredeleteProcs
number of pre-delete procs attached
Definition Fl_Text_Buffer.H:764
int mPreferredGapSize
the default allocation for the text gap is 1024 bytes and should only be increased if frequent and la...
Definition Fl_Text_Buffer.H:772
Fl_Text_Modify_Cb * mModifyProcs
procedures to call when buffer is modified to redisplay contents
Definition Fl_Text_Buffer.H:761
void(* transcoding_warning_action)(Fl_Text_Buffer *)
Pointer to a function called after reading a non UTF-8 encoded file.
Definition Fl_Text_Buffer.H:679
char mCanUndo
if this buffer is used for attributes, it must not do any undo calls
Definition Fl_Text_Buffer.H:770
void remove_selection_(Fl_Text_Selection *sel)
Removes the text from the buffer corresponding to sel.
Definition Fl_Text_Buffer.cxx:1274
int loadfile(const char *file, int buflen=128 *1024)
Loads a text file into the buffer.
Definition Fl_Text_Buffer.H:320
int mTabDist
equiv.
Definition Fl_Text_Buffer.H:759
void update_selections(int pos, int nDeleted, int nInserted)
Updates all of the selections in the buffer for changes in the buffer's text.
Definition Fl_Text_Buffer.cxx:1439
int tab_distance() const
Gets the tab width.
Definition Fl_Text_Buffer.H:340
void reallocate_with_gap(int newGapStart, int newGapLen)
Reallocates the text storage in the buffer to have a gap starting at newGapStart and a gap size of ne...
Definition Fl_Text_Buffer.cxx:1410
int mLength
length of the text in the buffer (the length of the buffer itself must be calculated: gapEnd - gapSta...
Definition Fl_Text_Buffer.H:751
This is an internal class for Fl_Text_Buffer to manage text selections.
Definition Fl_Text_Buffer.H:80
int end() const
Return the byte ofsset to the character after the last selected character.
Definition Fl_Text_Buffer.H:111
bool selected() const
Returns true if any text is selected.
Definition Fl_Text_Buffer.H:118
void selected(bool b)
Modify the 'selected' flag.
Definition Fl_Text_Buffer.H:124
bool mSelected
this flag is set if any text is selected
Definition Fl_Text_Buffer.H:144
void set(int start, int end)
Set the selection range.
Definition Fl_Text_Buffer.cxx:1219
int mEnd
byte offset to the character after the last selected character
Definition Fl_Text_Buffer.H:143
int start() const
Return the byte offset to the first selected character.
Definition Fl_Text_Buffer.H:105
void update(int pos, int nDeleted, int nInserted)
Updates a selection afer text was modified.
Definition Fl_Text_Buffer.cxx:1449
int mStart
byte offset to the first selected character
Definition Fl_Text_Buffer.H:142