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
60 #include "Fl_Export.H"
79 void set(
int start,
int end);
88 void update(
int pos,
int nDeleted,
int nInserted);
94 int start()
const {
return mStart; }
100 int end()
const {
return mEnd; }
119 int includes(
int pos)
const;
127 int position(
int* start,
int* end)
const;
137 typedef void (*Fl_Text_Modify_Cb)(
int pos,
int nInserted,
int nDeleted,
138 int nRestyled,
const char* deletedText,
142 typedef void (*Fl_Text_Predelete_Cb)(
int pos,
int nDeleted,
void* cbArg);
168 Fl_Text_Buffer(
int requestedSize = 0,
int preferredGapSize = 1024);
193 void text(
const char* text);
205 char* text_range(
int start,
int end)
const;
213 unsigned int char_at(
int pos)
const;
221 char byte_at(
int pos)
const;
229 {
return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
237 {
return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
244 void insert(
int pos,
const char* text);
250 void append(
const char* t) { insert(length(), t); }
257 void remove(
int start,
int end);
265 void replace(
int start,
int end,
const char *text);
274 void copy(
Fl_Text_Buffer* fromBuf,
int fromStart,
int fromEnd,
int toPos);
285 void canUndo(
char flag=1);
298 int insertfile(
const char *file,
int pos,
int buflen = 128*1024);
304 {
return insertfile(file, length(), buflen); }
309 int loadfile(
const char *file,
int buflen = 128*1024)
310 { select(0, length()); remove_selection();
return appendfile(file, buflen); }
318 int outputfile(
const char *file,
int start,
int end,
int buflen = 128*1024);
323 int savefile(
const char *file,
int buflen = 128*1024)
324 {
return outputfile(file, 0, length(), buflen); }
335 void tab_distance(
int tabDist);
340 void select(
int start,
int end);
345 int selected()
const {
return mPrimary.selected(); }
355 int selection_position(
int* start,
int* end);
361 char* selection_text();
366 void remove_selection();
371 void replace_selection(
const char* text);
376 void secondary_select(
int start,
int end);
387 void secondary_unselect();
392 int secondary_selection_position(
int* start,
int* end);
398 char* secondary_selection_text();
403 void remove_secondary_selection();
409 void replace_secondary_selection(
const char* text);
414 void highlight(
int start,
int end);
430 int highlight_position(
int* start,
int* end);
436 char* highlight_text();
448 void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
453 void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
void* cbArg);
465 void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB,
void* cbArg);
471 void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB,
void* cbArg);
486 char* line_text(
int pos)
const;
493 int line_start(
int pos)
const;
502 int line_end(
int pos)
const;
509 int word_start(
int pos)
const;
516 int word_end(
int pos)
const;
524 int count_displayed_characters(
int lineStartPos,
int targetPos)
const;
534 int skip_displayed_characters(
int lineStartPos,
int nChars);
540 int count_lines(
int startPos,
int endPos)
const;
546 int skip_lines(
int startPos,
int nLines);
553 int rewind_lines(
int startPos,
int nLines);
568 int findchar_forward(
int startPos,
unsigned searchChar,
int* foundPos)
const;
582 int findchar_backward(
int startPos,
unsigned int searchChar,
int* foundPos)
const;
594 int search_forward(
int startPos,
const char* searchString,
int* foundPos,
595 int matchCase = 0)
const;
607 int search_backward(
int startPos,
const char* searchString,
int* foundPos,
608 int matchCase = 0)
const;
634 int prev_char(
int ix)
const;
635 int prev_char_clipped(
int ix)
const;
641 int next_char(
int ix)
const;
642 int next_char_clipped(
int ix)
const;
647 int utf8_align(
int)
const;
676 void call_modify_callbacks(
int pos,
int nDeleted,
int nInserted,
677 int nRestyled,
const char* deletedText)
const;
683 void call_predelete_callbacks(
int pos,
int nDeleted)
const;
693 int insert_(
int pos,
const char* text);
700 void remove_(
int start,
int end);
712 void move_gap(
int pos);
718 void reallocate_with_gap(
int newGapStart,
int newGapLen);
735 void update_selections(
int pos,
int nDeleted,
int nInserted);
int mNModifyProcs
number of modify-redisplay procs attached
Definition: Fl_Text_Buffer.H:749
Fl_Text_Modify_Cb * mModifyProcs
procedures to call when buffer is modified to redisplay contents
Definition: Fl_Text_Buffer.H:750
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:657
Fl_Text_Selection mPrimary
highlighted areas
Definition: Fl_Text_Buffer.H:737
Fl_Text_Selection mSecondary
highlighted areas
Definition: Fl_Text_Buffer.H:738
const Fl_Text_Selection * highlight_selection() const
Returns the current highlight selection.
Definition: Fl_Text_Buffer.H:628
int length() const
Returns the number of bytes in the buffer.
Definition: Fl_Text_Buffer.H:179
void selected(bool b)
Modify the 'selected' flag.
Definition: Fl_Text_Buffer.H:113
int mCursorPosHint
hint for reasonable cursor position after a buffer modification operation
Definition: Fl_Text_Buffer.H:757
This class manages unicode displayed in one or more Fl_Text_Display widgets.
Definition: Fl_Text_Buffer.H:157
int end() const
Return the byte ofsset to the character after the last selected character.
Definition: Fl_Text_Buffer.H:100
int mStart
byte offset to the first selected character
Definition: Fl_Text_Buffer.H:131
bool mSelected
this flag is set if any text is selected
Definition: Fl_Text_Buffer.H:133
void append(const char *t)
Appends the text string to the end of the buffer.
Definition: Fl_Text_Buffer.H:250
int appendfile(const char *file, int buflen=128 *1024)
Appends the named file to the end of the buffer.
Definition: Fl_Text_Buffer.H:303
const char * address(int pos) const
Convert a byte offset in buffer into a memory address.
Definition: Fl_Text_Buffer.H:228
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:740
int mGapStart
points to the first character of the gap
Definition: Fl_Text_Buffer.H:744
int mTabDist
equiv.
Definition: Fl_Text_Buffer.H:748
Fl_Text_Selection * primary_selection()
Returns the primary selection.
Definition: Fl_Text_Buffer.H:618
This is an internal class for Fl_Text_Buffer to manage text selections.
Definition: Fl_Text_Buffer.H:69
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:761
char * address(int pos)
Convert a byte offset in buffer into a memory address.
Definition: Fl_Text_Buffer.H:236
int start() const
Return the byte offset to the first selected character.
Definition: Fl_Text_Buffer.H:94
int highlight()
Returns the highlighted text.
Definition: Fl_Text_Buffer.H:420
int savefile(const char *file, int buflen=128 *1024)
Saves a text file from the current buffer.
Definition: Fl_Text_Buffer.H:323
void call_modify_callbacks()
Calls all modify callbacks that have been registered using the add_modify_callback() method...
Definition: Fl_Text_Buffer.H:460
char mCanUndo
if this buffer is used for attributes, it must not do any undo calls
Definition: Fl_Text_Buffer.H:759
void ** mCbArgs
caller arguments for modifyProcs above
Definition: Fl_Text_Buffer.H:752
const Fl_Text_Selection * primary_selection() const
Returns the primary selection.
Definition: Fl_Text_Buffer.H:613
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:754
const Fl_Text_Selection * secondary_selection() const
Returns the secondary selection.
Definition: Fl_Text_Buffer.H:623
Fl_Text_Selection mHighlight
highlighted areas
Definition: Fl_Text_Buffer.H:739
int mNPredeleteProcs
number of pre-delete procs attached
Definition: Fl_Text_Buffer.H:753
int loadfile(const char *file, int buflen=128 *1024)
Loads a text file into the buffer.
Definition: Fl_Text_Buffer.H:309
bool selected() const
Returns true if any text is selected.
Definition: Fl_Text_Buffer.H:107
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:382
char * mBuf
allocated memory where the text is stored
Definition: Fl_Text_Buffer.H:743
int input_file_was_transcoded
true iff the loaded file has been transcoded to UTF-8
Definition: Fl_Text_Buffer.H:652
int selected() const
Returns a non 0 value if text has been selected, 0 otherwise.
Definition: Fl_Text_Buffer.H:345
void ** mPredeleteCbArgs
caller argument for pre-delete proc above
Definition: Fl_Text_Buffer.H:756
int mGapEnd
points to the first char after the gap
Definition: Fl_Text_Buffer.H:745
int tab_distance() const
Gets the tab width.
Definition: Fl_Text_Buffer.H:329
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:477
int mEnd
byte offset to the character after the last selected character
Definition: Fl_Text_Buffer.H:132