Page 2 of 2

Posted: Mon Sep 26, 2005 12:01 am
by Tommeh
I have to say, some of your codes there show you are very very clever, congrats and you are an awesome credit to the PB community, thanks very much =]

PS: English comments would be even more helpfull :p, love the stuff on Nnetworks

Posted: Mon Sep 26, 2005 12:24 am
by rsts
Wow, what a treasure trove.

Thanks for sharing these.

Posted: Mon Sep 26, 2005 6:00 pm
by Kale
:shock:

Posted: Sat Jan 21, 2006 5:14 pm
by remi_meier
Just translated some comments to English (really fast, so please forgive
some mistakes) if you are still interested :wink:

Posted: Sat Jan 21, 2006 5:27 pm
by Dare2
Wow.

How did I miss this earlier! Mega code!
remi_meier wrote: :lol: Yes, but not as pompous as this.
And a sense of humour as well.
:D

Posted: Sat Jan 21, 2006 6:17 pm
by remi_meier
Thx!

Just another code I didn't post here before. A framework for event driven
programming (like VB I think, although I don't know VB by myself). A
translated reference is added below the code.

Code: Select all

Structure EOP_MENU
  *ParentWindow.EOP_WINDOW
  
  *NextMenu.EOP_MENU
  *PreviousMenu.EOP_MENU
  
  MenuItemID.l
  *fChosen
EndStructure

Structure EOP_GADGET_FUNCS
  *fLeftClick
  *fRightClick
  *fLeftDoubleClick
  *fRightDoubleClick
  *fFocus
  *fLostFocus
  *fChange
EndStructure

Structure EOP_GADGET Extends EOP_GADGET_FUNCS
  *ParentWindow.EOP_WINDOW
  
  *NextGadget.EOP_GADGET
  *PreviousGadget.EOP_GADGET
  
  GadgetID.l
EndStructure

Structure EOP_WINDOW_FUNCS
  *fMenu
  *fGadget
  *fCloseWindow
  *fRepaint
  *fSizeWindow
  *fMoveWindow
EndStructure

Structure EOP_WINDOW Extends EOP_WINDOW_FUNCS
  *NextWindow.EOP_WINDOW
  *PreviousWindow.EOP_WINDOW
  *CurrentWindow.EOP_WINDOW
  
  *Gadget.EOP_GADGET
  *CurrentGadget.EOP_GADGET
  
  *Menu.EOP_MENU
  *CurrentMenu.EOP_MENU
  
  WindowID.l
EndStructure




Procedure _EOP_NewGadget()
  ProcedureReturn AllocateMemory(SizeOf(EOP_GADGET))
EndProcedure

Procedure _EOP_NewMenu()
  ProcedureReturn AllocateMemory(SizeOf(EOP_MENU))
EndProcedure

Procedure _EOP_NewWindow()
  ProcedureReturn AllocateMemory(SizeOf(EOP_WINDOW))
EndProcedure


Procedure EOP_AddWindow(*EOP.EOP_WINDOW, Window.l)
  Protected *p.EOP_WINDOW, *n.EOP_WINDOW
  
  *p = *EOP\CurrentWindow
  
  If *p\NextWindow = #Null
    ; Add
    *p\NextWindow                 = _EOP_NewWindow()
    *EOP\CurrentWindow            = *p\NextWindow
    *p\NextWindow\PreviousWindow  = *p
    *p\NextWindow\WindowID        = Window
  Else
    ; Insert
    *n = _EOP_NewWindow()
    *n\PreviousWindow             = *p
    *n\NextWindow                 = *p\NextWindow
    *n\WindowID                   = Window
    
    *p\NextWindow\PreviousWindow  = *n
    *p\NextWindow                 = *n
    *EOP\CurrentWindow            = *n
  EndIf
  
  ProcedureReturn *p\NextWindow
EndProcedure

Procedure EOP_RemoveWindow(*EOP.EOP_WINDOW, Window.l)
  Protected *Win.EOP_WINDOW, *Gad.EOP_GADGET, *Men.EOP_MENU
  
  If *EOP\WindowID = Window
    Debug "Error: You are not allowed to remove the EOP-Window!"
    ProcedureReturn #False
  EndIf
  
  ; Window suchen
  If *EOP\NextWindow = #Null
    Debug "Error: This window does not exist!"
    ProcedureReturn #False
  EndIf
  *Win = *EOP\NextWindow
  While *Win\WindowID <> Window And *Win\NextWindow <> #Null
    *Win = *Win\NextWindow
  Wend
  
  If *Win\WindowID = Window
    If *EOP\CurrentWindow = *Win\WindowID
      *EOP\CurrentWindow = *Win\PreviousWindow
    EndIf
    
    If *Win\NextWindow <> #Null
      *Win\NextWindow\PreviousWindow = *Win\PreviousWindow
    EndIf
    *Win\PreviousWindow\NextWindow = *Win\NextWindow
    
    ; Gadget-Liste dieses Fensters löschen
    If *Win\Gadget
      *Gad = *Win\Gadget
      While *Gad\NextGadget
        *Gad = *Gad\NextGadget
        If *Gad\PreviousGadget <> #Null
          FreeMemory(*Gad\PreviousGadget)
        EndIf
      Wend
      FreeMemory(*Gad)
    EndIf
    
    ; Menu-Liste dieses Fensters löschen
    If *Win\Menu
      *Men = *Win\Menu
      While *Men\NextMenu
        *Men = *Men\NextMenu
        If *Men\PreviousMenu <> #Null
          FreeMemory(*Men\PreviousMenu)
        EndIf
      Wend
      FreeMemory(*Men)
    EndIf
    
    FreeMemory(*Win)
  Else
    Debug "Warning: Could not find this window."
    ProcedureReturn #False
  EndIf
  
  ProcedureReturn #True
EndProcedure

Procedure EOP_SetCurrentWindow(*EOP.EOP_WINDOW, Window.l)
  Protected *Win.EOP_WINDOW
  
  If *EOP\WindowID = Window
    *EOP\CurrentWindow = *EOP
    
    ProcedureReturn #True
  Else
    
    ; Window suchen
    If *EOP\NextWindow = #Null
      ProcedureReturn #False
    EndIf
    
    *Win = *EOP\NextWindow
    While *Win\WindowID <> Window And *Win\NextWindow <> #Null
      *Win = *Win\NextWindow
    Wend
    
    If *Win\WindowID = Window
      *EOP\CurrentWindow = *Win
      
      ProcedureReturn #True
    EndIf
  EndIf
  
  ProcedureReturn #False
EndProcedure

Procedure EOP_AddGadget(*EOP.EOP_WINDOW, Gadget.l)
  Protected *p.EOP_WINDOW, *g.EOP_GADGET, *n.EOP_GADGET
  
  *p = *EOP\CurrentWindow
  
  *g = *p\CurrentGadget
  If *g = #Null
    *p\Gadget         = _EOP_NewGadget()
    *p\CurrentGadget  = *p\Gadget
    *g                = *p\Gadget
    *g\PreviousGadget = #Null
  Else
    If *g\NextGadget = #Null
      ; Adden
      *g\NextGadget                 = _EOP_NewGadget()
      *p\CurrentGadget              = *g\NextGadget
      *g\NextGadget\PreviousGadget  = *g
      *g                            = *g\NextGadget
    Else
      ; Inserten
      *n                            = *g\NextGadget
      *g\NextGadget                 = _EOP_NewGadget()
      *p\CurrentGadget              = *g\NextGadget
      *g\NextGadget\PreviousGadget  = *g
      *g                            = *g\NextGadget
      *g\NextGadget                 = *n
      *n\PreviousGadget             = *g
    EndIf
  EndIf
  
  *g\ParentWindow = *p
  *g\GadgetID     = Gadget
  
  ProcedureReturn *g
EndProcedure

Procedure EOP_RemoveGadget(*EOP.EOP_WINDOW, Gadget.l)
  Protected *Win.EOP_WINDOW, *Gad.EOP_GADGET
  
  If *EOP <> #Null
    *Win = *EOP
    While *Win\NextWindow <> #Null
      If *Win\Gadget <> #Null
        ; Gadget in der Liste suchen
        *Gad = *Win\Gadget
        While *Gad\GadgetID <> Gadget And *Gad\NextGadget <> #Null
          *Gad = *Gad\NextGadget
        Wend
        
        If *Gad\GadgetID = Gadget
          If *Gad\NextGadget <> #Null
            *Gad\NextGadget\PreviousGadget = *Gad\PreviousGadget
          EndIf
          If *Gad\PreviousGadget <> #Null
            *Gad\PreviousGadget\NextGadget = *Gad\NextGadget
          EndIf
          If *Win\CurrentGadget = *Gad
            If *Gad\PreviousGadget <> #Null
              *Win\CurrentGadget = *Gad\PreviousGadget
            ElseIf *Gad\NextGadget <> #Null
              *Win\CurrentGadget = *Gad\NextGadget
            Else
              *Win\CurrentGadget = #Null
            EndIf
          EndIf
          
          FreeMemory(*Gad)
          Break
        EndIf
      EndIf
      
      *Win = *Win\NextWindow
    Wend
    
  Else
    Debug "Error: *EOP - Pointer ist NULL!"
    ProcedureReturn #False
  EndIf
  
  ProcedureReturn #True
EndProcedure

Procedure EOP_SetCurrentGadget(*EOP.EOP_WINDOW, Gadget.l)
  Protected *Win.EOP_WINDOW, *Gad.EOP_GADGET
  
  If *EOP <> #Null
    *Win = *EOP
    While *Win\NextWindow <> #Null
      If *Win\Gadget <> #Null
        ; Gadget in der Liste suchen
        *Gad = *Win\Gadget
        While *Gad\GadgetID <> Gadget And *Gad\NextGadget <> #Null
          *Gad = *Gad\NextGadget
        Wend
        
        If *Gad\GadgetID = Gadget
          *EOP\CurrentWindow = *Win
          *Win\CurrentGadget = *Gad
          Break
        EndIf
      EndIf
      
      *Win = *Win\NextWindow
    Wend
    
  Else
    Debug "Error: *EOP - Pointer ist NULL!"
    ProcedureReturn #False
  EndIf
EndProcedure

Procedure EOP_AddMenuItem(*EOP.EOP_WINDOW, MenuItem.l, *CallProcAddress)
  Protected *p.EOP_WINDOW, *m.EOP_MENU, *n.EOP_MENU
  
  *p = *EOP\CurrentWindow
  
  *m = *p\CurrentMenu
  If *m = #Null
    *p\Menu         = _EOP_NewMenu()
    *p\CurrentMenu  = *p\Menu
    *m              = *p\Menu
    *m\PreviousMenu = #Null
  Else
    If *m\NextMenu = #Null
      ; Adden
      *m\NextMenu               = _EOP_NewMenu()
      *p\CurrentMenu            = *m\NextMenu
      *m\NextMenu\PreviousMenu  = *m
      *m                        = *m\NextMenu
    Else
      ; Inserten
      *n                        = *m\NextMenu
      *m\NextMenu               = _EOP_NewMenu()
      *p\CurrentMenu            = *m\NextMenu
      *m\NextMenu\PreviousMenu  = *m
      *m                        = *m\NextMenu
      *m\NextMenu               = *n
      *n\PreviousMenu           = *m
    EndIf
  EndIf
  
  *m\ParentWindow = *p
  *m\MenuItemID   = MenuItem
  *m\fChosen      = *CallProcAddress
  
  ProcedureReturn *m
EndProcedure

Procedure EOP_RemoveMenuItem(*EOP.EOP_WINDOW, MenuItem.l)
  Protected *Win.EOP_WINDOW, *Men.EOP_MENU
  
  If *EOP <> #Null
    *Win = *EOP
    While *Win\NextWindow <> #Null
      If *Win\Menu <> #Null
        ; Menu in der Liste suchen
        *Men = *Win\Menu
        While *Men\MenuItemID <> MenuItem And *Men\NextMenu <> #Null
          *Men = *Men\NextMenu
        Wend
        
        If *Men\MenuItemID = MenuItem
          If *Men\NextMenu <> #Null
            *Men\NextMenu\PreviousMenu = *Men\PreviousMenu
          EndIf
          If *Men\PreviousMenu <> #Null
            *Men\PreviousMenu\NextMenu = *Men\NextMenu
          EndIf
          If *Win\CurrentMenu = *Men
            If *Men\PreviousMenu <> #Null
              *Win\CurrentMenu = *Men\PreviousMenu
            ElseIf *Men\NextMenu <> #Null
              *Win\CurrentMenu = *Men\NextMenu
            Else
              *Win\CurrentMenu = #Null
            EndIf
          EndIf
          
          FreeMemory(*Men)
          Break
        EndIf
      EndIf
      
      *Win = *Win\NextWindow
    Wend
    
  Else
    Debug "Error: *EOP - Pointer ist NULL!"
    ProcedureReturn #False
  EndIf
  
  ProcedureReturn #True
EndProcedure

Procedure EOP_SetCurrentMenuItem(*EOP.EOP_WINDOW, MenuItem.l)
  Protected *Win.EOP_WINDOW, *Men.EOP_MENU
  
  If *EOP <> #Null
    *Win = *EOP
    While *Win\NextWindow <> #Null
      If *Win\Menu <> #Null
        ; Menu in der Liste suchen
        *Men = *Win\Menu
        While *Men\MenuItemID <> MenuItem And *Men\NextMenu <> #Null
          *Men = *Men\NextMenu
        Wend
        
        If *Men\MenuItemID = MenuItem
          *EOP\CurrentWindow = *Win
          *Win\CurrentMenu   = *Men
          Break
        EndIf
      EndIf
      
      *Win = *Win\NextWindow
    Wend
    
  Else
    Debug "Error: *EOP - Pointer ist NULL!"
    ProcedureReturn #False
  EndIf
EndProcedure

Procedure EOP_RegisterMenuItemFunction(*EOP.EOP_WINDOW, *CallProcAddress)
  *EOP\CurrentMenu\fChosen = *CallProcAddress
EndProcedure

Procedure EOP_RegisterGadgetFunctions(*EOP.EOP_WINDOW, *Funcs.EOP_GADGET_FUNCS)
  *EOP\CurrentGadget\fLeftClick         = *Funcs\fLeftClick
  *EOP\CurrentGadget\fRightClick        = *Funcs\fRightClick
  *EOP\CurrentGadget\fLeftDoubleClick   = *Funcs\fLeftDoubleClick
  *EOP\CurrentGadget\fRightDoubleClick  = *Funcs\fRightDoubleClick
  *EOP\CurrentGadget\fFocus             = *Funcs\fFocus
  *EOP\CurrentGadget\fLostFocus         = *Funcs\fLostFocus
  *EOP\CurrentGadget\fChange            = *Funcs\fChange
EndProcedure

Procedure EOP_RegisterWindowFunctions(*EOP.EOP_WINDOW, *Funcs.EOP_WINDOW_FUNCS)
  *EOP\CurrentWindow\fMenu        = *Funcs\fMenu
  *EOP\CurrentWindow\fGadget      = *Funcs\fGadget
  *EOP\CurrentWindow\fCloseWindow = *Funcs\fCloseWindow
  *EOP\CurrentWindow\fRepaint     = *Funcs\fRepaint
  *EOP\CurrentWindow\fSizeWindow  = *Funcs\fSizeWindow
  *EOP\CurrentWindow\fMoveWindow  = *Funcs\fMoveWindow
EndProcedure


; Returns Pointer to EOP_WINDOW -> *EOP
Procedure EOP_Create(Window.l)
  Protected *p.EOP_WINDOW
  
  *p = _EOP_NewWindow()
  *p\NextWindow     = #Null
  *p\PreviousWindow = #Null
  *p\CurrentWindow  = *p
  *p\Gadget         = #Null
  *p\CurrentGadget  = #Null
  *p\Menu           = #Null
  *p\WindowID       = Window
  
  ProcedureReturn *p
EndProcedure

Procedure EOP_Delete(*EOP.EOP_WINDOW)
  Protected *Win.EOP_WINDOW, *Gad.EOP_GADGET, *Men.EOP_MENU
  
  If *EOP\NextWindow <> #Null
    
    *Win = *EOP\NextWindow
    While *Win\NextWindow <> #Null
      
      ; Gadget-Liste dieses Fensters löschen
      If *Win\Gadget
        *Gad = *Win\Gadget
        While *Gad\NextGadget
          *Gad = *Gad\NextGadget
          If *Gad\PreviousGadget <> #Null
            FreeMemory(*Gad\PreviousGadget)
          EndIf
        Wend
        FreeMemory(*Gad)
      EndIf
      
      ; Menu-Liste dieses Fensters löschen
      If *Win\Menu
        *Men = *Win\Menu
        While *Men\NextMenu
          *Men = *Men\NextMenu
          If *Men\PreviousMenu <> #Null
            FreeMemory(*Men\PreviousMenu)
          EndIf
        Wend
        FreeMemory(*Men)
      EndIf
      
      *Win = *Win\NextWindow
      FreeMemory(*Win\PreviousWindow)
    Wend
    FreeMemory(*Win\PreviousWindow)
  Else
    FreeMemory(*EOP)
  EndIf
  
EndProcedure

Procedure EOP_ProcessEvents(*EOP.EOP_WINDOW, WindowEvent.l, WindowID.l, GadgetID.l, MenuItemID.l, EventType.l)
  Protected *Win.EOP_WINDOW, *Gad.EOP_GADGET, *Men.EOP_MENU
  
  ; Fenster finden
  If *EOP = #Null
    ProcedureReturn WindowEvent
  EndIf
  
  *Win = *EOP
  While *Win\WindowID <> WindowID And *Win\NextWindow <> #Null
    *Win = *Win\NextWindow
  Wend
  
  If *Win\WindowID = WindowID
    Select WindowEvent
      Case #PB_Event_Menu
        If *Win\fMenu <> #Null
          CallFunctionFast(*Win\fMenu)
        EndIf
      Case #PB_Event_Gadget
        If *Win\fGadget <> #Null
          CallFunctionFast(*Win\fGadget)
        EndIf
      Case #PB_Event_CloseWindow
        If *Win\fCloseWindow <> #Null
          CallFunctionFast(*Win\fCloseWindow)
        EndIf
      Case #PB_Event_Repaint
        If *Win\fRepaint <> #Null
          CallFunctionFast(*Win\fRepaint)
        EndIf
      Case #PB_Event_SizeWindow
        If *Win\fSizeWindow <> #Null
          CallFunctionFast(*Win\fSizeWindow)
        EndIf
      Case #PB_Event_MoveWindow
        If *Win\fMoveWindow <> #Null
          CallFunctionFast(*Win\fMoveWindow)
        EndIf
    EndSelect
    
    ; Gadget finden
    If *Win\Gadget = #Null
      ProcedureReturn WindowEvent
    EndIf
    
    *Gad = *Win\Gadget
    While *Gad\GadgetID <> GadgetID And *Gad\NextGadget <> #Null
      *Gad = *Gad\NextGadget
    Wend
    
    If *Gad\GadgetID = GadgetID
      Select EventType
        Case #PB_EventType_LeftClick
          If *Gad\fLeftClick <> #Null
            CallFunctionFast(*Gad\fLeftClick)
          EndIf
        Case #PB_EventType_RightClick
          If *Gad\fRightClick <> #Null
            CallFunctionFast(*Gad\fRightClick)
          EndIf
        Case #PB_EventType_LeftDoubleClick
          If *Gad\fLeftDoubleClick <> #Null
            CallFunctionFast(*Gad\fLeftDoubleClick)
          EndIf
        Case #PB_EventType_RightDoubleClick
          If *Gad\fRightDoubleClick <> #Null
            CallFunctionFast(*Gad\fRightDoubleClick)
          EndIf
        Case #PB_EventType_Focus
          If *Gad\fFocus <> #Null
            CallFunctionFast(*Gad\fFocus)
          EndIf
        Case #PB_EventType_LostFocus
          If *Gad\fLostFocus <> #Null
            CallFunctionFast(*Gad\fLostFocus)
          EndIf
        Case #PB_EventType_Change
          If *Gad\fChange <> #Null
            CallFunctionFast(*Gad\fChange)
          EndIf
      EndSelect
    EndIf
    
    ; Menu finden
    If *Win\Menu = #Null
      ProcedureReturn WindowEvent
    EndIf
    
    *Men = *Win\Menu
    While *Men\MenuItemID <> MenuItemID And *Men\NextMenu <> #Null
      *Men = *Men\NextMenu
    Wend
    
    If *Men\MenuItemID = MenuItemID
      If *Men\fChosen <> #Null
        CallFunctionFast(*Men\fChosen)
      EndIf
    EndIf
  EndIf
  
  
  ProcedureReturn WindowEvent
EndProcedure

Procedure EOP_WindowEvent(*EOP.EOP_WINDOW)
  Protected WindowEvent.l, WindowID.l, GadgetID.l, MenuItemID.l, EventType.l
  
  WindowEvent = WindowEvent()
  WindowID    = EventWindowID()
  GadgetID    = EventGadgetID()
  MenuItemID  = EventMenuID()
  EventType   = EventType()
  ProcedureReturn EOP_ProcessEvents(*EOP.EOP_WINDOW, WindowEvent, WindowID.l, GadgetID.l, MenuItemID.l, EventType.l)
EndProcedure

Procedure EOP_WaitWindowEvent(*EOP.EOP_WINDOW)
  Protected Res.l
  
  Repeat
    Delay(2)
    Res = EOP_WindowEvent(*EOP.EOP_WINDOW)
  Until Res
  
  ProcedureReturn Res
EndProcedure


; Data structure:
; I will just call it later 'EOP-Tree'
; 
; Window0-----------------Window1-----------------Window2----------. . . .
;   |    \               /    \                      |
; Menu1   Gadget1     Menu3   Gadget3             Gadget4
;   |        |          |
; Menu2   Gadget2     Menu4
;   |        |
;   .        .
;   .        .
;   .        .
; 
; 
; Function reference:
; 
; *EOP.EOP_WINDOW = EOP_Create(Window.l)
; This function creates the first object "Window0" and
; connects it with the first window, the main window,
; which is identified through Window.l.
; It returns the pointer to the first element of the EOP-Tree,
; out of this first element, everything will be coordinated,
; each EOP function needs this pointer except EOP_Create
; and the internally used _EOP_New***(). This pointer won't
; be modified by any function!

; EOP_Delete(*EOP.EOP_WINDOW)
; This function deletes the whole EOP-Tree, identified 
; through the pointer *EOP to the first element.

; EOP_SetCurrentWindow(*EOP.EOP_WINDOW, Window.l)
; Sets the window Window.l as the current window. That means
; all EOP_Add***() will be applied to this window and i. c.
; EOP_AddWindow() will add the window after the current one.

; EOP_SetCurrentMenuItem/Gadget()
; is the same as EOP_SetCurrentWindow() just for gadgets and
; MenuItems! With this you can modify the event functions of
; a Gadget/MenuItem later!

; EOP_AddWindow(*EOP.EOP_WINDOW, Window.l)
; This function works the same as EOP_Create(), but it doesn't
; create a new EOP-Tree, but adds a new window to the tree,
; EOP_AddGadget() and EOP_AddMenu() are underlying to this function.
; This function sets the current window to the newly added one.

; EOP_AddGadget(*EOP.EOP_WINDOW, Gadget.l)
; This function adds a new Gadget to the current window.
; Gadget.l is the PB handle for a gadget, i. c. #Button_0

; EOP_AddMenuItem(*EOP.EOP_WINDOW, MenuItem.l, *CallProcAddress)
; This function adds a new MenuItem to the current window.
; MenuItem.l is the PB handle for a menu item.
; *CallProcAddress is the address to the procedure which will be
; called in case of an event.

; EOP_Remove***(*EOP.EOP_WINDOW, ***.l)
; These functions remove the Gadget/MenuItem/Window and all its
; underlying things (MenuItems, Gadgets) in the EOP-Tree.

; EOP_RegisterGadgetFunctions(*EOP.EOP_WINDOW, *Funcs.EOP_GADGET_FUNCS)
; This functions registers the event procedures to the current Gadget.
; To do so, the following structure EOP_GADGET_FUNCS has to be passed
; to the function:
; Structure EOP_GADGET_FUNCS
;   *fLeftClick
;   *fRightClick
;   *fLeftDoubleClick
;   *fRightDoubleClick
;   *fFocus
;   *fLostFocus
;   *fChange
; EndStructure
; Don't forget that for some events on some gadgets you will have to
; use AdvancedEventGadgets() to enable them. And some don't even work.
; 
; These pointers have to be filled with addresses to procedures.
; If you don't want to register a function to a special event, you
; have to set its value to #NULL.
; ATTENTION! These functions mustn't take parameters!

; EOP_RegisterWindowFunctions(*EOP.EOP_WINDOW, *Funcs.EOP_WINDOW_FUNCS)
; This is the same function for window events.
; And EOP_RegisterMenuItemFunction() sets the function for the current
; MenuItem.

; EOP_WaitWindowEvent(*EOP.EOP_WINDOW)
; and EOP_WindowEvent(*EOP.EOP_WINDOW)
; are functions, which do the same as the ones from PB with the difference
; that they call the appropriate event function before they return the event.

; EOP_ProcessEvents(*EOP.EOP_WINDOW, WindowEvent.l, WindowID.l, GadgetID.l,
;                                                MenuItemID.l, EventType.l)
; Here you cann pass the event directly without using i. c. EOP_WindowEvent().
; For use with multiple EOP-Trees or if you want to raise an event.

; ####################################################################
; What you have to do:
; 
; 1.) Create window (with OpenWindow)
; 2.) Create new EOP-Tree (as many as you want)
;     *EOP = EOP_Create(Window.l)
; 3.) CreateGadgetList()
; 4.) Create gadgets (i.c. ButtonGadget(1, ...))
; 4.) Add gadget to EOP-Tree: EOP_AddGadget(*EOP, 1)
; 5.) Fill the structure for EOP_RegisterGadgetFunctions() with pointers
;     to function addresses.
; 6.) EOP_RegisterGadgetFunctions()
; 7.) Loop like:
;     Repeat 
;     Until EOP_WaitWindowEvent(*EOP) = #PB_Event_CloseWindow
; 8.) EOP_Delete(*EOP)

