GadgetManager for all OS
Posted: Sun May 10, 2015 4:07 pm
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
Functions Image Manager
----------------------
ImageIDFromHandle(handle)
Update v1.02
bugfix: RemoveGadgetItem(). Internal Item for PanelGadget
bugfix: OpenWindow with same WindowID
GadgetManager_v102.pbi
GT 
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
----------------------
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
