aboutsummaryrefslogtreecommitdiff
path: root/src/dialog.cc
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2011-09-25 20:11:35 +0000
committercorvid <corvid@lavabit.com>2011-09-25 20:11:35 +0000
commitc30e88ff95eb09b4fc6a2939d62d51ae3f0ef708 (patch)
tree2433f7435bdd32a61bbb33afd4dbe7bfce3bae35 /src/dialog.cc
parentf5c87d5d8f0bea64c867c42f994225a59b0c42be (diff)
let the enter key trigger buttons when possible
Topic brought up by Alexander recently. In FLTK2, Enter and Space would both trigger buttons. In 1.3, only Space does it. I asked the FLTK guys about this, and I learned that Space to trigger buttons is actually old-school X behaviour that I somehow never became aware of.
Diffstat (limited to 'src/dialog.cc')
-rw-r--r--src/dialog.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/dialog.cc b/src/dialog.cc
index 15e5d7a9..f830f2d3 100644
--- a/src/dialog.cc
+++ b/src/dialog.cc
@@ -95,6 +95,24 @@ public:
};
};
+class EnterButton : public Fl_Button {
+public:
+ EnterButton (int x,int y,int w,int h, const char* label = 0) :
+ Fl_Button (x,y,w,h,label) {};
+ int handle(int e);
+};
+
+int EnterButton::handle(int e)
+{
+ if (e == FL_KEYBOARD && Fl::focus() == this && Fl::event_key() == FL_Enter){
+ set_changed();
+ simulate_key_action();
+ do_callback();
+ return 1;
+ }
+ return Fl_Button::handle(e);
+}
+
//----------------------------------------------------------------------------
@@ -354,7 +372,7 @@ int a_Dialog_choice5(const char *QuestionTxt,
bw = (ww - gap)/nb - gap;
xpos += gap;
for (int i=1; i <= nb; ++i) {
- b = new Fl_Button(xpos, wh-bh, bw, bh, txt[i]);
+ b = new EnterButton(xpos, wh-bh, bw, bh, txt[i]);
b->align(FL_ALIGN_WRAP|FL_ALIGN_CLIP);
b->box(FL_UP_BOX);
b->callback(choice5_cb, INT2VOIDP(i));
@@ -426,14 +444,14 @@ int a_Dialog_user_password(const char *message, UserPasswordCB cb, void *vp)
/* "OK" button */
y += input_h + 20;
- Fl_Button *ok_button = new Fl_Button(200, y, 50, button_h, "OK");
+ Fl_Button *ok_button = new EnterButton(200, y, 50, button_h, "OK");
ok_button->labelsize(14);
ok_button->callback(Dialog_user_password_cb);
window->add(ok_button);
/* "Cancel" button */
Fl_Button *cancel_button =
- new Fl_Button(50, y, 100, button_h, "Cancel");
+ new EnterButton(50, y, 100, button_h, "Cancel");
cancel_button->labelsize(14);
cancel_button->callback(Dialog_user_password_cb);
window->add(cancel_button);