; You can also have as many EOP-Trees as you want. To do so, you have
; to change the event loop to something like this:
; Repeat
;   Event = EOP_WaitWindowEvent(*EOP1)
;   EOP_ProcessEvents(*EOP2, Event, 0, 0, 0, 0)
;   EOP_ProcessEvents(*EOP3, Event, 0, 0, 0, 0)
; Until Event = #PB_Event_CloseWindow


; It's all coded in PB, no WinApi, so don't expect it to do more than
; PB but expect it to work on all plattforms ;)
And two examples:

Code: Select all

Global *EOP.EOP_WINDOW

Procedure.s StrRep(s.s, Anz.l)
  Protected z.l, n.s
  
  For z = 1 To Anz
    n + s
  Next
   
  ProcedureReturn n
EndProcedure

Procedure O_o()
  Static s.l
  If s = 0
    v.s = "O_o did you push OK!?"
  ElseIf s = 1
    v.s = "Again??? WTF do you want?"
  ElseIf s = 2
    v.s = "You're bugging me! Go and die!"
  ElseIf s = 3
    v.s = "-_-*"
  ElseIf s < 9
    v.s = StrRep("o", s*3) + "k, I'll give you a new dummy!"
    ButtonGadget(s, (s - 3) * 55 + 5, (s - 3) * 55 + 5, 50, 50, "OK")
    EOP_AddGadget(*EOP, s)
    b.EOP_GADGET_FUNCS\fLeftClick = @O_o()
    EOP_RegisterGadgetFunctions(*EOP, @b)
  Else
    v.s = "Forget it..."
  EndIf
  MessageRequester("°_°", v)
  
  s + 1
