Page 1 of 1

Is it possible to change row spacing in a ListIconGadget?

Posted: Mon Mar 14, 2005 11:14 pm
by P-J
Does anyone know if it's possible to change the padding/distance between each row when using the gadget in List/Details mode?

I've had a good scour of the the API and Purearea, no dice :/

Any help, once again, much appreciated!

Posted: Tue Mar 15, 2005 2:38 pm
by Sparkie
This works on WinXPhome SP2 with PB 3.93...

Code: Select all

#MyWindow = 0
#myListIcon = 0
Procedure myWindowCallback(hWnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_MEASUREITEM
      If wParam = #myListIcon
        *mis.MEASUREITEMSTRUCT = lParam
        ;--> We'll increase row height by 5 pixels
        *mis\itemHeight + 5
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure
If OpenWindow(#MyWindow, 0, 0, 320, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ListIconGadget Set Row Height") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@myWindowCallback())
  ListIconGadget(#myListIcon, 10, 10, 299, 160, "", 139, #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines)
  ChangeListIconGadgetDisplay(#myListIcon, 2)
  ;--> Temporarily set ListIconGadget to #LVS_OWNERDRAWFIXED so we get the #WM_MEASUREITEM message
  SetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE, GetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE) | #LVS_OWNERDRAWFIXED)
  For i = 0 To 29
    AddGadgetItem(#myListIcon, -1, "Item " + Str(i))
  Next i
  ;--> Init #WM_MEASUREITEM with a resize
  ResizeGadget(#myListIcon, 10, 10, 300, 160)
  ;--> Remove #LVS_OWNERDRAWFIXED
  SetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE, GetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE) &~#LVS_OWNERDRAWFIXED)
  ;--> Redraw items with our new row height
  SendMessage_(GadgetID(#myListIcon), #LVM_REDRAWITEMS, 0, CountGadgetItems(0) -1 )
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_Event_CloseWindow
        quit = #True
     EndSelect
  Until quit = #True 
EndIf 
End

Posted: Tue Mar 15, 2005 3:12 pm
by P-J
That's just the ticket, thanks.

I'll make a point of scouring that code so I know exactly how it works, better to learn I reckon :)

Posted: Tue Mar 15, 2005 3:47 pm
by Sparkie
You're welcome P-J :)
P-J wrote:I'll make a point of scouring that code so I know exactly how it works, better to learn I reckon
In order to change the row height, you need to receive the #WM_MEASUREITEM message. This is only sent when the ListIconGadget style has the #LVS_OWNERDRAWFIXED flag.

Code: Select all

SetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE, GetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE) | #LVS_OWNERDRAWFIXED) 
Once you receive the #WM_MEASUREITEM message, you set the row height by adding your pixel count to the MEASUREITEMSTRUCT (*mis\itemHeight) member

Code: Select all

*mis\itemHeight + 5
You can now remove the #LVS_OWNERDRAWFIXED flag from the ListIconGadget, and let Windows continue to do the drawing.

Code: Select all

SetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE, GetWindowLong_(GadgetID(#myListIcon), #GWL_STYLE) &~#LVS_OWNERDRAWFIXED)