Move the sources to trunk
[opencv] / otherlibs / _fltk / include / FL / Fl_Text_Editor.H
1 //
2 // "$Id: Fl_Text_Editor.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $"
3 //
4 // Header file for Fl_Text_Editor class.
5 //
6 // Copyright 2001-2002 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 to "fltk-bugs@fltk.org".
26 //
27
28
29 #ifndef FL_TEXT_EDITOR_H
30 #define FL_TEXT_EDITOR_H
31
32 #include "Fl_Text_Display.H"
33
34 // key will match in any state
35 #define FL_TEXT_EDITOR_ANY_STATE  (-1L)
36
37 class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
38   public:
39     typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
40
41     struct Key_Binding {
42       int          key;
43       int          state;
44       Key_Func     function;
45       Key_Binding* next;
46     };
47
48     Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
49     ~Fl_Text_Editor() { remove_all_key_bindings(); }
50     virtual int handle(int e);
51     void insert_mode(int b) { insert_mode_ = b; }
52     int insert_mode() { return insert_mode_; }
53
54     void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
55     void add_key_binding(int key, int state, Key_Func f)
56       { add_key_binding(key, state, f, &key_bindings); }
57     void remove_key_binding(int key, int state, Key_Binding** list);
58     void remove_key_binding(int key, int state)
59       { remove_key_binding(key, state, &key_bindings); }
60     void remove_all_key_bindings(Key_Binding** list);
61     void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
62     void add_default_key_bindings(Key_Binding** list);
63     Key_Func bound_key_function(int key, int state, Key_Binding* list);
64     Key_Func bound_key_function(int key, int state)
65       { return bound_key_function(key, state, key_bindings); }
66     void default_key_function(Key_Func f) { default_key_function_ = f; }
67
68     // functions for the built in default bindings
69     static int kf_default(int c, Fl_Text_Editor* e);
70     static int kf_ignore(int c, Fl_Text_Editor* e);
71     static int kf_backspace(int c, Fl_Text_Editor* e);
72     static int kf_enter(int c, Fl_Text_Editor* e);
73     static int kf_move(int c, Fl_Text_Editor* e);
74     static int kf_shift_move(int c, Fl_Text_Editor* e);
75     static int kf_ctrl_move(int c, Fl_Text_Editor* e);
76     static int kf_c_s_move(int c, Fl_Text_Editor* e);
77     static int kf_home(int, Fl_Text_Editor* e);
78     static int kf_end(int c, Fl_Text_Editor* e);
79     static int kf_left(int c, Fl_Text_Editor* e);
80     static int kf_up(int c, Fl_Text_Editor* e);
81     static int kf_right(int c, Fl_Text_Editor* e);
82     static int kf_down(int c, Fl_Text_Editor* e);
83     static int kf_page_up(int c, Fl_Text_Editor* e);
84     static int kf_page_down(int c, Fl_Text_Editor* e);
85     static int kf_insert(int c, Fl_Text_Editor* e);
86     static int kf_delete(int c, Fl_Text_Editor* e);
87     static int kf_copy(int c, Fl_Text_Editor* e);
88     static int kf_cut(int c, Fl_Text_Editor* e);
89     static int kf_paste(int c, Fl_Text_Editor* e);
90     static int kf_select_all(int c, Fl_Text_Editor* e);
91     static int kf_undo(int c, Fl_Text_Editor* e);
92
93   protected:
94     int handle_key();
95     void maybe_do_callback();
96
97     int insert_mode_;
98     Key_Binding* key_bindings;
99     static Key_Binding* global_key_bindings;
100     Key_Func default_key_function_;
101 };
102
103 #endif
104
105 //
106 // End of "$Id: Fl_Text_Editor.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $".
107 //
108