mirror of
https://github.com/fltk/fltk.git
synced 2026-06-04 23:42:15 +08:00
Added visual indication for buttons activated by a keyboard shortcut (STR 2372
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7826 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 @@ class FL_EXPORT Fl_Button : public Fl_Widget {
|
||||
|
||||
protected:
|
||||
|
||||
static Fl_Widget_Tracker *key_release_tracker;
|
||||
static void key_release_timeout(void*);
|
||||
void simulate_key_action();
|
||||
|
||||
virtual void draw();
|
||||
|
||||
public:
|
||||
|
||||
@@ -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 @@ int Fl_Button::handle(int event) {
|
||||
} 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 @@ int Fl_Button::handle(int event) {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -61,6 +61,7 @@ void Fl_Return_Button::draw() {
|
||||
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
|
||||
|
||||
+2
-1
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user