FLTK 1.3.0
Fl_Text_Editor.H
00001 //
00002 // "$Id: Fl_Text_Editor.H 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Header file for Fl_Text_Editor class.
00005 //
00006 // Copyright 2001-2010 by Bill Spitzak and others.
00007 // Original code Copyright Mark Edel.  Permission to distribute under
00008 // the LGPL for the FLTK library granted by Mark Edel.
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Library General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Library General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Library General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA.
00024 //
00025 // Please report all bugs and problems on the following page:
00026 //
00027 //     http://www.fltk.org/str.php
00028 //
00029 
00030 /* \file
00031    Fl_Text_Editor widget . */
00032 
00033 
00034 #ifndef FL_TEXT_EDITOR_H
00035 #define FL_TEXT_EDITOR_H
00036 
00037 #include "Fl_Text_Display.H"
00038 
00039 // key will match in any state
00040 #define FL_TEXT_EDITOR_ANY_STATE  (-1L)
00041 
00049 class FL_EXPORT Fl_Text_Editor : public Fl_Text_Display {
00050   public:
00052     typedef int (*Key_Func)(int key, Fl_Text_Editor* editor);
00053 
00055     struct Key_Binding {
00056       int          key;         
00057       int          state;       
00058       Key_Func     function;    
00059       Key_Binding* next;        
00060     };
00061 
00062     Fl_Text_Editor(int X, int Y, int W, int H, const char* l = 0);
00063     ~Fl_Text_Editor() { remove_all_key_bindings(); }
00064     virtual int handle(int e);
00070     void insert_mode(int b) { insert_mode_ = b; }
00076     int insert_mode() { return insert_mode_; }
00077 
00078     void add_key_binding(int key, int state, Key_Func f, Key_Binding** list);
00080     void add_key_binding(int key, int state, Key_Func f)
00081       { add_key_binding(key, state, f, &key_bindings); }
00082     void remove_key_binding(int key, int state, Key_Binding** list);
00084     void remove_key_binding(int key, int state)
00085       { remove_key_binding(key, state, &key_bindings); }
00086     void remove_all_key_bindings(Key_Binding** list);
00088     void remove_all_key_bindings() { remove_all_key_bindings(&key_bindings); }
00089     void add_default_key_bindings(Key_Binding** list);
00090     Key_Func bound_key_function(int key, int state, Key_Binding* list);
00092     Key_Func bound_key_function(int key, int state)
00093       { return bound_key_function(key, state, key_bindings); }
00095     void default_key_function(Key_Func f) { default_key_function_ = f; }
00096 
00097     // functions for the built in default bindings
00098     static int kf_default(int c, Fl_Text_Editor* e);
00099     static int kf_ignore(int c, Fl_Text_Editor* e);
00100     static int kf_backspace(int c, Fl_Text_Editor* e);
00101     static int kf_enter(int c, Fl_Text_Editor* e);
00102     static int kf_move(int c, Fl_Text_Editor* e);
00103     static int kf_shift_move(int c, Fl_Text_Editor* e);
00104     static int kf_ctrl_move(int c, Fl_Text_Editor* e);
00105     static int kf_c_s_move(int c, Fl_Text_Editor* e);
00106     static int kf_meta_move(int c, Fl_Text_Editor* e);
00107     static int kf_m_s_move(int c, Fl_Text_Editor* e);
00108     static int kf_home(int, Fl_Text_Editor* e);
00109     static int kf_end(int c, Fl_Text_Editor* e);
00110     static int kf_left(int c, Fl_Text_Editor* e);
00111     static int kf_up(int c, Fl_Text_Editor* e);
00112     static int kf_right(int c, Fl_Text_Editor* e);
00113     static int kf_down(int c, Fl_Text_Editor* e);
00114     static int kf_page_up(int c, Fl_Text_Editor* e);
00115     static int kf_page_down(int c, Fl_Text_Editor* e);
00116     static int kf_insert(int c, Fl_Text_Editor* e);
00117     static int kf_delete(int c, Fl_Text_Editor* e);
00118     static int kf_copy(int c, Fl_Text_Editor* e);
00119     static int kf_cut(int c, Fl_Text_Editor* e);
00120     static int kf_paste(int c, Fl_Text_Editor* e);
00121     static int kf_select_all(int c, Fl_Text_Editor* e);
00122     static int kf_undo(int c, Fl_Text_Editor* e);
00123 
00124   protected:
00125     int handle_key();
00126     void maybe_do_callback();
00127 
00128 #ifndef FL_DOXYGEN
00129     int insert_mode_;
00130     Key_Binding* key_bindings;
00131     static Key_Binding* global_key_bindings;
00132     Key_Func default_key_function_;
00133 #endif
00134 };
00135 
00136 #endif
00137 
00138 //
00139 // End of "$Id: Fl_Text_Editor.H 7903 2010-11-28 21:06:39Z matt $".
00140 //
00141