- Unixware (Solaris) linker typo fixed
[wine/wine64.git] / windows / syscolor.c
blob1dddaceaa38926007826daccbc9894d597b932d8
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 "wine/winbase16.h"
14 #include "wine/winuser16.h"
15 #include "sysmetrics.h"
16 #include "winbase.h"
17 #include "winuser.h"
18 #include "debugtools.h"
19 #include "tweak.h"
20 #include "winreg.h"
22 DEFAULT_DEBUG_CHANNEL(syscolor)
24 static const char * const DefSysColors[] =
26 "Scrollbar", "224 224 224", /* COLOR_SCROLLBAR */
27 "Background", "192 192 192", /* COLOR_BACKGROUND */
28 "ActiveTitle", "0 64 128", /* COLOR_ACTIVECAPTION */
29 "InactiveTitle", "255 255 255", /* COLOR_INACTIVECAPTION */
30 "Menu", "255 255 255", /* COLOR_MENU */
31 "Window", "255 255 255", /* COLOR_WINDOW */
32 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
33 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
34 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
35 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
36 "ActiveBorder", "128 128 128", /* COLOR_ACTIVEBORDER */
37 "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER */
38 "AppWorkspace", "255 255 232", /* COLOR_APPWORKSPACE */
39 "Hilight", "224 224 224", /* COLOR_HIGHLIGHT */
40 "HilightText", "0 0 0", /* COLOR_HIGHLIGHTTEXT */
41 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
42 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
43 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
44 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
45 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
46 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
47 "3DDarkShadow", "32 32 32", /* COLOR_3DDKSHADOW */
48 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
49 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
50 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
51 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
52 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
53 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
54 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
57 static const char * const DefSysColors95[] =
59 "Scrollbar", "223 223 223", /* COLOR_SCROLLBAR */
60 "Background", "192 192 192", /* COLOR_BACKGROUND */
61 "ActiveTitle", "0 0 128", /* COLOR_ACTIVECAPTION */
62 "InactiveTitle", "128 128 128", /* COLOR_INACTIVECAPTION */
63 "Menu", "192 192 192", /* COLOR_MENU */
64 "Window", "255 255 255", /* COLOR_WINDOW */
65 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
66 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
67 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
68 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
69 "ActiveBorder", "192 192 192", /* COLOR_ACTIVEBORDER */
70 "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER */
71 "AppWorkspace", "128 128 128", /* COLOR_APPWORKSPACE */
72 "Hilight", "0 0 128", /* COLOR_HIGHLIGHT */
73 "HilightText", "255 255 255", /* COLOR_HIGHLIGHTTEXT */
74 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
75 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
76 "GrayText", "128 128 128", /* COLOR_GRAYTEXT */
77 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
78 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
79 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
80 "3DDarkShadow", "0 0 0", /* COLOR_3DDKSHADOW */
81 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
82 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
83 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
84 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
85 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
86 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
87 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
91 #define NUM_SYS_COLORS (COLOR_GRADIENTINACTIVECAPTION+1)
93 static COLORREF SysColors[NUM_SYS_COLORS];
94 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
95 static HPEN SysColorPens[NUM_SYS_COLORS];
97 #define MAKE_SOLID(color) \
98 (PALETTEINDEX(GetNearestPaletteIndex(STOCK_DEFAULT_PALETTE,(color))))
100 /*************************************************************************
101 * SYSCOLOR_SetColor
103 static void SYSCOLOR_SetColor( int index, COLORREF color )
105 if (index < 0 || index >= NUM_SYS_COLORS) return;
106 SysColors[index] = color;
107 if (SysColorBrushes[index]) DeleteObject( SysColorBrushes[index] );
108 SysColorBrushes[index] = CreateSolidBrush( color );
109 if (SysColorPens[index]) DeleteObject( SysColorPens[index] );
110 SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
114 /*************************************************************************
115 * SYSCOLOR_Init
117 void SYSCOLOR_Init(void)
119 int i, r, g, b;
120 const char * const *p;
121 char buffer[100];
122 BOOL bOk = FALSE, bNoReg = FALSE;
123 HKEY hKey;
125 p = (TWEAK_WineLook == WIN31_LOOK) ? DefSysColors : DefSysColors95;
127 /* first, try to read the values from the registry */
128 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
129 bNoReg = TRUE;
130 for (i = 0; i < NUM_SYS_COLORS; i++)
131 { bOk = FALSE;
133 /* first try, registry */
134 if (!bNoReg)
136 DWORD dwDataSize = sizeof(buffer);
137 if (!(RegQueryValueExA(hKey,(LPSTR)p[i*2], 0, 0, buffer, &dwDataSize)))
138 if (sscanf( buffer, "%d %d %d", &r, &g, &b ) == 3)
139 bOk = TRUE;
142 /* second try, win.ini */
143 if (!bOk)
144 { GetProfileStringA( "colors", p[i*2], p[i*2+1], buffer, 100 );
145 if (sscanf( buffer, " %d %d %d", &r, &g, &b ) == 3)
146 bOk = TRUE;
149 /* last chance, take the default */
150 if (!bOk)
151 { int iNumColors = sscanf( p[i*2+1], " %d %d %d", &r, &g, &b );
152 assert (iNumColors==3);
155 SYSCOLOR_SetColor( i, RGB(r,g,b) );
157 if (!bNoReg)
158 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("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];