diff options
Diffstat (limited to 'FL/Fl_Text_Display.H')
| -rw-r--r-- | FL/Fl_Text_Display.H | 222 |
1 files changed, 108 insertions, 114 deletions
diff --git a/FL/Fl_Text_Display.H b/FL/Fl_Text_Display.H index 6d077fbb7..59dc24bee 100644 --- a/FL/Fl_Text_Display.H +++ b/FL/Fl_Text_Display.H @@ -1,6 +1,4 @@ // -// "$Id$" -// // Header file for Fl_Text_Display class. // // Copyright 2001-2020 by Bill Spitzak and others. @@ -13,9 +11,9 @@ // // https://www.fltk.org/COPYING.php // -// Please report all bugs and problems on the following page: +// Please see the following page on how to report bugs and issues: // -// https://www.fltk.org/str.php +// https://www.fltk.org/bugs.php // /* \file @@ -24,7 +22,7 @@ #ifndef FL_TEXT_DISPLAY_H #define FL_TEXT_DISPLAY_H -#include <FL/Fl.H> // Fl::scrollbar_size() +#include <FL/Fl.H> // Fl::scrollbar_size() #include "fl_draw.H" #include "Fl_Group.H" #include "Fl_Widget.H" @@ -33,7 +31,7 @@ /** \brief Rich text display widget. - + This is the FLTK text display widget. It allows the user to view multiple lines of text and supports highlighting, word wrap, mixes of font faces and colors, line numbers and scrolling. The buffer @@ -57,7 +55,7 @@ Fl_Text_Display *disp = new Fl_Text_Display(10, 10, 640, 480); disp->buffer(buff); // attach text buffer to display widget buff->text("line one\nline two"); // add some text to buffer - .. + .. } \endcode @@ -80,9 +78,9 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group { public: - - /** - text display cursor shapes enumeration + + /** + text display cursor shapes enumeration */ enum { NORMAL_CURSOR, /**< I-beam */ @@ -92,18 +90,18 @@ public: HEAVY_CURSOR, /**< thick I-beam */ SIMPLE_CURSOR /**< as cursor as Fl_Input cursor */ }; - + /** - the character position is the left edge of a character, whereas + the character position is the left edge of a character, whereas the cursor is thought to be between the centers of two consecutive characters. */ enum { - CURSOR_POS, + CURSOR_POS, CHARACTER_POS }; - - /** + + /** drag types - they match Fl::event_clicks() so that single clicking to start a collection selects by character, double clicking selects by word and triple clicking selects by line. @@ -111,11 +109,11 @@ public: enum { DRAG_NONE = -2, DRAG_START_DND = -1, - DRAG_CHAR = 0, - DRAG_WORD = 1, + DRAG_CHAR = 0, + DRAG_WORD = 1, DRAG_LINE = 2 }; - + /** wrap types - used in wrap_mode() */ @@ -124,13 +122,13 @@ public: WRAP_AT_COLUMN, /**< wrap text at the given text column */ WRAP_AT_PIXEL, /**< wrap text at a pixel position */ WRAP_AT_BOUNDS /**< wrap text so that it fits into the widget width */ - }; - + }; + friend void fl_text_drag_me(int pos, Fl_Text_Display* d); - + typedef void (*Unfinished_Style_Cb)(int, void *); - - /** + + /** This structure associates the color, font, and font size of a string to draw with an attribute mask matching attr. @@ -144,19 +142,19 @@ public: \see Fl_Text_Display::highlight_data() */ struct Style_Table_Entry { - Fl_Color color; ///< text color - Fl_Font font; ///< text font - Fl_Fontsize size; ///< text font size - unsigned attr; ///< currently unused (this may be changed in the future) + Fl_Color color; ///< text color + Fl_Font font; ///< text font + Fl_Fontsize size; ///< text font size + unsigned attr; ///< currently unused (this may be changed in the future) }; - + Fl_Text_Display(int X, int Y, int W, int H, const char *l = 0); ~Fl_Text_Display(); - + virtual int handle(int e); - + void buffer(Fl_Text_Buffer* buf); - + /** Sets the current text buffer associated with the text widget. Multiple text widgets can be associated with the same text buffer. @@ -164,7 +162,7 @@ public: \see Fl_Text_Display::buffer(Fl_Text_Buffer* buf) */ void buffer(Fl_Text_Buffer& buf) { buffer(&buf); } - + /** Gets the current text buffer associated with the text widget. Multiple text widgets can be associated with the same text buffer. @@ -173,7 +171,7 @@ public: \see Fl_Text_Display::buffer(Fl_Text_Buffer& buf) */ Fl_Text_Buffer* buffer() const { return mBuffer; } - + void redisplay_range(int start, int end); void scroll(int topLineNum, int horizOffset); void insert(const char* text); @@ -196,10 +194,10 @@ public: int in_selection(int x, int y) const; void show_insert_position(); - + int move_right(); int move_left(); - int move_up(); + int move_up(); int move_down(); int count_lines(int start, int end, bool start_pos_is_line_start) const; int line_start(int pos) const; @@ -208,29 +206,29 @@ public: int rewind_lines(int startPos, int nLines); void next_word(void); void previous_word(void); - + void show_cursor(int b = 1); - + /** Hides the text cursor. */ void hide_cursor() { show_cursor(0); } - + void cursor_style(int style); int cursor_style() const { return mCursorStyle; } - + /** - Gets the text cursor color. + Gets the text cursor color. \return cursor color */ Fl_Color cursor_color() const {return mCursor_color;} - - /** + + /** Sets the text cursor color. \param n new cursor color */ void cursor_color(Fl_Color n) {mCursor_color = n;} - + /** Returns the global value Fl::scrollbar_size() unless a specific scrollbar_width_ has been set. \deprecated Use scrollbar_size() instead. @@ -249,13 +247,13 @@ public: Fl::scrollbar_size(width); scrollbar_width_ = 0; } - + /** Gets the current size of the scrollbars' troughs, in pixels. - If this value is zero (default), this widget will use the + If this value is zero (default), this widget will use the Fl::scrollbar_size() value as the scrollbar's width. - + \returns Scrollbar size in pixels, or 0 if the global Fl::scrollbar_size() is being used. \see Fl::scrollbar_size(int) */ @@ -267,114 +265,114 @@ public: Sets the pixel size of the scrollbars' troughs to \p newSize, in pixels. Normally you should not need this method, and should use - Fl::scrollbar_size(int) instead to manage the size of ALL - your widgets' scrollbars. This ensures your application + Fl::scrollbar_size(int) instead to manage the size of ALL + your widgets' scrollbars. This ensures your application has a consistent UI, is the default behavior, and is normally what you want. Only use THIS method if you really need to override the global scrollbar size. The need for this should be rare. - + Setting \p newSize to the special value of 0 causes the widget to track the global Fl::scrollbar_size(), which is the default. - + \param[in] newSize Sets the scrollbar size in pixels.\n If 0 (default), scrollbar size tracks the global Fl::scrollbar_size() \see Fl::scrollbar_size() */ void scrollbar_size(int newSize) { scrollbar_width_ = newSize; - } + } /** Gets the scrollbar alignment type. \return scrollbar alignment */ Fl_Align scrollbar_align() const { return scrollbar_align_; } - + /** Sets the scrollbar alignment type. \param a new scrollbar alignment */ void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; } - + /** Moves the insert position to the beginning of the current word. \param pos start calculation at this index \return beginning of the words */ int word_start(int pos) const { return buffer()->word_start(pos); } - - /** + + /** Moves the insert position to the end of the current word. \param pos start calculation at this index \return index of first character after the end of the word */ int word_end(int pos) const { return buffer()->word_end(pos); } - - + + void highlight_data(Fl_Text_Buffer *styleBuffer, const Style_Table_Entry *styleTable, int nStyles, char unfinishedStyle, Unfinished_Style_Cb unfinishedHighlightCB, void *cbArg); - + int position_style(int lineStartPos, int lineLen, int lineIndex) const; - - /** - \todo FIXME : get set methods pointing on shortcut_ - have no effects as shortcut_ is unused in this class and derived! + + /** + \todo FIXME : get set methods pointing on shortcut_ + have no effects as shortcut_ is unused in this class and derived! \return the current shortcut key */ int shortcut() const {return shortcut_;} - + /** - \todo FIXME : get set methods pointing on shortcut_ - have no effects as shortcut_ is unused in this class and derived! + \todo FIXME : get set methods pointing on shortcut_ + have no effects as shortcut_ is unused in this class and derived! \param s the new shortcut key */ void shortcut(int s) {shortcut_ = s;} - + /** Gets the default font used when drawing text in the widget. \return current text font face unless overridden by a style */ Fl_Font textfont() const {return textfont_;} - + /** Sets the default font used when drawing text in the widget. \param s default text font face */ void textfont(Fl_Font s) {textfont_ = s; mColumnScale = 0; } - + /** Gets the default size of text in the widget. \return current text height unless overridden by a style */ Fl_Fontsize textsize() const {return textsize_;} - + /** Sets the default size of text in the widget. \param s new text size */ void textsize(Fl_Fontsize s) {textsize_ = s; mColumnScale = 0; } - + /** Gets the default color of text in the widget. \return text color unless overridden by a style */ Fl_Color textcolor() const {return textcolor_;} - + /** Sets the default color of text in the widget. \param n new text color */ void textcolor(Fl_Color n) {textcolor_ = n;} - + int wrapped_column(int row, int column) const; int wrapped_row(int row) const; void wrap_mode(int wrap, int wrap_margin); - + virtual void recalc_display(); virtual void resize(int X, int Y, int W, int H); @@ -384,15 +382,15 @@ public: \return an approximate column number based on the main font */ double x_to_col(double x) const; - + /** Convert a column number into an x pixel position. \param col an approximate column number based on the main font \return number of pixels from the left margin to the left of an - average sized character + average sized character */ double col_to_x(double col) const; - + void linenumber_width(int width); int linenumber_width() const; void linenumber_font(Fl_Font val); @@ -413,57 +411,57 @@ protected: // draw(). // Anything with "vline" indicates thats it deals with currently // visible lines. - + virtual void draw(); void draw_text(int X, int Y, int W, int H); void draw_range(int start, int end); void draw_cursor(int, int); - + void draw_string(int style, int x, int y, int toX, const char *string, int nChars) const; - + void draw_vline(int visLineNum, int leftClip, int rightClip, int leftCharIndex, int rightCharIndex); - + int find_x(const char *s, int len, int style, int x) const; - - enum { - DRAW_LINE, + + enum { + DRAW_LINE, FIND_INDEX, FIND_INDEX_FROM_ZERO, GET_WIDTH, - FIND_CURSOR_INDEX // STR #2788 + FIND_CURSOR_INDEX // STR #2788 }; - - int handle_vline(int mode, + + int handle_vline(int mode, int lineStart, int lineLen, int leftChar, int rightChar, int topClip, int bottomClip, int leftClip, int rightClip) const; - + void draw_line_numbers(bool clearAll); - + void clear_rect(int style, int x, int y, int width, int height) const; void display_insert(); - + void offset_line_starts(int newTopLineNum); - + void calc_line_starts(int startLine, int endLine); - + void update_line_starts(int pos, int charsInserted, int charsDeleted, int linesInserted, int linesDeleted, int *scrolled); - + void calc_last_char(); - + int position_to_line( int pos, int* lineNum ) const; double string_width(const char* string, int length, int style) const; - + static void scroll_timer_cb(void*); - + static void buffer_predelete_cb(int pos, int nDeleted, void* cbArg); static void buffer_modified_cb(int pos, int nInserted, int nDeleted, int nRestyled, const char* deletedText, void* cbArg); - + static void h_scrollbar_cb(Fl_Scrollbar* w, Fl_Text_Display* d); static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display* d); void update_v_scrollbar(); @@ -473,7 +471,7 @@ protected: int empty_vlines() const; int vline_length(int visLineNum) const; int xy_to_position(int x, int y, int PosType = CHARACTER_POS) const; - + void xy_to_rowcol(int x, int y, int* row, int* column, int PosType = CHARACTER_POS) const; void maintain_absolute_top_line_number(int state); @@ -483,9 +481,9 @@ protected: void reset_absolute_top_line_number(); int position_to_linecol(int pos, int* lineNum, int* column) const; int scroll_(int topLineNum, int horizOffset); - + void extend_range_for_styles(int* start, int* end); - + void find_wrap_range(const char *deletedText, int pos, int nInserted, int nDeleted, int *modRangeStart, int *modRangeEnd, int *linesInserted, int *linesDeleted); @@ -499,7 +497,7 @@ protected: int *nextLineStart) const; double measure_proportional_character(const char *s, int colNum, int pos) const; int wrap_uses_character(int lineEndPos) const; - + int damage_range1_start, damage_range1_end; int damage_range2_start, damage_range2_end; int mCursorPos; @@ -521,7 +519,7 @@ protected: either to a newline or one character beyond the end of the buffer) */ int mContinuousWrap; /* Wrap long lines when displaying */ - int mWrapMarginPix; /* Margin in # of pixels for + int mWrapMarginPix; /* Margin in # of pixels for wrapping in continuousWrap mode */ int* mLineStarts; /* Array of the size mNVisibleLines. This array only keeps track of lines @@ -554,9 +552,9 @@ protected: Unfinished_Style_Cb mUnfinishedHighlightCB; /* Callback to parse "unfinished" */ /* regions */ void* mHighlightCBArg; /* Arg to unfinishedHighlightCB */ - + int mMaxsize; - + int mSuppressResync; /* Suppress resynchronization of line starts during buffer updates */ int mNLinesDeleted; /* Number of lines deleted during @@ -565,26 +563,26 @@ protected: int mModifyingTabDistance; /* Whether tab distance is being modified XXX: UNUSED */ mutable double mColumnScale; /* Width in pixels of an average character. This - value is calculated as needed (lazy eval); it + value is calculated as needed (lazy eval); it needs to be mutable so that it can be calculated within a method marked as "const" */ - + Fl_Color mCursor_color; - + Fl_Scrollbar* mHScrollBar; Fl_Scrollbar* mVScrollBar; - int scrollbar_width_; // size of scrollbar trough (behavior changed in 1.4) + int scrollbar_width_; // size of scrollbar trough (behavior changed in 1.4) Fl_Align scrollbar_align_; int dragPos, dragType, dragging; int display_insert_position_hint; struct { int x, y, w, h; } text_area; - + int shortcut_; - + Fl_Font textfont_; Fl_Fontsize textsize_; Fl_Color textcolor_; - + // Line number margin and width int mLineNumLeft, mLineNumWidth; @@ -598,7 +596,3 @@ protected: }; #endif - -// -// End of "$Id$". -// |
