Page 1 of 1
Changeing ListIconGadget's Item-Select color
Posted: Sat Aug 09, 2008 4:21 pm
by Tranquil
I have got a little problem to struggle with:
Is it possible to change the color of a selected Item in a listview? On XP it's mostly black. If the gadget has not focus any more it's shown in a very light gray, nearly white. I also want to change this color. possible?
Posted: Sat Aug 09, 2008 10:35 pm
by freak
It uses the colors from the system color settings. I think the only way to overwrite this locally is to ownerdraw the items.
Posted: Sat Aug 09, 2008 11:17 pm
by Sparkie
*** Edit to fix bugs
This is cut out from some old code of mine and could use a little TLC but it shows the basics.
Quickly tested and working on XP...
Code: Select all
#LVS_EX_CHECKBOXES = 4
;... Create brushes for painting item background
Structure MYBRUSHES
brushDefault.l
brushFocus.l
brushSelected.l
EndStructure
Global brush.MYBRUSHES
brush\brushSelected = CreateSolidBrush_(RGB(128, 255, 128))
brush\brushFocus = CreateSolidBrush_(RGB(200, 255, 200))
brush\brushDefault = GetStockObject_(#WHITE_BRUSH)
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*nmhdr.NMHDR = 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
thisRow = *lvCD\nmcd\dwItemSpec
thisCol = *lvCD\iSubItem
;... Draw checkboxes as needed
exStyle = SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
If thisCol = 0 And exStyle & #LVS_EX_CHECKBOXES
stateList = SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETIMAGELIST, #LVSIL_STATE, 0)
ckState = SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETITEMSTATE, thisRow, #LVIS_STATEIMAGEMASK) >>12 -1
checkRect.RECT\left = #LVIR_ICON
checkRect.RECT\top = 0
SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETITEMRECT, thisRow, @checkRect)
ImageList_Draw_(stateList, ckState, *lvCD\nmcd\hdc, 0, checkRect\top, #ILD_TRANSPARENT)
EndIf
;... Define rect for text
subItemRect.RECT\left = #LVIR_LABEL
subItemRect.RECT\top = *lvCD\iSubItem
;... Get the subitem rect
SendMessage_(*lvCD\nmcd\hdr\hwndFrom, #LVM_GETSUBITEMRECT, thisRow, @subItemRect)
subItemText$ = GetGadgetItemText(0, thisRow, thisCol)
If GetGadgetItemState(*lvCD\nmcd\hdr\idFrom, thisRow) & #PB_ListIcon_Selected And GetFocus_() <> *lvCD\nmcd\hdr\hwndFrom
FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushFocus)
ElseIf GetGadgetItemState(*lvCD\nmcd\hdr\idFrom, thisRow) & #PB_ListIcon_Selected And GetFocus_() = *lvCD\nmcd\hdr\hwndFrom
FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushSelected)
Else
FillRect_(*lvCD\nmcd\hdc, subItemRect, brush\brushDefault)
EndIf
;.. Set left margin
subItemRect\left + 3
DrawText_(*lvCD\nmcd\hdc, subItemText$, Len(subItemText$), subItemRect, #DT_WORD_ELLIPSIS | #DT_SINGLELINE | #DT_VCENTER)
result = #CDRF_SKIPDEFAULT
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 480, 260, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@myWindowCallback())
ListIconGadget(0, 10, 10, 470, 225, "Column 0", 150, #PB_ListIcon_CheckBoxes | #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Column 1", 150)
For a = 0 To 9
addtext$ = "Column 0 Item " + Str(a) + Chr(10) + "Column 1 Item " + Str(a)
atLen = Len(addtext$)
AddGadgetItem(0,-1, addtext$)
Next
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
DeleteObject_(brush\brushSelected)
DeleteObject_(brush\brushFocus)
EndIf
End
Posted: Sun Aug 10, 2008 1:44 pm
by Tranquil
Thanks both of you. I hoped to came arround owner drawed items as I have dynamicly added listicongadgets with multiselection enabled on many MDI-Windows which does not make it easier.
Maybe I will use SetGadgetItemColor() to do this with some tricks.
Posted: Sun Aug 10, 2008 2:27 pm
by Mike Yurgalavage
Tranquil wrote:Thanks both of you. I hoped to came arround owner drawed items as I have dynamicly added listicongadgets with multiselection enabled on many MDI-Windows which does not make it easier.
Maybe I will use SetGadgetItemColor() to do this with some tricks.
here's a small snippet of code from a project i am working on:
If TotalFiles = MaxFiles
AddGadgetItem(7, TotalFiles-1, "REGISTER TO SEE MORE STUFF!")
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_FrontColor,RGB(180,0,0) )
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_BackColor,RGB(200,255,255) )
Else
AddGadgetItem(7, TotalFiles-1, FileEntry$)
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_FrontColor,#Black)
SetGadgetItemColor(7,TotalFiles-1,#PB_Gadget_BackColor,RGB(255,255,255) )
endif
sets the color of a single item in the list. at least it works for me-
hope this helps-
best,
Mike
Posted: Sun Aug 10, 2008 3:01 pm
by AND51
@ Sparkie:
Not correctly working on 4.20/Vista.
Posted: Sun Aug 10, 2008 4:14 pm
by rsts
Looks OK to me wih Vista. What seems to be wrong?
cheers
Posted: Sun Aug 10, 2008 6:35 pm
by Denis
AND51 wrote:@ Sparkie:
Not correctly working on 4.20/Vista.
The same here.
Posted: Sun Aug 10, 2008 9:26 pm
by Sparkie
Yes, it is a bit buggy isn't it. I'll take a look under the hood and see what's come loose.

Posted: Sun Aug 10, 2008 9:43 pm
by Sparkie
I edited my original code and it should work better now. I still need to fix the code to allow for checkboxes.
Posted: Mon Aug 11, 2008 1:08 am
by Sparkie
Code ^up there^ should now work on XP and Vista.

Posted: Mon Aug 11, 2008 8:22 am
by Denis
Now it's Ok under Vista and PB 4.20
Tks parkie
