TreeGadget : Ajout d'un frère sur un noeud
Publié : jeu. 05/juil./2007 15:56
Salut,
Voici le code qui me pose soucis
La création d'un enfant ne pose pas de problème.
La création d'un frère fonctionne sauf quand on sélectionne un noeud (dans ce cas un enfant est créé )
Voici le code qui me pose soucis
Code : Tout sélectionner
#WINDOW=0
Enumeration ; gadgets
#Tree
#StatusBar
EndEnumeration
Enumeration ; Menu
#AjoutEnfant
#AjoutFrere
#Supprimer
EndEnumeration
Procedure CB(Window, message, wParam, lParam) ; CallBack pour Treegadget éditable
Result = #PB_ProcessPureBasicEvents
If Window =WindowID(#WINDOW)
If message=#WM_NOTIFY
; =======================
; Treeview Notifications
; =======================
*tvinfo.NMTVDISPINFO=lParam
If *tvinfo\hdr\hwndFrom=GadgetID(#Tree)
If *tvinfo\hdr\code=#TVN_BEGINLABELEDIT
;
;something to do before editing ...
;
EndIf
If *tvinfo\hdr\code=#TVN_ENDLABELEDIT And *tvinfo\item\pszText<>0
;
;get result ...its work !!
;
Debug "Selected Item: "+Str(GetGadgetState(#Tree))
Debug "The new label is: "+PeekS(*tvinfo\item\pszText)
Result= 1
EndIf
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
OpenWindow(0, 0, 0, 640,480, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
TreeGadget(#Tree, 10, 10, 620, 440,#PB_Tree_AlwaysShowSelection)
CreateStatusBar(#StatusBar,WindowID(0))
AddGadgetItem (#Tree, -1, "Root", 0, 55)
AddStatusBarField(70)
AddStatusBarField(70)
AddStatusBarField(500)
;/ Treegadget éditable
SetWindowLong_(GadgetID(#Tree),#GWL_STYLE,GetWindowLong_(GadgetID(#Tree),#GWL_STYLE) | #TVS_EDITLABELS)
SetWindowCallback(@CB())
CreatePopupMenu(0)
MenuItem(#AjoutEnfant,"Ajout enfant")
MenuItem(#AjoutFrere, "Ajout frère")
MenuItem(#Supprimer,"Supprimer")
Repeat
evt=WaitWindowEvent()
Select evt
Case #WM_RBUTTONDOWN
DisplayPopupMenu(0,WindowID(0))
Case #PB_Event_Gadget
Select EventGadget()
Case #Tree ;/ Affiche infos sur l'élément du Treegadget sélectionné
StatusBarText(#StatusBar,0,"Element n° "+Str(GetGadgetState(#Tree)))
StatusBarText(#StatusBar,1,"Niveau n° "+Str(GetGadgetItemAttribute(#Tree,GetGadgetState(#Tree),#PB_Tree_SubLevel)))
StatusBarText(#StatusBar,2,GetGadgetText(#Tree))
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #AjoutEnfant
ElementSelectionne=GetGadgetState(#Tree)
Niveau=GetGadgetItemAttribute(#Tree,ElementSelectionne,#PB_Tree_SubLevel)
AddGadgetItem(#Tree,ElementSelectionne+1,"Enfant",0,Niveau+1)
SetGadgetState(#Tree,ElementSelectionne+1)
Case #AjoutFrere
ElementSelectionne=GetGadgetState(#Tree)
Niveau=GetGadgetItemAttribute(#Tree,ElementSelectionne,#PB_Tree_SubLevel)
AddGadgetItem(#Tree,ElementSelectionne+1,"Frère",0,Niveau)
SetGadgetState(#Tree,ElementSelectionne+1)
Case #Supprimer
ElementSelectionne=GetGadgetState(#Tree)
RemoveGadgetItem(#Tree,ElementSelectionne)
EndSelect
EndSelect
Until evt = #PB_Event_CloseWindow
La création d'un frère fonctionne sauf quand on sélectionne un noeud (dans ce cas un enfant est créé )
