Page 1 of 1

ListIcon Items margins

Posted: Wed Sep 26, 2007 10:41 am
by Max
Hi @all

I'm setting StringGadget margins* with this message:

Code: Select all

SendMessage_(GadgetID(#Gadget), #EM_SETMARGINS, #EC_LEFTMARGIN | #EC_RIGHTMARGIN, margins)
It's possible also to set ListIcon items margings*?. I've looked for in msdn and I've no find anything.


(* margins refers to space between gadget or item inner border and text into it)

Posted: Wed Sep 26, 2007 5:53 pm
by Sparkie
You can customdraw your ListIconGadget and gain some control over your margins. Just look for the commented lines
;... Adjust rect for text margins for this item

Code: Select all

;... Create brushes for painting item background
Structure MYBRUSHES
  brushDefault.l
  brushSelected.l
EndStructure
Global brush.MYBRUSHES 
brush\brushSelected = CreateSolidBrush_(RGB(255, 255, 155))
brush\brushDefault = GetStockObject_(#WHITE_BRUSH)

Procedure myWindowCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *nmhdr.NMHEADER = lParam 
      *lvCD.NMLVCUSTOMDRAW = lParam 
      If *lvCD\nmcd\hdr\hwndFrom=GadgetID(0) And *lvCD\nmcd\hdr\code = #NM_CUSTOMDRAW    
        Select *lvCD\nmcd\dwDrawStage 
          Case #CDDS_PREPAINT 
            result = #CDRF_NOTIFYITEMDRAW 
          Case #CDDS_ITEMPREPAINT 
            result = #CDRF_NOTIFYSUBITEMDRAW; 
          Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM 
            thisItem = *lvCD\nmcd\dwItemSpec 
            ;... Define rect for text 
            subItemRect.RECT\left = #LVIR_LABEL 
            subItemRect.RECT\top = *lvCD\iSubItem 
            ;... Get the subitem rect 
            SendMessage_(GadgetID(0), #LVM_GETSUBITEMRECT, thisItem, @subItemRect) 
            subItemText$ = GetGadgetItemText(0, *lvCD\nmcd\dwItemSpec, *lvCD\iSubItem) 
            sitLen = Len(subItemText$) 
            Select *lvCD\iSubItem 
              Case 0 
               ;... Define text and background colors for column 0 and set Drawtext_() flags 
                lvFlags =  #DT_END_ELLIPSIS | #DT_WORDBREAK;| #DT_MODIFYSTRING 
                ;... Paint over unused icon rect 
                subItemRect\left = 0 
                If GetGadgetState(0) = thisItem 
                  ;... If item is selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushSelected) 
                Else 
                  ;... If item is not selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushDefault) 
                EndIf 
                ;... Text color for column 0 
                SetTextColor_(*lvCD\nmcd\hdc, RGB(100, 0, 0)) 
                ;... Adjust rect for text margins for this item
                subItemRect\left + 15 
                ;subItemRect\right = subItemRect\left + 15
              Case 1 
                ;... Define text and background colors for column 1 and set Drawtext_() flags 
                lvFlags = #DT_END_ELLIPSIS | #DT_SINGLELINE | #DT_VCENTER 
                If GetGadgetState(0) = thisItem 
                  ;... If item is selected, colorize column 1 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushSelected) 
                Else 
                  ;... If item is not selected, colorize column 1 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushDefault) 
                EndIf 
                ;... Text color for column 1 
                SetTextColor_(*lvCD\nmcd\hdc, RGB(0, 100, 0)) 
                ;... Adjust rect for text margins for this item
                subItemRect\left + 25 
                subItemRect\right = subItemRect\left + 25  
              Case 2 
               ;... Define text and background colors for column 2 and set Drawtext_() flags 
                lvFlags = #DT_END_ELLIPSIS | #DT_SINGLELINE | #DT_VCENTER 
                If GetGadgetState(0) = thisItem 
                  ;... If item is selected, colorize column x 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushSelected) 
                Else 
                  ;... If item is not selected, colorize column x 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushDefault) 
                EndIf 
                ;... Text color for column x 
                SetTextColor_(*lvCD\nmcd\hdc, RGB(0, 0, 100)) 
                ;... Adjust rect for text margins for this item
                subItemRect\left + 35 
                subItemRect\right  = subItemRect\left + 55
            EndSelect 
            ; --> Draw our text 
            DrawText_(*lvCD\nmcd\hdc, subItemText$, sitLen, subItemRect, lvFlags) 
            result = #CDRF_SKIPDEFAULT 
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

If OpenWindow(0, 0, 0, 480, 260, "Set Margins Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@myWindowCallback()) 
  CreateStatusBar(0, WindowID(0)) 
  ListIconGadget(0, 10, 10, 470, 225, "Column 0", 150, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_AlwaysShowSelection) 
  AddGadgetColumn(0, 1, "Column 1", 150) 
  AddGadgetColumn(0, 2, "Column 2", 150) 
 For a=0 To 9 
    addtext$ = "Column 0 item #" + Str(a) + Chr(10) + "Column 1 item #" + Str(a) + Chr(10) + "Column 2 item #" + Str(a) 
    atLen = Len(addtext$) 
    AddGadgetItem(0,-1, addtext$) 
  Next 
  Repeat 
    event = WaitWindowEvent() 
    Select event 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case 0 
            ;... Display selected ListIconGadget index in statusbar 
            StatusBarText(0, 0, "Selected item index is: " + Str(GetGadgetState(0))) 
        EndSelect 
    EndSelect 
  Until event = #PB_Event_CloseWindow 
  DeleteObject_(brush\brushSelected)
EndIf 
End 

Posted: Wed Sep 26, 2007 5:55 pm
by srod
Yes I use a similar method with EsGRID when superimposing edit controls over cells being edited etc.

As far as I know there is no simple and direct way of altering margins for the individual items in a listicon gadget.

Posted: Thu Sep 27, 2007 8:33 am
by Max
Thanks, Sparkie & srod, I will try it.

Nevertheless, I'm not sure of using so many complex form for so little result.

thanks, again.

Posted: Thu Sep 27, 2007 11:43 am
by Shardik
Sparkie,

thank you very much for another nice example. But those who are still working with PB 4.02 or lower have to add this missing declaration:

Code: Select all

#LVM_GETSUBITEMRECT = #LVM_FIRST + 56