From 3384fe93dfb08be200bfde1e488177bb650376a6 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sun, 26 Jan 2020 19:14:45 +0100 Subject: Add Fl_Widget::shortcut_label(int) to control effect of '&' in some widget labels --- FL/Fl_Button.H | 2 +- FL/Fl_Input_.H | 1 + FL/Fl_Menu_.H | 2 +- FL/Fl_Tabs.H | 2 ++ FL/Fl_Text_Display.H | 1 + FL/Fl_Value_Input.H | 1 + FL/Fl_Widget.H | 22 ++++++++++++++++++++++ 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/FL/Fl_Button.H b/FL/Fl_Button.H index 33c684962..49f5dfa4b 100644 --- a/FL/Fl_Button.H +++ b/FL/Fl_Button.H @@ -51,7 +51,7 @@ class Fl_Widget_Tracker; down, but if you have an input field in the same window, the user will have to hold down the \e Alt key so that the input field does not eat the event first as an \c FL_KEYBOARD event. - + \see Fl_Widget::shortcut_label(int) \todo Refactor the doxygen comments for Fl_Button type() documentation. For an Fl_Button object, the type() call returns one of: diff --git a/FL/Fl_Input_.H b/FL/Fl_Input_.H index c56b802b6..a07a70282 100644 --- a/FL/Fl_Input_.H +++ b/FL/Fl_Input_.H @@ -79,6 +79,7 @@ UTF-8 sequences and pointers into the middle of a sequence are undefined. \see Fl_Text_Display, Fl_Text_Editor for more powerful text handling widgets + \see Fl_Widget::shortcut_label(int) \internal When porting this widget from ASCII to UTF-8, previously legal pointers into diff --git a/FL/Fl_Menu_.H b/FL/Fl_Menu_.H index 4cca761d9..4ebfc5852 100644 --- a/FL/Fl_Menu_.H +++ b/FL/Fl_Menu_.H @@ -50,7 +50,7 @@ The line spacing between menu items can be controlled with the global setting Fl::menu_linespacing(). - + \see Fl_Widget::shortcut_label(int) */ class FL_EXPORT Fl_Menu_ : public Fl_Widget { diff --git a/FL/Fl_Tabs.H b/FL/Fl_Tabs.H index 45387b410..dd0820418 100644 --- a/FL/Fl_Tabs.H +++ b/FL/Fl_Tabs.H @@ -41,6 +41,8 @@ on the card tab, including the label font and style. The selection color of that child is used to color the tab, while the color of the child determines the background color of the pane. + '&' in labels are used to prefix a shortcut that is drawn underlined and + that activates the corresponding tab; repeated '&&' avoids that. The size of the tabs is controlled by the bounding box of the children (there should be some space between the children and diff --git a/FL/Fl_Text_Display.H b/FL/Fl_Text_Display.H index 62f8b8d68..c9b8cd321 100644 --- a/FL/Fl_Text_Display.H +++ b/FL/Fl_Text_Display.H @@ -75,6 +75,7 @@ and Fl_Text_Buffer classes. \note Line numbers were added in FLTK 1.3.3. + \see Fl_Widget::shortcut_label(int) */ class FL_EXPORT Fl_Text_Display: public Fl_Group { diff --git a/FL/Fl_Value_Input.H b/FL/Fl_Value_Input.H index e37532046..1aabe8ed7 100644 --- a/FL/Fl_Value_Input.H +++ b/FL/Fl_Value_Input.H @@ -52,6 +52,7 @@

\image html Fl_Value_Input.png \image latex Fl_Value_Input.png "Fl_Value_Input" width=4cm + \see Fl_Widget::shortcut_label(int) */ class FL_EXPORT Fl_Value_Input : public Fl_Valuator { public: diff --git a/FL/Fl_Widget.H b/FL/Fl_Widget.H index 89ca2e80f..375830f65 100644 --- a/FL/Fl_Widget.H +++ b/FL/Fl_Widget.H @@ -1042,6 +1042,28 @@ public: \deprecated Use selection_color(unsigned) instead. */ void color2(unsigned a) {color2_ = a;} + + /** Sets whether the widget's label use '&' to indicate shortcuts. + By default, all objects of classes Fl_Menu_ (and derivatives), Fl_Button (and derivatives), + Fl_Text_Display, Fl_Value_Input, and Fl_Input_ (and derivatives) + use character '&' in their label, unless '&' is repeated, + to indicate shortcuts: '&' does not appear in the drawn label, + the next character after '&' in the label is drawn underlined, and typing this character + triggers the corresponding menu window, button, or other widget. If the label contains 2 consecutive '&', + only one is drawn and the next character is not underlined and not used as a shortcut. + If \p value is set to 0, all these labels don't process character '&' as indicating a shortcut: + '&' is drawn in the label, the next character is not underlined and does not define a shortcut. + */ + void shortcut_label(int value) { + if (value) + set_flag(SHORTCUT_LABEL); + else + clear_flag(SHORTCUT_LABEL); + } + + /** Returns whether the widget's label use '&' to indicate shortcuts. + \see void shortcut_label(int value) */ + int shortcut_label() const { return flags_ & SHORTCUT_LABEL; } }; /** -- cgit v1.2.3