2001-08-02 01:24:49 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// Header file for Fl_Text_Editor class.
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 2001-2010 by Bill Spitzak and others.
|
2002-01-01 18:11:33 +03:00
|
|
|
// Original code Copyright Mark Edel. Permission to distribute under
|
|
|
|
// the LGPL for the FLTK library granted by Mark Edel.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Text_Editor widget . */
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
#ifndef FL_TEXT_EDITOR_H
|
|
|
|
#define FL_TEXT_EDITOR_H
|
|
|
|
|
2001-08-04 16:21:34 +04:00
|
|
|
#include "Fl_Text_Display.H"
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
// key will match in any state
|
|
|
|
#define FL_TEXT_EDITOR_ANY_STATE (-1L)
|
|
|
|
|
2008-09-15 20:39:05 +04:00
|
|
|
/**
|
2015-08-13 13:07:17 +03:00
|
|
|
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.
|
2008-09-15 20:39:05 +04:00
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
|
2001-08-02 01:24:49 +04:00
|
|
|
public:
|
2015-08-13 13:07:17 +03:00
|
|
|
/** Key function binding callback type. */
|
2001-08-02 01:24:49 +04:00
|
|
|
typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
|
|
|
|
|
2015-08-13 13:07:17 +03:00
|
|
|
/** Simple linked list item associating a key/state to a function. */
|
2002-08-14 20:49:38 +04:00
|
|
|
struct Key_Binding {
|
2008-09-18 23:09:34 +04:00
|
|
|
int key; ///< the key pressed
|
|
|
|
int state; ///< the state of key modifiers
|
|
|
|
Key_Func function; ///< associated function
|
|
|
|
Key_Binding* next; ///< next key binding in the list
|
2001-08-02 01:24:49 +04:00
|
|
|
};
|
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
|
2001-08-02 01:24:49 +04:00
|
|
|
~Fl_Text_Editor() { remove_all_key_bindings(); }
|
2002-08-14 20:49:38 +04:00
|
|
|
virtual int handle(int e);
|
2008-09-15 20:39:05 +04:00
|
|
|
/**
|
|
|
|
Sets the current insert mode; if non-zero, new text
|
|
|
|
is inserted before the current cursor position. Otherwise, new
|
|
|
|
text replaces text at the current cursor position.
|
|
|
|
*/
|
2001-08-02 01:24:49 +04:00
|
|
|
void insert_mode(int b) { insert_mode_ = b; }
|
2008-09-15 20:39:05 +04:00
|
|
|
/**
|
|
|
|
Gets the current insert mode; if non-zero, new text
|
|
|
|
is inserted before the current cursor position. Otherwise, new
|
|
|
|
text replaces text at the current cursor position.
|
|
|
|
*/
|
2001-08-02 01:24:49 +04:00
|
|
|
int insert_mode() { return insert_mode_; }
|
|
|
|
|
2016-07-14 21:48:43 +03:00
|
|
|
#if FLTK_ABI_VERSION >= 10304
|
|
|
|
void tab_nav(int val);
|
|
|
|
int tab_nav() const;
|
|
|
|
#endif
|
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
|
2015-08-13 13:07:17 +03:00
|
|
|
/** Adds a \p key of state \p state with the function \p f. */
|
2001-08-02 01:24:49 +04:00
|
|
|
void add_key_binding(int key, int state, Key_Func f)
|
|
|
|
{ add_key_binding(key, state, f, &key_bindings); }
|
2002-08-14 20:49:38 +04:00
|
|
|
void remove_key_binding(int key, int state, Key_Binding** list);
|
2008-09-15 20:39:05 +04:00
|
|
|
/** Removes the key binding associated with the key "key" of state "state". */
|
2001-08-02 01:24:49 +04:00
|
|
|
void remove_key_binding(int key, int state)
|
|
|
|
{ remove_key_binding(key, state, &key_bindings); }
|
2002-08-14 20:49:38 +04:00
|
|
|
void remove_all_key_bindings(Key_Binding** list);
|
2008-09-15 20:39:05 +04:00
|
|
|
/** Removes all of the key bindings associated with the text editor or list. */
|
2001-08-02 01:24:49 +04:00
|
|
|
void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
|
2002-08-14 20:49:38 +04:00
|
|
|
void add_default_key_bindings(Key_Binding** list);
|
2016-07-14 02:19:12 +03:00
|
|
|
#if FLTK_ABI_VERSION < 10304
|
|
|
|
// OLD: non-const
|
2002-08-14 20:49:38 +04:00
|
|
|
Key_Func bound_key_function(int key, int state, Key_Binding* list);
|
2008-09-15 20:39:05 +04:00
|
|
|
/** Returns the function associated with a key binding. */
|
2001-08-02 01:24:49 +04:00
|
|
|
Key_Func bound_key_function(int key, int state)
|
|
|
|
{ return bound_key_function(key, state, key_bindings); }
|
2016-07-14 02:19:12 +03:00
|
|
|
#else
|
|
|
|
// NEW: const (STR#3306)
|
|
|
|
Key_Func bound_key_function(int key, int state, Key_Binding* list) const;
|
|
|
|
/** Returns the function associated with a key binding. */
|
|
|
|
Key_Func bound_key_function(int key, int state) const
|
|
|
|
{ return bound_key_function(key, state, key_bindings); }
|
|
|
|
#endif
|
2008-09-15 20:39:05 +04:00
|
|
|
/** Sets the default key function for unassigned keys. */
|
2001-08-02 01:24:49 +04:00
|
|
|
void default_key_function(Key_Func f) { default_key_function_ = f; }
|
|
|
|
|
|
|
|
// functions for the built in default bindings
|
2002-08-14 20:49:38 +04:00
|
|
|
static int kf_default(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_ignore(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_backspace(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_enter(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_move(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_shift_move(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_ctrl_move(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_c_s_move(int c, Fl_Text_Editor* e);
|
2009-09-20 23:24:24 +04:00
|
|
|
static int kf_meta_move(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_m_s_move(int c, Fl_Text_Editor* e);
|
2002-08-14 20:49:38 +04:00
|
|
|
static int kf_home(int, Fl_Text_Editor* e);
|
|
|
|
static int kf_end(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_left(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_up(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_right(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_down(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_page_up(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_page_down(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_insert(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_delete(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_copy(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_cut(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_paste(int c, Fl_Text_Editor* e);
|
|
|
|
static int kf_select_all(int c, Fl_Text_Editor* e);
|
2002-11-05 22:53:50 +03:00
|
|
|
static int kf_undo(int c, Fl_Text_Editor* e);
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
protected:
|
2002-08-14 20:49:38 +04:00
|
|
|
int handle_key();
|
2002-11-05 09:45:41 +03:00
|
|
|
void maybe_do_callback();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2008-09-18 23:09:34 +04:00
|
|
|
#ifndef FL_DOXYGEN
|
2001-08-02 01:24:49 +04:00
|
|
|
int insert_mode_;
|
|
|
|
Key_Binding* key_bindings;
|
2015-08-13 13:07:17 +03:00
|
|
|
#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);
|
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
static Key_Binding* global_key_bindings;
|
2015-08-13 13:07:17 +03:00
|
|
|
|
|
|
|
#ifndef FL_DOXYGEN
|
2001-08-02 01:24:49 +04:00
|
|
|
Key_Func default_key_function_;
|
2008-09-18 23:09:34 +04:00
|
|
|
#endif
|
2001-08-02 01:24:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|