Hello,
A little command to free the Gadget. It's not really an issue if the SpeedBarGadget() is used on the main window but if it's used in a child window the SpeedBarGadget() will generate a memory leak because the memory is not released when the gadget is destroyed.
Code:
Procedure FreeSpeedBarGadget(Gadget)
Protected *d._SpeedBar = GetGadgetData(Gadget)
If *d <> #Null
FreeMemory(*d)
FreeGadget(Gadget)
EndIf
EndProcedure
When you allocate the memory for extra information needed for the SpeedBarGadget, it's better to use InitializeStructure() instead of NewList to initialize the Linked List.
Code:
Procedure SpeedBarGadget(Gadget, x, y, w, h, Flags=0)
;create new speedbar
Protected f, *d._SpeedBar, desktops, i
;build canvas flags
If Flags & #SpeedBarBorder
f | #PB_Canvas_Border
EndIf
;create additional speedbar object data
*d = AllocateMemory(SizeOf(_SpeedBar))
InitializeStructure(*d, _SpeedBar)
; NewList *d\Values() <--- With InitializeStructure(), NewList is no longer needed !
*d\Canvas = CanvasGadget(Gadget, x, y, w, h, f)
*d\Flags = Flags
*d\Font = FontID(LoadFont(#PB_Any, "", 8))
*d\Maximum = 100
*d\BackColor = $000000
*d\GridColor = $1C1C1C
*d\ValueColor = $0000FF
;store object in gadget data
If Gadget = #PB_Any
SetGadgetData(*d\Canvas, *d)
Else
SetGadgetData(Gadget, *d)
EndIf
;maximum number of values to store is limited to desktop width
desktops = ExamineDesktops()
For i = 0 To desktops - 1
If *d\MaxItems < DesktopWidth(i)
*d\MaxItems = DesktopWidth(i)
EndIf
Next
;return gadget id
ProcedureReturn *d\Canvas
EndProcedure
Otherwise, nice Gadget !
Best regards
Guimauve