Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit abdd45d

Browse files
committed
[[ Bug 21964 ]] Fix MCWidget::hittest for invisible/disabled widgets
This patch adds the same guard to `MCWidget::hittest` as seen in the `MCControl` and `MCGroup` implementation where the hit test should return nil if the target is not visible or the target is disabled and the current tool is browse. This issue was causing `controlAtLoc` to return hidden widgets on all platforms and touch events on mobile to be sent to hidden widgets.
1 parent f1287f0 commit abdd45d

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

docs/notes/bugfix-21945.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix touch events being sent to and controlAtLoc returning hidden and disabled widgets

engine/src/widget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ Boolean MCWidget::doubleup(uint2 p_which)
327327

328328
MCObject* MCWidget::hittest(int32_t x, int32_t y)
329329
{
330+
if (!(flags & F_VISIBLE || showinvisible()) ||
331+
(flags & F_DISABLED && getstack()->gettool(this) == T_BROWSE))
332+
return nil;
333+
330334
if (m_widget != nil)
331335
return MCwidgeteventmanager->event_hittest(this, x, y);
332336
return nil;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
script "CoreControlAtLoc"
2+
/*
3+
Copyright (C) 2019 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
20+
on TestControlAtLoc
21+
TestSkipIfNot "lcb"
22+
23+
create stack "Test"
24+
set the defaultStack to "Test"
25+
26+
local tControl, tLoc
27+
repeat for each item tType in "button,field,scrollbar,image,player,graphic,widget,group"
28+
switch tType
29+
case "graphic"
30+
do format("create %s", tType)
31+
set the opaque of it to true
32+
set the style of it to "rectangle"
33+
break
34+
case "group"
35+
do format("create %s", tType)
36+
set the opaque of it to true
37+
set the rect of it to 0,0,100,100
38+
break
39+
case "widget"
40+
TestLoadExtension "com.livecode.widget.clock"
41+
create widget "TestWidget" as "com.livecode.widget.clock"
42+
break
43+
default
44+
do format("create %s", tType)
45+
end switch
46+
put it into tControl
47+
TestDiagnostic tControl
48+
49+
put the loc of tControl into tLoc
50+
TestDiagnostic tLoc
51+
TestDiagnostic "hit" && controlAtLoc(tLoc)
52+
TestAssert format("visible %s controlAtLoc", tType), the long id of controlAtLoc(tLoc) is tControl
53+
set the visible of tControl to false
54+
TestAssert format("invisible %s controlAtLoc", tType), controlAtLoc(tLoc) is empty
55+
delete tControl
56+
end repeat
57+
end TestControlAtLoc

0 commit comments

Comments
 (0)