00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
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     
00046     
00047     
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     
00058     enum {
00059         ATTR_NONE = 0,
00060         ATTR_UNDERLINE = 1,
00061         ATTR_HIDDEN = 2, 
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     
00137     
00138     void wrap_mode(int wrap, int wrap_margin);
00139 
00140     
00141     void set_linenumber_area(int left, int width);
00142 
00143     
00144     void set_font();
00145 
00146 protected:
00147     void do_scroll(int topLineNum, int horizOffset);
00148 
00149     
00150     
00151     
00152     
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;          
00234 
00235 
00236     int mCursorStyle;           
00237     int mCursorPreferredCol;    
00238     int mNVisibleLines;         
00239     int mNBufferLines;          
00240     Fl_Text_Buffer* mBuffer;    
00241     Fl_Text_Buffer* mStyleBuffer; 
00242 
00243     int mFirstChar, mLastChar;  
00244 
00245 
00246 
00247     int mContinuousWrap;        
00248     int mWrapMargin;            
00249 
00250     Fl_Int_List mLineStarts;
00251     int mTopLineNum;            
00252 
00253     int mAbsTopLineNum;         
00254 
00255 
00256 
00257     int mNeedAbsTopLineNum;     
00258 
00259 
00260 
00261     int mHorizOffset;           
00262     int mVisibility;            
00263     int mNStyles;               
00264     Style_Table_Entry *mStyleTable; 
00265 
00266     char mUnfinishedStyle;      
00267 
00268     Unfinished_Style_Cb mUnfinishedHighlightCB; 
00269 
00270     void* mHighlightCBArg;      
00271 
00272     int mMaxsize;
00273 
00274     int mFixedFontWidth;        
00275 
00276 
00277     int mSuppressResync;        
00278 
00279     int mNLinesDeleted;         
00280 
00281 
00282     int mModifyingTabDistance;  
00283 
00284 
00285     int mMaxFontBound, mMinFontBound; 
00286 
00287     int mLongestVline; 
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;  
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