Code: Select all
;
;Mesa February 2022
Enumeration imagecheckbox
#imCheckNo
#imCheckYes
#imCheckNoGray
#imCheckYesGray
EndEnumeration
Enumeration gadget
#listicon
#btnlock
EndEnumeration
CreateImage(#imCheckNo,16,16,24,#White)
StartDrawing(ImageOutput(#imCheckNo))
DrawingMode(#PB_2DDrawing_Outlined )
Box(1,1,15,15,#Black)
StopDrawing()
CreateImage(#imCheckYes,16,16,24,#White)
StartDrawing(ImageOutput(#imCheckYes))
DrawingMode(#PB_2DDrawing_Outlined )
Box(1,1,15,15,#Black)
LineXY(1,1,15,15,#Black)
LineXY(15,1,1,15,#Black)
StopDrawing()
CreateImage(#imCheckNoGray,16,16,24,#Gray)
StartDrawing(ImageOutput(#imCheckNoGray))
DrawingMode(#PB_2DDrawing_Outlined )
Box(1,1,15,15,#Black)
StopDrawing()
CreateImage(#imCheckYesGray,16,16,24,#Gray)
StartDrawing(ImageOutput(#imCheckYesGray))
DrawingMode(#PB_2DDrawing_Outlined )
Box(1,1,15,15,#Black)
LineXY(1,1,15,15,#Black)
LineXY(15,1,1,15,#Black)
StopDrawing()
Global Dim checkstate(1)
ItemHeight = 18 ; Change this value if you change the fontsize of the listicongadget
If OpenWindow(0, 100, 100, 600, 200, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(#listicon, 40, 5, 470, 140, "Name", 100)
AddGadgetColumn(#listicon, 1, "Address", 250)
margin$=" "
For i=0 To 50
AddGadgetItem(#listicon, -1, margin$+"Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay",ImageID(#imCheckNo))
AddGadgetItem(#listicon, -1, margin$+"Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity",ImageID(#imCheckNo))
Next i
ReDim checkstate(CountGadgetItems(#listicon))
ButtonGadget(#btnlock, 20 , 160 , 100, 30, "Lock",#PB_Button_Toggle )
gadgetx = GadgetX(#listicon,#PB_Gadget_ScreenCoordinate)
gadgety = GadgetY(#listicon,#PB_Gadget_ScreenCoordinate)
AddWindowTimer(0,125,10)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Timer
If flag = 1
checkx = DesktopMouseX()
checky = DesktopMouseY()
If checkx > gadgetx And checkx < (gadgetx+ItemHeight)
item = Int((checky - gadgety - ItemHeight)/ItemHeight)
itemstste = GetGadgetItemState(#listicon,item)
checkstate(item) = checkstate(item)!1
If checkstate(item) = #PB_ListIcon_Selected
count + 1
SetGadgetItemImage(#listicon, item, ImageID(#imCheckYes))
Else
count - 1
SetGadgetItemImage(#listicon, item, ImageID(#imCheckNo))
EndIf
EndIf
If count <> oldcount
Debug "Item : "+Str(item)+" Checkbox state has changed "
EndIf
oldcount = count
flag = 0
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case #listicon
Select EventType()
Case #PB_EventType_LeftClick
If GetGadgetState(#btnlock)=0
; if not locked
flag = 1
EndIf
EndSelect
Case #btnlock
;If this button is toggled, it's not allowed to check or uncheck anything and checkboxes are grayed
;else checkboxes are enabled and white
Select EventType()
Case #PB_EventType_LeftClick
If GetGadgetState(#btnlock)=1
im0=#imCheckNoGray
im1=#imCheckYesGray
Else
im0=#imCheckNo
im1=#imCheckYes
EndIf
For i=0 To CountGadgetItems(#listicon) -1
If checkstate(i)=0
SetGadgetItemImage(#listicon, i, ImageID(im0))
Else
SetGadgetItemImage(#listicon, i, ImageID(im1))
EndIf
Next i
EndSelect
EndSelect
EndSelect
Until Quit = 1
EndIf