Move the sources to trunk
[opencv] / otherlibs / _fltk / include / FL / Fl_Text_Buffer.H
1 //
2 // "$Id: Fl_Text_Buffer.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $"
3 //
4 // Header file for Fl_Text_Buffer class.
5 //
6 // Copyright 2001-2002 by Bill Spitzak and others.
7 // Original code Copyright Mark Edel.  Permission to distribute under
8 // the LGPL for the FLTK library granted by Mark Edel.
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA.
24 //
25 // Please report all bugs and problems to "fltk-bugs@fltk.org".
26 //
27
28 #ifndef FL_TEXT_BUFFER_H
29 #define FL_TEXT_BUFFER_H
30
31 /* Maximum length in characters of a tab or control character expansion
32    of a single buffer character */
33 #define FL_TEXT_MAX_EXP_CHAR_LEN 20
34
35 #include "Fl_Export.H"
36
37 class FL_EXPORT Fl_Text_Selection {
38   friend class Fl_Text_Buffer;
39
40   public:
41     void set(int start, int end);
42     void set_rectangular(int start, int end, int rectStart, int rectEnd);
43     void update(int pos, int nDeleted, int nInserted);
44     char rectangular() { return mRectangular; }
45     int start() { return mStart; }
46     int end() { return mEnd; }
47     int rect_start() { return mRectStart; }
48     int rect_end() { return mRectEnd; }
49     char selected() { return mSelected; }
50     void selected(char b) { mSelected = b; }
51     int includes(int pos, int lineStartPos, int dispIndex);
52     int position(int* start, int* end);
53     int position(int* start, int* end, int* isRect, int* rectStart, int* rectEnd);
54
55
56   protected:
57     char mSelected;
58     char mRectangular;
59     int mStart;
60     int mEnd;
61     int mRectStart;
62     int mRectEnd;
63 };
64
65 typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
66                                   int nRestyled, const char* deletedText,
67                                   void* cbArg);
68 typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
69
70 class FL_EXPORT Fl_Text_Buffer {
71   public:
72     Fl_Text_Buffer(int requestedSize = 0);
73     ~Fl_Text_Buffer();
74
75     int length() { return mLength; }
76     char* text();
77     void text(const char* text);
78     char* text_range(int start, int end);
79     char character(int pos);
80     char* text_in_rectangle(int start, int end, int rectStart, int rectEnd);
81     void insert(int pos, const char* text);
82     void append(const char* t) { insert(length(), t); }
83     void remove(int start, int end);
84     void replace(int start, int end, const char *text);
85     void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
86     int undo(int *cp=0);
87     void canUndo(char flag=1);
88     int insertfile(const char *file, int pos, int buflen = 128*1024);
89     int appendfile(const char *file, int buflen = 128*1024)
90       { return insertfile(file, length(), buflen); }
91     int loadfile(const char *file, int buflen = 128*1024)
92       { select(0, length()); remove_selection(); return appendfile(file, buflen); }
93     int outputfile(const char *file, int start, int end, int buflen = 128*1024);
94     int savefile(const char *file, int buflen = 128*1024)
95       { return outputfile(file, 0, length(), buflen); }
96
97     void insert_column(int column, int startPos, const char* text,
98                        int* charsInserted, int* charsDeleted);
99
100     void replace_rectangular(int start, int end, int rectStart, int rectEnd,
101                              const char* text);
102
103     void overlay_rectangular(int startPos, int rectStart, int rectEnd,
104                              const char* text, int* charsInserted,
105                              int* charsDeleted);
106
107     void remove_rectangular(int start, int end, int rectStart, int rectEnd);
108     void clear_rectangular(int start, int end, int rectStart, int rectEnd);
109     int tab_distance() { return mTabDist; }
110     void tab_distance(int tabDist);
111     void select(int start, int end);
112     int selected() { return mPrimary.selected(); }
113     void unselect();
114     void select_rectangular(int start, int end, int rectStart, int rectEnd);
115     int selection_position(int* start, int* end);
116
117     int selection_position(int* start, int* end, int* isRect, int* rectStart,
118                            int* rectEnd);
119
120     char* selection_text();
121     void remove_selection();
122     void replace_selection(const char* text);
123     void secondary_select(int start, int end);
124     void secondary_unselect();
125
126     void secondary_select_rectangular(int start, int end, int rectStart,
127                                       int rectEnd);
128
129     int secondary_selection_position(int* start, int* end, int* isRect,
130                                      int* rectStart, int* rectEnd);
131
132     char* secondary_selection_text();
133     void remove_secondary_selection();
134     void replace_secondary_selection(const char* text);
135     void highlight(int start, int end);
136     void unhighlight();
137     void highlight_rectangular(int start, int end, int rectStart, int rectEnd);
138
139     int highlight_position(int* start, int* end, int* isRect, int* rectStart,
140                            int* rectEnd);
141
142     char* highlight_text();
143     void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
144     void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
145
146     void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); }
147
148     void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB, void* cbArg);
149     void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg);
150
151     void call_predelete_callbacks() { call_predelete_callbacks(0, 0); }
152
153     char* line_text(int pos);
154     int line_start(int pos);
155     int line_end(int pos);
156     int word_start(int pos);
157     int word_end(int pos);
158     int expand_character(int pos, int indent, char *outStr);
159
160     static int expand_character(char c, int indent, char* outStr, int tabDist,
161                                 char nullSubsChar);
162
163     static int character_width(char c, int indent, int tabDist, char nullSubsChar);
164     int count_displayed_characters(int lineStartPos, int targetPos);
165     int skip_displayed_characters(int lineStartPos, int nChars);
166     int count_lines(int startPos, int endPos);
167     int skip_lines(int startPos, int nLines);
168     int rewind_lines(int startPos, int nLines);
169     int findchar_forward(int startPos, char searchChar, int* foundPos);
170     int findchar_backward(int startPos, char searchChar, int* foundPos);
171     int findchars_forward(int startPos, const char* searchChars, int* foundPos);
172     int findchars_backward(int startPos, const char* searchChars, int* foundPos);
173
174     int search_forward(int startPos, const char* searchString, int* foundPos,
175                        int matchCase = 0);
176
177     int search_backward(int startPos, const char* searchString, int* foundPos,
178                         int matchCase = 0);
179
180     int substitute_null_characters(char* string, int length);
181     void unsubstitute_null_characters(char* string);
182     char null_substitution_character() { return mNullSubsChar; }
183     Fl_Text_Selection* primary_selection() { return &mPrimary; }
184     Fl_Text_Selection* secondary_selection() { return &mSecondary; }
185     Fl_Text_Selection* highlight_selection() { return &mHighlight; }
186
187   protected:
188     void call_modify_callbacks(int pos, int nDeleted, int nInserted,
189                                int nRestyled, const char* deletedText);
190     void call_predelete_callbacks(int pos, int nDeleted);
191
192     int insert_(int pos, const char* text);
193     void remove_(int start, int end);
194
195     void remove_rectangular_(int start, int end, int rectStart, int rectEnd,
196                              int* replaceLen, int* endPos);
197
198     void insert_column_(int column, int startPos, const char* insText,
199                         int* nDeleted, int* nInserted, int* endPos);
200
201     void overlay_rectangular_(int startPos, int rectStart, int rectEnd,
202                               const char* insText, int* nDeleted,
203                               int* nInserted, int* endPos);
204
205     void redisplay_selection(Fl_Text_Selection* oldSelection,
206                              Fl_Text_Selection* newSelection);
207
208     void move_gap(int pos);
209     void reallocate_with_gap(int newGapStart, int newGapLen);
210     char* selection_text_(Fl_Text_Selection* sel);
211     void remove_selection_(Fl_Text_Selection* sel);
212     void replace_selection_(Fl_Text_Selection* sel, const char* text);
213
214     void rectangular_selection_boundaries(int lineStartPos, int rectStart,
215                                           int rectEnd, int* selStart,
216                                           int* selEnd);
217
218     void update_selections(int pos, int nDeleted, int nInserted);
219
220     Fl_Text_Selection mPrimary; /* highlighted areas */
221     Fl_Text_Selection mSecondary;
222     Fl_Text_Selection mHighlight;
223     int mLength;                /* length of the text in the buffer (the length
224                                    of the buffer itself must be calculated:
225                                    gapEnd - gapStart + length) */
226     char* mBuf;                 /* allocated memory where the text is stored */
227     int mGapStart;              /* points to the first character of the gap */
228     int mGapEnd;                /* points to the first char after the gap */
229     // The hardware tab distance used by all displays for this buffer,
230     // and used in computing offsets for rectangular selection operations.
231     int mTabDist;               /* equiv. number of characters in a tab */
232     int mUseTabs;               /* True if buffer routines are allowed to use
233                                    tabs for padding in rectangular operations */
234     int mNModifyProcs;          /* number of modify-redisplay procs attached */
235     Fl_Text_Modify_Cb*          /* procedures to call when buffer is */
236     mNodifyProcs;               /* modified to redisplay contents */
237     void** mCbArgs;             /* caller arguments for modifyProcs above */
238     int mNPredeleteProcs;       /* number of pre-delete procs attached */
239     Fl_Text_Predelete_Cb*       /* procedure to call before text is deleted */
240          mPredeleteProcs;       /* from the buffer; at most one is supported. */
241     void **mPredeleteCbArgs;    /* caller argument for pre-delete proc above */
242     int mCursorPosHint;         /* hint for reasonable cursor position after
243                                    a buffer modification operation */
244     char mNullSubsChar;         /* NEdit is based on C null-terminated strings,
245                                    so ascii-nul characters must be substituted
246                                    with something else.  This is the else, but
247                                    of course, things get quite messy when you
248                                    use it */
249     char mCanUndo;              /* if this buffer is used for attributes, it must
250                                    not do any undo calls */
251 };
252
253 #endif
254
255 //
256 // End of "$Id: Fl_Text_Buffer.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $".
257 //