DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2753
Version: 1.3-feature


Option to enable a button to capture enter keys as a button click when it
has input focus.  This ensures that any other widget with a Fl_Enter type
shortcut does not get clicked instead.  Consistant with the way Windows
works.


Link: http://www.fltk.org/str.php?L2753
Version: 1.3-feature
Index: FL/Fl_Button.H
===================================================================
--- FL/Fl_Button.H      (revision 9157)
+++ FL/Fl_Button.H      (working copy)
@@ -78,8 +78,10 @@
   char value_;
   char oldval;
   uchar down_box_;
+  char flags_ex_;
 
 protected:
+  static const int FLAG_EX_CLICK_ON_ENTER_KEY=1;  // cause normal button press 
when enter pressed
 
   static Fl_Widget_Tracker *key_release_tracker;
   static void key_release_timeout(void*);
@@ -162,6 +164,12 @@
 
   /// (for backwards compatibility)
   void down_color(unsigned c) {selection_color(c);}
+
+  /// option for enter to cause button click when a normal button has kb focus
+  void enable_click_on_enter_key() { flags_ex_|=FLAG_EX_CLICK_ON_ENTER_KEY; };
+  void disable_click_on_enter_key() { flags_ex_&=~FLAG_EX_CLICK_ON_ENTER_KEY; 
};
+  bool using_click_on_enter_key() { return (flags_ex_ & 
FLAG_EX_CLICK_ON_ENTER_KEY)!=0; };
+
 };
 
 #endif
Index: src/Fl_Button.cxx
===================================================================
--- src/Fl_Button.cxx   (revision 9157)
+++ src/Fl_Button.cxx   (working copy)
@@ -140,7 +140,9 @@
       return 1;
     } else return 0;
   case FL_KEYBOARD :
-    if (Fl::focus() == this && Fl::event_key() == ' ' &&
+    if (Fl::focus() == this &&
+        (Fl::event_key() == ' ' ||
+         (type()==FL_NORMAL_BUTTON && (Fl::event_key()==FL_Enter || 
Fl::event_key()==FL_KP_Enter) && using_click_on_enter_key())) &&
         !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT | FL_META))) {
       set_changed();
     triggered_by_keyboard:
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to