[Solved] Capture Secondary Mouse button event for TreeView Gadget

Started by _PJ_, November 11, 2023, 12:56:24

Previous topic - Next topic

_PJ_

It seems that there is some "hardcoding" in processing events where using secondary mousebutton for TreeView items sends a "GadgetMenu" event.

This is great and intuitive, since this is typically the process for insdtancing a PopUpWindowMenu context-menu

HOWEVER

There doesn't seem to be a direct means to identify the specific Node which is under the mouse cursor when this is called* - although it seems visdually that the relevant node entry is highlighted brifly, the "SelectedTreeViewNode" always reverts to its prior reference, and therefore can be confusing for end-user if they attempt to openb a context menu for a node that is different from the one previously selected with, say, left-mouse button.


Any ideas on how to work around this, or force a new SelectTreeViewNode() to point to the node that was 'right-clicked'?


* Theroetically some huge computation process could be done to investigate the position and expanded status of an entire list of nodes and calculate their relaive mouse positions

_PJ_

And, typically, once again - no sooner have I posted after struggling for a while, then I manage to solve the issue :D



I am using a select/case switch to process polled events: the relevant event here is, as described, a GadgetMenu event:

Seems GadgetExtra() already identifies the Node gadget, so I just have to force the selection of this cast as a TGadget and everything works just fine!
Case EVENT_GADGETMENU
Select (EventSource())
Case MYTREEVIEWGADGET
SelectTreeViewNode(TGadget(EventExtra()))
                        DoPopUpStuff()