FLTK logo

[master] 9c55ad4 - Fixes #362

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 9c55ad4 - Fixes #362 "Greg Ercolano" Jan 13, 2022  
 
commit 9c55ad4273ff3e4327daaaf28fc06bf6bbd4a645
Author:     Greg Ercolano <erco@seriss.com>
AuthorDate: Thu Jan 13 15:26:27 2022 -0800
Commit:     Greg Ercolano <erco@seriss.com>
CommitDate: Thu Jan 13 15:26:27 2022 -0800

    Fixes #362

 FL/Fl_Input_Choice.H               |   2 ++
 documentation/src/input_choice.jpg | Bin 14814 -> 0 bytes
 documentation/src/input_choice.png | Bin 0 -> 16484 bytes
 src/Fl_Input_Choice.cxx            |  54 +++++++++++++++++++++++++++++++++++--
 4 files changed, 54 insertions(+), 2 deletions(-)

diff --git FL/Fl_Input_Choice.H FL/Fl_Input_Choice.H
index 56fdd10..c02195b 100644
--- FL/Fl_Input_Choice.H
+++ FL/Fl_Input_Choice.H
@@ -45,8 +45,10 @@ class FL_EXPORT Fl_Input_Choice : public Fl_Group {
   // Private class to handle slightly 'special' behavior of menu button
   class InputMenuButton : public Fl_Menu_Button {
     void draw();
+    const Fl_Menu_Item* popup();
   public:
     InputMenuButton(int X, int Y, int W, int H, const char *L=0);
+    int handle(int e);
   };
 
   Fl_Input *inp_;
diff --git documentation/src/input_choice.jpg documentation/src/input_choice.jpg
deleted file mode 100644
index 7600b1c..0000000
Binary files documentation/src/input_choice.jpg and /dev/null differ
diff --git documentation/src/input_choice.png documentation/src/input_choice.png
new file mode 100644
index 0000000..42cd6e7
Binary files /dev/null and documentation/src/input_choice.png differ
diff --git src/Fl_Input_Choice.cxx src/Fl_Input_Choice.cxx
index bf52360..781e822 100644
--- src/Fl_Input_Choice.cxx
+++ src/Fl_Input_Choice.cxx
@@ -32,8 +32,8 @@
 
   \brief A combination of the input widget and a menu button.
 
-  \image html input_choice.jpg
-  \image latex input_choice.jpg "Fl_Input_Choice widget" width=6cm
+  \image html input_choice.png
+  \image latex input_choice.png "Fl_Input_Choice widget" width=6cm
 
   The user can either type into the input area, or use the
   menu button chooser on the right to choose an item which loads
@@ -142,6 +142,56 @@ void Fl_Input_Choice::InputMenuButton::draw() {
   if (Fl::focus() == this) draw_focus();
 }
 
+// Make pulldown menu appear under entire width of widget
+const Fl_Menu_Item* Fl_Input_Choice::InputMenuButton::popup() {
+  menu_end();
+  redraw();
+  Fl_Widget_Tracker mb(this);
+  // Make menu appear under entire width of Fl_Input_Choice parent group
+  const Fl_Menu_Item *m = menu()->pulldown(parent()->x(), y(), parent()->w(), h(), 0, this);
+  picked(m);
+  if (mb.exists()) redraw();
+  return m;
+}
+
+// Invokes our popup() method to ensure pulldown menu appears full width under widget
+//    (This is the same handle() code in Fl_Menu_Button and Fl_Choice)
+//
+int Fl_Input_Choice::InputMenuButton::handle(int e) {
+  if (!menu() || !menu()->text) return 0;
+  switch (e) {
+  case FL_ENTER: /* FALLTHROUGH */
+  case FL_LEAVE:
+    return (box() && !type()) ? 1 : 0;
+  case FL_PUSH:
+    if (!box()) {
+      if (Fl::event_button() != 3) return 0;
+    } else if (type()) {
+      if (!(type() & (1 << (Fl::event_button()-1)))) return 0;
+    }
+    if (Fl::visible_focus()) Fl::focus(this);
+    popup();
+    return 1;
+  case FL_KEYBOARD:
+    if (!box()) return 0;
+    if (Fl::event_key() == ' ' &&
+        !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
+      popup();
+      return 1;
+    } else return 0;
+  case FL_SHORTCUT:
+    if (Fl_Widget::test_shortcut()) {popup(); return 1;}
+    return test_shortcut() != 0;
+  case FL_FOCUS: /* FALLTHROUGH */
+  case FL_UNFOCUS:
+    if (box() && Fl::visible_focus()) {
+      redraw();
+      return 1;
+    }
+  default:
+    return 0;
+  }
+}
 
 /** Callback for the Fl_Input_Choice menu. */
 
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.