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);
89 void update(
int pos,
int nDeleted,
int nInserted);
95 int start()
const {
return mStart; }
101 int end()
const {
return mEnd; }
120 int includes(
int pos)
const;
128 int position(
int* start,
int* end)
const;
138 typedef void (*Fl_Text_Modify_Cb)(
int pos,
int nInserted,
int nDeleted,
139 int nRestyled,
const char* deletedText,
143 typedef 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;
229 const char *address(
int pos)
const
230 {
return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
237 char *address(
int pos)
238 {
return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
245 void insert(
int pos,
const char* text);
251 void append(
const char* t) { insert(length(), t); }
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);
309 int appendfile(
const char *file,
int buflen = 128*1024)
310 {
return insertfile(file, length(), buflen); }
315 int loadfile(
const char *file,
int buflen = 128*1024)
316 { select(0, length()); remove_selection();
return appendfile(file, buflen); }
328 int outputfile(
const char *file,
int start,
int end,
int buflen = 128*1024);
340 int savefile(
const char *file,
int buflen = 128*1024)
341 {
return outputfile(file, 0, length(), buflen); }
355 void tab_distance(
int tabDist);
360 void select(
int start,
int end);
365 int selected()
const {
return mPrimary.selected(); }
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;
709 void call_modify_callbacks(
int pos,
int nDeleted,
int nInserted,
710 int nRestyled,
const char* deletedText)
const;
716 void call_predelete_callbacks(
int pos,
int nDeleted)
const;
727 int insert_(
int pos,
const char* text);
735 void remove_(
int start,
int end);
747 void move_gap(
int pos);
753 void reallocate_with_gap(
int newGapStart,
int newGapLen);
770 void update_selections(
int pos,
int nDeleted,
int nInserted);
785 Fl_Text_Modify_Cb *mModifyProcs;
789 Fl_Text_Predelete_Cb *mPredeleteProcs;
796 int mPreferredGapSize;