[773] | 1 | // |
---|
| 2 | // "$Id: TextEditor.h 4467 2005-08-05 19:17:34Z dejan $" |
---|
| 3 | // |
---|
| 4 | // Header file for TextEditor class. |
---|
| 5 | // |
---|
| 6 | // Copyright 2001-2005 by Bill Spitzak and others. |
---|
| 7 | // Original code Copyright Mark Edel. Permission to distribute under |
---|
| 8 | // the LGPL for the FLTK library granted by Mark Edel. |
---|
| 9 | // |
---|
| 10 | // This library is free software; you can redistribute it and/or |
---|
| 11 | // modify it under the terms of the GNU Library General Public |
---|
| 12 | // License as published by the Free Software Foundation; either |
---|
| 13 | // version 2 of the License, or (at your option) any later version. |
---|
| 14 | // |
---|
| 15 | // This library is distributed in the hope that it will be useful, |
---|
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | // Library General Public License for more details. |
---|
| 19 | // |
---|
| 20 | // You should have received a copy of the GNU Library General Public |
---|
| 21 | // License along with this library; if not, write to the Free Software |
---|
| 22 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
| 23 | // USA. |
---|
| 24 | // |
---|
| 25 | // Please report all bugs and problems on the following page: |
---|
| 26 | // |
---|
| 27 | // http://www.fltk.org/str.php |
---|
| 28 | // |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | #ifndef TEXT_EDITOR_H |
---|
| 32 | #define TEXT_EDITOR_H |
---|
| 33 | |
---|
| 34 | #include "TextDisplay.h" |
---|
| 35 | |
---|
| 36 | namespace fltk { |
---|
| 37 | |
---|
| 38 | // key will match in any state |
---|
| 39 | #define TEXT_EDITOR_ANY_STATE (-1L) |
---|
| 40 | |
---|
| 41 | class FL_API TextEditor : public TextDisplay { |
---|
| 42 | public: |
---|
| 43 | typedef int (*Key_Func)(int key, TextEditor* editor); |
---|
| 44 | |
---|
| 45 | struct Key_Binding { |
---|
| 46 | int key; |
---|
| 47 | int state; |
---|
| 48 | Key_Func function; |
---|
| 49 | Key_Binding* next; |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | TextEditor(int X, int Y, int W, int H, const char* l = 0); |
---|
| 53 | ~TextEditor() { remove_all_key_bindings(); } |
---|
| 54 | static NamedStyle* default_style; |
---|
| 55 | virtual int handle(int e); |
---|
| 56 | void insert_mode(int b) { insert_mode_ = b; } |
---|
| 57 | int insert_mode() { return insert_mode_; } |
---|
| 58 | |
---|
| 59 | void add_key_binding(int key, int state, Key_Func f, Key_Binding** list); |
---|
| 60 | void add_key_binding(int key, int state, Key_Func f) |
---|
| 61 | { add_key_binding(key, state, f, &key_bindings); } |
---|
| 62 | void remove_key_binding(int key, int state, Key_Binding** list); |
---|
| 63 | void remove_key_binding(int key, int state) |
---|
| 64 | { remove_key_binding(key, state, &key_bindings); } |
---|
| 65 | void remove_all_key_bindings(Key_Binding** list); |
---|
| 66 | void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); } |
---|
| 67 | void add_default_key_bindings(Key_Binding** list); |
---|
| 68 | Key_Func bound_key_function(int key, int state, Key_Binding* list); |
---|
| 69 | Key_Func bound_key_function(int key, int state) |
---|
| 70 | { return bound_key_function(key, state, key_bindings); } |
---|
| 71 | void default_key_function(Key_Func f) { default_key_function_ = f; } |
---|
| 72 | |
---|
| 73 | // functions for the built in default bindings |
---|
| 74 | static int kf_default(int c, TextEditor* e); |
---|
| 75 | static int kf_ignore(int c, TextEditor* e); |
---|
| 76 | static int kf_backspace(int c, TextEditor* e); |
---|
| 77 | static int kf_enter(int c, TextEditor* e); |
---|
| 78 | static int kf_move(int c, TextEditor* e); |
---|
| 79 | static int kf_shift_move(int c, TextEditor* e); |
---|
| 80 | static int kf_ctrl_move(int c, TextEditor* e); |
---|
| 81 | static int kf_c_s_move(int c, TextEditor* e); |
---|
| 82 | static int kf_home(int, TextEditor* e); |
---|
| 83 | static int kf_end(int c, TextEditor* e); |
---|
| 84 | static int kf_left(int c, TextEditor* e); |
---|
| 85 | static int kf_up(int c, TextEditor* e); |
---|
| 86 | static int kf_right(int c, TextEditor* e); |
---|
| 87 | static int kf_down(int c, TextEditor* e); |
---|
| 88 | static int kf_page_up(int c, TextEditor* e); |
---|
| 89 | static int kf_page_down(int c, TextEditor* e); |
---|
| 90 | static int kf_insert(int c, TextEditor* e); |
---|
| 91 | static int kf_delete(int c, TextEditor* e); |
---|
| 92 | static int kf_copy(int c, TextEditor* e); |
---|
| 93 | static int kf_cut(int c, TextEditor* e); |
---|
| 94 | static int kf_paste(int c, TextEditor* e); |
---|
| 95 | static int kf_select_all(int c, TextEditor* e); |
---|
| 96 | static int kf_undo(int c, TextEditor* e); |
---|
| 97 | |
---|
| 98 | protected: |
---|
| 99 | int handle_key(); |
---|
| 100 | void maybe_do_callback(); |
---|
| 101 | |
---|
| 102 | int insert_mode_; |
---|
| 103 | Key_Binding* key_bindings; |
---|
| 104 | static Key_Binding* global_key_bindings; |
---|
| 105 | Key_Func default_key_function_; |
---|
| 106 | }; |
---|
| 107 | |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | #endif |
---|
| 111 | |
---|
| 112 | // |
---|
| 113 | // End of "$Id: TextEditor.h 4467 2005-08-05 19:17:34Z dejan $". |
---|
| 114 | // |
---|
| 115 | |
---|
| 116 | |
---|