2 * Support for system colors
4 * Copyright David W. Metcalfe, 1993
5 * Copyright Alexandre Julliard, 1994
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
17 #include "sysmetrics.h"
20 #include "debugtools.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
];
101 #define MAKE_SOLID(color) \
102 (PALETTEINDEX(GetNearestPaletteIndex(STOCK_DEFAULT_PALETTE,(color))))
105 /*************************************************************************
106 * SYSCOLOR_MakeObjectSystem
108 * OK, now for a very ugly hack.
109 * USER somehow has to tell GDI that its system brushes and pens are
111 * We don't want to export a function from GDI doing this for us,
112 * so we just do that ourselves by "wildly flipping some bits in memory".
113 * For a description of the GDI object magics and their flags,
114 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
116 static void SYSCOLOR_MakeObjectSystem( HGDIOBJ handle
, BOOL set
)
118 static WORD GDI_heap_sel
= 0;
123 GDI_heap_sel
= LoadLibrary16("gdi");
124 FreeLibrary16(GDI_heap_sel
);
127 ptr
= (LPWORD
)LOCAL_Lock(GDI_heap_sel
, handle
);
129 /* touch the "system" bit of the wMagic field of a GDIOBJHDR */
131 *(ptr
+1) &= ~OBJECT_NOSYSTEM
;
133 *(ptr
+1) |= OBJECT_NOSYSTEM
;
134 LOCAL_Unlock( GDI_heap_sel
, handle
);
137 /*************************************************************************
140 static void SYSCOLOR_SetColor( int index
, COLORREF color
)
142 if (index
< 0 || index
>= NUM_SYS_COLORS
) return;
143 SysColors
[index
] = color
;
144 if (SysColorBrushes
[index
])
146 SYSCOLOR_MakeObjectSystem(SysColorBrushes
[index
], FALSE
);
147 DeleteObject( SysColorBrushes
[index
] );
149 SysColorBrushes
[index
] = CreateSolidBrush( color
);
150 SYSCOLOR_MakeObjectSystem(SysColorBrushes
[index
], TRUE
);
152 if (SysColorPens
[index
])
154 SYSCOLOR_MakeObjectSystem(SysColorBrushes
[index
], FALSE
);
155 DeleteObject( SysColorPens
[index
] );
157 SysColorPens
[index
] = CreatePen( PS_SOLID
, 1, color
);
158 SYSCOLOR_MakeObjectSystem(SysColorBrushes
[index
], TRUE
);
162 /*************************************************************************
165 void SYSCOLOR_Init(void)
168 const char * const *p
;
170 BOOL bOk
= FALSE
, bNoReg
= FALSE
;
173 p
= (TWEAK_WineLook
== WIN31_LOOK
) ? DefSysColors
: DefSysColors95
;
175 /* first, try to read the values from the registry */
176 if (RegCreateKeyExA(HKEY_CURRENT_USER
, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0))
178 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
181 /* first try, registry */
184 DWORD dwDataSize
= sizeof(buffer
);
185 if (!(RegQueryValueExA(hKey
,(LPSTR
)p
[i
*2], 0, 0, buffer
, &dwDataSize
)))
186 if (sscanf( buffer
, "%d %d %d", &r
, &g
, &b
) == 3)
190 /* second try, win.ini */
192 { GetProfileStringA( "colors", p
[i
*2], p
[i
*2+1], buffer
, 100 );
193 if (sscanf( buffer
, " %d %d %d", &r
, &g
, &b
) == 3)
197 /* last chance, take the default */
199 { int iNumColors
= sscanf( p
[i
*2+1], " %d %d %d", &r
, &g
, &b
);
200 assert (iNumColors
==3);
203 SYSCOLOR_SetColor( i
, RGB(r
,g
,b
) );
210 /*************************************************************************
211 * GetSysColor16 (USER.180)
213 COLORREF WINAPI
GetSysColor16( INT16 nIndex
)
215 return GetSysColor (nIndex
);
219 /*************************************************************************
220 * GetSysColor (USER32.289)
222 COLORREF WINAPI
GetSysColor( INT nIndex
)
224 if (nIndex
>= 0 && nIndex
< NUM_SYS_COLORS
)
225 return SysColors
[nIndex
];
231 /*************************************************************************
232 * SetSysColors16 (USER.181)
234 VOID WINAPI
SetSysColors16( INT16 nChanges
, const INT16
*lpSysColor
,
235 const COLORREF
*lpColorValues
)
239 for (i
= 0; i
< nChanges
; i
++)
241 SYSCOLOR_SetColor( lpSysColor
[i
], lpColorValues
[i
] );
244 /* Send WM_SYSCOLORCHANGE message to all windows */
246 SendMessageA( HWND_BROADCAST
, WM_SYSCOLORCHANGE
, 0, 0 );
248 /* Repaint affected portions of all visible windows */
250 RedrawWindow( GetDesktopWindow(), NULL
, 0,
251 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
255 /*************************************************************************
256 * SetSysColors (USER32.505)
258 BOOL WINAPI
SetSysColors( INT nChanges
, const INT
*lpSysColor
,
259 const COLORREF
*lpColorValues
)
263 for (i
= 0; i
< nChanges
; i
++)
265 SYSCOLOR_SetColor( lpSysColor
[i
], lpColorValues
[i
] );
268 /* Send WM_SYSCOLORCHANGE message to all windows */
270 SendMessageA( HWND_BROADCAST
, WM_SYSCOLORCHANGE
, 0, 0 );
272 /* Repaint affected portions of all visible windows */
274 RedrawWindow( GetDesktopWindow(), NULL
, 0,
275 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
280 /***********************************************************************
281 * GetSysColorBrush16 (USER.281)
283 HBRUSH16 WINAPI
GetSysColorBrush16( INT16 index
)
285 return (HBRUSH16
)GetSysColorBrush(index
);
289 /***********************************************************************
290 * GetSysColorBrush (USER32.290)
292 HBRUSH WINAPI
GetSysColorBrush( INT index
)
294 if (0 <= index
&& index
< NUM_SYS_COLORS
)
295 return SysColorBrushes
[index
];
296 WARN("Unknown index(%d)\n", index
);
297 return GetStockObject(LTGRAY_BRUSH
);
301 /***********************************************************************
302 * GetSysColorPen16 (Not a Windows API)
304 HPEN16 WINAPI
GetSysColorPen16( INT16 index
)
306 return (HPEN16
)GetSysColorPen(index
);
310 /***********************************************************************
311 * GetSysColorPen (Not a Windows API)
313 * This function is new to the Wine lib -- it does not exist in
314 * Windows. However, it is a natural complement for GetSysColorBrush
315 * in the Win32 API and is needed quite a bit inside Wine.
317 HPEN WINAPI
GetSysColorPen( INT index
)
319 /* We can assert here, because this function is internal to Wine */
320 assert (0 <= index
&& index
< NUM_SYS_COLORS
);
321 return SysColorPens
[index
];