Converted to the new debug interface, using script written by Patrik
[wine.git] / windows / syscolor.c
blob1d63b6fb4b119292fa5b72c9f3c45d04ab14199c
1 /*
2 * Support for system colors
4 * Copyright David W. Metcalfe, 1993
5 * Copyright Alexandre Julliard, 1994
7 */
9 #include <assert.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "winbase.h"
13 #include "winuser.h"
14 #include "debug.h"
15 #include "tweak.h"
16 #include "winreg.h"
17 #include "winversion.h"
19 DEFAULT_DEBUG_CHANNEL(syscolor)
21 static const char * const DefSysColors[] =
23 "Scrollbar", "224 224 224", /* COLOR_SCROLLBAR */
24 "Background", "192 192 192", /* COLOR_BACKGROUND */
25 "ActiveTitle", "0 64 128", /* COLOR_ACTIVECAPTION */
26 "InactiveTitle", "255 255 255", /* COLOR_INACTIVECAPTION */
27 "Menu", "255 255 255", /* COLOR_MENU */
28 "Window", "255 255 255", /* COLOR_WINDOW */
29 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
30 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
31 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
32 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
33 "ActiveBorder", "128 128 128", /* COLOR_ACTIVEBORDER */
34 "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER */
35 "AppWorkspace", "255 255 232", /* COLOR_APPWORKSPACE */
36 "Hilight", "224 224 224", /* COLOR_HIGHLIGHT */
37 "HilightText", "0 0 0", /* COLOR_HIGHLIGHTTEXT */
38 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
39 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
40 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
41 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
42 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
43 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
44 "3DDarkShadow", "32 32 32", /* COLOR_3DDKSHADOW */
45 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
46 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
47 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
48 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
49 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
50 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
51 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
54 static const char * const DefSysColors95[] =
56 "Scrollbar", "223 223 223", /* COLOR_SCROLLBAR */
57 "Background", "192 192 192", /* COLOR_BACKGROUND */
58 "ActiveTitle", "0 0 128", /* COLOR_ACTIVECAPTION */
59 "InactiveTitle", "128 128 128", /* COLOR_INACTIVECAPTION */
60 "Menu", "192 192 192", /* COLOR_MENU */
61 "Window", "255 255 255", /* COLOR_WINDOW */
62 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
63 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
64 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
65 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
66 "ActiveBorder", "192 192 192", /* COLOR_ACTIVEBORDER */
67 "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER */
68 "AppWorkspace", "128 128 128", /* COLOR_APPWORKSPACE */
69 "Hilight", "0 0 128", /* COLOR_HIGHLIGHT */
70 "HilightText", "255 255 255", /* COLOR_HIGHLIGHTTEXT */
71 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
72 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
73 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
74 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
75 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
76 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
77 "3DDarkShadow", "0 0 0", /* COLOR_3DDKSHADOW */
78 "3DLight", "223 223 223", /* COLOR_3DLIGHT */
79 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
80 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
81 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
82 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
83 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
84 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
88 #define NUM_SYS_COLORS (COLOR_GRADIENTINACTIVECAPTION+1)
90 static COLORREF SysColors[NUM_SYS_COLORS];
91 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
92 static HPEN SysColorPens[NUM_SYS_COLORS];
94 #define MAKE_SOLID(color) \
95 (PALETTEINDEX(GetNearestPaletteIndex(STOCK_DEFAULT_PALETTE,(color))))
97 /*************************************************************************
98 * SYSCOLOR_SetColor
100 static void SYSCOLOR_SetColor( int index, COLORREF color )
102 if (index < 0 || index >= NUM_SYS_COLORS) return;
103 SysColors[index] = color;
104 if (SysColorBrushes[index]) DeleteObject( SysColorBrushes[index] );
105 SysColorBrushes[index] = CreateSolidBrush( color );
106 if (SysColorPens[index]) DeleteObject( SysColorPens[index] );
107 SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
111 /*************************************************************************
112 * SYSCOLOR_Init
114 void SYSCOLOR_Init(void)
116 int i, r, g, b;
117 const char * const *p;
118 char buffer[100];
119 BOOL bOk = FALSE, bNoReg = FALSE;
120 HKEY hKey;
121 DWORD dwDataSize = 32;
123 p = (TWEAK_WineLook == WIN31_LOOK) ? DefSysColors : DefSysColors95;
125 /* first, try to read the values from the registry */
126 if (VERSION_GetVersion() != WIN31)
128 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
129 bNoReg = TRUE;
132 for (i = 0; i < NUM_SYS_COLORS; i++)
133 { bOk = FALSE;
135 /* first try, registry */
136 if (!bNoReg)
137 if (!(RegQueryValueExA(hKey, (LPSTR)(p[i*2]), 0, 0, (LPBYTE) &buffer[0], &dwDataSize)))
138 if (sscanf( buffer, "%d %d %d", &r, &g, &b ) == 3)
139 bOk = TRUE;
141 /* second try, win.ini */
142 if (!bOk)
143 { GetProfileStringA( "colors", p[i*2], p[i*2+1], buffer, 100 );
144 if (sscanf( buffer, " %d %d %d", &r, &g, &b ) == 3)
145 bOk = TRUE;
148 /* last chance, take the default */
149 if (!bOk)
150 { int iNumColors = sscanf( p[i*2+1], " %d %d %d", &r, &g, &b );
151 assert (iNumColors==3);
154 SYSCOLOR_SetColor( i, RGB(r,g,b) );
156 if (!bNoReg)
157 RegCloseKey(hKey);
162 /*************************************************************************
163 * GetSysColor16 (USER.180)
165 COLORREF WINAPI GetSysColor16( INT16 nIndex )
167 return GetSysColor (nIndex);
171 /*************************************************************************
172 * GetSysColor32 (USER32.289)
174 COLORREF WINAPI GetSysColor( INT nIndex )
176 if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
177 return SysColors[nIndex];
178 else
179 return 0;
183 /*************************************************************************
184 * SetSysColors16 (USER.181)
186 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
187 const COLORREF *lpColorValues )
189 int i;
191 for (i = 0; i < nChanges; i++)
193 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
196 /* Send WM_SYSCOLORCHANGE message to all windows */
198 SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
200 /* Repaint affected portions of all visible windows */
202 RedrawWindow( GetDesktopWindow(), NULL, 0,
203 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
207 /*************************************************************************
208 * SetSysColors32 (USER32.505)
210 BOOL WINAPI SetSysColors( INT nChanges, const INT *lpSysColor,
211 const COLORREF *lpColorValues )
213 int i;
215 for (i = 0; i < nChanges; i++)
217 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
220 /* Send WM_SYSCOLORCHANGE message to all windows */
222 SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
224 /* Repaint affected portions of all visible windows */
226 RedrawWindow( GetDesktopWindow(), NULL, 0,
227 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
228 return TRUE;
232 /***********************************************************************
233 * GetSysColorBrush16 (USER.281)
235 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
237 return (HBRUSH16)GetSysColorBrush(index);
241 /***********************************************************************
242 * GetSysColorBrush32 (USER32.290)
244 HBRUSH WINAPI GetSysColorBrush( INT index )
246 if (0 <= index && index < NUM_SYS_COLORS)
247 return SysColorBrushes[index];
248 WARN(syscolor, "Unknown index(%d)\n", index );
249 return GetStockObject(LTGRAY_BRUSH);
253 /***********************************************************************
254 * GetSysColorPen16 (Not a Windows API)
256 HPEN16 WINAPI GetSysColorPen16( INT16 index )
258 return (HPEN16)GetSysColorPen(index);
262 /***********************************************************************
263 * GetSysColorPen32 (Not a Windows API)
265 * This function is new to the Wine lib -- it does not exist in
266 * Windows. However, it is a natural complement for GetSysColorBrush
267 * in the Win32 API and is needed quite a bit inside Wine.
269 HPEN WINAPI GetSysColorPen( INT index )
271 /* We can assert here, because this function is internal to Wine */
272 assert (0 <= index && index < NUM_SYS_COLORS);
273 return SysColorPens[index];