Add SHGetSpecialFolderPathW to spec file.
[wine.git] / windows / syscolor.c
blob6f69389c5b84659b17ca4bdbba621d5ef23bab7c
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>
13 #include "windef.h"
14 #include "wingdi.h"
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
17 #include "sysmetrics.h"
18 #include "winbase.h"
19 #include "winuser.h"
20 #include "debugtools.h"
21 #include "winreg.h"
22 #include "local.h"
23 #include "user.h"
24 #include "gdi.h" /* sic */
26 DEFAULT_DEBUG_CHANNEL(syscolor);
28 static const char * const DefSysColors[] =
30 "Scrollbar", "224 224 224", /* COLOR_SCROLLBAR */
31 "Background", "192 192 192", /* COLOR_BACKGROUND */
32 "ActiveTitle", "0 64 128", /* COLOR_ACTIVECAPTION */
33 "InactiveTitle", "255 255 255", /* COLOR_INACTIVECAPTION */
34 "Menu", "255 255 255", /* COLOR_MENU */
35 "Window", "255 255 255", /* COLOR_WINDOW */
36 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
37 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
38 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
39 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
40 "ActiveBorder", "128 128 128", /* COLOR_ACTIVEBORDER */
41 "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER */
42 "AppWorkspace", "255 255 232", /* COLOR_APPWORKSPACE */
43 "Hilight", "224 224 224", /* COLOR_HIGHLIGHT */
44 "HilightText", "0 0 0", /* COLOR_HIGHLIGHTTEXT */
45 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
46 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
47 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
48 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
49 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
50 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
51 "3DDarkShadow", "32 32 32", /* COLOR_3DDKSHADOW */
52 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
53 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
54 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
55 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
56 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
57 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
58 "GradientInactiveTitle", "181 181 181" /* COLOR_GRADIENTINACTIVECAPTION */
61 static const char * const DefSysColors95[] =
63 "Scrollbar", "192 192 192", /* COLOR_SCROLLBAR */
64 "Background", "0 128 128", /* COLOR_BACKGROUND */
65 "ActiveTitle", "0 0 128", /* COLOR_ACTIVECAPTION */
66 "InactiveTitle", "128 128 128", /* COLOR_INACTIVECAPTION */
67 "Menu", "192 192 192", /* COLOR_MENU */
68 "Window", "255 255 255", /* COLOR_WINDOW */
69 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
70 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
71 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
72 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
73 "ActiveBorder", "192 192 192", /* COLOR_ACTIVEBORDER */
74 "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER */
75 "AppWorkspace", "128 128 128", /* COLOR_APPWORKSPACE */
76 "Hilight", "0 0 128", /* COLOR_HIGHLIGHT */
77 "HilightText", "255 255 255", /* COLOR_HIGHLIGHTTEXT */
78 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
79 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
80 "GrayText", "128 128 128", /* COLOR_GRAYTEXT */
81 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
82 "InactiveTitleText", "192 192 192",/* COLOR_INACTIVECAPTIONTEXT */
83 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
84 "3DDarkShadow", "0 0 0", /* COLOR_3DDKSHADOW */
85 "3DLight", "224 224 224", /* COLOR_3DLIGHT */
86 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
87 "InfoBackground", "255 255 225", /* COLOR_INFOBK */
88 "AlternateButtonFace", "180 180 180", /* COLOR_ALTERNATEBTNFACE */
89 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
90 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
91 "GradientInactiveTitle", "181 181 181" /* COLOR_GRADIENTINACTIVECAPTION */
95 #define NUM_SYS_COLORS (COLOR_GRADIENTINACTIVECAPTION+1)
97 static COLORREF SysColors[NUM_SYS_COLORS];
98 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
99 static HPEN SysColorPens[NUM_SYS_COLORS];
102 /*************************************************************************
103 * SYSCOLOR_MakeObjectSystem
105 * OK, now for a very ugly hack.
106 * USER somehow has to tell GDI that its system brushes and pens are
107 * non-deletable.
108 * We don't want to export a function from GDI doing this for us,
109 * so we just do that ourselves by "wildly flipping some bits in memory".
110 * For a description of the GDI object magics and their flags,
111 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
113 static void SYSCOLOR_MakeObjectSystem( HGDIOBJ handle, BOOL set)
115 static WORD GDI_heap_sel = 0;
116 LPWORD ptr;
118 if (!GDI_heap_sel)
120 GDI_heap_sel = LoadLibrary16("gdi");
121 FreeLibrary16(GDI_heap_sel);
124 ptr = (LPWORD)LOCAL_Lock(GDI_heap_sel, handle);
126 /* touch the "system" bit of the wMagic field of a GDIOBJHDR */
127 if (set)
128 *(ptr+1) &= ~OBJECT_NOSYSTEM;
129 else
130 *(ptr+1) |= OBJECT_NOSYSTEM;
131 LOCAL_Unlock( GDI_heap_sel, handle );
134 /*************************************************************************
135 * SYSCOLOR_SetColor
137 static void SYSCOLOR_SetColor( int index, COLORREF color )
139 if (index < 0 || index >= NUM_SYS_COLORS) return;
140 SysColors[index] = color;
141 if (SysColorBrushes[index])
143 SYSCOLOR_MakeObjectSystem(SysColorBrushes[index], FALSE);
144 DeleteObject( SysColorBrushes[index] );
146 SysColorBrushes[index] = CreateSolidBrush( color );
147 SYSCOLOR_MakeObjectSystem(SysColorBrushes[index], TRUE);
149 if (SysColorPens[index])
151 SYSCOLOR_MakeObjectSystem(SysColorBrushes[index], FALSE);
152 DeleteObject( SysColorPens[index] );
154 SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
155 SYSCOLOR_MakeObjectSystem(SysColorBrushes[index], TRUE);
159 /*************************************************************************
160 * SYSCOLOR_Init
162 void SYSCOLOR_Init(void)
164 int i, r, g, b;
165 const char * const *p;
166 char buffer[100];
167 BOOL bOk = FALSE, bNoReg = FALSE;
168 HKEY hKey;
170 p = (TWEAK_WineLook == WIN31_LOOK) ? DefSysColors : DefSysColors95;
172 /* first, try to read the values from the registry */
173 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
174 bNoReg = TRUE;
175 for (i = 0; i < NUM_SYS_COLORS; i++)
176 { bOk = FALSE;
178 /* first try, registry */
179 if (!bNoReg)
181 DWORD dwDataSize = sizeof(buffer);
182 if (!(RegQueryValueExA(hKey,(LPSTR)p[i*2], 0, 0, buffer, &dwDataSize)))
183 if (sscanf( buffer, "%d %d %d", &r, &g, &b ) == 3)
184 bOk = TRUE;
187 /* second try, win.ini */
188 if (!bOk)
189 { GetProfileStringA( "colors", p[i*2], p[i*2+1], buffer, 100 );
190 if (sscanf( buffer, " %d %d %d", &r, &g, &b ) == 3)
191 bOk = TRUE;
194 /* last chance, take the default */
195 if (!bOk)
196 { int iNumColors = sscanf( p[i*2+1], " %d %d %d", &r, &g, &b );
197 assert (iNumColors==3);
200 SYSCOLOR_SetColor( i, RGB(r,g,b) );
202 if (!bNoReg)
203 RegCloseKey(hKey);
207 /*************************************************************************
208 * GetSysColor (USER.180)
210 COLORREF WINAPI GetSysColor16( INT16 nIndex )
212 return GetSysColor (nIndex);
216 /*************************************************************************
217 * GetSysColor (USER32.@)
219 COLORREF WINAPI GetSysColor( INT nIndex )
221 if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
222 return SysColors[nIndex];
223 else
224 return 0;
228 /*************************************************************************
229 * SetSysColors (USER.181)
231 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
232 const COLORREF *lpColorValues )
234 int i;
236 for (i = 0; i < nChanges; i++)
238 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
241 /* Send WM_SYSCOLORCHANGE message to all windows */
243 SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
245 /* Repaint affected portions of all visible windows */
247 RedrawWindow( GetDesktopWindow(), NULL, 0,
248 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
252 /*************************************************************************
253 * SetSysColors (USER32.@)
255 BOOL WINAPI SetSysColors( INT nChanges, const INT *lpSysColor,
256 const COLORREF *lpColorValues )
258 int i;
260 for (i = 0; i < nChanges; i++)
262 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
265 /* Send WM_SYSCOLORCHANGE message to all windows */
267 SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
269 /* Repaint affected portions of all visible windows */
271 RedrawWindow( GetDesktopWindow(), NULL, 0,
272 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
273 return TRUE;
276 /*************************************************************************
277 * SetSysColorsTemp (USER32.@)
279 BOOL WINAPI SetSysColorsTemp( int n, const int* p, const COLORREF* ptr)
281 FIXME("(%d,%p,%p): stub!\n", n, p, ptr);
282 return 0;
285 /***********************************************************************
286 * GetSysColorBrush (USER.281)
288 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
290 return (HBRUSH16)GetSysColorBrush(index);
294 /***********************************************************************
295 * GetSysColorBrush (USER32.@)
297 HBRUSH WINAPI GetSysColorBrush( INT index )
299 if (0 <= index && index < NUM_SYS_COLORS)
300 return SysColorBrushes[index];
301 WARN("Unknown index(%d)\n", index );
302 return GetStockObject(LTGRAY_BRUSH);
306 /***********************************************************************
307 * GetSysColorPen (USER32.@) (Not a Windows API)
309 * This function is new to the Wine lib -- it does not exist in
310 * Windows. However, it is a natural complement for GetSysColorBrush
311 * in the Win32 API and is needed quite a bit inside Wine.
313 HPEN WINAPI GetSysColorPen( INT index )
315 /* We can assert here, because this function is internal to Wine */
316 assert (0 <= index && index < NUM_SYS_COLORS);
317 return SysColorPens[index];