00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __TEXTEDIT_H__
00023 #define __TEXTEDIT_H__
00024
00025 #include "htobj.h"
00026 #include "textfile.h"
00027
00028 #include "htformat.h"
00029
00030 #define TEXTEDITOPT_NULL 0
00031 #define TEXTEDITOPT_INPUTTABS 1
00032 #define TEXTEDITOPT_UNDO 2
00033
00034 struct text_viewer_pos {
00035 UINT line;
00036 UINT pofs;
00037 };
00038
00039 union text_search_pos {
00040 FILEOFS offset;
00041 };
00042
00043 class ht_text_editor;
00044
00045 #define ATOM_HT_UNDO_DATA_INSERT MAGICD("UND\x01")
00046 #define ATOM_HT_UNDO_DATA_OVERWRITE MAGICD("UND\x02")
00047 #define ATOM_HT_UNDO_DATA_DELETE MAGICD("UND\x03")
00048 #define ATOM_HT_UNDO_DATA_DELETE2 MAGICD("UND\x04")
00049 #define ATOM_HT_UNDO_DATA_SPLIT_LINE MAGICD("UND\x05")
00050 #define ATOM_HT_UNDO_DATA_JOIN_LINE MAGICD("UND\x06")
00051 #define ATOM_HT_UNDO_DATA_INSERT_BLOCK MAGICD("UND\x07")
00052 #define ATOM_HT_UNDO_DATA_DELETE_BLOCK MAGICD("UND\x08")
00053
00054
00055
00056
00057 class ht_undo_data: public Object {
00058 public:
00059 ht_undo_data();
00060 virtual bool combine(ht_undo_data *ud);
00061 virtual UINT getsize()=0;
00062 virtual void gettext(char *text, UINT maxlen)=0;
00063 virtual void apply(ht_text_editor *te)=0;
00064 virtual void unapply(ht_text_editor *te, bool *goto_only)=0;
00065 };
00066
00067
00068
00069
00070 class ht_undo_data_delete_string: public ht_undo_data {
00071 text_viewer_pos apos;
00072 text_viewer_pos bpos;
00073 void *string;
00074 UINT len;
00075 public:
00076 ht_undo_data_delete_string(text_viewer_pos *apos, text_viewer_pos *bpos, void *string, UINT len);
00077 ~ht_undo_data_delete_string();
00078 virtual bool combine(ht_undo_data *ud);
00079 virtual UINT getsize();
00080 virtual void gettext(char *text, UINT maxlen);
00081 virtual OBJECT_ID object_id() const;
00082 virtual void apply(ht_text_editor *te);
00083 virtual void unapply(ht_text_editor *te, bool *goto_only);
00084 };
00085
00086
00087
00088
00089 class ht_undo_data_delete_string2: public ht_undo_data {
00090 text_viewer_pos apos;
00091 text_viewer_pos bpos;
00092 void *string;
00093 UINT len;
00094 public:
00095 ht_undo_data_delete_string2(text_viewer_pos *apos, text_viewer_pos *bpos, void *string, UINT len);
00096 ~ht_undo_data_delete_string2();
00097 virtual bool combine(ht_undo_data *ud);
00098 virtual UINT getsize();
00099 virtual void gettext(char *text, UINT maxlen);
00100 virtual OBJECT_ID object_id() const;
00101 virtual void apply(ht_text_editor *te);
00102 virtual void unapply(ht_text_editor *te, bool *goto_only);
00103 };
00104
00105
00106
00107
00108 class ht_undo_data_insert_string: public ht_undo_data {
00109 text_viewer_pos apos;
00110 text_viewer_pos bpos;
00111 text_viewer_pos cpos;
00112 void *string;
00113 UINT len;
00114 public:
00115 ht_undo_data_insert_string(text_viewer_pos *apos, text_viewer_pos *bpos, void *string, UINT len);
00116 ~ht_undo_data_insert_string();
00117 virtual bool combine(ht_undo_data *ud);
00118 virtual UINT getsize();
00119 virtual void gettext(char *text, UINT maxlen);
00120 virtual OBJECT_ID object_id() const;
00121 virtual void apply(ht_text_editor *te);
00122 virtual void unapply(ht_text_editor *te, bool *goto_only);
00123 };
00124
00125
00126
00127
00128 class ht_undo_data_overwrite_string: public ht_undo_data {
00129 text_viewer_pos apos;
00130 text_viewer_pos bpos;
00131 text_viewer_pos cpos;
00132 void *string;
00133 UINT len;
00134 void *string2;
00135 UINT len2;
00136 public:
00137 ht_undo_data_overwrite_string(text_viewer_pos *apos, text_viewer_pos *bpos, void *string, UINT len, void *string2, UINT len2);
00138 ~ht_undo_data_overwrite_string();
00139 virtual bool combine(ht_undo_data *ud);
00140 virtual UINT getsize();
00141 virtual void gettext(char *text, UINT maxlen);
00142 virtual OBJECT_ID object_id() const;
00143 virtual void apply(ht_text_editor *te);
00144 virtual void unapply(ht_text_editor *te, bool *goto_only);
00145 };
00146
00147
00148
00149
00150
00151 class ht_undo_data_split_line: public ht_undo_data {
00152 text_viewer_pos apos;
00153 text_viewer_pos bpos;
00154 UINT indent;
00155 public:
00156 ht_undo_data_split_line(text_viewer_pos *apos, text_viewer_pos *bpos, UINT Indent);
00157 ~ht_undo_data_split_line();
00158 virtual UINT getsize();
00159 virtual void gettext(char *text, UINT maxlen);
00160 virtual OBJECT_ID object_id() const;
00161 virtual void apply(ht_text_editor *te);
00162 virtual void unapply(ht_text_editor *te, bool *goto_only);
00163 };
00164
00165
00166
00167
00168 class ht_undo_data_join_line: public ht_undo_data {
00169 text_viewer_pos apos;
00170 text_viewer_pos bpos;
00171 text_viewer_pos cpos;
00172 public:
00173 ht_undo_data_join_line(text_viewer_pos *apos, text_viewer_pos *bpos);
00174 ~ht_undo_data_join_line();
00175 virtual UINT getsize();
00176 virtual void gettext(char *text, UINT maxlen);
00177 virtual OBJECT_ID object_id() const;
00178 virtual void apply(ht_text_editor *te);
00179 virtual void unapply(ht_text_editor *te, bool *goto_only);
00180 };
00181
00182
00183
00184
00185
00186 class ht_undo_data_insert_block: public ht_undo_data {
00187 text_viewer_pos apos;
00188 text_viewer_pos bpos;
00189 text_viewer_pos cpos;
00190 text_viewer_pos sel_start;
00191 text_viewer_pos sel_end;
00192 void *block;
00193 UINT size;
00194 public:
00195 ht_undo_data_insert_block(text_viewer_pos *apos, text_viewer_pos *bpos, void *block, UINT size);
00196 ~ht_undo_data_insert_block();
00197 virtual UINT getsize();
00198 virtual void gettext(char *text, UINT maxlen);
00199 virtual OBJECT_ID object_id() const;
00200 virtual void apply(ht_text_editor *te);
00201 virtual void unapply(ht_text_editor *te, bool *goto_only);
00202 };
00203
00204
00205
00206
00207
00208 class ht_undo_data_delete_block: public ht_undo_data {
00209 text_viewer_pos apos;
00210 text_viewer_pos bpos;
00211 text_viewer_pos cpos;
00212 text_viewer_pos sel_start;
00213 text_viewer_pos sel_end;
00214 void *block;
00215 UINT size;
00216 public:
00217 ht_undo_data_delete_block(text_viewer_pos *apos, text_viewer_pos *bpos, text_viewer_pos *Sel_start, text_viewer_pos *Sel_end);
00218 ~ht_undo_data_delete_block();
00219 virtual UINT getsize();
00220 virtual void gettext(char *text, UINT maxlen);
00221 virtual OBJECT_ID object_id() const;
00222 virtual void apply(ht_text_editor *te);
00223 virtual void unapply(ht_text_editor *te, bool *goto_only);
00224 };
00225
00226
00227
00228
00229
00230 class ht_text_editor_undo: public ht_clist {
00231 public:
00232 UINT size, max_size;
00233 int clean_state;
00234 int current_position;
00235 bool goto_state;
00236 public:
00237 void init(UINT max_undo_size);
00238 void insert_undo(ht_text_editor *te, ht_undo_data *undo);
00239 bool is_clean();
00240 bool is_clean(int i);
00241 int get_current_position();
00242 void mark_clean();
00243 void undo(ht_text_editor *te, bool place_cursor_first);
00244 void redo(ht_text_editor *te);
00245 };
00246
00247
00248
00249
00250
00251 #define cmd_text_viewer_goto HT_COMMAND(601)
00252 #define cmd_text_viewer_change_highlight HT_COMMAND(602)
00253
00254 #define cmd_text_editor_undo HT_COMMAND(620)
00255 #define cmd_text_editor_redo HT_COMMAND(621)
00256 #define cmd_text_editor_protocol HT_COMMAND(622)
00257 #define cmd_text_editor_delete_line HT_COMMAND(623)
00258
00259 class ht_text_viewer: public ht_view {
00260 friend class ht_undo_data;
00261 friend class ht_undo_data_delete_string;
00262 friend class ht_undo_data_delete_string2;
00263 friend class ht_undo_data_insert_string;
00264 friend class ht_undo_data_overwrite_string;
00265 friend class ht_undo_data_split_line;
00266 friend class ht_undo_data_join_line;
00267 friend class ht_undo_data_insert_block;
00268 friend class ht_undo_data_delete_block;
00269 protected:
00270 ht_textfile *textfile;
00271 bool own_textfile;
00272
00273 ht_list *lexers;
00274
00275 ht_syntax_lexer *lexer;
00276 bool own_lexer;
00277
00278 UINT cursorx, cursory;
00279 text_viewer_pos sel_start, sel_end;
00280
00281 UINT top_line;
00282 UINT xofs;
00283
00284 bool selectcursor;
00285 bool selectmode;
00286 text_viewer_pos selectstart;
00287
00288 char *EOL_string;
00289 char *EOF_string;
00290 bool show_EOL;
00291 bool show_EOF;
00292 bool highlight_wrap;
00293 UINT tab_size;
00294
00295 ht_search_request *last_search_request;
00296 FILEOFS last_search_end_ofs;
00297
00298
00299 int buf_lprint0(int x, int y, int c, int l, char *text);
00300 UINT char_vsize(char c, UINT x);
00301 void clipboard_copy_cmd();
00302 bool continue_search();
00303 virtual vcp get_bgcolor();
00304 void make_pos_physical(text_viewer_pos *p);
00305 void normalize_selection();
00306 UINT physical_cursorx();
00307 void popup_change_highlight();
00308 void render_meta(UINT x, UINT y, text_viewer_pos *pos, vcp color);
00309 void render_str(int x, int y, vcp color, text_viewer_pos *pos, UINT len, char *str, bool multi);
00310 void render_str_color(vcp *color, text_viewer_pos *pos);
00311 ht_search_result *search(ht_search_request *request, text_search_pos *start, text_search_pos *end);
00312 bool show_search_result(ht_search_result *result);
00313 public:
00314 void init(bounds *b, bool own_textfile, ht_textfile *textfile, ht_list *lexers);
00315 virtual void done();
00316
00317 virtual void config_changed();
00318 virtual void draw();
00319 virtual void handlemsg(htmsg *msg);
00320 virtual void resize(int rw, int rh);
00321
00322 virtual char *func(UINT i, bool execute);
00323 UINT get_line_length(UINT line);
00324 UINT get_line_vlength(UINT line);
00325 UINT get_line_indent(UINT line);
00326 void get_selection(text_viewer_pos *start, text_viewer_pos *end);
00327 bool goto_line(UINT line);
00328
00329 virtual void get_pindicator_str(char *buf);
00330
00331 virtual bool get_hscrollbar_pos(int *pstart, int *psize);
00332 virtual bool get_vscrollbar_pos(int *pstart, int *psize);
00333
00334 virtual cursor_mode get_cursor_mode();
00335 virtual void get_cursor_pos(text_viewer_pos *cursor);
00336
00337 virtual bool pos_to_offset(text_viewer_pos *pos, FILEOFS *ofs);
00338
00339 ht_syntax_lexer *get_lexer();
00340 int ppos_str(char *buf, UINT bufsize, text_viewer_pos *ppos);
00341 void set_lexer(ht_syntax_lexer *l, bool own_l);
00342 void set_textfile(ht_textfile *t, bool own_t);
00343 ht_textfile *get_textfile();
00344
00345 UINT cursor_up(UINT n);
00346 UINT cursor_down(UINT n);
00347 UINT cursor_left(UINT n);
00348 UINT cursor_right(UINT n);
00349 void cursor_home();
00350 void cursor_end();
00351 void cursor_vput(UINT vx);
00352 void cursor_pput(UINT px);
00353 void cursor_set(text_viewer_pos *pos);
00354 UINT scroll_up(UINT n);
00355 UINT scroll_down(UINT n);
00356 UINT scroll_left(UINT n);
00357 UINT scroll_right(UINT n);
00358 void select_add(text_viewer_pos *from, text_viewer_pos *to);
00359 void select_clear();
00360 void select_end();
00361 void select_set(text_viewer_pos *from, text_viewer_pos *to);
00362 void select_start();
00363 };
00364
00365
00366
00367
00368
00369 class ht_text_editor: public ht_text_viewer {
00370 protected:
00371 UINT edit_options;
00372 ht_text_editor_undo *undo_list;
00373 bool auto_indent;
00374 bool overwrite_mode;
00375
00376
00377 void clipboard_cut_cmd();
00378 void clipboard_delete_cmd();
00379 void clipboard_paste_cmd();
00380 virtual vcp get_bgcolor();
00381 bool save();
00382 public:
00383 void init(bounds *b, bool own_textfile, ht_textfile *textfile, ht_list *lexers, UINT edit_options);
00384 virtual void done();
00385
00386 virtual void config_changed();
00387 virtual char *func(UINT i, bool execute);
00388 virtual void handlemsg(htmsg *msg);
00389
00390 virtual void get_pindicator_str(char *buf);
00391
00392 virtual cursor_mode get_cursor_mode();
00393
00394 bool concat_lines(UINT a);
00395 void delete_chars(UINT line, UINT ofs, UINT count);
00396 void delete_lines(UINT line, UINT count);
00397 void indent(UINT line, UINT start, UINT size);
00398 void insert_chars(UINT line, UINT ofs, void *chars, UINT len);
00399 void insert_lines(UINT line, UINT count);
00400 void split_line(UINT a, UINT pos);
00401 void unindent(UINT line, UINT start, UINT size);
00402
00403 void textoperation_apply(ht_undo_data *ud);
00404 void redo();
00405 void show_protocol();
00406 void undo(bool place_cursor_first);
00407 };
00408
00409 extern int text_viewer_pos_compare(text_viewer_pos *a, text_viewer_pos *b);
00410
00411 #endif
00412