#include <editors.h>
Inheritance diagram for TEditor::
TEditor is the base class for all editors. It implements most of the editor's functionality. If a TEditor object is created, it allocates a buffer of the given size out of the heap. The buffer is initially empty.
Definition at line 308 of file editors.h.
|
Constructor. Calls TView::TView(bounds) by creating a view with the given bounds. The hScrollBar, vScrollBar, indicator and bufSize data members are set from the given arguments.
Variable Value Description canUndo True TEditor::canUndo selecting False TEditor::selecting overwrite False TEditor::overwrite autoIndent False TEditor::autoIndent lockCount 0 TEditor::lockCount keyState 0 TEditor::keyState growMode gfGrowHiX | gfGrowHiY TView::growMode options ofSelectable TView::options eventMask evMouseDown | evKeyDown | evCommand | evBroadcast TView::eventMask `aBufSize' is the buffer initial size; 0 is its common value. The buffer is allocated and cleared. If insufficient memory exists, the edOutOfMemory dialog box is displayed using editorDialog, and isValid data member is set False. Otherwise isValid is set True. The data members associated with the editor buffer are initialized in the obvious way: bufLen to 0, gapLen to bufSize, selStart to 0, modified to False, and so on. |
|
Destructor. Destroys the editor and deletes the buffer. |
|
Each streamable class needs a "builder" to allocate the correct memory for its objects together with the initialized virtual table pointers. This is achieved by calling this constructor with an argument of type StreamableInit. |
|
Returns the p'th character in the file, factoring in the gap. |
|
Returns the offset into buffer of the p'th character in the file, factoring in the gap. |
|
Called to create an object in certain stream reading situations. Reimplemented from TView. Reimplemented in TMemo, and TFileEditor. |
|
Changes the views bounds, adjusting the delta value and redrawing the scrollbars and view if necessary. Overridden to ensure the file stays within view if the parent size changes. Reimplemented from TView. |
|
Calculates and returns the actual cursor position by examining the characters in the buffer between `p' and `target'. Any tab codes encountered are counted as spaces modulo the tab setting.
|
|
The reverse of charPos(). Calculates and returns the buffer position corresponding to a cursor position. |
|
Called by handleEvent() in response to a cmScrollBarChanged broadcast event. If the scroll bar's current value is different from `d', the scroll bar is redrawn. |
|
Returns False if this editor has no active clipboard. Otherwise, copies the selected text from the editor to the clipboard using clipboard->insertFrom(this).
|
|
The same as for clipCopy(), but the selected text is deleted after being copied to the clipboard. |
|
The reverse of clipCopy(): the contents of the clipboard (if any) are copied to the current position of the editor using insertFrom(clipboard).
|
|
Used by handleEvent() to provide basic editing operations by converting various key events to command events. You can change or extend these default key bindings by overriding the convertEvent() member function. |
|
Returns True if the cursor (insertion point) is visible within the view. |
|
If `delSelect' is True and a current selection exists, the current selection is deleted; otherwise, the range `startPtr' to `endPtr' is selected and deleted. |
|
Deletes the selection if one exists. For example, after a successful clipCopy(), the selected block is deleted. |
|
Can be used in both find and find/replace operations, depending on the state of editorFlags data member bits and user-dialog box interactions. If efDoReplace is not set, doSearchReplace() acts as a simple search for findStr data member, with no replacement. Otherwise, this function aims at replacing occurrences of findStr with replaceStr data member. In all cases, if the target string is not found, an editorDialog(edSearchFailed) call is invoked.
|
|
If updateFlags data member is 0, nothing happens. Otherwise, the view and its scrollbars are updated and redrawn depending on the state of the updateFlags bits. For example, if ufView is set, the view is redrawn with drawView(). If the view is sfActive, the command set is updated with updateCommands().
|
|
Deletes the buffer. Reimplemented in TFileEditor. |
|
Overrides TView::draw() to draw the editor. Reimplemented from TView. |
|
Draws `count' copies of the line at `linePtr', starting at line position `y'. |
|
Finds occurrences of the existing findStr or a new user-supplied string. find() displays an editor dialog inviting the input of a find string or the acceptance of the existing findStr. If a new find string is entered, it will replace the previous findStr (unless the user cancels). find() first creates a TFindDialogRec object defined as follows:
struct TFindDialogRec { TFindDialogRec(const char *str, ushort flgs) { strcpy(find, str); options = flgs; } char find[80]; ushort options; }; The constructor is called with `str' set to the current findStr, and `flgs' set to the current editorFlags. The edFind editor dialog then invites change or acceptance of the findStr. Finally, doSearchReplace() is called for a simple find-no-replace (efDoReplace switched off). |
|
Formats the line at `linePtr' in the given color and sets result in `buff'. Used by drawLines(). |
|
Returns the buffer character pointer corresponding to the point `m' on the screen. |
|
Returns the default TEditor palette. Override if you wish to change the palette of the editor. Reimplemented from TView. Reimplemented in TMemo. |
|
Provides the event handling for the editor. Override if you wish to extend the commands the editor handles. The default handler calls TView::handleEvent(), then converts all relevant editing key events to command events by calling convertEvent(). Reimplemented from TView. Reimplemented in TMemo, and TFileEditor. |
|
Returns True if a selection has been made; that is, if selStart does not equal selEnd. If these two data members are equal, no selection exists, and False is returned. |
|
Sets selecting to False and hides the current selection with setSelect(curPtr, curPtr, False).
|
|
Allocates a buffer of size bufSize and sets buffer to point at it. Reimplemented in TFileEditor. |
|
This is the lowest-level text insertion member function. It inserts `length' bytes of text from the array `p' (starting at p[offset]) into the buffer (starting at the curPtr). If `allowUndo' is set True, insertBuffer() records undo information. If `selectText' is set True, the inserted text will be selected. insertBuffer() returns True for a successful operation. Failure invokes a suitable dialog box and returns False. insertBuffer() is used by insertFrom() and insertText(); you will seldom need to call it directly. |
|
Inserts the current block-marked selection from the argument `editor' into this editor. This member function implements clipCut(), clipCopy(), and clipPaste(). The implementation may help you understand the insertFrom() and insertBuffer() functions:
Boolean TEditor::insertFrom(TEditor *editor) { return insertBuffer(editor->buffer, editor->bufPtr(editor->selStart), editor->selEnd - editor->selStart, canUndo, isClipboard()); } Note the the `allowUndo' argument is set to the value of the data member canUndo. The `selectText' argument will be True if there is an active clipboard for this editor. |
|
Copies `length' bytes from the given text into this object's buffer. If `selectText' is True, the inserted text will be selected. This is a simplified version of insertBuffer(). |
|
Returns True if this editor has an attached clipboard; otherwise returns False. |
|
Returns the buffer pointer (offset) of the end of the line containing the given pointer `p'. |
|
Moves the line containing the pointer (offset) `p' up or down `count' lines depending on the sign of `count'. |
|
Returns the buffer pointer (offset) of the start of the line contaning the given pointer `p'. |
|
Increments the semaphore lockCount. |
|
Inserts a newline at the current pointer. If autoIndent is set, appropriate tabs (if needed) are also inserted at the start of the new line. |
|
Returns the buffer offset for the character following the one at the given offset `p'. |
|
Returns the buffer offset for the start of the line following the line containing the given offset `p'. |
|
Returns the buffer offset for the start of the word following the word containing the given offset `p'. |
|
Returns the buffer offset for the character preceding the one at the given offset `p'. |
|
Returns the buffer offset for the start of the line preceding the line containing the given offset `p'. |
|
Returns the buffer offset corresponding to the start of the word preceding the word containing the given offset `p'. |
|
Reads an editor object from the input stream `is'. Reimplemented from TView. Reimplemented in TMemo, and TFileEditor. |
|
Replaces occurrences of the existing findStr (or a new user-supplied find string) with the existing replaceStr (or a new user-supplied replace string). replace() displays an editor dialog inviting the input of both strings or the acceptance of the existing findStr and replaceStr. If new strings are entered, they will replace the previous values (unless the user cancels). replace() first creates a TReplaceDialogRec object defined as follows:
struct TReplaceDialogRec { TReplaceDialogRec(const char *str, const char *rep, ushort flgs) { strcpy(find, str); strcpy(replace, rep); options = flgs; } char find[80]; char replace[80]; ushort options; }; The constructor is called with `str' and `rep' set to the current findStr and replaceStr, and with `flg' set to the current editorFlags. The edReplace editor dialog then invites change or acceptance of the two strings.
|
|
Move column `x' and line `y' to the upper-left corner of the editor. |
|
Search for the given string `findStr' in the editor buffer (starting at curPtr) with the given options in `opts'. The valid options are:
Name Value Description efCaseSensitive 0x0001 Case sensitive search efWholeWordsOnly 0x0002 Whole words only search Returns True if a match is found; otherwise returns False. If a match is found, the matching text is selected. |
|
Sets bufLen to `length', then adjusts gapLen and limit accordingly. selStart, selEnd, curPtr, delta.x, delta.y, drawLine, drawPtr, delCount, and insCount are all set to 0.
The TEditor constructor calls setBufLen(0). setBufLen() is also used by insertBuffer().
|
|
Should be called before changing the buffer size to `newSize'. It should return True if the the buffer can be of this new size. By default, it returns True if `newSize' is less than or equal to bufSize. Reimplemented in TFileEditor. |
|
Enables or disables the given command depending on whether `enable' is True or False and whether the editor is sfActive.
|
|
Calls setSelect() and repositions curPtr to the offset `p'. Some adjustments may be made, depending on the value of `selectMode', if curPtr is at the beginning or end of a selected text. |
|
Sets the selection to the given offsets into the file, and redraws the view as needed. This member function will either place the cursor in front of or behind the selection, depending on the value (True or False, respectively) of `curStart'. |
|
Overrides TView::setState() to hide and show the indicator and scroll bars. It first calls TView::setState() to enable and disable commands. If you wish to enable and disable additional commands, override updateCommands() instead. This is called whenever the command states should be updated. Reimplemented from TView. |
|
Used internally by TObject::destroy() to ensure correct destruction of derived and related objects. shutDown() is overridden in many classes to ensure the proper setting of related data members when destroy() is called. Reimplemented from TView. Reimplemented in TFileEditor. |
|
Called by handleEvent() when a Ctrl-K Ctrl-B selection is detected. Hides the previous selection and sets selecting to True. |
|
Toggles the overwrite data member from True to False and from False to True. Changes the cursor shape by calling setState(). |
|
Forces the cursor to be visible. If `center' is True, the cursor is forced to be in the center of the screen in the y (line) direction. The x (column) position is not changed. |
|
Undoes the changes since the last cursor movement. |
|
Decrements the data member lockCount until it reaches the value 0, at which point a doUpdate() is triggered. The lock/unlock mechanism prevents over-frequent redrawing of the view. |
|
Sets `aFlags' in the updateFlags data member. If lockCount is 0, calls doUpdate(). |
|
Called whenever the commands should be updated. This is used to enable and disable commands such as cmUndo and cmCopy. Reimplemented in TFileEditor. |
|
Returns whether the view is valid for the given command. By default it returns the value of isValid, which is True if buffer is not 0. Reimplemented from TView. Reimplemented in TFileEditor. |
|
Writes to the output stream `os'. Reimplemented from TView. Reimplemented in TMemo, and TFileEditor. |
|
True if the editor is in autoindent mode. |
|
The amount of text stored between the start of the buffer and the current cursor position. |
|
Size of the buffer (in bytes). |
|
Pointer to the buffer used to hold the text. |
|
True if the editor is to support undo. Otherwise False. |
|
Pointer to the clipboard. Any TEditor can be the clipboard; it just needs be assigned to this variable. The clipboard should not support undo (i.e., its canUndo should be false). |
|
The line/column location of the cursor in the file. |
|
Offset of the cursor. |
|
Number of characters in the end of the gap that were deleted from the text. Used to implement undo(). |
|
The top line and leftmost column shown in the view. |
|
Column position on the screen where inserted characters are drawn. Used internally by draw(). |
|
Buffer offset corresponding to the current cursor. Used internally by draw(). |
|
The TEditorDialog data type is a pointer to function returning ushort and taking one int argument and a variable number of additional arguments. It is defined in `editors.h' as follows:
typedef ushort (*TEditorDialog)(int, ...); Variable editorDialog is a function pointer used by TEditor objects to display various dialog boxes. Since dialog boxes are very application-dependent, a TEditor object does not display its own dialog boxes directly. Instead it controls them through this function pointer. The various dialog values, passed in the first int argument, are self-explanatory: edOutOfMemory, edReadError, edWriteError, edCreateError, edSaveModify, edSaveUntitled, edSaveAs, edFind, edSearchFailed, edReplace and edReplacePrompt. The default editorDialog, defEditorDialog(), simply returns cmCancel. |
|
Variable editorFlags contains various flags for use in the editor:
Name Value Description efCaseSensitive 0x0001 Default to case-sensitive search efWholeWordsOnly 0x0002 Default to whole words only search efPromptOnReplace 0x0004 Prompt on replace efReplaceAll 0x0008 Replace all occurrences efDoReplace 0x0010 Do replace efBackupFiles 0x0100 Create backup files with a trailing ~ on saves The default value is efBackupFiles | efPromptOnReplace. |
|
Stores the last string value used for a find operation. |
|
The size of the "gap" between the text before the cursor and the text after the cursor. |
|
Pointer to the horizontal scroll bar; 0 if the scroll bar does not exist. |
|
Pointer to the indicator; 0 if the indicator does not exist. |
|
Number of characters inserted into the text since the last cursor movement. Used to implement undo(). |
|
True if the view is valid. Used by the valid() function. |
|
Indicates that a special key, such as Ctrl-K, has been pressed. Used by handleEvent() to keep track of "double" control keys such as Ctrl-K-H and Ctrl-K-B. |
|
The maximum number of columns to display, and the number of lines in the file. Records the limits of the scroll bars. |
|
Holds the lock count semaphore that controls when a view is redrawn. lockCount is incremented by lock() and decremented by unlock(). |
|
True if the buffer has been modified. |
|
Undocumented. Reimplemented from TView. Reimplemented in TMemo, and TFileEditor. |
|
True if in overwrite mode; otherwise the editor is in insert mode. |
|
Stores the last string value of a replace operation. |
|
The offset of the end of the text selected by Ctrl-K Ctrl-K. |
|
The offset of the start of the text selected by Ctrl-K Ctrl-B. |
|
True if the editor is in selecting mode (that is, Ctrl-K Ctrl-B has been pressed). |
|
A set of flags indicating the state of the editor. doUpdate() and other member functions examine these flags to determine whether the view needs to be redrawn. |
|
Pointer to the vertical scroll bar; 0 if the scroll bar does not exist. |