mirror of
https://github.com/fltk/fltk.git
synced 2026-05-30 21:25:30 +08:00
Fixes #362
This commit is contained in:
@@ -45,8 +45,10 @@ class FL_EXPORT Fl_Input_Choice : public Fl_Group {
|
|||||||
// Private class to handle slightly 'special' behavior of menu button
|
// Private class to handle slightly 'special' behavior of menu button
|
||||||
class InputMenuButton : public Fl_Menu_Button {
|
class InputMenuButton : public Fl_Menu_Button {
|
||||||
void draw();
|
void draw();
|
||||||
|
const Fl_Menu_Item* popup();
|
||||||
public:
|
public:
|
||||||
InputMenuButton(int X, int Y, int W, int H, const char *L=0);
|
InputMenuButton(int X, int Y, int W, int H, const char *L=0);
|
||||||
|
int handle(int e);
|
||||||
};
|
};
|
||||||
|
|
||||||
Fl_Input *inp_;
|
Fl_Input *inp_;
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
+52
-2
@@ -32,8 +32,8 @@
|
|||||||
|
|
||||||
\brief A combination of the input widget and a menu button.
|
\brief A combination of the input widget and a menu button.
|
||||||
|
|
||||||
\image html input_choice.jpg
|
\image html input_choice.png
|
||||||
\image latex input_choice.jpg "Fl_Input_Choice widget" width=6cm
|
\image latex input_choice.png "Fl_Input_Choice widget" width=6cm
|
||||||
|
|
||||||
The user can either type into the input area, or use the
|
The user can either type into the input area, or use the
|
||||||
menu button chooser on the right to choose an item which loads
|
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();
|
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. */
|
/** Callback for the Fl_Input_Choice menu. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user