Implement the [!file] format to produce the short filename.
[wine/gsoc_dplay.git] / windows / syscolor.c
blob53343be185e04f75ce1f14e0672d14eb76268285
1 /*
2 * Support for system colors
4 * Copyright David W. Metcalfe, 1993
5 * Copyright Alexandre Julliard, 1994
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "winternl.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(syscolor);
37 static const char * const DefSysColors[] =
39 "Scrollbar", "192 192 192", /* COLOR_SCROLLBAR */
40 "Background", "0 128 128", /* COLOR_BACKGROUND */
41 "ActiveTitle", "0 0 128", /* COLOR_ACTIVECAPTION */
42 "InactiveTitle", "128 128 128", /* COLOR_INACTIVECAPTION */
43 "Menu", "192 192 192", /* COLOR_MENU */
44 "Window", "255 255 255", /* COLOR_WINDOW */
45 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
46 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
47 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
48 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
49 "ActiveBorder", "192 192 192", /* COLOR_ACTIVEBORDER */
50 "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER */
51 "AppWorkSpace", "128 128 128", /* COLOR_APPWORKSPACE */
52 "Hilight", "0 0 128", /* COLOR_HIGHLIGHT */
53 "HilightText", "255 255 255", /* COLOR_HIGHLIGHTTEXT */
54 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
55 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
56 "GrayText", "128 128 128", /* COLOR_GRAYTEXT */
57 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
58 "InactiveTitleText", "192 192 192",/* COLOR_INACTIVECAPTIONTEXT */
59 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
60 "ButtonDkShadow", "0 0 0", /* COLOR_3DDKSHADOW */
61 "ButtonLight", "224 224 224", /* COLOR_3DLIGHT */
62 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
63 "InfoWindow", "255 255 225", /* COLOR_INFOBK */
64 "ButtonAlternateFace", "180 180 180", /* COLOR_ALTERNATEBTNFACE */
65 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
66 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
67 "GradientInactiveTitle", "181 181 181",/* COLOR_GRADIENTINACTIVECAPTION */
68 "MenuHilight", "0 0 0", /* COLOR_MENUHILIGHT */
69 "MenuBar", "192 192 192" /* COLOR_MENUBAR */
73 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
75 static COLORREF SysColors[NUM_SYS_COLORS];
76 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
77 static HPEN SysColorPens[NUM_SYS_COLORS];
79 static const WORD wPattern55AA[] =
80 { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
82 HBRUSH SYSCOLOR_55AABrush = 0;
84 extern void __wine_make_gdi_object_system( HGDIOBJ handle, BOOL set );
86 /*************************************************************************
87 * SYSCOLOR_SetColor
89 static void SYSCOLOR_SetColor( int index, COLORREF color )
91 if (index < 0 || index >= NUM_SYS_COLORS) return;
92 SysColors[index] = color;
93 if (SysColorBrushes[index])
95 __wine_make_gdi_object_system( SysColorBrushes[index], FALSE);
96 DeleteObject( SysColorBrushes[index] );
98 SysColorBrushes[index] = CreateSolidBrush( color );
99 __wine_make_gdi_object_system( SysColorBrushes[index], TRUE);
101 if (SysColorPens[index])
103 __wine_make_gdi_object_system( SysColorPens[index], FALSE);
104 DeleteObject( SysColorPens[index] );
106 SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
107 __wine_make_gdi_object_system( SysColorPens[index], TRUE);
111 /*************************************************************************
112 * SYSCOLOR_Init
114 void SYSCOLOR_Init(void)
116 int i, r, g, b;
117 char buffer[100];
118 BOOL bOk = FALSE, bNoReg = FALSE;
119 HKEY hKey;
120 HBITMAP h55AABitmap;
122 /* first, try to read the values from the registry */
123 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
124 bNoReg = TRUE;
125 for (i = 0; i < NUM_SYS_COLORS; i++)
126 { bOk = FALSE;
128 /* first try, registry */
129 if (!bNoReg)
131 DWORD dwDataSize = sizeof(buffer);
132 if (!(RegQueryValueExA(hKey,DefSysColors[i*2], 0, 0, buffer, &dwDataSize)))
133 if (sscanf( buffer, "%d %d %d", &r, &g, &b ) == 3)
134 bOk = TRUE;
137 /* second try, win.ini */
138 if (!bOk)
139 { GetProfileStringA( "colors", DefSysColors[i*2], DefSysColors[i*2+1], buffer, 100 );
140 if (sscanf( buffer, " %d %d %d", &r, &g, &b ) == 3)
141 bOk = TRUE;
144 /* last chance, take the default */
145 if (!bOk)
146 { int iNumColors = sscanf( DefSysColors[i*2+1], " %d %d %d", &r, &g, &b );
147 assert (iNumColors==3);
150 SYSCOLOR_SetColor( i, RGB(r,g,b) );
152 if (!bNoReg)
153 RegCloseKey(hKey);
155 h55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
156 SYSCOLOR_55AABrush = CreatePatternBrush( h55AABitmap );
157 __wine_make_gdi_object_system( SYSCOLOR_55AABrush, TRUE );
161 /*************************************************************************
162 * GetSysColor (USER32.@)
164 COLORREF WINAPI GetSysColor( INT nIndex )
166 if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
167 return SysColors[nIndex];
168 else
169 return 0;
173 /*************************************************************************
174 * SetSysColors (USER32.@)
176 BOOL WINAPI SetSysColors( INT nChanges, const INT *lpSysColor,
177 const COLORREF *lpColorValues )
179 int i;
181 for (i = 0; i < nChanges; i++)
183 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
186 /* Send WM_SYSCOLORCHANGE message to all windows */
188 SendMessageTimeoutW( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0,
189 SMTO_ABORTIFHUNG, 2000, NULL );
191 /* Repaint affected portions of all visible windows */
193 RedrawWindow( GetDesktopWindow(), NULL, 0,
194 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
195 return TRUE;
198 /*************************************************************************
199 * SetSysColorsTemp (USER32.@)
201 * UNDOCUMENTED !!
203 * Called by W98SE desk.cpl Control Panel Applet:
204 * handle = SetSysColorsTemp(ptr, ptr, nCount); ("set" call)
205 * result = SetSysColorsTemp(NULL, NULL, handle); ("restore" call)
207 * pPens is an array of COLORREF values, which seems to be used
208 * to indicate the color values to create new pens with.
210 * pBrushes is an array of solid brush handles (returned by a previous
211 * CreateSolidBrush), which seems to contain the brush handles to set
212 * for the system colors.
214 * n seems to be used for
215 * a) indicating the number of entries to operate on (length of pPens,
216 * pBrushes)
217 * b) passing the handle that points to the previously used color settings.
218 * I couldn't figure out in hell what kind of handle this is on
219 * Windows. I just use a heap handle instead. Shouldn't matter anyway.
221 * RETURNS
222 * heap handle of our own copy of the current syscolors in case of
223 * "set" call, i.e. pPens, pBrushes != NULL.
224 * TRUE (unconditionally !) in case of "restore" call,
225 * i.e. pPens, pBrushes == NULL.
226 * FALSE in case of either pPens != NULL and pBrushes == NULL
227 * or pPens == NULL and pBrushes != NULL.
229 * I'm not sure whether this implementation is 100% correct. [AM]
231 DWORD WINAPI SetSysColorsTemp( const COLORREF *pPens, const HBRUSH *pBrushes, DWORD n)
233 int i;
235 if (pPens && pBrushes) /* "set" call */
237 /* allocate our structure to remember old colors */
238 LPVOID pOldCol = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD)+n*sizeof(HPEN)+n*sizeof(HBRUSH));
239 LPVOID p = pOldCol;
240 *(DWORD *)p = n; p = (char*)p + sizeof(DWORD);
241 memcpy(p, SysColorPens, n*sizeof(HPEN)); p = (char*)p + n*sizeof(HPEN);
242 memcpy(p, SysColorBrushes, n*sizeof(HBRUSH)); p = (char*)p + n*sizeof(HBRUSH);
244 for (i=0; i < n; i++)
246 SysColorPens[i] = CreatePen( PS_SOLID, 1, pPens[i] );
247 SysColorBrushes[i] = pBrushes[i];
250 return (DWORD)pOldCol;
252 if ((!pPens) && (!pBrushes)) /* "restore" call */
254 LPVOID pOldCol = (LPVOID)n;
255 LPVOID p = pOldCol;
256 DWORD nCount = *(DWORD *)p;
257 p = (char*)p + sizeof(DWORD);
259 for (i=0; i < nCount; i++)
261 DeleteObject(SysColorPens[i]);
262 SysColorPens[i] = *(HPEN *)p; p = (char*)p + sizeof(HPEN);
264 for (i=0; i < nCount; i++)
266 SysColorBrushes[i] = *(HBRUSH *)p; p = (char*)p + sizeof(HBRUSH);
268 /* get rid of storage structure */
269 HeapFree(GetProcessHeap(), 0, pOldCol);
271 return TRUE;
273 return FALSE;
276 /***********************************************************************
277 * GetSysColorBrush (USER32.@)
279 HBRUSH WINAPI GetSysColorBrush( INT index )
281 if (0 <= index && index < NUM_SYS_COLORS)
282 return SysColorBrushes[index];
283 WARN("Unknown index(%d)\n", index );
284 return GetStockObject(LTGRAY_BRUSH);
288 /***********************************************************************
289 * SYSCOLOR_GetPen
291 HPEN SYSCOLOR_GetPen( INT index )
293 /* We can assert here, because this function is internal to Wine */
294 assert (0 <= index && index < NUM_SYS_COLORS);
295 return SysColorPens[index];