class Fl_Editor

Class Hierarchy

Include Files


This is an extension to the basic text editor widget. This one supports interactive find and replace, an optional status panel display, and other features.

The editor widgets allow you to enter text of any length, limited by available memory. A number of operations can be performed on the text, including loading from and saving to files, cutting and pasting from the clipboard, and searching and replacing text.

The editor widgets support "CUA-style" keys. That is, in addition to the normal ASCII keys, the following keys are recognized by the editor:

Cursor Arrows Move left, right, up, and down
Page Up/Down Move the text up or down one screen
Ctrl-Home Move to the first character of the text
Ctrl-End Move to the last character of the text
Home Move to the start of the current line
End Move to the end of the current line
Ctrl-Left Move to the start of the previous word
Ctrl-Right Move to the start of the next word
Delete Delete the character under the cursor.
Insert Toggle Insert / Overstrike mode
Backspace Delete character to the left of the cursor.
Shift-Delete or Ctrl-X Cut selection to clipboard
Ctrl-Insert or Ctrl-C Copy selection to clipboard
Shift-Insert or Ctrl-V Paste from clipboard
Mouse Click for cursor placement
Double-click selects word
Triple-click selects line
Click and drag selects text.
Shift hold the Shift key while moving the cursor to select text.

The editor also has a scrollbar which will automatically appear when the text being edited is larger than will fit in the visible area. Text is reformatted automatically when the editor widget is resized.

Also please note that this is NOT presently a "rich text" editor -- that is, it doesn't support more than one font, size, or color at a time. This is planned for a future release, but the present widgets limit you to one font at a time.


Fl_Editor::Fl_Editor(int x, int y, int w, int h, const char *label = 0)

Creates a new Fl_Editor widget using the given position, size, and label string. The default boxtype is FL_DOWN_BOX. The widget will be created to fit within the given dimensions.

virtual Fl_Editor::~Fl_Editor()

Destroys the widget and any value associated with it.

void Fl_Editor::browse(bool)

Changes the editor state into or out of "browse mode". In browse mode, the editor is made read-only, the cursor is hidden, and using the up/down arrows scrolls the visible text. This is useful for situations where all you want to do is display some text, but not edit it.

bool Fl_Editor::changed()

Returns true if there have been any changes to the edited text, otherwise returns false.

long Fl_Editor::CharacterCount()

Returns the character count in the editor's buffers. Note that this is NOT the number of characters to allocate in a buffer to save the text, but rather the actual number of characters in the editor's buffers. To find the number of characters to allocate, use GetTextBuffeSize() instead.

void Fl_Editor::Clear()

Resets the editor to a "clean slate" -- a blank document, cursor at the start of the document.

void Fl_Editor::Copy()

Copy selected text to the clipboard.

short Fl_Editor::CursorX()
short Fl_Editor::CursorY()

Based on the position of the logical cursor in the edit buffer, returns the top left corner where the cursor image will be drawn on the display.

void Fl_Editor::Cut()

Cuts selected text to the clipboard.

void Fl_Editor::draw()

Redraws the editor. Tries to minimize the area redrawn to only the part that actually needs drawn.

void Fl_Editor::draw_clip(void *, int, int, int, int)

Used in conjunction with the HandleScroll() routine to redraw while scrolling.

void Fl_Editor::Engine()

Returns a pointer to the editor engine being driven by the widget. This engine can be driven by sending it commands (see the header file, editor.hpp for details), and then resynchronized with the editor widget by calling SyncDisplay() on the widget.

long Fl_Editor::FindColumn(short)
long Fl_Editor::FindRow(short)

void Fl_Editor::FindCursor() Positions the logical edit cursor based on a screen position. Returns the position set. If the cursor is outside the text (for example, a mouse click past the end of the text being edited), both functions will position to the end of the text and return -1.

long Fl_Editor::GetTextBufferSize()

Returns the number of characters that would be needed to do a SaveTo(char *buffer) call on this instance. (The number returned already includes space for a terminating NULL, so you don't need to add one to it). If you need to save the edited text to a buffer, just allocate a buffer of this size and call SaveTo() with your buffer as an argument.

void Fl_Editor::handle()

This is the event handler loop. If you need to subclass and define special event processing, this is where you'll start.

void Fl_Editor::HandleScroll()

Checks for whether the widget display contains the logical cursor. If it doesn't, it is automatically "scrolled" (redrawn) so that the cursor is visible.

void Fl_Editor::HideCursor(bool)
bool Fl_Editor::HideCursor()

Allows for having the cursor shown or hidden, or determining the present state.

short Fl_Editor::LoadFrom(const char *)
void Fl_Editor::LoadFrom(FILE *)

Reads a file or buffer, inserting it at the current cursor position.

void Fl_Editor::Paste()

Paste from the clipboard at the current cursor location. After pasting, the cursor will be positioned at the end of the inserted text.

bool Fl_Editor::readonly()
void Fl_Editor::readonly(bool)

Determine whether the edit buffer is read only, and be able to change whether it is or not.

void Fl_Editor::Replace()

Displays a "search and replace" dialog where the user can enter a string to search for and replace with another string. Various options can be set for case sensitivity, etc., and the user can optionally be asked to confirm each replacement.

void Fl_Editor::resize()

Overrides the standard FLTK resize method. Reformats the text to match the new size.

short Fl_Editor::SaveTo(char *)
void Fl_Editor::SaveTo(FILE *)

Saves the entire contents of the editor to the buffer or file specified. Note that no length checking is done when saving to buffers. You should check your buffer size against CharacterCount() first.

void Fl_Editor::scrollspeed(int lines)
int Fl_Editor::scrollspeed()

Get or set the speed at which scroll select operates, in lines per second. The default is five lines per second.

void Fl_Editor::SyncDisplay()

The editor uses an internal engine that can be manipulated without involving the user or the display. This function allows for synchronizing the display with the present editor state after programmatic manipulations.

Fl_Color Fl_Editor::textcolor() const
void Fl_Editor::textcolor(Fl_Color)

Gets or sets the color of the text in the input field.

Fl_Font Fl_Editor::textfont() const
void Fl_Editor::textfont(Fl_Font)

Gets or sets the font of the text in the input field.

uchar Fl_Editor::textsize() const
void Fl_Editor::textsize(uchar)

Gets or sets the size of the text in the input field.

bool Fl_Editor::TimerEnabled() const

Returns true if the scroll timer is presently enabled (if the user is drag-selecting and has moved the mouse outside the bounds of the widget).

bool Fl_Editor::Wrap()
void Fl_Editor::Wrap(bool)

Read the word wrap state, or change it. Setting it true turns on word wrap. Setting it false turns off word wrap, but the cursor still wraps at the margin. (That is, with word wrap off, when the user hits the margin, the word will split in the middle and typing will continue on the next line.)