diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-08-13 14:32:31 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-08-13 14:32:41 +0200 |
| commit | 5e484524c8713697182cf50e303ecc4305f60bd4 (patch) | |
| tree | 740dc4883ca921a40fb64fc2fb59f6d61ed85181 | |
| parent | 17d0a4cc5f88ebfc4d86b978aa5a93d0afd31d54 (diff) | |
Fl_Tabs now supports horizontal mouse wheel events.
| -rw-r--r-- | FL/Fl_Tabs.H | 2 | ||||
| -rw-r--r-- | src/Fl_Tabs.cxx | 85 | ||||
| -rw-r--r-- | test/tabs.fl | 8 |
3 files changed, 72 insertions, 23 deletions
diff --git a/FL/Fl_Tabs.H b/FL/Fl_Tabs.H index 278e1a437..d625e7614 100644 --- a/FL/Fl_Tabs.H +++ b/FL/Fl_Tabs.H @@ -248,6 +248,8 @@ protected: virtual void draw_tab(int x1, int x2, int W, int H, Fl_Widget* o, int flags, int sel); virtual int tab_height(); virtual int hit_close(Fl_Widget *o, int event_x, int event_y); + virtual int hit_overflow_menu(int event_x, int event_y); + virtual int hit_tabs_area(int event_x, int event_y); void draw() FL_OVERRIDE; diff --git a/src/Fl_Tabs.cxx b/src/Fl_Tabs.cxx index 82fffad52..2efc337f0 100644 --- a/src/Fl_Tabs.cxx +++ b/src/Fl_Tabs.cxx @@ -211,7 +211,7 @@ Fl_Widget *Fl_Tabs::which(int event_x, int event_y) { \param o check the tab of this widget \param event_x, event_y event coordinatese - \return 1 if we hit the close button, and 0 otherwie + \return 1 if we hit the close button, and 0 otherwise */ int Fl_Tabs::hit_close(Fl_Widget *o, int event_x, int event_y) { (void)event_y; @@ -229,6 +229,46 @@ int Fl_Tabs::hit_close(Fl_Widget *o, int event_x, int event_y) { return 0; } +/** Determine if the coordinates are in the area of the overflow menu button. + + \param event_x, event_y event coordinatese + \return 1 if we hit the overflow menu button, and 0 otherwise + */ +int Fl_Tabs::hit_overflow_menu(int event_x, int event_y) { + if (!has_overflow_menu) + return 0; + int H = tab_height(); + if (event_x < x()+w()-abs(H)) + return 0; + if (H >= 0) { + if (event_y > y()+H) + return 0; + } else { + if (event_y < y()+h()+H) + return 0; + } + return 1; +} + +/** Determine if the coordinates are within the tabs area. + + \param event_x, event_y event coordinatese + \return 1 if we hit the tabs area, and 0 otherwise + */ +int Fl_Tabs::hit_tabs_area(int event_x, int event_y) { + int H = tab_height(); + if (H >= 0) { + if (event_y > y()+H) + return 0; + } else { + if (event_y < y()+h()+H) + return 0; + } + if (has_overflow_menu && event_x > x()+w()-abs(H)) + return 0; + return 1; +} + void Fl_Tabs::check_overflow_menu() { int nc = children(); int H = tab_height(); if (H < 0) H = -H; @@ -314,28 +354,35 @@ int Fl_Tabs::handle(int event) { switch (event) { + case FL_MOUSEWHEEL: + if ( ( (overflow_type == OVERFLOW_DRAG) || (overflow_type == OVERFLOW_PULLDOWN) ) + && hit_tabs_area(Fl::event_x(), Fl::event_y()) ) { + int original_tab_offset = tab_offset; + tab_offset -= 2 * Fl::event_dx(); + if (tab_offset > 0) + tab_offset = 0; + int m = 0; + if (overflow_type == OVERFLOW_PULLDOWN) m = abs(tab_height()); + int dw = tab_pos[children()] + tab_offset - w(); + if (dw < -m) + tab_offset -= dw+m; + if (tab_offset != original_tab_offset) { + damage(FL_DAMAGE_EXPOSE|FL_DAMAGE_SCROLL); + redraw(); + } + return 1; + } + return Fl_Group::handle(event); case FL_PUSH: initial_x = Fl::event_x(); initial_tab_offset = tab_offset; forward_motion_to_group = 0; - { - int H = tab_height(); - if (H >= 0) { - if (Fl::event_y() > y()+H) { - forward_motion_to_group = 1; - return Fl_Group::handle(event); - } - } else { - if (Fl::event_y() < y()+h()+H) { - forward_motion_to_group = 1; - return Fl_Group::handle(event); - } - H = - H; - } - if (has_overflow_menu && Fl::event_x() > x()+w()-H) { - handle_overflow_menu(); - return 1; - } + if (hit_overflow_menu(Fl::event_x(), Fl::event_y())) { + handle_overflow_menu(); + return 1; + } + if (!hit_tabs_area(Fl::event_x(), Fl::event_y())) { + forward_motion_to_group = 1; } /* FALLTHROUGH */ case FL_DRAG: diff --git a/test/tabs.fl b/test/tabs.fl index ec8d4871c..56aec468b 100644 --- a/test/tabs.fl +++ b/test/tabs.fl @@ -17,7 +17,7 @@ Function {} {open label {class Fl_Tabs} xywh {95 0 130 35} labeltype ENGRAVED_LABEL labelfont 1 } - Fl_Tabs tabs_group {open selected + Fl_Tabs tabs_group {open tooltip {the various index cards test different aspects of the Fl_Tabs widget} xywh {10 35 315 260} selection_color 4 labelcolor 7 resizable code0 {// tabs_group->handle_overflow(Fl_Tabs::OVERFLOW_PULLDOWN);} } { @@ -164,8 +164,8 @@ Function {} {open } } Fl_Group {} { - label tab2 - tooltip {tab2 tests among other things the cooperation of modal windows and tabs} xywh {330 60 320 235} selection_color 2 hide + label tab2 selected + tooltip {tab2 tests among other things the cooperation of modal windows and tabs} xywh {330 60 320 235} selection_color 2 } { Fl_Button {} { label button1 @@ -225,7 +225,7 @@ Function {} {open } Fl_Group {} { label { tab5 } open - tooltip {tab5 verifies if visibility requests are handled correctly} xywh {330 60 320 235} labeltype ENGRAVED_LABEL + tooltip {tab5 verifies if visibility requests are handled correctly} xywh {330 60 320 235} labeltype ENGRAVED_LABEL hide } { Fl_Button {} { label button2 |
