00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _FL_TEXT_EDITOR_H_
00023 #define _FL_TEXT_EDITOR_H_
00024
00025 #include "Fl_Text_Display.h"
00026
00027
00028 #define FL_TEXT_EDITOR_ANY_STATE (-1L)
00029
00031 class FL_API Fl_Text_Editor : public Fl_Text_Display {
00032 public:
00033 typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
00034
00035 struct FL_API Key_Binding {
00036 int key;
00037 int state;
00038 Key_Func function;
00039 Key_Binding* next;
00040 };
00041
00043 Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
00044
00046 Fl_Text_Editor(const char* l = 0,int layout_size=30,Fl_Align layout_al=FL_ALIGN_TOP,int label_w=-1);
00047
00049 ~Fl_Text_Editor() { remove_all_key_bindings(); }
00050
00051 static Fl_Named_Style* default_style;
00052 virtual int handle(int e);
00053 void insert_mode(int b) { insert_mode_ = b; }
00054 int insert_mode() { return insert_mode_; }
00055
00056 void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
00057 void add_key_binding(int key, int state, Key_Func f)
00058 { add_key_binding(key, state, f, &key_bindings); }
00059 void remove_key_binding(int key, int state, Key_Binding** list);
00060 void remove_key_binding(int key, int state)
00061 { remove_key_binding(key, state, &key_bindings); }
00062 void remove_all_key_bindings(Key_Binding** list);
00063 void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
00064 void add_default_key_bindings(Key_Binding** list);
00065 Key_Func bound_key_function(int key, int state, Key_Binding* list);
00066 Key_Func bound_key_function(int key, int state)
00067 { return bound_key_function(key, state, key_bindings); }
00068 void default_key_function(Key_Func f) { default_key_function_ = f; }
00069
00070
00071 static int kf_default(int c, Fl_Text_Editor* e);
00072 static int kf_ignore(int c, Fl_Text_Editor* e);
00073 static int kf_backspace(int c, Fl_Text_Editor* e);
00074 static int kf_enter(int c, Fl_Text_Editor* e);
00075 static int kf_move(int c, Fl_Text_Editor* e);
00076 static int kf_shift_move(int c, Fl_Text_Editor* e);
00077 static int kf_ctrl_move(int c, Fl_Text_Editor* e);
00078 static int kf_c_s_move(int c, Fl_Text_Editor* e);
00079 static int kf_home(int, Fl_Text_Editor* e);
00080 static int kf_end(int c, Fl_Text_Editor* e);
00081 static int kf_left(int c, Fl_Text_Editor* e);
00082 static int kf_up(int c, Fl_Text_Editor* e);
00083 static int kf_right(int c, Fl_Text_Editor* e);
00084 static int kf_down(int c, Fl_Text_Editor* e);
00085 static int kf_page_up(int c, Fl_Text_Editor* e);
00086 static int kf_page_down(int c, Fl_Text_Editor* e);
00087 static int kf_insert(int c, Fl_Text_Editor* e);
00088 static int kf_delete(int c, Fl_Text_Editor* e);
00089 static int kf_copy(int c, Fl_Text_Editor* e);
00090 static int kf_cut(int c, Fl_Text_Editor* e);
00091 static int kf_undo(int c, Fl_Text_Editor* e);
00092 static int kf_paste(int c, Fl_Text_Editor* e);
00093 static int kf_select_all(int c, Fl_Text_Editor* e);
00094
00095 void insert(const char* text);
00096 void overstrike(const char* text);
00097
00098 protected:
00099 int handle_key();
00100 int insert_mode_;
00101 Key_Binding* key_bindings;
00102 static Key_Binding* global_key_bindings;
00103 Key_Func default_key_function_;
00104 private:
00105 void ctor_init();
00106 };
00107
00108 #endif