On Fri, Sep 28, 2012 at 11:16 AM, Staffan Tylen <firstname.lastname@example.org> wrote:
Correction: as I added the ::method and expose lines afterwards while composing my note I forgot to include the arg statement, so the sample code I use is therefore:
:method onTreeviewContext unguarded
expose tree cmenu
use arg hwnd, x, y
pos = .Point~new(x, y)
say tree~hitTestInfo(pos)~hItem tree~hitTestInfo(pos)~location
if tree~hitTestInfo(pos)~hItem <> 0 then cmenu~show(pos)
The x and y sent here are in screen co-ordinates. hitTestInfo() takes client co-ordinates. So you need to map the screen co-ordinates to the tree-view client co-ordinates to use with hitTestInfo().
Use the screen2client() method to map the point. That will change the x and y value of pos. So, if you need to retain those values, use the copy() method of the Point class to do that.
In pseudo code it goes something like this
treeView = newTreeView
clientPos = pos~copy
d = treeView~hitTestInfo(clientPos)
I believe that is the problem and solution. If you still can't get it to work, then post again.