Release 980628
[wine/multimedia.git] / windows / syscolor.c
blobfe48431378ccf9b21a82aa9cf04a88092318c44b
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>
12 #include "debug.h"
13 #include "gdi.h"
14 #include "tweak.h"
16 static const char * const DefSysColors[] =
18 "Scrollbar", "224 224 224", /* COLOR_SCROLLBAR */
19 "Background", "192 192 192", /* COLOR_BACKGROUND */
20 "ActiveTitle", "0 64 128", /* COLOR_ACTIVECAPTION */
21 "InactiveTitle", "255 255 255", /* COLOR_INACTIVECAPTION */
22 "Menu", "255 255 255", /* COLOR_MENU */
23 "Window", "255 255 255", /* COLOR_WINDOW */
24 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
25 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
26 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
27 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
28 "ActiveBorder", "128 128 128", /* COLOR_ACTIVEBORDER */
29 "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER */
30 "AppWorkspace", "255 255 232", /* COLOR_APPWORKSPACE */
31 "Hilight", "224 224 224", /* COLOR_HIGHLIGHT */
32 "HilightText", "0 0 0", /* COLOR_HIGHLIGHTTEXT */
33 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
34 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
35 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
36 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
37 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
38 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
39 "3DDarkShadow", "32 32 32", /* COLOR_3DDKSHADOW */
40 "3DLight", "192 192 192", /* COLOR_3DLIGHT */
41 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
42 "InfoBackground", "255 255 192" /* COLOR_INFOBK */
45 static const char * const DefSysColors95[] =
47 "Scrollbar", "223 223 223", /* COLOR_SCROLLBAR */
48 "Background", "192 192 192", /* COLOR_BACKGROUND */
49 "ActiveTitle", "0 64 128", /* COLOR_ACTIVECAPTION */
50 "InactiveTitle", "255 255 255", /* COLOR_INACTIVECAPTION */
51 "Menu", "192 192 192", /* COLOR_MENU */
52 "Window", "255 255 255", /* COLOR_WINDOW */
53 "WindowFrame", "0 0 0", /* COLOR_WINDOWFRAME */
54 "MenuText", "0 0 0", /* COLOR_MENUTEXT */
55 "WindowText", "0 0 0", /* COLOR_WINDOWTEXT */
56 "TitleText", "255 255 255", /* COLOR_CAPTIONTEXT */
57 "ActiveBorder", "128 128 128", /* COLOR_ACTIVEBORDER */
58 "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER */
59 "AppWorkspace", "128 128 128", /* COLOR_APPWORKSPACE */
60 "Hilight", "223 223 223", /* COLOR_HIGHLIGHT */
61 "HilightText", "0 0 0", /* COLOR_HIGHLIGHTTEXT */
62 "ButtonFace", "192 192 192", /* COLOR_BTNFACE */
63 "ButtonShadow", "128 128 128", /* COLOR_BTNSHADOW */
64 "GrayText", "192 192 192", /* COLOR_GRAYTEXT */
65 "ButtonText", "0 0 0", /* COLOR_BTNTEXT */
66 "InactiveTitleText", "0 0 0", /* COLOR_INACTIVECAPTIONTEXT */
67 "ButtonHilight", "255 255 255", /* COLOR_BTNHIGHLIGHT */
68 "3DDarkShadow", "0 0 0", /* COLOR_3DDKSHADOW */
69 "3DLight", "223 223 223", /* COLOR_3DLIGHT */
70 "InfoText", "0 0 0", /* COLOR_INFOTEXT */
71 "InfoBackground", "255 255 192" /* COLOR_INFOBK */
75 #define NUM_SYS_COLORS (COLOR_INFOBK+1)
77 static COLORREF SysColors[NUM_SYS_COLORS];
78 static HBRUSH32 SysColorBrushes[NUM_SYS_COLORS];
79 static HPEN32 SysColorPens[NUM_SYS_COLORS];
81 #define MAKE_SOLID(color) \
82 (PALETTEINDEX(GetNearestPaletteIndex32(STOCK_DEFAULT_PALETTE,(color))))
84 /*************************************************************************
85 * SYSCOLOR_SetColor
87 static void SYSCOLOR_SetColor( int index, COLORREF color )
89 if (index < 0 || index >= NUM_SYS_COLORS) return;
90 SysColors[index] = color;
91 if (SysColorBrushes[index]) DeleteObject32( SysColorBrushes[index] );
92 SysColorBrushes[index] = CreateSolidBrush32( color );
93 if (SysColorPens[index]) DeleteObject32( SysColorPens[index] );
94 SysColorPens[index] = CreatePen32( PS_SOLID, 1, color );
98 /*************************************************************************
99 * SYSCOLOR_Init
101 void SYSCOLOR_Init(void)
103 int i, r, g, b;
104 const char * const *p;
105 char buffer[100];
107 for (i = 0, p = TWEAK_Win95Look ? DefSysColors95 : DefSysColors;
108 i < NUM_SYS_COLORS; i++, p += 2)
110 GetProfileString32A( "colors", p[0], p[1], buffer, 100 );
111 if (sscanf( buffer, " %d %d %d", &r, &g, &b ) != 3) r = g = b = 0;
112 SYSCOLOR_SetColor( i, RGB(r,g,b) );
117 /*************************************************************************
118 * GetSysColor16 (USER.180)
120 COLORREF WINAPI GetSysColor16( INT16 nIndex )
122 return GetSysColor32 (nIndex);
126 /*************************************************************************
127 * GetSysColor32 (USER32.289)
129 COLORREF WINAPI GetSysColor32( INT32 nIndex )
131 if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
132 return SysColors[nIndex];
133 else
134 return 0;
138 /*************************************************************************
139 * SetSysColors16 (USER.181)
141 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
142 const COLORREF *lpColorValues )
144 int i;
146 for (i = 0; i < nChanges; i++)
148 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
151 /* Send WM_SYSCOLORCHANGE message to all windows */
153 SendMessage32A( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
155 /* Repaint affected portions of all visible windows */
157 RedrawWindow32( GetDesktopWindow32(), NULL, 0,
158 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
162 /*************************************************************************
163 * SetSysColors32 (USER32.505)
165 BOOL32 WINAPI SetSysColors32( INT32 nChanges, const INT32 *lpSysColor,
166 const COLORREF *lpColorValues )
168 int i;
170 for (i = 0; i < nChanges; i++)
172 SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
175 /* Send WM_SYSCOLORCHANGE message to all windows */
177 SendMessage32A( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
179 /* Repaint affected portions of all visible windows */
181 RedrawWindow32( GetDesktopWindow32(), NULL, 0,
182 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
183 return TRUE;
187 /***********************************************************************
188 * GetSysColorBrush16 (USER.281)
190 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
192 return (HBRUSH16)GetSysColorBrush32(index);
196 /***********************************************************************
197 * GetSysColorBrush32 (USER32.290)
199 HBRUSH32 WINAPI GetSysColorBrush32( INT32 index )
201 if (0 <= index && index < NUM_SYS_COLORS)
202 return SysColorBrushes[index];
203 WARN(syscolor, "Unknown index(%d)\n", index );
204 return GetStockObject32(LTGRAY_BRUSH);
208 /***********************************************************************
209 * GetSysColorPen16 (Not a Windows API)
211 HPEN16 WINAPI GetSysColorPen16( INT16 index )
213 return (HPEN16)GetSysColorPen32(index);
217 /***********************************************************************
218 * GetSysColorPen32 (Not a Windows API)
220 * This function is new to the Wine lib -- it does not exist in
221 * Windows. However, it is a natural complement for GetSysColorBrush
222 * in the Win32 API and is needed quite a bit inside Wine.
224 HPEN32 WINAPI GetSysColorPen32( INT32 index )
226 /* We can assert here, because this function is internal to Wine */
227 assert (0 <= index && index < NUM_SYS_COLORS);
228 return SysColorPens[index];