EndProcedure

Procedure event_GadgetLeftClick()
  Protected GadgetID.l, EventType.l, WindowID.l
  
  GadgetID  = EventGadgetID()
  EventType = EventType()
  WindowID  = EventWindowID()
  
EndProcedure

Procedure event_Menu()
  Protected MenuItemID.l, WindowID.l
  
  MenuItemID  = EventMenuID()
  WindowID    = EventWindowID()
  
EndProcedure



AdvancedGadgetEvents(#True)
OpenWindow(0, 200,200, 500,500, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "EOP")
CreateGadgetList(WindowID())
ButtonGadget(1, 5,5, 50,50, "OK")

*EOP = EOP_Create(0)

Button1.EOP_GADGET_FUNCS\fLeftClick = @O_o()
EOP_AddGadget(*EOP, 1)
EOP_RegisterGadgetFunctions(*EOP, @Button1)

Repeat
  
Until EOP_WaitWindowEvent(*EOP) = #PB_Event_CloseWindow

EOP_Delete(*EOP)

Code: Select all

Enumeration 
  #frmMain 
  #myTextGadget 
  #myStringGadget 
  #myButtonGadget 
  #myCheckBoxGadget 
  #myOptionGadget 
  #Ausgabe 
EndEnumeration 

Global *EOP.EOP_WINDOW 

Procedure myButtonGadget_LeftClick() 
  AddGadgetItem(#Ausgabe, -1, "myButtonGadget_LeftClick") 
EndProcedure 

Procedure myButtonGadget_RightClick() 
  AddGadgetItem(#Ausgabe, -1, "myButtonGadget_RightClick") 
EndProcedure 

Procedure myButtonGadget_Focus() 
  AddGadgetItem(#Ausgabe, -1, "myButtonGadget_Focus") 
EndProcedure 

Procedure myButtonGadget_LostFocus() 
  AddGadgetItem(#Ausgabe, -1, "myButtonGadget_LostFocus") 
EndProcedure 

Procedure myTextGadget_LeftClick() 
  AddGadgetItem(#Ausgabe, -1, "myTextGadget_LeftClick") 
EndProcedure 

Procedure myTextGadget_RightClick() 
  AddGadgetItem(#Ausgabe, -1, "myTextGadget_RightClick") 
EndProcedure 

Procedure myStringGadget_LeftClick() 
  AddGadgetItem(#Ausgabe, -1, "myStringGadget_LeftClick") 
EndProcedure 

Procedure myStringGadget_RightClick() 
  AddGadgetItem(#Ausgabe, -1, "myStringGadget_RightClick") 
EndProcedure 

Procedure myStringGadget_Change() 
  AddGadgetItem(#Ausgabe, -1, "myStringGadget_Change") 
EndProcedure 

Procedure myStringGadget_Focus() 
  AddGadgetItem(#Ausgabe, -1, "myStringGadget_Focus") 
EndProcedure 

Procedure myStringGadget_LostFocus() 
  AddGadgetItem(#Ausgabe, -1, "myStringGadget_LostFocus") 
EndProcedure 

If OpenWindow(#frmMain, 302, 77, 414, 169,  #PB_Window_SystemMenu | #PB_Window_TitleBar , "EOP-Sample") 
  AdvancedGadgetEvents(#True)
  If CreateGadgetList(WindowID()) 
    
    TextGadget(#myTextGadget, 8, 8, 128, 24, "TextGadget", #PB_Text_Border | #SS_NOTIFY) ; #SS_NOTIFY ist wichtig 
    
    StringGadget(#myStringGadget, 8, 40, 128, 24, "StringGadget") 
    
    myStyle = GetWindowLong_(GadgetID(#myStringGadget), #GWL_STYLE) 
    newStyle = myStyle | #SS_NOTIFY 
    SetWindowLong_(GadgetID(#myStringGadget), #GWL_STYLE, newStyle) 
    
    
    ButtonGadget(#myButtonGadget, 8, 72, 128, 24, "ButtonGadget") 
    ; CheckBoxGadget(#myCheckBoxGadget, 8, 104, 128, 24, "CheckBoxGadget") 
    ; OptionGadget(#myOptionGadget, 8, 136, 128, 24, "OptionGadget") 
    EditorGadget(#Ausgabe, 144, 8, 264, 152, "") 
    
    *EOP = EOP_Create(0) 
    
    ; ButtonGadget 
    
    EOP_AddGadget(*EOP, #myButtonGadget) 
    myButtonGadget.EOP_GADGET_FUNCS\fLeftClick  = @myButtonGadget_LeftClick()     ; OK  
    myButtonGadget.EOP_GADGET_FUNCS\fRightClick = @myButtonGadget_RightClick()    ; ?? 
    myButtonGadget.EOP_GADGET_FUNCS\fFocus      = @myButtonGadget_Focus()         ; ?? 
    myButtonGadget.EOP_GADGET_FUNCS\fLostFocus  = @myButtonGadget_LostFocus()     ; ?? 
    EOP_RegisterGadgetFunctions(*EOP, @myButtonGadget) 
    
    ; TextGadget 
    
    EOP_AddGadget(*EOP, #myTextGadget) 
    myTextGadget.EOP_GADGET_FUNCS\fLeftClick = @myTextGadget_LeftClick()          ; Teilweise 
    myTextGadget.EOP_GADGET_FUNCS\fRightClick = @myTextGadget_RightClick()        ; ?? 
    EOP_RegisterGadgetFunctions(*EOP, @myTextGadget) 
    
    ; StringGadget 
    
    EOP_AddGadget(*EOP, #myStringGadget) 
    myStringGadget.EOP_GADGET_FUNCS\fLeftClick  = @myStringGadget_LeftClick()     ; ?? 
    myStringGadget.EOP_GADGET_FUNCS\fRightClick = @myStringGadget_RightClick()    ; ?? 
    myStringGadget.EOP_GADGET_FUNCS\fChange     = @myStringGadget_Change()        ; OK 
    myStringGadget.EOP_GADGET_FUNCS\fFocus      = @myStringGadget_Focus()         ; OK 
    myStringGadget.EOP_GADGET_FUNCS\fLostFocus  = @myStringGadget_LostFocus()     ; OK 
    EOP_RegisterGadgetFunctions(*EOP, @myStringGadget) 
    
    Repeat 
      
    Until EOP_WaitWindowEvent(*EOP) = #PB_Event_CloseWindow 
    
    EOP_Delete(*EOP) 
    
  EndIf 
  
EndIf

Posted: Sat Jan 21, 2006 7:32 pm
by josku_x
Wow! Not that's a piece of code!

Thanks remi_meier for sharing you absolutely rock!