/* * 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 true * 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 = true, int caretstyle = BarCaret); FullTextEditor( const char* name, int r, int c, int t = 8, int h = Reversed, bool scroll = true, bool cmdline = true, 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); }; /* * The following are inline implementations of the public TextEditor functions. * An alternative to this approach would be to subclass FullTextEditor from * both Monoscene and TextEditor. This multiple inheritance scheme was not * chosen, since it would require further modifications to the FullTextEditor * class and its member functions. Also, multiple inheritance makes me ill. * * And yes, I know that putting function implementations in the .h file is * seriously bad style. However, for some unknown reason, g++ won't compile * the inline virtuals correctly when they're in the .c file. So, rather than * put only inline virtuals here, and the rest in the .c file, they're all * here. */ inline int FullTextEditor::Dot() {return editor->Dot();} inline int FullTextEditor::Mark() {return editor->Mark();} inline void FullTextEditor::InsertText(const char* s, int i) {editor->InsertText(s,i);} inline void FullTextEditor::DeleteText(int i) {editor->DeleteText(i);} inline void FullTextEditor::DeleteSelection() {editor->DeleteSelection();} inline void FullTextEditor::BackwardCharacter(int i) {editor->BackwardCharacter();} inline void FullTextEditor::ForwardCharacter(int i) {editor->ForwardCharacter(i);} inline void FullTextEditor::BackwardLine(int i) {editor->BackwardLine(i);} inline void FullTextEditor::ForwardLine(int i) {editor->ForwardLine(i);} inline void FullTextEditor::BackwardWord(int i) {editor->BackwardWord(i);} inline void FullTextEditor::ForwardWord(int i) {editor->ForwardWord(i);} inline void FullTextEditor::BackwardPage(int i) {editor->BackwardPage(i);} inline void FullTextEditor::ForwardPage(int i) {editor->ForwardPage(i);} inline void FullTextEditor::BeginningOfLine() {editor->BeginningOfLine();} inline void FullTextEditor::EndOfLine() {editor->EndOfLine();} inline void FullTextEditor::BeginningOfWord() {editor->BeginningOfWord();} inline void FullTextEditor::EndOfWord() {editor->EndOfWord();} inline void FullTextEditor::BeginningOfSelection() {editor->BeginningOfSelection();} inline void FullTextEditor::EndOfSelection() {editor->EndOfSelection();} inline void FullTextEditor::BeginningOfText() {editor->BeginningOfText();} inline void FullTextEditor::EndOfText() {editor->EndOfText();} inline void FullTextEditor::SetScrollAlignment(Alignment a) {editor->SetScrollAlignment(a);} inline Alignment FullTextEditor::GetScrollAlignment() {return editor->GetScrollAlignment();} inline void FullTextEditor::ScrollToSelection(bool always) {editor->ScrollToSelection(always);} inline void FullTextEditor::ScrollToView(Coord x, Coord y) {editor->ScrollToView(x, y);} inline void FullTextEditor::ScrollBy(Coord dx, Coord dy) {editor->ScrollBy(dx, dy);} inline void FullTextEditor::GrabScroll(Event& e) {editor->GrabScroll(e);} inline void FullTextEditor::RateScroll(Event& e) {editor->RateScroll(e);} inline void FullTextEditor::Adjust(Perspective& p) {editor->Adjust(p);} inline void FullTextEditor::Select(int dot) {editor->Select(dot);} inline void FullTextEditor::SelectMore(int mark) {editor->SelectMore(mark);} inline void FullTextEditor::SelectAll() {editor->SelectAll();} inline void FullTextEditor::Select(int dot, int mark) {editor->Select(dot, mark);} inline int FullTextEditor::Locate(Coord x, Coord y) {return editor->Locate(x, y);} inline void FullTextEditor::CaretStyle(int style) {editor->CaretStyle(style);} #endif