source: NonGTP/include/fltk/TextDisplay.h @ 769

Revision 769, 11.6 KB checked in by gumbau, 18 years ago (diff)

FLTK imported to SVN repository to be linked agains the GeoTool? application

Line 
1//
2// "$Id: TextDisplay.h 4467 2005-08-05 19:17:34Z dejan $"
3//
4// Header file for TextDisplay class.
5//
6// Copyright 2001-2005 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 on the following page:
26//
27//     http://www.fltk.org/str.php
28//
29
30#ifndef TEXT_DISPLAY_H
31#define TEXT_DISPLAY_H
32
33#include "draw.h"
34#include "Group.h"
35#include "Widget.h"
36#include "Scrollbar.h"
37#include "TextBuffer.h"
38#include "Font.h"
39
40namespace fltk {
41
42class FL_API TextDisplay: public Group {
43  public:
44    enum {
45      NORMAL_CURSOR, CARET_CURSOR, DIM_CURSOR,
46      BLOCK_CURSOR, HEAVY_CURSOR
47    };
48
49    enum {
50      CURSOR_POS, CHARACTER_POS
51    };
52
53    // drag types- they match Fl::event_clicks() so that single clicking to
54    // start a collection selects by character, double clicking selects by
55    // word and triple clicking selects by line.
56    enum {
57      DRAG_CHAR = 0, DRAG_WORD = 1, DRAG_LINE = 2
58    };
59
60    typedef void (*UnfinishedStyleCb)(int, void *);
61
62    // style attributes - currently not implemented!
63    enum {
64      ATTR_NONE = 0,
65      ATTR_UNDERLINE = 1,
66      ATTR_HIDDEN = 2
67    };
68
69    struct StyleTableEntry {
70      Color     color;
71      Font*     font;
72      int       size;
73      unsigned  attr;
74    };
75
76    TextDisplay(int X, int Y, int W, int H, const char *l = 0);
77    ~TextDisplay();
78
79    virtual int handle(int e);
80    void buffer(TextBuffer* buf);
81    void buffer(TextBuffer& buf) { buffer(&buf); }
82    TextBuffer* buffer() { return mBuffer; }
83    void redisplay_range(int start, int end);
84    void scroll(int topLineNum, int horizOffset);
85    void insert(const char* text);
86    void overstrike(const char* text);
87    void insert_position(int newPos);
88    int insert_position() { return mCursorPos; }
89    int in_selection(int x, int y);
90    void show_insert_position();
91    int move_right();
92    int move_left();
93    int move_up();
94    int move_down();
95    int count_lines(int start, int end, bool start_pos_is_line_start);
96    int line_start(int pos);
97    int line_end(int pos, bool start_pos_is_line_start);
98    int skip_lines(int startPos, int nLines, bool startPosIsLineStart);
99    int rewind_lines(int startPos, int nLines);
100    void next_word(void);
101    void previous_word(void);
102    void show_cursor(int b = 1);
103    void hide_cursor() { show_cursor(0); }
104    void cursor_style(int style);
105    Color cursor_color() const {return mCursor_color;}
106    void cursor_color(Color n) {mCursor_color = n;}
107    int scrollbar_width() { return scrollbar_width_; }
108    Align scrollbar_align() { return scrollbar_align_; }
109    void scrollbar_width(int W) { scrollbar_width_ = W; }
110    void scrollbar_align(Align a) { scrollbar_align_ = a; }
111    int word_start(int pos) { return buffer()->word_start(pos); }
112    int word_end(int pos) { return buffer()->word_end(pos); }
113
114   
115    void highlight_data(TextBuffer *styleBuffer,
116                        StyleTableEntry *styleTable,
117                        int nStyles, char unfinishedStyle,
118                        UnfinishedStyleCb unfinishedHighlightCB,
119                        void *cbArg);
120
121    int position_style(int lineStartPos, int lineLen, int lineIndex,
122                       int dispIndex);
123
124    //Font textfont() const {return (Font)textfont_;}
125    //void textfont(uchar s) {textfont_ = s;}
126    uchar textsize() const {return textsize_;}
127    void textsize(uchar s) {textsize_ = s;}
128    Color textcolor() const {return (Color)textcolor_;}
129    void textcolor(unsigned n) {textcolor_ = n;}
130
131    int wrapped_column(int row, int column);
132    int wrapped_row(int row);
133    void wrap_mode(int wrap, int wrap_margin);
134
135    //virtual void resize(int X, int Y, int W, int H);
136
137  protected:
138    // Most (all?) of this stuff should only be called from resize() or
139    // draw().
140    // Anything with "vline" indicates thats it deals with currently
141    // visible lines.
142
143    virtual void draw();
144    virtual void layout();
145
146    void draw_text(int X, int Y, int W, int H);
147    void draw_range(int start, int end);
148    void draw_cursor(int, int);
149
150    void draw_string(int style, int x, int y, int toX, const char *string,
151                     int nChars);
152
153    void draw_vline(int visLineNum, int leftClip, int rightClip,
154                    int leftCharIndex, int rightCharIndex);
155
156    void draw_line_numbers(bool clearAll);
157
158    void clear_rect(int style, int x, int y, int width, int height);
159    void display_insert();
160
161    void offset_line_starts(int newTopLineNum);
162
163    void calc_line_starts(int startLine, int endLine);
164
165    void update_line_starts(int pos, int charsInserted, int charsDeleted,
166                            int linesInserted, int linesDeleted, int *scrolled);
167
168    void calc_last_char();
169
170    int position_to_line( int pos, int* lineNum );
171    int string_width(const char* string, int length, int style);
172
173    static void buffer_predelete_cb(int pos, int nDeleted, void* cbArg);
174    static void buffer_modified_cb(int pos, int nInserted, int nDeleted,
175                                   int nRestyled, const char* deletedText,
176                                   void* cbArg);
177
178    static void h_scrollbar_cb(Scrollbar* w, TextDisplay* d);
179    static void v_scrollbar_cb( Scrollbar* w, TextDisplay* d);
180    void update_v_scrollbar();
181    void update_h_scrollbar();
182    int measure_vline(int visLineNum);
183    int longest_vline();
184    int empty_vlines();
185    int vline_length(int visLineNum);
186    int xy_to_position(int x, int y, int PosType = CHARACTER_POS);
187
188    void xy_to_rowcol(int x, int y, int* row, int* column,
189                      int PosType = CHARACTER_POS);
190
191    int position_to_xy(int pos, int* x, int* y);
192    void maintain_absolute_top_line_number(int state);
193    int get_absolute_top_line_number();
194    void absolute_top_line_number(int oldFirstChar);
195    int maintaining_absolute_top_line_number();
196    void reset_absolute_top_line_number();
197    int position_to_linecol(int pos, int* lineNum, int* column);
198    void scroll_(int topLineNum, int horizOffset);
199
200    void extend_range_for_styles(int* start, int* end);
201
202    void find_wrap_range(const char *deletedText, int pos, int nInserted,
203                           int nDeleted, int *modRangeStart, int *modRangeEnd,
204                           int *linesInserted, int *linesDeleted);
205    void measure_deleted_lines(int pos, int nDeleted);
206    void wrapped_line_counter(TextBuffer *buf, int startPos, int maxPos,
207                               int maxLines, bool startPosIsLineStart,
208                               int styleBufOffset, int *retPos, int *retLines,
209                               int *retLineStart, int *retLineEnd,
210                               bool countLastLineMissingNewLine = true);
211    void find_line_end(int pos, bool start_pos_is_line_start, int *lineEnd,
212                         int *nextLineStart);
213    int measure_proportional_character(char c, int colNum, int pos);
214    int wrap_uses_character(int lineEndPos);
215    int range_touches_selection(TextSelection *sel, int rangeStart,
216                                 int rangeEnd);
217    void text_drag_me(int pos);
218
219    int damage_range1_start, damage_range1_end;
220    int damage_range2_start, damage_range2_end;
221    int mCursorPos;
222    int mCursorOn;
223    int mCursorOldY;            /* Y pos. of cursor for blanking */
224    int mCursorToHint;          /* Tells the buffer modified callback
225                                   where to move the cursor, to reduce
226                                   the number of redraw calls */
227    int mCursorStyle;           /* One of enum cursorStyles above */
228    int mCursorPreferredCol;    /* Column for vert. cursor movement */
229    int mNVisibleLines;         /* # of visible (displayed) lines */
230    int mNBufferLines;          /* # of newlines in the buffer */
231    TextBuffer* mBuffer;    /* Contains text to be displayed */
232    TextBuffer* mStyleBuffer; /* Optional parallel buffer containing
233                                     color and font information */
234    int mFirstChar, mLastChar;  /* Buffer positions of first and last
235                                   displayed character (lastChar points
236                                   either to a newline or one character
237                                   beyond the end of the buffer) */
238    int mContinuousWrap;          /* Wrap long lines when displaying */
239    int mWrapMargin;              /* Margin in # of char positions for
240                                           wrapping in continuousWrap mode */
241    int* mLineStarts;
242    int mTopLineNum;            /* Line number of top displayed line
243                                   of file (first line of file is 1) */
244    int mAbsTopLineNum;                 /* In continuous wrap mode, the line
245                                           number of the top line if the text
246                                           were not wrapped (note that this is
247                                           only maintained as needed). */
248    int mNeedAbsTopLineNum;     /* Externally settable flag to continue
249                                           maintaining absTopLineNum even if
250                                           it isn't needed for line # display */
251    int mHorizOffset;           /* Horizontal scroll pos. in pixels */
252    int mTopLineNumHint;        /* Line number of top displayed line
253                                   of file (first line of file is 1) */
254    int mHorizOffsetHint;       /* Horizontal scroll pos. in pixels */
255    int mNStyles;               /* Number of entries in styleTable */
256    const StyleTableEntry *mStyleTable; /* Table of fonts and colors for
257                                   coloring/syntax-highlighting */
258    char mUnfinishedStyle;      /* Style buffer entry which triggers
259                                   on-the-fly reparsing of region */
260    UnfinishedStyleCb mUnfinishedHighlightCB; /* Callback to parse "unfinished" */
261                                /* regions */
262    void* mHighlightCBArg;      /* Arg to unfinishedHighlightCB */
263
264    int mMaxsize;
265
266    int mFixedFontWidth;        /* Font width if all current fonts are
267                                   fixed and match in width, else -1 */
268    int mSuppressResync;                /* Suppress resynchronization of line
269                                           starts during buffer updates */
270    int mNLinesDeleted;                 /* Number of lines deleted during
271                                           buffer modification (only used
272                                           when resynchronization is suppressed) */
273    int mModifyingTabDistance;  /* Whether tab distance is being
274                                           modified */
275
276    Color mCursor_color;
277
278    Scrollbar* mHScrollBar;
279    Scrollbar* mVScrollBar;
280    int scrollbar_width_;
281    Align scrollbar_align_;
282    int dragPos, dragType, dragging;
283    int display_insert_position_hint;
284    //struct { int x, y, w, h; } text_area;
285    Rectangle text_area;
286
287    uchar textfont_;
288    uchar textsize_;
289    unsigned textcolor_;
290
291         // The following are not presently used from the original NEdit code,
292         // but are being put here so that future versions of TextDisplay
293         // can implement line numbers without breaking binary compatibility.
294    int mLineNumLeft, mLineNumWidth;
295                                /* Line number margin and width */
296};
297
298}
299#endif
300
301//
302// End of "$Id: TextDisplay.h 4467 2005-08-05 19:17:34Z dejan $".
303//
304
Note: See TracBrowser for help on using the repository browser.