ListIconGadget - Multiline Entry

Just starting out? Need help? Post your questions and find answers here.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

ListIconGadget - Multiline Entry

Post by Christian »

Hi!

I am looking for a way to have a ListIconGadget displaying multiline entries. Chr(13)+Chr(10) unfortunately didn't work. Any idea how to solve this problem? Would be really great if someone could help! :(

Thank you,
Christian
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Nobody got an answer? In the German board Andre mentioned that it might be possible that Windows doesn't support a feature like this. Is this right?

regards,
Christian

PS: Perhaps I explained it not understandable enough:
I want somthing like this in a ListIcon-/ListViewGadget:

Code: Select all

ListIcon-/ListViewGadget:

Column 1 ...... Column 2
Entry 1 ....... Entry 1 (first line of Entry 1)
------------------------------------------------
Entry 2 ....... Entry 2 (first line of Entry 2)
............... Entry 2 (second line of Entry 2)
------------------------------------------------
Entry 3 ....... Entry 3 (first line of Entry 3)
Hope it's better to understand now.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I don't think you can. I've never seen an app that does it. What about just
setting column 1 to "" (null) and then putting the second line in column 2?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Hi PB,

also thought this could be a solution but because of the selection the user can recognize that it isn't a multiline entry. :(

Well, Ok ... seems I have to live without it.

Regards,
Christian
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> because of the selection the user can recognize that it isn't a multiline entry

If the user selects line 1, can't you force line 2 to be selected too? That would
at least show the user that the lines are "linked" to each other? I'd do that.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Hi PB,

I tried this already before I wrote my question here but for me it was bad to see how firstly the one entry was chosen and afterwards the second one.
But I got used to live without this function. I get along now with single line entries ... ;) ... nevertheless thank you for your help!

regards,
Christian
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

After seeing this thread, I took on the challenge. :twisted:

Multiline entries are possible but it requires some custom drawing. I first set the ListIconGadget imagelist size to 1x32. This creates a row height for 2 lines of text. I then catch the #NM_CUSTOMDRAW notification through #WM_NOTIFY. From there I do my own ListIconGadget drawing, depending on the current dwDrawStage.

I'm still doing some clean up on the code, but here's a pic to show it is possible. :)

Image
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

sparkie: waaa...aaaoooowww
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

WOW! Brilliant!
Christian wrote:But I got used to live without this function. I get along now with single line entries ...
... forget what I said! Are you going to post the source? :P Would be great!

regards,
Christian
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks guys :)

This one took me more than a few hours to figure out. There was plenty of Googled code available but none that showed the exact sequence of what we needed. This was all trial and error coding. :?

I've made some more progress with column text and background coloring, selection hilight color, as well as the always show selection option. Still need to dim the selection when losing focus as well as test with icons and or checkboxes. 8)

Image

Give me a day or two to clean up and comment the code and I'll post it here. :)
Last edited by Sparkie on Sun Jul 26, 2009 3:23 pm, edited 2 times in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Great! :)

But it seems as if the rows are needing a bit more height because the "g" of "ListIconGadget" is cut in its second half.
Another question: Is it also possible to just have some entries in a mutiline style depending on their Textlength?

regards,
Christian
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You can specify wordwrap for each column as necessary. Here I use wordwrap in Column 0 and single line with ellipsis (...) as needed.

I also adjusted the row height but it creates a new problem when resizing the column width, the ellipsis fail to appear. :?

After I post the code, we can work together optimizing the code. :)
Last edited by Sparkie on Sun Jul 26, 2009 3:25 pm, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

* Edited to update to PB 4.30 *

As promised, here's the code I'm working with. It needs more work/optimizing, but it gives you the basics for drawing a custom ListIconGadget. I'll post updated code as I make progress with this and I hope others will as well. :)

Still to do list:

Support #PB_ListIcon_CheckBoxes
Support #PB_ListIcon_AlwaysShowSelection
Support #PB_ListIcon_MultiSelect
Support icons

as well as a few other options I'm sure I missed.

Here's what you should get with the following code:
Image

Code: Select all

; --> Create assorted brushes for passing on to device context 
Global Dim brush(4) 

