findbar behaviour
"corvid" <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <20121225190826.GA7060@local> |
When I want to change the case-sensitivity of a search, I don't like having to switch to the mouse and aim it toward the little checkbox. So I looked up why we disable tabbing to the other widgets (and found nothing). Then a little experimentation showed that triggering shortcuts causes widgets to get focus, which we don't want. With that answered, I tried letting the input do its own callbacks upon Enter or Shift-Enter, and letting everything accept focus. This isn't heavily tested, but I wanted to see how the idea goes over first... _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
findbar_keyboard.diff
(text/plain, 3.3 KB)
diff -r 16a868705112 src/findbar.cc
--- a/src/findbar.cc Tue Dec 25 18:24:12 2012 +0000
+++ b/src/findbar.cc Tue Dec 25 18:56:23 2012 +0000
@@ -63,6 +63,32 @@
return ret;
}
+class EnterCustButton : public CustButton {
+public:
+ EnterCustButton (int x,int y,int w,int h, const char* label = 0) :
+ CustButton (x,y,w,h,label) {};
+ int handle(int e);
+};
+
+int EnterCustButton::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 CustButton::handle(e);
+}
+
+void Findbar::input_cb(Fl_Widget *w, void *vfb)
+{
+ if (Fl::event_shift())
+ searchBackwards_cb(w, vfb);
+ else
+ search_cb(w, vfb);
+}
+
/*
* Find next occurrence of input key
*/
@@ -131,25 +157,22 @@
i = new MyInput(x, border, input_width, height);
x += input_width + gap;
resizable(i);
+ i->callback(input_cb, this);
i->color(206);
- i->when(FL_WHEN_NEVER);
+ i->when(FL_WHEN_ENTER_KEY_ALWAYS);
add(i);
- next_btn = new CustButton(x, border, button_width, height, "Next");
+ next_btn = new EnterCustButton(x, border, button_width, height, "Next");
x += button_width + gap;
- next_btn->shortcut(FL_Enter);
next_btn->callback(search_cb, this);
- next_btn->clear_visible_focus();
next_btn->box(FL_THIN_UP_BOX);
next_btn->set_tooltip("Find next occurrence of the search phrase\n"
"shortcut: Enter");
add(next_btn);
- prev_btn= new CustButton(x, border, button_width, height, "Previous");
+ prev_btn= new EnterCustButton(x, border, button_width, height, "Previous");
x += button_width + gap;
- prev_btn->shortcut(FL_SHIFT+FL_Enter);
prev_btn->callback(searchBackwards_cb, this);
- prev_btn->clear_visible_focus();
prev_btn->box(FL_THIN_UP_BOX);
prev_btn->set_tooltip("Find previous occurrence of the search phrase\n"
"shortcut: Shift+Enter");
@@ -158,7 +181,6 @@
check_btn = new Fl_Check_Button(x, border, 2*button_width, height,
"Case-sensitive");
x += 2 * button_width + gap;
- check_btn->clear_visible_focus();
add(check_btn);
}
@@ -176,9 +198,20 @@
int k = Fl::event_key();
unsigned modifier = Fl::event_state() & (FL_SHIFT| FL_CTRL| FL_ALT|FL_META);
- if (event == FL_KEYBOARD && modifier == 0 && k == FL_Escape) {
- /* let the UI handle it */
- return 0;
+ if (event == FL_KEYBOARD) {
+ if (k == FL_Escape && modifier == 0) {
+ /* let the UI handle it */
+ return 0;
+ } else if (k == FL_Tab) {
+ if (Fl_Group::handle(event) == 0) {
+ // make focus cycle around
+ if (Fl::event_shift())
+ check_btn->take_focus();
+ else
+ i->take_focus();
+ }
+ return 1;
+ }
}
return Fl_Group::handle(event);
diff -r 16a868705112 src/findbar.hh
--- a/src/findbar.hh Tue Dec 25 18:24:12 2012 +0000
+++ b/src/findbar.hh Tue Dec 25 18:56:23 2012 +0000
@@ -19,6 +19,7 @@
Fl_Pixmap *hideImg;
Fl_Input *i;
+ static void input_cb (Fl_Widget *, void *);
static void search_cb (Fl_Widget *, void *);
static void searchBackwards_cb (Fl_Widget *, void *);
static void hide_cb (Fl_Widget *, void *);