Skip to content

Commit

Permalink
Document Fl_Text_Editor::global_key_bindings and related methods.
Browse files Browse the repository at this point in the history
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10830 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Albrecht Schlosser committed Aug 13, 2015
1 parent 9bedf7a commit 0650563
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
27 changes: 19 additions & 8 deletions FL/Fl_Text_Editor.H
Expand Up @@ -31,18 +31,18 @@
#define FL_TEXT_EDITOR_ANY_STATE (-1L)

/**
This is the FLTK text editor widget. It allows the user to
edit multiple lines of text and supports highlighting and
scrolling. The buffer that is displayed in the widget is managed
by the Fl_Text_Buffer
class.
This is the FLTK text editor widget.
It allows the user to edit multiple lines of text and supports highlighting
and scrolling. The buffer that is displayed in the widget is managed
by the Fl_Text_Buffer class.
*/
class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
public:
/** Key function binding callback type */
/** Key function binding callback type. */
typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);

/** Simple linked list associating a key/state to a function */
/** Simple linked list item associating a key/state to a function. */
struct Key_Binding {
int key; ///< the key pressed
int state; ///< the state of key modifiers
Expand All @@ -67,7 +67,7 @@ class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
int insert_mode() { return insert_mode_; }

void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
/** Adds a key of state "state" with the function "function" */
/** Adds a \p key of state \p state with the function \p f. */
void add_key_binding(int key, int state, Key_Func f)
{ add_key_binding(key, state, f, &key_bindings); }
void remove_key_binding(int key, int state, Key_Binding** list);
Expand Down Expand Up @@ -119,7 +119,18 @@ class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
#ifndef FL_DOXYGEN
int insert_mode_;
Key_Binding* key_bindings;
#endif

/** Global key binding list.
Derived classes can add key bindings for all Fl_Text_Editor widgets
by adding a Key_Binding to this list.
\see add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
*/
static Key_Binding* global_key_bindings;

#ifndef FL_DOXYGEN
Key_Func default_key_function_;
#endif
};
Expand Down
17 changes: 15 additions & 2 deletions src/Fl_Text_Editor.cxx
Expand Up @@ -192,7 +192,13 @@ void Fl_Text_Editor::remove_all_key_bindings(Key_Binding** list) {
*list = 0;
}

/** Removes the key binding associated with the key "key" of state "state" */
/** Removes the key binding associated with the key \p key of state \p state
from the Key_Binding list \p list.
This can be used in derived classes to remove global key bindings
by using the global (static) Key_Binding list
Fl_Text_Editor::global_key_bindings.
*/
void Fl_Text_Editor::remove_key_binding(int key, int state, Key_Binding** list) {
Key_Binding *cur, *last = 0;
for (cur = *list; cur; last = cur, cur = cur->next)
Expand All @@ -202,7 +208,14 @@ void Fl_Text_Editor::remove_key_binding(int key, int state, Key_Binding** list)
else *list = cur->next;
delete cur;
}
/** Adds a key of state "state" with the function "function" */

/** Adds a \p key of state \p state with the function \p function to an
arbitrary key binding list \p list.
This can be used in derived classes to add global key bindings
by using the global (static) Key_Binding list
Fl_Text_Editor::global_key_bindings.
*/
void Fl_Text_Editor::add_key_binding(int key, int state, Key_Func function,
Key_Binding** list) {
Key_Binding* kb = new Key_Binding;
Expand Down

0 comments on commit 0650563

Please sign in to comment.