2 * Support for system colors
4 * Copyright David W. Metcalfe, 1993
5 * Copyright Alexandre Julliard, 1994
13 #include "wine/winbase16.h"
14 #include "wine/winuser16.h"
15 #include "sysmetrics.h"
18 #include "debugtools.h"
21 #include "winversion.h"
23 DEFAULT_DEBUG_CHANNEL(syscolor
)
25 static const char * const DefSysColors
[] =
27 "Scrollbar", "224 224 224", /* COLOR_SCROLLBAR */
28 "Background", "192 192 192", /* COLOR_BACKGROUND */
29 "ActiveTitle", "0 64 128", /* COLOR_ACTIVECAPTION */
30 "InactiveTitle", "255 255 255", /* COLOR_INACTIVECAPTION */
31 "Menu", "255 255 255", /* COLOR_MENU */
32 "Window", "255 255 255", /* COLOR_WINDOW */
33 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
34 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
35 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
36 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
37 "ActiveBorder", "128 128 128", /* COLOR_ACTIVEBORDER */
38 "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER */
39 "AppWorkspace", "255 255 232", /* COLOR_APPWORKSPACE */
40 "Hilight", "224 224 224", /* COLOR_HIGHLIGHT */
41 "HilightText", "0 0 0", /* COLOR_HIGHLIGHTTEXT */
42 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
43 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
44 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
45 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
46 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
47 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
48 "3DDarkShadow", "32 32 32", /* COLOR_3DDKSHADOW */
49 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
50 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
51 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
52 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
53 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
54 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
55 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
58 static const char * const DefSysColors95
[] =
60 "Scrollbar", "223 223 223", /* COLOR_SCROLLBAR */
61 "Background", "192 192 192", /* COLOR_BACKGROUND */
62 "ActiveTitle", "0 0 128", /* COLOR_ACTIVECAPTION */
63 "InactiveTitle", "128 128 128", /* COLOR_INACTIVECAPTION */
64 "Menu", "192 192 192", /* COLOR_MENU */
65 "Window", "255 255 255", /* COLOR_WINDOW */
66 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
67 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
68 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
69 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
70 "ActiveBorder", "192 192 192", /* COLOR_ACTIVEBORDER */
71 "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER */
72 "AppWorkspace", "128 128 128", /* COLOR_APPWORKSPACE */
73 "Hilight", "0 0 128", /* COLOR_HIGHLIGHT */
74 "HilightText", "255 255 255", /* COLOR_HIGHLIGHTTEXT */
75 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
76 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
77 "GrayText", "128 128 128", /* COLOR_GRAYTEXT */
78 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
79 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
80 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
81 "3DDarkShadow", "0 0 0", /* COLOR_3DDKSHADOW */
82 "3DLight", "223 223 223", /* COLOR_3DLIGHT */
83 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
84 "InfoBackground", "255 255 192", /* COLOR_INFOBK */
85 "AlternateButtonFace", "184 180 184", /* COLOR_ALTERNATEBTNFACE */
86 "HotTrackingColor", "0 0 255", /* COLOR_HOTLIGHT */
87 "GradientActiveTitle", "16 132 208", /* COLOR_GRADIENTACTIVECAPTION */
88 "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
92 #define NUM_SYS_COLORS (COLOR_GRADIENTINACTIVECAPTION+1)
94 static COLORREF SysColors
[NUM_SYS_COLORS
];
95 static HBRUSH SysColorBrushes
[NUM_SYS_COLORS
];
96 static HPEN SysColorPens
[NUM_SYS_COLORS
];
98 #define MAKE_SOLID(color) \
99 (PALETTEINDEX(GetNearestPaletteIndex(STOCK_DEFAULT_PALETTE,(color))))
101 /*************************************************************************
104 static void SYSCOLOR_SetColor( int index
, COLORREF color
)
106 if (index
< 0 || index
>= NUM_SYS_COLORS
) return;
107 SysColors
[index
] = color
;
108 if (SysColorBrushes
[index
]) DeleteObject( SysColorBrushes
[index
] );
109 SysColorBrushes
[index
] = CreateSolidBrush( color
);
110 if (SysColorPens
[index
]) DeleteObject( SysColorPens
[index
] );
111 SysColorPens
[index
] = CreatePen( PS_SOLID
, 1, color
);
115 /*************************************************************************
118 void SYSCOLOR_Init(void)
121 const char * const *p
;
123 BOOL bOk
= FALSE
, bNoReg
= FALSE
;
126 p
= (TWEAK_WineLook
== WIN31_LOOK
) ? DefSysColors
: DefSysColors95
;
128 /* first, try to read the values from the registry */
129 if (VERSION_GetVersion() != WIN31
)
131 if (RegCreateKeyExA(HKEY_CURRENT_USER
, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0))
135 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
138 /* first try, registry */
141 DWORD dwDataSize
= sizeof(buffer
);
142 if (!(RegQueryValueExA(hKey
,(LPSTR
)p
[i
*2], 0, 0, buffer
, &dwDataSize
)))
143 if (sscanf( buffer
, "%d %d %d", &r
, &g
, &b
) == 3)
147 /* second try, win.ini */
149 { GetProfileStringA( "colors", p
[i
*2], p
[i
*2+1], buffer
, 100 );
150 if (sscanf( buffer
, " %d %d %d", &r
, &g
, &b
) == 3)
154 /* last chance, take the default */
156 { int iNumColors
= sscanf( p
[i
*2+1], " %d %d %d", &r
, &g
, &b
);
157 assert (iNumColors
==3);
160 SYSCOLOR_SetColor( i
, RGB(r
,g
,b
) );
168 /*************************************************************************
169 * GetSysColor16 (USER.180)
171 COLORREF WINAPI
GetSysColor16( INT16 nIndex
)
173 return GetSysColor (nIndex
);
177 /*************************************************************************
178 * GetSysColor32 (USER32.289)
180 COLORREF WINAPI
GetSysColor( INT nIndex
)
182 if (nIndex
>= 0 && nIndex
< NUM_SYS_COLORS
)
183 return SysColors
[nIndex
];
189 /*************************************************************************
190 * SetSysColors16 (USER.181)
192 VOID WINAPI
SetSysColors16( INT16 nChanges
, const INT16
*lpSysColor
,
193 const COLORREF
*lpColorValues
)
197 for (i
= 0; i
< nChanges
; i
++)
199 SYSCOLOR_SetColor( lpSysColor
[i
], lpColorValues
[i
] );
202 /* Send WM_SYSCOLORCHANGE message to all windows */
204 SendMessageA( HWND_BROADCAST
, WM_SYSCOLORCHANGE
, 0, 0 );
206 /* Repaint affected portions of all visible windows */
208 RedrawWindow( GetDesktopWindow(), NULL
, 0,
209 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
213 /*************************************************************************
214 * SetSysColors32 (USER32.505)
216 BOOL WINAPI
SetSysColors( INT nChanges
, const INT
*lpSysColor
,
217 const COLORREF
*lpColorValues
)
221 for (i
= 0; i
< nChanges
; i
++)
223 SYSCOLOR_SetColor( lpSysColor
[i
], lpColorValues
[i
] );
226 /* Send WM_SYSCOLORCHANGE message to all windows */
228 SendMessageA( HWND_BROADCAST
, WM_SYSCOLORCHANGE
, 0, 0 );
230 /* Repaint affected portions of all visible windows */
232 RedrawWindow( GetDesktopWindow(), NULL
, 0,
233 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
238 /***********************************************************************
239 * GetSysColorBrush16 (USER.281)
241 HBRUSH16 WINAPI
GetSysColorBrush16( INT16 index
)
243 return (HBRUSH16
)GetSysColorBrush(index
);
247 /***********************************************************************
248 * GetSysColorBrush32 (USER32.290)
250 HBRUSH WINAPI
GetSysColorBrush( INT index
)
252 if (0 <= index
&& index
< NUM_SYS_COLORS
)
253 return SysColorBrushes
[index
];
254 WARN("Unknown index(%d)\n", index
);
255 return GetStockObject(LTGRAY_BRUSH
);
259 /***********************************************************************
260 * GetSysColorPen16 (Not a Windows API)
262 HPEN16 WINAPI
GetSysColorPen16( INT16 index
)
264 return (HPEN16
)GetSysColorPen(index
);
268 /***********************************************************************
269 * GetSysColorPen32 (Not a Windows API)
271 * This function is new to the Wine lib -- it does not exist in
272 * Windows. However, it is a natural complement for GetSysColorBrush
273 * in the Win32 API and is needed quite a bit inside Wine.
275 HPEN WINAPI
GetSysColorPen( INT index
)
277 /* We can assert here, because this function is internal to Wine */
278 assert (0 <= index
&& index
< NUM_SYS_COLORS
);
279 return SysColorPens
[index
];