BindEvent() add #PB_All

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

BindEvent() add #PB_All

Post by mestnyi »

Code: Select all

  CompilerIf Not Defined( CountWindow, #PB_Function ) And
             Not Defined( CountWindow, #PB_Procedure )
    
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      Import ""
      CompilerElse
        ImportC ""
        CompilerEndIf
        
        PB_Object_Count( *Object )
        PB_Window_Objects.i
      EndImport
      
      ProcedureDLL CountWindow( )
        ProcedureReturn PB_Object_Count( PB_Window_Objects )
      EndProcedure 
    CompilerEndIf
  
ProcedureDLL BindPBEvent( Event, *EventCallBack, Window, Object, EventType ) ;Returns TRUE is purebasic event
  If Event = #PB_All
    BindEvent( #PB_Event_DeactivateWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_ActivateWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_LeftClick, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_CloseWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_FirstCustomValue, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_Gadget, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_GadgetDrop, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_LeftClick, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_LeftDoubleClick, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_MaximizeWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_Menu, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_MinimizeWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_MoveWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_Repaint, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_RestoreWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_RightClick, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_SizeWindow, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_SysTray, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_Timer, *EventCallBack, Window, Object, EventType)
    BindEvent( #PB_Event_WindowDrop, *EventCallBack, Window, Object, EventType)
  ;  BindEvent( #PB_Event_None, *EventCallBack, Window, Object, EventType)
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      BindEvent( #PB_Event_ClientConnected, *EventCallBack, Window, Object, EventType)
      BindEvent( #PB_Event_ClientDisconnected, *EventCallBack, Window, Object, EventType)
      BindEvent( #PB_Event_FileReceived, *EventCallBack, Window, Object, EventType)
    CompilerEndIf   
  Else
    BindEvent( Event, *EventCallBack, Window, Object, EventType)
  EndIf
EndProcedure
Macro BindEvent( Event, EventCallBack, Window =-1, Object =-1, EventType =-1) 
  BindPBEvent( Event, EventCallBack, Window, Object, EventType ) 
EndMacro

Procedure WindowCallBack()
  Select Event() ; WaitWindowEvent()
    Case #PB_Event_ActivateWindow
      Debug "#PB_Event_ActivateWindow "+EventWindow()
    Case #PB_Event_MoveWindow
    Debug "#PB_Event_MoveWindow "+EventWindow()
    Case #PB_Event_SizeWindow
      Debug "#PB_Event_SizeWindow "+EventWindow()
    Case #PB_Event_DeactivateWindow
      Debug "#PB_Event_DeactivateWindow "+EventWindow()
    Case #PB_Event_CloseWindow
      Debug "#PB_Event_CloseWindow "+EventWindow()
      CloseWindow(EventWindow())
  EndSelect
EndProcedure

Procedure CreateWindow(ParentID=0,Flag = #PB_Window_SystemMenu|#PB_Window_SizeGadget)
  Static Count, Window =-1
  Protected W=400,H=300
   BindEvent( #PB_All, @WindowCallBack(), Window )
   Window = OpenWindow(#PB_Any,0,0, W,H, "Window_"+Str(Count),Flag, ParentID) 
   
   ProcedureReturn Window  
EndProcedure

Window = CreateWindow()

ResizeWindow(Window,#PB_Ignore,#PB_Ignore,300,300)
ResizeWindow(Window,300,300,#PB_Ignore,#PB_Ignore)

      
Repeat
  If CountWindow()
    WaitWindowEvent()
  Else
    Break
  EndIf
ForEver
Last edited by mestnyi on Fri Apr 08, 2022 2:20 pm, edited 1 time in total.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: BindEvent() add #PB_All

Post by jacdelad »

I know this is a bit older, but I would like to push this. I think it's a logical thing to be able to do this natively (and recently wondered why it wasn't possible).
Also the respective UnbindEvent()-extension would be great, with #PB_All to unbind all bindings, even if not #PB_All was used to bind them.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: BindEvent() add #PB_All

Post by Rinzwind »

User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: BindEvent() add #PB_All

Post by jacdelad »

No. I/We want #PB_All for the first parameter.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply