Page 11 of 35

Posted: Sat Dec 03, 2005 8:08 pm
by Straker
whoops. :oops:

That did it. Thanks for the reply.

Posted: Sat Dec 10, 2005 11:45 am
by gnozal
Update

Changes :
- new parameter #PureCOLOR_LV_AlternateColors2 for PureCOLOR_SetGadgetColorEx() : alternate ListIconView column colors
- some fixes

Different Colours for each line of a ComboBoxGadet (HowTo??)

Posted: Mon Dec 12, 2005 10:04 pm
by Hartmut
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

Re: Different Colours for each line of a ComboBoxGadet (HowT

Posted: Tue Dec 13, 2005 8:43 am
by gnozal
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
Actually no. Maybe in the future, I don't know.
Maybe this helps : viewtopic.php?t=14334&start=0&postdays=0&postorder=asc

Posted: Wed Dec 14, 2005 11:54 am
by Hartmut
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 :)

Posted: Wed Dec 14, 2005 1:20 pm
by zikitrake
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 :)
You can try MoreComboBoxGadget Lib (from purearea.net)

Posted: Wed Dec 14, 2005 11:29 pm
by Hartmut
Thanks for the hint.
I will give it a try in the next few days.

Cheers

Hartmut

Posted: Tue Dec 20, 2005 3:01 pm
by gnozal
Update

No more Callback needed

Posted: Wed Dec 21, 2005 12:32 am
by DoubleDutch
Tested the new method and it seems to have a problem co-existing with my customdraw treegadget. It used to work fine.

I init the tree (#Subjects) then have a container next to it that contains a text gadget and a listicon gadget. I then connect the container with the subject tree with a splitter gadget - see this code:

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)
If I then do a

Code: Select all

PureCOLOR_SetGadgetColor(#FavouritesBorder,Palette(#NormalTextColour),#PureCOLOR_DontSetBackColor)
Then I lose the customdraw of the tree (thats at the other side of the splitter)!!! Commenting out the line will keep my ownerdraw working.

Posted: Wed Dec 21, 2005 12:41 am
by DoubleDutch
Here is some code to show the problem directly:

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
See what I mean?

Posted: Wed Dec 21, 2005 10:12 am
by gnozal
Update

Changes :
- Fixed TreeView ownerdraw problem

Posted: Wed Dec 21, 2005 10:43 am
by DoubleDutch
Thanks, it now works great! :D

Posted: Thu Dec 22, 2005 8:53 am
by gnozal
Flype 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.
Fixed

Posted: Fri Dec 23, 2005 10:36 pm
by DoubleDutch
Now it seems to mess up the ownerdraw menus...

Please see:

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  
The menu is now all the way across the screen...

Infact you can delete the callback and it still goes wrong - I think its the line:

Code: Select all

ModifyMenu_(MenuID(),item,#MF_BYCOMMAND|#MF_OWNERDRAW,item,iMenuItems())
Please note that the button is just there for illustration, I use other gadgets that also cause this - its just that the button is easier to demonstrate.

Hope this info helps... :)

Posted: Sat Dec 24, 2005 9:37 am
by gnozal
Update

Changes :
- Fixed ownerdraw menu inferference

@ DoubleDutch : when it receives a #WM_MEASUREITEM or #WM_DRAWITEM message sent by a menu, PureCOLOR now checks if there is a PureCOLOR defined menu. The new uploaded library does not react to #WM_MEASUREITEM / #WM_DRAWITEM with your code example.
I could not test it further because your menu is looking strange anyway on my current system (WinNT4).