00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef FL_TEXT_BUFFER_H
00034 #define FL_TEXT_BUFFER_H
00035
00036
00037 #undef ASSERT_UTF8
00038
00039 #ifdef ASSERT_UTF8
00040 # include <assert.h>
00041 # define IS_UTF8_ALIGNED(a) if (a && *a) assert(fl_utf8len(*(a))>0);
00042 # define IS_UTF8_ALIGNED2(a, b) if (b>=0 && b<a->length()) assert(fl_utf8len(a->byte_at(b))>0);
00043 #else
00044 # define IS_UTF8_ALIGNED(a)
00045 # define IS_UTF8_ALIGNED2(a, b)
00046 #endif
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #define FL_TEXT_MAX_EXP_CHAR_LEN 20
00070
00071 #include "Fl_Export.H"
00072
00073
00080 class FL_EXPORT Fl_Text_Selection {
00081 friend class Fl_Text_Buffer;
00082
00083 public:
00084
00090 void set(int start, int end);
00091
00099 void update(int pos, int nDeleted, int nInserted);
00100
00105 int start() const { return mStart; }
00106
00111 int end() const { return mEnd; }
00112
00118 bool selected() const { return mSelected; }
00119
00124 void selected(bool b) { mSelected = b; }
00125
00130 int includes(int pos) const;
00131
00138 int position(int* start, int* end) const;
00139
00140 protected:
00141
00142 int mStart;
00143 int mEnd;
00144 bool mSelected;
00145 };
00146
00147
00148 typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
00149 int nRestyled, const char* deletedText,
00150 void* cbArg);
00151
00152
00153 typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
00154
00155
00168 class FL_EXPORT Fl_Text_Buffer {
00169 public:
00170
00179 Fl_Text_Buffer(int requestedSize = 0, int preferredGapSize = 1024);
00180
00184 ~Fl_Text_Buffer();
00185
00190 int length() const { return mLength; }
00191
00198 char* text() const;
00199
00204 void text(const char* text);
00205
00216 char* text_range(int start, int end) const;
00217
00224 unsigned int char_at(int pos) const;
00225
00232 char byte_at(int pos) const;
00233
00239 const char *address(int pos) const
00240 { return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
00241
00247 char *address(int pos)
00248 { return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
00249
00255 void insert(int pos, const char* text);
00256
00261 void append(const char* t) { insert(length(), t); }
00262
00268 void remove(int start, int end);
00269
00276 void replace(int start, int end, const char *text);
00277
00285 void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
00286
00291 int undo(int *cp=0);
00292
00296 void canUndo(char flag=1);
00297
00309 int insertfile(const char *file, int pos, int buflen = 128*1024);
00310
00314 int appendfile(const char *file, int buflen = 128*1024)
00315 { return insertfile(file, length(), buflen); }
00316
00320 int loadfile(const char *file, int buflen = 128*1024)
00321 { select(0, length()); remove_selection(); return appendfile(file, buflen); }
00322
00329 int outputfile(const char *file, int start, int end, int buflen = 128*1024);
00330
00334 int savefile(const char *file, int buflen = 128*1024)
00335 { return outputfile(file, 0, length(), buflen); }
00336
00340 int tab_distance() const { return mTabDist; }
00341
00346 void tab_distance(int tabDist);
00347
00351 void select(int start, int end);
00352
00356 int selected() const { return mPrimary.selected(); }
00357
00361 void unselect();
00362
00366 int selection_position(int* start, int* end);
00367
00372 char* selection_text();
00373
00377 void remove_selection();
00378
00382 void replace_selection(const char* text);
00383
00387 void secondary_select(int start, int end);
00388
00393 int secondary_selected() { return mSecondary.selected(); }
00394
00398 void secondary_unselect();
00399
00403 int secondary_selection_position(int* start, int* end);
00404
00409 char* secondary_selection_text();
00410
00414 void remove_secondary_selection();
00415
00420 void replace_secondary_selection(const char* text);
00421
00425 void highlight(int start, int end);
00426
00431 int highlight() { return mHighlight.selected(); }
00432
00436 void unhighlight();
00437
00441 int highlight_position(int* start, int* end);
00442
00447 char* highlight_text();
00448
00459 void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
00460
00464 void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
00465
00471 void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); }
00472
00476 void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB, void* cbArg);
00477
00482 void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg);
00483
00488 void call_predelete_callbacks() { call_predelete_callbacks(0, 0); }
00489
00497 char* line_text(int pos) const;
00498
00504 int line_start(int pos) const;
00505
00513 int line_end(int pos) const;
00514
00520 int word_start(int pos) const;
00521
00527 int word_end(int pos) const;
00528
00535 int count_displayed_characters(int lineStartPos, int targetPos) const;
00536
00545 int skip_displayed_characters(int lineStartPos, int nChars);
00546
00551 int count_lines(int startPos, int endPos) const;
00552
00557 int skip_lines(int startPos, int nLines);
00558
00564 int rewind_lines(int startPos, int nLines);
00565
00579 int findchar_forward(int startPos, unsigned searchChar, int* foundPos) const;
00580
00593 int findchar_backward(int startPos, unsigned int searchChar, int* foundPos) const;
00594
00605 int search_forward(int startPos, const char* searchString, int* foundPos,
00606 int matchCase = 0) const;
00607
00618 int search_backward(int startPos, const char* searchString, int* foundPos,
00619 int matchCase = 0) const;
00620
00624 const Fl_Text_Selection* primary_selection() const { return &mPrimary; }
00625
00629 Fl_Text_Selection* primary_selection() { return &mPrimary; }
00630
00634 const Fl_Text_Selection* secondary_selection() const { return &mSecondary; }
00635
00639 const Fl_Text_Selection* highlight_selection() const { return &mHighlight; }
00640
00645 int prev_char(int ix) const;
00646 int prev_char_clipped(int ix) const;
00647
00652 char *prev_char(char *c) const;
00653 const char *prev_char(const char *c) const;
00654
00659 int next_char(int ix) const;
00660 int next_char_clipped(int ix) const;
00661
00666 char *next_char(char *c) const;
00667 const char *next_char(const char *c) const;
00668
00672 int utf8_align(int) const;
00673
00677 int input_file_was_transcoded;
00678
00682 static const char* file_encoding_warning_message;
00683
00693 void (*transcoding_warning_action)(Fl_Text_Buffer*);
00694
00695 protected:
00696
00701 void call_modify_callbacks(int pos, int nDeleted, int nInserted,
00702 int nRestyled, const char* deletedText) const;
00703
00708 void call_predelete_callbacks(int pos, int nDeleted) const;
00709
00718 int insert_(int pos, const char* text);
00719
00725 void remove_(int start, int end);
00726
00731 void redisplay_selection(Fl_Text_Selection* oldSelection,
00732 Fl_Text_Selection* newSelection) const;
00733
00737 void move_gap(int pos);
00738
00743 void reallocate_with_gap(int newGapStart, int newGapLen);
00744
00745 char* selection_text_(Fl_Text_Selection* sel) const;
00746
00750 void remove_selection_(Fl_Text_Selection* sel);
00751
00755 void replace_selection_(Fl_Text_Selection* sel, const char* text);
00756
00760 void update_selections(int pos, int nDeleted, int nInserted);
00761
00762 Fl_Text_Selection mPrimary;
00763 Fl_Text_Selection mSecondary;
00764 Fl_Text_Selection mHighlight;
00765 int mLength;
00768 char* mBuf;
00769 int mGapStart;
00770 int mGapEnd;
00771
00772
00773 int mTabDist;
00774 int mNModifyProcs;
00775 Fl_Text_Modify_Cb *mModifyProcs;
00777 void** mCbArgs;
00778 int mNPredeleteProcs;
00779 Fl_Text_Predelete_Cb *mPredeleteProcs;
00781 void **mPredeleteCbArgs;
00782 int mCursorPosHint;
00784 char mCanUndo;
00786 int mPreferredGapSize;
00789 };
00790
00791 #endif
00792
00793
00794
00795