• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

Fl_Text_Display.H

00001 //
00002 // "$Id$"
00003 //
00004 // Header file for Fl_Text_Display class.
00005 //
00006 // Copyright 2001-2016 by Bill Spitzak and others.
00007 // Original code Copyright Mark Edel.  Permission to distribute under
00008 // the LGPL for the FLTK library granted by Mark Edel.
00009 //
00010 // This library is free software. Distribution and use rights are outlined in
00011 // the file "COPYING" which should have been included with this file.  If this
00012 // file is missing or damaged, see the license at:
00013 //
00014 //     http://www.fltk.org/COPYING.php
00015 //
00016 // Please report all bugs and problems on the following page:
00017 //
00018 //     http://www.fltk.org/str.php
00019 //
00020 
00021 /* \file
00022  Fl_Text_Display widget . */
00023 
00024 #ifndef FL_TEXT_DISPLAY_H
00025 #define FL_TEXT_DISPLAY_H
00026 
00027 #include "fl_draw.H"
00028 #include "Fl_Group.H"
00029 #include "Fl_Widget.H"
00030 #include "Fl_Scrollbar.H"
00031 #include "Fl_Text_Buffer.H"
00032 
00082 class FL_EXPORT Fl_Text_Display: public Fl_Group {
00083 
00084 public:
00085   
00089   enum {
00090     NORMAL_CURSOR,    
00091     CARET_CURSOR,     
00092     DIM_CURSOR,       
00093     BLOCK_CURSOR,     
00094     HEAVY_CURSOR,     
00095     SIMPLE_CURSOR    
00096   };
00097   
00103   enum {
00104     CURSOR_POS, 
00105     CHARACTER_POS
00106   };
00107   
00113   enum {
00114     DRAG_NONE = -2,
00115     DRAG_START_DND = -1,
00116     DRAG_CHAR = 0, 
00117     DRAG_WORD = 1, 
00118     DRAG_LINE = 2
00119   };
00120   
00124   enum {
00125     WRAP_NONE,      
00126     WRAP_AT_COLUMN, 
00127     WRAP_AT_PIXEL,  
00128     WRAP_AT_BOUNDS  
00129   };    
00130   
00131   friend void fl_text_drag_me(int pos, Fl_Text_Display* d);
00132   
00133   typedef void (*Unfinished_Style_Cb)(int, void *);
00134   
00148   struct Style_Table_Entry {
00149     Fl_Color    color;  
00150     Fl_Font     font;   
00151     Fl_Fontsize size;   
00152     unsigned    attr;   
00153   };
00154   
00155   Fl_Text_Display(int X, int Y, int W, int H, const char *l = 0);
00156   ~Fl_Text_Display();
00157   
00158   virtual int handle(int e);
00159   
00160   void buffer(Fl_Text_Buffer* buf);
00161   
00167   void buffer(Fl_Text_Buffer& buf) { buffer(&buf); }
00168   
00174   Fl_Text_Buffer* buffer() const { return mBuffer; }
00175   
00176   void redisplay_range(int start, int end);
00177   void scroll(int topLineNum, int horizOffset);
00178   void insert(const char* text);
00179   void overstrike(const char* text);
00180   void insert_position(int newPos);
00181   
00186   int insert_position() const { return mCursorPos; }
00187   int position_to_xy(int pos, int* x, int* y) const;
00188 
00189   int in_selection(int x, int y) const;
00190   void show_insert_position();
00191   
00192   int move_right();
00193   int move_left();
00194   int move_up();  
00195   int move_down();
00196   int count_lines(int start, int end, bool start_pos_is_line_start) const;
00197   int line_start(int pos) const;
00198   int line_end(int startPos, bool startPosIsLineStart) const;
00199   int skip_lines(int startPos, int nLines, bool startPosIsLineStart);
00200   int rewind_lines(int startPos, int nLines);
00201   void next_word(void);
00202   void previous_word(void);
00203   
00204   void show_cursor(int b = 1);
00205   
00209   void hide_cursor() { show_cursor(0); }
00210   
00211   void cursor_style(int style);
00212   
00217   Fl_Color cursor_color() const {return mCursor_color;}
00218   
00223   void cursor_color(Fl_Color n) {mCursor_color = n;}
00224   
00229   int scrollbar_width() const { return scrollbar_width_; }
00230   
00235   void scrollbar_width(int W) { scrollbar_width_ = W; }
00236   
00241   Fl_Align scrollbar_align() const { return scrollbar_align_; }
00242   
00247   void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; }
00248   
00254   int word_start(int pos) const { return buffer()->word_start(pos); }
00255   
00261   int word_end(int pos) const { return buffer()->word_end(pos); }
00262   
00263   
00264   void highlight_data(Fl_Text_Buffer *styleBuffer,
00265                       const Style_Table_Entry *styleTable,
00266                       int nStyles, char unfinishedStyle,
00267                       Unfinished_Style_Cb unfinishedHighlightCB,
00268                       void *cbArg);
00269   
00270   int position_style(int lineStartPos, int lineLen, int lineIndex) const;
00271   
00277   int shortcut() const {return shortcut_;}
00278   
00284   void shortcut(int s) {shortcut_ = s;}
00285   
00290   Fl_Font textfont() const {return textfont_;}
00291   
00296   void textfont(Fl_Font s) {textfont_ = s; mColumnScale = 0;}
00297   
00302   Fl_Fontsize textsize() const {return textsize_;}
00303   
00308   void textsize(Fl_Fontsize s) {textsize_ = s; mColumnScale = 0;}
00309   
00314   Fl_Color textcolor() const {return textcolor_;}
00315   
00320   void textcolor(Fl_Color n) {textcolor_ = n;}
00321   
00322   int wrapped_column(int row, int column) const;
00323   int wrapped_row(int row) const;
00324   void wrap_mode(int wrap, int wrap_margin);
00325   
00326   virtual void resize(int X, int Y, int W, int H);
00327 
00333   double x_to_col(double x) const;
00334   
00341   double col_to_x(double col) const;
00342   
00343   void linenumber_width(int width);
00344   int linenumber_width() const;
00345   void linenumber_font(Fl_Font val);
00346   Fl_Font linenumber_font() const;
00347   void linenumber_size(Fl_Fontsize val);
00348   Fl_Fontsize linenumber_size() const;
00349   void linenumber_fgcolor(Fl_Color val);
00350   Fl_Color linenumber_fgcolor() const;
00351   void linenumber_bgcolor(Fl_Color val);
00352   Fl_Color linenumber_bgcolor() const;
00353   void linenumber_align(Fl_Align val);
00354   Fl_Align linenumber_align() const;
00355   void linenumber_format(const char* val);
00356   const char* linenumber_format() const;
00357 
00358 protected:
00359   // Most (all?) of this stuff should only be called from resize() or
00360   // draw().
00361   // Anything with "vline" indicates thats it deals with currently
00362   // visible lines.
00363   
00364   virtual void draw();
00365   void draw_text(int X, int Y, int W, int H);
00366   void draw_range(int start, int end);
00367   void draw_cursor(int, int);
00368   
00369   void draw_string(int style, int x, int y, int toX, const char *string,
00370                    int nChars) const;
00371   
00372   void draw_vline(int visLineNum, int leftClip, int rightClip,
00373                   int leftCharIndex, int rightCharIndex);
00374   
00375   int find_x(const char *s, int len, int style, int x) const;
00376   
00377   enum { 
00378     DRAW_LINE, 
00379     FIND_INDEX,
00380     FIND_INDEX_FROM_ZERO,
00381     GET_WIDTH 
00382   };
00383   
00384   int handle_vline(int mode, 
00385                    int lineStart, int lineLen, int leftChar, int rightChar,
00386                    int topClip, int bottomClip,
00387                    int leftClip, int rightClip) const;
00388   
00389   void draw_line_numbers(bool clearAll);
00390   
00391   void clear_rect(int style, int x, int y, int width, int height) const;
00392   void display_insert();
00393   
00394   void offset_line_starts(int newTopLineNum);
00395   
00396   void calc_line_starts(int startLine, int endLine);
00397   
00398   void update_line_starts(int pos, int charsInserted, int charsDeleted,
00399                           int linesInserted, int linesDeleted, int *scrolled);
00400   
00401   void calc_last_char();
00402   
00403   int position_to_line( int pos, int* lineNum ) const;
00404   double string_width(const char* string, int length, int style) const;
00405   
00406   static void scroll_timer_cb(void*);
00407   
00408   static void buffer_predelete_cb(int pos, int nDeleted, void* cbArg);
00409   static void buffer_modified_cb(int pos, int nInserted, int nDeleted,
00410                                  int nRestyled, const char* deletedText,
00411                                  void* cbArg);
00412   
00413   static void h_scrollbar_cb(Fl_Scrollbar* w, Fl_Text_Display* d);
00414   static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display* d);
00415   void update_v_scrollbar();
00416   void update_h_scrollbar();
00417   int measure_vline(int visLineNum) const;
00418   int longest_vline() const;
00419   int empty_vlines() const;
00420   int vline_length(int visLineNum) const;
00421   int xy_to_position(int x, int y, int PosType = CHARACTER_POS) const;
00422   
00423   void xy_to_rowcol(int x, int y, int* row, int* column,
00424                     int PosType = CHARACTER_POS) const;
00425   void maintain_absolute_top_line_number(int state);
00426   int get_absolute_top_line_number() const;
00427   void absolute_top_line_number(int oldFirstChar);
00428   int maintaining_absolute_top_line_number() const;
00429   void reset_absolute_top_line_number();
00430   int position_to_linecol(int pos, int* lineNum, int* column) const;
00431   int scroll_(int topLineNum, int horizOffset);
00432   
00433   void extend_range_for_styles(int* start, int* end);
00434   
00435   void find_wrap_range(const char *deletedText, int pos, int nInserted,
00436                        int nDeleted, int *modRangeStart, int *modRangeEnd,
00437                        int *linesInserted, int *linesDeleted);
00438   void measure_deleted_lines(int pos, int nDeleted);
00439   void wrapped_line_counter(Fl_Text_Buffer *buf, int startPos, int maxPos,
00440                             int maxLines, bool startPosIsLineStart,
00441                             int styleBufOffset, int *retPos, int *retLines,
00442                             int *retLineStart, int *retLineEnd,
00443                             bool countLastLineMissingNewLine = true) const;
00444   void find_line_end(int pos, bool start_pos_is_line_start, int *lineEnd,
00445                      int *nextLineStart) const;
00446   double measure_proportional_character(const char *s, int colNum, int pos) const;
00447   int wrap_uses_character(int lineEndPos) const;
00448   
00449   int damage_range1_start, damage_range1_end;
00450   int damage_range2_start, damage_range2_end;
00451   int mCursorPos;
00452   int mCursorOn;
00453   int mCursorOldY;              /* Y pos. of cursor for blanking */
00454   int mCursorToHint;            /* Tells the buffer modified callback
00455                                  where to move the cursor, to reduce
00456                                  the number of redraw calls */
00457   int mCursorStyle;             /* One of enum cursorStyles above */
00458   int mCursorPreferredXPos;     /* Pixel position for vert. cursor movement */
00459   int mNVisibleLines;           /* # of visible (displayed) lines */
00460   int mNBufferLines;            /* # of newlines in the buffer */
00461   Fl_Text_Buffer* mBuffer;      /* Contains text to be displayed */
00462   Fl_Text_Buffer* mStyleBuffer; /* Optional parallel buffer containing
00463                                  color and font information */
00464   int mFirstChar, mLastChar;    /* Buffer positions of first and last
00465                                  displayed character (lastChar points
00466                                  either to a newline or one character
00467                                  beyond the end of the buffer) */
00468   int mContinuousWrap;          /* Wrap long lines when displaying */
00469   int mWrapMarginPix;           /* Margin in # of pixels for
00470                                  wrapping in continuousWrap mode */
00471   int* mLineStarts;
00472   int mTopLineNum;              /* Line number of top displayed line
00473                                  of file (first line of file is 1) */
00474   int mAbsTopLineNum;           /* In continuous wrap mode, the line
00475                                   number of the top line if the text
00476                                   were not wrapped (note that this is
00477                                   only maintained as needed). */
00478   int mNeedAbsTopLineNum;       /* Externally settable flag to continue
00479                                  maintaining absTopLineNum even if
00480                                  it isn't needed for line # display */
00481   int mHorizOffset;             /* Horizontal scroll pos. in pixels */
00482   int mTopLineNumHint;          /* Line number of top displayed line
00483                                  of file (first line of file is 1) */
00484   int mHorizOffsetHint;         /* Horizontal scroll pos. in pixels */
00485   int mNStyles;                 /* Number of entries in styleTable */
00486   const Style_Table_Entry *mStyleTable; /* Table of fonts and colors for
00487                                          coloring/syntax-highlighting */
00488   char mUnfinishedStyle;        /* Style buffer entry which triggers
00489                                  on-the-fly reparsing of region */
00490   Unfinished_Style_Cb mUnfinishedHighlightCB; /* Callback to parse "unfinished" */
00491   /* regions */
00492   void* mHighlightCBArg;        /* Arg to unfinishedHighlightCB */
00493   
00494   int mMaxsize;
00495   
00496   int mSuppressResync;          /* Suppress resynchronization of line
00497                                  starts during buffer updates */
00498   int mNLinesDeleted;           /* Number of lines deleted during
00499                                  buffer modification (only used
00500                                  when resynchronization is suppressed) */
00501   int mModifyingTabDistance;    /* Whether tab distance is being
00502                                  modified */
00503   
00504   mutable double mColumnScale; /* Width in pixels of an average character. This
00505                                  value is calculated as needed (lazy eval); it 
00506                                  needs to be mutable so that it can be calculated
00507                                  within a method marked as "const" */
00508   
00509   Fl_Color mCursor_color;
00510   
00511   Fl_Scrollbar* mHScrollBar;
00512   Fl_Scrollbar* mVScrollBar;
00513   int scrollbar_width_;
00514   Fl_Align scrollbar_align_;
00515   int dragPos, dragType, dragging;
00516   int display_insert_position_hint;
00517   struct { int x, y, w, h; } text_area;
00518   
00519   int shortcut_;
00520   
00521   Fl_Font textfont_;
00522   Fl_Fontsize textsize_;
00523   Fl_Color textcolor_;
00524   
00525   // Line number margin and width
00526   int mLineNumLeft, mLineNumWidth;
00527 
00528   // Line number font/colors
00529 #if FLTK_ABI_VERSION >= 10303
00530   Fl_Font     linenumber_font_;
00531   Fl_Fontsize linenumber_size_;
00532   Fl_Color    linenumber_fgcolor_;
00533   Fl_Color    linenumber_bgcolor_;
00534   Fl_Align    linenumber_align_;
00535   const char* linenumber_format_;
00536 #endif
00537 };
00538 
00539 #endif
00540 
00541 //
00542 // End of "$Id$".
00543 //
  • © 1998-2016 by Bill Spitzak and others.     FLTK

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.