00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _FL_TEXT_BUFFER_H_
00023 #define _FL_TEXT_BUFFER_H_
00024
00025
00026
00027 #define FL_TEXT_MAX_EXP_CHAR_LEN 20
00028
00029 #include <efltk/Fl_Export.h>
00030 #include <efltk/Fl_Ptr_Stack.h>
00031 #include <efltk/Fl_Buffer.h>
00032
00033 typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
00034 int nRestyled, const char* deletedText,
00035 void* cbArg);
00036 typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
00037
00039 class FL_API Fl_Text_Selection {
00040 friend class Fl_Text_Buffer;
00041
00042 public:
00043 void set(int start, int end);
00044 void set_rectangular(int start, int end, int rectStart, int rectEnd);
00045 void update(int pos, int nDeleted, int nInserted);
00046 char rectangular() { return mRectangular; }
00047 int start() { return mStart; }
00048 int end() { return mEnd; }
00049 int rect_start() { return mRectStart; }
00050 int rect_end() { return mRectEnd; }
00051 char selected() { return mSelected; }
00052 void selected(char b) { mSelected = b; }
00053 int includes(int pos, int lineStartPos, int dispIndex);
00054 int position(int* start, int* end);
00055 int position(int* start, int* end, int* isRect, int* rectStart, int* rectEnd);
00056
00057
00058 protected:
00059 char mSelected;
00060 char mRectangular;
00061 int mStart;
00062 int mEnd;
00063 int mRectStart;
00064 int mRectEnd;
00065 };
00066
00067 typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
00068 int nRestyled, const char* deletedText,
00069 void* cbArg);
00070 typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
00071
00072
00073 class Fl_UndoNode_Stack;
00074
00076 class FL_API Fl_Text_Buffer {
00077 public:
00078 Fl_Text_Buffer(int requestedSize = 0);
00079 ~Fl_Text_Buffer();
00080
00081 char *Fl_Text_Buffer::static_buffer();
00082
00083
00084 int undo_size();
00085 void undo_size(int newsize);
00086
00087
00088 int undo();
00089 void add_undo(const char *str, int pos, int len, bool inserted, bool replaced);
00090
00091 int length() { return mLength; }
00092 const char* text();
00093 void text(const char* text);
00094 const char* text_range(int start, int end);
00095 void text_range(Fl_String_Buffer& outStr, int start, int end);
00096 char character(int pos);
00097 const char* text_in_rectangle(int start, int end, int rectStart, int rectEnd);
00098
00099 void insert(int pos, const char* text, int text_len=-1);
00100 void append(const char* text, int text_len=-1) { insert(length(), text, text_len); }
00101 void remove(int start, int end);
00102 void replace(int start, int end, const char *text, int text_len=-1);
00103 void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
00104 int insertfile(const char *file, int pos, int buflen = 128*1024);
00105 int appendfile(const char *file, int buflen = 128*1024)
00106 { return insertfile(file, length(), buflen); }
00107 int loadfile(const char *file, int buflen = 128*1024)
00108 { select(0, length()); remove_selection(); return appendfile(file, buflen); }
00109 int outputfile(const char *file, int start, int end, int buflen = 128*1024);
00110 int savefile(const char *file, int buflen = 128*1024)
00111 { return outputfile(file, 0, length(), buflen); }
00112
00113 void insert_column(int column, int startPos, const char* text,
00114 int* charsInserted, int* charsDeleted);
00115
00116 void replace_rectangular(int start, int end, int rectStart, int rectEnd,
00117 const char* text);
00118
00119 void overlay_rectangular(int startPos, int rectStart, int rectEnd,
00120 const char* text, int* charsInserted,
00121 int* charsDeleted);
00122
00123 void remove_rectangular(int start, int end, int rectStart, int rectEnd);
00124 void clear_rectangular(int start, int end, int rectStart, int rectEnd);
00125 int tab_distance() { return mTabDist; }
00126 void tab_distance(int tabDist);
00127 void select(int start, int end);
00128 int selected() { return mPrimary.selected(); }
00129 void unselect();
00130 void select_rectangular(int start, int end, int rectStart, int rectEnd);
00131 int selection_position(int* start, int* end);
00132
00133 int selection_position(int* start, int* end, int* isRect, int* rectStart,
00134 int* rectEnd);
00135
00136 const char* selection_text();
00137 void remove_selection();
00138 void replace_selection(const char* text);
00139 void secondary_select(int start, int end);
00140 void secondary_unselect();
00141
00142 void secondary_select_rectangular(int start, int end, int rectStart,
00143 int rectEnd);
00144
00145 int secondary_selection_position(int* start, int* end, int* isRect,
00146 int* rectStart, int* rectEnd);
00147
00148 const char* secondary_selection_text();
00149 void remove_secondary_selection();
00150 void replace_secondary_selection(const char* text);
00151 void highlight(int start, int end);
00152 void unhighlight();
00153 void highlight_rectangular(int start, int end, int rectStart, int rectEnd);
00154
00155 int highlight_position(int* start, int* end, int* isRect, int* rectStart,
00156 int* rectEnd);
00157
00158 const char* highlight_text();
00159
00160 void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
00161 void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
00162 void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); }
00163
00164 void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB, void* cbArg);
00165 void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg);
00166 void call_predelete_callbacks() { call_predelete_callbacks(0, 0); }
00167
00168 const char* line_text(int pos);
00169 int line_start(int pos);
00170 int line_end(int pos);
00171 int word_start(int pos);
00172 int word_end(int pos);
00173 int expand_character(int pos, int indent, char *outStr);
00174
00175 static int expand_character(char c, int indent, char* outStr, int tabDist);
00176
00177 static int character_width(char c, int indent, int tabDist);
00178 int count_displayed_characters(int lineStartPos, int targetPos);
00179 int skip_displayed_characters(int lineStartPos, int nChars);
00180 int count_lines(int startPos, int endPos);
00181 int skip_lines(int startPos, int nLines);
00182 int rewind_lines(int startPos, int nLines);
00183 int findchar_forward(int startPos, char searchChar, int* foundPos);
00184 int findchar_backward(int startPos, char searchChar, int* foundPos);
00185 int findchars_forward(int startPos, const char* searchChars, int* foundPos);
00186 int findchars_backward(int startPos, const char* searchChars, int* foundPos);
00187
00188 int search_forward(int startPos, const char* searchString, int* foundPos,
00189 int matchCase = 0);
00190
00191 int search_backward(int startPos, const char* searchString, int* foundPos,
00192 int matchCase = 0);
00193
00194 Fl_Text_Selection* primary_selection() { return &mPrimary; }
00195 Fl_Text_Selection* secondary_selection() { return &mSecondary; }
00196 Fl_Text_Selection* highlight_selection() { return &mHighlight; }
00197
00198 protected:
00199 void call_modify_callbacks(int pos, int nDeleted, int nInserted,
00200 int nRestyled, const char* deletedText);
00201
00202 void call_predelete_callbacks(int pos, int nDeleted);
00203
00204 int insert_(int pos, const char* text, int text_len);
00205 void remove_(int start, int end);
00206
00207 void remove_rectangular_(int start, int end, int rectStart, int rectEnd,
00208 int* replaceLen, int* endPos);
00209
00210 void insert_column_( int column, int startPos, const char* insText,
00211 int* nDeleted, int* nInserted, int* endPos);
00212
00213 void overlay_rectangular_(int startPos, int rectStart, int rectEnd,
00214 const char* insText, int* nDeleted,
00215 int* nInserted, int* endPos);
00216
00217 void redisplay_selection(Fl_Text_Selection* oldSelection,
00218 Fl_Text_Selection* newSelection);
00219
00220 void move_gap(int pos);
00221 void reallocate_with_gap(int newGapStart, int newGapLen);
00222 const char* selection_text_(Fl_Text_Selection* sel);
00223 void remove_selection_(Fl_Text_Selection* sel);
00224 void replace_selection_(Fl_Text_Selection* sel, const char* text);
00225
00226 void rectangular_selection_boundaries(int lineStartPos, int rectStart,
00227 int rectEnd, int* selStart,
00228 int* selEnd);
00229
00230 void update_selections(int pos, int nDeleted, int nInserted);
00231
00232 Fl_UndoNode_Stack *undo_stack;
00233
00234 Fl_Text_Selection mPrimary;
00235 Fl_Text_Selection mSecondary;
00236 Fl_Text_Selection mHighlight;
00237 int mLength;
00238
00239
00240 char* mBuf;
00241 int mGapStart;
00242 int mGapEnd;
00243
00244
00245 int mTabDist;
00246 int mUseTabs;
00247
00248 int mNModifyProcs;
00249 Fl_Text_Modify_Cb*
00250 mNodifyProcs;
00251 void** mCbArgs;
00252
00253 int mNPredeleteProcs;
00254 Fl_Text_Predelete_Cb*
00255 mPredeleteProcs;
00256 void **mPredeleteCbArgs;
00257
00258 int mCursorPosHint;
00259
00260 };
00261
00262 #endif