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;
228 const char *address(
int pos)
const
229 {
return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
236 char *address(
int pos)
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);
303 int appendfile(
const char *file,
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);
750 Fl_Text_Modify_Cb *mModifyProcs;
754 Fl_Text_Predelete_Cb *mPredeleteProcs;
761 int mPreferredGapSize;