FreeGadget() - Optional parameter for Window

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

FreeGadget() - Optional parameter for Window

Post by RSBasic »

Hello,

I hope this thread does not exist already and I wish this optional parameter for window:

Code: Select all

FreeGadget(#PB_All [, Window])
Image
Image
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: FreeGadget() - Optional parameter for Window

Post by bbanelli »

Would that even be possible if one is using #PB_Any for creation of gadgets?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: FreeGadget() - Optional parameter for Window

Post by mestnyi »

Code: Select all

DeclareModule Free
  EnableExplicit
  Declare Gadgets(Gadget = #PB_Any, Window = #PB_Any)
EndDeclareModule

Module Free
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Import ""
    CompilerElse
      ImportC ""
      CompilerEndIf
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
      
      PB_Gadget_Objects.i
    EndImport
    
    Procedure GadgetWindowID( Gadget )
    Protected GadgetWindowID, GadgetID
    
    If IsGadget( Gadget )
      GadgetID = GadgetID( Gadget )
      
      CompilerSelect #PB_Compiler_OS 
        CompilerCase #PB_OS_MacOS
          CompilerError #PB_Compiler_Procedure
        CompilerCase #PB_OS_Linux 
          GadgetWindowID = gtk_widget_get_toplevel_ ( GadgetID )
        CompilerCase #PB_OS_Windows
          While GadgetID 
            GadgetWindowID = GadgetID :GadgetID = GetParent_( GadgetID )
          Wend 
      CompilerEndSelect
      
      ProcedureReturn GadgetWindowID
    EndIf
  EndProcedure
  
    Procedure Gadgets(Gadget = #PB_Any, Window = #PB_Any)
      If Gadget = #PB_Any
        If PB_Gadget_Objects
          PB_Object_EnumerateStart(PB_Gadget_Objects)
          While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget)
            If IsWindow(Window) 
              If (WindowID(Window) ! GadgetWindowID( Gadget ))
                Continue
              EndIf
            EndIf
            FreeGadget(Gadget)
          Wend
          PB_Object_EnumerateAbort(PB_Gadget_Objects)
        EndIf
      Else
        FreeGadget(Gadget)
      EndIf
    EndProcedure
  EndModule
  
  Macro FreeGadget(Gadget = #PB_Any, Window = #PB_Any)
    Free::Gadgets(Gadget, Window)
  EndMacro
  
  CompilerIf #PB_Compiler_IsMainFile
    X = 100
    For i = 1 To 3
      OpenWindow(i, 200, X, 150, 60, "Window_" + Trim(Str(i)))
      ContainerGadget(100 * (i), 5, 5, 120,50, #PB_Container_Flat)
        ButtonGadget(10 * (i),10,10,100,15,"Button_" + Trim(Str(i*10)))
        ButtonGadget((i),10,25,100,15,"Button_" + Trim(Str(i)))
      CloseGadgetList() ; ContainerGadget
      X + 100
    Next :Window = 1
    
    FreeGadget(#PB_Any, 2)
    
    Repeat
      If IsWindow( Window )
        Event = WaitWindowEvent( )
        If Event = #PB_Event_CloseWindow
          CloseWindow( EventWindow( ) )
          Debug "Close " + EventWindow( )
        EndIf
      Else 
        Break
      EndIf
    ForEver
    
    Debug "Exit"
  CompilerEndIf
    
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: FreeGadget() - Optional parameter for Window

Post by Kurzer »

RSBasic wrote:Hello,

I hope this thread does not exist already and I wish this optional parameter for window:

Code: Select all

FreeGadget(#PB_All [, Window])
I was about to write the same feature request, so +1 from me.

Such a parameter is very handy, if a programm creates and destroy different gadget-layouts on the same window during runtime.
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: FreeGadget() - Optional parameter for Window

Post by mk-soft »

For MacOS

Code: Select all

      CompilerSelect #PB_Compiler_OS 
        CompilerCase #PB_OS_MacOS
          GadgetWindowID = WindowID(PeekI(IsGadget( Gadget ) + 4 * SizeOf(Integer)))
SDK

Code: Select all

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ;- PB Interne Struktur Gadget Windows
      Structure Gadget
        Gadget.i
        *vt.GadgetVT
        UserData.i
        OldCallback.i
        Daten.i[4]
      EndStructure
    CompilerCase #PB_OS_Linux
      ;- PB Interne Struktur Gadget Linux
      Structure Gadget
        Gadget.i
        GadgetContainer.i
        *vt.GadgetVT
        UserData.i
        Daten.i[4]
      EndStructure
    CompilerCase #PB_OS_MacOS
      ; PB Interne Struktur Gadget MAcOS
      Structure Gadget
        *gadget
        *container
        *vt.GadgetVT
        UserData.i
        WindowID.i
        Type.i
        Flags.i
      EndStructure
  CompilerEndSelect
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply