2 * Support for system colors
4 * Copyright David W. Metcalfe, 1993
5 * Copyright Alexandre Julliard, 1994
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
17 #include "sysmetrics.h"
20 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(syscolor)
26 static const char * const DefSysColors[] =
28 "Scrollbar", "224 224 224", /* COLOR_SCROLLBAR */
29 "Background", "192 192 192", /* COLOR_BACKGROUND */
30 "ActiveTitle", "0 64 128", /* COLOR_ACTIVECAPTION */
31 "InactiveTitle", "255 255 255", /* COLOR_INACTIVECAPTION */
32 "Menu", "255 255 255", /* COLOR_MENU */
33 "Window", "255 255 255", /* COLOR_WINDOW */
34 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
35 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
36 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
37 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
38 "ActiveBorder", "128 128 128", /* COLOR_ACTIVEBORDER */
39 "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER */
40 "AppWorkspace", "255 255 232", /* COLOR_APPWORKSPACE */
41 "Hilight", "224 224 224", /* COLOR_HIGHLIGHT */
42 "HilightText", "0 0 0", /* COLOR_HIGHLIGHTTEXT */
43 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
44 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
45 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
46 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
47 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
48 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
49 "3DDarkShadow", "32 32 32", /* COLOR_3DDKSHADOW */
50 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
51 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
52 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
53 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
54 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
55 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
56 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
59 static const char * const DefSysColors95[] =
61 "Scrollbar", "223 223 223", /* COLOR_SCROLLBAR */
62 "Background", "192 192 192", /* COLOR_BACKGROUND */
63 "ActiveTitle", "0 0 128", /* COLOR_ACTIVECAPTION */
64 "InactiveTitle", "128 128 128", /* COLOR_INACTIVECAPTION */
65 "Menu", "192 192 192", /* COLOR_MENU */
66 "Window", "255 255 255", /* COLOR_WINDOW */
67 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
68 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
69 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
70 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
71 "ActiveBorder", "192 192 192", /* COLOR_ACTIVEBORDER */
72 "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER */
73 "AppWorkspace", "128 128 128", /* COLOR_APPWORKSPACE */
74 "Hilight", "0 0 128", /* COLOR_HIGHLIGHT */
75 "HilightText", "255 255 255", /* COLOR_HIGHLIGHTTEXT */
76 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
77 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
78 "GrayText", "128 128 128", /* COLOR_GRAYTEXT */
79 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
80 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
81 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
82 "3DDarkShadow", "0 0 0", /* COLOR_3DDKSHADOW */
83 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
84 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
85 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
86 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
87 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
88 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
89 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
93 #define NUM_SYS_COLORS (COLOR_GRADIENTINACTIVECAPTION+1)
95 static COLORREF SysColors[NUM_SYS_COLORS];
96 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
97 static HPEN SysColorPens[NUM_SYS_COLORS];
99 #define MAKE_SOLID(color) \
100 (PALETTEINDEX(GetNearestPaletteIndex(STOCK_DEFAULT_PALETTE,(color))))
102 /*************************************************************************
105 static void SYSCOLOR_SetColor( int index, COLORREF color )
107 if (index < 0 || index >= NUM_SYS_COLORS) return;
108 SysColors[index] = color;
109 if (SysColorBrushes[index]) DeleteObject( SysColorBrushes[index] );
110 SysColorBrushes[index] = CreateSolidBrush( color );
111 if (SysColorPens[index]) DeleteObject( SysColorPens[index] );
112 SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
116 /*************************************************************************
119 void SYSCOLOR_Init(void)
122 const char * const *p;
124 BOOL bOk = FALSE, bNoReg = FALSE;
127 p = (TWEAK_WineLook == WIN31_LOOK) ? DefSysColors : DefSysColors95;
129 /* first, try to read the values from the registry */
130 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
132 for (i = 0; i < NUM_SYS_COLORS; i++)
135 /* first try, registry */
138 DWORD dwDataSize = sizeof(buffer);
139 if (!(RegQueryValueExA(hKey,(LPSTR)p[i*2], 0, 0, buffer, &dwDataSize)))
140 if (sscanf( buffer, "%d %d %d", &r, &g, &b ) == 3)
144 /* second try, win.ini */
146 { GetProfileStringA( "colors", p[i*2], p[i*2+1], buffer, 100 );
147 if (sscanf( buffer, " %d %d %d", &r, &g, &b ) == 3)
151 /* last chance, take the default */
153 { int iNumColors = sscanf( p[i*2+1], " %d %d %d", &r, &g, &b );
154 assert (iNumColors==3);
157 SYSCOLOR_SetColor( i, RGB(r,g,b) );
164 /*************************************************************************
165 * GetSysColor16 (USER.180)
167 COLORREF WINAPI GetSysColor16( INT16 nIndex )
169 return GetSysColor (nIndex);
173 /*************************************************************************
174 * GetSysColor (USER32.289)
176 COLORREF WINAPI GetSysColor( INT nIndex )
178 if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
179 return SysColors[nIndex];
185 /*************************************************************************
186 * SetSysColors16 (USER.181)
188 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
189 const COLORREF *lpColorValues )
193 for (i = 0; i < nChanges; i++)
195 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
198 /* Send WM_SYSCOLORCHANGE message to all windows */
200 SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
202 /* Repaint affected portions of all visible windows */
204 RedrawWindow( GetDesktopWindow(), NULL, 0,
205 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
209 /*************************************************************************
210 * SetSysColors (USER32.505)
212 BOOL WINAPI SetSysColors( INT nChanges, const INT *lpSysColor,
213 const COLORREF *lpColorValues )
217 for (i = 0; i < nChanges; i++)
219 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
222 /* Send WM_SYSCOLORCHANGE message to all windows */
224 SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
226 /* Repaint affected portions of all visible windows */
228 RedrawWindow( GetDesktopWindow(), NULL, 0,
229 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
234 /***********************************************************************
235 * GetSysColorBrush16 (USER.281)
237 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
239 return (HBRUSH16)GetSysColorBrush(index);
243 /***********************************************************************
244 * GetSysColorBrush (USER32.290)
246 HBRUSH WINAPI GetSysColorBrush( INT index )
248 if (0 <= index && index < NUM_SYS_COLORS)
249 return SysColorBrushes[index];
250 WARN("Unknown index(%d)\n", index );
251 return GetStockObject(LTGRAY_BRUSH);
255 /***********************************************************************
256 * GetSysColorPen16 (Not a Windows API)
258 HPEN16 WINAPI GetSysColorPen16( INT16 index )
260 return (HPEN16)GetSysColorPen(index);
264 /***********************************************************************
265 * GetSysColorPen (Not a Windows API)
267 * This function is new to the Wine lib -- it does not exist in
268 * Windows. However, it is a natural complement for GetSysColorBrush
269 * in the Win32 API and is needed quite a bit inside Wine.
271 HPEN WINAPI GetSysColorPen( INT index )
273 /* We can assert here, because this function is internal to Wine */
274 assert (0 <= index && index < NUM_SYS_COLORS);
275 return SysColorPens[index];