I needed a way to store additional data to each item in a ListIconGadget, but I wanted to avoid a separate LinkedList or any "hidden" columns. So here's what I did.
I don't know if this code is correct (mem leaks or so) but for the moment it seems to run fine here.
Probably it is helpful to somebody.
Code: Select all
Structure LISTICON_ITEMDATA_EX
DateModified.l
Extension.s
DummyVariable1.l
DummyVariable2.l
EndStructure
Procedure RemoveGadgetItemEx(Gadget, Position)
Protected lParam.l= 0
lParam= GetGadgetItemData(Gadget, Position)
If lParam
FreeMemory(lParam)
EndIf
RemoveGadgetItem(Gadget, Position)
EndProcedure
Procedure ClearGadgetItemListEx(Gadget)
Protected Position.l= 0
For Position= CountGadgetItems(Gadget) - 1 To 0 Step -1
RemoveGadgetItemEx(Gadget, Position)
Next
EndProcedure
Procedure AddGadgetItemEx(Text$, DateModified, Extension$, Dummy1, Dummy2)
Protected n= CountGadgetItems(1)
AddGadgetItem(1, n, Text$)
hMem= AllocateMemory(SizeOf(LISTICON_ITEMDATA_EX)) ; Memory is freed when the item is removed
*lii.LISTICON_ITEMDATA_EX= hMem
*lii\DateModified= DateModified
*lii\Extension= Extension$
*lii\DummyVariable1= Dummy1
*lii\DummyVariable2= Dummy2
SetGadgetItemData(1, n, hMem)
EndProcedure
If OpenWindow(0, 0, 0, 300, 300, "MoreGadgetItemData", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
StringGadget(2, 10, 10, 135, 20, "", #PB_String_ReadOnly)
StringGadget(3, 10, 35, 135, 20, "", #PB_String_ReadOnly)
StringGadget(4, 155, 10, 135, 20, "", #PB_String_ReadOnly)
StringGadget(5, 155, 35, 135, 20, "", #PB_String_ReadOnly)
ListIconGadget(1, 10, 70, 280, 220, "Name", 200)
EndIf
AddGadgetItemEx("Hello World", Date() - 2800000, "Word Document", 123, 45)
AddGadgetItemEx("Hello Moon", Date(), "Excel Workbook", 678, 90)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If EventType() = #PB_EventType_Change
idx.l= GetGadgetState(1)
If idx > -1
lParam= GetGadgetItemData(1, idx)
If lParam
*lii.LISTICON_ITEMDATA_EX= lParam
SetGadgetText(2, *lii\Extension)
SetGadgetText(3, FormatDate("%yyyy.%mm.%dd %hh:%ii:%ss", *lii\DateModified))
SetGadgetText(4, Str(*lii\DummyVariable1))
SetGadgetText(5, Str(*lii\DummyVariable2))
EndIf
EndIf
EndIf
EndSelect
EndSelect
ForEver
ClearGadgetItemListEx(1)
CloseWindow(0)
EndIf
End