tree view and key events, double click

BlitzMax Forums/MaxGUI Module/tree view and key events, double click

Jur(Posted 2012) [#1]
I would like to perform an operation by clicking on a tree node while holding down a key. I used SetGadgetSensitivity to get key events, but it looks they doesnt work well with tree views. When I hold down a key I get that clicking noise like when keys get stuck and my code behaves strangely.
Does anybody successfully use keyboard input with tree views?

Another thing - is there a way to disable the expand node behavior for double click? I would like to reserve double click only for my gadget action. I tried to collapse node after expansion but this give a flicker of expaned node.


jsp(Posted 2012) [#2]
Never used keyboard input with treeviews, but if it is windows only you could use:

?win32
Extern "Win32"
Function GetKeyState(nVirtKey)
EndExtern
?

?win32
If GetKeyState(17) & 128
'CTRL key is pressed ....
End If
?

The double click behavoir was added on request. You would need to overwrite the MaxGUI method.
IIRC it was not possible to just kill the event.

Maybe it's easier to use another combination for example a right mouse click?


JoshK(Posted 2012) [#3]
What are you trying to do? Requiring a key press when clicking a tree node is not a standard way of doing things.


Jur(Posted 2012) [#4]
I am using tree nodes for layers. I would like to add a quick hide/show operation for a layer by holding down a "H" key and clicking on a node.
(hidden layer is indicated by a changed icon of a node).

@jsp
Actually you are using double-click in your LGP editor for hiding layers. Can you tell me how did you did it? I think I notice a flicker occasionally but it is much better then what I got in my code.
I havent yet tried using right button. That can be done via SENSITIZE_MOUSE, right? The problem with right button is that I would like the best options for a tablet pen where the "left button" is the most suitable for that (and any) kind of work.

I like the variant with a shortcut key because it could be coded that the originaly selected node is stored and preserved as a selected one.

Of course the best variant would be if tree nodes could be composed from other gadgets and I could use checkers for visibility. As that is not possible I am trying to get the most I can from what the tree gadget offers.

Last edited 2012


JoshK(Posted 2012) [#5]
I think you should either use checkboxes, or a right-click menu. See EVENT_GADGETMENU.


jsp(Posted 2012) [#6]
I store all layer in a type and there are extra fields for every node if it is selected or expanded.
When updating the layer treeview I first of all free the treeview root and then go through all layer
and add them as needed and also expand every node immediately (important, directly after adding the node) as stored in the field.

Actually it was much smoother in the older MaxGUI where I could work with ModifyNode (no flicker at all), but now I do have also some little flicker as you noticed. As you don't have hundreds of layers normally it's not a problem.

The right mouse button can be used just easily without SENSITIZE_MOUSE. It's also directly supported in Logic Gui. Check the Events tab and EVENT_GADGETMENU of the treeview properties.


JoshK(Posted 2012) [#7]
Use this to enable checkboxes:
Const TVM_GETITEMSTATE = TV_FIRST+39
Const TVS_CHECKBOXES =$0100
Const TVM_SETITEM=TV_FIRST+13
Local htree=QueryGadget(tree,QUERY_HWND)
Local style=GetWindowLongW(htree,GWL_STYLE)
SetWindowLongW htree,GWL_STYLE,style|TVS_CHECKBOXES

And this will get and set their state:
Function TreeViewNodeChecked:Int(gadget:TGadget)
	Local htree:Int=TWindowsTreeNode(gadget)._tree
	Local item:Int=TWindowsTreeNode(gadget)._item
	Return (SendMessageW(htree,TVM_GETITEMSTATE,item,TVIS_STATEIMAGEMASK) Shr 12)-1
EndFunction

Function CheckTreeViewNode(gadget:TGadget, truefalse:Int = True)
	Local htree:Int=TWindowsTreeNode(gadget)._tree
	Local item:Int=TWindowsTreeNode(gadget)._item
	Local state=SendMessageW(htree,TVM_GETITEMSTATE,item,TVIS_STATEIMAGEMASK)
	Local tmpItem:TVITEMW = New TVITEMW
	tmpItem.hitem = item
	tmpItem.mask = TVIF_STATE
	If truefalse Then tmpItem.state = 2 Shl 12 Else tmpitem.state = 1 Shl 12
	tmpItem.statemask = TVIS_STATEIMAGEMASK
	SendMessageW(htree,TVM_SETITEM,0,Int Byte Ptr tmpitem)
EndFunction

I don't remember how to detect events, I think I made some modifications to win32maxgui.

Last edited 2012


Jur(Posted 2012) [#8]
Thanks Josh. It works nicely but will try to use crossplatform solutions.

@jsp
Thanks for explanation. If I wont find a better solution, I will probably use your method. In future I may try to make a custom tree from panels...


shinkiro1(Posted 2012) [#9]
I implemented the exact same functionality (hiding a Layer) and did this as JoshK suggested via RightClick Menu. If ever somebody else other than you will be using your software I strongly suggest you should do the same, as it is intuitive/expected behavior and it's easily implemented (no maxgui hacking required).