FLTK 1.4.4: Fl_Text_Editor.H Source File

FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_Text_Editor.H
1//
2// Header file for Fl_Text_Editor class.
3//
4// Copyright 2001-2023 by Bill Spitzak and others.
5// Original code Copyright Mark Edel. Permission to distribute under
6// the LGPL for the FLTK library granted by Mark Edel.
7//
8// This library is free software. Distribution and use rights are outlined in
9// the file "COPYING" which should have been included with this file. If this
10// file is missing or damaged, see the license at:
11//
12// https://www.fltk.org/COPYING.php
13//
14// Please see the following page on how to report bugs and issues:
15//
16// https://www.fltk.org/bugs.php
17//
18
19/* \file
20 Fl_Text_Editor widget . */
21
22
23#ifndef FL_TEXT_EDITOR_H
24#define FL_TEXT_EDITOR_H
25
26#include "Fl_Text_Display.H"
27
28// key will match in any state
29#define FL_TEXT_EDITOR_ANY_STATE (-1L)
30
38 class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
39 public:
41 typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
42
44 struct Key_Binding {
45 int key;
46 int state;
47 Key_Func function;
48 Key_Binding* next;
49 };
50
51 Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
52 ~Fl_Text_Editor() { remove_all_key_bindings(); }
53 int handle(int e) FL_OVERRIDE;
59 void insert_mode(int b) { insert_mode_ = b; }
65 int insert_mode() { return insert_mode_; }
66 void tab_nav(int val);
67 int tab_nav() const;
68 void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
70 void add_key_binding(int key, int state, Key_Func f)
71 { add_key_binding(key, state, f, &key_bindings); }
72 void remove_key_binding(int key, int state, Key_Binding** list);
74 void remove_key_binding(int key, int state)
75 { remove_key_binding(key, state, &key_bindings); }
76 void remove_all_key_bindings(Key_Binding** list);
78 void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
79 void add_default_key_bindings(Key_Binding** list);
80 Key_Func bound_key_function(int key, int state, Key_Binding* list) const;
82 Key_Func bound_key_function(int key, int state) const
83 { return bound_key_function(key, state, key_bindings); }
84
85 void default_key_function(Key_Func f) { default_key_function_ = f; }
86
87 // functions for the built in default bindings
88 static int kf_default(int c, Fl_Text_Editor* e);
89 static int kf_ignore(int c, Fl_Text_Editor* e);
90 static int kf_backspace(int c, Fl_Text_Editor* e);
91 static int kf_enter(int c, Fl_Text_Editor* e);
92 static int kf_move(int c, Fl_Text_Editor* e);
93 static int kf_shift_move(int c, Fl_Text_Editor* e);
94 static int kf_ctrl_move(int c, Fl_Text_Editor* e);
95 static int kf_c_s_move(int c, Fl_Text_Editor* e);
96 static int kf_meta_move(int c, Fl_Text_Editor* e);
97 static int kf_m_s_move(int c, Fl_Text_Editor* e);
98 static int kf_home(int, Fl_Text_Editor* e);
99 static int kf_end(int c, Fl_Text_Editor* e);
100 static int kf_left(int c, Fl_Text_Editor* e);
101 static int kf_up(int c, Fl_Text_Editor* e);
102 static int kf_right(int c, Fl_Text_Editor* e);
103 static int kf_down(int c, Fl_Text_Editor* e);
104 static int kf_page_up(int c, Fl_Text_Editor* e);
105 static int kf_page_down(int c, Fl_Text_Editor* e);
106 static int kf_insert(int c, Fl_Text_Editor* e);
107 static int kf_delete(int c, Fl_Text_Editor* e);
108 static int kf_copy(int c, Fl_Text_Editor* e);
109 static int kf_cut(int c, Fl_Text_Editor* e);
110 static int kf_paste(int c, Fl_Text_Editor* e);
111 static int kf_select_all(int c, Fl_Text_Editor* e);
112 static int kf_undo(int c, Fl_Text_Editor* e);
113 static int kf_redo(int c, Fl_Text_Editor* e);
114
115 protected:
116 int handle_key();
117 void maybe_do_callback(Fl_Callback_Reason reason = FL_REASON_CHANGED);
118
119#ifndef FL_DOXYGEN
120 int insert_mode_;
121 Key_Binding* key_bindings;
122#endif
123
131 static Key_Binding* global_key_bindings;
132
133#ifndef FL_DOXYGEN
134 Key_Func default_key_function_;
135#endif
136};
137
138#endif
139
Fl_Callback_Reason
Fl_Callback_Reason
These constants describe why a callback is performed.
Definition Enumerations.H:455
FL_REASON_CHANGED
@ FL_REASON_CHANGED
the value of the widget was modified
Definition Enumerations.H:464
Fl_Text_Display::Fl_Text_Display
Fl_Text_Display(int X, int Y, int W, int H, const char *l=0)
Creates a new text display widget.
Definition Fl_Text_Display.cxx:106
Fl_Text_Display::handle
int handle(int e) FL_OVERRIDE
Event handling.
Definition Fl_Text_Display.cxx:4197
Fl_Text_Editor
This is the FLTK text editor widget.
Definition Fl_Text_Editor.H:38
Fl_Text_Editor::Key_Func
int(* Key_Func)(int key, Fl_Text_Editor *editor)
Key function binding callback type.
Definition Fl_Text_Editor.H:41
Fl_Text_Editor::remove_key_binding
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:74
Fl_Text_Editor::add_key_binding
void add_key_binding(int key, int state, Key_Func f)
Adds a key of state state with the function f.
Definition Fl_Text_Editor.H:70
Fl_Text_Editor::remove_all_key_bindings
void remove_all_key_bindings(Key_Binding **list)
Removes all of the key bindings associated with the text editor or list.
Definition Fl_Text_Editor.cxx:179
Fl_Text_Editor::add_key_binding
void add_key_binding(int key, int state, Key_Func f, Key_Binding **list)
Adds a key of state state with the function function to an arbitrary key binding list list.
Definition Fl_Text_Editor.cxx:212
Fl_Text_Editor::bound_key_function
Key_Func bound_key_function(int key, int state) const
Returns the function associated with a key binding.
Definition Fl_Text_Editor.H:82
Fl_Text_Editor::insert_mode
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:65
Fl_Text_Editor::remove_all_key_bindings
void remove_all_key_bindings()
Removes all of the key bindings associated with the text editor or list.
Definition Fl_Text_Editor.H:78
Fl_Text_Editor::global_key_bindings
static Key_Binding * global_key_bindings
Global key binding list.
Definition Fl_Text_Editor.H:131
Fl_Text_Editor::remove_key_binding
void remove_key_binding(int key, int state, Key_Binding **list)
Removes the key binding associated with the key key of state state from the Key_Binding list list.
Definition Fl_Text_Editor.cxx:195
Fl_Text_Editor::insert_mode
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:59
Fl_Text_Editor::bound_key_function
Key_Func bound_key_function(int key, int state, Key_Binding *list) const
Returns the function associated with a key binding.
Definition Fl_Text_Editor.cxx:168
Fl_Text_Editor::Fl_Text_Editor
Fl_Text_Editor(int X, int Y, int W, int H, const char *l=0)
The constructor creates a new text editor widget.
Definition Fl_Text_Editor.cxx:70
Fl_Text_Editor::default_key_function
void default_key_function(Key_Func f)
Sets the default key function for unassigned keys.
Definition Fl_Text_Editor.H:85
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
Fl_Text_Editor::Key_Binding
Simple linked list item associating a key/state to a function.
Definition Fl_Text_Editor.H:44
Fl_Text_Editor::Key_Binding::key
int key
the key pressed
Definition Fl_Text_Editor.H:45
Fl_Text_Editor::Key_Binding::function
Key_Func function
associated function
Definition Fl_Text_Editor.H:47
Fl_Text_Editor::Key_Binding::state
int state
the state of key modifiers
Definition Fl_Text_Editor.H:46
Fl_Text_Editor::Key_Binding::next
Key_Binding * next
next key binding in the list
Definition Fl_Text_Editor.H:48