Voilà qui pourra surement servir à d'autre !
- Gestion complète du Tree -> Monter / Descendre un élément.
- Déplacer un élément au niveau Supérieur ou Inférieur.
- Gestion du Drag en Drop.
- Tree Avec gros Icônes.
J'ai presque rien fais moi si ce n'est assembler le code.
Tous le mérite ne m'en reviens donc pas.
Code : Tout sélectionner
; Tree avec Gestion complète.
; Code créé par Monsieur Dieppedalle David le 13/06/2016.
; Correction par Michel Lye (Micoute)
; Code pour éditer les lien du tree créé par ?.
; Code pour la gestion du drag en drop ainsi que le déplacement des lien du tree créer par "Le Soldat Inconnu" du forum FR de Pure Basic.
; Merci à Falsam du forum PB, pour son aide pour la gestion des icônes grand format pour le Tree.
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; Active le support du format PNG (Portable Network Graphic) pour les commandes CatchImage(), LoadImage(), CatchSprite() et LoadSprite().
UsePNGImageDecoder()
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;{ Constante
#Version = 1
#SousVersion = 1
#Build = 1
#Tree_DragDrop_Deplacer = 0
;}
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;{ Enumeration
Enumeration Programme_Maker
; Windows
#Window_Main
; Gadgets
#Gadget_Tree
#Gadget_BoutonArbreMonter
#Gadget_BoutonArbreDescendre
#Gadget_BoutonArbreNiveauPlus
#Gadget_BoutonArbreNiveauMoins
EndEnumeration
;}
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;{ CatchImage
; Bouton Commande Tree
Global Descendre.i = CatchImage(#PB_Any, ?Descendre)
Global Monter.i = CatchImage(#PB_Any, ?Monter)
Global NiveauPlus.i = CatchImage(#PB_Any, ?NiveauPlus)
Global NiveauMoins.i = CatchImage(#PB_Any, ?NiveauMoins)
; Tree
Global Bank.i = CatchImage(#PB_Any, ?Bank)
Global Cinema.i = CatchImage(#PB_Any, ?Cinema)
Global City.i = CatchImage(#PB_Any, ?City)
Global CommercialBuilding.i = CatchImage(#PB_Any, ?CommercialBuilding)
Global Hospital.i = CatchImage(#PB_Any, ?Hospital)
Global RetailShop.i = CatchImage(#PB_Any, ?RetailShop)
Global School.i = CatchImage(#PB_Any, ?School)
;}
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;{ DataSection
DataSection
; Bouton Commande Tree
Descendre:
IncludeBinary "Icones\Descendre.png"
Monter:
IncludeBinary "Icones\Monter.png"
NiveauPlus:
IncludeBinary "Icones\Niveau Plus.png"
NiveauMoins:
IncludeBinary "Icones\Niveau Moins.png"
; Tree
Bank:
IncludeBinary "Icones\Bank.ico"
Cinema:
IncludeBinary "Icones\Cinema.ico"
City:
IncludeBinary "Icones\City.ico"
CommercialBuilding:
IncludeBinary "Icones\Commercial Building.ico"
Hospital:
IncludeBinary "Icones\Hospital.ico"
RetailShop:
IncludeBinary "Icones\Retail Shop.ico"
School:
IncludeBinary "Icones\School.ico"
EndDataSection
;}
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;{ Gestion de Tree
; Taille des icones
IconSize = 32
; Création de la liste d'image
Global ImageList = ImageList_Create_(IconSize, IconSize, #ILC_COLOR32 | #ILC_MASK, 0, 10)
;Ajoute des icones dans la liste d'icone
ImageList_AddIcon_(ImageList, ImageID(City)) ; Ne serra pas visible.
ImageList_AddIcon_(ImageList, ImageID(City))
ImageList_AddIcon_(ImageList, ImageID(Bank))
ImageList_AddIcon_(ImageList, ImageID(Cinema))
ImageList_AddIcon_(ImageList, ImageID(CommercialBuilding))
ImageList_AddIcon_(ImageList, ImageID(Hospital))
ImageList_AddIcon_(ImageList, ImageID(RetailShop))
ImageList_AddIcon_(ImageList, ImageID(School))
Structure ArbreInfo
Nom.s
Niveau.l
Pliage.l
EndStructure
Global NewList Arbre.ArbreInfo()
Global DragDrop_Start, DragDrop_Start_X
Procedure Arbre_Edit(Val)
hd_gadget = SendMessage_(GadgetID(#Gadget_Tree), #TVM_GETEDITCONTROL, 0, 0)
ligne.s
ligne = Space(256)
Repeat
Delay(1)
resu = GetWindowText_(hd_gadget, @ligne, 256)
hd_gadget = SendMessage_(GadgetID(#Gadget_Tree), #TVM_GETEDITCONTROL, 0, 0)
If ligne <> ""
NouveauxNom$ = ligne
EndIf
Until hd_gadget = 0
SetGadgetText(#Gadget_Tree, NouveauxNom$)
EndProcedure
Procedure Arbre_Pliage()
ForEach Arbre()
If GetGadgetItemState(#Gadget_Tree, ListIndex(Arbre())) & #PB_Tree_Expanded
Arbre()\Pliage = 1
Else
Arbre()\Pliage = 0
EndIf
Next
EndProcedure
Procedure Arbre_Niveau_Correction()
Niveau = 0
ForEach Arbre()
If Arbre()\Niveau > Niveau + 1
Arbre()\Niveau = Niveau + 1
EndIf
If Arbre()\Niveau < 0
Arbre()\Niveau = 0
EndIf
Niveau = Arbre()\Niveau
Next
EndProcedure
Procedure Arbre_Remplir(Position = -1)
LockWindowUpdate_(WindowID(0))
ClearGadgetItems(#Gadget_Tree)
ForEach Arbre()
AddGadgetItem(#Gadget_Tree, -1, Arbre()\Nom, 0, Arbre()\Niveau)
If Pliage
SetGadgetItemState(#Gadget_Tree, ListIndex(Arbre()) - 1, #PB_Tree_Expanded)
EndIf
Pliage = Arbre()\Pliage
Next
If Position >= 0
SetGadgetState(#Gadget_Tree, Position)
EndIf
LockWindowUpdate_(0)
EndProcedure
Procedure Arbre_Deplacer(Position, Mouvement)
Protected PositionFinale, *Deplacer1.ArbreInfo, *Deplacer2.ArbreInfo
Arbre_Pliage()
If Position >= 0
; Vérification
If Position + Mouvement < 0
Mouvement = -Position
EndIf
If Position + Mouvement >= ListSize(Arbre())
Mouvement = ListSize(Arbre()) - 1 - Position
EndIf
; Position finale
PositionFinale = Position + Mouvement
; Evolution du niveau entre le départ et l'arrivée
SelectElement(Arbre(), Position)
Niveau = Arbre()\Niveau
SelectElement(Arbre(), PositionFinale)
Evolution = Arbre()\Niveau - Niveau
If NextElement(Arbre())
If Arbre()\Niveau > Niveau + Evolution
Evolution + 1
EndIf
EndIf
; Nombre d'élément à déplacer (Regarde le nombre d'enfants à déplacer)
SelectElement(Arbre(), Position)
Suivant = 0
While NextElement(Arbre())
If Arbre()\Niveau <= Niveau
Break
EndIf
Suivant + 1
Wend
If Mouvement > 0 And Position + Suivant >= PositionFinale
Suivant = 0 ; Si le déplacement se fait dans un élément enfant, on ne déplace pas les enfants
EndIf
; Déplacement
Repeat
SelectElement(Arbre(), Position)
If Mouvement > 0
For i = 1 To Mouvement
*Deplacer1 = @Arbre()
NextElement(Arbre())
*Deplacer2 = @Arbre()
SwapElements(Arbre(), *Deplacer1, *Deplacer2)
ChangeCurrentElement(Arbre(), *Deplacer1)
Next
ElseIf Mouvement < 0
For i = 1 To -Mouvement
*Deplacer1 = @Arbre()
PreviousElement(Arbre())
*Deplacer2 = @Arbre()
SwapElements(Arbre(), *Deplacer1, *Deplacer2)
ChangeCurrentElement(Arbre(), *Deplacer1)
Next
Position + 1
EndIf
Arbre()\Niveau + Evolution
Suivant - 1
Until Suivant < 0
Arbre_Niveau_Correction()
Arbre_Remplir(PositionFinale)
EndIf
EndProcedure
Procedure Arbre_Niveau(Position, Evolution)
Arbre_Pliage()
If Position >= 0
SelectElement(Arbre(), Position)
Niveau = Arbre()\Niveau
; Vérification
If Niveau + Evolution < 0
Evolution = -Niveau
EndIf
If Evolution > 0
If PreviousElement(Arbre())
If Niveau + Evolution > Arbre()\Niveau + 1
Evolution = Arbre()\Niveau + 1 - Niveau
EndIf
NextElement(Arbre())
EndIf
EndIf
; Correction du pliage de l'arbre
If Evolution > 0
If PreviousElement(Arbre())
Arbre()\Pliage = 1
NextElement(Arbre())
EndIf
EndIf
If Evolution < 0
If NextElement(Arbre())
If Arbre()\Niveau = Niveau
PreviousElement(Arbre())
Arbre()\Pliage = 1
Else
PreviousElement(Arbre())
EndIf
EndIf
EndIf
; Change le niveau
Arbre()\Niveau + Evolution
While NextElement(Arbre())
If Arbre()\Niveau <= Niveau
Break
EndIf
Arbre()\Niveau + Evolution
Wend
Arbre_Niveau_Correction()
Arbre_Remplir(Position)
EndIf
EndProcedure
Procedure Arbre_GlisserDeposer()
Protected DragDrop_X, DragDrop_End
DragDrop_End = GetGadgetState(#Gadget_Tree)
If DragDrop_End = -1
DragDrop_End = CountGadgetItems(#Gadget_Tree) - 1
EndIf
DragDrop_X = WindowMouseX(#Window_Main) - DragDrop_Start_X
If DragDrop_End = DragDrop_Start
; On change le niveau de l'élément
If DragDrop_X > 8
Arbre_Niveau(DragDrop_Start, 1)
ElseIf DragDrop_X < -8
Arbre_Niveau(DragDrop_Start, -1)
EndIf
Else
; On déplace l'élément
Arbre_Deplacer(DragDrop_Start, DragDrop_End - DragDrop_Start)
EndIf
EndProcedure
;}
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Procedure Open_Tree()
If OpenWindow(#Window_Main, 0, 0, 800, 600, "Tree Avec Gestion complète...", #PB_Window_SystemMenu | #PB_Window_TitleBar| #PB_Window_ScreenCentered)
ButtonImageGadget(#Gadget_BoutonArbreMonter, 265, 20, 40, 40, ImageID(Monter))
ButtonImageGadget(#Gadget_BoutonArbreDescendre, 265, 60, 40, 40, ImageID(Descendre))
ButtonImageGadget(#Gadget_BoutonArbreNiveauPlus, 265, 100, 40, 40, ImageID(NiveauPlus))
ButtonImageGadget(#Gadget_BoutonArbreNiveauMoins, 265, 140, 40, 40, ImageID(NiveauMoins))
TreeGadget(#Gadget_Tree, 10, 10, 250, 580, #PB_Tree_AlwaysShowSelection)
SetWindowLong_(GadgetID(#Gadget_Tree), #GWL_STYLE, GetWindowLong_(GadgetID(#Gadget_Tree), #GWL_STYLE) | #TVS_EDITLABELS) ; liste arborescente standard
EnableGadgetDrop(#Gadget_Tree, #PB_Drop_Private, #PB_Drag_Move, #Tree_DragDrop_Deplacer)
;{ Ajoute Element Tree
AddElement(Arbre())
Arbre()\Nom = "City"
Arbre()\Niveau = 0
AddElement(Arbre())
Arbre()\Nom = "Cinema"
Arbre()\Niveau = 1
AddElement(Arbre())
Arbre()\Nom = "Bank"
Arbre()\Niveau = 1
AddElement(Arbre())
Arbre()\Nom = "CommercialBuilding"
Arbre()\Niveau = 1
AddElement(Arbre())
Arbre()\Nom = "Hospital"
Arbre()\Niveau = 1
AddElement(Arbre())
Arbre()\Nom = "RetailShop"
Arbre()\Niveau = 1
AddElement(Arbre())
Arbre()\Nom = "School"
Arbre()\Niveau = 1
AddGadgetItem(#Gadget_Tree, -1, "City", ImageID(City), 0)
AddGadgetItem(#Gadget_Tree, -1, "Cinema", ImageID(Cinema), 1)
AddGadgetItem(#Gadget_Tree, -1, "Bank", ImageID(Bank), 1)
AddGadgetItem(#Gadget_Tree, -1, "Commercial Building", ImageID(CommercialBuilding), 1)
AddGadgetItem(#Gadget_Tree, -1, "Hospital", ImageID(Hospital), 1)
AddGadgetItem(#Gadget_Tree, -1, "Retail Shop", ImageID(RetailShop), 1)
AddGadgetItem(#Gadget_Tree, -1, "School", ImageID(School), 1)
;}
SendMessage_(GadgetID(#Gadget_Tree), #TVM_SETIMAGELIST, #TVSIL_NORMAL, ImageList)
SetGadgetItemState(#Gadget_Tree, 0, #PB_Tree_Expanded)
Repeat
WindowEvent = WaitWindowEvent()
EventGadget = EventGadget()
EventType = EventType()
Select WindowEvent
Case #PB_Event_Gadget
Position = GetGadgetState(#Gadget_Tree)
Select EventGadget
Case #Gadget_Tree
Select EventType()
Case #PB_EventType_DragStart ; Glisser déposer
DragDrop_Start = Position
DragDrop_Start_X = WindowMouseX(#Window_Main)
DragPrivate(#Tree_DragDrop_Deplacer, #PB_Drag_Move)
Case #PB_EventType_LeftDoubleClick
SendMessage_(GadgetID(#Gadget_Tree), #TVM_EDITLABEL, 0, GadgetItemID(#Gadget_Tree, GetGadgetState(#Gadget_Tree)))
CreateThread(@Arbre_Edit(), 0)
EndSelect
Case #Gadget_BoutonArbreMonter
Arbre_Deplacer(Position, -1)
Case #Gadget_BoutonArbreDescendre
Arbre_Deplacer(Position, 1)
Case #Gadget_BoutonArbreNiveauPlus
Arbre_Niveau(Position, 1)
Case #Gadget_BoutonArbreNiveauMoins
Arbre_Niveau(Position, -1)
EndSelect
Case #PB_Event_GadgetDrop
; Opération de glisser déposer
Select EventGadget()
Case #Gadget_Tree
Select EventDropType()
Case #PB_Drop_Private
Select EventDropPrivate()
Case #Tree_DragDrop_Deplacer
Arbre_GlisserDeposer()
EndSelect
EndSelect
EndSelect
EndSelect
Until WindowEvent = #PB_Event_CloseWindow
CloseWindow(Windows)
EndIf
EndProcedure
Open_Tree()
http://www.aht.li/2909900/Tree_Avec_Ges ... mplete.zip