22#ifndef FL_TEXT_BUFFER_H
23#define FL_TEXT_BUFFER_H
30# define IS_UTF8_ALIGNED(a) if (a && *a) assert(fl_utf8len(*(a))>0);
31# define IS_UTF8_ALIGNED2(a, b) if (b>=0 && b<a->length()) assert(fl_utf8len(a->byte_at(b))>0);
33# define IS_UTF8_ALIGNED(a)
34# define IS_UTF8_ALIGNED2(a, b)
58#define FL_TEXT_MAX_EXP_CHAR_LEN 20
70 friend class Fl_Text_Buffer;
89 void update(
int pos,
int nDeleted,
int nInserted);
120 int includes(
int pos)
const;
128 int position(
int* start,
int* end)
const;
138typedef void (*Fl_Text_Modify_Cb)(
int pos,
int nInserted,
int nDeleted,
139 int nRestyled,
const char* deletedText,
143typedef void (*Fl_Text_Predelete_Cb)(
int pos,
int nDeleted,
void* cbArg);
169 Fl_Text_Buffer(
int requestedSize = 0,
int preferredGapSize = 1024);
194 void text(
const char* text);
206 char* text_range(
int start,
int end)
const;
214 unsigned int char_at(
int pos)
const;
222 char byte_at(
int pos)
const;
245 void insert(
int pos,
const char* text);
258 void remove(
int start,
int end);
267 void replace(
int start,
int end,
const char *text);
276 void copy(
Fl_Text_Buffer* fromBuf,
int fromStart,
int fromEnd,
int toPos);
287 void canUndo(
char flag=1);
304 int insertfile(
const char *file,
int pos,
int buflen = 128*1024);
315 int loadfile(
const char *file,
int buflen = 128*1024)
328 int outputfile(
const char *file,
int start,
int end,
int buflen = 128*1024);
340 int savefile(
const char *file,
int buflen = 128*1024)
355 void tab_distance(
int tabDist);
360 void select(
int start,
int end);
375 int selection_position(
int* start,
int* end);
382 char* selection_text();
387 void remove_selection();
392 void replace_selection(
const char* text);
397 void secondary_select(
int start,
int end);
408 void secondary_unselect();
413 int secondary_selection_position(
int* start,
int* end);
420 char* secondary_selection_text();
426 void remove_secondary_selection();
432 void replace_secondary_selection(
const char* text);
437 void highlight(
int start,
int end);
454 int highlight_position(
int* start,
int* end);
461 char* highlight_text();
474 void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
479 void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
490 void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB,
void* cbArg);
496 void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB,
void* cbArg);
512 char* line_text(
int pos)
const;
519 int line_start(
int pos)
const;
528 int line_end(
int pos)
const;
535 int word_start(
int pos)
const;
542 int word_end(
int pos)
const;
551 int count_displayed_characters(
int lineStartPos,
int targetPos)
const;
562 int skip_displayed_characters(
int lineStartPos,
int nChars);
568 int count_lines(
int startPos,
int endPos)
const;
574 int skip_lines(
int startPos,
int nLines);
582 int rewind_lines(
int startPos,
int nLines);
598 int findchar_forward(
int startPos,
unsigned searchChar,
int* foundPos)
const;
613 int findchar_backward(
int startPos,
unsigned int searchChar,
int* foundPos)
const;
626 int search_forward(
int startPos,
const char* searchString,
int* foundPos,
627 int matchCase = 0)
const;
640 int search_backward(
int startPos,
const char* searchString,
int* foundPos,
641 int matchCase = 0)
const;
667 int prev_char(
int ix)
const;
668 int prev_char_clipped(
int ix)
const;
674 int next_char(
int ix)
const;
675 int next_char_clipped(
int ix)
const;
680 int utf8_align(
int)
const;
710 int nRestyled,
const char* deletedText)
const;
735 void remove_(
int start,
int end);
This class manages Unicode text displayed in one or more Fl_Text_Display widgets.
Definition Fl_Text_Buffer.H:158
void replace_selection_(Fl_Text_Selection *sel, const char *text)
Replaces the text in selection sel.
Definition Fl_Text_Buffer.cxx:1281
Fl_Text_Selection mSecondary
highlighted areas
Definition Fl_Text_Buffer.H:773
void append(const char *t)
Appends the text string to the end of the buffer.
Definition Fl_Text_Buffer.H:251
void ** mCbArgs
caller arguments for modifyProcs above
Definition Fl_Text_Buffer.H:787
int savefile(const char *file, int buflen=128 *1024)
Saves a text file from the current buffer.
Definition Fl_Text_Buffer.H:340
char * text() const
Get a copy of the entire contents of the text buffer.
Definition Fl_Text_Buffer.cxx:153
char * mBuf
allocated memory where the text is stored
Definition Fl_Text_Buffer.H:778
int insertfile(const char *file, int pos, int buflen=128 *1024)
Inserts a file at the specified position.
Definition Fl_Text_Buffer.cxx:1670
void remove_(int start, int end)
Internal (non-redisplaying) version of remove().
Definition Fl_Text_Buffer.cxx:1159
void insert(int pos, const char *text)
Inserts null-terminated string text at position pos.
Definition Fl_Text_Buffer.cxx:269
int length() const
Returns the number of bytes in the buffer.
Definition Fl_Text_Buffer.H:180
const Fl_Text_Selection * primary_selection() const
Returns the primary selection.
Definition Fl_Text_Buffer.H:646
int secondary_selected()
Returns a non-zero value if text has been selected in the secondary text selection,...
Definition Fl_Text_Buffer.H:403
const Fl_Text_Selection * secondary_selection() const
Returns the secondary selection.
Definition Fl_Text_Buffer.H:656
void select(int start, int end)
Selects a range of characters in the buffer.
Definition Fl_Text_Buffer.cxx:485
int selected() const
Returns a non-zero value if text has been selected, 0 otherwise.
Definition Fl_Text_Buffer.H:365
int input_file_was_transcoded
true if the loaded file has been transcoded to UTF-8.
Definition Fl_Text_Buffer.H:685
void remove_selection()
Removes the text in the primary selection.
Definition Fl_Text_Buffer.cxx:530
const char * address(int pos) const
Convert a byte offset in buffer into a memory address.
Definition Fl_Text_Buffer.H:229
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:690
void move_gap(int pos)
Move the gap to start at a new position.
Definition Fl_Text_Buffer.cxx:1385
int mNModifyProcs
number of modify-redisplay procs attached
Definition Fl_Text_Buffer.H:784
const Fl_Text_Selection * highlight_selection() const
Returns the current highlight selection.
Definition Fl_Text_Buffer.H:661
Fl_Text_Buffer(int requestedSize=0, int preferredGapSize=1024)
Create an empty text buffer of a pre-determined size.
Definition Fl_Text_Buffer.cxx:105
int insert_(int pos, const char *text)
Internal (non-redisplaying) version of insert().
Definition Fl_Text_Buffer.cxx:1116
int mGapStart
points to the first character of the gap
Definition Fl_Text_Buffer.H:779
int mCursorPosHint
hint for reasonable cursor position after a buffer modification operation
Definition Fl_Text_Buffer.H:792
int appendfile(const char *file, int buflen=128 *1024)
Appends the named file to the end of the buffer.
Definition Fl_Text_Buffer.H:309
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:502
void call_modify_callbacks()
Calls all modify callbacks that have been registered using the add_modify_callback() method.
Definition Fl_Text_Buffer.H:485
Fl_Text_Selection mHighlight
highlighted areas
Definition Fl_Text_Buffer.H:774
int highlight()
Returns the highlighted text.
Definition Fl_Text_Buffer.H:444
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:1329
int mGapEnd
points to the first character after the gap
Definition Fl_Text_Buffer.H:780
int outputfile(const char *file, int start, int end, int buflen=128 *1024)
Writes the specified portions of the text buffer to a file.
Definition Fl_Text_Buffer.cxx:1711
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:789
void ** mPredeleteCbArgs
caller argument for pre-delete proc above
Definition Fl_Text_Buffer.H:791
char * address(int pos)
Convert a byte offset in buffer into a memory address.
Definition Fl_Text_Buffer.H:237
Fl_Text_Selection mPrimary
highlighted areas
Definition Fl_Text_Buffer.H:772
Fl_Text_Selection * primary_selection()
Returns the primary selection.
Definition Fl_Text_Buffer.H:651
int mNPredeleteProcs
number of pre-delete procs attached
Definition Fl_Text_Buffer.H:788
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:796
Fl_Text_Modify_Cb * mModifyProcs
procedures to call when buffer is modified to redisplay contents
Definition Fl_Text_Buffer.H:785
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:701
char mCanUndo
if this buffer is used for attributes, it must not do any undo calls
Definition Fl_Text_Buffer.H:794
void remove_selection_(Fl_Text_Selection *sel)
Removes the text from the buffer corresponding to sel.
Definition Fl_Text_Buffer.cxx:1266
int loadfile(const char *file, int buflen=128 *1024)
Loads a text file into the buffer.
Definition Fl_Text_Buffer.H:315
int mTabDist
equiv.
Definition Fl_Text_Buffer.H:783
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:1431
int tab_distance() const
Gets the tab width.
Definition Fl_Text_Buffer.H:349
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:1402
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:775
This is an internal class for Fl_Text_Buffer to manage text selections.
Definition Fl_Text_Buffer.H:69
int end() const
Return the byte offset to the character after the last selected character.
Definition Fl_Text_Buffer.H:101
bool selected() const
Returns true if any text is selected.
Definition Fl_Text_Buffer.H:108
void selected(bool b)
Modify the 'selected' flag.
Definition Fl_Text_Buffer.H:114
bool mSelected
this flag is set if any text is selected
Definition Fl_Text_Buffer.H:134
void set(int start, int end)
Set the selection range.
Definition Fl_Text_Buffer.cxx:1211
int mEnd
byte offset to the character after the last selected character
Definition Fl_Text_Buffer.H:133
int start() const
Return the byte offset to the first selected character.
Definition Fl_Text_Buffer.H:95
void update(int pos, int nDeleted, int nInserted)
Updates a selection after text was modified.
Definition Fl_Text_Buffer.cxx:1441
int mStart
byte offset to the first selected character
Definition Fl_Text_Buffer.H:132