PureCOLOR library
Overview
Coloring gadgets in Purebasic as simply as possible.Functions
PureCOLOR_SetGadgetColor(GadgetNumber.l, TextColor.l, BackColor.l)Set gadget colors (any gadget except a ButtonGadget).PureCOLOR_SetGadgetColorEx(GadgetNumber.l, TextColor.l, BackColor.l, Param.l, Flag.l)
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)
Extended version of PureCOLOR_SetGadgetColor()PureCOLOR_GetGadgetColor(GadgetNumber.l, WhatColor.l)
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, like ImageOutput(#Image).
- #PureCOLOR_ImageID [Param is a long (Param.l)]
Set a background image for the gadget.
Param is the image ID, like ImageID(#Image).
Get the gadget colors set with PureCOLOR_SetGadgetColor().PureCOLOR_ClearGadgetColor(GadgetNumber.l)
WhatColor :
1 : TextColor
2 : BackColor
Clear PureCOLOR resources set with PureCOLOR_SetGadgetColor(), PureCOLOR_SetGadgetColorEx().PureCOLOR_SetCellColor(ListIconNumber.l, Row.l, Column.l, TextColor.l, BackColor.l)
Set listicon cell color.PureCOLOR_GetCellColor(ListIconNumber.l, Row.l, Column.l, WhatColor.l)
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().
Get the listicon cell color, set with the PureCOLOR SetCellColor() / SetColumnColor() / SetRowColor() functions.PureCOLOR_ClearCellColor(ListIconNumber.l, Row.l, Column.l)
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 doesn't exist
TextColor and BackColor are RGB values.
Clear listicon cell color.PureCOLOR_SetCellColorCallback(WindowNumber.l, *ProcedureAddress)
Declare a ListIcon coloring callback for the specified window.PureCOLOR_ResetCellColorCallback(*ProcedureAddress)
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
Notes :
1. You are supposed to call PureCOLOR_SetGadgetColor() before this function to ensure the gadget is subclassed.
A simple PureCOLOR_SetGadgetColor(#Listicon, #PureCOLOR_SystemColor, #PureCOLOR_SystemColor) does the trick.
2. If you change the font using *FontID\l, the standard row height may become too small.
You may increase it by using SetGadgetFont(MyListIcon, FontID)
Reset the cell colorization callback address set with PureCOLOR_SetCellColorCallback().PureCOLOR_SetColumnColor(ListIconNumber.l, Column.l, TextColor.l, BackColor.l)
If *ProcedureAddress is #Null, the callback is inactivated.
Set listicon column color.PureCOLOR_ClearColumnColor(ListIconNumber.l, Column.l)
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().
Clear listicon column color.PureCOLOR_SetRowColor(ListIconNumber.l, Row.l, TextColor.l, BackColor.l)
Set listicon row color.PureCOLOR_ClearRowColor(ListIconNumber.l, Row.l)
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().
Clear listicon row color.PureCOLOR_SetTreeItemColor(TreeNumber.l, itemNumber.l, TextColor.l, BackColor.l)
Set tree item color.PureCOLOR_ClearTreeItemColor(TreeNumber.l, itemNumber.l)
TextColor and BackColor are RGB values.
Special values :
- TextColor :
#PureCOLOR_SystemColor => TextColor is system color
- BackColor :
#PureCOLOR_SystemColor => BackColor is system color
Clear tree item color.PureCOLOR_SetColumnHeaderColor(ListIconNumber.l, Column.l, TextColor.l, BackColor.l [, Font.l])
Set listicon column header color (and font).PureCOLOR_ClearColumnHeaderColor(ListIconNumber.l, Column.l)
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.
Clear listicon column header color.PureCOLOR_ClearAllColorsForGadget(GadgetNumber.l)
Clear all colors for the specified gadget.PureCOLOR_ClearAllGadgetColors()
Usefull for complex gadgets like ListIcon or TreeView (clears cells colors, row colors, column colors, etc...).
Clear all gadget (except buttons) PureCOLOR resources.PureCOLOR_RedrawGadgetAfterColor(TrueOrFalse.l)
If #True [Default], the gadget is redrawn [RedrawWindow()] after a color is set or cleared.PureCOLOR_SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l [, TextColorPushed.l [, BackColorPushed.l]])
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).
Set button colors.PureCOLOR_GetButtonColor(GadgetNumber.l, WhatColor.l)
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 : to disable a colored button, use PureCOLOR_DisableButton().
Get the gadget colors set withPureCOLOR_SetIconButton(GadgetNumber.l, TextColor.l, BackColor.l, Icon.l)
- PureCOLOR_SetButtonColor(),
- PureCOLOR_SetIconButton(),
- PureCOLOR_SetIconToggleButton().
WhatColor :
1 : TextColor
2 : BackColor
3 : TextColor 2
4 : BackColor 2
Define an icon button.PureCOLOR_SetIconToggleButton(GadgetNumber.l, TextColor.l, BackColor.l, TextColorPushed.l, BackColorPushed.l, Icon.l, IconPushed.l)
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)
Note : to disable such a button, use PureCOLOR_DisableButton().
Define an toggle icon button.PureCOLOR_DisableButton(GadgetNumber.l, Disabled.l)
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)
Note : to disable such a button, use PureCOLOR_DisableButton().
Disable or enable a colored / icon button.PureCOLOR_ClearButtonColor(GadgetNumber.l)
Use this function instead of DisableGadget().
Clear PureCOLOR resources set withPureCOLOR_ClearAllButtonColors()
- PureCOLOR_SetButtonColor(),
- PureCOLOR_SetIconButton(),
- PureCOLOR_SetIconToggleButton().
Clear all button PureCOLOR resourcesPureCOLOR_RedrawButtonAfterColor(TrueOrFalse.l)
If #True [Default], the button is redrawn [RedrawWindow()] after a color is cleared.PureCOLOR_SetWindowColor(WindowNumber.l, BackColor.l)
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).
Set window back color.PureCOLOR_ClearWindowColor(WindowNumber.l)
BackColor is a RGB value.
Special values :
- BackColor :
#PureCOLOR_SystemColor => BackColor is system color
Clear window color.PureCOLOR_MenuItem(MenuNumber.l, MenuItem.l, MenuText.s [, IconID.l])
Add a menu item.PureCOLOR_SetMenuItemText(MenuNumber.l, MenuItem.l, MenuText.s)
It works like the genuine MenuItem() function.
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.PureCOLOR_ActivateColoredPopUpMenu(MenuNumber.l, WindowNumber.l)
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().
Activate a colored popup menu.PureCOLOR_SetMenuOptions(MenuNumber.l, MenuTextColor.l, MenuDisabledTextColor.l, MenuBackColor.l, MenuHighlightText.l, MenuHighlightBack.l, MenuCheckedText.l, MenuIconSize.l, MenuItemHeight.l, MenuTabAlign.l)
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.
Set menu options.PureCOLOR_SetOfficeStyle(MenuNumber.l)
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().
Set Office style for menu.PureCOLOR_SetPopUpOfficeStyle(MenuNumber.l, WindowNumber.l)
Notes :
- This function must be called after PureCOLOR_ActivateColoredMenu().
- For popup menus, use PureCOLOR_SetPopUpOfficeStyle().
Set Office style for popup menu.PureCOLOR_SetMenuItemSelectionCallback(*ProcedureAddress)
Note :
This function must be called after PureCOLOR_ActivateColoredPopUpMenu().
Set a menu item selection callback.PureCOLOR_SetPopupMenuBackColor(MenuNumber.l, BackColor.l)
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
Set PopUp menu backcolor.PureCOLOR_FreeMenu(MenuNumber.l)
Returned value :
- backcolor brush if success (delete it when not used anymore) ;
- 0 if failed.
Note :
This function has no effect on Win NT4.
Free colored menu.PureCOLOR_FreePopUpMenu(MenuNumber.l, WindowNumber.l)
Use this function when you would use FreeMenu().
Free colored popup menu.PureCOLOR_Version()
Use this function when you would use FreeMenu().
Get PureCOLOR library version.
Returns a string, like "XX.XX".