PureCOLOR library

Overview

Coloring gadgets in Purebasic as simply as possible.

Works for almost all gadgets, including standard ButtonGadgets.

PB 4.xx version ; note that some PureCOLOR features now exist as native Purebasic 4.xx functions.
I recommend using the genuine PB functions whenever it's possible.

Functions

PureCOLOR_SetGadgetColor(GadgetNumber.l, TextColor.l, BackColor.l)

Set gadget colors (any supported gadget except a ButtonGadget).

Important : for buttons, use PureCOLOR_SetButtonColor().

TextColor and BackColor are RGB values.

Special values :

- TextColor :
  #PureCOLOR_SystemColor => TextColor is system color
  #PureCOLOR_UseLastColor => TextColor is the last color set (don't change current color)

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color
  #PureCOLOR_DontSetBackColor => Simulates transparency
  #PureCOLOR_UseLastColor => BackColor is the last color set (don't change current color)

Notes :

1. Transparency : #PureCOLOR_DontSetBackColor is only supported for Text/Option/CheckBox gadgets
2. XP themes : PureCOLOR does not fully support XP themes.
	If your application is themed,
	- PanelGadget backcolor is ignored
	- Some gadgets will loose their theme in order to keep their colors
3. Class issues : for better result (less flickering), PureCOLOR uses SetClassLong() to color PanelGadgets, ContainerGadgets and PureScrollAreaGadgets.
	This means that if you colorize one gadget, all gadgets within the same class will have the same colors.
