Author: matt
Date: 2010-11-14 03:02:18 -0800 (Sun, 14 Nov 2010)
New Revision: 7826
Log:
Added visual indication for buttons activated by a keyboard shortcut (STR 2372

Modified:
   branches/branch-1.3/CHANGES
   branches/branch-1.3/FL/Fl_Button.H
   branches/branch-1.3/src/Fl_Button.cxx
   branches/branch-1.3/src/Fl_Return_Button.cxx
   branches/branch-1.3/test/buttons.cxx

Modified: branches/branch-1.3/CHANGES
===================================================================
--- branches/branch-1.3/CHANGES 2010-11-13 16:47:47 UTC (rev 7825)
+++ branches/branch-1.3/CHANGES 2010-11-14 11:02:18 UTC (rev 7826)
@@ -1,5 +1,6 @@
 CHANGES IN FLTK 1.3.0
 
+       - Added visual feedback for button shortcuts (STR #2372)
        - Fixed internationalisation of menus using FLuid (STR #2246)
        - Fixed blinking of selection when the mouse was dragged 
          outside of the Fl_Text_* widget

Modified: branches/branch-1.3/FL/Fl_Button.H
===================================================================
--- branches/branch-1.3/FL/Fl_Button.H  2010-11-13 16:47:47 UTC (rev 7825)
+++ branches/branch-1.3/FL/Fl_Button.H  2010-11-14 11:02:18 UTC (rev 7826)
@@ -46,6 +46,8 @@
 
 extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
 
+class Fl_Widget_Tracker;
+
 /**
   \class Fl_Button
   \brief Buttons generate callbacks when they are clicked by the user.
@@ -88,6 +90,10 @@
 
 protected:
 
+  static Fl_Widget_Tracker *key_release_tracker;
+  static void key_release_timeout(void*);
+  void simulate_key_action();
+  
   virtual void draw();
 
 public:

Modified: branches/branch-1.3/src/Fl_Button.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Button.cxx       2010-11-13 16:47:47 UTC (rev 
7825)
+++ branches/branch-1.3/src/Fl_Button.cxx       2010-11-14 11:02:18 UTC (rev 
7826)
@@ -30,6 +30,10 @@
 #include <FL/Fl_Group.H>
 #include <FL/Fl_Window.H>
 
+
+Fl_Widget_Tracker *Fl_Button::key_release_tracker = 0;
+
+
 // There are a lot of subclasses, named Fl_*_Button.  Some of
 // them are implemented by setting the type() value and testing it
 // here.  This includes Fl_Radio_Button and Fl_Toggle_Button
@@ -156,6 +160,8 @@
       } else if (type() == FL_TOGGLE_BUTTON) {
        value(!value());
        if (when() & FL_WHEN_CHANGED) do_callback();
+      } else {
+        simulate_key_action();
       }
       if (wp.deleted()) return 1;
       if (when() & FL_WHEN_RELEASE) do_callback();
@@ -166,6 +172,33 @@
   }
 }
 
+void Fl_Button::simulate_key_action()
+{
+  if (key_release_tracker) {
+    Fl::remove_timeout(key_release_timeout, key_release_tracker);
+    key_release_timeout(key_release_tracker);
+  }
+  value(1); 
+  redraw();
+  key_release_tracker = new Fl_Widget_Tracker(this);
+  Fl::add_timeout(0.15, key_release_timeout, key_release_tracker);
+}
+
+void Fl_Button::key_release_timeout(void *d)
+{
+  Fl_Widget_Tracker *wt = (Fl_Widget_Tracker*)d;
+  if (!wt)
+    return;
+  if (wt==key_release_tracker) 
+    key_release_tracker = 0L;
+  Fl_Button *btn = (Fl_Button*)wt->widget();
+  if (btn) {
+    btn->value(0);
+    btn->redraw();
+  }
+  delete wt;
+}
+
 /**
   The constructor creates the button using the given position, size and label.
   \param[in] X, Y, W, H position and size of the widget

Modified: branches/branch-1.3/src/Fl_Return_Button.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Return_Button.cxx        2010-11-13 16:47:47 UTC 
(rev 7825)
+++ branches/branch-1.3/src/Fl_Return_Button.cxx        2010-11-14 11:02:18 UTC 
(rev 7826)
@@ -61,6 +61,7 @@
 int Fl_Return_Button::handle(int event) {
   if (event == FL_SHORTCUT &&
       (Fl::event_key() == FL_Enter || Fl::event_key() == FL_KP_Enter)) {
+    simulate_key_action();
     do_callback();
     return 1;
   } else

Modified: branches/branch-1.3/test/buttons.cxx
===================================================================
--- branches/branch-1.3/test/buttons.cxx        2010-11-13 16:47:47 UTC (rev 
7825)
+++ branches/branch-1.3/test/buttons.cxx        2010-11-14 11:02:18 UTC (rev 
7826)
@@ -39,7 +39,8 @@
 
 int main(int argc, char ** argv) {
   Fl_Window *window = new Fl_Window(320,130);
-  (new Fl_Button(10, 10, 130, 30, "Fl_Button"))->tooltip("This is a Tooltip.");
+  Fl_Button *b = new Fl_Button(10, 10, 130, 30, "Fl_Button");
+  b->tooltip("This is a Tooltip.");
   new Fl_Return_Button(150, 10, 160, 30, "Fl_Return_Button");
   new Fl_Repeat_Button(10,50,130,30,"Fl_Repeat_Button");
   new Fl_Light_Button(10,90,130,30,"Fl_Light_Button");

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to