Debian Codegraph @

src/include/Fl_Text_Editor_mod.H

raw
1 //
2 // "$Id: Fl_Text_Editor_mod.H 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Header file for Fl_Text_Editor_mod class.
5 //
6 // Copyright 2001-2010 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
22 //
23 // Free Software Foundation, Inc.
24 // 51 Franklin Street, Fifth Floor
25 // Boston, MA 02110-1301 USA.
26 //
27 // Please report all bugs and problems on the following page:
28 //
29 // http://www.fltk.org/str.php
30 //
31
32 /* \file
33 Fl_Text_Editor_mod widget . */
34
35
36 #ifndef Fl_Text_Editor_mod_H
37 #define Fl_Text_Editor_mod_H
38
39 #include "Fl_Text_Display_mod.H"
40
41 #include <config.h>
42
43 // key will match in any state
44 #define Fl_Text_Editor_mod_ANY_STATE (-1L)
45
46 /**
47 This is the FLTK text editor widget. It allows the user to
48 edit multiple lines of text and supports highlighting and
49 scrolling. The buffer that is displayed in the widget is managed
50 by the Fl_Text_Buffer_mod
51 class.
52 */
53 class FL_EXPORT Fl_Text_Editor_mod : public Fl_Text_Display_mod {
54 public:
55 /** Key function binding callback type */
56 typedef int (*Key_Func)(int key, Fl_Text_Editor_mod* editor);
57
58 /** Simple linked list associating a key/state to a function */
59 struct Key_Binding {
60 int key; ///< the key pressed
61 int state; ///< the state of key modifiers
62 Key_Func function; ///< associated function
63 Key_Binding* next; ///< next key binding in the list
64 };
65
66 Fl_Text_Editor_mod(int X, int Y, int W, int H, const char* l = 0);
67 ~Fl_Text_Editor_mod() { remove_all_key_bindings(); }
68 virtual int handle(int e);
69 /**
70 Sets the current insert mode; if non-zero, new text
71 is inserted before the current cursor position. Otherwise, new
72 text replaces text at the current cursor position.
73 */
74 void insert_mode(int b) { insert_mode_ = b; }
75 /**
76 Gets the current insert mode; if non-zero, new text
77 is inserted before the current cursor position. Otherwise, new
78 text replaces text at the current cursor position.
79 */
80 int insert_mode() { return insert_mode_; }
81
82 void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
83 /** Adds a key of state "state" with the function "function" */
84 void add_key_binding(int key, int state, Key_Func f)
85 { add_key_binding(key, state, f, &key_bindings); }
86 void remove_key_binding(int key, int state, Key_Binding** list);
87 /** Removes the key binding associated with the key "key" of state "state". */
88 void remove_key_binding(int key, int state)
89 { remove_key_binding(key, state, &key_bindings); }
90 void remove_all_key_bindings(Key_Binding** list);
91 /** Removes all of the key bindings associated with the text editor or list. */
92 void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
93 void add_default_key_bindings(Key_Binding** list);
94 Key_Func bound_key_function(int key, int state, Key_Binding* list);
95 /** Returns the function associated with a key binding. */
96 Key_Func bound_key_function(int key, int state)
97 { return bound_key_function(key, state, key_bindings); }
98 /** Sets the default key function for unassigned keys. */
99 void default_key_function(Key_Func f) { default_key_function_ = f; }
100
101 // functions for the built in default bindings
102 static int kf_default(int c, Fl_Text_Editor_mod* e);
103 static int kf_ignore(int c, Fl_Text_Editor_mod* e);
104 static int kf_backspace(int c, Fl_Text_Editor_mod* e);
105 static int kf_enter(int c, Fl_Text_Editor_mod* e);
106 static int kf_move(int c, Fl_Text_Editor_mod* e);
107 static int kf_shift_move(int c, Fl_Text_Editor_mod* e);
108 static int kf_ctrl_move(int c, Fl_Text_Editor_mod* e);
109 static int kf_c_s_move(int c, Fl_Text_Editor_mod* e);
110 static int kf_meta_move(int c, Fl_Text_Editor_mod* e);
111 static int kf_m_s_move(int c, Fl_Text_Editor_mod* e);
112 static int kf_home(int, Fl_Text_Editor_mod* e);
113 static int kf_end(int c, Fl_Text_Editor_mod* e);
114 static int kf_left(int c, Fl_Text_Editor_mod* e);
115 static int kf_up(int c, Fl_Text_Editor_mod* e);
116 static int kf_right(int c, Fl_Text_Editor_mod* e);
117 static int kf_down(int c, Fl_Text_Editor_mod* e);
118 static int kf_page_up(int c, Fl_Text_Editor_mod* e);
119 static int kf_page_down(int c, Fl_Text_Editor_mod* e);
120 static int kf_insert(int c, Fl_Text_Editor_mod* e);
121 static int kf_delete(int c, Fl_Text_Editor_mod* e);
122 static int kf_copy(int c, Fl_Text_Editor_mod* e);
123 static int kf_cut(int c, Fl_Text_Editor_mod* e);
124 static int kf_paste(int c, Fl_Text_Editor_mod* e);
125 static int kf_select_all(int c, Fl_Text_Editor_mod* e);
126 static int kf_undo(int c, Fl_Text_Editor_mod* e);
127
128 protected:
129 int handle_key();
130 void maybe_do_callback();
131
132 #ifndef FL_DOXYGEN
133 int insert_mode_;
134 Key_Binding* key_bindings;
135 static Key_Binding* global_key_bindings;
136 Key_Func default_key_function_;
137 #endif
138 };
139
140 #endif
141
142 //
143 // End of "$Id: Fl_Text_Editor_mod.H 7903 2010-11-28 21:06:39Z matt $".
144 //
145