1
2 // ------------------------------------------------------------------
3 // GoldED+
4 // Copyright (C) 1990-1999 Odinn Sorensen
5 // Copyright (C) 1999-2000 Alexander S. Aganichev
6 // ------------------------------------------------------------------
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 // MA 02111-1307 USA
21 // ------------------------------------------------------------------
22 // $Id: geedit.h,v 1.16 2006/07/03 17:04:07 stas_degteff Exp $
23 // ------------------------------------------------------------------
24 // The Internal Editor (IE).
25 // ------------------------------------------------------------------
26 #ifndef __GEEDIT_H
27 #define __GEEDIT_H
28
29 #ifdef __GNUG__
30 #pragma interface "geedit.h"
31 #endif
32
33
34 // ------------------------------------------------------------------
35 // Screen coordinate models
36 // ------------------------------------------------------------------
37 //
38 // 00 �������������������������� 01
39 // 01 Msg# : 02
40 // 02 From : 03
41 // 03 To : 04
42 // 04 Subj : 05
43 // 05 �������������������������� 06
44 // 06 00 EDIT_MINROW 07 EDIT_MIN_ROW
45 // 07 01 08
46 // 08 02 09
47 // 09 03 10
48 // 10 04 11
49 // 11 05 12
50 // 12 06 13
51 // 13 07 14
52 // 14 08 15
53 // 15 09 16
54 // 16 10 17
55 // 17 11 18
56 // 18 12 19
57 // 19 13 10
58 // 10 14 21
59 // 21 15 22
60 // 22 16 23
61 // 23 17 EDIT_MAXROW 24 EDIT_MAX_ROW
62 // 24 �GoldED xxxx (statusline) 25
63 // � � �
64 // � � ����� one-based old-style coord
65 // � ���������������������������������� editor window coordinates
66 // ������������������������������������� actual screen coordinates
67 //
68 // ------------------------------------------------------------------
69
70
71 // ------------------------------------------------------------------
72 // Defines
73
74 #define EDIT_BUFLEN 256
75 #define EDIT_PARABUFLEN 2048
76
77 #define EDIT_UNDO_CHAR 0x00000010U
78 #define EDIT_UNDO_INS_CHAR 0x00000011U
79 #define EDIT_UNDO_DEL_CHAR 0x00000012U
80 #define EDIT_UNDO_OVR_CHAR 0x00000014U
81
82 #define EDIT_UNDO_TEXT 0x00001000U
83 #define EDIT_UNDO_DEL_TEXT 0x00001100U
84 #define EDIT_UNDO_CUT_TEXT 0x00001200U
85 #define EDIT_UNDO_INS_TEXT 0x00001400U
86 #define EDIT_UNDO_WRAP_TEXT 0x00001800U
87
88 #define EDIT_UNDO_LINE 0x00100000U
89 #define EDIT_UNDO_DEL_LINE 0x00110000U
90 #define EDIT_UNDO_NEW_LINE 0x00120000U
91 #define EDIT_UNDO_PUSH_LINE 0x00140000U
92 #define EDIT_UNDO_POP_LINE 0x00180000U
93 #define EDIT_UNDO_ORPHAN_LINE 0x00190000U
94
95 #define EDIT_UNDO_VOID 0x00000000U
96
97 #define EDIT_UNDO_TYPE 0x00101010U
98 #define EDIT_UNDO_ACTION 0x001F1F1FU
99
100 #define LAST_LINE 0x20000000U
101 #define PREV_LINE 0x40000000U
102 #define BATCH_MODE 0x80000000U
103 #define NO_VALUE 0xFFFFFFFFU
104
105
106 // ------------------------------------------------------------------
107 // Globals
108
109 extern Line* Edit__killbuf;
110 extern Line* Edit__pastebuf;
111
112 extern Path Edit__exportfilename;
113
114
115 // ------------------------------------------------------------------
116 // Reality check define and function
117
118 #ifdef NDEBUG
119 #define _test_halt(__t)
120 #define _test_haltab(__t, __a, __b)
121 #else
122 #define _test_halt(__t) if(__t) { debugtest(#__t, 0, 0, __FILE__, __LINE__, false); }
123 #define _test_haltab(__t, __a, __b) if(__t) { debugtest(#__t, __a, __b, __FILE__, __LINE__, true); }
124 #endif
125
126
127 // ------------------------------------------------------------------
128 // Undo data structures
129
130 class text_item {
131
132 public:
133
134 uint col; // Begining offset in the .text string
135 uint len; // Text length
136 __extension__ char text[0]; // Text string itself
137
text_item(uint __col,uint __len)138 text_item(uint __col, uint __len) : col(__col), len(__len) { }
139 void* operator new(size_t size, uint text_len = 0) { return malloc(sizeof(text_item) + size + text_len); }
delete(void * ptr)140 void operator delete(void* ptr) { free(ptr); }
delete(void * ptr,uint)141 void operator delete(void* ptr, uint) { free(ptr); }
142 };
143
144 // ----------------------------------------------------------------
145
146 union data_rec {
147
148 text_item* text_ptr;
149 Line* line_ptr;
150 void* void_ptr;
151 char char_int;
152 };
153
154 struct col_rec {
155
156 uint num;
157 uint sav;
158 };
159
160 // ----------------------------------------------------------------
161
162 class UndoItem {
163
164 static UndoItem** last_item;
165
166 friend class UndoStack;
167
168 public:
169
170 UndoItem* prev;
171
172 Line* line; // Cursor line
173 col_rec col; // Cursor column
174 uint pcol; // After undo move cursor to pcol, prow
175 uint prow; //
176 uint action; // Undo action
177 data_rec data; // Undo data
178
UndoItem()179 UndoItem() { this->prev = *last_item; }
~UndoItem()180 ~UndoItem() { *last_item = this->prev; }
181 };
182
183 // ----------------------------------------------------------------
184
185 class IEclass;
186
187 class UndoStack {
188
189 IEclass* editor;
190
191 uint& row;
192 uint& col;
193 uint& pcol;
194 uint& prow;
195 uint& minrow;
196 uint& maxrow;
197 uint& thisrow;
198 Line*& currline;
199 bool& undo_ready;
200
201 public:
202
203 UndoItem* last_item;
204 bool undo_enabled;
205
206 UndoStack(IEclass* this_editor);
207 ~UndoStack();
208
209 bool FixPushLine(Line* __line);
210 void PushItem(uint action, Line* __line = NULL, uint __col = NO_VALUE, uint __len = NO_VALUE);
211 void PlayItem();
212 };
213
214
215 // ------------------------------------------------------------------
216 // Internal Editor Class
217
218 class IEclass : public Container {
219
220 public:
221
222 gwindow editwin; // window
223
224 protected:
225
226 // ----------------------------------------------------------------
227 // Editor window data
228
229 int win_mincol; // First column
230 int win_minrow; // First row
231 int win_maxcol; // Last column
232 int win_maxrow; // Last row
233 int win_border; // Border type
234 int win_hasborder; // 1 == window has a border, 0 == no border
235
236
237 // ----------------------------------------------------------------
238 // Window-relative minimum/maximum values
239
240 uint mincol;
241 uint minrow;
242 uint maxcol;
243 uint maxrow;
244
245
246 // ----------------------------------------------------------------
247 // Cursor coordinates
248
249 uint col;
250 uint row;
251 uint pcol;
252 uint prow;
253 uint ccol;
254 uint crow;
255
256
257 // ----------------------------------------------------------------
258 // Undo stuff
259
260 friend class UndoStack;
261
262 UndoStack* Undo;
263 long batch_mode;
264 bool undo_ready;
265
266
267 // ----------------------------------------------------------------
268 // Misc.
269
270 int chartyped;
271 Line* currline;
272 int done;
273 int insert;
274 int drawlines;
275 int drawflag;
276 int marginquotes;
277 int margintext;
278 int msgmode;
279 GMsg* msgptr;
280 int quitnow;
281 uint thisrow;
282 char* unfinished;
283 int blockcol;
284 int selecting;
285
286 // ----------------------------------------------------------------
287 // Speller (DLL)
288
289 #if defined(GCFG_SPELL_INCLUDED)
290 CSpellChecker schecker;
291 #endif
292
293 // ----------------------------------------------------------------
294 // Internal helper functions
295
296 void clreol (int __col=-1, int __row=-1);
297 void cursoroff ();
298 void cursoron ();
299 void deleteline (bool zapquotesbelow = false);
300 vattr dispchar (vchar __ch, vattr attr = DEFATTR);
301 void dispins ();
302 void dispdl ();
303 void displine (Line* __line, uint __row);
304 #if defined(GCFG_SPELL_INCLUDED)
305 void dispstringsc (char *__buf, uint __beg, uint __end, uint __row, uint __col, char endchar);
306 void dispstring (Line* line, uint __row);
307 #else
308 void dispstring (const char* __string, uint __row, int attr=-1, Line* line=NULL);
309 #endif
310 int downoneline (uint __row);
311 void editexport (Line* __exportline, int __endat);
312 Line* findanchor ();
313 Line* findfirstline ();
314 Line* findtopline ();
315 void getthisrow (Line* __currline);
316 void gotorowcol (uint __col, uint __row);
317 int handlekey (gkey __key);
318 void editimport (Line* __line, char* __filename, bool imptxt = false);
319 void imptxt (char* __filename, bool imptxt = false);
320 void insertchar (char __ch);
321 Line* insertlinebelow (Line* __currline, const char* __text = NULL, long __batch_mode = 0);
322 int isempty (Line* __line=NULL);
323 void killkillbuf ();
324 void killpastebuf ();
325 void prints (int wrow, int wcol, vattr atr, const char* str);
326 int reflowok (char* __qstr);
327 void refresh (Line* __currline, uint __row);
328 void savefile (int __status);
329 void scrolldown (int __scol, int __srow, int __ecol, int __erow, int __lines=1);
330 void scrollup (int __scol, int __srow, int __ecol, int __erow, int __lines=1);
331 void setcolor (Line* __line);
332 void setlinetype (Line* __line);
333 void statusline ();
334 void windowclose ();
335 void windowopen ();
336 Line* wrapit (Line** __currline, uint* __curr_col, uint* __curr_row, bool __display=true);
337 Line* wrapdel (Line** __currline, uint* __curr_col, uint* __curr_row, bool __display=true);
338 Line* wrapins (Line** __currline, uint* __curr_col, uint* __curr_row, bool __display=true);
339
340 #ifndef NDEBUG
341 void debugtest (char* __test, int __a, int __b, char* __file, int __line, int __values);
342 #endif
343
344 void Buf2Clip ();
345 void Clip2Buf ();
346
347
348 public:
349
350 // ----------------------------------------------------------------
351 // Constructor and destructor
352
353 IEclass(int __scol, int __ecol, int __srow, int __erow, int __border);
354 ~IEclass();
355
356
357 // ----------------------------------------------------------------
358 // Function to start the editor
359
360 int Start(int __mode, uint* __position, GMsg* __msg);
361
362
363 // ----------------------------------------------------------------
364 // User key functions
365
366 void Abort ();
367 void AskExit ();
368 void BlockAnchor ();
369 void BlockCopy ();
370 void BlockCut (bool just_delete = false);
371 void BlockPaste ();
372 void BlockDel (Line* _anchor);
373 void ClearDeleteBuf ();
374 void ClearPasteBuf ();
375 void CopyAboveChar ();
376 void DelChar ();
377 void DeleteEOL ();
378 void DeleteSOL ();
379 void DelLeft ();
380 void DelLine ();
381 void DelLtWord ();
382 void DelRtWord ();
383 void DosShell ();
384 void DupLine ();
385 void ExitMsg ();
386 void ExportText ();
387 void GoBegLine ();
388 void GoBotLine ();
389 void GoBotMsg ();
390 void GoDown ();
391 void GoEOL ();
392 void GoLeft ();
393 void GoPgDn ();
394 void GoPgUp ();
395 void GoRight ();
396 void GoTopLine ();
397 void GoTopMsg ();
398 void GoUp ();
399 void GoWordLeft ();
400 void GoWordRight ();
401 void Header ();
402 void ImportQuotebuf ();
403 void ImportText ();
404 void LoadFile ();
405 void LookupCursor ();
406 void LookupDest ();
407 void LookupOrig ();
408 void Newline ();
409 void QuitNow ();
410 void Reflow ();
411 void ReTab ();
412 void SaveFile ();
413 void SaveMsg ();
414 #if defined(GCFG_SPELL_INCLUDED)
415 void SCheckerMenu ();
416 #endif
417 void Soundkill ();
418 // External spell check tool
419 void SpellCheck ();
420 void Tab ();
421 void ToggleCase ();
422 void ToggleCaseBlock(gkey key);
423 void SCodeChange(gkey key);
424 void ToggleInsert ();
425 void ToggleDrawLines();
426 void DrawLines (gkey key);
427 void ToLower ();
428 void ToUpper ();
429 void UnDelete (bool before=true);
430 void ZapQuoteBelow ();
431
432 private:
433 void ToggleCaseChar(gkey key, std::string::iterator it, Line *ln, int n);
434
435 // ----------------------------------------------------------------
436 };
437
438 // ------------------------------------------------------------------
439
440 void Edit__killpastebuf(void);
441
killpastebuf()442 inline void IEclass::killpastebuf() { Edit__killpastebuf(); }
443
444 // ------------------------------------------------------------------
445
446 #endif
447