Code : Tout sélectionner
; PureBasic 3.93
; Droopy 10/05/05
;{ Constantes
#LClick=1
#RClick=2
#LDClick=4
#RDClick=8
#Focus=16
#LFocus=32
#Change=64
;}
Structure GadgetStructure
LeftClick.l
RightClick.l
LeftDoubleClick.l
RightDoubleClick.l
Focus.l
LostFocus.l
Change.l
EndStructure
Procedure ManageEventInit()
Static Flag
Global ManageEventFlagClose,ManageEventDebugMode
If Flag=0
Flag=1
NewList GadgetEventList.GadgetStructure()
AddElement(GadgetEventList())
NewList MenuEventList()
AddElement(MenuEventList())
Else
ManageEventFlagClose=0
ClearList(GadgetEventList())
ClearList(MenuEventList())
EndIf
EndProcedure
ProcedureDLL ManageEventDebug(Bool)
ManageEventDebugMode=Bool
EndProcedure
Procedure ManageEventDebugText(ObjectType,Number,Text.s,ProcedurePointer)
If ManageEventDebugMode ; Mode debug actif
If ObjectType=0 ; Gadget
If ProcedurePointer=0 ; Pas de procedure Call définie
Debug "Gadget "+Str(Number)+" "+Text+" No Procedure Call define"
Else ; Procedure Call define
Debug "Gadget "+Str(Number)+" "+Text+" Call Procedure "+Str(ProcedurePointer)
EndIf
Else ; Menu
If ProcedurePointer=0
Debug "Menu "+Str(Number)+" No Procedure Call define"
Else
Debug "Menu "+Str(Number)+" Call Procedure "+Str(ProcedurePointer)
EndIf
EndIf
EndIf
EndProcedure
ProcedureDLL ManageEventGadget(Gadget,Event,ProcedurePointer) ; #LClick #RClick #LDClick #RDClick #Focus #LFocus #Change
; Si pas assez d'élément on en ajoute
Compte=CountList(GadgetEventList())
If Compte-1<Gadget
ElementACreer=Gadget-Compte+1
LastElement(GadgetEventList())
For n=1 To ElementACreer
AddElement(GadgetEventList())
Next
EndIf
SelectElement(GadgetEventList(),Gadget)
If Event & #LClick
GadgetEventList()\LeftClick=ProcedurePointer
EndIf
If Event & #RClick
GadgetEventList()\RightClick=ProcedurePointer
EndIf
If Event & #LDClick
GadgetEventList()\LeftDoubleClick=ProcedurePointer
EndIf
If Event & #RDClick
GadgetEventList()\RightDoubleClick=ProcedurePointer
EndIf
If Event & #Focus
GadgetEventList()\Focus=ProcedurePointer
EndIf
If Event & #LFocus
GadgetEventList()\LostFocus=ProcedurePointer
EndIf
If Event & #Change
GadgetEventList()\Change=ProcedurePointer
EndIf
EndProcedure
ProcedureDLL ManageEventMenu(Menu,ProcedurePointer)
; Si pas assez d'élément on en ajoute
ElementACreer=CountList(MenuEventList())-Menu
If ElementACreer>0
LastElement(MenuEventList())
For n=1 To ElementACreer
AddElement(MenuEventList())
Next
EndIf
SelectElement(MenuEventList(),Menu)
MenuEventList()=ProcedurePointer
EndProcedure
ProcedureDLL ManageEventStart()
Repeat
Evenement=WaitWindowEvent()
;/ Gadget
If Evenement=#PB_Event_Gadget
GadgetID=EventGadgetID()
SelectElement(GadgetEventList(),GadgetID)
Event= EventType()
Select Event
Case #PB_EventType_LeftClick
temp=GadgetEventList()\LeftClick
ManageEventDebugText(0,GadgetID,"Left Click",temp)
If GadgetEventList()\LeftClick<>0
CallFunctionFast(temp,"")
EndIf
Case #PB_EventType_RightClick
temp=GadgetEventList()\RightClick
ManageEventDebugText(0,GadgetID,"Right click",temp)
If GadgetEventList()\RightClick<>0
CallFunctionFast(temp,"")
EndIf
Case #PB_EventType_LeftDoubleClick
temp=GadgetEventList()\LeftDoubleClick
ManageEventDebugText(0,GadgetID,"LeftDoubleClick",temp)
If GadgetEventList()\LeftDoubleClick<>0
CallFunctionFast(temp,"")
EndIf
Case #PB_EventType_RightDoubleClick
temp=GadgetEventList()\RightDoubleClick
ManageEventDebugText(0,GadgetID,"RightDoubleClick",temp)
If GadgetEventList()\RightDoubleClick<>0
CallFunctionFast(temp,"")
EndIf
Case #PB_EventType_Focus
temp=GadgetEventList()\Focus
ManageEventDebugText(0,GadgetID,"Focus",temp)
If GadgetEventList()\Focus<>0
CallFunctionFast(temp,"")
EndIf
Case #PB_EventType_LostFocus
temp=GadgetEventList()\LostFocus
ManageEventDebugText(0,GadgetID,"LostFocus",temp)
If GadgetEventList()\LostFocus <>0
CallFunctionFast(temp,"")
EndIf
Case #PB_EventType_Change
temp=GadgetEventList()\Change
ManageEventDebugText(0,GadgetID,"Change",temp)
If GadgetEventList()\Change<>0
CallFunctionFast(temp,"")
EndIf
EndSelect
EndIf
;/ Menu
If Evenement=#PB_Event_Menu
Menu=EventMenuID()
SelectElement(MenuEventList(),Menu)
CallFunctionFast(MenuEventList(),"")
EndIf
;/ #PB_Event_CloseWindow
If Evenement=#PB_Event_CloseWindow
Select ManageEventFlagClose
Case -1 ; Quitter la gestion des evenements
Break
Case 0 ; Fin du Programme
End
Default ; Appel d'une procédure
CallFunctionFast(ManageEventFlagClose,"")
EndSelect
EndIf
ForEver
EndProcedure
ProcedureDLL ManageEventSetCloseEvent(ProcedurePointer)
ManageEventFlagClose=ProcedurePointer
EndProcedure
Procedure Bip()
beep_(3000,100)
EndProcedure
Procedure Bop()
beep_(400,100)
EndProcedure
Procedure Tap()
beep_(200,30)
EndProcedure
Procedure Bup()
beep_(100,30)
beep_(300,30)
beep_(600,30)
EndProcedure
Enumeration ; Définition des Gadgets
#Texte1
#Bouton1
EndEnumeration
;/ Test de la Librairie
OpenWindow(0, 302, 150, 382, 143, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "Manage Event")
CreateGadgetList(WindowID())
StringGadget(#Texte1, 10, 10, 360, 30, "")
ButtonGadget(#Bouton1, 10, 50, 360, 80, "")
ManageEventInit()
ManageEventGadget(#Texte1,#Focus,@Bip())
ManageEventGadget(#Texte1,#LFocus,@Bop())
ManageEventGadget(#Texte1,#Change,@Tap())
ManageEventGadget(#Bouton1,#LClick,@Bup())
ManageEventDebug(#True)
ManageEventStart()