Skip to content

Commit f1345cd

Browse files
committed
Added support for event filtering for automatic hide of overlay
1 parent bf719ba commit f1345cd

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

include/lsp-plug.in/tk/widgets/containers/Overlay.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ namespace lsp
6060
*/
6161
typedef bool (*overlay_position_t)(ws::rectangle_t *rect, Overlay *overlay, void *data);
6262

63+
/**
64+
* Function for filtering events on automatic overlay hide
65+
* @param ev the event for filtering
66+
* @param overlay overlay that triggered the filtering
67+
* @param data supplementary data
68+
* @return true on success execution
69+
*/
70+
typedef bool (*overlay_filter_t)(const ws::event_t *ev, Overlay *overlay, void *data);
71+
6372
/**
6473
* Overlayment, implements a single widget container that Overlays the child widget
6574
* according to the layout settings. The container ignores allocation() property
@@ -91,7 +100,10 @@ namespace lsp
91100
prop::Padding sIPadding; // Internal padding
92101

93102
overlay_position_t pPosFunc; // Position calculation function
94-
void *pPosData; // Position data function
103+
void *pPosData; // Position function data
104+
105+
overlay_filter_t pFilterFunc; // Event filter function
106+
void *pFilterData; // Event filter data
95107

96108
protected:
97109
void do_destroy();
@@ -152,7 +164,9 @@ namespace lsp
152164

153165
public:
154166
void set_position_function(overlay_position_t func, void *data = NULL);
167+
void set_filter_function(overlay_filter_t func, void *data = NULL);
155168
bool calculate_position(ws::rectangle_t *rect);
169+
bool filter_event(const ws::event_t *ev);
156170
};
157171

158172
} /* namespace tk */

include/lsp-plug.in/tk/widgets/containers/Window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace lsp
140140
status_t do_render();
141141
void do_destroy();
142142
void draw_widgets(ws::ISurface *s);
143-
void auto_close_overlays(ssize_t x, ssize_t y);
143+
void auto_close_overlays(const ws::event_t *ev);
144144
Overlay *find_overlay(ssize_t x, ssize_t y);
145145
virtual status_t sync_size(bool force);
146146
status_t update_pointer();

src/main/widgets/containers/Overlay.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ namespace lsp
9393
wWidget = NULL;
9494
pPosFunc = NULL;
9595
pPosData = NULL;
96+
pFilterFunc = NULL;
97+
pFilterData = NULL;
9698
}
9799

98100
Overlay::~Overlay()
@@ -466,6 +468,12 @@ namespace lsp
466468
query_resize();
467469
}
468470

471+
void Overlay::set_filter_function(overlay_filter_t func, void *data)
472+
{
473+
pFilterFunc = func;
474+
pFilterData = data;
475+
}
476+
469477
bool Overlay::calculate_position(ws::rectangle_t *rect)
470478
{
471479
if (rect == NULL)
@@ -478,6 +486,16 @@ namespace lsp
478486
return true;
479487
}
480488

489+
bool Overlay::filter_event(const ws::event_t *ev)
490+
{
491+
if (ev == NULL)
492+
return false;
493+
if (!sAutoClose.get())
494+
return false;
495+
496+
return (pFilterFunc != NULL) ? pFilterFunc(ev, this, pFilterData) : false;
497+
}
498+
481499
} /* namespace tk */
482500
} /* namespace lsp */
483501

src/main/widgets/containers/Window.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,9 @@ namespace lsp
857857
return hKeys.vKeys.size();
858858
}
859859

860-
void Window::auto_close_overlays(ssize_t x, ssize_t y)
860+
void Window::auto_close_overlays(const ws::event_t *ev)
861861
{
862-
Overlay *ov = find_overlay(x, y);
862+
Overlay *ov = find_overlay(ev->nLeft, ev->nTop);
863863
size_t updates = 0;
864864

865865
for (size_t i=0, n=vDrawOverlays.size(); i<n; ++i)
@@ -874,8 +874,11 @@ namespace lsp
874874
continue;
875875
if (!xov->auto_close()->get())
876876
continue;
877+
if (xov == ov)
878+
continue;
877879

878-
if (xov != ov)
880+
// Hide the overlay if the event was not filtered
881+
if (!xov->filter_event(ev))
879882
{
880883
xov->visibility()->set(false);
881884
++updates;
@@ -986,10 +989,9 @@ namespace lsp
986989

987990
case ws::UIE_MOUSE_DOWN:
988991
{
989-
auto_close_overlays(e->nLeft, e->nTop);
992+
auto_close_overlays(e);
990993

991994
Widget *h = acquire_mouse_handler(e);
992-
// int old_state = hMouse.nState;
993995
hMouse.nState |= (size_t(1) << e->nCode);
994996
hMouse.nLeft = e->nLeft;
995997
hMouse.nTop = e->nTop;
@@ -1030,7 +1032,7 @@ namespace lsp
10301032
case ws::UIE_MOUSE_TRI_CLICK:
10311033
case ws::UIE_MOUSE_SCROLL:
10321034
{
1033-
auto_close_overlays(e->nLeft, e->nTop);
1035+
auto_close_overlays(e);
10341036

10351037
Widget *h = acquire_mouse_handler(e);
10361038
if (h == this)

0 commit comments

Comments
 (0)