diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2008-04-22 23:33:17 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2008-04-22 23:33:17 +0000 |
| commit | 8198e51799ba715d27e82b276b93cb39918d3361 (patch) | |
| tree | b21114724d43324e86450d6d43ca56527b14ff7c | |
| parent | 6a143b1f61533c03ef20a8f2b82d2c90180055bc (diff) | |
Added support for keyboard shortcuts to Fl_Input_ derived widgets (STR #1770). Code added for Fluid. Documentation updated.
This commit must be considered partial because there is no shortcut handling for Fl_Text_Display derived widgets or Fl_Value_Input which is derived form Fl_Valuator.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6109 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | FL/Fl_Input_.H | 4 | ||||
| -rw-r--r-- | documentation/Fl_Input_.html | 18 | ||||
| -rw-r--r-- | fluid/Fl_Menu_Type.cxx | 14 | ||||
| -rw-r--r-- | fluid/Fl_Type.cxx | 1 | ||||
| -rw-r--r-- | fluid/Fl_Type.h | 1 | ||||
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 23 | ||||
| -rw-r--r-- | fluid/factory.cxx | 4 | ||||
| -rw-r--r-- | src/Fl_Input_.cxx | 9 | ||||
| -rw-r--r-- | test/input.cxx | 14 |
10 files changed, 82 insertions, 8 deletions
@@ -1,5 +1,7 @@ CHANGES IN FLTK 1.3.0 + - added support for shortcuts for Fl_Input_ derived + widgets (STR #1770) - initial setup (STR #1904) CHANGES IN FLTK 1.1.9 diff --git a/FL/Fl_Input_.H b/FL/Fl_Input_.H index df52e36a0..985d74f99 100644 --- a/FL/Fl_Input_.H +++ b/FL/Fl_Input_.H @@ -58,6 +58,7 @@ class FL_EXPORT Fl_Input_ : public Fl_Widget { int xscroll_, yscroll_; int mu_p; int maximum_size_; + int shortcut_; uchar erase_cursor_only; uchar textfont_; @@ -119,6 +120,9 @@ public: int undo(); int copy_cuts(); + int shortcut() const {return shortcut_;} + void shortcut(int s) {shortcut_ = s;} + Fl_Font textfont() const {return (Fl_Font)textfont_;} void textfont(uchar s) {textfont_ = s;} uchar textsize() const {return textsize_;} diff --git a/documentation/Fl_Input_.html b/documentation/Fl_Input_.html index 9b7fb34ed..0c6c8fe7b 100644 --- a/documentation/Fl_Input_.html +++ b/documentation/Fl_Input_.html @@ -87,6 +87,7 @@ setting <TT>type()</TT> to one of the following values:</P> </UL> </TD><TD align="left" valign="top"> <UL> +<LI><A href="#Fl_Input_.shortcut">shortcut</A></LI> <LI><A href="#Fl_Input_.undo">undo</A></LI> <LI><A href="#Fl_Input_.up_down_position">up_down_position</A></LI> <LI><A href="#Fl_Input_.wrap">wrap</A></LI> @@ -255,6 +256,23 @@ information to the clipboard. This is used to make ^K work. <P>Gets or sets the read-only state of the input field. +<H4><A name="Fl_Input_.shortcut">ulong Fl_Input_::shortcut() const +<BR> void Fl_Input_::shortcut(ulong key)</A></H4> + The first form returns the current shortcut key for the Input. +<P>The second form sets the shortcut key to <TT>key</TT>. Setting this +overrides the use of '&' in the <TT>label()</TT>. The value is a bitwise +OR of a key and a set of shift flags, for example <CODE>FL_ALT | 'a'</CODE> +, <CODE>FL_ALT | (FL_F + 10)</CODE>, or just <CODE>'a'</CODE>. A value +of 0 disables the shortcut. </P> +<P>The key can be any value returned by <A href="Fl.html#Fl.event_key"> +<TT>Fl::event_key()</TT></A>, but will usually be an ASCII letter. Use +a lower-case letter unless you require the shift key to be held down. </P> +<P>The shift flags can be any set of values accepted by <A href="Fl.html#Fl.event_state"> +<TT>Fl::event_state()</TT></A>. If the bit is on that shift key must +be pushed. Meta, Alt, Ctrl, and Shift must be off if they are not in +the shift flags (zero for the other bits indicates a "don't care" +setting). </P> + <H4><A name="Fl_Input_.wrap">int Fl_Input_::wrap() const <BR>void Fl_Input_::wrap(int)</A></H4> diff --git a/fluid/Fl_Menu_Type.cxx b/fluid/Fl_Menu_Type.cxx index 94bd160e7..8055bf312 100644 --- a/fluid/Fl_Menu_Type.cxx +++ b/fluid/Fl_Menu_Type.cxx @@ -589,9 +589,14 @@ int Shortcut_Button::handle(int e) { void shortcut_in_cb(Shortcut_Button* i, void* v) { if (v == LOAD) { - if (!current_widget->is_button()) {i->hide(); return;} + if ( !current_widget->is_button() && !current_widget->is_input() ) { + i->hide(); return; + } i->show(); - i->svalue = ((Fl_Button*)(current_widget->o))->shortcut(); + if (current_widget->is_button()) + i->svalue = ((Fl_Button*)(current_widget->o))->shortcut(); + else if (current_widget->is_input()) + i->svalue = ((Fl_Input_*)(current_widget->o))->shortcut(); i->redraw(); } else { int mod = 0; @@ -602,6 +607,11 @@ void shortcut_in_cb(Shortcut_Button* i, void* v) { b->shortcut(i->svalue); if (o->is_menu_item()) ((Fl_Widget_Type*)o)->redraw(); } + else if (o->selected && o->is_input()) { + Fl_Input_* b = (Fl_Input_*)(((Fl_Widget_Type*)o)->o); + if (b->shortcut()!=i->svalue) mod = 1; + b->shortcut(i->svalue); + } if (mod) set_modflag(1); } } diff --git a/fluid/Fl_Type.cxx b/fluid/Fl_Type.cxx index d2ae60ca7..621650f82 100644 --- a/fluid/Fl_Type.cxx +++ b/fluid/Fl_Type.cxx @@ -628,6 +628,7 @@ int Fl_Type::is_widget() const {return 0;} int Fl_Type::is_valuator() const {return 0;} int Fl_Type::is_spinner() const {return 0;} int Fl_Type::is_button() const {return 0;} +int Fl_Type::is_input() const {return 0;} int Fl_Type::is_menu_item() const {return 0;} int Fl_Type::is_menu_button() const {return 0;} int Fl_Type::is_group() const {return 0;} diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h index a35fc6201..04c159c13 100644 --- a/fluid/Fl_Type.h +++ b/fluid/Fl_Type.h @@ -131,6 +131,7 @@ public: virtual int is_parent() const; virtual int is_widget() const; virtual int is_button() const; + virtual int is_input() const; virtual int is_valuator() const; virtual int is_spinner() const; virtual int is_menu_item() const; diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index cae00ab0c..c67bb6438 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -2162,6 +2162,17 @@ void Fl_Widget_Type::write_widget_code() { write_c("%s%s->type(%d);\n", indent(), var, o->type()); if (o->box() != tplate->box() || subclass()) write_c("%s%s->box(FL_%s);\n", indent(), var, boxname(o->box())); + if (is_input()) { + Fl_Input_* b = (Fl_Input_*)o; + if (b->shortcut()) { + int s = b->shortcut(); + if (use_FL_COMMAND && (s & (FL_CTRL|FL_META))) { + write_c("%s%s->shortcut(FL_COMMAND|0x%x);\n", indent(), var, s & ~(FL_CTRL|FL_META)); + } else { + write_c("%s%s->shortcut(0x%x);\n", indent(), var, s); + } + } + } if (is_button()) { Fl_Button* b = (Fl_Button*)o; if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var, @@ -2333,6 +2344,10 @@ void Fl_Widget_Type::write_properties() { } if (o->box() != tplate->box()) { write_string("box"); write_word(boxname(o->box()));} + if (is_input()) { + Fl_Input_* b = (Fl_Input_*)o; + if (b->shortcut()) write_string("shortcut 0x%x", b->shortcut()); + } if (is_button()) { Fl_Button* b = (Fl_Button*)o; if (b->down_box()) { @@ -2524,6 +2539,8 @@ void Fl_Widget_Type::read_property(const char *c) { subclass(read_word()); } else if (is_button() && !strcmp(c,"shortcut")) { ((Fl_Button*)o)->shortcut(strtol(read_word(),0,0)); + } else if (is_input() && !strcmp(c,"shortcut")) { + ((Fl_Input_*)o)->shortcut(strtol(read_word(),0,0)); } else { if (!strncmp(c,"code",4)) { int n = atoi(c+4); @@ -2694,6 +2711,12 @@ void Fl_Widget_Type::copy_properties() { d->value(s->value()); } + // copy all attributes specific to widgets derived from Fl_Input_ + if (is_input()) { + Fl_Input_* d = (Fl_Input_*)live_widget, *s = (Fl_Input_*)o; + d->shortcut(s->shortcut()); + } + // copy all attributes specific to Fl_Valuator and derived classes if (is_valuator()) { Fl_Valuator* d = (Fl_Valuator*)live_widget, *s = (Fl_Valuator*)o; diff --git a/fluid/factory.cxx b/fluid/factory.cxx index 78723a167..6e061cc5a 100644 --- a/fluid/factory.cxx +++ b/fluid/factory.cxx @@ -442,6 +442,7 @@ public: if (w < 15) w = 15; } virtual const char *type_name() {return "Fl_Input";} + int is_input() const {return 1;} Fl_Widget *widget(int x,int y,int w,int h) { Fl_Input *myo = new Fl_Input(x,y,w,h,"input:"); myo->value("Text Input"); @@ -455,6 +456,7 @@ public: d->textfont(s->textfont()); d->textsize(s->textsize()); d->textcolor(s->textcolor()); + d->shortcut(s->shortcut()); } }; static Fl_Input_Type Fl_Input_type; @@ -489,6 +491,7 @@ public: if (w < 50) w = 50; } virtual const char *type_name() {return "Fl_File_Input";} + int is_input() const {return 1;} Fl_Widget *widget(int x,int y,int w,int h) { Fl_File_Input *myo = new Fl_File_Input(x,y,w,h,"file:"); myo->value("/now/is/the/time/for/a/filename.ext"); @@ -788,6 +791,7 @@ public: if (w < 15) w = 15; } virtual const char *type_name() {return "Fl_Value_Input";} + int is_input() const {return 1;} int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c); int is_valuator() const {return 1;} Fl_Widget *widget(int x,int y,int w,int h) { diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx index 4d96a3150..ec45d554c 100644 --- a/src/Fl_Input_.cxx +++ b/src/Fl_Input_.cxx @@ -788,6 +788,13 @@ int Fl_Input_::handletext(int event, int X, int Y, int W, int H) { } return replace(position(), mark(), t, e-t);} + case FL_SHORTCUT: + if (!(shortcut() ? Fl::test_shortcut(shortcut()) : test_shortcut())) + return 0; + if (Fl::visible_focus() && handle(FL_FOCUS)) + Fl::focus(this); + return 1; + default: return 0; } @@ -810,6 +817,8 @@ Fl_Input_::Fl_Input_(int X, int Y, int W, int H, const char* l) value_ = ""; xscroll_ = yscroll_ = 0; maximum_size_ = 32767; + shortcut_ = 0; + set_flag(SHORTCUT_LABEL); } void Fl_Input_::put_in_buffer(int len) { diff --git a/test/input.cxx b/test/input.cxx index fd955a7c0..9131707cd 100644 --- a/test/input.cxx +++ b/test/input.cxx @@ -88,13 +88,15 @@ int main(int argc, char **argv) { // input[0]->maximum_size(20); // input[0]->static_value("this is a testgarbage"); input[1] = new Fl_Float_Input(70,y,300,30,"Float:"); y += 35; - input[1]->tooltip("Input field for floating-point number"); + input[1]->tooltip("Input field for floating-point number (F1)"); + input[1]->shortcut(FL_F+1); input[2] = new Fl_Int_Input(70,y,300,30,"Int:"); y += 35; - input[2]->tooltip("Input field for integer number"); - input[3] = new Fl_Secret_Input(70,y,300,30,"Secret:"); y += 35; - input[3]->tooltip("Input field for password"); - input[4] = new Fl_Multiline_Input(70,y,300,100,"Multiline:"); y += 105; - input[4]->tooltip("Input field for short text with newlines"); + input[2]->tooltip("Input field for integer number (F2)"); + input[2]->shortcut(FL_F+2); + input[3] = new Fl_Secret_Input(70,y,300,30,"&Secret:"); y += 35; + input[3]->tooltip("Input field for password (Alt-S)"); + input[4] = new Fl_Multiline_Input(70,y,300,100,"&Multiline:"); y += 105; + input[4]->tooltip("Input field for short text with newlines (Alt-M)"); input[4]->wrap(1); for (int i = 0; i < 4; i++) { |
