Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Fl_Text_Display.h

00001 /*
00002  * $Id: Fl_Text_Display.h,v 1.18 2003/06/16 19:42:02 laza2000 Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Mikko Lahteenmaki
00016  * Email  : mikko@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
00019  *
00020  */
00021 
00022 #ifndef _FL_TEXT_DISPLAY_H_
00023 #define _FL_TEXT_DISPLAY_H_
00024 
00025 #include <efltk/fl_draw.h>
00026 #include <efltk/Fl_Group.h>
00027 #include <efltk/Fl_Widget.h>
00028 #include <efltk/Fl_Scrollbar.h>
00029 #include <efltk/Fl_Text_Buffer.h>
00030 #include <efltk/Fl_Int_List.h>
00031 
00033 class FL_API Fl_Text_Display: public Fl_Group {
00034 public:
00035     enum {
00036         NORMAL_CURSOR, CARET_CURSOR, DIM_CURSOR,
00037         BLOCK_CURSOR, HEAVY_CURSOR
00038     };
00039 
00040     enum {
00041         CURSOR_POS,
00042         CHARACTER_POS
00043     };
00044 
00045     // drag types- they match Fl::event_clicks() so that single clicking to
00046     // start a collection selects by character, double clicking selects by
00047     // word and triple clicking selects by line.
00048     enum {
00049         DRAG_CHAR = 0, 
00050         DRAG_WORD = 1, 
00051         DRAG_LINE = 2
00052     };
00053     friend void fl_text_drag_me(int pos, Fl_Text_Display* d);
00054 
00055     typedef void (*Unfinished_Style_Cb)(Fl_Text_Display *disp, int pos, void *arg);
00056 
00057     // style attributes
00058     enum {
00059         ATTR_NONE = 0,
00060         ATTR_UNDERLINE = 1,
00061         ATTR_HIDDEN = 2, //Not implement
00062         ATTR_IMAGE = 3 
00063     };
00064 
00065     struct FL_API Style_Table_Entry {
00066         Fl_Color color;
00067         Fl_Font font;
00068         int size;
00069         unsigned attr;
00070         Fl_Image *image;
00071     };
00072 
00074     Fl_Text_Display(int X, int Y, int W, int H, const char *l = 0);
00075 
00077     Fl_Text_Display(const char* l = 0,int layout_size=30,Fl_Align layout_al=FL_ALIGN_TOP,int label_w=-1);
00078 
00080     ~Fl_Text_Display();
00081 
00082     virtual void layout();
00083     virtual void draw();
00084 
00085     virtual int handle(int e);
00086     void buffer(Fl_Text_Buffer* buf);
00087     void buffer(Fl_Text_Buffer& buf) { buffer(&buf); }
00088 
00089     Fl_Text_Buffer* buffer() { return mBuffer; }
00090     Fl_Text_Buffer* style_buffer() { return mStyleBuffer; }
00091 
00092     void redisplay_range(int start, int end);
00093     void scroll(int topLineNum, int horizOffset);
00094     void insert(const char* text);
00095     void overstrike(const char* text);
00096     void insert_position(int newPos);
00097     int insert_position() { return mCursorPos; }
00098     int in_selection(int x, int y);
00099     void show_insert_position();
00100     int move_right();
00101     int move_left();
00102     int move_up(int lines=1);
00103     int move_down(int lines=1);
00104 
00105     int count_lines(int start, int end, bool start_pos_is_line_start);
00106     int line_start(int pos);
00107     int line_end(int pos, bool start_pos_is_line_start);
00108     int skip_lines(int startPos, int nLines, bool startPosIsLineStart);
00109     int rewind_lines(int startPos, int nLines);
00110 
00111     void next_word(void);
00112     void previous_word(void);
00113     
00114     void show_cursor(int b = 1);
00115     void hide_cursor() { show_cursor(0); }
00116     void cursor_style(int style);
00117 
00118     Fl_Color cursor_color() const { return mCursorColor; }
00119     void cursor_color(Fl_Color c) { mCursorColor = c; }
00120 
00121     int word_start(int pos) { return buffer()->word_start(pos); }
00122     int word_end(int pos) { return buffer()->word_end(pos); }
00123 
00124     void highlight_data(Fl_Text_Buffer *styleBuffer,
00125         Style_Table_Entry *styleTable,
00126         int nStyles, char unfinishedStyle,
00127         Unfinished_Style_Cb unfinishedHighlightCB,
00128         void *cbArg);
00129 
00130     int position_style(int lineStartPos, int lineLen, int lineIndex,
00131         int dispIndex);
00132 
00133     int wrapped_column(int row, int column);
00134     int wrapped_row(int row);
00135 
00136     // Wrap mode, wrap=[enable/disable]
00137     // wrap_margin=0 = continuos wrap. or character to wrap.
00138     void wrap_mode(int wrap, int wrap_margin);
00139 
00140     // Sets line number area, width=0 = disable...
00141     void set_linenumber_area(int left, int width);
00142 
00143     // Calculates fontmetrics
00144     void set_font();
00145 
00146 protected:
00147     void do_scroll(int topLineNum, int horizOffset);
00148 
00149     // Most (all?) of this stuff should only be called from layout() or
00150     // draw().
00151     // Anything with "vline" indicates thats it deals with currently
00152     // visible lines.
00153 
00154     void draw_text(int X, int Y, int W, int H);
00155     void draw_range(int start, int end);
00156     
00157     void clear_cursor();
00158     void draw_cursor();
00159     void draw_cursor(int pos);
00160 
00161     void draw_string(int style, int x, int y, int toX, const char *string, int nChars);
00162     void draw_line_numbers();
00163     void draw_vline(int visLineNum, int leftClip, int rightClip, int leftCharIndex, int rightCharIndex);
00164 
00165     void clear_rect(int style, int x, int y, int width, int height);
00166     void display_insert();
00167 
00168     void offset_line_starts(int newTopLineNum);
00169     void calc_line_starts(int startLine, int endLine);
00170     void update_line_starts(int pos, int charsInserted, int charsDeleted,
00171         int linesInserted, int linesDeleted, int *scrolled);
00172 
00173     void calc_last_char();
00174     void calc_longest_vline();
00175 
00176     int find_next_char(int pos);
00177     int find_prev_char(int pos);
00178 
00179     int position_to_line( int pos, int* lineNum );
00180     int string_width(const char* string, int length, int style);
00181 
00182     static void buffer_predelete_cb(int pos, int nDeleted, void* cbArg);
00183 
00184     static void buffer_modified_cb( int pos, int nInserted, int nDeleted,
00185                                     int nRestyled, const char* deletedText,
00186                                     void* cbArg);
00187 
00188     static void h_scrollbar_cb(Fl_Scrollbar* w, Fl_Text_Display* d);
00189     static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display* d);
00190     void update_v_scrollbar();
00191     void update_h_scrollbar();
00192 
00193     int measure_vline(int visLineNum);
00194     int empty_vlines();
00195     int vline_length(int visLineNum);
00196     int xy_to_position(int x, int y, int PosType = CHARACTER_POS);
00197 
00198     void xy_to_rowcol(int x, int y, int* row, int* column, int PosType = CHARACTER_POS);
00199 
00200     int position_to_xy(int pos, int* x, int* y);
00201 
00202     void maintain_absolute_top_line_number(int state);
00203     int get_absolute_top_line_number();
00204     void absolute_top_line_number(int oldFirstChar);
00205     int maintaining_absolute_top_line_number();
00206     void reset_absolute_top_line_number();
00207 
00208     int position_to_linecol(int pos, int* lineNum, int* column);
00209 
00210     void extend_range_for_styles(int* start, int* end);
00211 
00212     void find_wrap_range(const char *deletedText, int pos, int nInserted,
00213         int nDeleted, int *modRangeStart, int *modRangeEnd,
00214         int *linesInserted, int *linesDeleted);
00215     void measure_deleted_lines(int pos, int nDeleted);
00216     void wrapped_line_counter(Fl_Text_Buffer *buf, int startPos, int maxPos,
00217                             int maxLines, bool startPosIsLineStart,
00218                             int styleBufOffset, int *retPos, int *retLines,
00219                             int *retLineStart, int *retLineEnd,
00220                             bool countLastLineMissingNewLine = true);
00221     void find_line_end(int pos, bool start_pos_is_line_start, int *lineEnd, int *nextLineStart);
00222     int measure_proportional_character(char c, int colNum, int pos);
00223     int wrap_uses_character(int lineEndPos);
00224     int range_touches_selection(Fl_Text_Selection *sel, int rangeStart,
00225         int rangeEnd);
00226 
00227     int damage_range1_start, damage_range1_end;
00228     int damage_range2_start, damage_range2_end;
00229 
00230     Fl_Color mCursorColor;
00231     int mCursorPos, mCursorPosOld;
00232     int mCursorOn;
00233     int mCursorToHint;          /* Tells the buffer modified callback
00234                                    where to move the cursor, to reduce
00235                                    the number of redraw calls */
00236     int mCursorStyle;           /* One of enum cursorStyles above */
00237     int mCursorPreferredCol;    /* Column for vert. cursor movement */
00238     int mNVisibleLines;         /* # of visible (displayed) lines */
00239     int mNBufferLines;          /* # of newlines in the buffer */
00240     Fl_Text_Buffer* mBuffer;    /* Contains text to be displayed */
00241     Fl_Text_Buffer* mStyleBuffer; /* Optional parallel buffer containing
00242                                      color and font information */
00243     int mFirstChar, mLastChar;  /* Buffer positions of first and last
00244                                    displayed character (lastChar points
00245                                    either to a newline or one character
00246                                    beyond the end of the buffer) */
00247     int mContinuousWrap;        /* Wrap long lines when displaying */
00248     int mWrapMargin;            /* Margin in # of char positions for
00249                                    wrapping in continuousWrap mode */
00250     Fl_Int_List mLineStarts;
00251     int mTopLineNum;            /* Line number of top displayed line
00252                                    of file (first line of file is 1) */
00253     int mAbsTopLineNum;         /* In continuous wrap mode, the line
00254                                    number of the top line if the text
00255                                    were not wrapped (note that this is
00256                                    only maintained as needed). */
00257     int mNeedAbsTopLineNum;     /* Externally settable flag to continue
00258                                    maintaining absTopLineNum even if
00259                                    it isn't needed for line # display */
00260 
00261     int mHorizOffset;           /* Horizontal scroll pos. in pixels */
00262     int mVisibility;            /* Window visibility (see XVisibility event) */
00263     int mNStyles;               /* Number of entries in styleTable */
00264     Style_Table_Entry *mStyleTable; /* Table of fonts and colors for
00265                                        coloring/syntax-highlighting */
00266     char mUnfinishedStyle;      /* Style buffer entry which triggers
00267                                    on-the-fly reparsing of region */
00268     Unfinished_Style_Cb mUnfinishedHighlightCB; /* Callback to parse "unfinished"
00269                                                    regions */
00270     void* mHighlightCBArg;      /* Arg to unfinishedHighlightCB */
00271 
00272     int mMaxsize;
00273 
00274     int mFixedFontWidth;        /* Font width if all current fonts are
00275                                    fixed and match in width, else -1 */
00276 
00277     int mSuppressResync;        /* Suppress resynchronization of line
00278                                    starts during buffer updates */
00279     int mNLinesDeleted;         /* Number of lines deleted during
00280                                    buffer modification (only used
00281                                           when resynchronization is suppressed) */
00282     int mModifyingTabDistance;  /* Whether tab distance is being
00283                                    modified */
00284 
00285     int mMaxFontBound, mMinFontBound; //Min and Max bound of font (non-styled)
00286 
00287     int mLongestVline; // Longest vline, measured in layout()
00288 
00289     Fl_Scrollbar* mHScrollBar;
00290     Fl_Scrollbar* mVScrollBar;
00291     int dragPos, dragType, dragging;
00292     struct area { int x, y, w, h; } text_area;
00293 
00294     int mLineNumLeft, mLineNumWidth;  /* Line number margin and width */
00295     Fl_String_Buffer m_lineBuffer;
00296 
00297     static void fl_scroll_cb(void* v,int X, int Y, int W, int H);
00298     int scrolldx, scrolldy;
00299 
00300 private:
00301     void ctor_init();   
00302 };
00303 
00304 #endif

Generated on Thu Jul 31 15:33:45 2003 for eFLTK by doxygen1.2.15