Page 1 of 1

GadgetManager for all OS

Posted: Sun May 10, 2015 4:07 pm
by mk-soft
Advanced purebasic with some requested features. ParentGadget, ParentWindow, IDFromHandle, etc.
For this purpose all the necessary features of PureBasic are diverted via macros and the required data is stored in a recursive list.

Functions Gadget Manager
-----------------------
ParentGadget(gadget) ; Result: GadgetID, Not exists = -1
ParentWindow(gadget) ; Result: WindowID, Not exists = -1

GadgetIDFromHandle(handle) ; Result: GadgetID, Not found = -1
WindowIDFromHandle(handle) ; Result: WindowID, Not found = - 1

GetGlobalGadgetData(gadget) ; Result: Pointer to GadgetData Object, Not found = 0
GetUserGadgetData(gadget) ; Result: Pointer to UserGadgetData Object, Not found = 0

SetFreeGadgetCallback(gadget, *callback) ; Result: Pointer to previous callback function, CloseWindow required

Code: Select all

Procedure MyFreeGadgetCB(*this.gm_GadgetData)
  Debug "Destroy Gadget " + Str(*this\id)
EndProcedure
Functions Image Manager
----------------------
ImageIDFromHandle(handle)

Update v1.02
bugfix: RemoveGadgetItem(). Internal Item for PanelGadget
bugfix: OpenWindow with same WindowID

GadgetManager_v102.pbi

Code: Select all

;-TOP
; Comment       : Gadget Manager
; Author        : mk-soft
; Second Author : 
; File          : GadgetManager.pbi
; Version       : 1.021
; Created       : 01.04.2015
; Modified      : 10.05.2015
; 
; Compilermode  : All
; OS            : All
;
; ***************************************************************************************

; ***************************************************************************************

; EnableExplicit

;- Functions Gadget Manager 
Declare ParentGadget(gadget) ; Result: GadgetID, Not exists = -1
Declare ParentWindow(gadget) ; Result: WindowID, Not exists = -1

Declare GadgetIDFromHandle(handle) ; Result: GadgetID, Not found = -1
Declare WindowIDFromHandle(handle) ; Result: WindowID, Not found = - 1

Declare GetGlobalGadgetData(gadget) ; Result: Pointer to GadgetData Object, Not found = 0
Declare GetUserGadgetData(gadget)   ; Result: Pointer to UserGadgetData Object, Not found = 0

Declare SetFreeGadgetCallback(gadget, *callback) ; Result: Pointer to previous callbackfunction, CloseWindow required

; ---------------------------------------------------------------------------------------

;- Functions Image Manager
Declare ImageIDFromHandle(handle)

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;- *** Window und Gadget Objects ***

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Globale Variablen und Strukturen

Prototype gm_FreeGadgetCallback(*this)

