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

Fl_Text_Buffer.h

00001 /*
00002  * $Id: Fl_Text_Buffer.h,v 1.11 2003/06/15 20:05:55 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_BUFFER_H_
00023 #define _FL_TEXT_BUFFER_H_
00024 
00025 /* Maximum length in characters of a tab or control character expansion
00026  of a single buffer character */
00027 #define FL_TEXT_MAX_EXP_CHAR_LEN 20
00028 
00029 #include <efltk/Fl_Export.h>
00030 #include <efltk/Fl_Ptr_Stack.h>
00031 #include <efltk/Fl_Buffer.h>
00032 
00033 typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
00034    int nRestyled, const char* deletedText,
00035    void* cbArg);
00036 typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
00037 
00039 class FL_API Fl_Text_Selection {
00040    friend class Fl_Text_Buffer;
00041 
00042 public:
00043    void set(int start, int end);
00044    void set_rectangular(int start, int end, int rectStart, int rectEnd);
00045    void update(int pos, int nDeleted, int nInserted);
00046    char rectangular() { return mRectangular; }
00047    int start() { return mStart; }
00048    int end() { return mEnd; }
00049    int rect_start() { return mRectStart; }
00050    int rect_end() { return mRectEnd; }
00051    char selected() { return mSelected; }
00052    void selected(char b) { mSelected = b; }
00053    int includes(int pos, int lineStartPos, int dispIndex);
00054    int position(int* start, int* end);
00055    int position(int* start, int* end, int* isRect, int* rectStart, int* rectEnd);
00056 
00057 
00058 protected:
00059    char mSelected;
00060    char mRectangular;
00061    int mStart;
00062    int mEnd;
00063    int mRectStart;
00064    int mRectEnd;
00065 };
00066 
00067 typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
00068    int nRestyled, const char* deletedText,
00069    void* cbArg);
00070 typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
00071 
00072 //Forward declare...
00073 class Fl_UndoNode_Stack;
00074 
00076 class FL_API Fl_Text_Buffer {
00077 public:
00078    Fl_Text_Buffer(int requestedSize = 0);
00079    ~Fl_Text_Buffer();
00080 
00081    char *Fl_Text_Buffer::static_buffer();
00082 
00083     // Undo stack size: (default 50)
00084    int undo_size();
00085    void undo_size(int newsize);
00086 
00087     // Returns insert position
00088    int undo();
00089    void add_undo(const char *str, int pos, int len, bool inserted, bool replaced);
00090 
00091    int length() { return mLength; }
00092    const char* text();
00093    void text(const char* text);
00094    const char* text_range(int start, int end);
00095    void text_range(Fl_String_Buffer& outStr, int start, int end);
00096    char character(int pos);
00097    const char* text_in_rectangle(int start, int end, int rectStart, int rectEnd);
00098 
00099    void insert(int pos, const char* text, int text_len=-1);
00100    void append(const char* text, int text_len=-1) { insert(length(), text, text_len); }
00101    void remove(int start, int end);
00102    void replace(int start, int end, const char *text, int text_len=-1);
00103    void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
00104    int insertfile(const char *file, int pos, int buflen = 128*1024);
00105    int appendfile(const char *file, int buflen = 128*1024)
00106    { return insertfile(file, length(), buflen); }
00107    int loadfile(const char *file, int buflen = 128*1024)
00108    { select(0, length()); remove_selection(); return appendfile(file, buflen); }
00109    int outputfile(const char *file, int start, int end, int buflen = 128*1024);
00110    int savefile(const char *file, int buflen = 128*1024)
00111    { return outputfile(file, 0, length(), buflen); }
00112 
00113    void insert_column(int column, int startPos, const char* text,
00114       int* charsInserted, int* charsDeleted);
00115 
00116    void replace_rectangular(int start, int end, int rectStart, int rectEnd,
00117       const char* text);
00118 
00119    void overlay_rectangular(int startPos, int rectStart, int rectEnd,
00120       const char* text, int* charsInserted,
00121       int* charsDeleted);
00122 
00123    void remove_rectangular(int start, int end, int rectStart, int rectEnd);
00124    void clear_rectangular(int start, int end, int rectStart, int rectEnd);
00125    int tab_distance() { return mTabDist; }
00126    void tab_distance(int tabDist);
00127    void select(int start, int end);
00128    int selected() { return mPrimary.selected(); }
00129    void unselect();
00130    void select_rectangular(int start, int end, int rectStart, int rectEnd);
00131    int selection_position(int* start, int* end);
00132 
00133    int selection_position(int* start, int* end, int* isRect, int* rectStart,
00134       int* rectEnd);
00135 
00136    const char* selection_text();
00137    void remove_selection();
00138    void replace_selection(const char* text);
00139    void secondary_select(int start, int end);
00140    void secondary_unselect();
00141 
00142    void secondary_select_rectangular(int start, int end, int rectStart,
00143       int rectEnd);
00144 
00145    int secondary_selection_position(int* start, int* end, int* isRect,
00146       int* rectStart, int* rectEnd);
00147 
00148    const char* secondary_selection_text();
00149    void remove_secondary_selection();
00150    void replace_secondary_selection(const char* text);
00151    void highlight(int start, int end);
00152    void unhighlight();
00153    void highlight_rectangular(int start, int end, int rectStart, int rectEnd);
00154 
00155    int highlight_position(int* start, int* end, int* isRect, int* rectStart,
00156       int* rectEnd);
00157 
00158    const char* highlight_text();
00159 
00160    void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
00161    void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg);
00162    void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); }
00163 
00164    void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB, void* cbArg); 
00165    void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg); 
00166    void call_predelete_callbacks() { call_predelete_callbacks(0, 0); } 
00167 
00168    const char* line_text(int pos);
00169    int line_start(int pos);
00170    int line_end(int pos);
00171    int word_start(int pos);
00172    int word_end(int pos);
00173    int expand_character(int pos, int indent, char *outStr);
00174 
00175    static int expand_character(char c, int indent, char* outStr, int tabDist);
00176 
00177    static int character_width(char c, int indent, int tabDist);
00178    int count_displayed_characters(int lineStartPos, int targetPos);
00179    int skip_displayed_characters(int lineStartPos, int nChars);
00180    int count_lines(int startPos, int endPos);
00181    int skip_lines(int startPos, int nLines);
00182    int rewind_lines(int startPos, int nLines);
00183    int findchar_forward(int startPos, char searchChar, int* foundPos);
00184    int findchar_backward(int startPos, char searchChar, int* foundPos);
00185    int findchars_forward(int startPos, const char* searchChars, int* foundPos);
00186    int findchars_backward(int startPos, const char* searchChars, int* foundPos);
00187 
00188    int search_forward(int startPos, const char* searchString, int* foundPos,
00189       int matchCase = 0);
00190 
00191    int search_backward(int startPos, const char* searchString, int* foundPos,
00192       int matchCase = 0);
00193 
00194    Fl_Text_Selection* primary_selection() { return &mPrimary; }
00195    Fl_Text_Selection* secondary_selection() { return &mSecondary; }
00196    Fl_Text_Selection* highlight_selection() { return &mHighlight; }
00197 
00198 protected:
00199    void call_modify_callbacks(int pos, int nDeleted, int nInserted,
00200       int nRestyled, const char* deletedText);
00201 
00202    void call_predelete_callbacks(int pos, int nDeleted);
00203 
00204    int insert_(int pos, const char* text, int text_len);
00205    void remove_(int start, int end);
00206 
00207    void remove_rectangular_(int start, int end, int rectStart, int rectEnd,
00208                             int* replaceLen, int* endPos);
00209 
00210    void insert_column_( int column, int startPos, const char* insText,
00211                         int* nDeleted, int* nInserted, int* endPos);
00212 
00213    void overlay_rectangular_(int startPos, int rectStart, int rectEnd,
00214                              const char* insText, int* nDeleted,
00215                              int* nInserted, int* endPos);
00216 
00217    void redisplay_selection(Fl_Text_Selection* oldSelection,
00218                             Fl_Text_Selection* newSelection);
00219 
00220    void move_gap(int pos);
00221    void reallocate_with_gap(int newGapStart, int newGapLen);
00222    const char* selection_text_(Fl_Text_Selection* sel);
00223    void remove_selection_(Fl_Text_Selection* sel);
00224    void replace_selection_(Fl_Text_Selection* sel, const char* text);
00225 
00226    void rectangular_selection_boundaries(int lineStartPos, int rectStart,
00227                                          int rectEnd, int* selStart,
00228                                          int* selEnd);
00229 
00230    void update_selections(int pos, int nDeleted, int nInserted);
00231 
00232    Fl_UndoNode_Stack *undo_stack;
00233 
00234    Fl_Text_Selection mPrimary; /* highlighted areas */
00235    Fl_Text_Selection mSecondary;
00236    Fl_Text_Selection mHighlight;
00237    int mLength;                /* length of the text in the buffer (the length
00238                                    of the buffer itself must be calculated:
00239                                    gapEnd - gapStart + length) */
00240    char* mBuf;                 /* allocated memory where the text is stored */
00241    int mGapStart;              /* points to the first character of the gap */
00242    int mGapEnd;                /* points to the first char after the gap */
00243     // The hardware tab distance used by all displays for this buffer,
00244     // and used in computing offsets for rectangular selection operations.
00245    int mTabDist;               /* equiv. number of characters in a tab */
00246    int mUseTabs;               /* True if buffer routines are allowed to use
00247                                    tabs for padding in rectangular operations */
00248    int mNModifyProcs;          /* number of modify-redisplay procs attached */
00249    Fl_Text_Modify_Cb*          /* procedures to call when buffer is */
00250       mNodifyProcs;               /* modified to redisplay contents */
00251    void** mCbArgs;             /* caller arguments for modifyProcs above */
00252 
00253    int mNPredeleteProcs;       /* number of pre-delete procs attached */ 
00254    Fl_Text_Predelete_Cb*       /* procedure to call before text is deleted */ 
00255       mPredeleteProcs;       /* from the buffer; at most one is supported. */ 
00256    void **mPredeleteCbArgs;    /* caller argument for pre-delete proc above */ 
00257 
00258    int mCursorPosHint;         /* hint for reasonable cursor position after
00259                                    a buffer modification operation */
00260 };
00261 
00262 #endif

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