diff options
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | FL/Fl_Text_Display.H | 5 | ||||
| -rw-r--r-- | FL/Fl_Value_Input.H | 3 | ||||
| -rw-r--r-- | documentation/Fl_Text_Editor.html | 6 | ||||
| -rw-r--r-- | documentation/Fl_Value_Input.html | 18 | ||||
| -rw-r--r-- | fluid/Fl_Menu_Type.cxx | 26 | ||||
| -rw-r--r-- | fluid/Fl_Type.cxx | 2 | ||||
| -rw-r--r-- | fluid/Fl_Type.h | 2 | ||||
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 62 | ||||
| -rw-r--r-- | fluid/factory.cxx | 3 | ||||
| -rw-r--r-- | src/Fl_Text_Display.cxx | 10 | ||||
| -rw-r--r-- | src/Fl_Text_Editor.cxx | 7 | ||||
| -rw-r--r-- | src/Fl_Value_Input.cxx | 3 |
13 files changed, 121 insertions, 29 deletions
@@ -1,6 +1,7 @@ CHANGES IN FLTK 1.3.0 - - added support for shortcuts for Fl_Input_ derived + - added support for shortcuts for Fl_Input_, + Fl_Value_Input, and Fl_Text_Display derived widgets (STR #1770) - initial setup (STR #1904) diff --git a/FL/Fl_Text_Display.H b/FL/Fl_Text_Display.H index 7e94ef001..fa7f0d0c4 100644 --- a/FL/Fl_Text_Display.H +++ b/FL/Fl_Text_Display.H @@ -119,6 +119,9 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group { int position_style(int lineStartPos, int lineLen, int lineIndex, int dispIndex); + 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_;} @@ -280,6 +283,8 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group { int display_insert_position_hint; struct { int x, y, w, h; } text_area; + int shortcut_; + uchar textfont_; uchar textsize_; unsigned textcolor_; diff --git a/FL/Fl_Value_Input.H b/FL/Fl_Value_Input.H index 5f29dd155..3e0110040 100644 --- a/FL/Fl_Value_Input.H +++ b/FL/Fl_Value_Input.H @@ -47,6 +47,9 @@ public: void soft(char s) {soft_ = s;} char soft() const {return soft_;} + int shortcut() const {return input.shortcut();} + void shortcut(int s) {input.shortcut(s);} + Fl_Font textfont() const {return input.textfont();} void textfont(uchar s) {input.textfont(s);} uchar textsize() const {return input.textsize();} diff --git a/documentation/Fl_Text_Editor.html b/documentation/Fl_Text_Editor.html index 2714fb103..ced3ac968 100644 --- a/documentation/Fl_Text_Editor.html +++ b/documentation/Fl_Text_Editor.html @@ -78,6 +78,7 @@ class. <LI><A HREF="#Fl_Text_Editor.kf_up">kf_up</A></LI> <LI><A HREF="#Fl_Text_Editor.remove_all_key_bindings">remove_all_key_bindings</A></LI> <LI><A HREF="#Fl_Text_Editor.remove_key_binding">remove_key_binding</A></LI> + <LI><A href="#Fl_Text_Editor.shortcut">shortcut</A></LI> </UL></TD></TR> </TABLE> @@ -217,5 +218,10 @@ void remove_key_binding(int key, int state);</A></H4> <P>Removes a single key binding from the text editor or list. +<H4><A name="Fl_Text_Editor.shortcut">ulong Fl_Text_Editor::shortcut() const +<BR> void Fl_Text_Editor::shortcut(ulong key)</A></H4> + The first form returns the current shortcut key for the editor. +<P>The second form sets the shortcut key to <TT>key</TT>. + </BODY> </HTML> diff --git a/documentation/Fl_Value_Input.html b/documentation/Fl_Value_Input.html index 3495d565c..aeecc89fe 100644 --- a/documentation/Fl_Value_Input.html +++ b/documentation/Fl_Value_Input.html @@ -59,6 +59,7 @@ ALT="Fl_Value_Input widget."></P> <LI><A href="#Fl_Value_Input.Fl_Value_Input">Fl_Value_Input</A></LI> <LI><A href="#Fl_Value_Input.~Fl_Value_Input">~Fl_Value_Input</A></LI> <LI><A href="#Fl_Value_Input.cursor_color">cursor_color</A></LI> + <LI><A href="#Fl_Value_Input.shortcut">shortcut</A></LI> <LI><A href="#Fl_Value_Input.soft">soft</A></LI> <LI><A href="#Fl_Value_Input.textcolor">textcolor</A></LI> <LI><A href="#Fl_Value_Input.textfont">textfont</A></LI> @@ -85,6 +86,23 @@ void Fl_Value_Input::cursor_color(Fl_Color)</A></H4> <P>Get or set the color of the text cursor. The text cursor is black by default. +<H4><A name="Fl_Value_Input.shortcut">ulong Fl_Value_Input::shortcut() const +<BR> void Fl_Value_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_Value_Input.soft">uchar Fl_Value_Input::soft() const<BR> void Fl_Value_Input::soft(uchar)</A></H4> diff --git a/fluid/Fl_Menu_Type.cxx b/fluid/Fl_Menu_Type.cxx index 8055bf312..9cf128c50 100644 --- a/fluid/Fl_Menu_Type.cxx +++ b/fluid/Fl_Menu_Type.cxx @@ -37,6 +37,8 @@ #include <FL/fl_message.H> #include <FL/Fl_Menu_.H> #include <FL/Fl_Button.H> +#include <FL/Fl_Value_Input.H> +#include <FL/Fl_Text_Display.H> #include "../src/flstring.h" #include <stdio.h> #include <stdlib.h> @@ -589,14 +591,19 @@ int Shortcut_Button::handle(int e) { void shortcut_in_cb(Shortcut_Button* i, void* v) { if (v == LOAD) { - if ( !current_widget->is_button() && !current_widget->is_input() ) { - i->hide(); return; - } - i->show(); 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(); + else if (current_widget->is_value_input()) + i->svalue = ((Fl_Value_Input*)(current_widget->o))->shortcut(); + else if (current_widget->is_text_display()) + i->svalue = ((Fl_Text_Display*)(current_widget->o))->shortcut(); + else { + i->hide(); + return; + } + i->show(); i->redraw(); } else { int mod = 0; @@ -606,11 +613,18 @@ void shortcut_in_cb(Shortcut_Button* i, void* v) { if (b->shortcut()!=i->svalue) mod = 1; b->shortcut(i->svalue); if (o->is_menu_item()) ((Fl_Widget_Type*)o)->redraw(); - } - else if (o->selected && o->is_input()) { + } 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); + } else if (o->selected && o->is_value_input()) { + Fl_Value_Input* b = (Fl_Value_Input*)(((Fl_Widget_Type*)o)->o); + if (b->shortcut()!=i->svalue) mod = 1; + b->shortcut(i->svalue); + } else if (o->selected && o->is_text_display()) { + Fl_Text_Display* b = (Fl_Text_Display*)(((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 621650f82..1ce2fb99f 100644 --- a/fluid/Fl_Type.cxx +++ b/fluid/Fl_Type.cxx @@ -629,6 +629,8 @@ 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_value_input() const {return 0;} +int Fl_Type::is_text_display() 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 04c159c13..a3bf02490 100644 --- a/fluid/Fl_Type.h +++ b/fluid/Fl_Type.h @@ -132,6 +132,8 @@ public: virtual int is_widget() const; virtual int is_button() const; virtual int is_input() const; + virtual int is_value_input() const; + virtual int is_text_display() 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 c67bb6438..e1213008a 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -2162,30 +2162,26 @@ 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); - } - } + + // write shortcut command if needed + int shortcut = 0; + if (is_button()) shortcut = ((Fl_Button*)o)->shortcut(); + else if (is_input()) shortcut = ((Fl_Input_*)o)->shortcut(); + else if (is_value_input()) shortcut = ((Fl_Value_Input*)o)->shortcut(); + else if (is_text_display()) shortcut = ((Fl_Text_Display*)o)->shortcut(); + if (shortcut) { + if (use_FL_COMMAND && (shortcut & (FL_CTRL|FL_META))) { + write_c("%s%s->shortcut(FL_COMMAND|0x%x);\n", indent(), var, shortcut & ~(FL_CTRL|FL_META)); + } else { + write_c("%s%s->shortcut(0x%x);\n", indent(), var, shortcut); + } } + if (is_button()) { Fl_Button* b = (Fl_Button*)o; if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var, boxname(b->down_box())); if (b->value()) write_c("%s%s->value(1);\n", indent(), var); - 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); - } - } } else if (!strcmp(type_name(), "Fl_Input_Choice")) { Fl_Input_Choice* b = (Fl_Input_Choice*)o; if (b->down_box()) write_c("%s%s->down_box(FL_%s);\n", indent(), var, @@ -2348,6 +2344,14 @@ void Fl_Widget_Type::write_properties() { Fl_Input_* b = (Fl_Input_*)o; if (b->shortcut()) write_string("shortcut 0x%x", b->shortcut()); } + if (is_value_input()) { + Fl_Value_Input* b = (Fl_Value_Input*)o; + if (b->shortcut()) write_string("shortcut 0x%x", b->shortcut()); + } + if (is_text_display()) { + Fl_Text_Display* b = (Fl_Text_Display*)o; + if (b->shortcut()) write_string("shortcut 0x%x", b->shortcut()); + } if (is_button()) { Fl_Button* b = (Fl_Button*)o; if (b->down_box()) { @@ -2537,10 +2541,12 @@ void Fl_Widget_Type::read_property(const char *c) { hotspot(1); } else if (!strcmp(c,"class")) { 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 (!strcmp(c,"shortcut")) { + int shortcut = strtol(read_word(),0,0); + if (is_button()) ((Fl_Button*)o)->shortcut(shortcut); + else if (is_input()) ((Fl_Input_*)o)->shortcut(shortcut); + else if (is_value_input()) ((Fl_Value_Input*)o)->shortcut(shortcut); + else if (is_text_display()) ((Fl_Text_Display*)o)->shortcut(shortcut); } else { if (!strncmp(c,"code",4)) { int n = atoi(c+4); @@ -2717,6 +2723,18 @@ void Fl_Widget_Type::copy_properties() { d->shortcut(s->shortcut()); } + // copy all attributes specific to widgets derived from Fl_Value_Input + if (is_value_input()) { + Fl_Value_Input* d = (Fl_Value_Input*)live_widget, *s = (Fl_Value_Input*)o; + d->shortcut(s->shortcut()); + } + + // copy all attributes specific to widgets derived from Fl_Text_Display + if (is_text_display()) { + Fl_Text_Display* d = (Fl_Text_Display*)live_widget, *s = (Fl_Text_Display*)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 ab1da8781..5e08c4ba1 100644 --- a/fluid/factory.cxx +++ b/fluid/factory.cxx @@ -533,6 +533,7 @@ public: if (w < 50) w = 50; } virtual const char *type_name() {return "Fl_Text_Display";} + int is_text_display() const {return 1;} Fl_Widget *widget(int x,int y,int w,int h) { Fl_Text_Display *myo = new Fl_Text_Display(x,y,w,h); return myo; @@ -573,6 +574,7 @@ public: if (w < 50) w = 50; } virtual const char *type_name() {return "Fl_Text_Editor";} + int is_text_display() const {return 1;} Fl_Widget *widget(int x,int y,int w,int h) { Fl_Text_Editor *myo = new Fl_Text_Editor(x,y,w,h); return myo; @@ -793,6 +795,7 @@ public: virtual const char *type_name() {return "Fl_Value_Input";} int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c); int is_valuator() const {return 1;} + int is_value_input() const {return 1;} Fl_Widget *widget(int x,int y,int w,int h) { Fl_Value_Input *myo = new Fl_Value_Input(x,y,w,h,"value:"); return myo; diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index 5ae5f6ff2..e0f26e01c 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -85,12 +85,14 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l) damage_range2_start = damage_range2_end = -1; dragPos = dragType = dragging = 0; display_insert_position_hint = 0; + shortcut_ = 0; color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR); box(FL_DOWN_FRAME); textsize((uchar)FL_NORMAL_SIZE); textcolor(FL_FOREGROUND_COLOR); textfont(FL_HELVETICA); + set_flag(SHORTCUT_LABEL); text_area.x = 0; text_area.y = 0; @@ -3261,6 +3263,14 @@ int Fl_Text_Display::handle(int event) { if (mHScrollBar->handle(event)) return 1; break; + + 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; + } return 0; diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx index c26532906..6cfc0240d 100644 --- a/src/Fl_Text_Editor.cxx +++ b/src/Fl_Text_Editor.cxx @@ -482,6 +482,13 @@ int Fl_Text_Editor::handle(int event) { return 1; } break; + + 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; } return Fl_Text_Display::handle(event); diff --git a/src/Fl_Value_Input.cxx b/src/Fl_Value_Input.cxx index d3f5c6e61..d6dc6ab22 100644 --- a/src/Fl_Value_Input.cxx +++ b/src/Fl_Value_Input.cxx @@ -106,6 +106,8 @@ int Fl_Value_Input::handle(int event) { return 1; case FL_FOCUS: return input.take_focus(); + case FL_SHORTCUT: + return input.handle(event); default: DEFAULT: input.type(((step() - floor(step()))>0.0 || step() == 0.0) ? FL_FLOAT_INPUT : FL_INT_INPUT); @@ -126,6 +128,7 @@ Fl_Value_Input::Fl_Value_Input(int X, int Y, int W, int H, const char* l) selection_color(input.selection_color()); align(FL_ALIGN_LEFT); value_damage(); + set_flag(SHORTCUT_LABEL); } // |
