/* * Sted is a class that defines a Simple Text Editor. It is based on the * standard InterViews' application sted.c, defined in iv/src/bin/sted/. Class * Sted is a monoscene that contains a TextEditor, with an automatically * allocated TextBuffer * * A Sted has the same two constructors as a standard InterViews TextEditor. * Namely, the first constructor takes rows, cols, tabsize, and highlight. * When the Sted is built, it allocates a TextEditor, containing a TextBuffer * of an appropriate size to hold rows and cols. The second Sted 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. * * To the end user, a Sted implements the basic editing model defined in the * original sted.c. Hence, "man sted" describes the user-level features of a * Sted exactly, except that following three operations are omitted: * * quit, close, and visit * * Quit is omitted, since a Sted 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 Sted provides all of the public * functions of a TextEditor. Hence, "man TextEditor" describes all of the * programmer-level features of a Sted 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 Sted automatically allocates a TextBuffer, the programmer * does not normally need to call Sted::Edit. When necessary, the contained * buffer is accessed via the function GetBuffer. * */ #ifndef stedIncluded #define stedIncluded #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 Sted : public MonoScene { /* * The following public and protected members are from the StedWindow class, * defined originally in iv/src/bin/sted.c. */ public: Sted(int rows, int cols, int tabsize, int highlight); Sted(const char* name, int r, int c, int t, int h); virtual ~Sted(); void Open(const char* filename); const char* GetFilename(); TextBuffer* GetBuffer(); protected: void Init(const char* filename); 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&); Sted* sted; char lastchar; char filename[FILENAMESIZE]; boolean modified; boolean prefix1; boolean prefix2; char* buffer; int size; TextBuffer* text; TextEditor* 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(boolean 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); Interactor* GetUpMover(); Interactor* GetDownMover(); Interactor* GetScroller(); protected: UpMover* upmover; Scroller* scroller; DownMover* downmover; }; /* * The following are quick inline implementations of the public TextEditor * functions. An alternative to this approach would be to subclass Sted from * both Monoscene and TextEditor. This multiple inheritance scheme was not * chosen, since it would require further modifications to the Sted class and * its member functions. */ inline int Sted::Dot() {return editor->Dot();} inline int Sted::Mark() {return editor->Mark();} inline void Sted::InsertText(const char* s, int i) {editor->InsertText(s,i);} inline void Sted::DeleteText(int i) {editor->DeleteText(i);} inline void Sted::DeleteSelection() {editor->DeleteSelection();} inline void Sted::BackwardCharacter(int i) {editor->BackwardCharacter();} inline void Sted::ForwardCharacter(int i) {editor->ForwardCharacter(i);} inline void Sted::BackwardLine(int i) {editor->BackwardLine(i);} inline void Sted::ForwardLine(int i) {editor->ForwardLine(i);} inline void Sted::BackwardWord(int i) {editor->BackwardWord(i);} inline void Sted::ForwardWord(int i) {editor->ForwardWord(i);} inline void Sted::BackwardPage(int i) {editor->BackwardPage(i);} inline void Sted::ForwardPage(int i) {editor->ForwardPage(i);} inline void Sted::BeginningOfLine() {editor->BeginningOfLine();} inline void Sted::EndOfLine() {editor->EndOfLine();} inline void Sted::BeginningOfWord() {editor->BeginningOfWord();} inline void Sted::EndOfWord() {editor->EndOfWord();} inline void Sted::BeginningOfSelection() {editor->BeginningOfSelection();} inline void Sted::EndOfSelection() {editor->EndOfSelection();} inline void Sted::BeginningOfText() {editor->BeginningOfText();} inline void Sted::EndOfText() {editor->EndOfText();} inline void Sted::SetScrollAlignment(Alignment a) {editor->SetScrollAlignment(a);} inline Alignment Sted::GetScrollAlignment() {return editor->GetScrollAlignment();} inline void Sted::ScrollToSelection(boolean always) {editor->ScrollToSelection(always);} inline void Sted::ScrollToView(Coord x, Coord y) {editor->ScrollToView(x, y);} inline void Sted::ScrollBy(Coord dx, Coord dy) {editor->ScrollBy(dx, dy);} inline void Sted::GrabScroll(Event& e) {editor->GrabScroll(e);} inline void Sted::RateScroll(Event& e) {editor->RateScroll(e);} inline void Sted::Adjust(Perspective& p) {editor->Adjust(p);} inline void Sted::Select(int dot) {editor->Select(dot);} inline void Sted::SelectMore(int mark) {editor->SelectMore(mark);} inline void Sted::SelectAll() {editor->SelectAll();} inline void Sted::Select(int dot, int mark) {editor->Select(dot, mark);} inline int Sted::Locate(Coord x, Coord y) {return editor->Locate(x, y);} inline UpMover* Sted::GetUpMover {return upmover}; inline Scroller* Sted::GetScroller {return scroller}; inline DownMover* Sted::GetDownMover {return downmover}; #endif