1 /***************************************************************************
2                           Edit.h - The main Editor implementation
3                              -------------------
4     begin                : Thu Mar  1 13:15:18 IST 2001
5     copyright            : (C) 2001 by Arie Tal
6     email                : tal_arie@yahoo.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 
19 
20 #ifndef __Edit_h__
21 #define __Edit_h__
22 
23 #include "hebFile.h"
24 #include <string.h>
25 #include "Input.h"
26 #include "Array.h"
27 #include "Action.h"
28 #include "Screen.h"
29 #include "aString.h"
30 #include "aDictionary.h"
31 
32 #include "aWindow.h"
33 
34 // recompile_section after MAX_DELAY events of Char and Delete/BackSpace
35 // so recompile only the current line.
36 // set MAX_DELAY to 1 to recompile_section after every Char/Delete/BackSpace event.
37 //   for Delete/BackSpace, recompilation is delayed only if the action is assured to not involve any other lines,
38 //   because Delete can JOIN the next line with the current, when pressed at EOL, and BackSpace can JOIN the
39 //  current with the previous, when at HOL (Home Of Line)
40 #define MAX_DELAY 20
41 
42 #ifndef TRUE
43 #define TRUE 1
44 #define FALSE 0
45 #endif
46 
47 #define READ_ONLY 1
48 
49 #define SCRATCH_BUFFER_NAME "~~scratch~~"
50 
51 #include "Undo.h"
52 
53 class HebrewEditor ;
54 
55 class Edit {
56 protected:
57    HebrewEditor *he ;
58    Undo undo ;
59    Marker work_marker ;
60    aString work_data_block ;
61    int screen_start_line, screen_start_column ;
62    hebFile* file_p ;
63    aString name ;
64    int curx, cury, cury_offset ;
65    aWindow *win ;
66    Input input ;
67    int continue_edit ;
68    int first_line ; /* of file, that is show on screen */
69    int first_offset ; /* within line that is split into several virtual lines */
70    int current_line ;
71    int current_offset ;
72    int sizex, sizey ;
73    InputMode keyboard_mode ;
74    int specialSeparator ;
75    Action::Actions last_action ;
76    int esc, ctrlK, ctrlQ ;
77    char left_end_mark, right_end_mark ;
78    int read_only ;
79    int _x_position ;
80    int delay_compilation ;
81    int modified ;
82    static char buffer[MAX_SCREEN_WIDTH] ;
83    static char buffer2[MAX_SCREEN_WIDTH] ;
84    char workbuffer[5000] ;
85    char workbuffer2[5000] ;
86 public:
87    hebFile& file ;
88    Edit *from ;
89    Action &action ;
90    // these are updated by refresh and used by _relocateAtMarker()
91 protected:
getActiveSpelling()92    virtual int  getActiveSpelling() { return 1 ; }
93    virtual char *suggestWords(aDictionary *dict, aString& word) ;
show_line_end_marks()94    virtual int show_line_end_marks() { return 1 ; }
_need_to_save()95    virtual int _need_to_save() { return 1 ; }
96    virtual void _maketitle(int show = 1) ;
97    virtual void _scroll(int lines, int refresh_flag = 1) ;
98    virtual void _refresh() ;
99    virtual void _quite_refresh() ;
100    virtual char * _newline() ; // new line returns the characters that were added, since
101                         // indentation can be applied (for undo purposes)
102    virtual void _display_line(int num) ;
103    virtual int  _line_to_display(int num) ;
104    virtual int _x_pos() ;
105    virtual void _next_page(int refresh_flag=1) ;
106    virtual void _previous_page(int refresh_flag=1) ;
107    virtual int _next_line(int refresh_flag = 1) ;
108    virtual int _previous_line(int refresh_flag =1) ;
109    virtual void _forward() ;
110    virtual void _backward() ;
111    virtual void _calc_curx() ; // updates curx, _x_position and keyboard_mode
112    virtual int _relocate_curx(int update) ; // updates curx, _x_position and keyboard_mode , moves to next/previous logical
113                                                                  // position
114 // MESSAGE HANDLERS
115 public:
116    virtual void _LaxetCommandHelp(Action::Actions act) ;
117    virtual void _SpellWord(Action::Actions act) ;
118    virtual void _LearnAllWords(Action::Actions act) ;
_Tab(Action::Actions act)119    virtual void _Tab(Action::Actions act) {}
120    virtual void _MarkBlockBegin(Action::Actions act) ;
121    virtual void _MarkBlockEnd(Action::Actions act) ;
122    virtual void _UnmarkBlock(Action::Actions act) ;
123    virtual void _DeleteBlock(Action::Actions act) ;
124    virtual void _CopyBlock(Action::Actions act) ;
125    virtual void _MoveBlock(Action::Actions act) ;
126    virtual void _Suspend(Action::Actions act) ;
127    virtual void _Help(Action::Actions act) ;
128    virtual void _Find(Action::Actions act) ;
129    virtual void _FindReplace(Action::Actions act) ;
130    virtual void _DeleteChar(Action::Actions act) ;
131    virtual void _BackSpace(Action::Actions act) ;
132    virtual void _DeleteLine(Action::Actions act) ;
133    virtual void _SaveFile(Action::Actions act) ;
134    virtual void _Refresh(Action::Actions act) ;
135    virtual void _NewLine(Action::Actions act) ;
136    virtual void _Exit(Action::Actions act) ;
137    virtual void _NextLogicalWord(Action::Actions act) ;
138    virtual void _PreviousLogicalWord(Action::Actions act) ;
139    virtual void _RealForwardChar(Action::Actions act) ;
140    virtual void _RealBackwardChar(Action::Actions act) ;
141    virtual void _WordRight(Action::Actions act) ;
142    virtual void _WordLeft(Action::Actions act) ;
143    virtual void _ForwardChar(Action::Actions act) ; // go right
144    virtual void _BackwardChar(Action::Actions act) ; // go left
145    virtual void _NextLine(Action::Actions act) ;
146    virtual void _PreviousLine(Action::Actions act) ;
147    virtual void _Home(Action::Actions act) ;
148    virtual void _End(Action::Actions act) ;
149    virtual void _BeginningOfFile(Action::Actions act) ;
150    virtual void _EndOfFile(Action::Actions act) ;
151    virtual void _PgUp(Action::Actions act) ;
152    virtual void _PgDn(Action::Actions act) ;
153    virtual void _Char(Action::Actions act) ;
154    virtual void _LanguageToggle(Action::Actions act) ;
155    virtual void _ChangeDirection(Action::Actions act) ;
156    virtual void _Undo(Action::Actions act) ;
157    virtual void _Redo(Action::Actions act) ;
158 public:
159    Edit(HebrewEditor *he, const char *name, aWindow *win, int read_only = 0 , char *title=0) ;
160    // READ ONLY initialized from data_block ;
161    Edit(HebrewEditor *he, char *title, const char *text, aWindow *win, int read_only = 1 ) ;
162 
~Edit()163    virtual ~Edit() {}
164 
165    virtual void processFile(int show=1) {
166         if (show) {
167           _maketitle() ;
168           win->Message("(Processing files)") ;
169        }
170        file.recompile_file(sizex) ;
171    }
172 
refresh()173    virtual void refresh() {
174        win->Refresh() ;
175        win->MessageTip() ;
176        _refresh() ;
177    }
finished()178    virtual int finished() { return !continue_edit ; }
179    virtual void processAction(Action::Actions act) ;
getNextAction()180    Action::Actions getNextAction() { return action.getNextAction() ; }
setName(char * newname)181    void setName(char *newname) { name  = newname ; file.setName(newname) ; }
getName()182    aString& getName() { return name ; }
183    void goto_line(int num) ;
184    void searchFor(char *text) ;
185    void searchForNext(char *text) ;
186    void searchForPrevious(char *text) ;
where()187    Marker where() { Marker m={current_line, curx-1, cury} ; return m ; }
188    void _insertDataBlock(Marker location, char * data_block) ;
189    void _deleteDataBlock(Marker location, char * data_block) ;
190    virtual void _relocateAtMarker(Marker mark) ;
191    virtual void _markBlock(Marker startm, Marker endm, int copy_to_scratch=0) ;
192    virtual void _markBlock(int copy_to_scratch=0) ; // mark block by file.start_marker, file.end_marker
get_current_line()193    virtual int get_current_line() { return current_line ; }
getModified()194    virtual int getModified() { return undo.is_modified() ; }
195 } ;
196 
197 #endif
198