Structure gm_GadgetData ; Data Objects
  ; Header
  *parent.gm_GadgetData
  type.i
  handle.i
  id.i
  item.i
  List Gadgets.gm_GadgetData()
  ; Function
  FreeGadgetCB.gm_FreeGadgetCallback
  ; Gadget Initial Data
  x.i
  y.i
  dx.i
  dy.i
  text.s
  param1.i
  param2.i
  param3.i
  flags.i
  ; UserData
  CompilerIf Defined(UserGadgetData, #PB_Structure)
    user.UserGadgetData
  CompilerEndIf
EndStructure

Global NewList gm_ListWindow.gm_GadgetData()
Define *gm_GadgetList.gm_GadgetData
Define gm_GadgetItem = -1

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Interne recursive Funktionen

Procedure gm_CallFreeGadgetCB(List GList.gm_GadgetData())
  
  ForEach GList()
    If ListSize(GList()\Gadgets())
      gm_CallFreeGadgetCB(Glist()\Gadgets())
    EndIf
    If Glist()\FreeGadgetCB
      Glist()\FreeGadgetCB(GList())
    EndIf
  Next
  
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure gm_DeleteGadgetData(List GList.gm_GadgetData(), gadget)
  
  Protected result
  
  result = #False
  
  ForEach GList()
    If GList()\id = gadget
      gm_CallFreeGadgetCB(GList()\Gadgets())
      If Glist()\FreeGadgetCB
        Glist()\FreeGadgetCB(GList())
      EndIf
      DeleteElement(GList())
      LastElement(GList())
      result = #True
      Break
    ElseIf ListSize(GList()\Gadgets())
      result = gm_DeleteGadgetData(Glist()\Gadgets(), gadget)
      If result
        Break
      EndIf
    EndIf
  Next
  
  ProcedureReturn result
  
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure gm_FindGadgetData(List GList.gm_GadgetData(), gadget)
  
  Protected *result
  
  *result = 0
  
  ForEach GList()
    If GList()\id = gadget
      *result = GList()
      Break
    ElseIf ListSize(GList()\Gadgets())
      *result = gm_FindGadgetData(Glist()\Gadgets(), gadget)
      If *result
        Break
      EndIf
    EndIf
  Next
  
  ProcedureReturn *result
  
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure gm_FindGadgetDataFromHandle(List GList.gm_GadgetData(), handle)
  
  Protected *result
  
  *result = 0
  
  ForEach GList()
    If GList()\handle = handle
      *result = GList()
      Break
    ElseIf ListSize(GList()\Gadgets())
      *result = gm_FindGadgetDataFromHandle(Glist()\Gadgets(), handle)
      If *result
        Break
      EndIf
    EndIf
  Next
  
  ProcedureReturn *result
  
EndProcedure

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Umgeleitete Window Funktionen

Procedure gm_UseGadgetList(WindowID)
  
  Protected result
  Shared *gm_GadgetList
  
  result = UseGadgetList(WindowID)
  If result
    ForEach gm_ListWindow()
      If gm_ListWindow()\handle = WindowID
        *gm_GadgetList = gm_ListWindow()
        Break
      EndIf
    Next
  EndIf
  
  ProcedureReturn result
  
EndProcedure

Macro UseGadgetList(WindowID)
  gm_UseGadgetList(WindowID)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure gm_CloseWindow(Window)
  
  ForEach gm_ListWindow()
    If gm_ListWindow()\id = Window
      gm_CallFreeGadgetCB(gm_ListWindow()\Gadgets())
      DeleteElement(gm_ListWindow())
      Break
    EndIf
  Next
  
  CloseWindow(Window)
  
EndProcedure

Macro CloseWindow(Window)
  gm_CloseWindow(Window)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure gm_FreeGadget(Gadget)
  
  ForEach gm_ListWindow()
    If gm_DeleteGadgetData(gm_ListWindow()\Gadgets(), gadget)
      Break
    EndIf
  Next
  
  FreeGadget(Gadget)
  
EndProcedure

Macro FreeGadget(Gadget)
  gm_FreeGadget(Gadget)
EndMacro

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Umgeleitete Gadget Funktionen

Procedure gm_OpenGadgetList(gadget, item)
  
  Shared *gm_GadgetList.gm_GadgetData, gm_GadgetItem
  
  Protected *result
  
  ForEach gm_ListWindow()
    *result = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
    If *result
      *gm_GadgetList = *result
      Break
    EndIf
  Next
  If item >= 0
    OpenGadgetList(gadget, item)
    If GadgetType(gadget) = #PB_GadgetType_Panel
      gm_GadgetItem = item
    EndIf
  Else
    OpenGadgetList(gadget)
  EndIf
  
EndProcedure

Macro OpenGadgetList(gadget, item = -1)
  gm_OpenGadgetList(gadget, item)
EndMacro


; ---------------------------------------------------------------------------------------

Procedure gm_CloseGadgetList()
  
  Shared *gm_GadgetList.gm_GadgetData, gm_GadgetItem
  
  If *gm_GadgetList\parent
    *gm_GadgetList = *gm_GadgetList\parent
  EndIf
  
  gm_GadgetItem = -1
  
  CloseGadgetList()
  
EndProcedure

Macro CloseGadgetList()
  gm_CloseGadgetList()
EndMacro

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Umgeleitete GadgetItem Funktionen

Procedure gm_AddGadgetItem(gadget, position, text.s, imageid = 0, flags = 0)
  
  Shared gm_GadgetItem
  
  Protected result, *gm_List.gm_GadgetData
  
  If GadgetType(gadget) = #PB_GadgetType_Panel
    If position = -1
      gm_GadgetItem = CountGadgetItems(gadget)
    Else
      gm_GadgetItem = position
      ForEach gm_ListWindow()
        *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
        If *gm_List
          Break
        EndIf
      Next
      ; Item anpassen
      ForEach *gm_List\Gadgets()
        If *gm_List\Gadgets()\item >= position
          *gm_List\Gadgets()\item + 1
        EndIf
      Next
    EndIf
  EndIf
  
  result = AddGadgetItem(gadget, position, text.s, imageid, flags)
  
  ProcedureReturn result
  
EndProcedure

Macro AddGadgetItem(gadget, position, text, imageid = 0, flags = 0)
  gm_AddGadgetItem(gadget, position, text, imageid, flags)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure gm_RemoveGadgetItem(gadget, position)
  
  Protected *gm_List.gm_GadgetData
  
  If GadgetType(gadget) = #PB_GadgetType_Panel
    ForEach gm_ListWindow()
      *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
      If *gm_List
        Break
      EndIf
    Next
    ForEach *gm_List\Gadgets()
      If *gm_List\Gadgets()\item = position
        gm_CallFreeGadgetCB(*gm_List\Gadgets()\Gadgets())
        If *gm_List\Gadgets()\FreeGadgetCB
          *gm_List\Gadgets()\FreeGadgetCB(*gm_List\Gadgets())
        EndIf
        DeleteElement(*gm_List\Gadgets(), 1)
      EndIf
    Next
    RemoveGadgetItem(gadget, position)
    ; Item anpassen
    ForEach *gm_List\Gadgets()
      If *gm_List\Gadgets()\item >= position
        *gm_List\Gadgets()\item - 1
      EndIf
    Next
  Else
    RemoveGadgetItem(gadget, position)
  EndIf
    
EndProcedure

Macro RemoveGadgetItem(gadget, position)
  gm_RemoveGadgetItem(gadget, position)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure gm_ClearGadgetItems(gadget)
  
  Protected *gm_List.gm_GadgetData
  
  If GadgetType(gadget) = #PB_GadgetType_Panel
    ForEach gm_ListWindow()
      *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
      If *gm_List
        Break
      EndIf
    Next
    gm_CallFreeGadgetCB(*gm_List\Gadgets())
    ClearList(*gm_List\Gadgets())
  EndIf
  ClearGadgetItems(gadget)
  
EndProcedure

Macro ClearGadgetItems(gadget)
  gm_ClearGadgetItems(gadget)
EndMacro

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Umgeleitete Funktionen

Procedure gm_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Titel.s, Flags = #PB_Window_SystemMenu, ParentWindowID = 0)
  
  Shared *gm_GadgetList.gm_GadgetData
  
  Protected result, handle, id
  
  If IsWindow(Window)
    CloseWindow(Window)
  EndIf
  
  result = OpenWindow(Window, x, y, InnerWidth, InnerHeight, Titel.s, Flags, ParentWindowID)
  
  If result = 0
    ProcedureReturn 0
  EndIf
  
  If Window = #PB_Any
    handle = WindowID(result)
    id = result
  Else
    handle = WindowID(Window)
    id = Window
  EndIf
  
  ForEach gm_ListWindow()
    If gm_ListWindow()\id = Window
      DeleteElement(gm_ListWindow())
      Break
    EndIf
  Next
  
  *gm_GadgetList = AddElement(gm_ListWindow())
  With gm_ListWindow()
    \type = -1
    \handle = handle
    \id = id
    \item = 0
    \x = x
    \y = y
    \dx = InnerWidth
    \dy = InnerHeight
    \text = Titel
    \flags = Flags
  EndWith
  ProcedureReturn result
  
EndProcedure

Macro OpenWindow(Window, x, y, InnerWidth, InnerHeight, Titel, Flags = #PB_Window_SystemMenu, ParentWindowID = 0)
  gm_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Titel, Flags, ParentWindowID)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure CreateGadget(type, gadget, x, y, dx, dy, text.s, param1, param2, param3, flags)
  
  Shared *gm_GadgetList.gm_GadgetData, gm_GadgetItem
  
  Protected *NewGadgetList.gm_GadgetData
  Protected result, handle, id
  
  If IsGadget(gadget)
    FreeGadget(gadget)
  EndIf
  
  Select type
    Case #PB_GadgetType_Button : result = ButtonGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_ButtonImage : result = ButtonImageGadget(gadget, x, y, dx, dy, param1, flags)
    Case #PB_GadgetType_Calendar : result = CalendarGadget(gadget, x, y, dx, dy, param1, flags)
    Case #PB_GadgetType_Canvas : result = CanvasGadget(gadget, x, y, dx, dy, flags)
    Case #PB_GadgetType_CheckBox : result = CheckBoxGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_ComboBox : result = ComboBoxGadget(gadget, x, y, dx, dy, flags)
    Case #PB_GadgetType_Container : result = ContainerGadget(gadget, x, y, dx, dy, flags)
    Case #PB_GadgetType_Date : result = DateGadget(gadget, x, y, dx, dy, text, param1, flags)
    Case #PB_GadgetType_Editor : result = EditorGadget(gadget, x, y, dx, dy, flags)
    Case #PB_GadgetType_ExplorerCombo : result = ExplorerComboGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_ExplorerList : result = ExplorerListGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_ExplorerTree : result = ExplorerTreeGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_Frame : result = FrameGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_HyperLink : result = HyperLinkGadget(gadget, x, y, dx, dy, text, param1, flags)
    Case #PB_GadgetType_Image : result = ImageGadget(gadget, x, y, dx, dy, param1, flags)
    Case #PB_GadgetType_IPAddress : result = IPAddressGadget(gadget, x, y, dx, dy)
    Case #PB_GadgetType_ListIcon : result = ListIconGadget(gadget, x, y, dx, dy, text, param1, flags)
    Case #PB_GadgetType_ListView : result = ListViewGadget(gadget, x, y, dx, dy, flags)
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      Case #PB_GadgetType_MDI : result = MDIGadget(gadget, x, y, dx, dy, param1, param2, flags)
    CompilerEndIf
    CompilerIf #PB_Compiler_Version >= 530
      Case #PB_GadgetType_OpenGL : result = OpenGLGadget(gadget, x, y, dx, dy, flags)
    CompilerEndIf
    Case #PB_GadgetType_Option : result = OptionGadget(gadget, x, y, dx, dy, text)
    Case #PB_GadgetType_Panel : result = PanelGadget(gadget, x, y, dx, dy)
    Case #PB_GadgetType_ProgressBar : result = ProgressBarGadget(gadget, x, y, dx, dy, param1, param2, flags)
    Case #PB_GadgetType_Scintilla : result = ScintillaGadget(gadget, x, y, dx, dy, param1)
    Case #PB_GadgetType_ScrollArea : result = ScrollAreaGadget(gadget, x, y, dx, dy, param1, param2, param3, flags)
    Case #PB_GadgetType_ScrollBar : result = ScrollBarGadget(gadget, x, y, dx, dy, param1, param2, param3, flags)
    Case #PB_GadgetType_Shortcut : result = ShortcutGadget(gadget, x, y, dx, dy, param1)
    Case #PB_GadgetType_Spin : result = SpinGadget(gadget, x, y, dx, dy, param1, param2, flags)
    Case #PB_GadgetType_Splitter : result = SplitterGadget(gadget, x, y, dx, dy, param1, param2, flags)
    Case #PB_GadgetType_String : result = StringGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_Text : result = TextGadget(gadget, x, y, dx, dy, text, flags)
    Case #PB_GadgetType_TrackBar : result = TrackBarGadget(gadget, x, y, dx, dy, param1, param2, flags)
    Case #PB_GadgetType_Tree : result = TreeGadget(gadget, x, y, dx, dy, flags)
    Case #PB_GadgetType_Web : result = WebGadget(gadget, x, y, dx, dy, text)
  EndSelect
  
  If result = 0
    ProcedureReturn 0
  EndIf
  
  If gadget = #PB_Any
    handle = GadgetID(result)
    id = result
  Else
    handle = GadgetID(gadget)
    id = gadget
  EndIf
  
  *NewGadgetList = AddElement(*gm_GadgetList\Gadgets())
  
  With *gm_GadgetList\Gadgets()
    \parent = *gm_GadgetList
    \type = type
    \handle = handle
    \id = id
    \item = gm_GadgetItem
    \FreeGadgetCB = 0
    \x = x
    \y = y
    \dx = dx
    \dy = dy
    \text = text
    \param1 = param1
    \param2 = param2
    \param3 = param3
    \flags = flags
    If type = #PB_GadgetType_Container Or type = #PB_GadgetType_Panel Or type = #PB_GadgetType_ScrollArea
      *gm_GadgetList = *NewGadgetList
    EndIf
  EndWith
  
  ProcedureReturn result
  
EndProcedure

; Macros
Macro ButtonGadget(Gadget, x, y, dx, dy, text, Flags = 0)
  CreateGadget(#PB_GadgetType_Button, Gadget, x, y, dx, dy, text, 0, 0, 0, Flags)
EndMacro

Macro ButtonImageGadget(Gadget, x, y, dx, dy, ImageID, Flags = 0)
  CreateGadget(#PB_GadgetType_ButtonImage, Gadget, x, y, dx, dy, "", ImageID, 0, 0, Flags)
EndMacro

Macro CalendarGadget(gadget, x, y, dx, dy, Date, Flags = 0)
  CreateGadget(#PB_GadgetType_Calendar, Gadget, x, y, dx, dy, "", Date, 0, 0, Flags)
EndMacro

Macro CanvasGadget(gadget, x, y, dx, dy, Flags = 0)
  CreateGadget(#PB_GadgetType_Canvas, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro CheckBoxGadget(gadget, x, y, dx, dy, text, Flags = 0)
  CreateGadget(#PB_GadgetType_CheckBox, Gadget, x, y, dx, dy, text, 0, 0, 0, Flags)
EndMacro

Macro ComboBoxGadget(gadget, x, y, dx, dy, Flags = 0)
  CreateGadget(#PB_GadgetType_ComboBox, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro ContainerGadget(gadget, x, y, dx, dy, Flags = 0)
  CreateGadget(#PB_GadgetType_Container, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro DateGadget(gadget, x, y, dx, dy, Mask, Date, Flags = 0)
  CreateGadget(#PB_GadgetType_Date, Gadget, x, y, dx, dy, Mask, Date, 0, 0, Flags)
EndMacro

Macro EditorGadget(gadget, x, y, dx, dy, Flags = 0)
  CreateGadget(#PB_GadgetType_Editor, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro ExplorerComboGadget(gadget, x, y, dx, dy, Directory, Flags = 0)
  CreateGadget(#PB_GadgetType_ExplorerCombo, Gadget, x, y, dx, dy, Directory, 0, 0, 0, Flags)
EndMacro

Macro ExplorerListGadget(gadget, x, y, dx, dy, Directory, Flags = 0)
  CreateGadget(#PB_GadgetType_ExplorerList, Gadget, x, y, dx, dy, Directory, 0, 0, 0, Flags)
EndMacro

Macro ExplorerTreeGadget(gadget, x, y, dx, dy, Directory, Flags = 0)
  CreateGadget(#PB_GadgetType_ExplorerTree, Gadget, x, y, dx, dy, Directory, 0, 0, 0, Flags)
EndMacro

Macro FrameGadget(gadget, x, y, dx, dy, text, Flags = 0)
  CreateGadget(#PB_GadgetType_Frame, Gadget, x, y, dx, dy, text, 0, 0, 0, Flags)
EndMacro

Macro HyperLinkGadget(gadget, x, y, dx, dy, text, Color, Flags = 0)
  CreateGadget(#PB_GadgetType_HyperLink, Gadget, x, y, dx, dy, text, Color, 0, 0, Flags)
EndMacro

Macro ImageGadget(gadget, x, y, dx, dy, ImageID, Flags = 0)
  CreateGadget(#PB_GadgetType_Image, Gadget, x, y, dx, dy, "", ImageID, 0, 0, Flags)
EndMacro

Macro IPAddressGadget(gadget, x, y, dx, dy)
  CreateGadget(#PB_GadgetType_IPAddress, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro ListIconGadget(gadget, x, y, dx, dy, Titel, TitelWidth, Flags = 0)
  CreateGadget(#PB_GadgetType_ListIcon, Gadget, x, y, dx, dy, Titel, TitelWidth, 0, 0, Flags)
EndMacro

Macro ListViewGadget(gadget, x, y, dx, dy, Flags = 0)
  CreateGadget(#PB_GadgetType_ListView, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Macro MDIGadget(gadget, x, y, dx, dy, SubMenu, FirstMenuItem, Flags = 0)
    CreateGadget(#PB_GadgetType_MDI, Gadget, x, y, dx, dy, "", SubMenu, FirstMenuItem, 0, Flags)
  EndMacro
CompilerEndIf

Macro OptionGadget(gadget, x, y, dx, dy, text)
  CreateGadget(#PB_GadgetType_Option, Gadget, x, y, dx, dy, text, 0, 0, 0, Flags)
EndMacro

Macro PanelGadget(gadget, x, y, dx, dy)
  CreateGadget(#PB_GadgetType_Panel, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro OpenGLGadget(gadget, x, y, dx, dy, Flags = 0)
  CreateGadget(#PB_GadgetType_OpenGL, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro ProgressBarGadget(gadget, x, y, dx, dy, Minimum, Maximum, Flags = 0)
  CreateGadget(#PB_GadgetType_ProgressBar, Gadget, x, y, dx, dy, "", Minimum, Maximum, 0, Flags)
EndMacro

Macro ScintillaGadget(gadget, x, y, dx, dy, Callback)
  CreateGadget(#PB_GadgetType_Scintilla, Gadget, x, y, dx, dy, "", Callback, 0, 0, Flags)
EndMacro

Macro ScrollAreaGadget(gadget, x, y, dx, dy, param1, param2, param3, Flags = 0)
  CreateGadget(#PB_GadgetType_ScrollArea, Gadget, x, y, dx, dy, "", param1, param2, param3, Flags)
EndMacro

Macro ScrollBarGadget(gadget, x, y, dx, dy, param1, param2, param3, Flags = 0)
  CreateGadget(#PB_GadgetType_ScrollBar, Gadget, x, y, dx, dy, "", param1, parma2, param3, Flags)
EndMacro

Macro ShortcutGadget(gadget, x, y, dx, dy, Shortcut)
  CreateGadget(#PB_GadgetType_Shortcut, Gadget, x, y, dx, dy, "", Shortcut, 0, 0, Flags)
EndMacro

Macro SpinGadget(gadget, x, y, dx, dy, param1, param2, Flags = 0)
  CreateGadget(#PB_GadgetType_Spin, Gadget, x, y, dx, dy, "", param1, param2, 0, Flags)
EndMacro

Macro SplitterGadget(gadget, x, y, dx, dy, param1, param2, Flags = 0)
  CreateGadget(#PB_GadgetType_Splitter, Gadget, x, y, dx, dy, "", param1, param2, 0, Flags)
EndMacro

Macro StringGadget(gadget, x, y, dx, dy, text, Flags = 0)
  CreateGadget(#PB_GadgetType_String, Gadget, x, y, dx, dy, text, 0, 0, 0, Flags)
EndMacro

Macro TextGadget(gadget, x, y, dx, dy, text, Flags = 0)
  CreateGadget(#PB_GadgetType_Text, Gadget, x, y, dx, dy, text, 0, 0, 0, Flags)
EndMacro

Macro TrackBarGadget(gadget, x, y, dx, dy, param1, param2, Flags = 0)
  CreateGadget(#PB_GadgetType_TrackBar, Gadget, x, y, dx, dy, "", param1, param2, 0, Flags)
EndMacro

Macro TreeGadget(gadget, x, y, dx, dy, Flags = 0)
  CreateGadget(#PB_GadgetType_Tree, Gadget, x, y, dx, dy, "", 0, 0, 0, Flags)
EndMacro

Macro WebGadget(gadget, x, y, dx, dy, url)
  CreateGadget(#PB_GadgetType_Web, Gadget, x, y, dx, dy, url, 0, 0, 0, 0)
EndMacro

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Erweiterte Basis Funktionen

Procedure ParentGadget(gadget)
  
  Protected *gm_List.gm_GadgetData
  
  ForEach gm_ListWindow()
    *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
    If *gm_List
      If *gm_List\parent
        If *gm_List\parent\type >= 0
          ProcedureReturn *gm_List\parent\id
        EndIf
      EndIf
    EndIf
  Next
  
  ProcedureReturn -1
  
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure ParentWindow(gadget)
  
  Protected result, *gm_List, *parent.gm_GadgetData
  
  result = -1
  
  ForEach gm_ListWindow()
    *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
    If *gm_List
      *parent = *gm_List
      Repeat
        If *parent\type < 0
          result = *parent\id
          Break 2
        EndIf
        *parent = *parent\parent
      Until *parent = 0
    EndIf
  Next
  
  ProcedureReturn result
  
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure GadgetIDFromHandle(handle)
  
  Protected *gm_List.gm_GadgetData
  
  ForEach gm_ListWindow()
    *gm_List = gm_FindGadgetDataFromHandle(gm_ListWindow()\Gadgets(), handle)
    If *gm_List
      ProcedureReturn *gm_List\id
    EndIf
  Next
  
  ProcedureReturn -1
  
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure WindowIDFromHandle(handle)
  
  Protected *gm_List.gm_GadgetData
  
  ForEach gm_ListWindow()
    If gm_ListWindow()\handle = handle
      ProcedureReturn gm_ListWindow()\id
    EndIf
  Next
  
  ProcedureReturn -1
  
EndProcedure

; ---------------------------------------------------------------------------------------

Procedure GetGlobalGadgetData(gadget)
  
  Protected *gm_List
  
  *gm_List = 0
  
  ForEach gm_ListWindow()
    *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
    If *gm_List
      Break
    EndIf
  Next
  
  ProcedureReturn *gm_List
  
EndProcedure

; ---------------------------------------------------------------------------------------

CompilerIf Defined(UserGadgetData, #PB_Structure)
  Procedure GetUserGadgetData(gadget)
    
    Protected *gm_List.gm_GadgetData
    
    ForEach gm_ListWindow()
      *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
      If *gm_List
        ProcedureReturn *gm_list\user
      EndIf
    Next
    
    ProcedureReturn 0
    
  EndProcedure
CompilerEndIf

; ---------------------------------------------------------------------------------------

Procedure SetFreeGadgetCallback(gadget, *callback)
  
  Protected *gm_List.gm_GadgetData, result
  
  *gm_List = 0
  
  ForEach gm_ListWindow()
    *gm_List = gm_FindGadgetData(gm_ListWindow()\Gadgets(), gadget)
    If *gm_List
      result = *gm_list\FreeGadgetCB
      *gm_list\FreeGadgetCB = *callback
      Break
    EndIf
  Next
  
  ProcedureReturn result
  
EndProcedure

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

; ***************************************************************************************

;- *** Image Objects ***

Structure ImageData
  handle.i
  id.i
  filename.s
EndStructure

Global NewMap ListImages.ImageData()

; ---------------------------------------------------------------------------------------

Procedure gm_LoadImage(Image, Filename.s)
  
  Protected result, handle, id, key.s
  
  result = LoadImage(Image, Filename)
  If result = 0
    ProcedureReturn 0
  EndIf
  If Image = #PB_Any
    handle = ImageID(result)
    id = result
  Else
    handle = result
    id = Image
  EndIf
  
  key = Str(handle)
  AddMapElement(ListImages(), key)
  With ListImages()
    \handle = handle
    \id = id
    \filename = Filename
  EndWith
  
  ProcedureReturn result
  
EndProcedure

Macro LoadImage(Image, Filename)
  gm_LoadImage(Image, Filename)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure gm_CatchImage(Image, *Memory, Size = 0)
  
  Protected result, handle, id, key.s
  
  result = CatchImage(Image, *Memory, Size)
  If result = 0
    ProcedureReturn 0
  EndIf
  If Image = #PB_Any
    handle = ImageID(result)
    id = result
  Else
    handle = result
    id = Image
  EndIf
  key = Str(handle)
  AddMapElement(ListImages(), key)
  With ListImages()
    \handle = handle
    \id = id
    \filename = ":memory:"
  EndWith
  
  ProcedureReturn result
  
EndProcedure

Macro CatchImage(Image, Memory, Size = 0)
  gm_CatchImage(Image, Memory, Size)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure gm_FreeImage(Image)
  
  Protected key.s
  
  If IsImage(Image)
    key = Str(ImageID(Image))
    DeleteMapElement(ListImages(), key)
    FreeImage(Image)
  EndIf
  
EndProcedure

Macro FreeImage(Image)
  gm_FreeImage(Image)
EndMacro

; ---------------------------------------------------------------------------------------

Procedure ImageIDFromHandle(Handle)
  
  Protected result, key.s
  
  result = -1
  key = Str(Handle)
  If FindMapElement(ListImages(), key)
    result = ListImages()\id
  EndIf
  
  ProcedureReturn result
  
EndProcedure
 
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;-- Gadget Overview
CompilerIf #True
  
  Global gm_view_window, gm_view_tree
  
  Procedure.s gm_GadgetTypeName(type)
  
    Protected result.s
    
    Select type
      Case #PB_GadgetType_Button : result = "ButtonGadget"
      Case #PB_GadgetType_ButtonImage : result = "ButtonImageGadget"
      Case #PB_GadgetType_Calendar : result = "CalendarGadget"
      Case #PB_GadgetType_Canvas : result = "CanvasGadget"
      Case #PB_GadgetType_CheckBox : result = "CheckBoxGadget"
      Case #PB_GadgetType_ComboBox : result = "ComboBoxGadget"
      Case #PB_GadgetType_Container : result = "ContainerGadget"
      Case #PB_GadgetType_Date : result = "DateGadget"
      Case #PB_GadgetType_Editor : result = "EditorGadget"
      Case #PB_GadgetType_ExplorerCombo : result = "ExplorerComboGadget"
      Case #PB_GadgetType_ExplorerList : result = "ExplorerListGadget"
      Case #PB_GadgetType_ExplorerTree : result = "ExplorerTreeGadget"
      Case #PB_GadgetType_Frame : result = "FrameGadget"
      Case #PB_GadgetType_HyperLink : result = "HyperLinkGadget"
      Case #PB_GadgetType_Image : result = "ImageGadget"
      Case #PB_GadgetType_IPAddress : result = "IPAddressGadget"
      Case #PB_GadgetType_ListIcon : result = "ListIconGadget"
      Case #PB_GadgetType_ListView : result = "ListViewGadget"
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        Case #PB_GadgetType_MDI : result = "MDIGadget"
      CompilerEndIf
      CompilerIf #PB_Compiler_Version => 530
        Case #PB_GadgetType_OpenGL : result = "OpenGLGadget"
      CompilerEndIf  
      Case #PB_GadgetType_Option : result = "OptionGadget"
      Case #PB_GadgetType_Panel : result = "PanelGadget"
      Case #PB_GadgetType_ProgressBar : result = "ProgressBarGadget"
      Case #PB_GadgetType_Scintilla : result = "ScintillaGadget"
      Case #PB_GadgetType_ScrollArea : result = "ScrollAreaGadget"
      Case #PB_GadgetType_ScrollBar : result = "ScrollBarGadget"
      Case #PB_GadgetType_Shortcut : result = "ShortcutGadget"
      Case #PB_GadgetType_Spin : result = "SpinGadget"
      Case #PB_GadgetType_Splitter : result = "SplitterGadget"
      Case #PB_GadgetType_String : result = "StringGadget"
      Case #PB_GadgetType_Text : result = "TextGadget"
      Case #PB_GadgetType_TrackBar : result = "TrackBarGadget"
      Case #PB_GadgetType_Tree : result = "TreeGadget"
      Case #PB_GadgetType_Web : result = "WebGadget"
    EndSelect
    
    ProcedureReturn result
    
  EndProcedure
  
  Procedure gm_HelpTreeGadget(gadget, List GList.gm_GadgetData(), a)
    
    ForEach Glist()
      With GList()
        If \item < 0
          AddGadgetItem(gadget, -1, gm_GadgetTypeName(\type), 0, a)
        Else
          AddGadgetItem(gadget, -1, "(Item " + \item + ") " + gm_GadgetTypeName(\type), 0, a)
        EndIf
        a + 1
        AddGadgetItem(gadget, -1, "Gadget ID = " + Str(\id), 0, a)
        AddGadgetItem(gadget, -1, "Handle = " + Str(\handle), 0, a)
        AddGadgetItem(gadget, -1, "X = " + Str(\x), 0, a)
        AddGadgetItem(gadget, -1, "Y = " + Str(\y), 0, a)
        AddGadgetItem(gadget, -1, "DX = " + Str(\dx), 0, a)
        AddGadgetItem(gadget, -1, "DY = " + Str(\dy), 0, a)
        AddGadgetItem(gadget, -1, "Item = " + Str(\item), 0, a)
        AddGadgetItem(gadget, -1, "Text = " + \text, 0, a)
        If ListSize(\Gadgets())
          AddGadgetItem(gadget, -1, "Gadgets", 0, a)
          gm_HelpTreeGadget(gadget, \Gadgets(), a + 1)
        EndIf
        a - 1
      EndWith
    Next
    
  EndProcedure
  
  Procedure gm_UpdateTreeGadget(gadget)
    
    Protected a
    
    ClearGadgetItems(gadget)
    
    ForEach gm_ListWindow()
      a = 0
      With gm_ListWindow()
        AddGadgetItem(gadget, -1, "Window ID " + Str(\id), 0, 0)
        a + 1
        AddGadgetItem(gadget, -1, "X = " + Str(\x), 0, a)
        AddGadgetItem(gadget, -1, "Y = " + Str(\y), 0, a)
        AddGadgetItem(gadget, -1, "DX = " + Str(\dx), 0, a)
        AddGadgetItem(gadget, -1, "DY = " + Str(\dy), 0, a)
        AddGadgetItem(gadget, -1, "Titel = " + \text, 0, a)
        If ListSize(\Gadgets())
          AddGadgetItem(gadget, -1, "Gadgets", 0, a)
          gm_HelpTreeGadget(gadget, \Gadgets(), a + 1)
        EndIf
        a - 1
      EndWith
    Next
  EndProcedure
  
  Procedure ShowGadgetOverview()
    Protected style
    style = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
    gm_view_window = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 600, 500, "Gadget Overview", style)
    gm_view_tree = TreeGadget(#PB_Any, 0, 0, 600, 500)
    gm_UpdateTreeGadget(gm_view_tree)
    
  EndProcedure
  
CompilerEndIf
  ; ---------------------------------------------------------------------------------

; ***************************************************************************************

;- BOTTOM

GT :wink:

Re: GadgetManager for all OS

Posted: Sun May 10, 2015 4:08 pm
by mk-soft
Example Informations of Gadgets

Code: Select all

; GadgetManager Example 2

IncludeFile "GadgetManager_v101.pbi"

#WindowWidth  = 450
#WindowHeight = 305

; Load our images.. 
;
LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/Drive.bmp")
LoadImage(1, #PB_Compiler_Home + "examples/sources/Data/File.bmp")
LoadImage(2, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  ; Only Windows supports .ico file format
  LoadImage(3, #PB_Compiler_Home + "examples/sources/Data/CdPlayer.ico")
CompilerElse
  LoadImage(3, #PB_Compiler_Home + "examples/sources/Data/Drive.bmp")
CompilerEndIf

CreatePopupMenu(0)
  MenuItem(0, "Popup !")
  
Procedure MyFreeGadgetCB(*this.gm_GadgetData)
  Debug "Destroy Gadget " + Str(*this\id)
EndProcedure

Procedure Main()
    
  style = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
  If OpenWindow(0, #PB_Any, #PB_Any, #WindowWidth, #WindowHeight, "Main 1 - Advanced Gadget Demonstration", style)
    
  
    ListIconGadget(5, 170, 50, 265, 200, "Column 1", 131)
    AddGadgetColumn(5, 1, "Column 2", 300)
    AddGadgetColumn(5, 2, "Column 3", 80)
    
    TextGadget(4, 10, 16, 180, 24, "Please wait while initializing...")
    
    ProgressBarGadget(3, 10, 260, #WindowWidth-25, 20, 0, 100)
    
    ; Update the ProgressBar, just for fun !
    ;
    For k=0 To 100
      SetGadgetState(3, k)
      Delay(10)
    Next
    
    ImageGadget      (0, 200, 5, 0, 0, ImageID(2))
    ButtonImageGadget(1, 384, 5, 50, 36, ImageID(3))
    
    TreeGadget    (2,  10, 50, 150, 200)
      
    SetGadgetText(4, "Initialize Ok... Welcome !")
    
    ; Fill Up the Tree gadget with lot of entries (including the image)
    ;
    
    For k=0 To 10
      AddGadgetItem(2, -1, "General "+Str(k), ImageID(1))
      AddGadgetItem(2, -1, "ScreenMode", ImageID(1))
        AddGadgetItem(2, -1, "640*480", ImageID(1), 1)
        AddGadgetItem(2, -1, "800*600", ImageID(3), 1)
        AddGadgetItem(2, -1, "1024*768", ImageID(1), 1)
        AddGadgetItem(2, -1, "1600*1200", ImageID(1), 1)
      AddGadgetItem(2, -1, "Joystick", ImageID(1))
    Next
      
    ; Fill Up the ListIcon gadget. Notice than the column are separated by Chr(10) (NewLine) character
    ;
    For k=0 To 100
      AddGadgetItem(5, -1, "Element "+Str(k)+Chr(10)+"C 2"+Chr(10)+"Comment 3", ImageID(3))
    Next
    
    SetGadgetState(5, 8)
  EndIf
    
EndProcedure


Main()
ShowGadgetOverview()

Debug "----------------------------------------------------------------------"
Debug "ParentWindow from Gadget 0 is Window " + ParentWindow(0)
Debug "ParentWindow from Gadget 1 is Window " + ParentWindow(1)
Debug "ParentWindow from Gadget 2 is Window " + ParentWindow(2)
Debug "----------------------------------------------------------------------"
Debug "ParendGadget from Gadget 21 is Gadget " + ParentGadget(21)
Debug "ParendGadget from Gadget 22 is Gadget " + ParentGadget(22)
Debug "ParendGadget from Gadget 27 is Gadget " + ParentGadget(27)
Debug "----------------------------------------------------------------------"
Debug "WindowID from Handle " + Str(WindowID(0)) + " is " + Str(WindowIDFromHandle(WindowID(0)))
Debug "GadgetID from Handle " + Str(GadgetID(1)) + " is " + Str(GadgetIDFromHandle(GadgetID(1)))

Debug "----------------------------------------------------------------------"
hImage = ImageID(0)
Debug "Image from hImage " + hImage + " is PB-ID " + ImageIDFromHandle(hImage)
hImage = ImageID(1)
Debug "Image from hImage " + hImage + " is PB-ID " + ImageIDFromHandle(hImage)
hImage = ImageID(2)
Debug "Image from hImage " + hImage + " is PB-ID " + ImageIDFromHandle(hImage)


Repeat
  Event = WaitWindowEvent()

  If Event = #PB_Event_Gadget
    
    Select EventGadget()
      Case 1
        MessageRequester("Information", "You did it !", 0)
    
      Case 2
        SetGadgetText(4, "Tree Gadget. Item selected: "+Str(GetGadgetState(2)))
        
        If EventType() = 2
          MessageRequester("Information", "Doubleclick: item"+Str(GetGadgetState(2))+", Text: "+GetGadgetText(2), 0)
        ElseIf EventType() = 1
          DisplayPopupMenu(0, WindowID(0))
        EndIf
        
      Case 5
        SetGadgetText(4, "ListIcon Gadget. Item selected: "+Str(GetGadgetState(5)))
        
        If EventType() = 2
          MessageRequester("Information", "Doubleclick: item"+Str(GetGadgetState(5))+", Text: "+GetGadgetText(5), 0)
        ElseIf EventType() = 1
          DisplayPopupMenu(0, WindowID(0))
        EndIf
        
   EndSelect

  EndIf
  
Until Event = #PB_Event_CloseWindow

End 

Re: GadgetManager for all OS

Posted: Sun May 10, 2015 4:09 pm
by mk-soft
Example FreeGadgetCallback

Code: Select all

; GadgetManager Example 3

IncludeFile "GadgetManager_v101.pbi"

Procedure MyFreeGadgetCB(*this.gm_GadgetData)
  Debug "Destroy Gadget " + Str(*this\id)
EndProcedure

If OpenWindow(0, #PB_Any, #PB_Any, 322, 220, "PanelGadget", #PB_Window_SystemMenu)
  PanelGadget     (0, 8, 8, 306, 203)
    AddGadgetItem (0, -1, "Panel 1")
      PanelGadget (1, 5, 5, 290, 166)
        AddGadgetItem(1, -1, "Sub-Panel 1")
        AddGadgetItem(1, -1, "Sub-Panel 2")
        AddGadgetItem(1, -1, "Sub-Panel 3")
      CloseGadgetList()
    AddGadgetItem (0, -1,"Panel 2")
      ButtonGadget(2, 10, 15, 80, 24,"Button 1")
      ButtonGadget(3, 95, 15, 80, 24,"Button 2")
    CloseGadgetList()
    
  ShowGadgetOverview()
  
  SetFreeGadgetCallback(2, @MyFreeGadgetCB())
  SetFreeGadgetCallback(3, @MyFreeGadgetCB())
  
  Debug "----------------------------------------------------------------------"
  Debug "ParentWindow from Gadget 0 is Window " + ParentWindow(0)
  Debug "ParentWindow from Gadget 1 is Window " + ParentWindow(1)
  Debug "ParentWindow from Gadget 2 is Window " + ParentWindow(2)
  Debug "ParentWindow from Gadget 3 is Window " + ParentWindow(3)
  Debug "----------------------------------------------------------------------"
  Debug "ParendGadget from Gadget 1 is Gadget " + ParentGadget(1)
  Debug "ParendGadget from Gadget 2 is Gadget " + ParentGadget(2)
  Debug "ParendGadget from Gadget 3 is Gadget " + ParentGadget(3)
  Debug "----------------------------------------------------------------------"
  Debug "Wait on FreeGadgetCallback..."
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 2
            FreeGadget(2)
            gm_UpdateTreeGadget(gm_view_tree)
            
          Case 3
            FreeGadget(3)
            gm_UpdateTreeGadget(gm_view_tree)
        EndSelect
        
      Case #PB_Event_CloseWindow
        CloseWindow(0)
        exit = 1
        
    EndSelect
    
  Until exit
EndIf

Re: GadgetManager for all OS

Posted: Sun May 10, 2015 4:10 pm
by mk-soft
Example UserGadgetData

Code: Select all

; GadgetManager Example 4

; This structure added to gm_gadgetdata
Structure UserGadgetData
  text1.s
  text2.s
EndStructure

IncludeFile "GadgetManager_v101.pbi"

Define *MyData1.UserGadgetData
Define *MyData2.UserGadgetData

If OpenWindow(0, #PB_Any, #PB_Any, 300, 200, "Gadget", #PB_Window_SystemMenu)
  
  ListViewGadget(0, 0, 0, 300, 160)
  ButtonGadget(1, 10, 165, 80, 25, "Data 1")
  ButtonGadget(2, 100, 165, 80, 25, "Data 2")
  
  *MyData1 = GetUserGadgetData(1)
  With *MyData1
    \text1 = "Hello World"
    \text2 = ";)"
  EndWith
  *MyData2 = GetUserGadgetData(2)
  With *MyData2
    \text1 = "World of Purebasis"
    \text2 = ":)"
  EndWith
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            AddGadgetItem(0, -1, *MyData1\text1)
            AddGadgetItem(0, -1, *MyData1\text2)
            
          Case 2
            AddGadgetItem(0, -1, *MyData2\text1)
            AddGadgetItem(0, -1, *MyData2\text2)
          
        EndSelect
        
      Case #PB_Event_CloseWindow
        CloseWindow(0)
        exit = 1
        
    EndSelect
    
  Until exit

EndIf

Re: GadgetManager for all OS

Posted: Sun May 10, 2015 7:13 pm
by mk-soft
Example remove panel item with FreeGadgetCallback

Code: Select all

; GadgetManager Example 5

IncludeFile "GadgetManager_v102.pbi"

Procedure MyFreeGadgetCB(*this.gm_GadgetData)
  Debug "Destroy Gadget " + Str(*this\id)
EndProcedure

Procedure Main()
  
  If OpenWindow(0, #PB_Any, #PB_Any, 800, 200, "Gadget", #PB_Window_SystemMenu)
    
    PanelGadget(0, 0, 0, 800, 160)
    For i = 11 To 20
      AddGadgetItem(0, -1, "Panel " + Str(i))
      ButtonGadget(i, 10, 10, 100, 25, "Button " +Str(i))
      SetFreeGadgetCallback(i, @MyFreeGadgetCB())
    Next
    CloseGadgetList()
    
    ButtonGadget(1, 10, 165, 160, 25, "Delete active panel")
  EndIf
  
EndProcedure
  
Main()
ShowGadgetOverview()

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          item = GetGadgetState(0)
          RemoveGadgetItem(0, item)
          gm_UpdateTreeGadget(gm_view_tree)
          
      EndSelect
      
    Case #PB_Event_CloseWindow
      CloseWindow(0)
      exit = 1
      
  EndSelect
  
Until exit