diff options
| author | Fabien Costantini <fabien@onepost.net> | 2008-09-15 16:39:05 +0000 |
|---|---|---|
| committer | Fabien Costantini <fabien@onepost.net> | 2008-09-15 16:39:05 +0000 |
| commit | b8955a9ced0270ec7aa7052e6e0852cae140ca27 (patch) | |
| tree | 2432866aeda02a7c0cfa93e04a2d0c3b802a6033 | |
| parent | 09f3094aef152ece5bf802983d54f1642d803e0d (diff) | |
Doxygen documentation WP11 Done!
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6255 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | FL/Fl_Spinner.H | 49 | ||||
| -rw-r--r-- | FL/Fl_Text_Buffer.H | 52 | ||||
| -rw-r--r-- | FL/Fl_Text_Display.H | 38 | ||||
| -rw-r--r-- | FL/Fl_Text_Editor.H | 22 | ||||
| -rw-r--r-- | FL/Fl_Tiled_Image.H | 10 | ||||
| -rw-r--r-- | FL/Fl_Toggle_Button.H | 14 | ||||
| -rw-r--r-- | FL/Fl_Tooltip.H | 34 | ||||
| -rw-r--r-- | FL/Fl_Wizard.H | 11 | ||||
| -rw-r--r-- | documentation/todo_filelist_doc.txt | 18 | ||||
| -rw-r--r-- | src/Fl_Text_Buffer.cxx | 2071 | ||||
| -rw-r--r-- | src/Fl_Text_Display.cxx | 636 | ||||
| -rw-r--r-- | src/Fl_Text_Editor.cxx | 51 | ||||
| -rw-r--r-- | src/Fl_Tiled_Image.cxx | 24 | ||||
| -rw-r--r-- | src/Fl_Tooltip.cxx | 48 | ||||
| -rw-r--r-- | src/Fl_Wizard.cxx | 55 |
15 files changed, 1708 insertions, 1425 deletions
diff --git a/FL/Fl_Spinner.H b/FL/Fl_Spinner.H index 3ff59affb..3d65dfebc 100644 --- a/FL/Fl_Spinner.H +++ b/FL/Fl_Spinner.H @@ -40,10 +40,11 @@ # include <stdlib.h> -// -// Fl_Spinner widget class... -// - +/** + This widget is a combination of the input + widget and repeat buttons. The user can either type into the + input area or use the buttons to change the value. +*/ class Fl_Spinner : public Fl_Group { double value_; // Current value @@ -114,6 +115,11 @@ class Fl_Spinner : public Fl_Group public: + /** + Creates a new Fl_Spinner widget using the given position, size, + and label string. + <P>Inherited destructor Destroys the widget and any value associated with it. + */ Fl_Spinner(int X, int Y, int W, int H, const char *L = 0) : Fl_Group(X, Y, W, H, L), input_(X, Y, W - H / 2 - 2, H), @@ -140,7 +146,9 @@ class Fl_Spinner : public Fl_Group down_button_.callback((Fl_Callback *)sb_cb, this); } + /** Sets or returns the format string for the value. */ const char *format() { return (format_); } + /** Sets or returns the format string for the value. */ void format(const char *f) { format_ = f; update(); } int handle(int event) { @@ -163,13 +171,19 @@ class Fl_Spinner : public Fl_Group return Fl_Group::handle(event); } - // Speling mistaks retained for source compatibility... + /** Speling mistakes retained for source compatibility \deprecated */ double maxinum() const { return (maximum_); } + /** Sets or returns the maximum value of the widget. */ double maximum() const { return (maximum_); } + /** Sets or returns the maximum value of the widget. */ void maximum(double m) { maximum_ = m; } + /** Speling mistakes retained for source compatibility \deprecated */ double mininum() const { return (minimum_); } + /** Sets or returns the minimum value of the widget. */ double minimum() const { return (minimum_); } + /** Sets or returns the minimum value of the widget. */ void minimum(double m) { minimum_ = m; } + /** Sets the minimum and maximum values for the widget. */ void range(double a, double b) { minimum_ = a; maximum_ = b; } void resize(int X, int Y, int W, int H) { Fl_Group::resize(X,Y,W,H); @@ -179,32 +193,51 @@ class Fl_Spinner : public Fl_Group down_button_.resize(X + W - H / 2 - 2, Y + H - H / 2, H / 2 + 2, H / 2); } + /** + Sets or returns the amount to change the value when the user clicks a button. + Before setting step to a non-integer value, the spinner + type() should be changed to floating point. + */ double step() const { return (step_); } + /** See double Fl_Spinner::step() const */ void step(double s) { step_ = s; if (step_ != (int)step_) input_.type(FL_FLOAT_INPUT); else input_.type(FL_INT_INPUT); update(); } + /** Sets or Gets the color of the text in the input field. */ Fl_Color textcolor() const { return (input_.textcolor()); } + /** Sets or Gets the color of the text in the input field. */ void textcolor(Fl_Color c) { input_.textcolor(c); } + /** Sets or Gets the font of the text in the input field. */ Fl_Font textfont() const { return (input_.textfont()); } + /** Sets or Gets the font of the text in the input field. */ void textfont(Fl_Font f) { input_.textfont(f); } + /** Sets or Gets the size of the text in the input field. */ Fl_Fontsize textsize() const { return (input_.textsize()); } + /** Sets or Gets the size of the text in the input field. */ void textsize(Fl_Fontsize s) { input_.textsize(s); } + /** Sets or returns the numeric representation in the input field. + Valid values are FL_INT_INPUT and FL_FLOAT_INPUT. + The first form also changes the format() template. + Setting a new spinner type via a superclass pointer will not work. + \note type is not a virtual function. + */ uchar type() const { return (input_.type()); } + /** See uchar Fl_Spinner::type() const */ void type(uchar v) { if (v==FL_FLOAT_INPUT) { format("%.*f"); @@ -213,7 +246,13 @@ class Fl_Spinner : public Fl_Group } input_.type(v); } + /** + Sets or returns the current value of the widget. + Before setting value to a non-integer value, the spinner + type() should be changed to floating point. + */ double value() const { return (value_); } + /** See double Fl_Spinner::value() const */ void value(double v) { value_ = v; update(); } }; diff --git a/FL/Fl_Text_Buffer.H b/FL/Fl_Text_Buffer.H index aa4bbf704..5f8e4bd75 100644 --- a/FL/Fl_Text_Buffer.H +++ b/FL/Fl_Text_Buffer.H @@ -48,6 +48,10 @@ class FL_EXPORT Fl_Text_Selection { int end() { return mEnd; } int rect_start() { return mRectStart; } int rect_end() { return mRectEnd; } + /** + Returns a non-zero number if any text has been selected, or 0 + if no text is selected. + */ char selected() { return mSelected; } void selected(char b) { mSelected = b; } int includes(int pos, int lineStartPos, int dispIndex); @@ -69,11 +73,26 @@ typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted, void* cbArg); typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg); +/** + The Fl_Text_Buffer class is used by the Fl_Text_Display + and Fl_Text_Editor to manage complex text data and is based upon the + excellent NEdit text editor engine - see http://www.nedit.org/. +*/ +/** + The Fl_Text_Buffer class is used by the + Fl_Text_Display + and + Fl_Text_Editor + to manage complex text data and is based upon the + excellent NEdit text editor engine - see + http://www.nedit.org/. +*/ class FL_EXPORT Fl_Text_Buffer { public: Fl_Text_Buffer(int requestedSize = 0); ~Fl_Text_Buffer(); + /** Returns the number of characters in the buffer. */ int length() { return mLength; } char* text(); void text(const char* text); @@ -81,6 +100,7 @@ class FL_EXPORT Fl_Text_Buffer { char character(int pos); char* text_in_rectangle(int start, int end, int rectStart, int rectEnd); void insert(int pos, const char* text); + /** Appends the text string to the end of the buffer. */ void append(const char* t) { insert(length(), t); } void remove(int start, int end); void replace(int start, int end, const char *text); @@ -88,11 +108,19 @@ class FL_EXPORT Fl_Text_Buffer { int undo(int *cp=0); void canUndo(char flag=1); int insertfile(const char *file, int pos, int buflen = 128*1024); + /** + Appends the named file to the end of the buffer. Returns 0 on + success, non-zero on error (strerror() contains reason). 1 indicates + open for read failed (no data loaded). 2 indicates error occurred + while reading data (data was partially loaded). + */ int appendfile(const char *file, int buflen = 128*1024) { return insertfile(file, length(), buflen); } + /** Loads a text file into the buffer */ int loadfile(const char *file, int buflen = 128*1024) { select(0, length()); remove_selection(); return appendfile(file, buflen); } int outputfile(const char *file, int start, int end, int buflen = 128*1024); + /** Saves a text file from the current buffer */ int savefile(const char *file, int buflen = 128*1024) { return outputfile(file, 0, length(), buflen); } @@ -108,9 +136,11 @@ class FL_EXPORT Fl_Text_Buffer { void remove_rectangular(int start, int end, int rectStart, int rectEnd); void clear_rectangular(int start, int end, int rectStart, int rectEnd); + /** Gets the tab width. */ int tab_distance() { return mTabDist; } void tab_distance(int tabDist); void select(int start, int end); + /** Returns a non 0 value if text has been selected, 0 otherwise */ int selected() { return mPrimary.selected(); } void unselect(); void select_rectangular(int start, int end, int rectStart, int rectEnd); @@ -123,7 +153,10 @@ class FL_EXPORT Fl_Text_Buffer { void remove_selection(); void replace_selection(const char* text); void secondary_select(int start, int end); + /** Returns a non 0 value if text has been selected in the secondary + text selection, 0 otherwise */ int secondary_selected() { return mSecondary.selected(); } + /** Clears any selection in the secondary text selection object. */ void secondary_unselect(); void secondary_select_rectangular(int start, int end, int rectStart, @@ -137,6 +170,10 @@ class FL_EXPORT Fl_Text_Buffer { void remove_secondary_selection(); void replace_secondary_selection(const char* text); void highlight(int start, int end); + /** + Returns the highlighted text. When you are done with the + text, free it using the free() function. + */ int highlight() { return mHighlight.selected(); } void unhighlight(); void highlight_rectangular(int start, int end, int rectStart, int rectEnd); @@ -149,12 +186,21 @@ class FL_EXPORT Fl_Text_Buffer { void add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg); void remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, void* cbArg); + /** + Calls all modify callbacks that have been registered using + the add_modify_callback() + method. + */ void call_modify_callbacks() { call_modify_callbacks(0, 0, 0, 0, 0); } void add_predelete_callback(Fl_Text_Predelete_Cb bufPredelCB, void* cbArg); void remove_predelete_callback(Fl_Text_Predelete_Cb predelCB, void* cbArg); - void call_predelete_callbacks() { call_predelete_callbacks(0, 0); } + /** + Calls the stored pre-delete callback procedure(s) for this buffer to update + the changed area(s) on the screen and any other listeners. + */ + void call_predelete_callbacks() { call_predelete_callbacks(0, 0); } char* line_text(int pos); int line_start(int pos); @@ -185,9 +231,13 @@ class FL_EXPORT Fl_Text_Buffer { int substitute_null_characters(char* string, int length); void unsubstitute_null_characters(char* string); + /** Returns the current nul substitution character. */ char null_substitution_character() { return mNullSubsChar; } + /** Returns the primary selection. */ Fl_Text_Selection* primary_selection() { return &mPrimary; } + /** Returns the secondary selection. */ Fl_Text_Selection* secondary_selection() { return &mSecondary; } + /** Returns the current highlight selection. */ Fl_Text_Selection* highlight_selection() { return &mHighlight; } protected: diff --git a/FL/Fl_Text_Display.H b/FL/Fl_Text_Display.H index 0c99b1366..f95d6ff81 100644 --- a/FL/Fl_Text_Display.H +++ b/FL/Fl_Text_Display.H @@ -36,6 +36,13 @@ #include "Fl_Scrollbar.H" #include "Fl_Text_Buffer.H" +/** + This is the FLTK text display widget. It allows the user to + view multiple lines of text and supports highlighting and + scrolling. The buffer that is displayed in the widget is managed + by the Fl_Text_Buffer + class. +*/ class FL_EXPORT Fl_Text_Display: public Fl_Group { public: enum { @@ -76,13 +83,22 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group { virtual int handle(int e); void buffer(Fl_Text_Buffer* buf); + /** + Sets or gets the current text buffer associated with the text widget. + Multiple text widgets can be associated with the same text buffer. + */ 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. + */ Fl_Text_Buffer* buffer() { return mBuffer; } void redisplay_range(int start, int end); void scroll(int topLineNum, int horizOffset); void insert(const char* text); void overstrike(const char* text); void insert_position(int newPos); + /** Gets the position of the text insertion cursor for text display */ int insert_position() { return mCursorPos; } int in_selection(int x, int y); void show_insert_position(); @@ -98,15 +114,24 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group { 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); + /** Sets or gets the text cursor color. */ Fl_Color cursor_color() const {return mCursor_color;} + /** Sets or gets the text cursor color. */ void cursor_color(Fl_Color n) {mCursor_color = n;} + /** Sets or gets the width/height of the scrollbars. */ int scrollbar_width() { return scrollbar_width_; } - Fl_Align scrollbar_align() { return scrollbar_align_; } + /** Sets or gets the width/height of the scrollbars. */ void scrollbar_width(int W) { scrollbar_width_ = W; } + /** Gets the scrollbar alignment type */ + Fl_Align scrollbar_align() { return scrollbar_align_; } + /** Sets the scrollbar alignment type */ void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; } + /** Moves the insert position to the beginning of the current word. */ int word_start(int pos) { return buffer()->word_start(pos); } + /** Moves the insert position to the end of the current word. */ int word_end(int pos) { return buffer()->word_end(pos); } @@ -118,15 +143,24 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group { int position_style(int lineStartPos, int lineLen, int lineIndex, int dispIndex); - + /** \todo FIXME : get set methods pointing on shortcut_ + have no effects as shortcut_ is unused in this class and derived! */ 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! */ void shortcut(int s) {shortcut_ = s;} + /** Gets the default font used when drawing text in the widget. */ Fl_Font textfont() const {return textfont_;} + /** Sets the default font used when drawing text in the widget. */ void textfont(Fl_Font s) {textfont_ = s;} + /** Gets the default size of text in the widget. */ Fl_Fontsize textsize() const {return textsize_;} + /** Sets the default size of text in the widget. */ void textsize(Fl_Fontsize s) {textsize_ = s;} + /** Gets the default color of text in the widget. */ Fl_Color textcolor() const {return (Fl_Color)textcolor_;} + /** Sets the default color of text in the widget. */ void textcolor(unsigned n) {textcolor_ = n;} int wrapped_column(int row, int column); diff --git a/FL/Fl_Text_Editor.H b/FL/Fl_Text_Editor.H index 8b1902746..3457acbf7 100644 --- a/FL/Fl_Text_Editor.H +++ b/FL/Fl_Text_Editor.H @@ -36,6 +36,13 @@ // key will match in any state #define FL_TEXT_EDITOR_ANY_STATE (-1L) +/** + This is the FLTK text editor widget. It allows the user to + edit multiple lines of text and supports highlighting and + scrolling. The buffer that is displayed in the widget is managed + by the Fl_Text_Buffer + class. +*/ class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display { public: typedef int (*Key_Func)(int key, Fl_Text_Editor* editor); @@ -50,21 +57,36 @@ class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display { Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0); ~Fl_Text_Editor() { remove_all_key_bindings(); } virtual int handle(int e); + /** + Sets the current insert mode; if non-zero, new text + is inserted before the current cursor position. Otherwise, new + text replaces text at the current cursor position. + */ void insert_mode(int b) { insert_mode_ = b; } + /** + Gets the current insert mode; if non-zero, new text + is inserted before the current cursor position. Otherwise, new + text replaces text at the current cursor position. + */ int insert_mode() { return insert_mode_; } void add_key_binding(int key, int state, Key_Func f, Key_Binding** list); + /** Adds a key of state "state" with the function "function" */ void add_key_binding(int key, int state, Key_Func f) { add_key_binding(key, state, f, &key_bindings); } void remove_key_binding(int key, int state, Key_Binding** list); + /** Removes the key binding associated with the key "key" of state "state". */ void remove_key_binding(int key, int state) { remove_key_binding(key, state, &key_bindings); } void remove_all_key_bindings(Key_Binding** list); + /** Removes all of the key bindings associated with the text editor or list. */ void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); } void add_default_key_bindings(Key_Binding** list); Key_Func bound_key_function(int key, int state, Key_Binding* list); + /** Returns the function associated with a key binding. */ Key_Func bound_key_function(int key, int state) { return bound_key_function(key, state, key_bindings); } + /** Sets the default key function for unassigned keys. */ void default_key_function(Key_Func f) { default_key_function_ = f; } // functions for the built in default bindings diff --git a/FL/Fl_Tiled_Image.H b/FL/Fl_Tiled_Image.H index 72db8212b..8e4bb40bf 100644 --- a/FL/Fl_Tiled_Image.H +++ b/FL/Fl_Tiled_Image.H @@ -31,7 +31,14 @@ # include "Fl_Image.H" -// Tiled image class. +/** + This class supports tiling of images + over a specified area. The source (tile) image is <B>not</B> + copied unless you call the color_average(), + desaturate(), + or inactive() + methods. +*/ class FL_EXPORT Fl_Tiled_Image : public Fl_Image { protected: @@ -49,6 +56,7 @@ class FL_EXPORT Fl_Tiled_Image : public Fl_Image { virtual void desaturate(); virtual void draw(int X, int Y, int W, int H, int cx, int cy); void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); } + /** Gets The image that is shared */ Fl_Image *image() { return image_; } }; diff --git a/FL/Fl_Toggle_Button.H b/FL/Fl_Toggle_Button.H index 755c1cec3..790d7361b 100644 --- a/FL/Fl_Toggle_Button.H +++ b/FL/Fl_Toggle_Button.H @@ -30,8 +30,22 @@ #include "Fl_Button.H" +/** + The toggle button is a push button that needs to be clicked once + to toggle on, and one more time to toggle off. + The Fl_Toggle_Button subclass displays the "on" state by + drawing a pushed-in button.</P> + <P>Buttons generate callbacks when they are clicked by the user. You + control exactly when and how by changing the values for type() + and when(). +*/ class Fl_Toggle_Button : public Fl_Button { public: + /** + Creates a new Fl_Toggle_Button widget using the given + position, size, and label string. + <P>The inherited destructor deletes the toggle button. + */ Fl_Toggle_Button(int X,int Y,int W,int H,const char *l=0) : Fl_Button(X,Y,W,H,l) {type(FL_TOGGLE_BUTTON);} }; diff --git a/FL/Fl_Tooltip.H b/FL/Fl_Tooltip.H index 3e26656d5..13c985efc 100644 --- a/FL/Fl_Tooltip.H +++ b/FL/Fl_Tooltip.H @@ -31,29 +31,55 @@ #include <FL/Fl.H> #include <FL/Fl_Widget.H> +/** + The Fl_Tooltip class provides tooltip support for + all FLTK widgets. +*/ class FL_EXPORT Fl_Tooltip { public: - static float delay() { return delay_; } + /** Gets the tooltip delay. The default delay is 1.0 seconds. */ + static float delay() { return delay_; } + /** Sets the tooltip delay. The default delay is 1.0 seconds. */ static void delay(float f) { delay_ = f; } + /** + Gets or sets the tooltip hover delay, the delay between tooltips. + The default delay is 0.2 seconds. + */ static float hoverdelay() { return hoverdelay_; } + /** + Gets or sets the tooltip hover delay, the delay between tooltips. + The default delay is 0.2 seconds. + */ static void hoverdelay(float f) { hoverdelay_ = f; } + /** Returns non-zero if tooltips are enabled. */ static int enabled() { return enabled_; } + /** Enables tooltips on all widgets (or disables if <i>b</i> is false). */ static void enable(int b = 1) { enabled_ = b;} + /** Same as enable(0), disables tooltips on all widgets. */ static void disable() { enabled_ = 0; } static void (*enter)(Fl_Widget* w); static void enter_area(Fl_Widget* w, int X, int Y, int W, int H, const char* tip); static void (*exit)(Fl_Widget *w); + /** Gets the current widget target */ static Fl_Widget* current() {return widget_;} static void current(Fl_Widget*); + /** Gets the typeface for the tooltip text. */ static Fl_Font font() { return font_; } - static Fl_Fontsize size() { return size_; } + /** Sets the typeface for the tooltip text. */ static void font(Fl_Font i) { font_ = i; } + /** Gets the size of the tooltip text. */ + static Fl_Fontsize size() { return size_; } + /** Sets the size of the tooltip text. */ static void size(Fl_Fontsize s) { size_ = s; } - static void color(unsigned c) { color_ = c; } + /** Gets the background color for tooltips. The default background color is a pale yellow. */ static Fl_Color color() { return (Fl_Color)color_; } - static void textcolor(unsigned c) { textcolor_ = c; } + /** Sets the background color for tooltips. The default background color is a pale yellow. */ + static void color(unsigned c) { color_ = c; } + /** Gets the color of the text in the tooltip. The default is black. */ static Fl_Color textcolor() { return (Fl_Color)textcolor_; } + /** Sets the color of the text in the tooltip. The default is black. */ + static void textcolor(unsigned c) { textcolor_ = c; } // These should not be public, but Fl_Widget::tooltip() needs them... static void enter_(Fl_Widget* w); diff --git a/FL/Fl_Wizard.H b/FL/Fl_Wizard.H index 1a37d3fb4..bec0b82c3 100644 --- a/FL/Fl_Wizard.H +++ b/FL/Fl_Wizard.H @@ -35,10 +35,15 @@ # include <FL/Fl_Group.H> -// -// Fl_Wizard class... -// +/** + This widget is based off the Fl_Tabs + widget, but instead of displaying tabs it only changes "tabs" under + program control. Its primary purpose is to support "wizards" that + step a user through configuration or troubleshooting tasks. + <P>As with Fl_Tabs, wizard panes are composed of child (usually + Fl_Group) widgets. Navigation buttons must be added separately. +*/ class FL_EXPORT Fl_Wizard : public Fl_Group { Fl_Widget *value_; diff --git a/documentation/todo_filelist_doc.txt b/documentation/todo_filelist_doc.txt index fa6afd345..631fd3581 100644 --- a/documentation/todo_filelist_doc.txt +++ b/documentation/todo_filelist_doc.txt @@ -19,7 +19,7 @@ In Progress Work List (add your WP and name here): - WP8 (Fabien) DONE - WP9 (Fabien) DONE - WP10 (Fabien) DONE - - WP11 (Fabien) + - WP11 (Fabien) DONE - WP12 (Albrecht) work in progress - WP13 (Albrecht) work in progress @@ -191,29 +191,13 @@ Fl_Radio_Light_Button.H Fl_Radio_Round_Button.H Fl_Round_Clock.H Fl_Simple_Counter.H -Fl_Spinner.H Fl_Sys_Menu_Bar.H Fl_Sys_Menu_Bar.cxx Fl_Tabs.H Fl_Tabs.cxx -Fl_Text_Buffer.H -Fl_Text_Buffer.cxx -Fl_Text_Display.H -Fl_Text_Display.cxx -Fl_Text_Editor.H -Fl_Text_Editor.cxx -Fl_Tiled_Image.H -Fl_Tiled_Image.cxx -Fl_Toggle_Button.H -Fl_Toggle_Light_Button.H -Fl_Toggle_Round_Button.H -Fl_Tooltip.H -Fl_Tooltip.cxx Fl_Window_fullscreen.cxx Fl_Window_hotspot.cxx Fl_Window_iconize.cxx -Fl_Wizard.H -Fl_Wizard.cxx Fl_XColor.H Fl_abort.cxx Fl_get_key.cxx diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index a4bd5fbd4..a1dfbc7a2 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -37,35 +37,35 @@ #define PREFERRED_GAP_SIZE 1024 /* Initial size for the buffer gap (empty space in the buffer where text might be inserted -if the user is typing sequential chars ) */ +if the user is typing sequential chars) */ -static void histogramCharacters( const char *string, int length, char hist[ 256 ], - int init ); -static void subsChars( char *string, int length, char fromChar, char toChar ); -static char chooseNullSubsChar( char hist[ 256 ] ); -static void insertColInLine( const char *line, char *insLine, int column, int insWidth, +static void histogramCharacters(const char *string, int length, char hist[ 256 ], + int init); +static void subsChars(char *string, int length, char fromChar, char toChar); +static char chooseNullSubsChar(char hist[ 256 ]); +static void insertColInLine(const char *line, char *insLine, int column, int insWidth, int tabDist, int useTabs, char nullSubsChar, char *outStr, int *outLen, - int *endOffset ); -static void deleteRectFromLine( const char *line, int rectStart, int rectEnd, + int *endOffset); +static void deleteRectFromLine(const char *line, int rectStart, int rectEnd, int tabDist, int useTabs, char nullSubsChar, char *outStr, int *outLen, - int *endOffset ); -static void overlayRectInLine( const char *line, char *insLine, int rectStart, + int *endOffset); +static void overlayRectInLine(const char *line, char *insLine, int rectStart, int rectEnd, int tabDist, int useTabs, char nullSubsChar, char *outStr, - int *outLen, int *endOffset ); - -static void addPadding( char *string, int startIndent, int toIndent, - int tabDist, int useTabs, char nullSubsChar, int *charsAdded ); -static char *copyLine( const char* text, int *lineLen ); -static int countLines( const char *string ); -static int textWidth( const char *text, int tabDist, char nullSubsChar ); -static char *realignTabs( const char *text, int origIndent, int newIndent, - int tabDist, int useTabs, char nullSubsChar, int *newLength ); -static char *expandTabs( const char *text, int startIndent, int tabDist, - char nullSubsChar, int *newLen ); -static char *unexpandTabs( char *text, int startIndent, int tabDist, - char nullSubsChar, int *newLen ); -static int max( int i1, int i2 ); -static int min( int i1, int i2 ); + int *outLen, int *endOffset); + +static void addPadding(char *string, int startIndent, int toIndent, + int tabDist, int useTabs, char nullSubsChar, int *charsAdded); +static char *copyLine(const char* text, int *lineLen); +static int countLines(const char *string); +static int textWidth(const char *text, int tabDist, char nullSubsChar); +static char *realignTabs(const char *text, int origIndent, int newIndent, + int tabDist, int useTabs, char nullSubsChar, int *newLength); +static char *expandTabs(const char *text, int startIndent, int tabDist, + char nullSubsChar, int *newLen); +static char *unexpandTabs(char *text, int startIndent, int tabDist, + char nullSubsChar, int *newLen); +static int max(int i1, int i2); +static int min(int i1, int i2); static const char *ControlCodeTable[ 32 ] = { "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", @@ -115,13 +115,14 @@ static void undobuffersize(int n) { } /* -** Create an empty text buffer of a pre-determined size (use this to -** avoid unnecessary re-allocation if you know exactly how much the buffer -** will need to hold + Create an empty text buffer of a pre-determined size (use this to + avoid unnecessary re-allocation if you know exactly how much the buffer + will need to hold */ -Fl_Text_Buffer::Fl_Text_Buffer( int requestedSize ) { +/** Creates a new text buffer of the specified initial size.*/ +Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize) { mLength = 0; - mBuf = (char *)malloc( requestedSize + PREFERRED_GAP_SIZE ); + mBuf = (char *)malloc(requestedSize + PREFERRED_GAP_SIZE); mGapStart = 0; mGapEnd = PREFERRED_GAP_SIZE; mTabDist = 8; @@ -149,40 +150,36 @@ Fl_Text_Buffer::Fl_Text_Buffer( int requestedSize ) { #endif } -/* -** Free a text buffer -*/ +/** Frees a text buffer */ Fl_Text_Buffer::~Fl_Text_Buffer() { - free( mBuf ); - if ( mNModifyProcs != 0 ) { + free(mBuf); + if (mNModifyProcs != 0) { delete[] mNodifyProcs; delete[] mCbArgs; } - if ( mNPredeleteProcs != 0 ) { + if (mNPredeleteProcs != 0) { delete[] mPredeleteProcs; delete[] mPredeleteCbArgs; } } -/* -** Get the entire contents of a text buffer. Memory is allocated to contain -** the returned string, which the caller must free. +/** + Get the entire contents of a text buffer. Memory is allocated to contain + the returned string, which the caller must free. */ char * Fl_Text_Buffer::text() { char *t; - t = (char *)malloc( mLength + 1 ); - memcpy( t, mBuf, mGapStart ); - memcpy( &t[ mGapStart ], &mBuf[ mGapEnd ], - mLength - mGapStart ); + t = (char *)malloc(mLength + 1); + memcpy(t, mBuf, mGapStart); + memcpy(&t[ mGapStart ], &mBuf[ mGapEnd ], + mLength - mGapStart); t[ mLength ] = '\0'; return t; } -/* -** Replace the entire contents of the text buffer -*/ -void Fl_Text_Buffer::text( const char *t ) { +/** Replaces the entire contents of the text buffer */ +void Fl_Text_Buffer::text(const char *t) { int insertedLength, deletedLength; const char *deletedText; @@ -191,104 +188,108 @@ void Fl_Text_Buffer::text( const char *t ) { /* Save information for redisplay, and get rid of the old buffer */ deletedText = text(); deletedLength = mLength; - free( (void *)mBuf ); + free((void *)mBuf); /* Start a new buffer with a gap of PREFERRED_GAP_SIZE in the center */ - insertedLength = strlen( t ); - mBuf = (char *)malloc( insertedLength + PREFERRED_GAP_SIZE ); + insertedLength = strlen(t); + mBuf = (char *)malloc(insertedLength + PREFERRED_GAP_SIZE); mLength = insertedLength; mGapStart = insertedLength / 2; mGapEnd = mGapStart + PREFERRED_GAP_SIZE; - memcpy( mBuf, t, mGapStart ); - memcpy( &mBuf[ mGapEnd ], &t[ mGapStart ], insertedLength - mGapStart ); + memcpy(mBuf, t, mGapStart); + memcpy(&mBuf[ mGapEnd ], &t[ mGapStart ], insertedLength - mGapStart); #ifdef PURIFY -{ int i; for ( i = mGapStart; i < mGapEnd; i++ ) mBuf[ i ] = '.'; } +{ int i; for (i = mGapStart; i < mGapEnd; i++) mBuf[ i ] = '.'; } #endif /* Zero all of the existing selections */ - update_selections( 0, deletedLength, 0 ); + update_selections(0, deletedLength, 0); /* Call the saved display routine(s) to update the screen */ - call_modify_callbacks( 0, deletedLength, insertedLength, 0, deletedText ); - free( (void *)deletedText ); + call_modify_callbacks(0, deletedLength, insertedLength, 0, deletedText); + free((void *)deletedText); } /* -** Return a copy of the text between "start" and "end" character positions -** from text buffer "buf". Positions start at 0, and the range does not -** include the character pointed to by "end" + Return a copy of the text between "start" and "end" character positions + from text buffer "buf". Positions start at 0, and the range does not + include the character pointed to by "end" */ -char * Fl_Text_Buffer::text_range( int start, int end ) { +/** + Returns the text from the range of characters. When you are + done with the text, free it using the free() function. +*/ +char * Fl_Text_Buffer::text_range(int start, int end) { char * s = NULL; int copiedLength, part1Length; /* Make sure start and end are ok, and allocate memory for returned string. If start is bad, return "", if end is bad, adjust it. */ - if ( start < 0 || start > mLength ) { - s = (char *)malloc( 1 ); + if (start < 0 || start > mLength) { + s = (char *)malloc(1); s[ 0 ] = '\0'; return s; } - if ( end < start ) { + if (end < start) { int temp = start; start = end; end = temp; } - if ( end > mLength ) + if (end > mLength) end = mLength; copiedLength = end - start; - s = (char *)malloc( copiedLength + 1 ); + s = (char *)malloc(copiedLength + 1); /* Copy the text from the buffer to the returned string */ - if ( end <= mGapStart ) { - memcpy( s, &mBuf[ start ], copiedLength ); - } else if ( start >= mGapStart ) { - memcpy( s, &mBuf[ start + ( mGapEnd - mGapStart ) ], copiedLength ); + if (end <= mGapStart) { + memcpy(s, &mBuf[ start ], copiedLength); + } else if (start >= mGapStart) { + memcpy(s, &mBuf[ start + (mGapEnd - mGapStart) ], copiedLength); } else { part1Length = mGapStart - start; - memcpy( s, &mBuf[ start ], part1Length ); - memcpy( &s[ part1Length ], &mBuf[ mGapEnd ], copiedLength - part1Length ); + memcpy(s, &mBuf[ start ], part1Length); + memcpy(&s[ part1Length ], &mBuf[ mGapEnd ], copiedLength - part1Length); } s[ copiedLength ] = '\0'; return s; } /* -** Return the character at buffer position "pos". Positions start at 0. + Return the character at buffer position "pos". Positions start at 0. */ -char Fl_Text_Buffer::character( int pos ) { - if ( pos < 0 || pos >= mLength ) +/** Returns the character at the specified position in the buffer.*/ +char Fl_Text_Buffer::character(int pos) { + if (pos < 0 || pos >= mLength) return '\0'; - if ( pos < mGapStart ) + if (pos < mGapStart) return mBuf[ pos ]; else return mBuf[ pos + mGapEnd - mGapStart ]; } -/* -** Insert null-terminated string "text" at position "pos" in "buf" -*/ -void Fl_Text_Buffer::insert( int pos, const char *s ) { +/** Inserts null-terminated string "s" at position "pos". */ +void Fl_Text_Buffer::insert(int pos, const char *s) { int nInserted; /* if pos is not contiguous to existing text, make it */ - if ( pos > mLength ) pos = mLength; - if ( pos < 0 ) pos = 0; + if (pos > mLength) pos = mLength; + if (pos < 0) pos = 0; /* Even if nothing is deleted, we must call these callbacks */ - call_predelete_callbacks( pos, 0 ); + call_predelete_callbacks(pos, 0); /* insert and redisplay */ - nInserted = insert_( pos, s ); + nInserted = insert_(pos, s); mCursorPosHint = pos + nInserted; - call_modify_callbacks( pos, 0, nInserted, 0, NULL ); + call_modify_callbacks(pos, 0, nInserted, 0, NULL); } /* -** Delete the characters between "start" and "end", and insert the -** null-terminated string "text" in their place in in "buf" + Delete the characters between "start" and "end", and insert the + null-terminated string "text" in their place in in "buf" */ -void Fl_Text_Buffer::replace( int start, int end, const char *s ) { +/** Replaces the text in the specified range of characters in the buffer.*/ +void Fl_Text_Buffer::replace(int start, int end, const char *s) { const char * deletedText; int nInserted; @@ -297,43 +298,48 @@ void Fl_Text_Buffer::replace( int start, int end, const char *s ) { if (start < 0) start = 0; if (end > mLength) end = mLength; - call_predelete_callbacks( start, end-start ); - deletedText = text_range( start, end ); - remove_( start, end ); + call_predelete_callbacks(start, end-start); + deletedText = text_range(start, end); + remove_(start, end); //undoyankcut = undocut; - nInserted = insert_( start, s ); + nInserted = insert_(start, s); mCursorPosHint = start + nInserted; - call_modify_callbacks( start, end - start, nInserted, 0, deletedText ); - free( (void *)deletedText ); + call_modify_callbacks(start, end - start, nInserted, 0, deletedText); + free((void *)deletedText); } -void Fl_Text_Buffer::remove( int start, int end ) { +/** Deletes a range of characters in the buffer.*/ +void Fl_Text_Buffer::remove(int start, int end) { const char * deletedText; /* Make sure the arguments make sense */ - if ( start > end ) { + if (start > end) { int temp = start; start = end; end = temp; } - if ( start > mLength ) start = mLength; - if ( start < 0 ) start = 0; - if ( end > mLength ) end = mLength; - if ( end < 0 ) end = 0; + if (start > mLength) start = mLength; + if (start < 0) start = 0; + if (end > mLength) end = mLength; + if (end < 0) end = 0; if (start == end) return; - call_predelete_callbacks( start, end-start ); + call_predelete_callbacks(start, end-start); /* Remove and redisplay */ - deletedText = text_range( start, end ); - remove_( start, end ); + deletedText = text_range(start, end); + remove_(start, end); mCursorPosHint = start; - call_modify_callbacks( start, end - start, 0, 0, deletedText ); - free( (void *)deletedText ); + call_modify_callbacks(start, end - start, 0, 0, deletedText); + free((void *)deletedText); } -void Fl_Text_Buffer::copy( Fl_Text_Buffer *fromBuf, int fromStart, - int fromEnd, int toPos ) { +/** + Copies text from one buffer to this one; fromBuf may + be the same as this. +*/ +void Fl_Text_Buffer::copy(Fl_Text_Buffer *fromBuf, int fromStart, + int fromEnd, int toPos) { int copiedLength = fromEnd - fromStart; int part1Length; @@ -342,32 +348,32 @@ void Fl_Text_Buffer::copy( Fl_Text_Buffer *fromBuf, int fromStart, the text should be inserted. If the new text is too large, reallocate the buffer with a gap large enough to accomodate the new text and a gap of PREFERRED_GAP_SIZE */ - if ( copiedLength > mGapEnd - mGapStart ) - reallocate_with_gap( toPos, copiedLength + PREFERRED_GAP_SIZE ); - else if ( toPos != mGapStart ) - move_gap( toPos ); + if (copiedLength > mGapEnd - mGapStart) + reallocate_with_gap(toPos, copiedLength + PREFERRED_GAP_SIZE); + else if (toPos != mGapStart) + move_gap(toPos); /* Insert the new text (toPos now corresponds to the start of the gap) */ - if ( fromEnd <= fromBuf->mGapStart ) { - memcpy( &mBuf[ toPos ], &fromBuf->mBuf[ fromStart ], copiedLength ); - } else if ( fromStart >= fromBuf->mGapStart ) { - memcpy( &mBuf[ toPos ], - &fromBuf->mBuf[ fromStart + ( fromBuf->mGapEnd - fromBuf->mGapStart ) ], - copiedLength ); + if (fromEnd <= fromBuf->mGapStart) { + memcpy(&mBuf[ toPos ], &fromBuf->mBuf[ fromStart ], copiedLength); + } else if (fromStart >= fromBuf->mGapStart) { + memcpy(&mBuf[ toPos ], + &fromBuf->mBuf[ fromStart + (fromBuf->mGapEnd - fromBuf->mGapStart) ], + copiedLength); } else { part1Length = fromBuf->mGapStart - fromStart; - memcpy( &mBuf[ toPos ], &fromBuf->mBuf[ fromStart ], part1Length ); - memcpy( &mBuf[ toPos + part1Length ], &fromBuf->mBuf[ fromBuf->mGapEnd ], - copiedLength - part1Length ); + memcpy(&mBuf[ toPos ], &fromBuf->mBuf[ fromStart ], part1Length); + memcpy(&mBuf[ toPos + part1Length ], &fromBuf->mBuf[ fromBuf->mGapEnd ], + copiedLength - part1Length); } mGapStart += copiedLength; mLength += copiedLength; - update_selections( toPos, 0, copiedLength ); + update_selections(toPos, 0, copiedLength); } -/* -** remove text according to the undo variables or insert text -** from the undo buffer +/** + Undo text modification according to the undo variables or insert text + from the undo buffer */ int Fl_Text_Buffer::undo(int *cursorPos) { if (undowidget != this || !undocut && !undoinsert &&!mCanUndo) return 0; @@ -403,80 +409,78 @@ int Fl_Text_Buffer::undo(int *cursorPos) { return 1; } -/* -** let the undo system know if we can undo changes -*/ +/** Lets the undo system know if we can undo changes */ void Fl_Text_Buffer::canUndo(char flag) { mCanUndo = flag; } -/* -** Insert "text" columnwise into buffer starting at displayed character -** position "column" on the line beginning at "startPos". Opens a rectangular -** space the width and height of "text", by moving all text to the right of -** "column" right. If charsInserted and charsDeleted are not NULL, the -** number of characters inserted and deleted in the operation (beginning -** at startPos) are returned in these arguments -*/ -void Fl_Text_Buffer::insert_column( int column, int startPos, const char *s, - int *charsInserted, int *charsDeleted ) { +/** + Insert "text" columnwise into buffer starting at displayed character + position "column" on the line beginning at "startPos". Opens a rectangular + space the width and height of "text", by moving all text to the right of + "column" right. If charsInserted and charsDeleted are not NULL, the + number of characters inserted and deleted in the operation (beginning + at startPos) are returned in these arguments +*/ +void Fl_Text_Buffer::insert_column(int column, int startPos, const char *s, + int *charsInserted, int *charsDeleted) { int nLines, lineStartPos, nDeleted, insertDeleted, nInserted; const char *deletedText; - nLines = countLines( s ); - lineStartPos = line_start( startPos ); - nDeleted = line_end( skip_lines( startPos, nLines ) ) - + nLines = countLines(s); + lineStartPos = line_start(startPos); + nDeleted = line_end(skip_lines(startPos, nLines)) - lineStartPos; - call_predelete_callbacks( lineStartPos, nDeleted ); - deletedText = text_range( lineStartPos, lineStartPos + nDeleted ); - insert_column_( column, lineStartPos, s, &insertDeleted, &nInserted, - &mCursorPosHint ); - if ( nDeleted != insertDeleted ) + call_predelete_callbacks(lineStartPos, nDeleted); + deletedText = text_range(lineStartPos, lineStartPos + nDeleted); + insert_column_(column, lineStartPos, s, &insertDeleted, &nInserted, + &mCursorPosHint); + if (nDeleted != insertDeleted) Fl::error("Fl_Text_Buffer::insert_column(): internal consistency check ins1 failed"); - call_modify_callbacks( lineStartPos, nDeleted, nInserted, 0, deletedText ); - free( (void *) deletedText ); - if ( charsInserted != NULL ) + call_modify_callbacks(lineStartPos, nDeleted, nInserted, 0, deletedText); + free((void *) deletedText); + if (charsInserted != NULL) * charsInserted = nInserted; - if ( charsDeleted != NULL ) + if (charsDeleted != NULL) * charsDeleted = nDeleted; } -/* -** Overlay "text" between displayed character positions "rectStart" and -** "rectEnd" on the line beginning at "startPos". If charsInserted and -** charsDeleted are not NULL, the number of characters inserted and deleted -** in the operation (beginning at startPos) are returned in these arguments. +/** + Overlay "text" between displayed character positions "rectStart" and + "rectEnd" on the line beginning at "startPos". If charsInserted and + charsDeleted are not NULL, the number of characters inserted and deleted + in the operation (beginning at startPos) are returned in these arguments. */ -void Fl_Text_Buffer::overlay_rectangular( int startPos, int rectStart, - int rectEnd, const char *s, int *charsInserted, int *charsDeleted ) { +void Fl_Text_Buffer::overlay_rectangular(int startPos, int rectStart, + int rectEnd, const char *s, int *charsInserted, int *charsDeleted) { int nLines, lineStartPos, nDeleted, insertDeleted, nInserted; const char *deletedText; - nLines = countLines( s ); - lineStartPos = line_start( startPos ); - nDeleted = line_end( skip_lines( startPos, nLines ) ) - + nLines = countLines(s); + lineStartPos = line_start(startPos); + nDeleted = line_end(skip_lines(startPos, nLines)) - lineStartPos; - call_predelete_callbacks( lineStartPos, nDeleted ); - deletedText = text_range( lineStartPos, lineStartPos + nDeleted ); - overlay_rectangular_( lineStartPos, rectStart, rectEnd, s, &insertDeleted, - &nInserted, &mCursorPosHint ); - if ( nDeleted != insertDeleted ) + call_predelete_callbacks(lineStartPos, nDeleted); + deletedText = text_range(lineStartPos, lineStartPos + nDeleted); + overlay_rectangular_(lineStartPos, rectStart, rectEnd, s, &insertDeleted, + &nInserted, &mCursorPosHint); + if (nDeleted != insertDeleted) Fl::error("Fl_Text_Buffer::overlay_rectangle(): internal consistency check ovly1 failed"); - call_modify_callbacks( lineStartPos, nDeleted, nInserted, 0, deletedText ); - free( (void *) deletedText ); - if ( charsInserted != NULL ) + call_modify_callbacks(lineStartPos, nDeleted, nInserted, 0, deletedText); + free((void *) deletedText); + if (charsInserted != NULL) * charsInserted = nInserted; - if ( charsDeleted != NULL ) + if (charsDeleted != NULL) * charsDeleted = nDeleted; } -/* -** Replace a rectangular area in buf, given by "start", "end", "rectStart", -** and "rectEnd", with "text". If "text" is vertically longer than the -** rectangle, add extra lines to make room for it. +/** + Replaces a rectangular area in buf, given by "start", "end", "rectStart", + and "rectEnd", with "text". If "text" is vertically longer than the + rectangle, add extra lines to make room for it. */ -void Fl_Text_Buffer::replace_rectangular( int start, int end, int rectStart, - int rectEnd, const char *s ) { +void Fl_Text_Buffer::replace_rectangular(int start, int end, int rectStart, + int rectEnd, const char *s) { char *insPtr; const char *deletedText; char *insText = (char *)""; @@ -486,10 +490,10 @@ void Fl_Text_Buffer::replace_rectangular( int start, int end, int rectStart, /* Make sure start and end refer to complete lines, since the columnar delete and insert operations will replace whole lines */ - start = line_start( start ); - end = line_end( end ); + start = line_start(start); + end = line_end(end); - call_predelete_callbacks( start, end-start ); + call_predelete_callbacks(start, end-start); /* If more lines will be deleted than inserted, pad the inserted text with newlines to make it as long as the number of deleted lines. This @@ -497,122 +501,127 @@ void Fl_Text_Buffer::replace_rectangular( int start, int end, int rectStart, column. If more lines will be inserted than deleted, insert extra lines in the buffer at the end of the rectangle to make room for the additional lines in "text" */ - nInsertedLines = countLines( s ); - nDeletedLines = count_lines( start, end ); - if ( nInsertedLines < nDeletedLines ) { - insLen = strlen( s ); - insText = (char *)malloc( insLen + nDeletedLines - nInsertedLines + 1 ); - strcpy( insText, s ); + nInsertedLines = countLines(s); + nDeletedLines = count_lines(start, end); + if (nInsertedLines < nDeletedLines) { + insLen = strlen(s); + insText = (char *)malloc(insLen + nDeletedLines - nInsertedLines + 1); + strcpy(insText, s); insPtr = insText + insLen; - for ( i = 0; i < nDeletedLines - nInsertedLines; i++ ) + for (i = 0; i < nDeletedLines - nInsertedLines; i++) *insPtr++ = '\n'; *insPtr = '\0'; - } else if ( nDeletedLines < nInsertedLines ) { + } else if (nDeletedLines < nInsertedLines) { linesPadded = nInsertedLines - nDeletedLines; - for ( i = 0; i < linesPadded; i++ ) - insert_( end, "\n" ); + for (i = 0; i < linesPadded; i++) + insert_(end, "\n"); } /* else nDeletedLines == nInsertedLines; */ /* Save a copy of the text which will be modified for the modify CBs */ - deletedText = text_range( start, end ); + deletedText = text_range(start, end); /* Delete then insert */ - remove_rectangular_( start, end, rectStart, rectEnd, &deleteInserted, &hint ); - insert_column_( rectStart, start, insText, &insertDeleted, &insertInserted, - &mCursorPosHint ); + remove_rectangular_(start, end, rectStart, rectEnd, &deleteInserted, &hint); + insert_column_(rectStart, start, insText, &insertDeleted, &insertInserted, + &mCursorPosHint); /* Figure out how many chars were inserted and call modify callbacks */ - if ( insertDeleted != deleteInserted + linesPadded ) + if (insertDeleted != deleteInserted + linesPadded) Fl::error("Fl_Text_Buffer::replace_rectangular(): internal consistency check repl1 failed"); - call_modify_callbacks( start, end - start, insertInserted, 0, deletedText ); - free( (void *) deletedText ); - if ( nInsertedLines < nDeletedLines ) - free( (void *) insText ); + call_modify_callbacks(start, end - start, insertInserted, 0, deletedText); + free((void *) deletedText); + if (nInsertedLines < nDeletedLines) + free((void *) insText); } -/* -** Remove a rectangular swath of characters between character positions start -** and end and horizontal displayed-character offsets rectStart and rectEnd. +/** + Removes a rectangular swath of characters between character positions start + and end and horizontal displayed-character offsets rectStart and rectEnd. */ -void Fl_Text_Buffer::remove_rectangular( int start, int end, int rectStart, - int rectEnd ) { +void Fl_Text_Buffer::remove_rectangular(int start, int end, int rectStart, + int rectEnd) { const char * deletedText; int nInserted; - start = line_start( start ); - end = line_end( end ); - call_predelete_callbacks( start, end-start ); - deletedText = text_range( start, end ); - remove_rectangular_( start, end, rectStart, rectEnd, &nInserted, - &mCursorPosHint ); - call_modify_callbacks( start, end - start, nInserted, 0, deletedText ); - free( (void *) deletedText ); -} - -/* -** Clear a rectangular "hole" out of the buffer between character positions -** start and end and horizontal displayed-character offsets rectStart and -** rectEnd. + start = line_start(start); + end = line_end(end); + call_predelete_callbacks(start, end-start); + deletedText = text_range(start, end); + remove_rectangular_(start, end, rectStart, rectEnd, &nInserted, + &mCursorPosHint); + call_modify_callbacks(start, end - start, nInserted, 0, deletedText); + free((void *) deletedText); +} + +/** + Clears text in the specified area. + It clears a rectangular "hole" out of the buffer between character positions + start and end and horizontal displayed-character offsets rectStart and + rectEnd. */ -void Fl_Text_Buffer::clear_rectangular( int start, int end, int rectStart, - int rectEnd ) { +void Fl_Text_Buffer::clear_rectangular(int start, int end, int rectStart, + int rectEnd) { int i, nLines; char *newlineString; - nLines = count_lines( start, end ); - newlineString = (char *)malloc( nLines + 1 ); - for ( i = 0; i < nLines; i++ ) + nLines = count_lines(start, end); + newlineString = (char *)malloc(nLines + 1); + for (i = 0; i < nLines; i++) newlineString[ i ] = '\n'; newlineString[ i ] = '\0'; - overlay_rectangular( start, rectStart, rectEnd, newlineString, - NULL, NULL ); - free( (void *) newlineString ); + overlay_rectangular(start, rectStart, rectEnd, newlineString, + NULL, NULL); + free((void *) newlineString); } - -char * Fl_Text_Buffer::text_in_rectangle( int start, int end, - int rectStart, int rectEnd ) { +/** + Returns the text from the given rectangle. When you are done + with the text, free it using the free() function. +*/ +char * Fl_Text_Buffer::text_in_rectangle(int start, int end, + int rectStart, int rectEnd) { int lineStart, selLeft, selRight, len; char *textOut, *outPtr, *retabbedStr; const char *textIn; - start = line_start( start ); - end = line_end( end ); - textOut = (char *)malloc( ( end - start ) + 1 ); + start = line_start(start); + end = line_end(end); + textOut = (char *)malloc((end - start) + 1); lineStart = start; outPtr = textOut; - while ( lineStart <= end ) { - rectangular_selection_boundaries( lineStart, rectStart, rectEnd, - &selLeft, &selRight ); - textIn = text_range( selLeft, selRight ); + while (lineStart <= end) { + rectangular_selection_boundaries(lineStart, rectStart, rectEnd, + &selLeft, &selRight); + textIn = text_range(selLeft, selRight); len = selRight - selLeft; - memcpy( outPtr, textIn, len ); - free( (void *) textIn ); + memcpy(outPtr, textIn, len); + free((void *) textIn); outPtr += len; - lineStart = line_end( selRight ) + 1; + lineStart = line_end(selRight) + 1; *outPtr++ = '\n'; } - if ( outPtr != textOut ) + if (outPtr != textOut) outPtr--; /* don't leave trailing newline */ *outPtr = '\0'; /* If necessary, realign the tabs in the selection as if the text were positioned at the left margin */ - retabbedStr = realignTabs( textOut, rectStart, 0, mTabDist, - mUseTabs, mNullSubsChar, &len ); - free( (void *) textOut ); + retabbedStr = realignTabs(textOut, rectStart, 0, mTabDist, + mUseTabs, mNullSubsChar, &len); + free((void *) textOut); return retabbedStr; } /* -** Set the hardware tab distance used by all displays for this buffer, -** and used in computing offsets for rectangular selection operations. + Set the hardware tab distance used by all displays for this buffer, + and used in computing offsets for rectangular selection operations. */ -void Fl_Text_Buffer::tab_distance( int tabDist ) { +/** Gets or sets the tab width.*/ +void Fl_Text_Buffer::tab_distance(int tabDist) { const char * deletedText; /* First call the pre-delete callbacks with the previous tab setting still active. */ - call_predelete_callbacks( 0, mLength ); + call_predelete_callbacks(0, mLength); /* Change the tab setting */ mTabDist = tabDist; @@ -620,153 +629,180 @@ void Fl_Text_Buffer::tab_distance( int tabDist ) { /* Force any display routines to redisplay everything (unfortunately, this means copying the whole buffer contents to provide "deletedText" */ deletedText = text(); - call_modify_callbacks( 0, mLength, mLength, 0, deletedText ); - free( (void *) deletedText ); + call_modify_callbacks(0, mLength, mLength, 0, deletedText); + free((void *) deletedText); } -void Fl_Text_Buffer::select( int start, int end ) { +/** Selects a range of characters in the buffer.*/ +void Fl_Text_Buffer::select(int start, int end) { Fl_Text_Selection oldSelection = mPrimary; - mPrimary.set( start, end ); - redisplay_selection( &oldSelection, &mPrimary ); + mPrimary.set(start, end); + redisplay_selection(&oldSelection, &mPrimary); } - +/** Cancels any previous selection on the primary text selection object */ void Fl_Text_Buffer::unselect() { Fl_Text_Selection oldSelection = mPrimary; mPrimary.mSelected = 0; - redisplay_selection( &oldSelection, &mPrimary ); + redisplay_selection(&oldSelection, &mPrimary); } - -void Fl_Text_Buffer::select_rectangular( int start, int end, int rectStart, - int rectEnd ) { +/** Achieves a rectangular selection on the primary text selection object */ +void Fl_Text_Buffer::select_rectangular(int start, int end, int rectStart, + int rectEnd) { Fl_Text_Selection oldSelection = mPrimary; - mPrimary.set_rectangular( start, end, rectStart, rectEnd ); - redisplay_selection( &oldSelection, &mPrimary ); + mPrimary.set_rectangular(start, end, rectStart, rectEnd); + redisplay_selection(&oldSelection, &mPrimary); } -int Fl_Text_Buffer::selection_position( int *start, int *end - ) { - return mPrimary.position( start, end ); +/** Gets the selection position */ +int Fl_Text_Buffer::selection_position(int *start, int *end + ) { + return mPrimary.position(start, end); } - -int Fl_Text_Buffer::selection_position( int *start, int *end, - int *isRect, int *rectStart, int *rectEnd ) { - return mPrimary.position( start, end, isRect, rectStart, - rectEnd ); +/** Gets the selection position, and rectangular selection info */ +int Fl_Text_Buffer::selection_position(int *start, int *end, + int *isRect, int *rectStart, int *rectEnd) { + return mPrimary.position(start, end, isRect, rectStart, + rectEnd); } +/** + Returns the currently selected text. When you are done with + the text, free it using the free() function. +*/ char * Fl_Text_Buffer::selection_text() { - return selection_text_( &mPrimary ); + return selection_text_(&mPrimary); } +/** Removes the text in the primary selection.*/ void Fl_Text_Buffer::remove_selection() { - remove_selection_( &mPrimary ); + remove_selection_(&mPrimary); } - -void Fl_Text_Buffer::replace_selection( const char *s ) { - replace_selection_( &mPrimary, s ); +/** Replaces the text in the primary selection.*/ +void Fl_Text_Buffer::replace_selection(const char *s) { + replace_selection_(&mPrimary, s); } -void Fl_Text_Buffer::secondary_select( int start, int end ) { +/** Selects a range of characters in the secondary selection.*/ +void Fl_Text_Buffer::secondary_select(int start, int end) { Fl_Text_Selection oldSelection = mSecondary; - mSecondary.set( start, end ); - redisplay_selection( &oldSelection, &mSecondary ); + mSecondary.set(start, end); + redisplay_selection(&oldSelection, &mSecondary); } - +/** Cancels any previous selection on the primary text selection object */ void Fl_Text_Buffer::secondary_unselect() { Fl_Text_Selection oldSelection = mSecondary; mSecondary.mSelected = 0; - redisplay_selection( &oldSelection, &mSecondary ); + redisplay_selection(&oldSelection, &mSecondary); } -void Fl_Text_Buffer::secondary_select_rectangular( int start, int end, - int rectStart, int rectEnd ) { +/** Achieves a rectangular selection on the secondary text selection object */ +void Fl_Text_Buffer::secondary_select_rectangular(int start, int end, + int rectStart, int rectEnd) { Fl_Text_Selection oldSelection = mSecondary; - mSecondary.set_rectangular( start, end, rectStart, rectEnd ); - redisplay_selection( &oldSelection, &mSecondary ); + mSecondary.set_rectangular(start, end, rectStart, rectEnd); + redisplay_selection(&oldSelection, &mSecondary); } - -int Fl_Text_Buffer::secondary_selection_position( int *start, int *end - ) { - return mSecondary.position( start, end ); +/** Returns the current selection in the secondary text selection object.*/ +int Fl_Text_Buffer::secondary_selection_position(int *start, int *end + ) { + return mSecondary.position(start, end); } - -int Fl_Text_Buffer::secondary_selection_position( int *start, int *end, - int *isRect, int *rectStart, int *rectEnd ) { - return mSecondary.position( start, end, isRect, rectStart, - rectEnd ); +/** Returns the current selection in the secondary text selection object.*/ +int Fl_Text_Buffer::secondary_selection_position(int *start, int *end, + int *isRect, int *rectStart, int *rectEnd) { + return mSecondary.position(start, end, isRect, rectStart, + rectEnd); } +/** + Returns the text in the secondary selection. When you are + done with the text, free it using the free() function. +*/ char * Fl_Text_Buffer::secondary_selection_text() { - return selection_text_( &mSecondary ); + return selection_text_(&mSecondary); } - +/** Removes the text from the buffer corresponding to the secondary text selection object.*/ void Fl_Text_Buffer::remove_secondary_selection() { - remove_selection_( &mSecondary ); + remove_selection_(&mSecondary); } - -void Fl_Text_Buffer::replace_secondary_selection( const char *s ) { - replace_selection_( &mSecondary, s ); +/** Replaces the text from the buffer corresponding to the secondary + text selection object with the new string "s".*/ +void Fl_Text_Buffer::replace_secondary_selection(const char *s) { + replace_selection_(&mSecondary, s); } -void Fl_Text_Buffer::highlight( int start, int end ) { +/** Highlights the specified text within the buffer.*/ +void Fl_Text_Buffer::highlight(int start, int end) { Fl_Text_Selection oldSelection = mHighlight; - mHighlight.set( start, end ); - redisplay_selection( &oldSelection, &mHighlight ); + mHighlight.set(start, end); + redisplay_selection(&oldSelection, &mHighlight); } +/** Unhighlights text in the buffer.*/ void Fl_Text_Buffer::unhighlight() { Fl_Text_Selection oldSelection = mHighlight; mHighlight.mSelected = 0; - redisplay_selection( &oldSelection, &mHighlight ); + redisplay_selection(&oldSelection, &mHighlight); } - -void Fl_Text_Buffer::highlight_rectangular( int start, int end, - int rectStart, int rectEnd ) { +/** Highlights a rectangular selection in the buffer */ +void Fl_Text_Buffer::highlight_rectangular(int start, int end, + int rectStart, int rectEnd) { Fl_Text_Selection oldSelection = mHighlight; - mHighlight.set_rectangular( start, end, rectStart, rectEnd ); - redisplay_selection( &oldSelection, &mHighlight ); + mHighlight.set_rectangular(start, end, rectStart, rectEnd); + redisplay_selection(&oldSelection, &mHighlight); } - -int Fl_Text_Buffer::highlight_position( int *start, int *end - ) { - return mHighlight.position( start, end ); +/** Highlights the specified text between "start" and "end" within the buffer.*/ +int Fl_Text_Buffer::highlight_position(int *start, int *end + ) { + return mHighlight.position(start, end); } - -int Fl_Text_Buffer::highlight_position( int *start, int *end, - int *isRect, int *rectStart, int *rectEnd ) { - return mHighlight.position( start, end, isRect, rectStart, - rectEnd ); +/** Highlights the specified rectangle of text within the buffer.*/ +int Fl_Text_Buffer::highlight_position(int *start, int *end, + int *isRect, int *rectStart, int *rectEnd) { + return mHighlight.position(start, end, isRect, rectStart, + rectEnd); } +/** + Returns the highlighted text. When you are done with the + text, free it using the free() function. +*/ char * Fl_Text_Buffer::highlight_text() { - return selection_text_( &mHighlight ); -} - -/* -** Add a callback routine to be called when the buffer is modified + return selection_text_(&mHighlight); +} + +/** + Adds a callback function that is called whenever the text buffer is + modified. The callback function is declared as follows: + + \code + typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted, + int nRestyled, const char* deletedText, + void* cbArg); + \endcode */ -void Fl_Text_Buffer::add_modify_callback( Fl_Text_Modify_Cb bufModifiedCB, - void *cbArg ) { +void Fl_Text_Buffer::add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, + void *cbArg) { Fl_Text_Modify_Cb * newModifyProcs; void **newCBArgs; int i; newModifyProcs = new Fl_Text_Modify_Cb [ mNModifyProcs + 1 ]; newCBArgs = new void * [ mNModifyProcs + 1 ]; - for ( i = 0; i < mNModifyProcs; i++ ) { + for (i = 0; i < mNModifyProcs; i++) { newModifyProcs[ i + 1 ] = mNodifyProcs[ i ]; newCBArgs[ i + 1 ] = mCbArgs[ i ]; } - if ( mNModifyProcs != 0 ) { + if (mNModifyProcs != 0) { delete [] mNodifyProcs; delete [] mCbArgs; } @@ -776,21 +812,21 @@ void Fl_Text_Buffer::add_modify_callback( Fl_Text_Modify_Cb bufModifiedCB, mNodifyProcs = newModifyProcs; mCbArgs = newCBArgs; } - -void Fl_Text_Buffer::remove_modify_callback( Fl_Text_Modify_Cb bufModifiedCB, - void *cbArg ) { +/** Removes a modify callback.*/ +void Fl_Text_Buffer::remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB, + void *cbArg) { int i, toRemove = -1; Fl_Text_Modify_Cb *newModifyProcs; void **newCBArgs; /* find the matching callback to remove */ - for ( i = 0; i < mNModifyProcs; i++ ) { - if ( mNodifyProcs[ i ] == bufModifiedCB && mCbArgs[ i ] == cbArg ) { + for (i = 0; i < mNModifyProcs; i++) { + if (mNodifyProcs[ i ] == bufModifiedCB && mCbArgs[ i ] == cbArg) { toRemove = i; break; } } - if ( toRemove == -1 ) { + if (toRemove == -1) { Fl::error("Fl_Text_Buffer::remove_modify_callback(): Can't find modify CB to remove"); return; } @@ -798,7 +834,7 @@ void Fl_Text_Buffer::remove_modify_callback( Fl_Text_Modify_Cb bufModifiedCB, /* Allocate new lists for remaining callback procs and args (if any are left) */ mNModifyProcs--; - if ( mNModifyProcs == 0 ) { + if (mNModifyProcs == 0) { mNModifyProcs = 0; delete[] mNodifyProcs; mNodifyProcs = NULL; @@ -810,11 +846,11 @@ void Fl_Text_Buffer::remove_modify_callback( Fl_Text_Modify_Cb bufModifiedCB, newCBArgs = new void * [ mNModifyProcs ]; /* copy out the remaining members and free the old lists */ - for ( i = 0; i < toRemove; i++ ) { + for (i = 0; i < toRemove; i++) { newModifyProcs[ i ] = mNodifyProcs[ i ]; newCBArgs[ i ] = mCbArgs[ i ]; } - for ( ; i < mNModifyProcs; i++ ) { + for (; i < mNModifyProcs; i++) { newModifyProcs[ i ] = mNodifyProcs[ i + 1 ]; newCBArgs[ i ] = mCbArgs[ i + 1 ]; } @@ -824,9 +860,7 @@ void Fl_Text_Buffer::remove_modify_callback( Fl_Text_Modify_Cb bufModifiedCB, mCbArgs = newCBArgs; } -/* -** Add a callback routine to be called before text is deleted from the buffer. -*/ +/** Adds a callback routine to be called before text is deleted from the buffer. */ void Fl_Text_Buffer::add_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg) { Fl_Text_Predelete_Cb *newPreDeleteProcs; @@ -835,7 +869,7 @@ void Fl_Text_Buffer::add_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, newPreDeleteProcs = new Fl_Text_Predelete_Cb[ mNPredeleteProcs + 1 ]; newCBArgs = new void * [ mNPredeleteProcs + 1 ]; - for ( i = 0; i < mNPredeleteProcs; i++ ) { + for (i = 0; i < mNPredeleteProcs; i++) { newPreDeleteProcs[i + 1] = mPredeleteProcs[i]; newCBArgs[i + 1] = mPredeleteCbArgs[i]; } @@ -849,7 +883,7 @@ void Fl_Text_Buffer::add_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, mPredeleteProcs = newPreDeleteProcs; mPredeleteCbArgs = newCBArgs; } - +/** Removes a callback routine "bufPreDeleteCB" to be called before text is deleted from the buffer. */ void Fl_Text_Buffer::remove_predelete_callback( Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg) { int i, toRemove = -1; @@ -857,7 +891,7 @@ void Fl_Text_Buffer::remove_predelete_callback( void **newCBArgs; /* find the matching callback to remove */ - for ( i = 0; i < mNPredeleteProcs; i++) { + for (i = 0; i < mNPredeleteProcs; i++) { if (mPredeleteProcs[i] == bufPreDeleteCB && mPredeleteCbArgs[i] == cbArg) { toRemove = i; @@ -884,11 +918,11 @@ void Fl_Text_Buffer::remove_predelete_callback( newCBArgs = new void * [ mNPredeleteProcs ]; /* copy out the remaining members and free the old lists */ - for ( i = 0; i < toRemove; i++) { + for (i = 0; i < toRemove; i++) { newPreDeleteProcs[i] = mPredeleteProcs[i]; newCBArgs[i] = mPredeleteCbArgs[i]; } - for ( ; i < mNPredeleteProcs; i++) { + for (; i < mNPredeleteProcs; i++) { newPreDeleteProcs[i] = mPredeleteProcs[i+1]; newCBArgs[i] = mPredeleteCbArgs[i+1]; } @@ -898,61 +932,65 @@ void Fl_Text_Buffer::remove_predelete_callback( mPredeleteCbArgs = newCBArgs; } -/* -** Return the text from the entire line containing position "pos" +/** + Returns the text from the entire line containing the specified + character position. When you are done with the text, free it + using the free() function. */ -char * Fl_Text_Buffer::line_text( int pos ) { - return text_range( line_start( pos ), line_end( pos ) ); +char * Fl_Text_Buffer::line_text(int pos) { + return text_range(line_start(pos), line_end(pos)); } -/* -** Find the position of the start of the line containing position "pos" -*/ -int Fl_Text_Buffer::line_start( int pos ) { - if ( !findchar_backward( pos, '\n', &pos ) ) +/** Returns the position of the start of the line containing position "pos". */ +int Fl_Text_Buffer::line_start(int pos) { + if (!findchar_backward(pos, '\n', &pos)) return 0; return pos + 1; } -/* -** Find the position of the end of the line containing position "pos" -** (which is either a pointer to the newline character ending the line, -** or a pointer to one character beyond the end of the buffer) +/** Finds and returns the position of the end of the line containing position "pos" + (which is either a pointer to the newline character ending the line, + or a pointer to one character beyond the end of the buffer) */ -int Fl_Text_Buffer::line_end( int pos ) { - if ( !findchar_forward( pos, '\n', &pos ) ) +int Fl_Text_Buffer::line_end(int pos) { + if (!findchar_forward(pos, '\n', &pos)) pos = mLength; return pos; } - -int Fl_Text_Buffer::word_start( int pos ) { - while ( pos && ( isalnum( character( pos ) ) || character( pos ) == '_' ) ) { +/** Returns the position corresponding to the start of the word */ +int Fl_Text_Buffer::word_start(int pos) { + while (pos && (isalnum(character(pos)) || character(pos) == '_')) { pos--; } - if ( !( isalnum( character( pos ) ) || character( pos ) == '_' ) ) pos++; + if (!(isalnum(character(pos)) || character(pos) == '_')) pos++; return pos; } -int Fl_Text_Buffer::word_end( int pos ) { - while (pos < length() && (isalnum(character(pos)) || character(pos) == '_' )) { +/** Returns the position corresponding to the end of the word.*/ +int Fl_Text_Buffer::word_end(int pos) { + while (pos < length() && (isalnum(character(pos)) || character(pos) == '_')) { pos++; } return pos; } /* -** Get a character from the text buffer expanded into it's screen -** representation (which may be several characters for a tab or a -** control code). Returns the number of characters written to "outStr". -** "indent" is the number of characters from the start of the line -** for figuring tabs. Output string is guranteed to be shorter or -** equal in length to FL_TEXT_MAX_EXP_CHAR_LEN -*/ -int Fl_Text_Buffer::expand_character( int pos, int indent, char *outStr ) { + Get a character from the text buffer expanded into it's screen + representation (which may be several characters for a tab or a + control code). Returns the number of characters written to "outStr". + "indent" is the number of characters from the start of the line + for figuring tabs. Output string is guranteed to be shorter or + equal in length to FL_TEXT_MAX_EXP_CHAR_LEN +*/ +/** + Expands the given character to a displayable format. Tabs and + other control characters are given special treatment. +*/ +int Fl_Text_Buffer::expand_character(int pos, int indent, char *outStr) { int ret; - char c = character( pos ); - ret = expand_character( c, indent, outStr, - mTabDist, mNullSubsChar ); + char c = character(pos); + ret = expand_character(c, indent, outStr, + mTabDist, mNullSubsChar); if (ret > 1 && (c & 0x80)) { int i; i = utf_len(c); @@ -960,43 +998,44 @@ int Fl_Text_Buffer::expand_character( int pos, int indent, char *outStr ) { i--; pos++; outStr++; - *outStr = character( pos ); + *outStr = character(pos); } } return ret; } -/* -** Expand a single character from the text buffer into it's screen -** representation (which may be several characters for a tab or a -** control code). Returns the number of characters added to "outStr". -** "indent" is the number of characters from the start of the line -** for figuring tabs. Output string is guranteed to be shorter or -** equal in length to FL_TEXT_MAX_EXP_CHAR_LEN -*/ -int Fl_Text_Buffer::expand_character( char c, int indent, char *outStr, int tabDist, - char nullSubsChar ) { +/** + Expand a single character from the text buffer into it's displayable screen + representation (which may be several characters for a tab or a + control code). Returns the number of characters added to "outStr". + "indent" is the number of characters from the start of the line + for figuring tabs. Output string is guranteed to be shorter or + equal in length to FL_TEXT_MAX_EXP_CHAR_LEN + Tabs and other control characters are given special treatment. +*/ +int Fl_Text_Buffer::expand_character(char c, int indent, char *outStr, int tabDist, + char nullSubsChar) { int i, nSpaces; /* Convert tabs to spaces */ - if ( c == '\t' ) { - nSpaces = tabDist - ( indent % tabDist ); - for ( i = 0; i < nSpaces; i++ ) + if (c == '\t') { + nSpaces = tabDist - (indent % tabDist); + for (i = 0; i < nSpaces; i++) outStr[ i ] = ' '; return nSpaces; } /* Convert control codes to readable character sequences */ /*... is this safe with international character sets? */ - if ( ( ( unsigned char ) c ) <= 31 ) { - sprintf( outStr, "<%s>", ControlCodeTable[ ( unsigned char ) c ] ); - return strlen( outStr ); - } else if ( c == 127 ) { - sprintf( outStr, "<del>" ); + if (((unsigned char) c) <= 31) { + sprintf(outStr, "<%s>", ControlCodeTable[ (unsigned char) c ]); + return strlen(outStr); + } else if (c == 127) { + sprintf(outStr, "<del>"); return 5; - } else if ( c == nullSubsChar ) { - sprintf( outStr, "<nul>" ); + } else if (c == nullSubsChar) { + sprintf(outStr, "<nul>"); return 5; } else if ((c & 0x80) && !(c & 0x40)) { return 0; @@ -1011,21 +1050,21 @@ int Fl_Text_Buffer::expand_character( char c, int indent, char *outStr, int tabD } /* -** Return the length in displayed characters of character "c" expanded -** for display (as discussed above in BufGetExpandedChar). If the -** buffer for which the character width is being measured is doing null -** substitution, nullSubsChar should be passed as that character (or nul -** to ignore). + Return the length in displayed characters of character "c" expanded + for display (as discussed above in BufGetExpandedChar). If the + buffer for which the character width is being measured is doing null + substitution, nullSubsChar should be passed as that character (or nul + to ignore). */ -int Fl_Text_Buffer::character_width( char c, int indent, int tabDist, char nullSubsChar ) { +int Fl_Text_Buffer::character_width(char c, int indent, int tabDist, char nullSubsChar) { /* Note, this code must parallel that in Fl_Text_Buffer::ExpandCharacter */ - if ( c == '\t' ) - return tabDist - ( indent % tabDist ); - else if ( ( ( unsigned char ) c ) <= 31 ) - return strlen( ControlCodeTable[ ( unsigned char ) c ] ) + 2; - else if ( c == 127 ) + if (c == '\t') + return tabDist - (indent % tabDist); + else if (((unsigned char) c) <= 31) + return strlen(ControlCodeTable[ (unsigned char) c ]) + 2; + else if (c == 127) return 5; - else if ( c == nullSubsChar ) + else if (c == nullSubsChar) return 5; else if ((c & 0x80) && !(c & 0x40)) return 0; @@ -1036,88 +1075,96 @@ int Fl_Text_Buffer::character_width( char c, int indent, int tabDist, char nullS } /* -** Count the number of displayed characters between buffer position -** "lineStartPos" and "targetPos". (displayed characters are the characters -** shown on the screen to represent characters in the buffer, where tabs and -** control characters are expanded) + Count the number of displayed characters between buffer position + "lineStartPos" and "targetPos". (displayed characters are the characters + shown on the screen to represent characters in the buffer, where tabs and + control characters are expanded) +*/ +/** + Determines the number of characters that will be displayed + between lineStartPos and targetPos. */ -int Fl_Text_Buffer::count_displayed_characters( int lineStartPos, int targetPos ) { +int Fl_Text_Buffer::count_displayed_characters(int lineStartPos, int targetPos) { int pos, charCount = 0; char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ]; pos = lineStartPos; - while ( pos < targetPos ) - charCount += expand_character( pos++, charCount, expandedChar ); + while (pos < targetPos) + charCount += expand_character(pos++, charCount, expandedChar); return charCount; } -/* -** Count forward from buffer position "startPos" in displayed characters -** (displayed characters are the characters shown on the screen to represent -** characters in the buffer, where tabs and control characters are expanded) +/** + Count forward from buffer position "startPos" in displayed characters + (displayed characters are the characters shown on the screen to represent + characters in the buffer, where tabs and control characters are expanded) */ -int Fl_Text_Buffer::skip_displayed_characters( int lineStartPos, int nChars ) { +int Fl_Text_Buffer::skip_displayed_characters(int lineStartPos, int nChars) { int pos, charCount = 0; char c; pos = lineStartPos; - while ( charCount < nChars && pos < mLength ) { - c = character( pos ); - if ( c == '\n' ) + while (charCount < nChars && pos < mLength) { + c = character(pos); + if (c == '\n') return pos; - charCount += character_width( c, charCount, mTabDist, mNullSubsChar ); + charCount += character_width(c, charCount, mTabDist, mNullSubsChar); pos++; } return pos; } -/* -** Count the number of newlines between startPos and endPos in buffer "buf". -** The character at position "endPos" is not counted. +/** + Counts the number of newlines between startPos and endPos in buffer "buf". + The character at position "endPos" is not counted. */ -int Fl_Text_Buffer::count_lines( int startPos, int endPos ) { +int Fl_Text_Buffer::count_lines(int startPos, int endPos) { int pos, gapLen = mGapEnd - mGapStart; int lineCount = 0; pos = startPos; - while ( pos < mGapStart ) { - if ( pos == endPos ) + while (pos < mGapStart) { + if (pos == endPos) return lineCount; - if ( mBuf[ pos++ ] == '\n' ) + if (mBuf[ pos++ ] == '\n') lineCount++; } - while ( pos < mLength ) { - if ( pos == endPos ) + while (pos < mLength) { + if (pos == endPos) return lineCount; - if ( mBuf[ pos++ + gapLen ] == '\n' ) + if (mBuf[ pos++ + gapLen ] == '\n') lineCount++; } return lineCount; } /* -** Find the first character of the line "nLines" forward from "startPos" -** in "buf" and return its position + Find the first character of the line "nLines" forward from "startPos" + in "buf" and return its position +*/ +/** + Returns the buffer position for the Nth line after the start + position. */ -int Fl_Text_Buffer::skip_lines( int startPos, int nLines ) { +int Fl_Text_Buffer::skip_lines(int startPos, int nLines) { int pos, gapLen = mGapEnd - mGapStart; int lineCount = 0; - if ( nLines == 0 ) + if (nLines == 0) return startPos; pos = startPos; - while ( pos < mGapStart ) { - if ( mBuf[ pos++ ] == '\n' ) { + while (pos < mGapStart) { + if (mBuf[ pos++ ] == '\n') { lineCount++; - if ( lineCount == nLines ) + if (lineCount == nLines) return pos; } } - while ( pos < mLength ) { - if ( mBuf[ pos++ + gapLen ] == '\n' ) { + while (pos < mLength) { + if (mBuf[ pos++ + gapLen ] == '\n') { lineCount++; - if ( lineCount >= nLines ) + if (lineCount >= nLines) return pos; } } @@ -1125,29 +1172,30 @@ int Fl_Text_Buffer::skip_lines( int startPos, int nLines ) { } /* -** Find the position of the first character of the line "nLines" backwards -** from "startPos" (not counting the character pointed to by "startpos" if -** that is a newline) in "buf". nLines == 0 means find the beginning of -** the line + Find the position of the first character of the line "nLines" backwards + from "startPos" (not counting the character pointed to by "startpos" if + that is a newline) in "buf". nLines == 0 means find the beginning of + the line */ -int Fl_Text_Buffer::rewind_lines( int startPos, int nLines ) { +/** Returns the buffer position for the Nth previous line.*/ +int Fl_Text_Buffer::rewind_lines(int startPos, int nLines) { int pos, gapLen = mGapEnd - mGapStart; int lineCount = -1; pos = startPos - 1; - if ( pos <= 0 ) + if (pos <= 0) return 0; - while ( pos >= mGapStart ) { - if ( mBuf[ pos + gapLen ] == '\n' ) { - if ( ++lineCount >= nLines ) + while (pos >= mGapStart) { + if (mBuf[ pos + gapLen ] == '\n') { + if (++lineCount >= nLines) return pos + 1; } pos--; } - while ( pos >= 0 ) { - if ( mBuf[ pos ] == '\n' ) { - if ( ++lineCount >= nLines ) + while (pos >= 0) { + if (mBuf[ pos ] == '\n') { + if (++lineCount >= nLines) return pos + 1; } pos--; @@ -1155,13 +1203,13 @@ int Fl_Text_Buffer::rewind_lines( int startPos, int nLines ) { return 0; } -/* -** Search forwards in buffer for string "searchString", starting with the -** character "startPos", and returning the result in "foundPos" -** returns 1 if found, 0 if not. +/** + Search forwards in buffer for string "searchString", starting with the + character "startPos", and returning the result in "foundPos" + returns 1 if found, 0 if not. */ -int Fl_Text_Buffer::search_forward( int startPos, const char *searchString, - int *foundPos, int matchCase ) +int Fl_Text_Buffer::search_forward(int startPos, const char *searchString, + int *foundPos, int matchCase) { if (!searchString) return 0; int bp; @@ -1179,13 +1227,13 @@ int Fl_Text_Buffer::search_forward( int startPos, const char *searchString, return 0; } -/* -** Search backwards in buffer for string "searchString", starting with the -** character BEFORE "startPos", returning the result in "foundPos" -** returns 1 if found, 0 if not. +/** + Search backwards in buffer for string <i>searchCharssearchString</i>, starting with the + character BEFORE "startPos", returning the result in "foundPos" + returns 1 if found, 0 if not. */ -int Fl_Text_Buffer::search_backward( int startPos, const char *searchString, - int *foundPos, int matchCase ) +int Fl_Text_Buffer::search_backward(int startPos, const char *searchString, + int *foundPos, int matchCase) { if (!searchString) return 0; int bp; @@ -1203,29 +1251,30 @@ int Fl_Text_Buffer::search_backward( int startPos, const char *searchString, return 0; } -/* -** Search forwards in buffer for characters in "searchChars", starting -** with the character "startPos", and returning the result in "foundPos" -** returns 1 if found, 0 if not. +/** + Finds the next occurrence of the specified characters. + Search forwards in buffer for characters in <i>searchChars</i>, starting + with the character <i>startPos</i>, and returning the result in <i>foundPos</i> + returns 1 if found, 0 if not. */ -int Fl_Text_Buffer::findchars_forward( int startPos, const char *searchChars, - int *foundPos ) { +int Fl_Text_Buffer::findchars_forward(int startPos, const char *searchChars, + int *foundPos) { int pos, gapLen = mGapEnd - mGapStart; const char *c; pos = startPos; - while ( pos < mGapStart ) { - for ( c = searchChars; *c != '\0'; c++ ) { - if ( mBuf[ pos ] == *c ) { + while (pos < mGapStart) { + for (c = searchChars; *c != '\0'; c++) { + if (mBuf[ pos ] == *c) { *foundPos = pos; return 1; } } pos++; } - while ( pos < mLength ) { - for ( c = searchChars; *c != '\0'; c++ ) { - if ( mBuf[ pos + gapLen ] == *c ) { + while (pos < mLength) { + for (c = searchChars; *c != '\0'; c++) { + if (mBuf[ pos + gapLen ] == *c) { *foundPos = pos; return 1; } @@ -1236,33 +1285,34 @@ int Fl_Text_Buffer::findchars_forward( int startPos, const char *searchChars, return 0; } -/* -** Search backwards in buffer for characters in "searchChars", starting -** with the character BEFORE "startPos", returning the result in "foundPos" -** returns 1 if found, 0 if not. +/** + Finds the previous occurrence of the specified characters. + Search backwards in buffer for characters in "searchChars", starting + with the character BEFORE "startPos", returning the result in "foundPos" + returns 1 if found, 0 if not. */ -int Fl_Text_Buffer::findchars_backward( int startPos, const char *searchChars, - int *foundPos ) { +int Fl_Text_Buffer::findchars_backward(int startPos, const char *searchChars, + int *foundPos) { int pos, gapLen = mGapEnd - mGapStart; const char *c; - if ( startPos == 0 ) { + if (startPos == 0) { *foundPos = 0; return 0; } pos = startPos == 0 ? 0 : startPos - 1; - while ( pos >= mGapStart ) { - for ( c = searchChars; *c != '\0'; c++ ) { - if ( mBuf[ pos + gapLen ] == *c ) { + while (pos >= mGapStart) { + for (c = searchChars; *c != '\0'; c++) { + if (mBuf[ pos + gapLen ] == *c) { *foundPos = pos; return 1; } } pos--; } - while ( pos >= 0 ) { - for ( c = searchChars; *c != '\0'; c++ ) { - if ( mBuf[ pos ] == *c ) { + while (pos >= 0) { + for (c = searchChars; *c != '\0'; c++) { + if (mBuf[ pos ] == *c) { *foundPos = pos; return 1; } @@ -1274,146 +1324,146 @@ int Fl_Text_Buffer::findchars_backward( int startPos, const char *searchChars, } /* -** A horrible design flaw in NEdit (from the very start, before we knew that -** NEdit would become so popular), is that it uses C NULL terminated strings -** to hold text. This means editing text containing NUL characters is not -** possible without special consideration. Here is the special consideration. -** The routines below maintain a special substitution-character which stands -** in for a null, and translates strings an buffers back and forth from/to -** the substituted form, figure out what to substitute, and figure out -** when we're in over our heads and no translation is possible. + A horrible design flaw in NEdit (from the very start, before we knew that + NEdit would become so popular), is that it uses C NULL terminated strings + to hold text. This means editing text containing NUL characters is not + possible without special consideration. Here is the special consideration. + The routines below maintain a special substitution-character which stands + in for a null, and translates strings an buffers back and forth from/to + the substituted form, figure out what to substitute, and figure out + when we're in over our heads and no translation is possible. */ -/* -** The primary routine for integrating new text into a text buffer with -** substitution of another character for ascii nuls. This substitutes null -** characters in the string in preparation for being copied or replaced -** into the buffer, and if neccessary, adjusts the buffer as well, in the -** event that the string contains the character it is currently using for -** substitution. Returns 0, if substitution is no longer possible -** because all non-printable characters are already in use. -*/ -int Fl_Text_Buffer::substitute_null_characters( char *string, int len ) { +/** + The primary routine for integrating new text into a text buffer with + substitution of another character for ascii nuls. This substitutes null + characters in the string in preparation for being copied or replaced + into the buffer, and if neccessary, adjusts the buffer as well, in the + event that the string contains the character it is currently using for + substitution. Returns 0, if substitution is no longer possible + because all non-printable characters are already in use. +*/ +int Fl_Text_Buffer::substitute_null_characters(char *string, int len) { char histogram[ 256 ]; /* Find out what characters the string contains */ - histogramCharacters( string, len, histogram, 1 ); + histogramCharacters(string, len, histogram, 1); /* Does the string contain the null-substitute character? If so, re- histogram the buffer text to find a character which is ok in both the string and the buffer, and change the buffer's null-substitution character. If none can be found, give up and return 0 */ - if ( histogram[ ( unsigned char ) mNullSubsChar ] != 0 ) { + if (histogram[ (unsigned char) mNullSubsChar ] != 0) { char * bufString; char newSubsChar; bufString = (char*)text(); - histogramCharacters( bufString, mLength, histogram, 0 ); - newSubsChar = chooseNullSubsChar( histogram ); - if ( newSubsChar == '\0' ) + histogramCharacters(bufString, mLength, histogram, 0); + newSubsChar = chooseNullSubsChar(histogram); + if (newSubsChar == '\0') return 0; - subsChars( bufString, mLength, mNullSubsChar, newSubsChar ); - remove_( 0, mLength ); - insert_( 0, bufString ); - free( (void *) bufString ); + subsChars(bufString, mLength, mNullSubsChar, newSubsChar); + remove_(0, mLength); + insert_(0, bufString); + free((void *) bufString); mNullSubsChar = newSubsChar; } /* If the string contains null characters, substitute them with the buffer's null substitution character */ - if ( histogram[ 0 ] != 0 ) - subsChars( string, len, '\0', mNullSubsChar ); + if (histogram[ 0 ] != 0) + subsChars(string, len, '\0', mNullSubsChar); return 1; } -/* -** Convert strings obtained from buffers which contain null characters, which -** have been substituted for by a special substitution character, back to -** a null-containing string. There is no time penalty for calling this -** routine if no substitution has been done. +/** + Converts strings obtained from buffers which contain null characters, which + have been substituted for by a special substitution character, back to + a null-containing string. There is no time penalty for calling this + routine if no substitution has been done. */ -void Fl_Text_Buffer::unsubstitute_null_characters( char *string ) { +void Fl_Text_Buffer::unsubstitute_null_characters(char *string) { register char * c, subsChar = mNullSubsChar; - if ( subsChar == '\0' ) + if (subsChar == '\0') return; - for ( c = string; *c != '\0'; c++ ) - if ( *c == subsChar ) + for (c = string; *c != '\0'; c++) + if (*c == subsChar) * c = '\0'; } -/* -** Create a pseudo-histogram of the characters in a string (don't actually -** count, because we don't want overflow, just mark the character's presence -** with a 1). If init is true, initialize the histogram before acumulating. -** if not, add the new data to an existing histogram. +/** + Creates a pseudo-histogram of the characters in a string (don't actually + count, because we don't want overflow, just mark the character's presence + with a 1). If init is true, initialize the histogram before acumulating. + if not, add the new data to an existing histogram. */ -static void histogramCharacters( const char *string, int length, char hist[ 256 ], - int init ) { +static void histogramCharacters(const char *string, int length, char hist[ 256 ], + int init) { int i; const char *c; - if ( init ) - for ( i = 0; i < 256; i++ ) + if (init) + for (i = 0; i < 256; i++) hist[ i ] = 0; - for ( c = string; c < &string[ length ]; c++ ) - hist[ *( ( unsigned char * ) c ) ] |= 1; + for (c = string; c < &string[ length ]; c++) + hist[ *((unsigned char *) c) ] |= 1; } -/* -** Substitute fromChar with toChar in string. +/** + Substitute fromChar with toChar in string. */ -static void subsChars( char *string, int length, char fromChar, char toChar ) { +static void subsChars(char *string, int length, char fromChar, char toChar) { char * c; - for ( c = string; c < &string[ length ]; c++ ) - if ( *c == fromChar ) * c = toChar; + for (c = string; c < &string[ length ]; c++) + if (*c == fromChar) * c = toChar; } -/* -** Search through ascii control characters in histogram in order of least -** likelihood of use, find an unused character to use as a stand-in for a -** null. If the character set is full (no available characters outside of -** the printable set, return the null character. +/** + Search through ascii control characters in histogram in order of least + likelihood of use, find an unused character to use as a stand-in for a + null. If the character set is full (no available characters outside of + the printable set, return the null character. */ -static char chooseNullSubsChar( char hist[ 256 ] ) { +static char chooseNullSubsChar(char hist[ 256 ]) { #define N_REPLACEMENTS 25 static char replacements[ N_REPLACEMENTS ] = {1, 2, 3, 4, 5, 6, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 11, 7}; int i; - for ( i = 0; i < N_REPLACEMENTS; i++ ) - if ( hist[ replacements[ i ] ] == 0 ) + for (i = 0; i < N_REPLACEMENTS; i++) + if (hist[ replacements[ i ] ] == 0) return replacements[ i ]; return '\0'; } -/* -** Internal (non-redisplaying) version of BufInsert. Returns the length of -** text inserted (this is just strlen(text), however this calculation can be -** expensive and the length will be required by any caller who will continue -** on to call redisplay). pos must be contiguous with the existing text in -** the buffer (i.e. not past the end). +/** + Internal (non-redisplaying) version of BufInsert. Returns the length of + text inserted (this is just strlen(text), however this calculation can be + expensive and the length will be required by any caller who will continue + on to call redisplay). pos must be contiguous with the existing text in + the buffer (i.e. not past the end). */ -int Fl_Text_Buffer::insert_( int pos, const char *s ) { - int insertedLength = strlen( s ); +int Fl_Text_Buffer::insert_(int pos, const char *s) { + int insertedLength = strlen(s); /* Prepare the buffer to receive the new text. If the new text fits in the current buffer, just move the gap (if necessary) to where the text should be inserted. If the new text is too large, reallocate the buffer with a gap large enough to accomodate the new text and a gap of PREFERRED_GAP_SIZE */ - if ( insertedLength > mGapEnd - mGapStart ) - reallocate_with_gap( pos, insertedLength + PREFERRED_GAP_SIZE ); - else if ( pos != mGapStart ) - move_gap( pos ); + if (insertedLength > mGapEnd - mGapStart) + reallocate_with_gap(pos, insertedLength + PREFERRED_GAP_SIZE); + else if (pos != mGapStart) + move_gap(pos); /* Insert the new text (pos now corresponds to the start of the gap) */ - memcpy( &mBuf[ pos ], s, insertedLength ); + memcpy(&mBuf[ pos ], s, insertedLength); mGapStart += insertedLength; mLength += insertedLength; - update_selections( pos, 0, insertedLength ); + update_selections(pos, 0, insertedLength); if (mCanUndo) { - if ( undowidget==this && undoat==pos && undoinsert ) { + if (undowidget==this && undoat==pos && undoinsert) { undoinsert += insertedLength; } else { @@ -1428,18 +1478,18 @@ int Fl_Text_Buffer::insert_( int pos, const char *s ) { return insertedLength; } -/* -** Internal (non-redisplaying) version of BufRemove. Removes the contents -** of the buffer between start and end (and moves the gap to the site of -** the delete). +/** + Internal (non-redisplaying) version of BufRemove. Removes the contents + of the buffer between start and end (and moves the gap to the site of + the delete). */ -void Fl_Text_Buffer::remove_( int start, int end ) { +void Fl_Text_Buffer::remove_(int start, int end) { /* if the gap is not contiguous to the area to remove, move it there */ if (mCanUndo) { - if ( undowidget==this && undoat==end && undocut ) { - undobuffersize( undocut+end-start+1 ); - memmove( undobuffer+end-start, undobuffer, undocut ); + if (undowidget==this && undoat==end && undocut) { + undobuffersize(undocut+end-start+1); + memmove(undobuffer+end-start, undobuffer, undocut); undocut += end-start; } else { @@ -1452,21 +1502,21 @@ void Fl_Text_Buffer::remove_( int start, int end ) { undowidget = this; } - if ( start > mGapStart ) { + if (start > mGapStart) { if (mCanUndo) - memcpy( undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start ); - move_gap( start ); + memcpy(undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start); + move_gap(start); } - else if ( end < mGapStart ) { + else if (end < mGapStart) { if (mCanUndo) - memcpy( undobuffer, mBuf+start, end-start ); - move_gap( end ); + memcpy(undobuffer, mBuf+start, end-start); + move_gap(end); } else { int prelen = mGapStart - start; if (mCanUndo) { - memcpy( undobuffer, mBuf+start, prelen ); - memcpy( undobuffer+prelen, mBuf+mGapEnd, end-start-prelen); + memcpy(undobuffer, mBuf+start, prelen); + memcpy(undobuffer+prelen, mBuf+mGapEnd, end-start-prelen); } } @@ -1478,20 +1528,20 @@ void Fl_Text_Buffer::remove_( int start, int end ) { mLength -= end - start; /* fix up any selections which might be affected by the change */ - update_selections( start, end - start, 0 ); + update_selections(start, end - start, 0); } -/* -** Insert a column of text without calling the modify callbacks. Note that -** in some pathological cases, inserting can actually decrease the size of -** the buffer because of spaces being coalesced into tabs. "nDeleted" and -** "nInserted" return the number of characters deleted and inserted beginning -** at the start of the line containing "startPos". "endPos" returns buffer -** position of the lower left edge of the inserted column (as a hint for -** routines which need to set a cursor position). -*/ -void Fl_Text_Buffer::insert_column_( int column, int startPos, const char *insText, - int *nDeleted, int *nInserted, int *endPos ) { +/** + Inserts a column of text without calling the modify callbacks. Note that + in some pathological cases, inserting can actually decrease the size of + the buffer because of spaces being coalesced into tabs. "nDeleted" and + "nInserted" return the number of characters deleted and inserted beginning + at the start of the line containing "startPos". "endPos" returns buffer + position of the lower left edge of the inserted column (as a hint for + routines which need to set a cursor position). +*/ +void Fl_Text_Buffer::insert_column_(int column, int startPos, const char *insText, + int *nDeleted, int *nInserted, int *endPos) { int nLines, start, end, insWidth, lineStart, lineEnd; int expReplLen, expInsLen, len, endOffset; char *c, *outStr, *outPtr, *expText, *insLine; @@ -1499,7 +1549,7 @@ void Fl_Text_Buffer::insert_column_( int column, int startPos, const char *insTe const char *replText; const char *insPtr; - if ( column < 0 ) + if (column < 0) column = 0; /* Allocate a buffer for the replacement string large enough to hold @@ -1512,20 +1562,20 @@ void Fl_Text_Buffer::insert_column_( int column, int startPos, const char *insTe the text beyond the inserted column. (Space for additional newlines if the inserted text extends beyond the end of the buffer is counted with the length of insText) */ - start = line_start( startPos ); - nLines = countLines( insText ) + 1; - insWidth = textWidth( insText, mTabDist, mNullSubsChar ); - end = line_end( skip_lines( start, nLines - 1 ) ); - replText = text_range( start, end ); - expText = expandTabs( replText, 0, mTabDist, mNullSubsChar, - &expReplLen ); - free( (void *) replText ); - free( (void *) expText ); - expText = expandTabs( insText, 0, mTabDist, mNullSubsChar, - &expInsLen ); - free( (void *) expText ); - outStr = (char *)malloc( expReplLen + expInsLen + - nLines * ( column + insWidth + FL_TEXT_MAX_EXP_CHAR_LEN ) + 1 ); + start = line_start(startPos); + nLines = countLines(insText) + 1; + insWidth = textWidth(insText, mTabDist, mNullSubsChar); + end = line_end(skip_lines(start, nLines - 1)); + replText = text_range(start, end); + expText = expandTabs(replText, 0, mTabDist, mNullSubsChar, + &expReplLen); + free((void *) replText); + free((void *) expText); + expText = expandTabs(insText, 0, mTabDist, mNullSubsChar, + &expInsLen); + free((void *) expText); + outStr = (char *)malloc(expReplLen + expInsLen + + nLines * (column + insWidth + FL_TEXT_MAX_EXP_CHAR_LEN) + 1); /* Loop over all lines in the buffer between start and end removing the text between rectStart and rectEnd and padding appropriately. Trim @@ -1535,46 +1585,46 @@ void Fl_Text_Buffer::insert_column_( int column, int startPos, const char *insTe lineStart = start; insPtr = insText; for (;;) { - lineEnd = line_end( lineStart ); - line = text_range( lineStart, lineEnd ); - insLine = copyLine( insPtr, &len ); + lineEnd = line_end(lineStart); + line = text_range(lineStart, lineEnd); + insLine = copyLine(insPtr, &len); insPtr += len; - insertColInLine( line, insLine, column, insWidth, mTabDist, - mUseTabs, mNullSubsChar, outPtr, &len, &endOffset ); - free( (void *) line ); - free( (void *) insLine ); - for ( c = outPtr + len - 1; c > outPtr && isspace( *c ); c-- ) + insertColInLine(line, insLine, column, insWidth, mTabDist, + mUseTabs, mNullSubsChar, outPtr, &len, &endOffset); + free((void *) line); + free((void *) insLine); + for (c = outPtr + len - 1; c > outPtr && isspace(*c); c--) len--; outPtr += len; *outPtr++ = '\n'; lineStart = lineEnd < mLength ? lineEnd + 1 : mLength; - if ( *insPtr == '\0' ) + if (*insPtr == '\0') break; insPtr++; } - if ( outPtr != outStr ) + if (outPtr != outStr) outPtr--; /* trim back off extra newline */ *outPtr = '\0'; /* replace the text between start and end with the new stuff */ - remove_( start, end ); - insert_( start, outStr ); + remove_(start, end); + insert_(start, outStr); *nInserted = outPtr - outStr; *nDeleted = end - start; - *endPos = start + ( outPtr - outStr ) - len + endOffset; - free( (void *) outStr ); + *endPos = start + (outPtr - outStr) - len + endOffset; + free((void *) outStr); } -/* -** Delete a rectangle of text without calling the modify callbacks. Returns -** the number of characters replacing those between start and end. Note that -** in some pathological cases, deleting can actually increase the size of -** the buffer because of tab expansions. "endPos" returns the buffer position -** of the point in the last line where the text was removed (as a hint for -** routines which need to position the cursor after a delete operation) -*/ -void Fl_Text_Buffer::remove_rectangular_( int start, int end, int rectStart, - int rectEnd, int *replaceLen, int *endPos ) { +/** + Deletes a rectangle of text without calling the modify callbacks. Returns + the number of characters replacing those between start and end. Note that + in some pathological cases, deleting can actually increase the size of + the buffer because of tab expansions. "endPos" returns the buffer position + of the point in the last line where the text was removed (as a hint for + routines which need to position the cursor after a delete operation) +*/ +void Fl_Text_Buffer::remove_rectangular_(int start, int end, int rectStart, + int rectEnd, int *replaceLen, int *endPos) { int nLines, lineStart, lineEnd, len, endOffset; char *outStr, *outPtr, *expText; const char *s, *line; @@ -1583,53 +1633,53 @@ void Fl_Text_Buffer::remove_rectangular_( int start, int end, int rectStart, possibly expanded tabs as well as an additional FL_TEXT_MAX_EXP_CHAR_LEN * 2 characters per line for padding where tabs and control characters cross the edges of the selection */ - start = line_start( start ); - end = line_end( end ); - nLines = count_lines( start, end ) + 1; - s = text_range( start, end ); - expText = expandTabs( s, 0, mTabDist, mNullSubsChar, &len ); - free( (void *) s ); - free( (void *) expText ); - outStr = (char *)malloc( len + nLines * FL_TEXT_MAX_EXP_CHAR_LEN * 2 + 1 ); + start = line_start(start); + end = line_end(end); + nLines = count_lines(start, end) + 1; + s = text_range(start, end); + expText = expandTabs(s, 0, mTabDist, mNullSubsChar, &len); + free((void *) s); + free((void *) expText); + outStr = (char *)malloc(len + nLines * FL_TEXT_MAX_EXP_CHAR_LEN * 2 + 1); /* loop over all lines in the buffer between start and end removing the text between rectStart and rectEnd and padding appropriately */ lineStart = start; outPtr = outStr; endOffset = 0; - while ( lineStart <= mLength && lineStart <= end ) { - lineEnd = line_end( lineStart ); - line = text_range( lineStart, lineEnd ); - deleteRectFromLine( line, rectStart, rectEnd, mTabDist, - mUseTabs, mNullSubsChar, outPtr, &len, &endOffset ); - free( (void *) line ); + while (lineStart <= mLength && lineStart <= end) { + lineEnd = line_end(lineStart); + line = text_range(lineStart, lineEnd); + deleteRectFromLine(line, rectStart, rectEnd, mTabDist, + mUseTabs, mNullSubsChar, outPtr, &len, &endOffset); + free((void *) line); outPtr += len; *outPtr++ = '\n'; lineStart = lineEnd + 1; } - if ( outPtr != outStr ) + if (outPtr != outStr) outPtr--; /* trim back off extra newline */ *outPtr = '\0'; /* replace the text between start and end with the newly created string */ - remove_( start, end ); - insert_( start, outStr ); + remove_(start, end); + insert_(start, outStr); *replaceLen = outPtr - outStr; - *endPos = start + ( outPtr - outStr ) - len + endOffset; - free( (void *) outStr ); + *endPos = start + (outPtr - outStr) - len + endOffset; + free((void *) outStr); } -/* -** Overlay a rectangular area of text without calling the modify callbacks. -** "nDeleted" and "nInserted" return the number of characters deleted and -** inserted beginning at the start of the line containing "startPos". -** "endPos" returns buffer position of the lower left edge of the inserted -** column (as a hint for routines which need to set a cursor position). +/** + Overlay a rectangular area of text without calling the modify callbacks. + "nDeleted" and "nInserted" return the number of characters deleted and + inserted beginning at the start of the line containing "startPos". + "endPos" returns buffer position of the lower left edge of the inserted + column (as a hint for routines which need to set a cursor position). */ void Fl_Text_Buffer::overlay_rectangular_(int startPos, int rectStart, int rectEnd, const char *insText, int *nDeleted, int *nInserted, - int *endPos ) { + int *endPos) { int nLines, start, end, lineStart, lineEnd; int expInsLen, len, endOffset; char *c, *outStr, *outPtr, *expText, *insLine; @@ -1645,14 +1695,14 @@ void Fl_Text_Buffer::overlay_rectangular_(int startPos, int rectStart, must be padded to align the text beyond the inserted column. (Space for additional newlines if the inserted text extends beyond the end of the buffer is counted with the length of insText) */ - start = line_start( startPos ); - nLines = countLines( insText ) + 1; - end = line_end( skip_lines( start, nLines - 1 ) ); - expText = expandTabs( insText, 0, mTabDist, mNullSubsChar, - &expInsLen ); - free( (void *) expText ); - outStr = (char *)malloc( end - start + expInsLen + - nLines * ( rectEnd + FL_TEXT_MAX_EXP_CHAR_LEN ) + 1 ); + start = line_start(startPos); + nLines = countLines(insText) + 1; + end = line_end(skip_lines(start, nLines - 1)); + expText = expandTabs(insText, 0, mTabDist, mNullSubsChar, + &expInsLen); + free((void *) expText); + outStr = (char *)malloc(end - start + expInsLen + + nLines * (rectEnd + FL_TEXT_MAX_EXP_CHAR_LEN) + 1); /* Loop over all lines in the buffer between start and end overlaying the text between rectStart and rectEnd and padding appropriately. Trim @@ -1662,47 +1712,47 @@ void Fl_Text_Buffer::overlay_rectangular_(int startPos, int rectStart, lineStart = start; insPtr = insText; for (;;) { - lineEnd = line_end( lineStart ); - line = text_range( lineStart, lineEnd ); - insLine = copyLine( insPtr, &len ); + lineEnd = line_end(lineStart); + line = text_range(lineStart, lineEnd); + insLine = copyLine(insPtr, &len); insPtr += len; - overlayRectInLine( line, insLine, rectStart, rectEnd, mTabDist, - mUseTabs, mNullSubsChar, outPtr, &len, &endOffset ); - free( (void *) line ); - free( (void *) insLine ); - for ( c = outPtr + len - 1; c > outPtr && isspace( *c ); c-- ) + overlayRectInLine(line, insLine, rectStart, rectEnd, mTabDist, + mUseTabs, mNullSubsChar, outPtr, &len, &endOffset); + free((void *) line); + free((void *) insLine); + for (c = outPtr + len - 1; c > outPtr && isspace(*c); c--) len--; outPtr += len; *outPtr++ = '\n'; lineStart = lineEnd < mLength ? lineEnd + 1 : mLength; - if ( *insPtr == '\0' ) + if (*insPtr == '\0') break; insPtr++; } - if ( outPtr != outStr ) + if (outPtr != outStr) outPtr--; /* trim back off extra newline */ *outPtr = '\0'; /* replace the text between start and end with the new stuff */ - remove_( start, end ); - insert_( start, outStr ); + remove_(start, end); + insert_(start, outStr); *nInserted = outPtr - outStr; *nDeleted = end - start; - *endPos = start + ( outPtr - outStr ) - len + endOffset; - free( (void *) outStr ); + *endPos = start + (outPtr - outStr) - len + endOffset; + free((void *) outStr); } -/* -** Insert characters from single-line string "insLine" in single-line string -** "line" at "column", leaving "insWidth" space before continuing line. -** "outLen" returns the number of characters written to "outStr", "endOffset" -** returns the number of characters from the beginning of the string to -** the right edge of the inserted text (as a hint for routines which need -** to position the cursor). -*/ -static void insertColInLine( const char *line, char *insLine, int column, int insWidth, +/** + Inserts characters from single-line string "insLine" in single-line string + "line" at "column", leaving "insWidth" space before continuing line. + "outLen" returns the number of characters written to "outStr", "endOffset" + returns the number of characters from the beginning of the string to + the right edge of the inserted text (as a hint for routines which need + to position the cursor). +*/ +static void insertColInLine(const char *line, char *insLine, int column, int insWidth, int tabDist, int useTabs, char nullSubsChar, char *outStr, int *outLen, - int *endOffset ) { + int *endOffset) { char * c, *outPtr, *retabbedStr; const char *linePtr; int indent, toIndent, len, postColIndent; @@ -1710,9 +1760,9 @@ static void insertColInLine( const char *line, char *insLine, int column, int in /* copy the line up to "column" */ outPtr = outStr; indent = 0; - for ( linePtr = line; *linePtr != '\0'; linePtr++ ) { - len = Fl_Text_Buffer::character_width( *linePtr, indent, tabDist, nullSubsChar ); - if ( indent + len > column ) + for (linePtr = line; *linePtr != '\0'; linePtr++) { + len = Fl_Text_Buffer::character_width(*linePtr, indent, tabDist, nullSubsChar); + if (indent + len > column) break; indent += len; *outPtr++ = *linePtr; @@ -1722,9 +1772,9 @@ static void insertColInLine( const char *line, char *insLine, int column, int in tab, leave it off and leave the indent short and it will get padded later. If it's a control character, insert it and adjust indent accordingly. */ - if ( indent < column && *linePtr != '\0' ) { + if (indent < column && *linePtr != '\0') { postColIndent = indent + len; - if ( *linePtr == '\t' ) + if (*linePtr == '\t') linePtr++; else { *outPtr++ = *linePtr++; @@ -1734,33 +1784,33 @@ static void insertColInLine( const char *line, char *insLine, int column, int in postColIndent = indent; /* If there's no text after the column and no text to insert, that's all */ - if ( *insLine == '\0' && *linePtr == '\0' ) { + if (*insLine == '\0' && *linePtr == '\0') { *outLen = *endOffset = outPtr - outStr; return; } /* pad out to column if text is too short */ - if ( indent < column ) { - addPadding( outPtr, indent, column, tabDist, useTabs, nullSubsChar, &len ); + if (indent < column) { + addPadding(outPtr, indent, column, tabDist, useTabs, nullSubsChar, &len); outPtr += len; indent = column; } /* Copy the text from "insLine" (if any), recalculating the tabs as if the inserted string began at column 0 to its new column destination */ - if ( *insLine != '\0' ) { - retabbedStr = realignTabs( insLine, 0, indent, tabDist, useTabs, - nullSubsChar, &len ); - for ( c = retabbedStr; *c != '\0'; c++ ) { + if (*insLine != '\0') { + retabbedStr = realignTabs(insLine, 0, indent, tabDist, useTabs, + nullSubsChar, &len); + for (c = retabbedStr; *c != '\0'; c++) { *outPtr++ = *c; - len = Fl_Text_Buffer::character_width( *c, indent, tabDist, nullSubsChar ); + len = Fl_Text_Buffer::character_width(*c, indent, tabDist, nullSubsChar); indent += len; } - free( (void *) retabbedStr ); + free((void *) retabbedStr); } /* If the original line did not extend past "column", that's all */ - if ( *linePtr == '\0' ) { + if (*linePtr == '\0') { *outLen = *endOffset = outPtr - outStr; return; } @@ -1768,31 +1818,31 @@ static void insertColInLine( const char *line, char *insLine, int column, int in /* Pad out to column + width of inserted text + (additional original offset due to non-breaking character at column) */ toIndent = column + insWidth + postColIndent - column; - addPadding( outPtr, indent, toIndent, tabDist, useTabs, nullSubsChar, &len ); + addPadding(outPtr, indent, toIndent, tabDist, useTabs, nullSubsChar, &len); outPtr += len; indent = toIndent; /* realign tabs for text beyond "column" and write it out */ - retabbedStr = realignTabs( linePtr, postColIndent, indent, tabDist, - useTabs, nullSubsChar, &len ); - strcpy( outPtr, retabbedStr ); - free( (void *) retabbedStr ); + retabbedStr = realignTabs(linePtr, postColIndent, indent, tabDist, + useTabs, nullSubsChar, &len); + strcpy(outPtr, retabbedStr); + free((void *) retabbedStr); *endOffset = outPtr - outStr; - *outLen = ( outPtr - outStr ) + len; + *outLen = (outPtr - outStr) + len; } -/* -** Remove characters in single-line string "line" between displayed positions -** "rectStart" and "rectEnd", and write the result to "outStr", which is -** assumed to be large enough to hold the returned string. Note that in -** certain cases, it is possible for the string to get longer due to -** expansion of tabs. "endOffset" returns the number of characters from -** the beginning of the string to the point where the characters were -** deleted (as a hint for routines which need to position the cursor). -*/ -static void deleteRectFromLine( const char *line, int rectStart, int rectEnd, +/** + Removes characters in single-line string "line" between displayed positions + "rectStart" and "rectEnd", and write the result to "outStr", which is + assumed to be large enough to hold the returned string. Note that in + certain cases, it is possible for the string to get longer due to + expansion of tabs. "endOffset" returns the number of characters from + the beginning of the string to the point where the characters were + deleted (as a hint for routines which need to position the cursor). +*/ +static void deleteRectFromLine(const char *line, int rectStart, int rectEnd, int tabDist, int useTabs, char nullSubsChar, char *outStr, int *outLen, - int *endOffset ) { + int *endOffset) { int indent, preRectIndent, postRectIndent, len; const char *c; char *retabbedStr, *outPtr; @@ -1800,11 +1850,11 @@ static void deleteRectFromLine( const char *line, int rectStart, int rectEnd, /* copy the line up to rectStart */ outPtr = outStr; indent = 0; - for ( c = line; *c != '\0'; c++ ) { - if ( indent > rectStart ) + for (c = line; *c != '\0'; c++) { + if (indent > rectStart) break; - len = Fl_Text_Buffer::character_width( *c, indent, tabDist, nullSubsChar ); - if ( indent + len > rectStart && ( indent == rectStart || *c == '\t' ) ) + len = Fl_Text_Buffer::character_width(*c, indent, tabDist, nullSubsChar); + if (indent + len > rectStart && (indent == rectStart || *c == '\t')) break; indent += len; *outPtr++ = *c; @@ -1812,12 +1862,12 @@ static void deleteRectFromLine( const char *line, int rectStart, int rectEnd, preRectIndent = indent; /* skip the characters between rectStart and rectEnd */ - for ( ; *c != '\0' && indent < rectEnd; c++ ) - indent += Fl_Text_Buffer::character_width( *c, indent, tabDist, nullSubsChar ); + for (; *c != '\0' && indent < rectEnd; c++) + indent += Fl_Text_Buffer::character_width(*c, indent, tabDist, nullSubsChar); postRectIndent = indent; /* If the line ended before rectEnd, there's nothing more to do */ - if ( *c == '\0' ) { + if (*c == '\0') { *outPtr = '\0'; *outLen = *endOffset = outPtr - outStr; return; @@ -1825,33 +1875,33 @@ static void deleteRectFromLine( const char *line, int rectStart, int rectEnd, /* fill in any space left by removed tabs or control characters which straddled the boundaries */ - indent = max( rectStart + postRectIndent - rectEnd, preRectIndent ); - addPadding( outPtr, preRectIndent, indent, tabDist, useTabs, nullSubsChar, - &len ); + indent = max(rectStart + postRectIndent - rectEnd, preRectIndent); + addPadding(outPtr, preRectIndent, indent, tabDist, useTabs, nullSubsChar, + &len); outPtr += len; /* Copy the rest of the line. If the indentation has changed, preserve the position of non-whitespace characters by converting tabs to spaces, then back to tabs with the correct offset */ - retabbedStr = realignTabs( c, postRectIndent, indent, tabDist, useTabs, - nullSubsChar, &len ); - strcpy( outPtr, retabbedStr ); - free( (void *) retabbedStr ); + retabbedStr = realignTabs(c, postRectIndent, indent, tabDist, useTabs, + nullSubsChar, &len); + strcpy(outPtr, retabbedStr); + free((void *) retabbedStr); *endOffset = outPtr - outStr; - *outLen = ( outPtr - outStr ) + len; + *outLen = (outPtr - outStr) + len; } -/* -** Overlay characters from single-line string "insLine" on single-line string -** "line" between displayed character offsets "rectStart" and "rectEnd". -** "outLen" returns the number of characters written to "outStr", "endOffset" -** returns the number of characters from the beginning of the string to -** the right edge of the inserted text (as a hint for routines which need -** to position the cursor). -*/ -static void overlayRectInLine( const char *line, char *insLine, int rectStart, +/** + Overlay characters from single-line string "insLine" on single-line string + "line" between displayed character offsets "rectStart" and "rectEnd". + "outLen" returns the number of characters written to "outStr", "endOffset" + returns the number of characters from the beginning of the string to + the right edge of the inserted text (as a hint for routines which need + to position the cursor). +*/ +static void overlayRectInLine(const char *line, char *insLine, int rectStart, int rectEnd, int tabDist, int useTabs, char nullSubsChar, char *outStr, - int *outLen, int *endOffset ) { + int *outLen, int *endOffset) { char * c, *outPtr, *retabbedStr; int inIndent, outIndent, len, postRectIndent; const char *linePtr; @@ -1859,9 +1909,9 @@ static void overlayRectInLine( const char *line, char *insLine, int rectStart, /* copy the line up to "rectStart" */ outPtr = outStr; inIndent = outIndent = 0; - for ( linePtr = line; *linePtr != '\0'; linePtr++ ) { - len = Fl_Text_Buffer::character_width( *linePtr, inIndent, tabDist, nullSubsChar ); - if ( inIndent + len > rectStart ) + for (linePtr = line; *linePtr != '\0'; linePtr++) { + len = Fl_Text_Buffer::character_width(*linePtr, inIndent, tabDist, nullSubsChar); + if (inIndent + len > rectStart) break; inIndent += len; outIndent += len; @@ -1872,8 +1922,8 @@ static void overlayRectInLine( const char *line, char *insLine, int rectStart, is a tab, leave it off and leave the outIndent short and it will get padded later. If it's a control character, insert it and adjust outIndent accordingly. */ - if ( inIndent < rectStart && *linePtr != '\0' ) { - if ( *linePtr == '\t' ) { + if (inIndent < rectStart && *linePtr != '\0') { + if (*linePtr == '\t') { linePtr++; inIndent += len; } else { @@ -1885,9 +1935,9 @@ static void overlayRectInLine( const char *line, char *insLine, int rectStart, /* skip the characters between rectStart and rectEnd */ postRectIndent = rectEnd; - for ( ; *linePtr != '\0'; linePtr++ ) { - inIndent += Fl_Text_Buffer::character_width( *linePtr, inIndent, tabDist, nullSubsChar ); - if ( inIndent >= rectEnd ) { + for (; *linePtr != '\0'; linePtr++) { + inIndent += Fl_Text_Buffer::character_width(*linePtr, inIndent, tabDist, nullSubsChar); + if (inIndent >= rectEnd) { linePtr++; postRectIndent = inIndent; break; @@ -1895,60 +1945,60 @@ static void overlayRectInLine( const char *line, char *insLine, int rectStart, } /* If there's no text after rectStart and no text to insert, that's all */ - if ( *insLine == '\0' && *linePtr == '\0' ) { + if (*insLine == '\0' && *linePtr == '\0') { *outLen = *endOffset = outPtr - outStr; return; } /* pad out to rectStart if text is too short */ - if ( outIndent < rectStart ) { - addPadding( outPtr, outIndent, rectStart, tabDist, useTabs, nullSubsChar, - &len ); + if (outIndent < rectStart) { + addPadding(outPtr, outIndent, rectStart, tabDist, useTabs, nullSubsChar, + &len); outPtr += len; } outIndent = rectStart; /* Copy the text from "insLine" (if any), recalculating the tabs as if the inserted string began at column 0 to its new column destination */ - if ( *insLine != '\0' ) { - retabbedStr = realignTabs( insLine, 0, rectStart, tabDist, useTabs, - nullSubsChar, &len ); - for ( c = retabbedStr; *c != '\0'; c++ ) { + if (*insLine != '\0') { + retabbedStr = realignTabs(insLine, 0, rectStart, tabDist, useTabs, + nullSubsChar, &len); + for (c = retabbedStr; *c != '\0'; c++) { *outPtr++ = *c; - len = Fl_Text_Buffer::character_width( *c, outIndent, tabDist, nullSubsChar ); + len = Fl_Text_Buffer::character_width(*c, outIndent, tabDist, nullSubsChar); outIndent += len; } - free( (void *) retabbedStr ); + free((void *) retabbedStr); } /* If the original line did not extend past "rectStart", that's all */ - if ( *linePtr == '\0' ) { + if (*linePtr == '\0') { *outLen = *endOffset = outPtr - outStr; return; } /* Pad out to rectEnd + (additional original offset due to non-breaking character at right boundary) */ - addPadding( outPtr, outIndent, postRectIndent, tabDist, useTabs, - nullSubsChar, &len ); + addPadding(outPtr, outIndent, postRectIndent, tabDist, useTabs, + nullSubsChar, &len); outPtr += len; outIndent = postRectIndent; /* copy the text beyond "rectEnd" */ - strcpy( outPtr, linePtr ); + strcpy(outPtr, linePtr); *endOffset = outPtr - outStr; - *outLen = ( outPtr - outStr ) + strlen( linePtr ); + *outLen = (outPtr - outStr) + strlen(linePtr); } -void Fl_Text_Selection::set( int startpos, int endpos ) { +void Fl_Text_Selection::set(int startpos, int endpos) { mSelected = startpos != endpos; mRectangular = 0; - mStart = min( startpos, endpos ); - mEnd = max( startpos, endpos ); + mStart = min(startpos, endpos); + mEnd = max(startpos, endpos); } -void Fl_Text_Selection::set_rectangular( int startpos, int endpos, - int rectStart, int rectEnd ) { +void Fl_Text_Selection::set_rectangular(int startpos, int endpos, + int rectStart, int rectEnd) { mSelected = rectStart < rectEnd; mRectangular = 1; mStart = startpos; @@ -1957,8 +2007,8 @@ void Fl_Text_Selection::set_rectangular( int startpos, int endpos, mRectEnd = rectEnd; } -int Fl_Text_Selection::position( int *startpos, int *endpos ) { - if ( !mSelected ) +int Fl_Text_Selection::position(int *startpos, int *endpos) { + if (!mSelected) return 0; *startpos = mStart; *endpos = mEnd; @@ -1966,97 +2016,97 @@ int Fl_Text_Selection::position( int *startpos, int *endpos ) { return 1; } -int Fl_Text_Selection::position( int *startpos, int *endpos, - int *isRect, int *rectStart, int *rectEnd ) { - if ( !mSelected ) +int Fl_Text_Selection::position(int *startpos, int *endpos, + int *isRect, int *rectStart, int *rectEnd) { + if (!mSelected) return 0; *isRect = mRectangular; *startpos = mStart; *endpos = mEnd; - if ( mRectangular ) { + if (mRectangular) { *rectStart = mRectStart; *rectEnd = mRectEnd; } return 1; } -/* -** Return true if position "pos" with indentation "dispIndex" is in -** the Fl_Text_Selection. +/** + Return true if position "pos" with indentation "dispIndex" is in + the Fl_Text_Selection. */ int Fl_Text_Selection::includes(int pos, int lineStartPos, int dispIndex) { return selected() && - ( (!rectangular() && pos >= start() && pos < end()) || + ((!rectangular() && pos >= start() && pos < end()) || (rectangular() && pos >= start() && lineStartPos <= end() && dispIndex >= rect_start() && dispIndex < rect_end()) - ); + ); } -char * Fl_Text_Buffer::selection_text_( Fl_Text_Selection *sel ) { +char * Fl_Text_Buffer::selection_text_(Fl_Text_Selection *sel) { int start, end, isRect, rectStart, rectEnd; char *s; /* If there's no selection, return an allocated empty string */ - if ( !sel->position( &start, &end, &isRect, &rectStart, &rectEnd ) ) { - s = (char *)malloc( 1 ); + if (!sel->position(&start, &end, &isRect, &rectStart, &rectEnd)) { + s = (char *)malloc(1); *s = '\0'; return s; } /* If the selection is not rectangular, return the selected range */ - if ( isRect ) - return text_in_rectangle( start, end, rectStart, rectEnd ); + if (isRect) + return text_in_rectangle(start, end, rectStart, rectEnd); else - return text_range( start, end ); + return text_range(start, end); } - -void Fl_Text_Buffer::remove_selection_( Fl_Text_Selection *sel ) { +/** Removes the text from the buffer corresponding to "sel".*/ +void Fl_Text_Buffer::remove_selection_(Fl_Text_Selection *sel) { int start, end; int isRect, rectStart, rectEnd; - if ( !sel->position( &start, &end, &isRect, &rectStart, &rectEnd ) ) + if (!sel->position(&start, &end, &isRect, &rectStart, &rectEnd)) return; - if ( isRect ) - remove_rectangular( start, end, rectStart, rectEnd ); + if (isRect) + remove_rectangular(start, end, rectStart, rectEnd); else { - remove( start, end ); + remove(start, end); //undoyankcut = undocut; } } -void Fl_Text_Buffer::replace_selection_( Fl_Text_Selection *sel, const char *s ) { +void Fl_Text_Buffer::replace_selection_(Fl_Text_Selection *sel, const char *s) { int start, end, isRect, rectStart, rectEnd; Fl_Text_Selection oldSelection = *sel; /* If there's no selection, return */ - if ( !sel->position( &start, &end, &isRect, &rectStart, &rectEnd ) ) + if (!sel->position(&start, &end, &isRect, &rectStart, &rectEnd)) return; /* Do the appropriate type of replace */ - if ( isRect ) - replace_rectangular( start, end, rectStart, rectEnd, s ); + if (isRect) + replace_rectangular(start, end, rectStart, rectEnd, s); else - replace( start, end, s ); + replace(start, end, s); /* Unselect (happens automatically in BufReplace, but BufReplaceRect can't detect when the contents of a selection goes away) */ sel->mSelected = 0; - redisplay_selection( &oldSelection, sel ); + redisplay_selection(&oldSelection, sel); } -static void addPadding( char *string, int startIndent, int toIndent, - int tabDist, int useTabs, char nullSubsChar, int *charsAdded ) { +static void addPadding(char *string, int startIndent, int toIndent, + int tabDist, int useTabs, char nullSubsChar, int *charsAdded) { char * outPtr; int len, indent; indent = startIndent; outPtr = string; - if ( useTabs ) { - while ( indent < toIndent ) { - len = Fl_Text_Buffer::character_width( '\t', indent, tabDist, nullSubsChar ); - if ( len > 1 && indent + len <= toIndent ) { + if (useTabs) { + while (indent < toIndent) { + len = Fl_Text_Buffer::character_width('\t', indent, tabDist, nullSubsChar); + if (len > 1 && indent + len <= toIndent) { *outPtr++ = '\t'; indent += len; } else { @@ -2065,7 +2115,7 @@ static void addPadding( char *string, int startIndent, int toIndent, } } } else { - while ( indent < toIndent ) { + while (indent < toIndent) { *outPtr++ = ' '; indent++; } @@ -2073,22 +2123,22 @@ static void addPadding( char *string, int startIndent, int toIndent, *charsAdded = outPtr - string; } -/* -** Call the stored modify callback procedure(s) for this buffer to update the -** changed area(s) on the screen and any other listeners. +/** + Calls the stored modify callback procedure(s) for this buffer to update the + changed area(s) on the screen and any other listeners. */ -void Fl_Text_Buffer::call_modify_callbacks( int pos, int nDeleted, - int nInserted, int nRestyled, const char *deletedText ) { +void Fl_Text_Buffer::call_modify_callbacks(int pos, int nDeleted, + int nInserted, int nRestyled, const char *deletedText) { int i; - for ( i = 0; i < mNModifyProcs; i++ ) - ( *mNodifyProcs[ i ] ) ( pos, nInserted, nDeleted, nRestyled, - deletedText, mCbArgs[ i ] ); + for (i = 0; i < mNModifyProcs; i++) + (*mNodifyProcs[ i ]) (pos, nInserted, nDeleted, nRestyled, + deletedText, mCbArgs[ i ]); } -/* -** Call the stored pre-delete callback procedure(s) for this buffer to update -** the changed area(s) on the screen and any other listeners. +/** + Calls the stored pre-delete callback procedure(s) for this buffer to update + the changed area(s) on the screen and any other listeners. */ void Fl_Text_Buffer::call_predelete_callbacks(int pos, int nDeleted) { int i; @@ -2097,12 +2147,12 @@ void Fl_Text_Buffer::call_predelete_callbacks(int pos, int nDeleted) { (*mPredeleteProcs[i])(pos, nDeleted, mPredeleteCbArgs[i]); } -/* -** Call the stored redisplay procedure(s) for this buffer to update the -** screen for a change in a selection. +/** + Calls the stored redisplay procedure(s) for this buffer to update the + screen for a change in a selection. */ -void Fl_Text_Buffer::redisplay_selection( Fl_Text_Selection *oldSelection, - Fl_Text_Selection *newSelection ) { +void Fl_Text_Buffer::redisplay_selection(Fl_Text_Selection *oldSelection, + Fl_Text_Selection *newSelection) { int oldStart, oldEnd, newStart, newEnd, ch1Start, ch1End, ch2Start, ch2End; /* If either selection is rectangular, add an additional character to @@ -2112,146 +2162,147 @@ void Fl_Text_Buffer::redisplay_selection( Fl_Text_Selection *oldSelection, newStart = newSelection->mStart; oldEnd = oldSelection->mEnd; newEnd = newSelection->mEnd; - if ( oldSelection->mRectangular ) + if (oldSelection->mRectangular) oldEnd++; - if ( newSelection->mRectangular ) + if (newSelection->mRectangular) newEnd++; /* If the old or new selection is unselected, just redisplay the single area that is (was) selected and return */ - if ( !oldSelection->mSelected && !newSelection->mSelected ) + if (!oldSelection->mSelected && !newSelection->mSelected) return; - if ( !oldSelection->mSelected ) { - call_modify_callbacks( newStart, 0, 0, newEnd - newStart, NULL ); + if (!oldSelection->mSelected) { + call_modify_callbacks(newStart, 0, 0, newEnd - newStart, NULL); return; } - if ( !newSelection->mSelected ) { - call_modify_callbacks( oldStart, 0, 0, oldEnd - oldStart, NULL ); + if (!newSelection->mSelected) { + call_modify_callbacks(oldStart, 0, 0, oldEnd - oldStart, NULL); return; } /* If the selection changed from normal to rectangular or visa versa, or if a rectangular selection changed boundaries, redisplay everything */ - if ( ( oldSelection->mRectangular && !newSelection->mRectangular ) || - ( !oldSelection->mRectangular && newSelection->mRectangular ) || - ( oldSelection->mRectangular && ( - ( oldSelection->mRectStart != newSelection->mRectStart ) || - ( oldSelection->mRectEnd != newSelection->mRectEnd ) ) ) ) { - call_modify_callbacks( min( oldStart, newStart ), 0, 0, - max( oldEnd, newEnd ) - min( oldStart, newStart ), NULL ); + if ((oldSelection->mRectangular && !newSelection->mRectangular) || + (!oldSelection->mRectangular && newSelection->mRectangular) || + (oldSelection->mRectangular && ( + (oldSelection->mRectStart != newSelection->mRectStart) || + (oldSelection->mRectEnd != newSelection->mRectEnd)))) { + call_modify_callbacks(min(oldStart, newStart), 0, 0, + max(oldEnd, newEnd) - min(oldStart, newStart), NULL); return; } /* If the selections are non-contiguous, do two separate updates and return */ - if ( oldEnd < newStart || newEnd < oldStart ) { - call_modify_callbacks( oldStart, 0, 0, oldEnd - oldStart, NULL ); - call_modify_callbacks( newStart, 0, 0, newEnd - newStart, NULL ); + if (oldEnd < newStart || newEnd < oldStart) { + call_modify_callbacks(oldStart, 0, 0, oldEnd - oldStart, NULL); + call_modify_callbacks(newStart, 0, 0, newEnd - newStart, NULL); return; } /* Otherwise, separate into 3 separate regions: ch1, and ch2 (the two changed areas), and the unchanged area of their intersection, and update only the changed area(s) */ - ch1Start = min( oldStart, newStart ); - ch2End = max( oldEnd, newEnd ); - ch1End = max( oldStart, newStart ); - ch2Start = min( oldEnd, newEnd ); - if ( ch1Start != ch1End ) - call_modify_callbacks( ch1Start, 0, 0, ch1End - ch1Start, NULL ); - if ( ch2Start != ch2End ) - call_modify_callbacks( ch2Start, 0, 0, ch2End - ch2Start, NULL ); + ch1Start = min(oldStart, newStart); + ch2End = max(oldEnd, newEnd); + ch1End = max(oldStart, newStart); + ch2Start = min(oldEnd, newEnd); + if (ch1Start != ch1End) + call_modify_callbacks(ch1Start, 0, 0, ch1End - ch1Start, NULL); + if (ch2Start != ch2End) + call_modify_callbacks(ch2Start, 0, 0, ch2End - ch2Start, NULL); } -void Fl_Text_Buffer::move_gap( int pos ) { +void Fl_Text_Buffer::move_gap(int pos) { int gapLen = mGapEnd - mGapStart; - if ( pos > mGapStart ) - memmove( &mBuf[ mGapStart ], &mBuf[ mGapEnd ], - pos - mGapStart ); + if (pos > mGapStart) + memmove(&mBuf[ mGapStart ], &mBuf[ mGapEnd ], + pos - mGapStart); else - memmove( &mBuf[ pos + gapLen ], &mBuf[ pos ], mGapStart - pos ); + memmove(&mBuf[ pos + gapLen ], &mBuf[ pos ], mGapStart - pos); mGapEnd += pos - mGapStart; mGapStart += pos - mGapStart; } /* -** reallocate the text storage in "buf" to have a gap starting at "newGapStart" -** and a gap size of "newGapLen", preserving the buffer's current contents. + reallocate the text storage in "buf" to have a gap starting at "newGapStart" + and a gap size of "newGapLen", preserving the buffer's current contents. */ -void Fl_Text_Buffer::reallocate_with_gap( int newGapStart, int newGapLen ) { +void Fl_Text_Buffer::reallocate_with_gap(int newGapStart, int newGapLen) { char * newBuf; int newGapEnd; - newBuf = (char *)malloc( mLength + newGapLen ); + newBuf = (char *)malloc(mLength + newGapLen); newGapEnd = newGapStart + newGapLen; - if ( newGapStart <= mGapStart ) { - memcpy( newBuf, mBuf, newGapStart ); - memcpy( &newBuf[ newGapEnd ], &mBuf[ newGapStart ], - mGapStart - newGapStart ); - memcpy( &newBuf[ newGapEnd + mGapStart - newGapStart ], - &mBuf[ mGapEnd ], mLength - mGapStart ); + if (newGapStart <= mGapStart) { + memcpy(newBuf, mBuf, newGapStart); + memcpy(&newBuf[ newGapEnd ], &mBuf[ newGapStart ], + mGapStart - newGapStart); + memcpy(&newBuf[ newGapEnd + mGapStart - newGapStart ], + &mBuf[ mGapEnd ], mLength - mGapStart); } else { /* newGapStart > mGapStart */ - memcpy( newBuf, mBuf, mGapStart ); - memcpy( &newBuf[ mGapStart ], &mBuf[ mGapEnd ], - newGapStart - mGapStart ); - memcpy( &newBuf[ newGapEnd ], + memcpy(newBuf, mBuf, mGapStart); + memcpy(&newBuf[ mGapStart ], &mBuf[ mGapEnd ], + newGapStart - mGapStart); + memcpy(&newBuf[ newGapEnd ], &mBuf[ mGapEnd + newGapStart - mGapStart ], - mLength - newGapStart ); + mLength - newGapStart); } - free( (void *) mBuf ); + free((void *) mBuf); mBuf = newBuf; mGapStart = newGapStart; mGapEnd = newGapEnd; #ifdef PURIFY -{int i; for ( i = mGapStart; i < mGapEnd; i++ ) mBuf[ i ] = '.'; } +{int i; for (i = mGapStart; i < mGapEnd; i++) mBuf[ i ] = '.'; } #endif } /* -** Update all of the selections in "buf" for changes in the buffer's text + Update all of the selections in "buf" for changes in the buffer's text */ -void Fl_Text_Buffer::update_selections( int pos, int nDeleted, - int nInserted ) { - mPrimary.update( pos, nDeleted, nInserted ); - mSecondary.update( pos, nDeleted, nInserted ); - mHighlight.update( pos, nDeleted, nInserted ); +void Fl_Text_Buffer::update_selections(int pos, int nDeleted, + int nInserted) { + mPrimary.update(pos, nDeleted, nInserted); + mSecondary.update(pos, nDeleted, nInserted); + mHighlight.update(pos, nDeleted, nInserted); } /* -** Update an individual selection for changes in the corresponding text + Update an individual selection for changes in the corresponding text */ -void Fl_Text_Selection::update( int pos, int nDeleted, - int nInserted ) { - if ( !mSelected || pos > mEnd ) +void Fl_Text_Selection::update(int pos, int nDeleted, + int nInserted) { + if (!mSelected || pos > mEnd) return; - if ( pos + nDeleted <= mStart ) { + if (pos + nDeleted <= mStart) { mStart += nInserted - nDeleted; mEnd += nInserted - nDeleted; - } else if ( pos <= mStart && pos + nDeleted >= mEnd ) { + } else if (pos <= mStart && pos + nDeleted >= mEnd) { mStart = pos; mEnd = pos; mSelected = 0; - } else if ( pos <= mStart && pos + nDeleted < mEnd ) { + } else if (pos <= mStart && pos + nDeleted < mEnd) { mStart = pos; mEnd = nInserted + mEnd - nDeleted; - } else if ( pos < mEnd ) { + } else if (pos < mEnd) { mEnd += nInserted - nDeleted; - if ( mEnd <= mStart ) + if (mEnd <= mStart) mSelected = 0; } } -/* -** Search forwards in buffer "buf" for character "searchChar", starting -** with the character "startPos", and returning the result in "foundPos" -** returns 1 if found, 0 if not. (The difference between this and -** BufSearchForward is that it's optimized for single characters. The -** overall performance of the text widget is dependent on its ability to -** count lines quickly, hence searching for a single character: newline) -*/ -int Fl_Text_Buffer::findchar_forward( int startPos, char searchChar, - int *foundPos ) { +/** + Finds the next occurrence of the specified character. + Search forwards in buffer for character "searchChar", starting + with the character "startPos", and returning the result in "foundPos" + returns 1 if found, 0 if not. (The difference between this and + BufSearchForward is that it's optimized for single characters. The + overall performance of the text widget is dependent on its ability to + count lines quickly, hence searching for a single character: newline) +*/ +int Fl_Text_Buffer::findchar_forward(int startPos, char searchChar, + int *foundPos) { int pos, gapLen = mGapEnd - mGapStart; if (startPos < 0 || startPos >= mLength) { @@ -2260,15 +2311,15 @@ int Fl_Text_Buffer::findchar_forward( int startPos, char searchChar, } pos = startPos; - while ( pos < mGapStart ) { - if ( mBuf[ pos ] == searchChar ) { + while (pos < mGapStart) { + if (mBuf[ pos ] == searchChar) { *foundPos = pos; return 1; } pos++; } - while ( pos < mLength ) { - if ( mBuf[ pos + gapLen ] == searchChar ) { + while (pos < mLength) { + if (mBuf[ pos + gapLen ] == searchChar) { *foundPos = pos; return 1; } @@ -2278,32 +2329,32 @@ int Fl_Text_Buffer::findchar_forward( int startPos, char searchChar, return 0; } -/* -** Search backwards in buffer "buf" for character "searchChar", starting -** with the character BEFORE "startPos", returning the result in "foundPos" -** returns 1 if found, 0 if not. (The difference between this and -** BufSearchBackward is that it's optimized for single characters. The -** overall performance of the text widget is dependent on its ability to -** count lines quickly, hence searching for a single character: newline) -*/ -int Fl_Text_Buffer::findchar_backward( int startPos, char searchChar, - int *foundPos ) { +/** + Search backwards in buffer "buf" for character "searchChar", starting + with the character BEFORE "startPos", returning the result in "foundPos" + returns 1 if found, 0 if not. (The difference between this and + BufSearchBackward is that it's optimized for single characters. The + overall performance of the text widget is dependent on its ability to + count lines quickly, hence searching for a single character: newline) +*/ +int Fl_Text_Buffer::findchar_backward(int startPos, char searchChar, + int *foundPos) { int pos, gapLen = mGapEnd - mGapStart; - if ( startPos <= 0 || startPos > mLength ) { + if (startPos <= 0 || startPos > mLength) { *foundPos = 0; return 0; } pos = startPos - 1; - while ( pos >= mGapStart ) { - if ( mBuf[ pos + gapLen ] == searchChar ) { + while (pos >= mGapStart) { + if (mBuf[ pos + gapLen ] == searchChar) { *foundPos = pos; return 1; } pos--; } - while ( pos >= 0 ) { - if ( mBuf[ pos ] == searchChar ) { + while (pos >= 0) { + if (mBuf[ pos ] == searchChar) { *foundPos = pos; return 1; } @@ -2314,82 +2365,82 @@ int Fl_Text_Buffer::findchar_backward( int startPos, char searchChar, } /* -** Copy from "text" to end up to but not including newline (or end of "text") -** and return the copy as the function value, and the length of the line in -** "lineLen" + Copy from "text" to end up to but not including newline (or end of "text") + and return the copy as the function value, and the length of the line in + "lineLen" */ -static char *copyLine( const char *text, int *lineLen ) { +static char *copyLine(const char *text, int *lineLen) { int len = 0; const char *c; char *outStr; - for ( c = text; *c != '\0' && *c != '\n'; c++ ) + for (c = text; *c != '\0' && *c != '\n'; c++) len++; - outStr = (char *)malloc( len + 1 ); - strlcpy( outStr, text, len + 1); + outStr = (char *)malloc(len + 1); + strlcpy(outStr, text, len + 1); *lineLen = len; return outStr; } /* -** Count the number of newlines in a null-terminated text string; + Count the number of newlines in a null-terminated text string; */ -static int countLines( const char *string ) { +static int countLines(const char *string) { const char * c; int lineCount = 0; - for ( c = string; *c != '\0'; c++ ) - if ( *c == '\n' ) lineCount++; + for (c = string; *c != '\0'; c++) + if (*c == '\n') lineCount++; return lineCount; } /* -** Measure the width in displayed characters of string "text" + Measure the width in displayed characters of string "text" */ -static int textWidth( const char *text, int tabDist, char nullSubsChar ) { +static int textWidth(const char *text, int tabDist, char nullSubsChar) { int width = 0, maxWidth = 0; const char *c; - for ( c = text; *c != '\0'; c++ ) { - if ( *c == '\n' ) { - if ( width > maxWidth ) + for (c = text; *c != '\0'; c++) { + if (*c == '\n') { + if (width > maxWidth) maxWidth = width; width = 0; } else - width += Fl_Text_Buffer::character_width( *c, width, tabDist, nullSubsChar ); + width += Fl_Text_Buffer::character_width(*c, width, tabDist, nullSubsChar); } - if ( width > maxWidth ) + if (width > maxWidth) return width; return maxWidth; } /* -** Find the first and last character position in a line within a rectangular -** selection (for copying). Includes tabs which cross rectStart, but not -** control characters which do so. Leaves off tabs which cross rectEnd. + Find the first and last character position in a line within a rectangular + selection (for copying). Includes tabs which cross rectStart, but not + control characters which do so. Leaves off tabs which cross rectEnd. ** -** Technically, the calling routine should convert tab characters which -** cross the right boundary of the selection to spaces which line up with -** the edge of the selection. Unfortunately, the additional memory -** management required in the parent routine to allow for the changes -** in string size is not worth all the extra work just for a couple of -** shifted characters, so if a tab protrudes, just lop it off and hope -** that there are other characters in the selection to establish the right -** margin for subsequent columnar pastes of this data. -*/ -void Fl_Text_Buffer::rectangular_selection_boundaries( int lineStartPos, - int rectStart, int rectEnd, int *selStart, int *selEnd ) { + Technically, the calling routine should convert tab characters which + cross the right boundary of the selection to spaces which line up with + the edge of the selection. Unfortunately, the additional memory + management required in the parent routine to allow for the changes + in string size is not worth all the extra work just for a couple of + shifted characters, so if a tab protrudes, just lop it off and hope + that there are other characters in the selection to establish the right + margin for subsequent columnar pastes of this data. +*/ +void Fl_Text_Buffer::rectangular_selection_boundaries(int lineStartPos, + int rectStart, int rectEnd, int *selStart, int *selEnd) { int pos, width, indent = 0; char c; /* find the start of the selection */ - for ( pos = lineStartPos; pos < mLength; pos++ ) { - c = character( pos ); - if ( c == '\n' ) + for (pos = lineStartPos; pos < mLength; pos++) { + c = character(pos); + if (c == '\n') break; - width = Fl_Text_Buffer::character_width( c, indent, mTabDist, mNullSubsChar ); - if ( indent + width > rectStart ) { - if ( indent != rectStart && c != '\t' ) { + width = Fl_Text_Buffer::character_width(c, indent, mTabDist, mNullSubsChar); + if (indent + width > rectStart) { + if (indent != rectStart && c != '\t') { pos++; indent += width; } @@ -2400,14 +2451,14 @@ void Fl_Text_Buffer::rectangular_selection_boundaries( int lineStartPos, *selStart = pos; /* find the end */ - for ( ; pos < mLength; pos++ ) { - c = character( pos ); - if ( c == '\n' ) + for (; pos < mLength; pos++) { + c = character(pos); + if (c == '\n') break; - width = Fl_Text_Buffer::character_width( c, indent, mTabDist, mNullSubsChar ); + width = Fl_Text_Buffer::character_width(c, indent, mTabDist, mNullSubsChar); indent += width; - if ( indent > rectEnd ) { - if ( indent - width != rectEnd && c != '\t' ) + if (indent > rectEnd) { + if (indent - width != rectEnd && c != '\t') pos++; break; } @@ -2416,78 +2467,78 @@ void Fl_Text_Buffer::rectangular_selection_boundaries( int lineStartPos, } /* -** Adjust the space and tab characters from string "text" so that non-white -** characters remain stationary when the text is shifted from starting at -** "origIndent" to starting at "newIndent". Returns an allocated string -** which must be freed by the caller with XtFree. + Adjust the space and tab characters from string "text" so that non-white + characters remain stationary when the text is shifted from starting at + "origIndent" to starting at "newIndent". Returns an allocated string + which must be freed by the caller with XtFree. */ -static char *realignTabs( const char *text, int origIndent, int newIndent, - int tabDist, int useTabs, char nullSubsChar, int *newLength ) { +static char *realignTabs(const char *text, int origIndent, int newIndent, + int tabDist, int useTabs, char nullSubsChar, int *newLength) { char * expStr, *outStr; int len; /* If the tabs settings are the same, retain original tabs */ - if ( origIndent % tabDist == newIndent % tabDist ) { - len = strlen( text ); - outStr = (char *)malloc( len + 1 ); - strcpy( outStr, text ); + if (origIndent % tabDist == newIndent % tabDist) { + len = strlen(text); + outStr = (char *)malloc(len + 1); + strcpy(outStr, text); *newLength = len; return outStr; } /* If the tab settings are not the same, brutally convert tabs to spaces, then back to tabs in the new position */ - expStr = expandTabs( text, origIndent, tabDist, nullSubsChar, &len ); - if ( !useTabs ) { + expStr = expandTabs(text, origIndent, tabDist, nullSubsChar, &len); + if (!useTabs) { *newLength = len; return expStr; } - outStr = unexpandTabs( expStr, newIndent, tabDist, nullSubsChar, newLength ); - free( (void *) expStr ); + outStr = unexpandTabs(expStr, newIndent, tabDist, nullSubsChar, newLength); + free((void *) expStr); return outStr; } /* -** Expand tabs to spaces for a block of text. The additional parameter -** "startIndent" if nonzero, indicates that the text is a rectangular selection -** beginning at column "startIndent" + Expand tabs to spaces for a block of text. The additional parameter + "startIndent" if nonzero, indicates that the text is a rectangular selection + beginning at column "startIndent" */ -static char *expandTabs( const char *text, int startIndent, int tabDist, - char nullSubsChar, int *newLen ) { +static char *expandTabs(const char *text, int startIndent, int tabDist, + char nullSubsChar, int *newLen) { char * outStr, *outPtr; const char *c; int indent, len, outLen = 0; /* rehearse the expansion to figure out length for output string */ indent = startIndent; - for ( c = text; *c != '\0'; c++ ) { - if ( *c == '\t' ) { - len = Fl_Text_Buffer::character_width( *c, indent, tabDist, nullSubsChar ); + for (c = text; *c != '\0'; c++) { + if (*c == '\t') { + len = Fl_Text_Buffer::character_width(*c, indent, tabDist, nullSubsChar); outLen += len; indent += len; - } else if ( *c == '\n' ) { + } else if (*c == '\n') { indent = startIndent; outLen++; } else { - indent += Fl_Text_Buffer::character_width( *c, indent, tabDist, nullSubsChar ); + indent += Fl_Text_Buffer::character_width(*c, indent, tabDist, nullSubsChar); outLen++; } } /* do the expansion */ - outStr = (char *)malloc( outLen + 1 ); + outStr = (char *)malloc(outLen + 1); outPtr = outStr; indent = startIndent; - for ( c = text; *c != '\0'; c++ ) { - if ( *c == '\t' ) { - len = Fl_Text_Buffer::expand_character( *c, indent, outPtr, tabDist, nullSubsChar ); + for (c = text; *c != '\0'; c++) { + if (*c == '\t') { + len = Fl_Text_Buffer::expand_character(*c, indent, outPtr, tabDist, nullSubsChar); outPtr += len; indent += len; - } else if ( *c == '\n' ) { + } else if (*c == '\n') { indent = startIndent; *outPtr++ = *c; } else { - indent += Fl_Text_Buffer::character_width( *c, indent, tabDist, nullSubsChar ); + indent += Fl_Text_Buffer::character_width(*c, indent, tabDist, nullSubsChar); *outPtr++ = *c; } } @@ -2497,23 +2548,23 @@ static char *expandTabs( const char *text, int startIndent, int tabDist, } /* -** Convert sequences of spaces into tabs. The threshold for conversion is -** when 3 or more spaces can be converted into a single tab, this avoids -** converting double spaces after a period withing a block of text. + Convert sequences of spaces into tabs. The threshold for conversion is + when 3 or more spaces can be converted into a single tab, this avoids + converting double spaces after a period withing a block of text. */ -static char *unexpandTabs( char *text, int startIndent, int tabDist, - char nullSubsChar, int *newLen ) { +static char *unexpandTabs(char *text, int startIndent, int tabDist, + char nullSubsChar, int *newLen) { char * outStr, *outPtr, *c, expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ]; int indent, len; - outStr = (char *)malloc( strlen( text ) + 1 ); + outStr = (char *)malloc(strlen(text) + 1); outPtr = outStr; indent = startIndent; - for ( c = text; *c != '\0'; ) { - if ( *c == ' ' ) { - len = Fl_Text_Buffer::expand_character( '\t', indent, expandedChar, tabDist, - nullSubsChar ); - if ( len >= 3 && !strncmp( c, expandedChar, len ) ) { + for (c = text; *c != '\0';) { + if (*c == ' ') { + len = Fl_Text_Buffer::expand_character('\t', indent, expandedChar, tabDist, + nullSubsChar); + if (len >= 3 && !strncmp(c, expandedChar, len)) { c += len; *outPtr++ = '\t'; indent += len; @@ -2521,7 +2572,7 @@ static char *unexpandTabs( char *text, int startIndent, int tabDist, *outPtr++ = *c++; indent++; } - } else if ( *c == '\n' ) { + } else if (*c == '\n') { indent = startIndent; *outPtr++ = *c++; } else { @@ -2534,15 +2585,21 @@ static char *unexpandTabs( char *text, int startIndent, int tabDist, return outStr; } -static int max( int i1, int i2 ) { +static int max(int i1, int i2) { return i1 >= i2 ? i1 : i2; } -static int min( int i1, int i2 ) { +static int min(int i1, int i2) { return i1 <= i2 ? i1 : i2; } int +/** + Inserts a file at the specified position. Returns 0 on success, + non-zero on error (strerror() contains reason). 1 indicates open + for read failed (no data loaded). 2 indicates error occurred + while reading data (data was partially loaded). +*/ Fl_Text_Buffer::insertfile(const char *file, int pos, int buflen) { FILE *fp; int r; if (!(fp = fl_fopen(file, "r"))) return 1; @@ -2559,6 +2616,12 @@ Fl_Text_Buffer::insertfile(const char *file, int pos, int buflen) { } int +/** + Writes the specified portions of the file to a file. Returns 0 on success, non-zero + on error (strerror() contains reason). 1 indicates open for write failed + (no data saved). 2 indicates error occurred while writing data + (data was partially saved). +*/ Fl_Text_Buffer::outputfile(const char *file, int start, int end, int buflen) { FILE *fp; if (!(fp = fl_fopen(file, "w"))) return 1; diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index dd5dc9f9f..d3b2eb69e 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -98,6 +98,7 @@ static int utf_len(char c) return 0; } +/** Creates a new text display widget.*/ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l) : Fl_Group(X, Y, W, H, l) { int i; @@ -172,10 +173,9 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l) mSuppressResync = mNLinesDeleted = mModifyingTabDistance = 0; } -/* -** Free a text display and release its associated memory. Note, the text -** BUFFER that the text display displays is a separate entity and is not -** freed, nor are the style buffer or style table. +/** Free a text display and release its associated memory. Note, the text + BUFFER that the text display displays is a separate entity and is not + freed, nor are the style buffer or style table. */ Fl_Text_Display::~Fl_Text_Display() { if (scroll_direction) { @@ -189,8 +189,8 @@ Fl_Text_Display::~Fl_Text_Display() { if (mLineStarts) delete[] mLineStarts; } -/* -** Attach a text buffer to display, replacing the current buffer (if any) +/** + Attach a text buffer to display, replacing the current buffer (if any) */ void Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) { /* If the text display is already displaying a buffer, clear it off @@ -218,21 +218,20 @@ void Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) { resize(x(), y(), w(), h()); } -/* -** Attach (or remove) highlight information in text display and redisplay. -** Highlighting information consists of a style buffer which parallels the -** normal text buffer, but codes font and color information for the display; -** a style table which translates style buffer codes (indexed by buffer -** character - 'A') into fonts and colors; and a callback mechanism for -** as-needed highlighting, triggered by a style buffer entry of -** "unfinishedStyle". Style buffer can trigger additional redisplay during -** a normal buffer modification if the buffer contains a primary Fl_Text_Selection -** (see extendRangeForStyleMods for more information on this protocol). -** -** Style buffers, tables and their associated memory are managed by the caller. +/** + Attach (or remove) highlight information in text display and redisplay. + Highlighting information consists of a style buffer which parallels the + normal text buffer, but codes font and color information for the display; + a style table which translates style buffer codes (indexed by buffer + character - 'A') into fonts and colors; and a callback mechanism for + as-needed highlighting, triggered by a style buffer entry of + "unfinishedStyle". Style buffer can trigger additional redisplay during + a normal buffer modification if the buffer contains a primary Fl_Text_Selection + (see extendRangeForStyleMods for more information on this protocol). + + Style buffers, tables and their associated memory are managed by the caller. */ -void -Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer, +void Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer, const Style_Table_Entry *styleTable, int nStyles, char unfinishedStyle, Unfinished_Style_Cb unfinishedHighlightCB, @@ -256,8 +255,8 @@ Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer, #if 0 // FIXME: this is in nedit code -- is it needed? -/* -** Change the (non highlight) font +/** + Change the (non highlight) font */ void TextDSetFont(textDisp *textD, XFontStruct *fontStruct) { Display *display = XtDisplay(textD->w); @@ -379,8 +378,8 @@ int Fl_Text_Display::longest_vline() { return longest; } -/* -** Change the size of the displayed text area +/** + Change the size of the displayed text area */ void Fl_Text_Display::resize(int X, int Y, int W, int H) { #ifdef DEBUG @@ -543,9 +542,9 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) { update_h_scrollbar(); } -/* -** Refresh a rectangle of the text display. left and top are in coordinates of -** the text drawing window +/** + Refresh a rectangle of the text display. left and top are in coordinates of + the text drawing window */ void Fl_Text_Display::draw_text( int left, int top, int width, int height ) { int fontHeight, firstLine, lastLine, line; @@ -568,6 +567,7 @@ void Fl_Text_Display::draw_text( int left, int top, int width, int height ) { fl_pop_clip(); } +/** Marks text from start to end as needing a redraw.*/ void Fl_Text_Display::redisplay_range(int startpos, int endpos) { int ok = 0; while (!ok && startpos > 0) { @@ -602,12 +602,12 @@ void Fl_Text_Display::redisplay_range(int startpos, int endpos) { } damage(FL_DAMAGE_SCROLL); } -/* -** Refresh all of the text between buffer positions "start" and "end" -** not including the character at the position "end". -** If end points beyond the end of the buffer, refresh the whole display -** after pos, including blank lines which are not technically part of -** any range of characters. +/** + Refresh all of the text between buffer positions "start" and "end" + not including the character at the position "end". + If end points beyond the end of the buffer, refresh the whole display + after pos, including blank lines which are not technically part of + any range of characters. */ void Fl_Text_Display::draw_range(int startpos, int endpos) { int i, startLine, lastLine, startIndex, endIndex; @@ -664,9 +664,7 @@ void Fl_Text_Display::draw_range(int startpos, int endpos) { draw_vline( lastLine, 0, INT_MAX, 0, endIndex ); } -/* -** Set the position of the text insertion cursor for text display -*/ +/** Sets the position of the text insertion cursor for text display */ void Fl_Text_Display::insert_position( int newPos ) { /* make sure new position is ok, do nothing if it hasn't changed */ if ( newPos == mCursorPos ) @@ -685,17 +683,39 @@ void Fl_Text_Display::insert_position( int newPos ) { /* draw cursor at its new position */ redisplay_range(mCursorPos - 1, mCursorPos + 1); // FIXME utf8 } - +/** Shows the text cursor */ void Fl_Text_Display::show_cursor(int b) { mCursorOn = b; redisplay_range(mCursorPos - 1, mCursorPos + 1); // FIXME utf8 } +/** + Sets the text cursor style to one of the following: + + <UL> + + <LI>Fl_Text_Display::NORMAL_CURSOR - Shows an I beam. + + <LI>Fl_Text_Display::CARET_CURSOR - Shows a caret under the text. + + <LI>Fl_Text_Display::DIM_CURSOR - Shows a dimmed I beam. + + <LI>Fl_Text_Display::BLOCK_CURSOR - Shows an unfilled box around the current + character. + + <LI>Fl_Text_Display::HEAVY_CURSOR - Shows a thick I beam. + + </UL> +*/ void Fl_Text_Display::cursor_style(int style) { mCursorStyle = style; if (mCursorOn) show_cursor(); } +/** + If <i>mode</i> is not zero, this call enables automatic word wrapping at column <i>pos</i>. + Word-wrapping does not change the text buffer itself, only the way that the text is displayed. +*/ void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) { mWrapMargin = wrapMargin; mContinuousWrap = wrap; @@ -726,11 +746,11 @@ void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) { resize(x(), y(), w(), h()); } -/* -** Insert "text" at the current cursor location. This has the same -** effect as inserting the text into the buffer using BufInsert and -** then moving the insert position after the newly inserted text, except -** that it's optimized to do less redrawing. +/** + Inserts "text" at the current cursor location. This has the same + effect as inserting the text into the buffer using BufInsert and + then moving the insert position after the newly inserted text, except + that it's optimized to do less redrawing. */ void Fl_Text_Display::insert(const char* text) { int pos = mCursorPos; @@ -740,10 +760,7 @@ void Fl_Text_Display::insert(const char* text) { mCursorToHint = NO_HINT; } -/* -** Insert "text" (which must not contain newlines), overstriking the current -** cursor location. -*/ +/** Replaces text at the current insert position.*/ void Fl_Text_Display::overstrike(const char* text) { int startPos = mCursorPos; Fl_Text_Buffer *buf = mBuffer; @@ -794,12 +811,12 @@ void Fl_Text_Display::overstrike(const char* text) { delete [] paddedText; } -/* -** Translate a buffer text position to the XY location where the top left -** of the cursor would be positioned to point to that character. Returns -** 0 if the position is not displayed because it is VERTICALLY out -** of view. If the position is horizontally out of view, returns the -** X coordinate where the position would be if it were visible. +/** + Translate a buffer text position to the XY location where the top left + of the cursor would be positioned to point to that character. Returns + 0 if the position is not displayed because it is VERTICALLY out + of view. If the position is horizontally out of view, returns the + X coordinate where the position would be if it were visible. */ int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) { @@ -872,13 +889,13 @@ int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) { return 1; } -/* -** Find the line number of position "pos". Note: this only works for -** displayed lines. If the line is not displayed, the function returns -** 0 (without the mLineStarts array it could turn in to very long -** calculation involving scanning large amounts of text in the buffer). -** If continuous wrap mode is on, returns the absolute line number (as opposed -** to the wrapped line number which is used for scrolling). +/** + Find the line number of position "pos". Note: this only works for + displayed lines. If the line is not displayed, the function returns + 0 (without the mLineStarts array it could turn in to very long + calculation involving scanning large amounts of text in the buffer). + If continuous wrap mode is on, returns the absolute line number (as opposed + to the wrapped line number which is used for scrolling). */ int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) { int retVal; @@ -905,8 +922,8 @@ int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) { return retVal; } -/* -** Return 1 if position (X, Y) is inside of the primary Fl_Text_Selection +/** + Return 1 if position (X, Y) is inside of the primary Fl_Text_Selection */ int Fl_Text_Display::in_selection( int X, int Y ) { int row, column, pos = xy_to_position( X, Y, CHARACTER_POS ); @@ -927,15 +944,15 @@ int Fl_Text_Display::in_selection( int X, int Y ) { return buf->primary_selection()->includes(pos, buf->line_start( pos ), column); } -/* -** Correct a column number based on an unconstrained position (as returned by -** TextDXYToUnconstrainedPosition) to be relative to the last actual newline -** in the buffer before the row and column position given, rather than the -** last line start created by line wrapping. This is an adapter -** for rectangular selections and code written before continuous wrap mode, -** which thinks that the unconstrained column is the number of characters -** from the last newline. Obviously this is time consuming, because it -** invloves character re-counting. +/** + Correct a column number based on an unconstrained position (as returned by + TextDXYToUnconstrainedPosition) to be relative to the last actual newline + in the buffer before the row and column position given, rather than the + last line start created by line wrapping. This is an adapter + for rectangular selections and code written before continuous wrap mode, + which thinks that the unconstrained column is the number of characters + from the last newline. Obviously this is time consuming, because it + invloves character re-counting. */ int Fl_Text_Display::wrapped_column(int row, int column) { int lineStart, dispLineStart; @@ -950,12 +967,12 @@ int Fl_Text_Display::wrapped_column(int row, int column) { + buffer()->count_displayed_characters(lineStart, dispLineStart); } -/* -** Correct a row number from an unconstrained position (as returned by -** TextDXYToUnconstrainedPosition) to a straight number of newlines from the -** top line of the display. Because rectangular selections are based on -** newlines, rather than display wrapping, and anywhere a rectangular selection -** needs a row, it needs it in terms of un-wrapped lines. +/** + Correct a row number from an unconstrained position (as returned by + TextDXYToUnconstrainedPosition) to a straight number of newlines from the + top line of the display. Because rectangular selections are based on + newlines, rather than display wrapping, and anywhere a rectangular selection + needs a row, it needs it in terms of un-wrapped lines. */ int Fl_Text_Display::wrapped_row(int row) { if (!mContinuousWrap || row < 0 || row > mNVisibleLines) @@ -963,13 +980,13 @@ int Fl_Text_Display::wrapped_row(int row) { return buffer()->count_lines(mFirstChar, mLineStarts[row]); } -/* -** Scroll the display to bring insertion cursor into view. +/** + Scroll the display to bring insertion cursor into view. ** -** Note: it would be nice to be able to do this without counting lines twice -** (scroll_() counts them too) and/or to count from the most efficient -** starting point, but the efficiency of this routine is not as important to -** the overall performance of the text display. + Note: it would be nice to be able to do this without counting lines twice + (scroll_() counts them too) and/or to count from the most efficient + starting point, but the efficiency of this routine is not as important to + the overall performance of the text display. */ void Fl_Text_Display::display_insert() { int hOffset, topLine, X, Y; @@ -1011,14 +1028,16 @@ void Fl_Text_Display::display_insert() { scroll_(topLine, hOffset); } +/** Scrolls the text buffer to show the current insert position.*/ void Fl_Text_Display::show_insert_position() { display_insert_position_hint = 1; resize(x(), y(), w(), h()); } /* -** Cursor movement functions + Cursor movement functions */ +/** Moves the current insert position right one character.*/ int Fl_Text_Display::move_right() { int ok = 0; while (!ok) { @@ -1031,7 +1050,7 @@ int Fl_Text_Display::move_right() { } return 1; } - +/** Moves the current insert position left one character.*/ int Fl_Text_Display::move_left() { int ok = 0; while (!ok) { @@ -1045,6 +1064,7 @@ int Fl_Text_Display::move_left() { return 1; } +/** Moves the current insert position up one line.*/ int Fl_Text_Display::move_up() { int lineStartPos, column, prevLineStartPos, newPos, visLineNum; @@ -1091,6 +1111,7 @@ int Fl_Text_Display::move_up() { return 1; } +/** Moves the current insert position down one line.*/ int Fl_Text_Display::move_down() { int lineStartPos, column, nextLineStartPos, newPos, visLineNum; @@ -1124,11 +1145,11 @@ int Fl_Text_Display::move_down() { return 1; } -/* -** Same as BufCountLines, but takes in to account wrapping if wrapping is -** turned on. If the caller knows that startPos is at a line start, it -** can pass "startPosIsLineStart" as True to make the call more efficient -** by avoiding the additional step of scanning back to the last newline. +/** + Same as BufCountLines, but takes in to account wrapping if wrapping is + turned on. If the caller knows that startPos is at a line start, it + can pass "startPosIsLineStart" as True to make the call more efficient + by avoiding the additional step of scanning back to the last newline. */ int Fl_Text_Display::count_lines(int startPos, int endPos, bool startPosIsLineStart) { @@ -1155,11 +1176,11 @@ int Fl_Text_Display::count_lines(int startPos, int endPos, return retLines; } -/* -** Same as BufCountForwardNLines, but takes in to account line breaks when -** wrapping is turned on. If the caller knows that startPos is at a line start, -** it can pass "startPosIsLineStart" as True to make the call more efficient -** by avoiding the additional step of scanning back to the last newline. +/** + Same as BufCountForwardNLines, but takes in to account line breaks when + wrapping is turned on. If the caller knows that startPos is at a line start, + it can pass "startPosIsLineStart" as True to make the call more efficient + by avoiding the additional step of scanning back to the last newline. */ int Fl_Text_Display::skip_lines(int startPos, int nLines, bool startPosIsLineStart) { @@ -1180,21 +1201,21 @@ int Fl_Text_Display::skip_lines(int startPos, int nLines, return retPos; } -/* -** Same as BufEndOfLine, but takes in to account line breaks when wrapping -** is turned on. If the caller knows that startPos is at a line start, it -** can pass "startPosIsLineStart" as True to make the call more efficient -** by avoiding the additional step of scanning back to the last newline. +/** + Same as BufEndOfLine, but takes in to account line breaks when wrapping + is turned on. If the caller knows that startPos is at a line start, it + can pass "startPosIsLineStart" as True to make the call more efficient + by avoiding the additional step of scanning back to the last newline. ** -** Note that the definition of the end of a line is less clear when continuous -** wrap is on. With continuous wrap off, it's just a pointer to the newline -** that ends the line. When it's on, it's the character beyond the last -** DISPLAYABLE character on the line, where a whitespace character which has -** been "converted" to a newline for wrapping is not considered displayable. -** Also note that, a line can be wrapped at a non-whitespace character if the -** line had no whitespace. In this case, this routine returns a pointer to -** the start of the next line. This is also consistent with the model used by -** visLineLength. + Note that the definition of the end of a line is less clear when continuous + wrap is on. With continuous wrap off, it's just a pointer to the newline + that ends the line. When it's on, it's the character beyond the last + DISPLAYABLE character on the line, where a whitespace character which has + been "converted" to a newline for wrapping is not considered displayable. + Also note that, a line can be wrapped at a non-whitespace character if the + line had no whitespace. In this case, this routine returns a pointer to + the start of the next line. This is also consistent with the model used by + visLineLength. */ int Fl_Text_Display::line_end(int pos, bool startPosIsLineStart) { int retLines, retPos, retLineStart, retLineEnd; @@ -1211,9 +1232,9 @@ int Fl_Text_Display::line_end(int pos, bool startPosIsLineStart) { return retLineEnd; } -/* -** Same as BufStartOfLine, but returns the character after last wrap point -** rather than the last newline. +/** + Same as BufStartOfLine, but returns the character after last wrap point + rather than the last newline. */ int Fl_Text_Display::line_start(int pos) { int retLines, retPos, retLineStart, retLineEnd; @@ -1227,9 +1248,9 @@ int Fl_Text_Display::line_start(int pos) { return retLineStart; } -/* -** Same as BufCountBackwardNLines, but takes in to account line breaks when -** wrapping is turned on. +/** + Same as BufCountBackwardNLines, but takes in to account line breaks when + wrapping is turned on. */ int Fl_Text_Display::rewind_lines(int startPos, int nLines) { Fl_Text_Buffer *buf = buffer(); @@ -1259,6 +1280,7 @@ static inline int fl_isseparator(int c) { return c != '$' && c != '_' && (isspace(c) || ispunct(c)); } +/** Moves the current insert position right one word.*/ void Fl_Text_Display::next_word() { int pos = insert_position(); while (pos < buffer()->length() && !fl_isseparator(buffer()->character(pos))) { @@ -1271,6 +1293,7 @@ void Fl_Text_Display::next_word() { insert_position( pos ); } +/** Moves the current insert position left one word.*/ void Fl_Text_Display::previous_word() { int pos = insert_position(); if (pos==0) return; @@ -1286,9 +1309,9 @@ void Fl_Text_Display::previous_word() { insert_position( pos ); } -/* -** Callback attached to the text buffer to receive delete information before -** the modifications are actually made. +/** + Callback attached to the text buffer to receive delete information before + the modifications are actually made. */ void Fl_Text_Display::buffer_predelete_cb(int pos, int nDeleted, void *cbArg) { Fl_Text_Display *textD = (Fl_Text_Display *)cbArg; @@ -1307,8 +1330,8 @@ void Fl_Text_Display::buffer_predelete_cb(int pos, int nDeleted, void *cbArg) { textD->mSuppressResync = 0; /* Probably not needed, but just in case */ } -/* -** Callback attached to the text buffer to receive modification information +/** + Callback attached to the text buffer to receive modification information */ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted, int nRestyled, const char *deletedText, void *cbArg ) { @@ -1427,24 +1450,24 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted, textD->redisplay_range( startDispPos, endDispPos ); // FIXME utf8 } -/* -** In continuous wrap mode, internal line numbers are calculated after -** wrapping. A separate non-wrapped line count is maintained when line -** numbering is turned on. There is some performance cost to maintaining this -** line count, so normally absolute line numbers are not tracked if line -** numbering is off. This routine allows callers to specify that they still -** want this line count maintained (for use via TextDPosToLineAndCol). -** More specifically, this allows the line number reported in the statistics -** line to be calibrated in absolute lines, rather than post-wrapped lines. +/** + In continuous wrap mode, internal line numbers are calculated after + wrapping. A separate non-wrapped line count is maintained when line + numbering is turned on. There is some performance cost to maintaining this + line count, so normally absolute line numbers are not tracked if line + numbering is off. This routine allows callers to specify that they still + want this line count maintained (for use via TextDPosToLineAndCol). + More specifically, this allows the line number reported in the statistics + line to be calibrated in absolute lines, rather than post-wrapped lines. */ void Fl_Text_Display::maintain_absolute_top_line_number(int state) { mNeedAbsTopLineNum = state; reset_absolute_top_line_number(); } -/* -** Returns the absolute (non-wrapped) line number of the first line displayed. -** Returns 0 if the absolute top line number is not being maintained. +/** + Returns the absolute (non-wrapped) line number of the first line displayed. + Returns 0 if the absolute top line number is not being maintained. */ int Fl_Text_Display::get_absolute_top_line_number() { if (!mContinuousWrap) @@ -1454,8 +1477,8 @@ int Fl_Text_Display::get_absolute_top_line_number() { return 0; } -/* -** Re-calculate absolute top line number for a change in scroll position. +/** + Re-calculate absolute top line number for a change in scroll position. */ void Fl_Text_Display::absolute_top_line_number(int oldFirstChar) { if (maintaining_absolute_top_line_number()) { @@ -1466,28 +1489,28 @@ void Fl_Text_Display::absolute_top_line_number(int oldFirstChar) { } } -/* -** Return true if a separate absolute top line number is being maintained -** (for displaying line numbers or showing in the statistics line). +/** + Return true if a separate absolute top line number is being maintained + (for displaying line numbers or showing in the statistics line). */ int Fl_Text_Display::maintaining_absolute_top_line_number() { return mContinuousWrap && (mLineNumWidth != 0 || mNeedAbsTopLineNum); } -/* -** Count lines from the beginning of the buffer to reestablish the -** absolute (non-wrapped) top line number. If mode is not continuous wrap, -** or the number is not being maintained, does nothing. +/** + Count lines from the beginning of the buffer to reestablish the + absolute (non-wrapped) top line number. If mode is not continuous wrap, + or the number is not being maintained, does nothing. */ void Fl_Text_Display::reset_absolute_top_line_number() { mAbsTopLineNum = 1; absolute_top_line_number(0); } -/* -** Find the line number of position "pos" relative to the first line of -** displayed text. Returns 0 if the line is not displayed. +/** + Find the line number of position "pos" relative to the first line of + displayed text. Returns 0 if the line is not displayed. */ int Fl_Text_Display::position_to_line( int pos, int *lineNum ) { int i; @@ -1519,12 +1542,12 @@ int Fl_Text_Display::position_to_line( int pos, int *lineNum ) { return 0; /* probably never be reached */ } -/* -** Draw the text on a single line represented by "visLineNum" (the -** number of lines down from the top of the display), limited by -** "leftClip" and "rightClip" window coordinates and "leftCharIndex" and -** "rightCharIndex" character positions (not including the character at -** position "rightCharIndex"). +/** + Draw the text on a single line represented by "visLineNum" (the + number of lines down from the top of the display), limited by + "leftClip" and "rightClip" window coordinates and "leftCharIndex" and + "rightCharIndex" character positions (not including the character at + position "rightCharIndex"). */ void Fl_Text_Display::draw_vline(int visLineNum, int leftClip, int rightClip, int leftCharIndex, int rightCharIndex) { @@ -1752,13 +1775,13 @@ void Fl_Text_Display::draw_vline(int visLineNum, int leftClip, int rightClip, free((void *)lineStr); } -/* -** Draw a string or blank area according to parameter "style", using the -** appropriate colors and drawing method for that style, with top left -** corner at X, y. If style says to draw text, use "string" as source of -** characters, and draw "nChars", if style is FILL, erase -** rectangle where text would have drawn from X to toX and from Y to -** the maximum Y extent of the current font(s). +/** + Draw a string or blank area according to parameter "style", using the + appropriate colors and drawing method for that style, with top left + corner at X, y. If style says to draw text, use "string" as source of + characters, and draw "nChars", if style is FILL, erase + rectangle where text would have drawn from X to toX and from Y to + the maximum Y extent of the current font(s). */ void Fl_Text_Display::draw_string( int style, int X, int Y, int toX, const char *string, int nChars ) { @@ -1842,8 +1865,8 @@ void Fl_Text_Display::draw_string( int style, int X, int Y, int toX, } -/* -** Clear a rectangle with the appropriate background color for "style" +/** + Clear a rectangle with the appropriate background color for "style" */ void Fl_Text_Display::clear_rect( int style, int X, int Y, int width, int height ) { @@ -1870,8 +1893,8 @@ void Fl_Text_Display::clear_rect( int style, int X, int Y, } -/* -** Draw a cursor with top center at X, y. +/** + Draw a cursor with top center at X, y. */ void Fl_Text_Display::draw_cursor( int X, int Y ) { typedef struct { @@ -1938,21 +1961,21 @@ void Fl_Text_Display::draw_cursor( int X, int Y ) { } } -/* -** Determine the drawing method to use to draw a specific character from "buf". -** "lineStartPos" gives the character index where the line begins, "lineIndex", -** the number of characters past the beginning of the line, and "dispIndex", -** the number of displayed characters past the beginning of the line. Passing -** lineStartPos of -1 returns the drawing style for "no text". +/** + Determine the drawing method to use to draw a specific character from "buf". + "lineStartPos" gives the character index where the line begins, "lineIndex", + the number of characters past the beginning of the line, and "dispIndex", + the number of displayed characters past the beginning of the line. Passing + lineStartPos of -1 returns the drawing style for "no text". ** -** Why not just: position_style(pos)? Because style applies to blank areas -** of the window beyond the text boundaries, and because this routine must also -** decide whether a position is inside of a rectangular Fl_Text_Selection, and do -** so efficiently, without re-counting character positions from the start of the -** line. + Why not just: position_style(pos)? Because style applies to blank areas + of the window beyond the text boundaries, and because this routine must also + decide whether a position is inside of a rectangular Fl_Text_Selection, and do + so efficiently, without re-counting character positions from the start of the + line. ** -** Note that style is a somewhat incorrect name, drawing method would -** be more appropriate. + Note that style is a somewhat incorrect name, drawing method would + be more appropriate. */ int Fl_Text_Display::position_style( int lineStartPos, int lineLen, int lineIndex, int dispIndex ) { @@ -1984,8 +2007,8 @@ int Fl_Text_Display::position_style( int lineStartPos, return style; } -/* -** Find the width of a string in the font of a particular style +/** + Find the width of a string in the font of a particular style */ int Fl_Text_Display::string_width( const char *string, int length, int style ) { Fl_Font font; @@ -2007,12 +2030,12 @@ int Fl_Text_Display::string_width( const char *string, int length, int style ) { return ( int ) ( fl_width( string, length ) ); } -/* -** Translate window coordinates to the nearest (insert cursor or character -** cell) text position. The parameter posType specifies how to interpret the -** position: CURSOR_POS means translate the coordinates to the nearest cursor -** position, and CHARACTER_POS means return the position of the character -** closest to (X, Y). +/** + Translate window coordinates to the nearest (insert cursor or character + cell) text position. The parameter posType specifies how to interpret the + position: CURSOR_POS means translate the coordinates to the nearest cursor + position, and CHARACTER_POS means return the position of the character + closest to (X, Y). */ int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) { int charIndex, lineStart, lineLen, fontHeight; @@ -2071,13 +2094,13 @@ int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) { return lineStart + lineLen; } -/* -** Translate window coordinates to the nearest row and column number for -** positioning the cursor. This, of course, makes no sense when the font is -** proportional, since there are no absolute columns. The parameter posType -** specifies how to interpret the position: CURSOR_POS means translate the -** coordinates to the nearest position between characters, and CHARACTER_POS -** means translate the position to the nearest character cell. +/** + Translate window coordinates to the nearest row and column number for + positioning the cursor. This, of course, makes no sense when the font is + proportional, since there are no absolute columns. The parameter posType + specifies how to interpret the position: CURSOR_POS means translate the + coordinates to the nearest position between characters, and CHARACTER_POS + means translate the position to the nearest character cell. */ void Fl_Text_Display::xy_to_rowcol( int X, int Y, int *row, int *column, int posType ) { @@ -2093,12 +2116,12 @@ void Fl_Text_Display::xy_to_rowcol( int X, int Y, int *row, if ( *column < 0 ) * column = 0; } -/* -** Offset the line starts array, mTopLineNum, mFirstChar and lastChar, for a new -** vertical scroll position given by newTopLineNum. If any currently displayed -** lines will still be visible, salvage the line starts values, otherwise, -** count lines from the nearest known line start (start or end of buffer, or -** the closest value in the mLineStarts array) +/** + Offset the line starts array, mTopLineNum, mFirstChar and lastChar, for a new + vertical scroll position given by newTopLineNum. If any currently displayed + lines will still be visible, salvage the line starts values, otherwise, + count lines from the nearest known line start (start or end of buffer, or + the closest value in the mLineStarts array) */ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) { int oldTopLineNum = mTopLineNum; @@ -2151,11 +2174,11 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) { absolute_top_line_number(oldFirstChar); } -/* -** Update the line starts array, mTopLineNum, mFirstChar and lastChar for text -** display "textD" after a modification to the text buffer, given by the -** position where the change began "pos", and the nmubers of characters -** and lines inserted and deleted. +/** + Update the line starts array, mTopLineNum, mFirstChar and lastChar for text + display "textD" after a modification to the text buffer, given by the + position where the change began "pos", and the nmubers of characters + and lines inserted and deleted. */ void Fl_Text_Display::update_line_starts( int pos, int charsInserted, int charsDeleted, int linesInserted, int linesDeleted, int *scrolled ) { @@ -2247,13 +2270,13 @@ void Fl_Text_Display::update_line_starts( int pos, int charsInserted, *scrolled = 0; } -/* -** Scan through the text in the "textD"'s buffer and recalculate the line -** starts array values beginning at index "startLine" and continuing through -** (including) "endLine". It assumes that the line starts entry preceding -** "startLine" (or mFirstChar if startLine is 0) is good, and re-counts -** newlines to fill in the requested entries. Out of range values for -** "startLine" and "endLine" are acceptable. +/** + Scan through the text in the "textD"'s buffer and recalculate the line + starts array values beginning at index "startLine" and continuing through + (including) "endLine". It assumes that the line starts entry preceding + "startLine" (or mFirstChar if startLine is 0) is good, and re-counts + newlines to fill in the requested entries. Out of range values for + "startLine" and "endLine" are acceptable. */ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) { int startPos, bufLen = mBuffer->length(); @@ -2308,9 +2331,9 @@ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) { lineStarts[ line ] = -1; } -/* -** Given a Fl_Text_Display with a complete, up-to-date lineStarts array, update -** the lastChar entry to point to the last buffer position displayed. +/** + Given a Fl_Text_Display with a complete, up-to-date lineStarts array, update + the lastChar entry to point to the last buffer position displayed. */ void Fl_Text_Display::calc_last_char() { int i; @@ -2318,6 +2341,7 @@ void Fl_Text_Display::calc_last_char() { mLastChar = i < 0 ? 0 : line_end(mLineStarts[i], true); } +/** Scrolls the current buffer to start at the specified line and column.*/ void Fl_Text_Display::scroll(int topLineNum, int horizOffset) { mTopLineNumHint = topLineNum; mHorizOffsetHint = horizOffset; @@ -2350,9 +2374,9 @@ void Fl_Text_Display::scroll_(int topLineNum, int horizOffset) { damage(FL_DAMAGE_EXPOSE); } -/* -** Update the minimum, maximum, slider size, page increment, and value -** for vertical scroll bar. +/** + Update the minimum, maximum, slider size, page increment, and value + for vertical scroll bar. */ void Fl_Text_Display::update_v_scrollbar() { /* The Vert. scroll bar value and slider size directly represent the top @@ -2369,17 +2393,17 @@ void Fl_Text_Display::update_v_scrollbar() { mVScrollBar->linesize(3); } -/* -** Update the minimum, maximum, slider size, page increment, and value -** for the horizontal scroll bar. +/** + Update the minimum, maximum, slider size, page increment, and value + for the horizontal scroll bar. */ void Fl_Text_Display::update_h_scrollbar() { int sliderMax = max(longest_vline(), text_area.w + mHorizOffset); mHScrollBar->value( mHorizOffset, text_area.w, 0, sliderMax ); } -/* -** Callbacks for drag or valueChanged on scroll bars +/** + Callbacks for drag or valueChanged on scroll bars */ void Fl_Text_Display::v_scrollbar_cb(Fl_Scrollbar* b, Fl_Text_Display* textD) { if (b->value() == textD->mTopLineNum) return; @@ -2391,11 +2415,11 @@ void Fl_Text_Display::h_scrollbar_cb(Fl_Scrollbar* b, Fl_Text_Display* textD) { textD->scroll(textD->mTopLineNum, b->value()); } -/* -** Refresh the line number area. If clearAll is False, writes only over -** the character cell areas. Setting clearAll to True will clear out any -** stray marks outside of the character cell area, which might have been -** left from before a resize or font change. +/** + Refresh the line number area. If clearAll is False, writes only over + the character cell areas. Setting clearAll to True will clear out any + stray marks outside of the character cell area, which might have been + left from before a resize or font change. */ void Fl_Text_Display::draw_line_numbers(bool /*clearAll*/) { #if 0 @@ -2459,8 +2483,8 @@ static int min( int i1, int i2 ) { return i1 <= i2 ? i1 : i2; } -/* -** Count the number of newlines in a null-terminated text string; +/** + Count the number of newlines in a null-terminated text string; */ static int countlines( const char *string ) { const char * c; @@ -2473,8 +2497,8 @@ static int countlines( const char *string ) { return lineCount; } -/* -** Return the width in pixels of the displayed line pointed to by "visLineNum" +/** + Return the width in pixels of the displayed line pointed to by "visLineNum" */ int Fl_Text_Display::measure_vline( int visLineNum ) { int i, width = 0, len, style, lineLen = vline_length( visLineNum ); @@ -2513,17 +2537,17 @@ int Fl_Text_Display::measure_vline( int visLineNum ) { return width; } -/* -** Return true if there are lines visible with no corresponding buffer text +/** + Return true if there are lines visible with no corresponding buffer text */ int Fl_Text_Display::empty_vlines() { return mNVisibleLines > 0 && mLineStarts[ mNVisibleLines - 1 ] == -1; } -/* -** Return the length of a line (number of displayable characters) by examining -** entries in the line starts array rather than by scanning for newlines +/** + Return the length of a line (number of displayable characters) by examining + entries in the line starts array rather than by scanning for newlines */ int Fl_Text_Display::vline_length( int visLineNum ) { int nextLineStart, lineStartPos; @@ -2545,14 +2569,14 @@ int Fl_Text_Display::vline_length( int visLineNum ) { return nextLineStart - lineStartPos; } -/* -** When continuous wrap is on, and the user inserts or deletes characters, -** wrapping can happen before and beyond the changed position. This routine -** finds the extent of the changes, and counts the deleted and inserted lines -** over that range. It also attempts to minimize the size of the range to -** what has to be counted and re-displayed, so the results can be useful -** both for delimiting where the line starts need to be recalculated, and -** for deciding what part of the text to redisplay. +/** + When continuous wrap is on, and the user inserts or deletes characters, + wrapping can happen before and beyond the changed position. This routine + finds the extent of the changes, and counts the deleted and inserted lines + over that range. It also attempts to minimize the size of the range to + what has to be counted and re-displayed, so the results can be useful + both for delimiting where the line starts need to be recalculated, and + for deciding what part of the text to redisplay. */ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos, int nInserted, int nDeleted, int *modRangeStart, int *modRangeEnd, @@ -2695,17 +2719,17 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos, mSuppressResync = 0; } -/* -** This is a stripped-down version of the findWrapRange() function above, -** intended to be used to calculate the number of "deleted" lines during -** a buffer modification. It is called _before_ the modification takes place. -** -** This function should only be called in continuous wrap mode with a -** non-fixed font width. In that case, it is impossible to calculate -** the number of deleted lines, because the necessary style information -** is no longer available _after_ the modification. In other cases, we -** can still perform the calculation afterwards (possibly even more -** efficiently). +/** + This is a stripped-down version of the findWrapRange() function above, + intended to be used to calculate the number of "deleted" lines during + a buffer modification. It is called _before_ the modification takes place. + + This function should only be called in continuous wrap mode with a + non-fixed font width. In that case, it is impossible to calculate + the number of deleted lines, because the necessary style information + is no longer available _after_ the modification. In other cases, we + can still perform the calculation afterwards (possibly even more + efficiently). */ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) { int retPos, retLines, retLineStart, retLineEnd; @@ -2771,22 +2795,22 @@ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) { mSuppressResync = 1; } -/* -** Count forward from startPos to either maxPos or maxLines (whichever is -** reached first), and return all relevant positions and line count. -** The provided textBuffer may differ from the actual text buffer of the -** widget. In that case it must be a (partial) copy of the actual text buffer -** and the styleBufOffset argument must indicate the starting position of the -** copy, to take into account the correct style information. +/** + Count forward from startPos to either maxPos or maxLines (whichever is + reached first), and return all relevant positions and line count. + The provided textBuffer may differ from the actual text buffer of the + widget. In that case it must be a (partial) copy of the actual text buffer + and the styleBufOffset argument must indicate the starting position of the + copy, to take into account the correct style information. ** -** Returned values: + Returned values: ** -** retPos: Position where counting ended. When counting lines, the -** position returned is the start of the line "maxLines" -** lines beyond "startPos". -** retLines: Number of line breaks counted -** retLineStart: Start of the line where counting ended -** retLineEnd: End position of the last line traversed + retPos: Position where counting ended. When counting lines, the + position returned is the start of the line "maxLines" + lines beyond "startPos". + retLines: Number of line breaks counted + retLineStart: Start of the line where counting ended + retLineEnd: End position of the last line traversed */ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos, int maxPos, int maxLines, bool startPosIsLineStart, int styleBufOffset, @@ -2915,19 +2939,19 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos, *retLineEnd = buf->length(); } -/* -** Measure the width in pixels of a character "c" at a particular column -** "colNum" and buffer position "pos". This is for measuring characters in -** proportional or mixed-width highlighting fonts. +/** + Measure the width in pixels of a character "c" at a particular column + "colNum" and buffer position "pos". This is for measuring characters in + proportional or mixed-width highlighting fonts. ** -** A note about proportional and mixed-width fonts: the mixed width and -** proportional font code in nedit does not get much use in general editing, -** because nedit doesn't allow per-language-mode fonts, and editing programs -** in a proportional font is usually a bad idea, so very few users would -** choose a proportional font as a default. There are still probably mixed- -** width syntax highlighting cases where things don't redraw properly for -** insertion/deletion, though static display and wrapping and resizing -** should now be solid because they are now used for online help display. + A note about proportional and mixed-width fonts: the mixed width and + proportional font code in nedit does not get much use in general editing, + because nedit doesn't allow per-language-mode fonts, and editing programs + in a proportional font is usually a bad idea, so very few users would + choose a proportional font as a default. There are still probably mixed- + width syntax highlighting cases where things don't redraw properly for + insertion/deletion, though static display and wrapping and resizing + should now be solid because they are now used for online help display. */ int Fl_Text_Display::measure_proportional_character(char c, int colNum, int pos) { int charLen, style; @@ -2949,15 +2973,15 @@ int Fl_Text_Display::measure_proportional_character(char c, int colNum, int pos) return string_width(expChar, charLen, style); } -/* -** Finds both the end of the current line and the start of the next line. Why? -** In continuous wrap mode, if you need to know both, figuring out one from the -** other can be expensive or error prone. The problem comes when there's a -** trailing space or tab just before the end of the buffer. To translate an -** end of line value to or from the next lines start value, you need to know -** whether the trailing space or tab is being used as a line break or just a -** normal character, and to find that out would otherwise require counting all -** the way back to the beginning of the line. +/** + Finds both the end of the current line and the start of the next line. Why? + In continuous wrap mode, if you need to know both, figuring out one from the + other can be expensive or error prone. The problem comes when there's a + trailing space or tab just before the end of the buffer. To translate an + end of line value to or from the next lines start value, you need to know + whether the trailing space or tab is being used as a line break or just a + normal character, and to find that out would otherwise require counting all + the way back to the beginning of the line. */ void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart, int *lineEnd, int *nextLineStart) { @@ -2977,21 +3001,21 @@ void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart, return; } -/* -** Line breaks in continuous wrap mode usually happen at newlines or -** whitespace. This line-terminating character is not included in line -** width measurements and has a special status as a non-visible character. -** However, lines with no whitespace are wrapped without the benefit of a -** line terminating character, and this distinction causes endless trouble -** with all of the text display code which was originally written without -** continuous wrap mode and always expects to wrap at a newline character. +/** + Line breaks in continuous wrap mode usually happen at newlines or + whitespace. This line-terminating character is not included in line + width measurements and has a special status as a non-visible character. + However, lines with no whitespace are wrapped without the benefit of a + line terminating character, and this distinction causes endless trouble + with all of the text display code which was originally written without + continuous wrap mode and always expects to wrap at a newline character. ** -** Given the position of the end of the line, as returned by TextDEndOfLine -** or BufEndOfLine, this returns true if there is a line terminating -** character, and false if there's not. On the last character in the -** buffer, this function can't tell for certain whether a trailing space was -** used as a wrap point, and just guesses that it wasn't. So if an exact -** accounting is necessary, don't use this function. + Given the position of the end of the line, as returned by TextDEndOfLine + or BufEndOfLine, this returns true if there is a line terminating + character, and false if there's not. On the last character in the + buffer, this function can't tell for certain whether a trailing space was + used as a wrap point, and just guesses that it wasn't. So if an exact + accounting is necessary, don't use this function. */ int Fl_Text_Display::wrap_uses_character(int lineEndPos) { char c; @@ -3004,9 +3028,9 @@ int Fl_Text_Display::wrap_uses_character(int lineEndPos) { lineEndPos + 1 != buffer()->length()); } -/* -** Return true if the selection "sel" is rectangular, and touches a -** buffer position withing "rangeStart" to "rangeEnd" +/** + Return true if the selection "sel" is rectangular, and touches a + buffer position withing "rangeStart" to "rangeEnd" */ int Fl_Text_Display::range_touches_selection(Fl_Text_Selection *sel, int rangeStart, int rangeEnd) { @@ -3014,10 +3038,10 @@ int Fl_Text_Display::range_touches_selection(Fl_Text_Selection *sel, sel->start() <= rangeEnd; } -/* -** Extend the range of a redraw request (from *start to *end) with additional -** redraw requests resulting from changes to the attached style buffer (which -** contains auxiliary information for coloring or styling text). +/** + Extend the range of a redraw request (from *start to *end) with additional + redraw requests resulting from changes to the attached style buffer (which + contains auxiliary information for coloring or styling text). */ void Fl_Text_Display::extend_range_for_styles( int *startpos, int *endpos ) { Fl_Text_Selection * sel = mStyleBuffer->primary_selection(); diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx index 880ca844c..c3fbf2fe0 100644 --- a/src/Fl_Text_Editor.cxx +++ b/src/Fl_Text_Editor.cxx @@ -55,6 +55,7 @@ static int utf_len(char c) return 0; } +/** The constructor creates a new text editor widget.*/ Fl_Text_Editor::Fl_Text_Editor(int X, int Y, int W, int H, const char* l) : Fl_Text_Display(X, Y, W, H, l) { mCursorOn = 1; @@ -137,6 +138,7 @@ static struct { { 0, 0, 0 } }; +/** Adds all of the default editor key bindings to the specified key binding list.*/ void Fl_Text_Editor::add_default_key_bindings(Key_Binding** list) { for (int i = 0; default_key_bindings[i].key; i++) { add_key_binding(default_key_bindings[i].key, @@ -146,8 +148,8 @@ void Fl_Text_Editor::add_default_key_bindings(Key_Binding** list) { } } -Fl_Text_Editor::Key_Func -Fl_Text_Editor::bound_key_function(int key, int state, Key_Binding* list) { +/** Returns the function associated with a key binding.*/ +Fl_Text_Editor::Key_Func Fl_Text_Editor::bound_key_function(int key, int state, Key_Binding* list) { Key_Binding* cur; for (cur = list; cur; cur = cur->next) if (cur->key == key) @@ -157,8 +159,8 @@ Fl_Text_Editor::bound_key_function(int key, int state, Key_Binding* list) { return cur->function; } -void -Fl_Text_Editor::remove_all_key_bindings(Key_Binding** list) { +/** Removes all of the key bindings associated with the text editor or list.*/ +void Fl_Text_Editor::remove_all_key_bindings(Key_Binding** list) { Key_Binding *cur, *next; for (cur = *list; cur; cur = next) { next = cur->next; @@ -167,8 +169,8 @@ Fl_Text_Editor::remove_all_key_bindings(Key_Binding** list) { *list = 0; } -void -Fl_Text_Editor::remove_key_binding(int key, int state, Key_Binding** list) { +/** Removes the key binding associated with the key "key" of state "state" */ +void Fl_Text_Editor::remove_key_binding(int key, int state, Key_Binding** list) { Key_Binding *cur, *last = 0; for (cur = *list; cur; last = cur, cur = cur->next) if (cur->key == key && cur->state == state) break; @@ -177,9 +179,8 @@ Fl_Text_Editor::remove_key_binding(int key, int state, Key_Binding** list) { else *list = cur->next; delete cur; } - -void -Fl_Text_Editor::add_key_binding(int key, int state, Key_Func function, +/** Adds a key of state "state" with the function "function" */ +void Fl_Text_Editor::add_key_binding(int key, int state, Key_Func function, Key_Binding** list) { Key_Binding* kb = new Key_Binding; kb->key = key; @@ -200,6 +201,7 @@ static void kill_selection(Fl_Text_Editor* e) { } } +/** Inserts the text associated with the key */ int Fl_Text_Editor::kf_default(int c, Fl_Text_Editor* e) { if (!c || (!isprint(c) && c != '\t')) return 0; char s[2] = "\0"; @@ -213,10 +215,11 @@ int Fl_Text_Editor::kf_default(int c, Fl_Text_Editor* e) { return 1; } +/** Ignores the keypress */ int Fl_Text_Editor::kf_ignore(int, Fl_Text_Editor*) { return 0; // don't handle } - +/** Does a backspace in the current buffer.*/ int Fl_Text_Editor::kf_backspace(int, Fl_Text_Editor* e) { if (!e->buffer()->selected() && e->move_left()) { int l = 1; @@ -233,6 +236,7 @@ int Fl_Text_Editor::kf_backspace(int, Fl_Text_Editor* e) { return 1; } +/** Inserts a newline at the current cursor position */ int Fl_Text_Editor::kf_enter(int, Fl_Text_Editor* e) { kill_selection(e); e->insert("\n"); @@ -243,7 +247,7 @@ int Fl_Text_Editor::kf_enter(int, Fl_Text_Editor* e) { } extern void fl_text_drag_me(int pos, Fl_Text_Display* d); - +/** Moves the text cursor in the direction indicated by key c.*/ int Fl_Text_Editor::kf_move(int c, Fl_Text_Editor* e) { int i; int selected = e->buffer()->selected(); @@ -280,12 +284,13 @@ int Fl_Text_Editor::kf_move(int c, Fl_Text_Editor* e) { return 1; } +/** Extends the current selection in the direction of key c.*/ int Fl_Text_Editor::kf_shift_move(int c, Fl_Text_Editor* e) { kf_move(c, e); fl_text_drag_me(e->insert_position(), e); return 1; } - +/** Moves the current text cursor in the direction indicated by control key */ int Fl_Text_Editor::kf_ctrl_move(int c, Fl_Text_Editor* e) { if (!e->buffer()->selected()) e->dragPos = e->insert_position(); @@ -324,50 +329,58 @@ int Fl_Text_Editor::kf_ctrl_move(int c, Fl_Text_Editor* e) { return 1; } +/** Extends the current selection in the direction indicated by control key c. */ int Fl_Text_Editor::kf_c_s_move(int c, Fl_Text_Editor* e) { kf_ctrl_move(c, e); fl_text_drag_me(e->insert_position(), e); return 1; } +/** Moves the text cursor to the beginning of the current line.*/ int Fl_Text_Editor::kf_home(int, Fl_Text_Editor* e) { return kf_move(FL_Home, e); } +/** Moves the text cursor to the end of the current line.*/ int Fl_Text_Editor::kf_end(int, Fl_Text_Editor* e) { return kf_move(FL_End, e); } +/** Moves the text cursor one character to the left.*/ int Fl_Text_Editor::kf_left(int, Fl_Text_Editor* e) { return kf_move(FL_Left, e); } +/** Moves the text cursor one line up.*/ int Fl_Text_Editor::kf_up(int, Fl_Text_Editor* e) { return kf_move(FL_Up, e); } +/** Moves the text cursor one character to the right.*/ int Fl_Text_Editor::kf_right(int, Fl_Text_Editor* e) { return kf_move(FL_Right, e); } - +/** Moves the text cursor one line down.*/ int Fl_Text_Editor::kf_down(int, Fl_Text_Editor* e) { return kf_move(FL_Down, e); } +/** Moves the text cursor up one page.*/ int Fl_Text_Editor::kf_page_up(int, Fl_Text_Editor* e) { return kf_move(FL_Page_Up, e); } +/** Moves the text cursor down one page.*/ int Fl_Text_Editor::kf_page_down(int, Fl_Text_Editor* e) { return kf_move(FL_Page_Down, e); } - - +/** Toggles the insert mode in the text editor.*/ int Fl_Text_Editor::kf_insert(int, Fl_Text_Editor* e) { e->insert_mode(e->insert_mode() ? 0 : 1); return 1; } +/** Does a delete of selected text or the current character in the current buffer.*/ int Fl_Text_Editor::kf_delete(int, Fl_Text_Editor* e) { if (!e->buffer()->selected()) { int l = 1; @@ -385,6 +398,7 @@ int Fl_Text_Editor::kf_delete(int, Fl_Text_Editor* e) { return 1; } +/** Does a copy of selected text or the current character in the current buffer.*/ int Fl_Text_Editor::kf_copy(int, Fl_Text_Editor* e) { if (!e->buffer()->selected()) return 1; const char *copy = e->buffer()->selection_text(); @@ -394,6 +408,7 @@ int Fl_Text_Editor::kf_copy(int, Fl_Text_Editor* e) { return 1; } +/** Does a cut of selected text in the current buffer.*/ int Fl_Text_Editor::kf_cut(int c, Fl_Text_Editor* e) { kf_copy(c, e); kill_selection(e); @@ -402,6 +417,7 @@ int Fl_Text_Editor::kf_cut(int c, Fl_Text_Editor* e) { return 1; } +/** Does a paste of selected text in the current buffer.*/ int Fl_Text_Editor::kf_paste(int, Fl_Text_Editor* e) { kill_selection(e); Fl::paste(*e, 1); @@ -411,11 +427,12 @@ int Fl_Text_Editor::kf_paste(int, Fl_Text_Editor* e) { return 1; } +/** Selects all text in the current buffer.*/ int Fl_Text_Editor::kf_select_all(int, Fl_Text_Editor* e) { e->buffer()->select(0, e->buffer()->length()); return 1; } - +/** Undo last edit in the current buffer. Also deselect previous selection. */ int Fl_Text_Editor::kf_undo(int , Fl_Text_Editor* e) { e->buffer()->unselect(); int crsr; @@ -427,6 +444,7 @@ int Fl_Text_Editor::kf_undo(int , Fl_Text_Editor* e) { return ret; } +/** Handles a key press in the editor */ int Fl_Text_Editor::handle_key() { // Call FLTK's rules to try to turn this into a printing character. // This uses the right-hand ctrl key as a "compose prefix" and returns @@ -456,6 +474,7 @@ int Fl_Text_Editor::handle_key() { return 0; } +/** does or does not a callback according to changed() and when() settings */ void Fl_Text_Editor::maybe_do_callback() { // printf("Fl_Text_Editor::maybe_do_callback()\n"); // printf("changed()=%d, when()=%x\n", changed(), when()); diff --git a/src/Fl_Tiled_Image.cxx b/src/Fl_Tiled_Image.cxx index c2058e3bc..fb200ead0 100644 --- a/src/Fl_Tiled_Image.cxx +++ b/src/Fl_Tiled_Image.cxx @@ -25,17 +25,15 @@ // http://www.fltk.org/str.php // + #include <FL/Fl.H> #include <FL/Fl_Tiled_Image.H> #include <FL/fl_draw.H> - -// -// 'Fl_Tiled_Image::Fl_Tiled_Image()' - Constructor. -// -// Use a width and height of 0 to tile the whole window/widget. -// - +/** + The constructors create a new tiled image containing the specified image. + Use a width and height of 0 to tile the whole window/widget. +*/ Fl_Tiled_Image::Fl_Tiled_Image(Fl_Image *i, // I - Image to tile int W, // I - Width of tiled area int H) : // I - Height of tiled area @@ -46,13 +44,11 @@ Fl_Tiled_Image::Fl_Tiled_Image(Fl_Image *i, // I - Image to tile if (W == 0) w(Fl::w()); if (H == 0) h(Fl::h()); } - - -// -// 'Fl_Tiled_Image::~Fl_Tiled_Image()' - Destructor. -// - -Fl_Tiled_Image::~Fl_Tiled_Image() { +/** + The destructor frees all memory and server resources that are used by + the tiled image. +*/ + Fl_Tiled_Image::~Fl_Tiled_Image() { if (alloc_image_) delete image_; } diff --git a/src/Fl_Tooltip.cxx b/src/Fl_Tooltip.cxx index c804d3153..8825da797 100644 --- a/src/Fl_Tooltip.cxx +++ b/src/Fl_Tooltip.cxx @@ -135,14 +135,16 @@ static void tooltip_timeout(void*) { recursion = 0; } -// If this widget or one of it's parents has a tooltip, enter it. This -// will do nothing if this is the current widget (even if the mouse moved -// out so an exit() was done and then moved back in). If no tooltip can -// be found do Fl_Tooltip::exit_(). If you don't want this behavior (for instance -// if you want the tooltip to reappear when the mouse moves back in) -// call the fancier enter_area() below. -void -Fl_Tooltip::enter_(Fl_Widget* w) { +/** + This method is called when the mouse pointer enters a widget. + <P>If this widget or one of it's parents has a tooltip, enter it. This + will do nothing if this is the current widget (even if the mouse moved + out so an exit() was done and then moved back in). If no tooltip can + be found do Fl_Tooltip::exit_(). If you don't want this behavior (for instance + if you want the tooltip to reappear when the mouse moves back in) + call the fancier enter_area() below. +*/ +void Fl_Tooltip::enter_(Fl_Widget* w) { #ifdef DEBUG printf("Fl_Tooltip::enter_(w=%p)\n", w); printf(" window=%p\n", window); @@ -158,11 +160,13 @@ Fl_Tooltip::enter_(Fl_Widget* w) { } enter_area(w, 0, 0, w->w(), w->h(), tw->tooltip()); } - -// Acts as though enter(widget) was done but does not pop up a -// tooltip. This is useful to prevent a tooltip from reappearing when -// a modal overlapping window is deleted. FLTK does this automatically -// when you click the mouse button. +/** + Sets the current widget target. + Acts as though enter(widget) was done but does not pop up a + tooltip. This is useful to prevent a tooltip from reappearing when + a modal overlapping window is deleted. FLTK does this automatically + when you click the mouse button. +*/ void Fl_Tooltip::current(Fl_Widget* w) { #ifdef DEBUG printf("Fl_Tooltip::current(w=%p)\n", w); @@ -181,8 +185,8 @@ void Fl_Tooltip::current(Fl_Widget* w) { } // Hide any visible tooltip. -void -Fl_Tooltip::exit_(Fl_Widget *w) { +/** This method is called when the mouse pointer leaves a widget. */ +void Fl_Tooltip::exit_(Fl_Widget *w) { #ifdef DEBUG printf("Fl_Tooltip::exit_(w=%p)\n", w); printf(" widget=%p, window=%p\n", widget_, window); @@ -203,8 +207,18 @@ Fl_Tooltip::exit_(Fl_Widget *w) { // it define an area the tooltip is for, this along with the current // mouse position places the tooltip (the mouse is assummed to point // inside or near the box). -void -Fl_Tooltip::enter_area(Fl_Widget* wid, int x,int y,int w,int h, const char* t) +/** + You may be able to use this to provide tooltips for internal pieces + of your widget. Call this after setting Fl::belowmouse() to + your widget (because that calls the above enter() method). Then figure + out what thing the mouse is pointing at, and call this with the widget + (this pointer is used to remove the tooltip if the widget is deleted + or hidden, and to locate the tooltip), the rectangle surrounding the + area, relative to the top-left corner of the widget (used to calculate + where to put the tooltip), and the text of the tooltip (which must be + a pointer to static data as it is not copied). +*/ +void Fl_Tooltip::enter_area(Fl_Widget* wid, int x,int y,int w,int h, const char* t) { (void)x; (void)w; diff --git a/src/Fl_Wizard.cxx b/src/Fl_Wizard.cxx index cf88f9058..6d48ebc45 100644 --- a/src/Fl_Wizard.cxx +++ b/src/Fl_Wizard.cxx @@ -25,6 +25,7 @@ // http://www.fltk.org/str.php // // Contents: + // // Fl_Wizard::Fl_Wizard() - Create an Fl_Wizard widget. // Fl_Wizard::draw() - Draw the wizard border and visible child. @@ -47,6 +48,11 @@ // 'Fl_Wizard::Fl_Wizard()' - Create an Fl_Wizard widget. // +/** + The constructor creates the Fl_Wizard widget at the specified + position and size. + <P>The inherited destructor destroys the widget and its children. +*/ Fl_Wizard::Fl_Wizard(int xx, // I - Lefthand position int yy, // I - Upper position int ww, // I - Width @@ -61,12 +67,8 @@ Fl_Wizard::Fl_Wizard(int xx, // I - Lefthand position // -// 'Fl_Wizard::draw()' - Draw the wizard border and visible child. -// - -void -Fl_Wizard::draw() -{ +/** Draws the wizard border and visible child. */ +void Fl_Wizard::draw() { Fl_Widget *kid; // Visible child @@ -89,13 +91,11 @@ Fl_Wizard::draw() } -// -// 'Fl_Wizard::next()' - Show the next child. -// - -void -Fl_Wizard::next() -{ +/** + This method shows the next child of the wizard. If the last child + is already visible, this function does nothing. +*/ +void Fl_Wizard::next() { int num_kids; Fl_Widget * const *kids; @@ -111,14 +111,8 @@ Fl_Wizard::next() value(kids[1]); } - -// -// 'Fl_Wizard::prev()' - Show the previous child. -// - - -void -Fl_Wizard::prev() +/** Shows the previous child.*/ +void Fl_Wizard::prev() { int num_kids; Fl_Widget * const *kids; @@ -135,13 +129,8 @@ Fl_Wizard::prev() value(kids[-1]); } - -// -// 'Fl_Wizard::value()' - Return the current visible child. -// - -Fl_Widget * -Fl_Wizard::value() +/** Gets the current visible child widget. */ +Fl_Widget* Fl_Wizard::value() { int num_kids; Fl_Widget * const *kids; @@ -172,13 +161,8 @@ Fl_Wizard::value() return (kid); } - -// -// 'Fl_Wizard::value()' - Set the visible child. -// - -void -Fl_Wizard::value(Fl_Widget *kid) +/** Sets the child widget that is visible.*/ +void Fl_Wizard::value(Fl_Widget *kid) { int num_kids; Fl_Widget * const *kids; @@ -205,6 +189,7 @@ Fl_Wizard::value(Fl_Widget *kid) } + // // End of "$Id$". // |
