Page 1 of 1

ListIconGadget with checkboxes

Posted: Thu Dec 02, 2004 9:35 pm
by PB
If I create a ListIconGadget with the #PB_ListIcon_CheckBoxes flag, is there
a way to have some items without a checkbox? I only want some to have a
checkbox, rather than all.

Posted: Fri Dec 03, 2004 2:50 am
by Sparkie
There might be a better way, but these 2 methods work for me on WinXPhome with PB3.92.
Remove ListIconGadget checkboxes in WaitWindowEvent()

Code: Select all

If OpenWindow(0, 0, 0, 270, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIconGadget") And CreateGadgetList(WindowID(0)) 
  ListIconGadget(0, 10, 10, 250, 125, "Testing", 200, #PB_ListIcon_CheckBoxes)
  For a = 0 To 12 
    addtext$ = "Item index #" + Str(a) +  " in the ListIconGadget"
    AddGadgetItem(0, -1, addtext$)
  Next 
  ; --> Remove checkboxes for items 2, 3, 4
  For i = 2 To 4
  lv.LV_ITEM\mask = #LVIF_STATE
  lv\iItem = i
  lv\state = 0 << 12
  lv\stateMask = #LVIS_STATEIMAGEMASK
  SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
  Next
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_EventGadget
        Select EventGadgetID()
          Case 0
            ; --> Remove checkboxes for items 2, 3, 4
            For i = 2 To 4
              SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
            Next
        EndSelect
    EndSelect
  Until event =# PB_Event_CloseWindow 
EndIf 
End

Remove ListIconGadget checkboxes with SetWindowCallback()

Code: Select all

Procedure myWindowCallback(hwnd, msg, wparam, lparam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NOTIFY
      *nmNMHDR.NMHDR = lparam
      If *nmNMHDR\code = #LVN_ITEMCHANGED
        *lvm.NMLISTVIEW = *nmNMHDR
        ; --> Remove checkboxes for items 2, 3, 4
        If *lvm\iItem > 1 And *lvm\iItem < 5
          lv.LV_ITEM\mask = #LVIF_STATE
          lv\state = 0 << 12
          lv\stateMask = #LVIS_STATEIMAGEMASK
          SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, *lvm\iItem, lv)
        EndIf
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 270, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIconGadget") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@myWindowCallback())
  ListIconGadget(0, 10, 10, 250, 125, "Testing", 200, #PB_ListIcon_CheckBoxes)
  For a = 0 To 12 
    addtext$ = "Item index #" + Str(a) +  " in the ListIconGadget"
    AddGadgetItem(0, -1, addtext$)
  Next 
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow 
EndIf 
End

Posted: Fri Dec 03, 2004 9:21 am
by PB
Thanks Sparkie! :)

Posted: Fri Dec 03, 2004 2:44 pm
by TerryHough
Nice, Sparkie!

One more question about the checkboxes.

Is it possible to change the character shown in a selected checkbox. For example, instead of showing a checkmark can that be an X instead?

Terry

Posted: Fri Dec 03, 2004 8:24 pm
by Sparkie
Thanks guys, glad to hear it works for you. :)

As for using x's in place of checkmarks, this seems to work ok. I'm not very good with 2DDrawing so I'm sure this can be optimized. If nothing else, it gives you a start in the right direction ;)

Code: Select all

If OpenWindow(0, 0, 0, 270, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIconGadget") And CreateGadgetList(WindowID(0)) 
  ListIconGadget(0, 10, 10, 250, 125, "Testing", 200, #PB_ListIcon_CheckBoxes)
  For a = 0 To 12 
    addtext$ = "Item index #" + Str(a) +  " in the ListIconGadget"
    AddGadgetItem(0, -1, addtext$)
  Next 
  ; --> Create our checked checkbox image with red x
  itemChecked = CreateImage(0, 16, 16)
  StartDrawing(ImageOutput())
  Box(0, 0, 16, 16, RGB(255, 255, 255))
  Box(1, 1, 14, 14, RGB(0, 0, 0))
  Box(3, 3, 10, 10, RGB(255, 255, 255))
  ; --> red line top left to bottom right
  LineXY(4, 4, 11, 11, RGB(255, 0, 0))
  LineXY(5, 4, 11, 10, RGB(255, 0, 0))
  LineXY(4, 5, 10, 11, RGB(255, 0, 0))
  ; --> red line bottom left to top right
  LineXY(4, 11, 11, 4, RGB(255, 0, 0))
  LineXY(4, 10, 10, 4, RGB(255, 0, 0))
  LineXY(5, 11, 11, 5, RGB(255, 0, 0))
  StopDrawing()
  ; --> Create our un-checked checkbox image with no red x
  itemUnchecked = CreateImage(1, 16, 16)
  StartDrawing(ImageOutput())
  Box(0, 0, 16, 16, RGB(255, 255, 255))
  Box(1, 1, 14, 14, RGB(0, 0, 0))
  Box(3, 3, 10, 10, RGB(255, 255, 255))
  StopDrawing()
  ; --> Create our new state imagelist for ListIconGadget 
  stateImageList= ImageList_Create_(16, 16, #ILC_COLOR32, 0, 2) 
  ImageList_Add_(stateImageList, itemUnchecked, 0)
  ImageList_Add_(stateImageList, itemChecked, 0)
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_STATE, stateImageList)
  ; --> Remove checkboxes for items 2, 3, 4
  For i = 2 To 4
    lv.LV_ITEM\mask = #LVIF_STATE
    lv\iItem = i
    lv\state = 0 << 12
    lv\stateMask = #LVIS_STATEIMAGEMASK
    SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
  Next
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_EventGadget
        Select EventGadgetID()
          Case 0
            ; --> Remove checkboxes for items 2, 3, 4
            For i = 2 To 4
              SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
            Next
        EndSelect
    EndSelect
  Until event =# PB_Event_CloseWindow 
EndIf 
End


Posted: Fri Dec 03, 2004 11:39 pm
by TerryHough
Sparkie wrote: it gives you a start in the right direction ;)
Thanks Sparkie!

I played with a bit and ende up with this...

Code: Select all


  FontID1 = LoadFont(3, "Arial", 8, #PB_Font_Bold)
------------
  ; --> Create our checked checkbox image with an X 
  itemChecked = CreateImage(0, 16, 16) 
  StartDrawing(ImageOutput()) 
    Box(1, 1, 14, 14, RGB(255, 255, 255)) 
    DrawingFont(FontID1)  ; Select a drawing font
    FrontColor(255, 0, 0) ; Choose the color of the X here
    Locate(5, 1)          ; Locate the cursor and
    DrawText("X")         ; draw the X using the chosen drawing font
  StopDrawing() 

  ; --> Create our un-checked checkbox image
  itemUnchecked = CreateImage(1, 16, 16) 
  StartDrawing(ImageOutput()) 
    Box(1, 1, 14, 14, RGB(255, 255, 255)) 
  StopDrawing() 
which was exactly how I wanted it to appear.

That will get some users off my back as soon as I can implement this in
three programs.

Tnanks for your suggestions and ideas,
Terry

Posted: Sat Dec 04, 2004 12:11 am
by Sparkie
Very nice Terry :)

I was so into drawing my pretty little red x's that I overlooked the fact that there was one sitting right in front of me on my keyboard. 8O :oops: :twisted: