FLTK 1.3.2

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

Fl_Text_Display.H
1 //
2 // "$Id: Fl_Text_Display.H 9078 2011-09-28 20:08:48Z matt $"
3 //
4 // Header file for Fl_Text_Display class.
5 //
6 // Copyright 2001-2010 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. Distribution and use rights are outlined in
11 // the file "COPYING" which should have been included with this file. If this
12 // file is missing or damaged, see the license at:
13 //
14 // http://www.fltk.org/COPYING.php
15 //
16 // Please report all bugs and problems on the following page:
17 //
18 // http://www.fltk.org/str.php
19 //
20
21 /* \file
22 Fl_Text_Display widget . */
23
24 #ifndef FL_TEXT_DISPLAY_H
25 #define FL_TEXT_DISPLAY_H
26
27 #include "fl_draw.H"
28 #include "Fl_Group.H"
29 #include "Fl_Widget.H"
30 #include "Fl_Scrollbar.H"
31 #include "Fl_Text_Buffer.H"
32
41 class FL_EXPORT Fl_Text_Display: public Fl_Group {
42
43 public:
44
48 enum {
49 NORMAL_CURSOR,
50 CARET_CURSOR,
51 DIM_CURSOR,
52 BLOCK_CURSOR,
53 HEAVY_CURSOR,
54 SIMPLE_CURSOR
55 };
56
62 enum {
63 CURSOR_POS,
64 CHARACTER_POS
65 };
66
72 enum {
73 DRAG_NONE = -2,
74 DRAG_START_DND = -1,
75 DRAG_CHAR = 0,
76 DRAG_WORD = 1,
77 DRAG_LINE = 2
78 };
79
83 enum {
84 WRAP_NONE,
85 WRAP_AT_COLUMN,
86 WRAP_AT_PIXEL,
87 WRAP_AT_BOUNDS
88 };
89
90 friend void fl_text_drag_me(int pos, Fl_Text_Display* d);
91
92 typedef void (*Unfinished_Style_Cb)(int, void *);
93
98 struct Style_Table_Entry {
99 Fl_Color color;
100 Fl_Font font;
101 Fl_Fontsize size;
102 unsigned attr;
103 };
104
105 Fl_Text_Display(int X, int Y, int W, int H, const char *l = 0);
106 ~Fl_Text_Display();
107
108 virtual int handle(int e);
109
110 void buffer(Fl_Text_Buffer* buf);
111
117 void buffer(Fl_Text_Buffer& buf) { buffer(&buf); }
118
124 Fl_Text_Buffer* buffer() const { return mBuffer; }
125
126 void redisplay_range(int start, int end);
127 void scroll(int topLineNum, int horizOffset);
128 void insert(const char* text);
129 void overstrike(const char* text);
130 void insert_position(int newPos);
131
136 int insert_position() const { return mCursorPos; }
137 int position_to_xy(int pos, int* x, int* y) const;
138
139 int in_selection(int x, int y) const;
140 void show_insert_position();
141
142 int move_right();
143 int move_left();
144 int move_up();
145 int move_down();
146 int count_lines(int start, int end, bool start_pos_is_line_start) const;
147 int line_start(int pos) const;
148 int line_end(int startPos, bool startPosIsLineStart) const;
149 int skip_lines(int startPos, int nLines, bool startPosIsLineStart);
150 int rewind_lines(int startPos, int nLines);
151 void next_word(void);
152 void previous_word(void);
153
154 void show_cursor(int b = 1);
155
159 void hide_cursor() { show_cursor(0); }
160
161 void cursor_style(int style);
162
167 Fl_Color cursor_color() const {return mCursor_color;}
168
173 void cursor_color(Fl_Color n) {mCursor_color = n;}
174
179 int scrollbar_width() const { return scrollbar_width_; }
180
185 void scrollbar_width(int W) { scrollbar_width_ = W; }
186
191 Fl_Align scrollbar_align() const { return scrollbar_align_; }
192
197 void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; }
198
204 int word_start(int pos) const { return buffer()->word_start(pos); }
205
211 int word_end(int pos) const { return buffer()->word_end(pos); }
212
213
214 void highlight_data(Fl_Text_Buffer *styleBuffer,
215 const Style_Table_Entry *styleTable,
216 int nStyles, char unfinishedStyle,
217 Unfinished_Style_Cb unfinishedHighlightCB,
218 void *cbArg);
219
220 int position_style(int lineStartPos, int lineLen, int lineIndex) const;
221
227 int shortcut() const {return shortcut_;}
228
234 void shortcut(int s) {shortcut_ = s;}
235
240 Fl_Font textfont() const {return textfont_;}
241
246 void textfont(Fl_Font s) {textfont_ = s; mColumnScale = 0;}
247
252 Fl_Fontsize textsize() const {return textsize_;}
253
258 void textsize(Fl_Fontsize s) {textsize_ = s; mColumnScale = 0;}
259
264 Fl_Color textcolor() const {return textcolor_;}
265
270 void textcolor(Fl_Color n) {textcolor_ = n;}
271
272 int wrapped_column(int row, int column) const;
273 int wrapped_row(int row) const;
274 void wrap_mode(int wrap, int wrap_margin);
275
276 virtual void resize(int X, int Y, int W, int H);
277
283 double x_to_col(double x) const;
284
291 double col_to_x(double col) const;
292
293 protected:
294 // Most (all?) of this stuff should only be called from resize() or
295 // draw().
296 // Anything with "vline" indicates thats it deals with currently
297 // visible lines.
298
299 virtual void draw();
300 void draw_text(int X, int Y, int W, int H);
301 void draw_range(int start, int end);
302 void draw_cursor(int, int);
303
304 void draw_string(int style, int x, int y, int toX, const char *string,
305 int nChars) const;
306
307 void draw_vline(int visLineNum, int leftClip, int rightClip,
308 int leftCharIndex, int rightCharIndex);
309
310 int find_x(const char *s, int len, int style, int x) const;
311
312 enum {
313 DRAW_LINE,
314 FIND_INDEX,
315 FIND_INDEX_FROM_ZERO,
316 GET_WIDTH
317 };
318
319 int handle_vline(int mode,
320 int lineStart, int lineLen, int leftChar, int rightChar,
321 int topClip, int bottomClip,
322 int leftClip, int rightClip) const;
323
324 void draw_line_numbers(bool clearAll);
325
326 void clear_rect(int style, int x, int y, int width, int height) const;
327 void display_insert();
328
329 void offset_line_starts(int newTopLineNum);
330
331 void calc_line_starts(int startLine, int endLine);
332
333 void update_line_starts(int pos, int charsInserted, int charsDeleted,
334 int linesInserted, int linesDeleted, int *scrolled);
335
336 void calc_last_char();
337
338 int position_to_line( int pos, int* lineNum ) const;
339 double string_width(const char* string, int length, int style) const;
340
341 static void scroll_timer_cb(void*);
342
343 static void buffer_predelete_cb(int pos, int nDeleted, void* cbArg);
344 static void buffer_modified_cb(int pos, int nInserted, int nDeleted,
345 int nRestyled, const char* deletedText,
346 void* cbArg);
347
348 static void h_scrollbar_cb(Fl_Scrollbar* w, Fl_Text_Display* d);
349 static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display* d);
350 void update_v_scrollbar();
351 void update_h_scrollbar();
352 int measure_vline(int visLineNum) const;
353 int longest_vline() const;
354 int empty_vlines() const;
355 int vline_length(int visLineNum) const;
356 int xy_to_position(int x, int y, int PosType = CHARACTER_POS) const;
357
358 void xy_to_rowcol(int x, int y, int* row, int* column,
359 int PosType = CHARACTER_POS) const;
360 void maintain_absolute_top_line_number(int state);
361 int get_absolute_top_line_number() const;
362 void absolute_top_line_number(int oldFirstChar);
363 int maintaining_absolute_top_line_number() const;
364 void reset_absolute_top_line_number();
365 int position_to_linecol(int pos, int* lineNum, int* column) const;
366 int scroll_(int topLineNum, int horizOffset);
367
368 void extend_range_for_styles(int* start, int* end);
369
370 void find_wrap_range(const char *deletedText, int pos, int nInserted,
371 int nDeleted, int *modRangeStart, int *modRangeEnd,
372 int *linesInserted, int *linesDeleted);
373 void measure_deleted_lines(int pos, int nDeleted);
374 void wrapped_line_counter(Fl_Text_Buffer *buf, int startPos, int maxPos,
375 int maxLines, bool startPosIsLineStart,
376 int styleBufOffset, int *retPos, int *retLines,
377 int *retLineStart, int *retLineEnd,
378 bool countLastLineMissingNewLine = true) const;
379 void find_line_end(int pos, bool start_pos_is_line_start, int *lineEnd,
380 int *nextLineStart) const;
381 double measure_proportional_character(const char *s, int colNum, int pos) const;
382 int wrap_uses_character(int lineEndPos) const;
383
384 int damage_range1_start, damage_range1_end;
385 int damage_range2_start, damage_range2_end;
386 int mCursorPos;
387 int mCursorOn;
388 int mCursorOldY; /* Y pos. of cursor for blanking */
389 int mCursorToHint; /* Tells the buffer modified callback
390 where to move the cursor, to reduce
391 the number of redraw calls */
392 int mCursorStyle; /* One of enum cursorStyles above */
393 int mCursorPreferredXPos; /* Pixel position for vert. cursor movement */
394 int mNVisibleLines; /* # of visible (displayed) lines */
395 int mNBufferLines; /* # of newlines in the buffer */
396 Fl_Text_Buffer* mBuffer; /* Contains text to be displayed */
397 Fl_Text_Buffer* mStyleBuffer; /* Optional parallel buffer containing
398 color and font information */
399 int mFirstChar, mLastChar; /* Buffer positions of first and last
400 displayed character (lastChar points
401 either to a newline or one character
402 beyond the end of the buffer) */
403 int mContinuousWrap; /* Wrap long lines when displaying */
404 int mWrapMarginPix; /* Margin in # of pixels for
405 wrapping in continuousWrap mode */
406 int* mLineStarts;
407 int mTopLineNum; /* Line number of top displayed line
408 of file (first line of file is 1) */
409 int mAbsTopLineNum; /* In continuous wrap mode, the line
410 number of the top line if the text
411 were not wrapped (note that this is
412 only maintained as needed). */
413 int mNeedAbsTopLineNum; /* Externally settable flag to continue
414 maintaining absTopLineNum even if
415 it isn't needed for line # display */
416 int mHorizOffset; /* Horizontal scroll pos. in pixels */
417 int mTopLineNumHint; /* Line number of top displayed line
418 of file (first line of file is 1) */
419 int mHorizOffsetHint; /* Horizontal scroll pos. in pixels */
420 int mNStyles; /* Number of entries in styleTable */
421 const Style_Table_Entry *mStyleTable; /* Table of fonts and colors for
422 coloring/syntax-highlighting */
423 char mUnfinishedStyle; /* Style buffer entry which triggers
424 on-the-fly reparsing of region */
425 Unfinished_Style_Cb mUnfinishedHighlightCB; /* Callback to parse "unfinished" */
426 /* regions */
427 void* mHighlightCBArg; /* Arg to unfinishedHighlightCB */
428
429 int mMaxsize;
430
431 int mSuppressResync; /* Suppress resynchronization of line
432 starts during buffer updates */
433 int mNLinesDeleted; /* Number of lines deleted during
434 buffer modification (only used
435 when resynchronization is suppressed) */
436 int mModifyingTabDistance; /* Whether tab distance is being
437 modified */
438
439 mutable double mColumnScale; /* Width in pixels of an average character. This
440 value is calculated as needed (lazy eval); it
441 needs to be mutable so that it can be calculated
442 within a method marked as "const" */
443
444 Fl_Color mCursor_color;
445
446 Fl_Scrollbar* mHScrollBar;
447 Fl_Scrollbar* mVScrollBar;
448 int scrollbar_width_;
449 Fl_Align scrollbar_align_;
450 int dragPos, dragType, dragging;
451 int display_insert_position_hint;
452 struct { int x, y, w, h; } text_area;
453
454 int shortcut_;
455
456 Fl_Font textfont_;
457 Fl_Fontsize textsize_;
458 Fl_Color textcolor_;
459
460 // The following are not presently used from the original NEdit code,
461 // but are being put here so that future versions of Fl_Text_Display
462 // can implement line numbers without breaking binary compatibility.
463
464 /* Line number margin and width */
465 int mLineNumLeft, mLineNumWidth;
466 };
467
468 #endif
469
470 //
471 // End of "$Id: Fl_Text_Display.H 9078 2011-09-28 20:08:48Z matt $".
472 //
Fl_Text_Display::hide_cursor
void hide_cursor()
Hides the text cursor.
Definition: Fl_Text_Display.H:159
Fl_Text_Display::textfont
Fl_Font textfont() const
Gets the default font used when drawing text in the widget.
Definition: Fl_Text_Display.H:240
Fl_Text_Display::WRAP_AT_PIXEL
wrap text at a pixel position
Definition: Fl_Text_Display.H:86
Fl_Text_Display::scrollbar_width
int scrollbar_width() const
Gets the width/height of the scrollbars.
Definition: Fl_Text_Display.H:179
Fl_Widget::x
int x() const
Gets the widget position in its window.
Definition: Fl_Widget.H:273
Fl_Text_Display::scrollbar_align
Fl_Align scrollbar_align() const
Gets the scrollbar alignment type.
Definition: Fl_Text_Display.H:191
Fl_Text_Display::Style_Table_Entry
This structure associates the color, font, andsize of a string to draw with an attribute mask matchin...
Definition: Fl_Text_Display.H:98
Fl_Text_Display::CARET_CURSOR
caret under the text
Definition: Fl_Text_Display.H:50
Fl_Widget::h
int h() const
Gets the widget height.
Definition: Fl_Widget.H:288
Fl_Text_Display::BLOCK_CURSOR
unfille box under the current character
Definition: Fl_Text_Display.H:52
Fl_Text_Display::insert_position
int insert_position() const
Gets the position of the text insertion cursor for text display.
Definition: Fl_Text_Display.H:136
Fl_Text_Display::scrollbar_align
void scrollbar_align(Fl_Align a)
Sets the scrollbar alignment type.
Definition: Fl_Text_Display.H:197
Fl_Text_Display::word_end
int word_end(int pos) const
Moves the insert position to the end of the current word.
Definition: Fl_Text_Display.H:211
Fl_Text_Buffer
This class manages unicode displayed in one or more Fl_Text_Display widgets.
Definition: Fl_Text_Buffer.H:157
Fl_Widget::w
int w() const
Gets the widget width.
Definition: Fl_Widget.H:283
Fl_Text_Display::DIM_CURSOR
dim I-beam
Definition: Fl_Text_Display.H:51
Fl_Text_Display::cursor_color
Fl_Color cursor_color() const
Gets the text cursor color.
Definition: Fl_Text_Display.H:167
Fl_Text_Display::WRAP_NONE
don&#39;t wrap text at all
Definition: Fl_Text_Display.H:84
Fl_Group::draw
void draw()
Draws the widget.
Definition: Fl_Group.cxx:736
Fl_Text_Display::textfont
void textfont(Fl_Font s)
Sets the default font used when drawing text in the widget.
Definition: Fl_Text_Display.H:246
Fl_Text_Display::WRAP_AT_COLUMN
wrap text at the given text column
Definition: Fl_Text_Display.H:85
Fl_Widget::y
int y() const
Gets the widget position in its window.
Definition: Fl_Widget.H:278
Fl_Group::insert
void insert(Fl_Widget &, int i)
The widget is removed from its current group (if any) and then inserted into this group...
Definition: Fl_Group.cxx:456
Fl_Group
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:36
Fl_Group::handle
int handle(int)
Handles the specified event.
Definition: Fl_Group.cxx:145
Fl_Widget.H
Fl_Widget, Fl_Label classes .
Fl_Text_Display::NORMAL_CURSOR
I-beam.
Definition: Fl_Text_Display.H:49
Fl_Text_Display::textsize
void textsize(Fl_Fontsize s)
Sets the default size of text in the widget.
Definition: Fl_Text_Display.H:258
Fl_Text_Display::buffer
void buffer(Fl_Text_Buffer &buf)
Sets the current text buffer associated with the text widget.
Definition: Fl_Text_Display.H:117
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:746
Fl_Group::resize
void resize(int, int, int, int)
Resizes the Fl_Group widget and all of its children.
Definition: Fl_Group.cxx:632
Fl_Text_Display::shortcut
int shortcut() const
Definition: Fl_Text_Display.H:227
Fl_Text_Display::textsize
Fl_Fontsize textsize() const
Gets the default size of text in the widget.
Definition: Fl_Text_Display.H:252
Fl_Text_Display::textcolor
void textcolor(Fl_Color n)
Sets the default color of text in the widget.
Definition: Fl_Text_Display.H:270
fl_draw.H
utility header to pull drawing functions together
Fl_Color
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:774
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:717
Fl_Text_Display::cursor_color
void cursor_color(Fl_Color n)
Sets the text cursor color.
Definition: Fl_Text_Display.H:173
Fl_Align
unsigned Fl_Align
FLTK type for alignment control.
Definition: Enumerations.H:668
Fl_Text_Display::word_start
int word_start(int pos) const
Moves the insert position to the beginning of the current word.
Definition: Fl_Text_Display.H:204
Fl_Text_Display::HEAVY_CURSOR
thick I-beam
Definition: Fl_Text_Display.H:53
Fl_Text_Display::buffer
Fl_Text_Buffer * buffer() const
Gets the current text buffer associated with the text widget.
Definition: Fl_Text_Display.H:124
Fl_Text_Display::textcolor
Fl_Color textcolor() const
Gets the default color of text in the widget.
Definition: Fl_Text_Display.H:264
Fl_Scrollbar
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition: Fl_Scrollbar.H:43
Fl_Text_Display
Rich text display widget.
Definition: Fl_Text_Display.H:41
Fl_Text_Display::shortcut
void shortcut(int s)
Definition: Fl_Text_Display.H:234
Fl_Text_Display::scrollbar_width
void scrollbar_width(int W)
Sets the width/height of the scrollbars.
Definition: Fl_Text_Display.H:185
- © 1998-2012 by Bill Spitzak and others.