1 /**@file texteditor/texteditor.h  Text editor/viewer.
2  * $Id: texteditor.h,v 1.2 2003/12/21 03:21:29 bitman Exp $
3  * @author Ryan Phillips
4  *
5  * Copyright (C) 2003 Ryan Phillips <bitman@users.sf.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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
15  * GNU 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 #ifndef TEXTEDITOR_TEXTEDITOR_H
23 #define TEXTEDITOR_TEXTEDITOR_H
24 
25 #include "libzzt2/zzt.h"
26 #include "display/display.h"
27 #include "structures/svector.h"
28 #include "zoopdraw.h"
29 
30 
31 /* Text editor updateflags */
32 #define TUD_NONE      0x00
33 #define TUD_CENTER    0x01
34 #define TUD_BOTTOM    0x02
35 #define TUD_TOP       0x04
36 #define TUD_EDITAREA  0x07
37 #define TUD_TITLE     0x08
38 #define TUD_PANEL     0x10
39 #define TUD_ALL       0xFF
40 
41 #define TEXTED_MAXWIDTH 42
42 #define TEXTED_PAGELENGTH 7
43 
44 /** A powerful, extendable text editing environment.
45  *
46  * TEXTEDITOR REFERENCE -- texteditor key actions
47  * - Basic movement keys
48  *   - up       : moves cursor up
49  *   - down     : moves cursor down
50  *   - pageup   : moves up 8 lines
51  *   - pagedown : moves down 8 lines
52  *
53  * - Scroll/Browse Dialog
54  *   - enter    : exit with SCROLL_OK
55  *   - escape   : exit with SCROLL_CANCEL
56  *
57  * - Browse Dialog
58  *   - right    : exit with BROWSE_FORWARD
59  *   - left     : exit with BROWSE_BACKWARD
60  *   - backspace: exit with BROWSE_BACK
61  *
62  * - Text Editor
63  *   - Basic
64  *     - left     : moves cursor left
65  *     - right    : moves cursor right
66  *     - insert   : toggle insert/replace modes
67  *     - delete   : removes char under cursor
68  *     - home     : moves to beginning of line
69  *     - end      : moves to end of line
70  *     - tab      : inserts 4 spaces
71  *     - enter    : inserts newline
72  *     - escape   : exit
73  *     - backspace: deletes space before cursor, or blank lines
74  *     - alt+'-'  : decrease wordwrap width
75  *     - alt+'+'  : increase wordwrap width
76  *     - ctrl-y   : deletes the current line
77  *     - ctrl-a   : inserts an ascii character (or a number on #char statements)
78  *   - File
79  *     - alt-s   : save zoc to file
80  *     - alt-o   : open zoc file (erases buffer)
81  *     - alt-i   : insert zoc from file
82  *     - alt-m   : insert zzm song from file
83  *   - Copy and Paste
84  *     - shift   : highlighting
85  *     - ctrl-x   : cut
86  *     - ctrl-c   : copy
87  *     - ctrl-v   : paste
88  */
89 typedef struct {
90 	displaymethod * d;      /**< Display method. */
91 	ZZTOOPdrawer drawer;    /**< Object code drawer. */
92 	char * title;           /**< Dialog title. */
93 
94 	/** The text to edit or view. */
95 	stringvector * text;
96 	stringnode * curline;   /**< Current line. */
97 	int pos;                /**< Cursor position on line. */
98 
99 	/* Configuration flags. */
100 	int editflag;       /**< True when text is editable. */
101 	int highlightflag;  /**< True when syntax highlighting should be used. */
102 	int insertflag;     /**< True when insert mode is on. */
103 
104 	/** Maximum line length. All strings in text are assumed to be
105 	 * able to hold this many characters. */
106 	int linewidth;
107 	/** Width at which a line should be wrapped if possible. */
108 	int wrapwidth;
109 
110 	/* Control flags */
111 	int updateflags;    /**< Show what parts of the display need to be updated. */
112 	int exitflag;       /**< True when editing/viewing should end. */
113 
114 	/** The current keypress */
115 	int key;
116 
117 	/* Text selection information */
118 	int selectflag;        /**< True when an area is being selected. */
119 	int selectpos;         /**< Cursor position of selection start. */
120 	int selectlineoffset;  /**< Offset of selection start from current line. */
121 
122 	/** @TODO: Include references to help system, registers, and themes. */
123 
124 } texteditor;
125 
126 texteditor * createtexteditor(char * title, stringvector * text, displaymethod * d);
127 
128 void deletetexteditor(texteditor * editor);
129 void deletetexteditortext(texteditor * editor);
130 
131 void textedit(texteditor * editor);
132 
133 /* For now, just use the real EDITBOX */
134 #include "editbox.h"
135 #if 0
136 /* Return codes */
137 #define EDITBOX_OK       1     /* ENTER, ESC when editbox > EDITBOX_NOEDIT */
138 #define EDITBOX_CANCEL   2     /* ESC */
139 #define EDITBOX_FORWARD  3     /* RIGHT-ARROW */
140 #define EDITBOX_BACK     4     /* BACKSPACE */
141 #define EDITBOX_BACKWARD 5     /* LEFT-ARROW */
142 #define EDITBOX_HELP     6     /* F1 */
143 
144 /* Flags */
145 #define EDITBOX_ZOCMODE  1     /* Use ZZT markup / syntax highlighting */
146 #define EDITBOX_MOVEMENT 2     /* Forward and backward exit dialog (only
147 																	effective with editwidth = EDITBOX_NOEDIT) */
148 
149 /* Editwidth */
150 #define EDITBOX_ZZTWIDTH 42    /* ZZT's maximum text width */
151 #define EDITBOX_NOEDIT   0     /* Width used to specify browse/scroll dialog */
152 
153 /* editbox() - edit/browse a string vector in a scroll box.
154  *   Browsing starts at sv->cur.
155  *   Editwidth determines maximum line width, zero for browse only.
156  *   Flags and return codes are listed above. */
157 int editbox(char* title, stringvector * sv, int editwidth, int flags, displaymethod * d);
158 
159 /* Special instances of editbox() */
160 #define scrolldialog(title, sv, d) editbox((title), (sv), EDITBOX_NOEDIT, EDITBOX_ZOCMODE, (d))
161 #define browsedialog(title, sv, d) editbox((title), (sv), EDITBOX_NOEDIT, EDITBOX_ZOCMODE | EDITBOX_MOVEMENT, (d))
162 #endif
163 
164 
165 
166 #endif
167