Enumeration 
  #C0Brush 
  #C1Brush 
  #C2Brush 
  #SelectedBrush 
EndEnumeration 

brush(#C0Brush) = CreateSolidBrush_(RGB(255, 155, 155))       ; column 0 brush 
brush(#C1Brush) = CreateSolidBrush_(RGB(155, 255, 155))       ; column 1 brush 
brush(#C2Brush) = CreateSolidBrush_(RGB(155, 155, 255))       ; column 2 brush 
brush(#SelectedBrush) = CreateSolidBrush_(RGB(255, 255, 155)) ; selected row brush 

; --> Windowcallback 
Procedure myWindowCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *nmhdr.NMHEADER = lParam 
      ; --> Lock column 0 width 
      If *nmhdr\hdr\code = #HDN_ITEMCHANGING  And *nmhdr\iItem = 0 
        result = #True 
      EndIf 
      *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(#SelectedBrush)) 
                Else 
                  ; --> If item is not selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush(#C0Brush)) 
                EndIf 
                ; --> Text color for column 0 
                SetTextColor_(*lvCD\nmcd\hdc, RGB(100, 0, 0)) 
              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(#SelectedBrush)) 
                Else 
                  ; --> If item is not selected, colorize column 1 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush(#C1Brush)) 
                EndIf 
                ; --> Text color for column 1 
                SetTextColor_(*lvCD\nmcd\hdc, RGB(0, 100, 0)) 
              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(#SelectedBrush)) 
                Else 
                  ; --> If item is not selected, colorize column x 
                  FillRect_(*lvCD\nmcd\hdc, subItemRect, brush(#C2Brush)) 
                EndIf 
                ; --> Text color for column x 
                SetTextColor_(*lvCD\nmcd\hdc, RGB(0, 0, 100)) 
            EndSelect 
            ; --> Adjust rect for text margins 
            subItemRect\left +3 
            subItemRect\right -3 
            subItemRect\bottom -3 
            ; --> 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, "Sparkies Multiline ListIconGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  SetWindowCallback(@myWindowCallback()) 
  CreateStatusBar(0, WindowID(0)) 
  ListIconGadget(0, 10, 10, 470, 225, "Column 0", 150) 
  AddGadgetColumn(0, 1, "Column 1", 150) 
  AddGadgetColumn(0, 2, "Column 2", 150) 
  ; --> Create a new imagelist (1x30) to increase row hieght 
  imageList = ImageList_Create_(1, 30, #ILC_COLOR32, 0, 30) 
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, imageList) 
  For a=0 To 9 
    addtext$ = "Locked Column 0 item #" + Str(a) + Chr(13) + "on 2 lines of text." + Chr(10) + "Column 1 item #" + Str(a) + " on 1 line" + Chr(10) + "Column 2 item #" + Str(a) + " on 1 line" 
    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 
EndIf 
End 
Last edited by Sparkie on Sun Jul 26, 2009 3:28 pm, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Hi Sparkie,

sorry that I needed some time to visit the forum. Thank you very much for your code. Never thought it would be that little piece of code! 8O

Hope I'll have some time to take a closer look on it at the Weekend. If I make progress I will post it here. :D

Thanks again
Christian
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Hi,

I managed to have MultiSelect and Icons work. Only AlwaysShowSelection and CheckBoxes missing ... ;)

Have fun!

Code: Select all

; Author: Sparkie & Christian
; Date: 12. December 2004 


; Basics for drawing a custom multiline ListIconGadget 
; **************************************************** 
; You can specify wordwrap for each column as necessary. 
; Here I use wordwrap in Column 0 and single line with ellipsis (...) as needed. 

; Still To-Do list:
; ------------------
; Support #PB_ListIcon_CheckBoxes

; --> Constants 
#LVM_GETSUBITEMRECT = #LVM_FIRST + 56 
#LVM_GETEXTENDEDLISTVIEWSTYLE = #LVM_FIRST + 55
#LVS_EX_CHECKBOXES = $4
#LVS_SHOWSELALWAYS = $8

#DT_WORD_ELLIPSIS = $40000 
#DT_END_ELLIPSIS = $8000 
#DT_PATH_ELLIPSIS = $4000 
#DT_MODIFYSTRING = $10000 

#CDIS_CHECKED = 8 
#CDIS_DEFAULT = $20 
#CDIS_DISABLED = 4 
#CDIS_FOCUS = $10 
#CDIS_GRAYED = 2 
#CDIS_HOT = $40 
#CDIS_INDETERMINATE = $100 
#CDIS_MARKED = $80 
#CDIS_SELECTED = 1 
#CDIS_SHOWKEYBOARDCUES = $200 

#CDDS_ITEM = $10000 
#CDDS_MAPPART = 5 
#CDDS_POSTERASE = 4 
#CDDS_POSTPAINT = 2 
#CDDS_PREERASE = 3 
#CDDS_PREPAINT = 1 
#CDDS_ITEMPOSTERASE = #CDDS_ITEM | #CDDS_POSTERASE 
#CDDS_ITEMPOSTPAINT = #CDDS_ITEM | #CDDS_POSTPAINT 
#CDDS_ITEMPREERASE = #CDDS_ITEM | #CDDS_PREERASE 
#CDDS_ITEMPREPAINT = #CDDS_ITEM | #CDDS_PREPAINT 
#CDDS_SUBITEM = $20000 

#CDRF_DODEFAULT = 0 
#CDRF_NEWFONT = 2 
#CDRF_NOTIFYITEMDRAW = $20 
#CDRF_NOTIFYPOSTERASE = $40 
#CDRF_NOTIFYPOSTPAINT = $10 
#CDRF_NOTIFYSUBITEMDRAW = $20 
#CDRF_SKIPDEFAULT = 4 

#NO_ICON = -1

#IconID = 0

; --> Needed Variables
Global ImgListHnd.l

; --> Create assorted brushes for passing on to device context 
Dim brush(4) 

Enumeration 
  #C0Brush 
  #C1Brush 
  #C2Brush 
  #SelectedBrush
  #AlwaysSelectedBrush
EndEnumeration 

brush(#C0Brush) = CreateSolidBrush_(RGB(255, 155, 155))       ; column 0 brush 
brush(#C1Brush) = CreateSolidBrush_(RGB(155, 255, 155))       ; column 1 brush 
brush(#C2Brush) = CreateSolidBrush_(RGB(155, 155, 255))       ; column 2 brush 
brush(#SelectedBrush) = CreateSolidBrush_(RGB(255, 255, 155)) ; selected row brush 
brush(#AlwaysSelectedBrush) = CreateSolidBrush_(RGB(200, 200, 200)) ; AlwaysShowSelection row brush 

; --> Load Icon
LoadImage(#IconID, "Icon16.bmp") ; Specify your own path -> Image has to be 16*16 or 32*32 in size



; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;                      Procedures
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; --> Get the Extended ListView Styles
Procedure GetExStyle(GadgetID)
  ProcedureReturn SendMessage_(GadgetID(GadgetID), #LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
EndProcedure

; --> Get the Styles of a Gadget
Procedure GetStyle(GadgetID)
  ProcedureReturn GetWindowLong_(GadgetID(GadgetID), #GWL_STYLE)
EndProcedure

; --> Windowcallback 
Procedure myWindowCallback(hwnd, msg, wparam, lparam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
     Case #WM_NOTIFY 
      *nmhdr.NMHEADER = lparam 
      ; --> Lock column 0 width 
      If *nmhdr\hdr\code = #HDN_ITEMCHANGING  And *nmhdr\iItem = 0 
        result = #True 
      EndIf 
      *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$)

            IconRect.RECT
            IconRect\left = #LVIR_ICON; 
            SendMessage_(GadgetID(0), #LVM_GETITEMRECT, thisItem, IconRect); 

            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 GetGadgetItemState(0, thisItem) & #PB_ListIcon_Selected And GetActiveWindow_() = hwnd
                  ; --> If item is selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#SelectedBrush)) 
                ElseIf GetGadgetItemState(0, thisItem) & #PB_ListIcon_Selected And GetActiveWindow_() <> hwnd And GetFocus_() <> GadgetID(0) And GetStyle(0) & #PB_ListIcon_AlwaysShowSelection
                  ; --> If item is selected but gadget has no focus, colorize column 0 
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#AlwaysSelectedBrush))                   
                Else
                  ; --> If item is not selected, colorize column 0 
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#C0Brush)) 
                EndIf 
              ; --> Text color for column 0 
              SetTextColor_(*lvCD\nmcd\hDC, RGB(100, 0, 0)) 

              ; --> Draw Icon if there is one
              ImageList_GetIconSize_(ImgListHnd, @IconWidth, @IconHeight)
              ImageList_Draw_(ImgListHnd, thisItem, *lvCD\nmcd\hDC, IconRect\left, subitemrect\top, #ILD_TRANSPARENT)

              Case 1 
                ; --> Define text and background colors for column 1 and set Drawtext_() flags 
                lvFlags = #DT_END_ELLIPSIS | #DT_SINGLELINE | #DT_VCENTER 
                If GetGadgetItemState(0, thisItem) & #PB_ListIcon_Selected And GetActiveWindow_() = hwnd
                  ; --> If item is selected, colorize column 1
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#SelectedBrush)) And GetActiveWindow_() <> hwnd And GetFocus_() <> GadgetID(0) And GetStyle(0) & #PB_ListIcon_AlwaysShowSelection
                ElseIf GetGadgetItemState(0, thisItem) & #PB_ListIcon_Selected
                  ; --> If item is selected but gadget has no focus, colorize column 1 
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#AlwaysSelectedBrush))                   
                Else 
                  ; --> If item is not selected, colorize column 1 
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#C1Brush)) 
                EndIf 
                ; --> Text color for column 1 
                SetTextColor_(*lvCD\nmcd\hDC, RGB(0, 100, 0)) 

              Case 2 
                ; --> Define text and background colors for column 2 and set Drawtext_() flags 
                lvFlags = #DT_END_ELLIPSIS | #DT_SINGLELINE | #DT_VCENTER 
                If GetGadgetItemState(0, thisItem) & #PB_ListIcon_Selected And GetActiveWindow_() = hwnd
                  ; --> If item is selected, colorize column 2
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#SelectedBrush)) 
                ElseIf GetGadgetItemState(0, thisItem) & #PB_ListIcon_Selected And GetActiveWindow_() <> hwnd And GetFocus_() <> GadgetID(0) And GetStyle(0) & #PB_ListIcon_AlwaysShowSelection
                  ; --> If item is selected but gadget has no focus, colorize column 2
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#AlwaysSelectedBrush))                   
                Else 
                  ; --> If item is not selected, colorize column 2
                  FillRect_(*lvCD\nmcd\hDC, subItemRect, brush(#C2Brush)) 
                EndIf 
                ; --> Text color for column x 
                SetTextColor_(*lvCD\nmcd\hDC, RGB(0, 0, 100)) 
            EndSelect 

            ; --> Adjust rect for text margins
            subItemRect\left + 5 + IconWidth
            subItemRect\right -3 
            subItemRect\bottom -3 
            ; --> Draw our text
            DrawText_(*lvCD\nmcd\hDC, subItemText$, sitLen, subItemRect, lvFlags) 
            result = #CDRF_SKIPDEFAULT 
        EndSelect 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 


; --> Own AddGadgetItem for better handling of the ImagleList
Procedure.l AddGadgetItem_(GadgetID.l, Position.l, Text.s, ImageID.l)
ImgListHnd = SendMessage_(GadgetID(GadgetID), #LVM_GETIMAGELIST, #LVSIL_SMALL, 0)
; --> If there is no ImageList but an image that has to be drawn ...
If ImgListHnd = 0  And ImageID <> -1
    ; --> ... create ImageList ...
    ImgListHnd = ImageList_Create_(32, 32, #ILC_COLORDDB|#ILC_MASK, 0, 0)
    SendMessage_(GadgetID(GadgetID), #LVM_SETIMAGELIST, #LVSIL_SMALL, ImgListHnd)

    ; -- ... check whether image is 16*16 or 32*32 ...
    UseImage(ImageID) : ImageWidth = ImageWidth() : ImageHeight = ImageHeight()
    ; --> ... if 16*16, set size to 32*32 and centre picture ...
    If ImageWidth = 16 And ImageHeight = 16
        CreateImage(ImageID + 1, 32, 32)
        If StartDrawing(ImageOutput())
            Box(0, 0, 32, 32, $000000)
            DrawImage(UseImage(ImageID), 16/2, 16/2)
            StopDrawing()
        EndIf
        ImageID = UseImage(ImageID + 1)
    ElseIf ImageWidth = 32 And ImageHeight = 32
        ImageID = UseImage(ImageID)
    EndIf

    If ImgListHnd
        ; --> ... and add item to ListIconGadget and transparent image to its ImageList
        AddGadgetItem(GadgetID, Position, Text) : ImageList_AddMasked_(ImgListHnd, ImageID, $000000)
    EndIf


; --> If there is an ImageList and an image that has to be drawn ...
ElseIf ImgListHnd And ImageID <> -1
    ; -- ... check whether image is 16*16 or 32*32 ...
    UseImage(ImageID) : ImageWidth = ImageWidth() : ImageHeight = ImageHeight()
    ; --> ... if 16*16, set size to 32*32 and centre picture ...
    If ImageWidth = 16 And ImageHeight = 16
        CreateImage(ImageID + 1, 32, 32)
        If StartDrawing(ImageOutput())
            Box(0, 0, 32, 32, $000000)
            DrawImage(UseImage(ImageID), 16/2, 16/2)
            StopDrawing()
        EndIf
        ImageID = UseImage(ImageID + 1)
    ElseIf ImageWidth = 32 And ImageHeight = 32
        ImageID = UseImage(ImageID)
    EndIf

        ; --> ... and add item to ListIconGadget and transparent image to its ImageList
    AddGadgetItem(GadgetID, Position, Text) : ImageList_AddMasked_(ImgListHnd, ImageID, $000000)


; --> If there is no ImageList and no image that has to be drawn ...
ElseIf ImgListHnd = 0 And ImageID = -1
    ; --> ... create ImageList for having two rows possible ...
    ImgListHnd = ImageList_Create_(1, 32, #ILC_COLORDDB|#ILC_MASK, 0, 0)
    SendMessage_(GadgetID(GadgetID), #LVM_SETIMAGELIST, #LVSIL_SMALL, ImgListHnd)

    If ImgListHnd
        ; --> ... and add item to ListIconGadget without image
        AddGadgetItem(GadgetID, Position, Text); : ImageList_AddMasked_(ImgListHnd, ImageID, $000000)
    EndIf


; --> If there is an ImageList and no image that has to be drawn ...
ElseIf ImgListHnd And ImageID = -1
    ; --> ... add item to ListIconGadget without image
    AddGadgetItem(GadgetID, Position, Text)
EndIf

ProcedureReturn ImgListHnd
EndProcedure


; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;                        Main
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If OpenWindow(0, 0, 0, 500, 260,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Sparkies Multiline ListIconGadget") And CreateGadgetList(WindowID(0)) 
  CreateStatusBar(0, WindowID(0)) 
  ListIconGadget(0, 10, 10, 490, 225, "Column 0", 170, #PB_ListIcon_FullRowSelect | #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "Column 1", 150) 
    AddGadgetColumn(0, 2, "Column 2", 150) 

  For a=0 To 9 
    addtext$ = "Locked Column 0 item #" + Str(a) + Chr(13) + "on 2 lines of text." + Chr(10) + "Column 1 item #" + Str(a) + " on 1 line" + Chr(10) + "Column 2 item #" + Str(a) + " on 1 line" 
    atLen = Len(addtext$) 
    AddGadgetItem_(0, a, addtext$, #IconID) ; last Parameter has to be #NO_ICON if you don't want to draw an icon 
                                            ; else the #ImageID of your image
  Next
  SetWindowCallback(@myWindowCallback())     

  Repeat 
    event = WaitWindowEvent() 
    Select event 
      Case #PB_EventGadget 
        Select EventGadgetID() 
          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 
EndIf 
End 
Post Reply