It is possible to work around that behavior by testing to see if the PNT clicked is inside the data Item RECT, as shown in the test code below. Of course, it is not necessary to do this test for Left-clicking in production code.
My question is this: Is there a built-in predicate in ListViewControl that would handle this more gracefully than checking for PNT in RECT?
Code: Select all
predicates
onListViewControlMouseRightClick : listViewControl::mouseRightClickListener.
clauses
onListViewControlMouseRightClick(Source, Pnt) :-
% RIGHT CLICK DOES NOT BEHAVE THE SAME WAY AS LEFT CLICKING ON COLUMN LABELS
if Source:hitTest(Pnt, ItemID, SubItemId) and listViewControl::item(ItemID, KeyStr, _, _, MoreSS) = Source:getItem(ItemID) then
%-- get item RCT and see if Pnt lies inside it
if pntInside(Pnt, Source:getItemRect(ItemID, listViewControl::bounds)) then
% ARRIVE HERE IF RIGHT CLICK OUTSIDE THE DATA GRID
stdio::write("\n\nRight Clicked Inside Data Area")
else
% ARRIVE HERE IF RIGHT CLICK ON COLUMN LABEL
stdio::write("\n\nRight Clicked Outside Data Area - you should ignore returned value!")
end if,
stdio::writef("\n% \t % \tClicked on cell containing '%'", ItemID, KeyStr, list::nth(SubItemId, [KeyStr | MoreSS]))
else
stdio::write("\nNOT on a DATA CELL or COLUMN LABEL")
end if.
predicates
onListViewControlMouseClick : listViewControl::mouseClickListener.
clauses
onListViewControlMouseClick(Source, Pnt) :-
if Source:hitTest(Pnt, ItemID, SubItemId) and listViewControl::item(ItemID, KeyStr, _, _, MoreSS) = Source:getItem(ItemID) then
%-- get item RCT and see if Pnt lies inside it
if pntInside(Pnt, Source:getItemRect(ItemID, listViewControl::bounds)) then
stdio::write("\n\nLeft Clicked Inside Data Area")
else
% NEVER GET HERE WHEN LEFT CLICKING so checking for PNT in RECT is unnecessary
stdio::write("\n\nLeft Clicked Outside Data Area - you should ignore returned value!")
end if,
stdio::writef("\n% \t % \tClicked on cell containing '%'", ItemID, KeyStr, list::nth(SubItemId, [KeyStr | MoreSS]))
else
% ARRIVE HERE IF LEFT CLICK OUTSIDE THE DATA GRID
stdio::write("\nNOT on a DATA CELL or COLUMN LABEL")
end if.
class predicates
pntInside : (pnt, rct) determ.
clauses
pntInside(pnt(X, Y), rct(L, T, R, B)) :-
L <= X,
X <= R,
T <= Y,
Y <= B.
Code: Select all
class predicates
tryGetTextClickRt : (listViewControl, pnt PointClicked) -> string determ.
clauses
tryGetTextClickRt(LVC, Pnt) = Text :-
LVC:hitTest(Pnt, ItemID, SubItemId),
pntInside(Pnt, LVC:getItemRect(ItemID, listViewControl::bounds)), % only necessary for Rt. click
listViewControl::item(ItemID, KeyStr, _, _, MoreSS) = LVC:getItem(ItemID),
Text = list::nth(SubItemId, [KeyStr | MoreSS]).
class predicates
tryGetTextClickLt : (listViewControl, pnt PointClicked) -> string determ.
clauses
tryGetTextClickLt(LVC, Pnt) = Text :-
LVC:hitTest(Pnt, ItemID, SubItemId),
listViewControl::item(ItemID, KeyStr, _, _, MoreSS) = LVC:getItem(ItemID),
Text = list::nth(SubItemId, [KeyStr | MoreSS]).