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
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef FL_TEXT_EDITOR_H
00035 #define FL_TEXT_EDITOR_H
00036
00037 #include "Fl_Text_Display.H"
00038
00039
00040 #define FL_TEXT_EDITOR_ANY_STATE (-1L)
00041
00049 class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
00050 public:
00052 typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
00053
00055 struct Key_Binding {
00056 int key;
00057 int state;
00058 Key_Func function;
00059 Key_Binding* next;
00060 };
00061
00062 Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
00063 ~Fl_Text_Editor() { remove_all_key_bindings(); }
00064 virtual int handle(int e);
00070 void insert_mode(int b) { insert_mode_ = b; }
00076 int insert_mode() { return insert_mode_; }
00077
00078 void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
00080 void add_key_binding(int key, int state, Key_Func f)
00081 { add_key_binding(key, state, f, &key_bindings); }
00082 void remove_key_binding(int key, int state, Key_Binding** list);
00084 void remove_key_binding(int key, int state)
00085 { remove_key_binding(key, state, &key_bindings); }
00086 void remove_all_key_bindings(Key_Binding** list);
00088 void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
00089 void add_default_key_bindings(Key_Binding** list);
00090 Key_Func bound_key_function(int key, int state, Key_Binding* list);
00092 Key_Func bound_key_function(int key, int state)
00093 { return bound_key_function(key, state, key_bindings); }
00095 void default_key_function(Key_Func f) { default_key_function_ = f; }
00096
00097
00098 static int kf_default(int c, Fl_Text_Editor* e);
00099 static int kf_ignore(int c, Fl_Text_Editor* e);
00100 static int kf_backspace(int c, Fl_Text_Editor* e);
00101 static int kf_enter(int c, Fl_Text_Editor* e);
00102 static int kf_move(int c, Fl_Text_Editor* e);
00103 static int kf_shift_move(int c, Fl_Text_Editor* e);
00104 static int kf_ctrl_move(int c, Fl_Text_Editor* e);
00105 static int kf_c_s_move(int c, Fl_Text_Editor* e);
00106 static int kf_meta_move(int c, Fl_Text_Editor* e);
00107 static int kf_m_s_move(int c, Fl_Text_Editor* e);
00108 static int kf_home(int, Fl_Text_Editor* e);
00109 static int kf_end(int c, Fl_Text_Editor* e);
00110 static int kf_left(int c, Fl_Text_Editor* e);
00111 static int kf_up(int c, Fl_Text_Editor* e);
00112 static int kf_right(int c, Fl_Text_Editor* e);
00113 static int kf_down(int c, Fl_Text_Editor* e);
00114 static int kf_page_up(int c, Fl_Text_Editor* e);
00115 static int kf_page_down(int c, Fl_Text_Editor* e);
00116 static int kf_insert(int c, Fl_Text_Editor* e);
00117 static int kf_delete(int c, Fl_Text_Editor* e);
00118 static int kf_copy(int c, Fl_Text_Editor* e);
00119 static int kf_cut(int c, Fl_Text_Editor* e);
00120 static int kf_paste(int c, Fl_Text_Editor* e);
00121 static int kf_select_all(int c, Fl_Text_Editor* e);
00122 static int kf_undo(int c, Fl_Text_Editor* e);
00123
00124 protected:
00125 int handle_key();
00126 void maybe_do_callback();
00127
00128 #ifndef FL_DOXYGEN
00129 int insert_mode_;
00130 Key_Binding* key_bindings;
00131 static Key_Binding* global_key_bindings;
00132 Key_Func default_key_function_;
00133 #endif
00134 };
00135
00136 #endif
00137
00138
00139
00140
00141