Posted: Sat Dec 03, 2005 8:08 pm
whoops.
That did it. Thanks for the reply.

That did it. Thanks for the reply.
http://www.purebasic.com
https://www.purebasic.fr/english/
Actually no. Maybe in the future, I don't know.Hartmut wrote:Hi there ...
i am using this great Library for my current project, but there seems to be one thing that cant be done with it.
Is it possible to create different colors for each entry of a Comboboxgadget ?
I would appreciate every hint i can get.
Thanks in advance
Hartmut
You can try MoreComboBoxGadget Lib (from purearea.net)Hartmut wrote:Thanks for the quick answer.
So I will have to wait for an update in the future.
Meanwhile my ComboBoxGadgets will stay uncoloured.
Thanks anyway
Code: Select all
ContainerGadget(#FavouritesWindow,0,0,0,0)
TextGadget(#FavouritesBorder,3,0,200,15," ")
ListIconGadget(#Favourites,0,#SpcY*4,0,0," ",500,#PB_ListIcon_FullRowSelect)
CloseGadgetList()
SplitterGadget(#SubjectSplitter,#STBWidth,0,0,0,#Subjects,#FavouritesWindow,#PB_Splitter_Vertical|#PB_Splitter_Separator|#PB_Splitter_SecondFixed)
Code: Select all
PureCOLOR_SetGadgetColor(#FavouritesBorder,Palette(#NormalTextColour),#PureCOLOR_DontSetBackColor)
Code: Select all
Enumeration
#MainWindow
#TreeGadget
#SubjectSplitter
#FavouritesWindow
#FavouritesBorder
#Favourites
EndEnumeration
#CDIS_FOCUS = $10
#CDIS_SELECTED = 1
#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
Procedure MyWindowCallback(WindowID,Message,wParam,lParam)
Result=#PB_ProcessPureBasicEvents
Select Message
Case #WM_NOTIFY
*tvCD.NMTVCUSTOMDRAW=lparam
If *tvCD\nmcd\hdr\hwndFrom=GadgetID(#TreeGadget) And *tvCD\nmcd\hdr\code=#NM_CUSTOMDRAW
Select *tvCD\nmcd\dwDrawStage
Case #CDDS_PREPAINT
ProcedureReturn #CDRF_NOTIFYPOSTPAINT|#CDRF_NOTIFYITEMDRAW
Case #CDDS_PREPAINT
ProcedureReturn #CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT
Select *tvCD\iLevel
Case 0
If *tvCD\nmcd\uItemState=(#CDIS_FOCUS|#CDIS_SELECTED)
*tvCD\clrText=RGB(255,255,0)
*tvCD\clrTextBk=RGB(0,0,255)
Else
*tvCD\clrText=RGB(255,255,0)
*tvCD\clrTextBk=RGB(0,0,255)
EndIf
Default
If *tvCD\nmcd\uItemState=(#CDIS_FOCUS|#CDIS_SELECTED)
*tvCD\clrText=RGB(255,255,255)
*tvCD\clrTextBk=RGB(128,0,128)
Else
*tvCD\clrText=RGB(0,255,0)
*tvCD\clrTextBk=RGB(0,128,0)
EndIf
EndSelect
ProcedureReturn #CDRF_NEWFONT
EndSelect
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
If OpenWindow(#MainWindow,0,0,355,180,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"TreeGadget") And CreateGadgetList(WindowID(0))
TreeGadget(#TreeGadget,0,0,0,0)
ContainerGadget(#FavouritesWindow,0,0,0,0)
TextGadget(#FavouritesBorder,3,0,200,15,"blah")
ListIconGadget(#Favourites,0,50,70,100," ",500,#PB_ListIcon_FullRowSelect)
CloseGadgetList()
SplitterGadget(#SubjectSplitter,10,10,330,160,#TreeGadget,#FavouritesWindow,#PB_Splitter_Vertical|#PB_Splitter_Separator|#PB_Splitter_SecondFixed)
For a=0 To 10
AddGadgetItem (#TreeGadget,-1,"Normal Item "+Str(a))
AddGadgetItem (#TreeGadget,-1,"Node "+Str(a))
OpenTreeGadgetNode(#TreeGadget)
AddGadgetItem(#TreeGadget,-1,"Sub-Item 1")
AddGadgetItem(#TreeGadget,-1,"Sub-Item 2")
AddGadgetItem(#TreeGadget,-1,"Sub-Item 3")
AddGadgetItem(#TreeGadget,-1,"Sub-Item 4")
CloseTreeGadgetNode(#TreeGadget)
AddGadgetItem (#TreeGadget,-1,"File "+Str(a))
Next
SetWindowCallback(@MyWindowCallback())
PureCOLOR_SetGadgetColor(#FavouritesBorder,RGB(255,0,255),#PureCOLOR_DontSetBackColor) ; <---- remove this line and the tree will customdraw as it should...
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
FixedFlype wrote:just a little bug ( or missing feature ) : the function PureCOLOR_SetGadgetColorEx(#Gadget,$000000,$FFFFFF,0,#PureCOLOR_LTV_SelectedItem) doesn't work when applied on a ListIconGadget() created with the flag #PB_ListIcon_AlwaysShowSelection.
Code: Select all
#MenuLeftMargin=25
#MenuIconSize=22
#DT_END_ELLIPSIS = $8000
#MIIM_STATE = 1
Global iMenu_Font,iMenu_Tick,iMenu_Background
Structure iMenuItem ;Used to store information on individual menu items.
id.l
hmenu.l
textcolour.l ;Unselected colour.
hicon.l ;Handle to the icon to be used
rlength.l
llength.l
EndStructure
NewList iMenuItems.iMenuItem()
Procedure iMenuCallbackProc(hWnd, uMsg, wParam, lParam, result)
Protected *lpmis.MEASUREITEMSTRUCT, *menuitem.iMenuItem, *lpdis.DRAWITEMSTRUCT, menuitinf.MENUITEMINFO, itemtext$
Protected rc.RECT, hFontOld, hdc, size.SIZE, pen, brush, oldpen, oldbrush, icontop
Select uMsg
Case #WM_MEASUREITEM ;This message is called when the menu / submenu is first created and is used to size the menu items.
*lpmis = lParam
If *lpmis\CtlType = #ODT_MENU ;Don't want this to run for an owner drawn button etc!
*menuitem = *lpmis\itemData
itemtext$=Space(255)
GetMenuString_(*menuitem\hmenu, *lpmis\itemid, @itemtext$,255,#MF_BYCOMMAND)
hdc = GetDC_(hWnd)
hFontOld = SelectObject_(hdc,iMenu_Font)
GetTextExtentPoint32_(hdc,itemtext$,Len(itemtext$),@size)
*lpmis\itemWidth = size\cx+#MenuLeftMargin
*lpmis\itemHeight = 22
SelectObject_(hdc,hOldFont)
ReleaseDC_(hWnd,hdc)
result = #True
EndIf
Case #WM_DRAWITEM
*lpdis = lParam
If *lpdis\CtlType = #ODT_MENU ;Don't want this to run for an owner drawn button etc!
*menuitem = *lpdis\itemData
itemtext$=Space(255)
GetMenuString_(*menuitem\hmenu, *lpdis\itemid, @itemtext$,255,#MF_BYCOMMAND)
hdc = *lpdis\hDC
SetBkMode_(hdc,#TRANSPARENT)
hOldFont = SelectObject_(hdc, iMenu_Font)
GetTextExtentPoint32_(hdc,@itemtext$,Len(itemtext$),@size)
menuitinf\cbSize = SizeOf(MENUITEMINFO)
menuitinf\fMask = #MIIM_STATE
GetMenuItemInfo_(*menuitem\hmenu, *lpdis\itemid, #False, @menuitinf)
icon=*menuitem\hicon
If *lpdis\itemState & #ODS_CHECKED
icon=iMenu_Tick
EndIf
If *lpdis\itemState & #ODS_SELECTED
;Check to see if the menu item is disabled.
If menuitinf\fState & #MFS_GRAYED = 0
SetTextColor_(hdc,RGB(160,20,90))
brush=CreateSolidBrush_(RGB(30,50,90))
borderpen=CreatePen_(#PS_SOLID, 1, 0)
oldbrush = SelectObject_(hdc,brush)
oldpen=SelectObject_(hdc,borderpen)
Rectangle_(hdc, *lpdis\rcItem\left-10, *lpdis\rcItem\top, *lpdis\rcItem\right, *lpdis\rcItem\bottom)
icontop = (*lpdis\rcItem\top+*lpdis\rcItem\bottom-#MenuIconSize)/2
DrawIconEx_(hdc,*lpdis\rcItem\left,icontop,icon,#MenuIconSize,#MenuIconSize,0,0,3)
*lpdis\rcItem\top=(*lpdis\rcItem\top+*lpdis\rcItem\bottom-size\cy)/2
*lpdis\rcItem\right-3
*lpdis\rcItem\left+#MenuLeftMargin
DrawText_(hdc, @itemtext$,*menuitem\llength, *lpdis\rcItem,#DT_END_ELLIPSIS|#ES_LEFT)
If *menuitem\rlength>0
SetTextColor_(hdc,RGB(30,90,20))
DrawText_(hdc, @itemtext$+*menuitem\llength+1,*menuitem\rlength, *lpdis\rcItem,#DT_END_ELLIPSIS|#ES_RIGHT)
EndIf
EndIf
Else
;Check to see if the menu item is disabled.
If menuitinf\fState & #MFS_GRAYED = 0
SetTextColor_(hdc,*menuitem\textcolour)
Else
SetTextColor_(hdc,RGB(20,40,30))
EndIf
brush=CreateSolidBrush_(iMenu_Background)
borderpen=GetStockObject_(#NULL_PEN)
oldbrush = SelectObject_(hdc,brush)
oldpen=SelectObject_(hdc,borderpen)
Rectangle_(hdc, *lpdis\rcItem\left-10, *lpdis\rcItem\top, *lpdis\rcItem\right+1, *lpdis\rcItem\bottom+1)
icontop = (*lpdis\rcItem\top+*lpdis\rcItem\bottom-#MenuIconSize)/2
DrawIconEx_(hdc,*lpdis\rcItem\left,icontop,icon,#MenuIconSize,#MenuIconSize,0,0,3)
*lpdis\rcItem\top=(*lpdis\rcItem\top+*lpdis\rcItem\bottom-size\cy)/2
*lpdis\rcItem\right-3
*lpdis\rcItem\left+#MenuLeftMargin
DrawText_(hdc, @itemtext$,*menuitem\llength, *lpdis\rcItem,#DT_END_ELLIPSIS|#ES_LEFT)
If *menuitem\rlength>0
SetTextColor_(hdc,RGB(20,90,30))
DrawText_(hdc, @itemtext$+*menuitem\llength+1,*menuitem\rlength, *lpdis\rcItem,#DT_END_ELLIPSIS|#ES_RIGHT)
EndIf
EndIf
;Tidy up.
SelectObject_(hdc,oldpen)
SelectObject_(hdc,oldbrush)
SelectObject_(hdc,hOldFont)
DeleteObject_(brush) : DeleteObject_(borderpen)
result = #True
EndIf
EndSelect
ProcedureReturn result
EndProcedure
Procedure iMenuItemIconColour(item,text$,icon$,txcolour)
iconaddr=#Null
If MenuItem(item,text$)
AddElement(iMenuItems())
iMenuItems()\id=item
iMenuItems()\hmenu=MenuID()
iMenuItems()\textcolour=txcolour
iMenuItems()\hicon =iconaddr
pos=FindString(text$,Chr(9),1)
If pos
llen=pos-1
rlen=Len(text$)-pos
Else
llen=Len(text$)
rlen=0
EndIf
imenuItems()\llength=llen
iMenuItems()\rlength=rlen
ModifyMenu_(MenuID(),item,#MF_BYCOMMAND|#MF_OWNERDRAW,item,iMenuItems())
EndIf
EndProcedure
Procedure iMenuItemIcon(item,text$,icon$)
iMenuItemIconColour(item,text$,icon$,RGB(0,0,0))
EndProcedure
Procedure iMenuItem(item,text$)
iMenuItemIconColour(item,text$,"",RGB(0,0,0))
EndProcedure
Procedure MyWindowCallback(WindowID,Message,wParam,lParam)
Result=#PB_ProcessPureBasicEvents
Result=iMenuCallbackProc(WindowID,Message,wParam,lParam,Result)
ProcedureReturn Result
EndProcedure
If OpenWindow(0, 100, 150, 195, 260, #PB_Window_SystemMenu, "PureBasic - Menu")
iMenu_Font=LoadFont(0,"Arial",10)
iMenu_Background=GetSysColor_(#COLOR_MENU)
If CreateMenu(0, WindowID())
MenuTitle("File")
iMenuItem( 1, "&Load...")
iMenuItem( 2, "Save")
iMenuItem( 3, "Save As...")
MenuBar()
OpenSubMenu("Recents")
iMenuItem( 5, "C:\Autoexec.bat")
iMenuItem( 6, "D:\Test.txt")
OpenSubMenu("Even more !")
iMenuItem( 12, "Test")
CloseSubMenu()
iMenuItem( 13, "C:\Ok.bat")
CloseSubMenu()
MenuBar()
iMenuItem( 7, "&Quit")
EndIf
CreateGadgetList(WindowID())
ButtonGadget(0,10,10,90,30,"button")
SetWindowCallback(@MyWindowCallback())
PureCOLOR_SetButtonColor(0, RGB(255,0,255), RGB(0,255,255))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
End
Code: Select all
ModifyMenu_(MenuID(),item,#MF_BYCOMMAND|#MF_OWNERDRAW,item,iMenuItems())