00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef FL_TEXT_EDITOR_H
00026 #define FL_TEXT_EDITOR_H
00027
00028 #include "Fl_Text_Display.H"
00029
00030
00031 #define FL_TEXT_EDITOR_ANY_STATE (-1L)
00032
00040 class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
00041 public:
00043 typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
00044
00046 struct Key_Binding {
00047 int key;
00048 int state;
00049 Key_Func function;
00050 Key_Binding* next;
00051 };
00052
00053 Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
00054 ~Fl_Text_Editor() { remove_all_key_bindings(); }
00055 virtual int handle(int e);
00061 void insert_mode(int b) { insert_mode_ = b; }
00067 int insert_mode() { return insert_mode_; }
00068
00069 #if FLTK_ABI_VERSION >= 10304
00070 void tab_nav(int val);
00071 int tab_nav() const;
00072 #endif
00073
00074 void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
00076 void add_key_binding(int key, int state, Key_Func f)
00077 { add_key_binding(key, state, f, &key_bindings); }
00078 void remove_key_binding(int key, int state, Key_Binding** list);
00080 void remove_key_binding(int key, int state)
00081 { remove_key_binding(key, state, &key_bindings); }
00082 void remove_all_key_bindings(Key_Binding** list);
00084 void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
00085 void add_default_key_bindings(Key_Binding** list);
00086 #if FLTK_ABI_VERSION < 10304
00087
00088 Key_Func bound_key_function(int key, int state, Key_Binding* list);
00090 Key_Func bound_key_function(int key, int state)
00091 { return bound_key_function(key, state, key_bindings); }
00092 #else
00093
00094 Key_Func bound_key_function(int key, int state, Key_Binding* list) const;
00096 Key_Func bound_key_function(int key, int state) const
00097 { return bound_key_function(key, state, key_bindings); }
00098 #endif
00099
00100 void default_key_function(Key_Func f) { default_key_function_ = f; }
00101
00102
00103 static int kf_default(int c, Fl_Text_Editor* e);
00104 static int kf_ignore(int c, Fl_Text_Editor* e);
00105 static int kf_backspace(int c, Fl_Text_Editor* e);
00106 static int kf_enter(int c, Fl_Text_Editor* e);
00107 static int kf_move(int c, Fl_Text_Editor* e);
00108 static int kf_shift_move(int c, Fl_Text_Editor* e);
00109 static int kf_ctrl_move(int c, Fl_Text_Editor* e);
00110 static int kf_c_s_move(int c, Fl_Text_Editor* e);
00111 static int kf_meta_move(int c, Fl_Text_Editor* e);
00112 static int kf_m_s_move(int c, Fl_Text_Editor* e);
00113 static int kf_home(int, Fl_Text_Editor* e);
00114 static int kf_end(int c, Fl_Text_Editor* e);
00115 static int kf_left(int c, Fl_Text_Editor* e);
00116 static int kf_up(int c, Fl_Text_Editor* e);
00117 static int kf_right(int c, Fl_Text_Editor* e);
00118 static int kf_down(int c, Fl_Text_Editor* e);
00119 static int kf_page_up(int c, Fl_Text_Editor* e);
00120 static int kf_page_down(int c, Fl_Text_Editor* e);
00121 static int kf_insert(int c, Fl_Text_Editor* e);
00122 static int kf_delete(int c, Fl_Text_Editor* e);
00123 static int kf_copy(int c, Fl_Text_Editor* e);
00124 static int kf_cut(int c, Fl_Text_Editor* e);
00125 static int kf_paste(int c, Fl_Text_Editor* e);
00126 static int kf_select_all(int c, Fl_Text_Editor* e);
00127 static int kf_undo(int c, Fl_Text_Editor* e);
00128
00129 protected:
00130 int handle_key();
00131 void maybe_do_callback();
00132
00133 #ifndef FL_DOXYGEN
00134 int insert_mode_;
00135 Key_Binding* key_bindings;
00136 #endif
00137
00145 static Key_Binding* global_key_bindings;
00146
00147 #ifndef FL_DOXYGEN
00148 Key_Func default_key_function_;
00149 #endif
00150 };
00151
00152 #endif
00153
00154
00155
00156
00157