Is it possible to change row spacing in a ListIconGadget?

Just starting out? Need help? Post your questions and find answers here.
P-J
User
User
Posts: 44
Joined: Fri Jan 23, 2004 6:54 pm
Contact:

Is it possible to change row spacing in a ListIconGadget?

Post 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!
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
P-J
User
User
Posts: 44
Joined: Fri Jan 23, 2004 6:54 pm
Contact:

Post 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 :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply