NTK 1.3.0
Fl_Text_Editor.H
1//
2// "$Id: Fl_Text_Editor.H 7903 2010-11-28 21:06:39Z matt $"
3//
4// Header file for Fl_Text_Editor 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 Free Software
22// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23// USA.
24//
25// Please report all bugs and problems on the following page:
26//
27// http://www.fltk.org/str.php
28//
29
30/* \file
31 Fl_Text_Editor widget . */
32
33
34#ifndef FL_TEXT_EDITOR_H
35#define FL_TEXT_EDITOR_H
36
37#include "Fl_Text_Display.H"
38
39// key will match in any state
40#define FL_TEXT_EDITOR_ANY_STATE (-1L)
41
49class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
50 public:
52 typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
53
55 struct Key_Binding {
56 int key;
57 int state;
58 Key_Func function;
60 };
61
62 Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
63 ~Fl_Text_Editor() { remove_all_key_bindings(); }
64 virtual int handle(int e);
70 void insert_mode(int b) { insert_mode_ = b; }
76 int insert_mode() { return insert_mode_; }
77
78 void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
80 void add_key_binding(int key, int state, Key_Func f)
81 { add_key_binding(key, state, f, &key_bindings); }
82 void remove_key_binding(int key, int state, Key_Binding** list);
84 void remove_key_binding(int key, int state)
85 { remove_key_binding(key, state, &key_bindings); }
86 void remove_all_key_bindings(Key_Binding** list);
89 void add_default_key_bindings(Key_Binding** list);
90 Key_Func bound_key_function(int key, int state, Key_Binding* list);
92 Key_Func bound_key_function(int key, int state)
93 { return bound_key_function(key, state, key_bindings); }
95 void default_key_function(Key_Func f) { default_key_function_ = f; }
96
97 // functions for the built in default bindings
98 static int kf_default(int c, Fl_Text_Editor* e);
99 static int kf_ignore(int c, Fl_Text_Editor* e);
100 static int kf_backspace(int c, Fl_Text_Editor* e);
101 static int kf_enter(int c, Fl_Text_Editor* e);
102 static int kf_move(int c, Fl_Text_Editor* e);
103 static int kf_shift_move(int c, Fl_Text_Editor* e);
104 static int kf_ctrl_move(int c, Fl_Text_Editor* e);
105 static int kf_c_s_move(int c, Fl_Text_Editor* e);
106 static int kf_meta_move(int c, Fl_Text_Editor* e);
107 static int kf_m_s_move(int c, Fl_Text_Editor* e);
108 static int kf_home(int, Fl_Text_Editor* e);
109 static int kf_end(int c, Fl_Text_Editor* e);
110 static int kf_left(int c, Fl_Text_Editor* e);
111 static int kf_up(int c, Fl_Text_Editor* e);
112 static int kf_right(int c, Fl_Text_Editor* e);
113 static int kf_down(int c, Fl_Text_Editor* e);
114 static int kf_page_up(int c, Fl_Text_Editor* e);
115 static int kf_page_down(int c, Fl_Text_Editor* e);
116 static int kf_insert(int c, Fl_Text_Editor* e);
117 static int kf_delete(int c, Fl_Text_Editor* e);
118 static int kf_copy(int c, Fl_Text_Editor* e);
119 static int kf_cut(int c, Fl_Text_Editor* e);
120 static int kf_paste(int c, Fl_Text_Editor* e);
121 static int kf_select_all(int c, Fl_Text_Editor* e);
122 static int kf_undo(int c, Fl_Text_Editor* e);
123
124 protected:
125 int handle_key();
126 void maybe_do_callback();
127
128#ifndef FL_DOXYGEN
129 int insert_mode_;
130 Key_Binding* key_bindings;
131 static Key_Binding* global_key_bindings;
132 Key_Func default_key_function_;
133#endif
134};
135
136#endif
137
138//
139// End of "$Id: Fl_Text_Editor.H 7903 2010-11-28 21:06:39Z matt $".
140//
141
Rich text display widget.
Definition: Fl_Text_Display.H:50
virtual int handle(int e)
Event handling.
Definition: Fl_Text_Display.cxx:3548
This is the FLTK text editor widget.
Definition: Fl_Text_Editor.H:49
void remove_key_binding(int key, int state)
Removes the key binding associated with the key "key" of state "state".
Definition: Fl_Text_Editor.H:84
void add_key_binding(int key, int state, Key_Func f)
Adds a key of state "state" with the function "function".
Definition: Fl_Text_Editor.H:80
Key_Func bound_key_function(int key, int state)
Returns the function associated with a key binding.
Definition: Fl_Text_Editor.H:92
int insert_mode()
Gets the current insert mode; if non-zero, new text is inserted before the current cursor position.
Definition: Fl_Text_Editor.H:76
void remove_all_key_bindings()
Removes all of the key bindings associated with the text editor or list.
Definition: Fl_Text_Editor.H:88
void insert_mode(int b)
Sets the current insert mode; if non-zero, new text is inserted before the current cursor position.
Definition: Fl_Text_Editor.H:70
void default_key_function(Key_Func f)
Sets the default key function for unassigned keys.
Definition: Fl_Text_Editor.H:95
Simple linked list associating a key/state to a function.
Definition: Fl_Text_Editor.H:55
int key
the key pressed
Definition: Fl_Text_Editor.H:56
Key_Func function
associated function
Definition: Fl_Text_Editor.H:58
int state
the state of key modifiers
Definition: Fl_Text_Editor.H:57
Key_Binding * next
next key binding in the list
Definition: Fl_Text_Editor.H:59