1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
/*
* HT Editor
* textedit.h
*
* Copyright (C) 1999, 2000, 2001 Stefan Weyergraf (stefan@weyergraf.de)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __TEXTEDIT_H__
#define __TEXTEDIT_H__
#include "htobj.h"
#include "textfile.h"
#define TEXTEDITOPT_NULL 0
#define TEXTEDITOPT_INPUTTABS 1
#define TEXTEDITOPT_UNDO 2
struct text_viewer_pos {
UINT line;
UINT pofs;
};
class ht_text_editor;
#define ATOM_HT_UNDO_DATA_CURSOR MAGICD("UND\x01")
#define ATOM_HT_UNDO_DATA_INSERT MAGICD("UND\x02")
#define ATOM_HT_UNDO_DATA_DELETE MAGICD("UND\x03")
#define ATOM_HT_UNDO_DATA_DELETE2 MAGICD("UND\x04")
#define ATOM_HT_UNDO_DATA_SPLIT_LINE MAGICD("UND\x05")
#define ATOM_HT_UNDO_DATA_JOIN_LINE MAGICD("UND\x06")
/*
* CLASS ht_undo_data
*/
class ht_undo_data: public ht_data {
public:
ht_undo_data();
virtual bool combine(ht_undo_data *ud)=0;
virtual UINT getsize()=0;
virtual void gettext(char *text, UINT maxlen)=0;
virtual void apply(ht_text_editor *te)=0;
virtual void unapply(ht_text_editor *te, bool *goto_only)=0;
};
/*
* CLASS ht_undo_data_delete_string
*/
class ht_undo_data_delete_string: public ht_undo_data {
text_viewer_pos apos;
text_viewer_pos bpos;
void *string;
UINT len;
public:
ht_undo_data_delete_string(text_viewer_pos *apos, text_viewer_pos *bpos, void *string, UINT len);
~ht_undo_data_delete_string();
virtual bool combine(ht_undo_data *ud);
virtual UINT getsize();
virtual void gettext(char *text, UINT maxlen);
virtual OBJECT_ID object_id();
virtual void apply(ht_text_editor *te);
virtual void unapply(ht_text_editor *te, bool *goto_only);
};
/*
* CLASS ht_undo_data_delete_string2
*/
class ht_undo_data_delete_string2: public ht_undo_data {
text_viewer_pos apos;
text_viewer_pos bpos;
void *string;
UINT len;
public:
ht_undo_data_delete_string2(text_viewer_pos *apos, text_viewer_pos *bpos, void *string, UINT len);
~ht_undo_data_delete_string2();
virtual bool combine(ht_undo_data *ud);
virtual UINT getsize();
virtual void gettext(char *text, UINT maxlen);
virtual OBJECT_ID object_id();
virtual void apply(ht_text_editor *te);
virtual void unapply(ht_text_editor *te, bool *goto_only);
};
/*
* CLASS ht_undo_data_insert_string
*/
class ht_undo_data_insert_string: public ht_undo_data {
text_viewer_pos apos;
text_viewer_pos bpos;
text_viewer_pos cpos;
void *string;
UINT len;
public:
ht_undo_data_insert_string(text_viewer_pos *apos, text_viewer_pos *bpos, void *string, UINT len);
~ht_undo_data_insert_string();
virtual bool combine(ht_undo_data *ud);
virtual UINT getsize();
virtual void gettext(char *text, UINT maxlen);
virtual OBJECT_ID object_id();
virtual void apply(ht_text_editor *te);
virtual void unapply(ht_text_editor *te, bool *goto_only);
};
/*
* CLASS ht_undo_data_split_line
*/
class ht_undo_data_split_line: public ht_undo_data {
text_viewer_pos apos;
text_viewer_pos bpos;
public:
ht_undo_data_split_line(text_viewer_pos *apos, text_viewer_pos *bpos);
~ht_undo_data_split_line();
virtual bool combine(ht_undo_data *ud);
virtual UINT getsize();
virtual void gettext(char *text, UINT maxlen);
virtual OBJECT_ID object_id();
virtual void apply(ht_text_editor *te);
virtual void unapply(ht_text_editor *te, bool *goto_only);
};
/*
* CLASS ht_undo_data_join_line
*/
class ht_undo_data_join_line: public ht_undo_data {
text_viewer_pos apos;
text_viewer_pos bpos;
public:
ht_undo_data_join_line(text_viewer_pos *apos, text_viewer_pos *bpos);
~ht_undo_data_join_line();
virtual bool combine(ht_undo_data *ud);
virtual UINT getsize();
virtual void gettext(char *text, UINT maxlen);
virtual OBJECT_ID object_id();
virtual void apply(ht_text_editor *te);
virtual void unapply(ht_text_editor *te, bool *goto_only);
};
/*
* CLASS ht_text_editor_undo
*/
class ht_text_editor_undo: public ht_clist {
UINT size, max_size;
UINT clean_state;
UINT current_position;
bool goto_state;
public:
void init(UINT max_undo_size);
void insert_undo(ht_text_editor *te, ht_undo_data *undo);
bool is_clean();
UINT get_current_position();
void mark_clean();
void undo(ht_text_editor *te);
void redo(ht_text_editor *te);
};
/*
* CLASS ht_text_viewer
*/
#define cmd_text_viewer_goto HT_COMMAND(601)
#define cmd_text_editor_undo HT_COMMAND(610)
#define cmd_text_editor_redo HT_COMMAND(611)
#define cmd_text_editor_protocol HT_COMMAND(612)
class ht_text_viewer: public ht_view {
protected:
ht_textfile *textfile;
bool own_textfile;
ht_syntax_lexer *lexer;
bool own_lexer;
UINT cursorx, cursory;
text_viewer_pos sel_start, sel_end;
UINT top_line;
UINT xofs;
bool selectcursor;
bool selectmode;
text_viewer_pos selectstart;
/* new */
UINT char_vsize(char c, UINT x);
void clipboard_copy_cmd();
UINT cursor_up(UINT n);
UINT cursor_down(UINT n);
UINT cursor_left(UINT n);
UINT cursor_right(UINT n);
void cursor_home();
void cursor_end();
void cursor_vput(UINT vx);
void cursor_pput(UINT px);
virtual vcp get_bgcolor();
void make_pos_physical(text_viewer_pos *p);
void normalize_selection();
UINT physical_cursorx();
void render_str(int x, int y, vcp color, text_viewer_pos *pos, UINT len, char *str, bool multi);
void render_str_color(vcp *color, text_viewer_pos *pos);
UINT scroll_up(UINT n);
UINT scroll_down(UINT n);
UINT scroll_left(UINT n);
UINT scroll_right(UINT n);
void select_add(text_viewer_pos *from, text_viewer_pos *to);
void select_clear();
void select_end();
void select_set(text_viewer_pos *from, text_viewer_pos *to);
void select_start();
public:
void init(bounds *b, bool own_textfile, ht_textfile *textfile, bool own_lexer, ht_syntax_lexer *lexer);
virtual void done();
/* overwritten */
virtual void draw();
virtual void handlemsg(htmsg *msg);
virtual void resize(int rw, int rh);
/* new */
virtual char *func(UINT i, bool execute);
UINT get_line_length(UINT line);
UINT get_line_vlength(UINT line);
bool goto_line(UINT line);
/* position indicator string */
virtual void get_pindicator_str(char *buf);
/* scrollbar pos */
virtual bool get_hscrollbar_pos(int *pstart, int *psize);
virtual bool get_vscrollbar_pos(int *pstart, int *psize);
/**/
virtual bool modified();
void set_lexer(ht_syntax_lexer *l, bool own_l);
void set_textfile(ht_textfile *t, bool own_t);
};
/*
* CLASS ht_text_editor
*/
class ht_text_editor: public ht_text_viewer {
friend class ht_undo_data;
friend class ht_undo_data_delete_string;
friend class ht_undo_data_delete_string2;
friend class ht_undo_data_insert_string;
friend class ht_undo_data_split_line;
friend class ht_undo_data_join_line;
protected:
UINT edit_options;
ht_text_editor_undo *undo_list;
/* new */
void clipboard_cut_cmd();
void clipboard_delete_cmd();
void clipboard_paste_cmd();
void concat_lines(UINT a);
void delete_chars(UINT line, UINT ofs, UINT count);
void delete_lines(UINT line, UINT count);
virtual vcp get_bgcolor();
void insert_chars(UINT line, UINT ofs, void *chars, UINT len);
void insert_lines(UINT line, UINT count);
void save();
void split_line(UINT a, UINT pos);
public:
void init(bounds *b, bool own_textfile, ht_textfile *textfile, bool own_lexer, ht_syntax_lexer *lexer, UINT edit_options);
virtual void done();
/* overwritten */
virtual char *func(UINT i, bool execute);
virtual void handlemsg(htmsg *msg);
void textoperation_apply(ht_undo_data *ud);
void redo();
void show_protocol();
void undo();
};
extern int text_viewer_pos_compare(text_viewer_pos *a, text_viewer_pos *b);
#endif /* __TEXTEDIT_H__ */
|