/* * Class FullTextEditor defines user-editable text editor. It is based on the * standard InterViews' application sted.c, defined in iv/src/bin/sted/. Class * FullTextEditor is a monoscene that contains an InterViews TextEditor, with * an automatically allocated TextBuffer. * * A FullTextEditor has the same two constructors as a standard InterViews * TextEditor. Namely, the first constructor takes rows, cols, tabsize, and * highlight. When the FullTextEditor is built, it allocates a TextEditor, * containing a TextBuffer of an appropriate size to hold rows and cols. The * second FullTextEditor constructor adds a name as the first parameter. This * parameter is taken as the name of a file to open as the initial contents of * the text buffer. * * FullTextEditor adds additional option parameters to each constructor. The * options are the following * * OPTION DESCRIPTION DEFAULT * ======================================================================= * bool scroll true => scroll bar on true * * bool cmdline true => emacs-like command-entry at bottom false * of text window * * int caretstyle one of the following pre-defined constants: BarCaret * NoCaret, BarCaret, UnderscoreCaret, * OutlineCaret * * * To the end user, a FullTextEditor implements the same basic editing model as * defined in the original sted.c. Hence, "man sted" describes the user-level * features of a FullTextEditor exactly, except that following three operations * are omitted: * * quit, close, and visit * * Quit is omitted, since a FullTextEditor is intended to be used as an * interactor embedded inside an InterViews application. Close is omitted, * since it leads to quit. Visit is omitted, since it causes a new window to * pop-up, which is inappropriate behavior for an embedded interactor. * * To the InterViews application programmer, a FullTextEditor provides all of * the public functions of a TextEditor. Hence, "man TextEditor" describes all * of the programmer-level features of a FullTextEditor exactly, except for * three additional public functions. The additional functions are: * * void Open(char *name) -- open a file, and insert the contents of the * file into the buffer * * char* GetFilename() -- return the name of the currently open file * * TextBuffer* GetBuffer() -- return the contained TextBuffer (for the * purposes of accessing its text) * * Note that since a FullTextEditor automatically allocates a TextBuffer, the * programmer does not normally need to call FullTextEditor::Edit. When * necessary, the contained buffer is accessed via the function GetBuffer. * */ #ifndef fulltexteditorIncluded #define fulltexteditorIncluded #include "std-macros.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static const int MINTEXTSIZE = 10000; static const int BUFFERSIZE = 100; static const int FILENAMESIZE = 100; class CaretModifiableTextEditor; class FullTextEditor : public MonoScene { /* * The following public and protected members are from the StedWindow class, * defined originally in iv/src/bin/sted.c. */ public: FullTextEditor( int rows, int cols, int tabsize = 8, int highlight = Reversed, bool scroll = true, bool cmdline = false, int caretstyle = BarCaret); FullTextEditor( const char* name, int r, int c, int t = 8, int h = Reversed, bool scroll = true, bool cmdline = false, int caretstyle = BarCaret); virtual ~FullTextEditor(); void Open(const char* filename); const char* GetFilename(); TextBuffer* GetBuffer(); protected: void Init(const char* filename, bool scroll, bool cmdline, int caretstyle); virtual void Handle(Event&); virtual void Update(); void Edit(const char* filename); void Do(const char*); void Ask(const char*, int, int); void HandleChar(char); void LeftMouse(Event&); char lastchar; char filename[FILENAMESIZE]; bool modified; bool prefix1; bool prefix2; char* buffer; int size; TextBuffer* text; CaretModifiableTextEditor* editor; StringEditor* command; ButtonState* state; void Complain(); /* * The following public functions are all of the public functions available * in a TextEditor. */ public: int Dot(); int Mark(); void InsertText(const char*, int); void DeleteText(int); void DeleteSelection(); void BackwardCharacter(int = 1), ForwardCharacter(int = 1); void BackwardLine(int = 1), ForwardLine(int = 1); void BackwardWord(int = 1), ForwardWord(int = 1); void BackwardPage(int = 1), ForwardPage(int = 1); void BeginningOfLine(), EndOfLine(); void BeginningOfWord(), EndOfWord(); void BeginningOfSelection(), EndOfSelection(); void BeginningOfText(), EndOfText(); void SetScrollAlignment(Alignment); Alignment GetScrollAlignment(); void ScrollToSelection(bool always = false); void ScrollToView(Coord x, Coord y); void ScrollBy(Coord dx, Coord dy); void GrabScroll(Event&); void RateScroll(Event&); virtual void Adjust(Perspective&); void Select(int dot); void SelectMore(int mark); void SelectAll(); void Select(int dot, int mark); int Locate(Coord x, Coord y); void CaretStyle(int style); }; /* * A CaretModifiableTextEditor is simply a standard InterViews TextEditor with * a new public function that allows the caret style of the underlying * TextDisplay to be changed. */ class CaretModifiableTextEditor : public TextEditor { public: CaretModifiableTextEditor(int rows, int cols, int tabsize, int highlight); CaretModifiableTextEditor( const char* name, int rows, int cols, int tabsize, int highlight); void CaretStyle(int style); }; #endif