4. ListIconGadget grid lines and PureCOLOR :
	Since version 4.30, PB uses ownerdraw for the gridlines, and this may conflict with some PureCOLOR functions.
	If the grid lines disappear, use this workaround : SendMessage_(GadgetID(#MyListIcon), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_GRIDLINES, #LVS_EX_GRIDLINES)
PureCOLOR_SetGadgetColorEx(GadgetNumber.l, TextColor.l, BackColor.l, Param.l, Flag.l)

Extended version of PureCOLOR_SetGadgetColor()

PureCOLOR_SetGadgetColorEx(GadgetNumber.l, TextColor.l, BackColor.l, 0, #PureCOLOR_LV_Standard) is equivalent to PureCOLOR_SetGadgetColor(GadgetNumber.l, TextColor.l, BackColor.l)


Colors :

TextColor and BackColor are RGB values.

Special values :

- TextColor :
  #PureCOLOR_SystemColor => TextColor is system color

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color
  #PureCOLOR_DontSetBackColor => Simulates transparency
  #PureCOLOR_UseLastColor => BackColor is the last color set (don't change current color)

Notes : see PureCOLOR_SetGadgetColor() notes.

Flags : * LISTICON GADGET

           - #PureCOLOR_LV_AlternateColors  [Param is a long (Param.l)]
  
            Alternate ListIconView row colors :		BackColor  -> Even row color
		                         		Param.l      -> Odd row color
            
           - #PureCOLOR_LV_AlternateColors2  [Param is a long (Param.l)]
  
            Alternate ListIconView column colors :	BackColor  -> Even column color
		                         		Param.l      -> Odd column color

            Note that #PureCOLOR_LV_AlternateColors and #PureCOLOR_LV_AlternateColors2 are mutually exclusive.

           - #PureCOLOR_LV_GreaterThan      [Param is a structure address (@Param.PureCOLOR_ParamStructure)]
          
            Value dependant cell colors       :		Param\SpecialTextColor -> text color
                                                                	Param\SpecialBackColor -> back color
	                                                               	Param\SpecialTestValue -> test value
            
            Gadget cell color is (Param\SpecialTextColor, Param\SpecialBackColor) if the cell value is > Param\SpecialTestValue
            If Param\SpecialBackColor = #PureCOLOR_DontSetBackColor, there is no background color change                        
            [WORKS WITH NUMERIC CELL VALUES ONLY]
            
           - #PureCOLOR_LV_LesserThan       [Param is a structure address (@Param.PureCOLOR_ParamStructure)]
          
            Value dependant cell colors       :		Param\SpecialTextColor -> text color
		                                                Param\SpecialBackColor -> back color
                                		                Param\SpecialTestValue -> test value
            
            Gadget cell color is (Param\SpecialTextColor, Param\SpecialBackColor) if the cell value is < Param\SpecialTestValue
            If Param\SpecialBackColor = #PureCOLOR_DontSetBackColor, there is no background color change                        
            [WORKS WITH NUMERIC CELL VALUES ONLY]
           
          * TREE GADGET
         
           - #PureCOLOR_TV_NodeLevel1  [Param is a long (Param.l)]
           
            Set colors for node level 1 (and TreeGadget background color) : TextColor.l, BackColor.l
            If Param = #PureCOLOR_DontSetBackColor, there is no background color change
         
           - #PureCOLOR_TV_NodeLevel2  [Param = 0]
           
            Set colors for node level 2 (and TreeGadget background color) : TextColor.l, BackColor.l

           - #PureCOLOR_TV_NodeLevel3  [Param = 0]
           
            Set colors for node level 3 (and TreeGadget background color) : TextColor.l, BackColor.l

           - #PureCOLOR_TV_NodeLevel4  [Param = 0]
           
            Set colors for node level 4 (and TreeGadget background color) : TextColor.l, BackColor.l
            
           The node levels > 4 are colored like node 1
           
          * TREE OR LISTICON GADGETS
         
           - #PureCOLOR_LTV_SelectedItem  [Param = 0]
           
            Set colors for the selected item (selection bar) : TextColor.l, BackColor.l

          * MISCELLANOUS GADGETS

           - #PureCOLOR_BackgroundImage        [Param is a long (Param.l)]

             Set a 'transparent' backcolor for the gadget (backcolor = image color)
             Param is the image output id.
PureCOLOR_GetGadgetColor(GadgetNumber.l, WhatColor.l)

Get the gadget colors set with PureCOLOR_SetGadgetColor() .

WhatColor :

1 : TextColor
2 : BackColor
PureCOLOR_ClearGadgetColor(GadgetNumber.l)

Clear PureCOLOR resources set with PureCOLOR_SetGadgetColor(), PureCOLOR_SetGadgetColorEx().
PureCOLOR_SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l [, TextColorPushed.l [, BackColorPushed.l]])

Set button colors.

All colors are are RGB values.

Optional parameters :

TextColorPushed :	text color when button is pushed (and toggle text color)
BackColorPushed :	back color when button is pushed (and toggle back color)

Special values :

#PureCOLOR_SystemColor => color is system color
#PureCOLOR_UseLastColor => color is the last color set (don't change current color)

Note : if disabled, the button looses all colors, i.e. looks like a standard disabled button.
PureCOLOR_SetIconButton(GadgetNumber.l, TextColor.l, BackColor.l, Icon.l)

Define an icon button.

All colors are are RGB values.
Icon is an icon image number.

Special values :

#PureCOLOR_SystemColor => color is system color
#PureCOLOR_UseLastColor => color is the last color set (don't change current color)
PureCOLOR_SetIconToggleButton(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l, Icon.l, IconPushed.l)

Define an toggle icon button.

All colors are are RGB values.
Icon and IconPushed are icon image numbers.

TextColorPushed :	text color when button is pushed (and toggle text color)
BackColorPushed :	back color when button is pushed (and toggle back color)
IconPushed :	icon when button is pushed or toggled

Special values :

#PureCOLOR_SystemColor => color is system color
#PureCOLOR_UseLastColor => color is the last color set (don't change current color)
PureCOLOR_GetButtonColor(GadgetNumber.l, WhatColor.l)

Get the gadget colors set with PureCOLOR_SetButtonColor(), PureCOLOR_SetIconButton() and PureCOLOR_SetIconToggleButton().

WhatColor :

1 : TextColor
2 : BackColor
3 : TextColor 2
4 : BackColor 2
PureCOLOR_ClearButtonColor(GadgetNumber.l)

Clear PureCOLOR resources set with PureCOLOR_SetButtonColor(), PureCOLOR_SetIconButton() and PureCOLOR_SetIconToggleButton().
PureCOLOR_SetCellColor(ListIconNumber.l, Row.l, Column.l, TextColor.l, BackColor.l)

Set listicon cell color.

TextColor and BackColor are RGB values.

Special values :

- TextColor :
  #PureCOLOR_SystemColor => TextColor is system color

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color

Note : the listicon cell / row / column coloring functions use dynamic coordinates, e.g. the colorized cells / rows / columns coordinates are changed in realtime when the listicon [Add|Remove]Gadget[Item|Column]() functions are used.
For example : if cell (1,1) is colorized and a column is added at position 1, the cell coordinates are changed to (1,2) : the cell remains colorized (the new cell (1,1) is not).
For better speed, use PureCOLOR_SetCellColorCallback().
PureCOLOR_GetCellColor(ListIconNumber.l, Row.l, Column.l, WhatColor.l)

Get the listicon cell color, set with the PureCOLOR SetCellColor() / SetColumnColor() / SetRowColor() functions. 

Returned values :

- Cell TextColor if WhatColor = 1 
- Cell BackColor if WhatColor = 2 
- #CLR_DEFAULT if no color is set for the cell or the cell don't exist 

TextColor and BackColor are RGB values.
PureCOLOR_ClearCellColor(ListIconNumber.l, Row.l, Column.l)

Clear listicon cell color.
PureCOLOR_SetCellColorCallback(WindowNumber.l, *ProcedureAddress)

Declare a ListIcon coloring callback for the specified window.

The callback is a procedure called for each cell in a ListIconGadget. It allows the user to modify the cell colors according to its content.

The callback procedure is like this :

Procedure MyCellColorCallback(GadgetNumber.l, CellRow.l, CellColumn.l, *TextColor.LONG, *BackColor.LONG, *FontID.LONG)
 ;
 ; Do Stuff
 ;
EndProcedure

declared like that :

PureCOLOR_SetCellColorCallback(#MyWindow,  @MyCellColorCallback())

where :

GadgetNumber is the purebasic gadget ID
CellRow is the cell row
CellColumn is the cell column
*TextColor is a pointer to the cell text color
*BackColor is a pointer to the cell back color
*FontID is a pointer to the font ID

Note : you are supposed to call PureCOLOR_SetGadgetColor() before this function to ensure the gadget is subclassed.
It may not be necessary if the gadget's parent is a window.
A simple PureCOLOR_SetGadgetColor(#Listicon, #PureCOLOR_SystemColor, #PureCOLOR_SystemColor) does the trick.
PureCOLOR_ResetCellColorCallback(*ProcedureAddress)

Reset the cell colorization callback address set with PureCOLOR_SetCellColorCallback().

If *ProcedureAddress is #Null, the callback is inactivated.
PureCOLOR_SetColumnColor(ListIconNumber.l, Column.l, TextColor.l, BackColor.l)

Set listicon column color.

TextColor and BackColor are RGB values.

Special values :

- TextColor :
  #PureCOLOR_SystemColor => TextColor is system color

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color

Note : the listicon cell / row / column coloring functions use dynamic coordinates, e.g. the colorized cells / rows / columns coordinates are changed in realtime when the listicon [Add|Remove]Gadget[Item|Column]() functions are used.
For example : if cell (1,1) is colorized and a column is added at position 1, the cell coordinates are changed to (1,2) : the cell remains colorized (the new cell (1,1) is not).
For better speed, use PureCOLOR_SetCellColorCallback().
PureCOLOR_ClearColumnColor(ListIconNumber.l, Column.l)

Clear listicon column color.
PureCOLOR_SetRowColor(ListIconNumber.l, Row.l, TextColor.l, BackColor.l)

Set listicon row color.

TextColor and BackColor are RGB values.

Special values :

- TextColor :
  #PureCOLOR_SystemColor => TextColor is system color

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color

Note : the listicon cell / row / column coloring functions use dynamic coordinates, e.g. the colorized cells / rows / columns coordinates are changed in realtime when the listicon [Add|Remove]Gadget[Item|Column]() functions are used.
For example : if cell (1,1) is colorized and a column is added at position 1, the cell coordinates are changed to (1,2) : the cell remains colorized (the new cell (1,1) is not).
For better speed, use PureCOLOR_SetCellColorCallback().
PureCOLOR_ClearRowColor(ListIconNumber.l, Row.l)

Clear listicon row color.
PureCOLOR_SetTreeItemColor(TreeNumber.l, itemNumber.l, TextColor.l, BackColor.l)

Set tree item color.

TextColor and BackColor are RGB values.

Special values :

- TextColor :
  #PureCOLOR_SystemColor => TextColor is system color

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color
PureCOLOR_ClearTreeItemColor(TreeNumber.l, itemNumber.l)

Clear tree item color.
PureCOLOR_SetColumnHeaderColor(ListIconNumber.l, Column.l, TextColor.l, BackColor.l [, Font.l])

Set listicon column header color (and font).

TextColor and BackColor are RGB values.
Font is a font ID.

Special values :

- TextColor :
  #PureCOLOR_SystemColor => TextColor is system color

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color

Note : this function uses dynamic coordinates, e.g. the colorized columns coordinates are changed in realtime when the listicon [Add|Remove]GadgetColumn() functions are used.
PureCOLOR_ClearColumnHeaderColor(ListIconNumber.l, Column.l)

Clear listicon column header color.
PureCOLOR_ClearAllColorsForGadget(GadgetNumber.l)

Clear all colors for the specified gadget.

Usefull for complex gadgets like ListIcon or TreeView (clears cells colors, row colors, column colors, etc...).
PureCOLOR_ClearAllGadgetColors()

Clear all gadget PureCOLOR resources (except buttons).
PureCOLOR_ClearAllButtonColors()

Clear all button PureCOLOR resources.
PureCOLOR_SetWindowColor(WindowNumber.l, BackColor.l)

Set window back color.

BackColor is a RGB value.

Special values :

- BackColor :
  #PureCOLOR_SystemColor => BackColor is system color
PureCOLOR_ClearWindowColor(WindowNumber.l)

Clear window color.
PureCOLOR_RedrawGadgetAfterColor(TrueOrFalse.l)

If #True [Default], the gadget is redrawn [RedrawWindow()] after a color is set or cleared.

The gadget redraw is enabled by default ; for time critical procedures (like coloring much elements in a ListIconGadget), you may disable the gadget redraw and enable it afterwards.
The gadget redraw can also be set to #False to avoid flickering in some cases (you might have to redraw the gadget manually though).
PureCOLOR_RedrawButtonAfterColor(TrueOrFalse.l)

If #True, the button is redrawn [RedrawWindow()] after a color is cleared.

The button redraw is enabled by default. It can be set to #False to avoid flickering in some cases (you might have to redraw the gadget manually though).
PureCOLOR_MenuItem(MenuNumber.l, MenuItem.l, MenuText.s [, IconID.l])

Add a menu item.

It works like the genuine MenuItem() function except that you can add an icon id.
PureCOLOR_SetMenuItemText(MenuNumber.l, MenuItem.l, MenuText.s)

Change a colored menu item text.
PureCOLOR_GetMenuItemText(MenuNumber.l, MenuItem.l)

Get a colored menu item text.
PureCOLOR_ActivateColoredMenu(MenuNumber.l)

Activate a colored menu.

The menu is created with the usual Purebasic functions, except that MenuItem() has to be replaced with PureCOLOR_MenuItem().

Notes :
- This function must be called after the menu is created.
- For popup menus, use PureCOLOR_ActivateColoredPopUpMenu().
PureCOLOR_ActivateColoredPopUpMenu(MenuNumber.l, WindowNumber.l)

Activate a colored popup menu.

The popup menu is created with the usual Purebasic functions, except that MenuItem() has to be replaced with PureCOLOR_MenuItem().

Note :
- This function must be called after the menu is created. 





PureCOLOR_SetMenuOptions(MenuNumber.l, MenuTextColor.l, MenuDisabledTextColor.l, MenuBackColor.l, MenuHighlightText.l, MenuHighlightBack.l, MenuCheckedText.l, MenuIconSize.l, MenuItemHeight.l, MenuTabAlign.l)

Set menu options.

Availables options :
- MenuIconSize : menu icon size [default is 16 (for 16 x 16)]
- MenuItemHeight : menu item heigth [default is 20]
- MenuTextColor : menu text color [default is GetSysColor_(#COLOR_MENUTEXT)]
- MenuDisabledTextColor : menu text color for disabled items [default is GetSysColor_(#COLOR_GRAYTEXT)]
- MenuBackColor  : menu background color [default is GetSysColor_(#COLOR_MENU)]
- MenuHighlightText : menu text color for highlighted items [default is GetSysColor_(#COLOR_HIGHLIGHTTEXT)]
- MenuHighlightBack : menu background color for highlighted items [default is GetSysColor_(#COLOR_HIGHLIGHT)]
- MenuCheckedText : menu text color for checked items [default is GetSysColor_(#COLOR_MENUTEXT)]
- MenuTabAlign : tabbed menu text alignment (#DT_RIGHT, #DT_LEFT, #DT_CENTER) [default is #DT_RIGHT]

Notes :
You can set the default option with -1 or #PB_Ignore.
This function must be called after PureCOLOR_ActivateColoredMenu().
PureCOLOR_SetOfficeStyle(MenuNumber.l)

Set Office style for menu.

Notes :
- This function must be called after PureCOLOR_ActivateColoredMenu().
- For popup menus, use PureCOLOR_SetPopUpOfficeStyle().
PureCOLOR_SetPopUpOfficeStyle(MenuNumber.l, WindowNumber.l)

Set Office style for popup menu. 

Note :
This function must be called after PureCOLOR_ActivateColoredPopUpMenu(). 

PureCOLOR_SetMenuItemSelectionCallback(*ProcedureAddress)

Set a menu item selection callback.

The callback is a procedure called each time a menu item is (un)selected.

The callback procedure is like this :

Procedure MyMenuItemSelectionCallback(WindowHandle.l, MenuItemID.l, MenuItemText.s)
 ;
 ; Do Stuff
 ;
EndProcedure

declared like that :

PureCOLOR_SetMenuItemSelectionCallback(@MyMenuItemSelectionCallback())

where :

WindowHandle identifies the window wich the menu is assigned to
MenuItemID is the currently selected menu item [if MenuItemID >= 0]
MenuItemText is the currently selected menu item text
PureCOLOR_SetPopupMenuBackColor(MenuNumber.l, BackColor.l)

Set PopUp menu backcolor.

Returned value :
- backcolor brush if success (delete it when not used anymore) ;
- 0 if failed.

Note :
This function has no effect on Win NT4.
PureCOLOR_FreeMenu(MenuNumber.l)

Free colored menu.
Use this function when you would use FreeMenu().
PureCOLOR_FreePopUpMenu(MenuNumber.l, WindowNumber.l)

Free colored popup menu.
Use this function when you would use FreeMenu().
PureCOLOR_Version()

Get PureCOLOR library version.

Returns a string, like "XX.XX".