User renaming treeview node

BlitzMax Forums/BlitzMax GUI Programming/User renaming treeview node

Is the manual renaming of a tree node with keyboard input something that Windows actually supports? It would be very useful to allow users to rename nodes without using a popup box or something.

yes, its possible.

You have to hack a bit in the win32maxguiex and the users.bmx but its easy to achive.

First add this to the pub.win32.user32.bmx :

Function GetWindowTextA( hwnd)
Function GetWindowTextW( hwnd)


Then modifiy the win32maxguiex.bmx:

Search the TWindowsTreeView Type and add the following field:

Field _edithwnd:Int


then edit the create function and change the wstyle variable to this:

wstyle=WS_CHILD|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_SHOWSELALWAYS|TVS_NOTOOLTIPS|WS_CLIPSIBLINGS|TVS_EDITLABELS


last change : search the OnNotify Method of TWindowsTreeView and add the following in the Select block:

Case TVN_BEGINLABELEDITW
				_edithwnd = SendMessageW(_hwnd,TVM_GETEDITCONTROL,0,0)
			Case TVN_ENDLABELEDITW
				Local buffer:Short[260]
				GetWindowTextW(_edithwnd , buffer , 256) 
				_selected.setText(String.FromShorts(buffer,256))


Rebuild the pub.win32 and maxgui.win32maxguiex modules.
Just start the treeview exsample and select a node. After a second click you're now able to edit the node.

I hope this helps you:)

That seems like a big part of it, but the application still needs to be able to turn label editing on:
http://msdn.microsoft.com/en-us/library/bb760017%28VS.85%29.aspx#tv_label_editing

In your sample application, if you rename the tree node with the "left-click twice" method, a crash ensues:
' createtreeview.bmx

Import MaxGui.Drivers

Strict 

Local window:TGadget=CreateWindow("My Window",50,50,240,240,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Local treeview:TGadget=CreateTreeView(5,5,ClientWidth(window)-10,ClientHeight(window)-10,window)

SetGadgetLayout treeview, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED

Local root:TGadget=TreeViewRoot(treeview)

Local help:TGadget=AddTreeViewNode("Help",root)
AddTreeViewNode "Topic 1",help
AddTreeViewNode "Topic 2",help
AddTreeViewNode "Topic 3",help

Local projects:TGadget=AddTreeViewNode("Projects",root)
AddTreeViewNode("Sub Project",AddTreeViewNode("Project 1",projects))
AddTreeViewNode("Project 2",projects)
AddTreeViewNode("Project 3" , projects) 

Local menu:TGadget  = CreateMenu("popup" , 0 , Null) 
CreateMenu("Rename" , 101 , menu)



While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			Exit
		Case EVENT_GADGETMENU
			SelectTreeViewNode TGadget(EventExtra()) 'Important !!! for good looking purpose this has to be done before PopupWindow
			PopupWindowMenu window , menu
		Case EVENT_MENUACTION
			If EventData() = 101
				EditTreeViewLabel(treeview,SelectedTreeViewNode(treeview))
				
			EndIf
	End Select
Wend

Notify GadgetText(SelectedTreeViewNode(treeview))

Function EditTreeViewLabel(treeview:TGadget , Item:TGadget) 
	Local TV:TWindowsTreeView = TWindowsTreeView(treeview)
	Local TI:TWindowsTreeNode = TWindowsTreeNode (Item)
	If Not TV Or Not TI Then Return
	SendMessageW TV._hwnd,TVM_EDITLABELW,0,TI._item
End Function


hmm, it works without crahes here, maybe you can try to avoid crashes by changing this line

_selected.setText(String.FromShorts(buffer,256))


to

if _selected then _selected.setText(String.FromShorts(buffer,256))