Release 970914
[wine] / windows / syscolor.c
1 /*
2  * Support for system colors
3  *
4  * Copyright  David W. Metcalfe, 1993
5  * Copyright  Alexandre Julliard, 1994
6  *
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "gdi.h"
12 #include "syscolor.h"
13 #include "stddebug.h"
14 #include "tweak.h"
15 /* #define DEBUG_SYSCOLOR */
16 #include "debug.h"
17
18 struct SysColorObjects sysColorObjects;
19
20 static const char * const DefSysColors[] =
21 {
22     "Scrollbar", "224 224 224",      /* COLOR_SCROLLBAR           */
23     "Background", "192 192 192",     /* COLOR_BACKGROUND          */
24     "ActiveTitle", "0 64 128",       /* COLOR_ACTIVECAPTION       */
25     "InactiveTitle", "255 255 255",  /* COLOR_INACTIVECAPTION     */
26     "Menu", "255 255 255",             /* COLOR_MENU                */
27     "Window", "255 255 255",         /* COLOR_WINDOW              */
28     "WindowFrame", "0 0 0",          /* COLOR_WINDOWFRAME         */
29     "MenuText", "0 0 0",             /* COLOR_MENUTEXT            */
30     "WindowText", "0 0 0",           /* COLOR_WINDOWTEXT          */
31     "TitleText", "255 255 255",      /* COLOR_CAPTIONTEXT         */
32     "ActiveBorder", "128 128 128",   /* COLOR_ACTIVEBORDER        */
33     "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER      */
34     "AppWorkspace", "255 255 232",   /* COLOR_APPWORKSPACE        */
35     "Hilight", "166 202 240",        /* COLOR_HIGHLIGHT           */
36     "HilightText", "0 0 0",          /* COLOR_HIGHLIGHTTEXT       */
37     "ButtonFace", "192 192 192",     /* COLOR_BTNFACE             */
38     "ButtonShadow", "128 128 128",   /* COLOR_BTNSHADOW           */
39     "GrayText", "192 192 192",       /* COLOR_GRAYTEXT            */
40     "ButtonText", "0 0 0",           /* COLOR_BTNTEXT             */
41     "InactiveTitleText", "0 0 0",    /* COLOR_INACTIVECAPTIONTEXT */
42     "ButtonHilight", "255 255 255",  /* COLOR_BTNHIGHLIGHT        */
43     "3DDarkShadow", "32 32 32",      /* COLOR_3DDKSHADOW          */
44     "3DLight", "192 192 192",        /* COLOR_3DLIGHT             */
45     "InfoText", "0 0 0",             /* COLOR_INFOTEXT            */
46     "InfoBackground", "255 255 192"  /* COLOR_INFOBK              */
47 };
48
49 static const char * const DefSysColors95[] =
50 {
51     "Scrollbar", "224 224 224",      /* COLOR_SCROLLBAR           */
52     "Background", "192 192 192",     /* COLOR_BACKGROUND          */
53     "ActiveTitle", "0 64 128",       /* COLOR_ACTIVECAPTION       */
54     "InactiveTitle", "255 255 255",  /* COLOR_INACTIVECAPTION     */
55     "Menu", "192 192 192",           /* COLOR_MENU                */
56     "Window", "255 255 255",         /* COLOR_WINDOW              */
57     "WindowFrame", "0 0 0",          /* COLOR_WINDOWFRAME         */
58     "MenuText", "0 0 0",             /* COLOR_MENUTEXT            */
59     "WindowText", "0 0 0",           /* COLOR_WINDOWTEXT          */
60     "TitleText", "255 255 255",      /* COLOR_CAPTIONTEXT         */
61     "ActiveBorder", "128 128 128",   /* COLOR_ACTIVEBORDER        */
62     "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER      */
63     "AppWorkspace", "255 255 232",   /* COLOR_APPWORKSPACE        */
64     "Hilight", "166 202 240",        /* COLOR_HIGHLIGHT           */
65     "HilightText", "0 0 0",          /* COLOR_HIGHLIGHTTEXT       */
66     "ButtonFace", "192 192 192",     /* COLOR_BTNFACE             */
67     "ButtonShadow", "128 128 128",   /* COLOR_BTNSHADOW           */
68     "GrayText", "192 192 192",       /* COLOR_GRAYTEXT            */
69     "ButtonText", "0 0 0",           /* COLOR_BTNTEXT             */
70     "InactiveTitleText", "0 0 0",    /* COLOR_INACTIVECAPTIONTEXT */
71     "ButtonHilight", "255 255 255",  /* COLOR_BTNHIGHLIGHT        */
72     "3DDarkShadow", "32 32 32",      /* COLOR_3DDKSHADOW          */
73     "3DLight", "192 192 192",        /* COLOR_3DLIGHT             */
74     "InfoText", "0 0 0",             /* COLOR_INFOTEXT            */
75     "InfoBackground", "255 255 192"  /* COLOR_INFOBK              */
76 };
77
78
79 #define NUM_SYS_COLORS     (COLOR_INFOBK+1)
80
81 static COLORREF SysColors[NUM_SYS_COLORS];
82
83 #define MAKE_SOLID(color) \
84        (PALETTEINDEX(GetNearestPaletteIndex32(STOCK_DEFAULT_PALETTE,(color))))
85
86 /*************************************************************************
87  *             SYSCOLOR_SetColor
88  */
89 static void SYSCOLOR_SetColor( int index, COLORREF color )
90 {
91     if (index < 0 || index >= NUM_SYS_COLORS) return;
92     SysColors[index] = color;
93     switch(index)
94     {
95     case COLOR_SCROLLBAR:
96         DeleteObject32( sysColorObjects.hbrushScrollbar );
97         sysColorObjects.hbrushScrollbar = CreateSolidBrush32( color );
98         break;
99     case COLOR_BACKGROUND:
100         break;
101     case COLOR_ACTIVECAPTION:
102         DeleteObject32( sysColorObjects.hbrushActiveCaption );
103         sysColorObjects.hbrushActiveCaption = CreateSolidBrush32( color );
104         break;
105     case COLOR_INACTIVECAPTION:
106         DeleteObject32( sysColorObjects.hbrushInactiveCaption );
107         sysColorObjects.hbrushInactiveCaption = CreateSolidBrush32( color );
108         break;
109     case COLOR_MENU:
110         DeleteObject32( sysColorObjects.hbrushMenu );
111         sysColorObjects.hbrushMenu = CreateSolidBrush32( MAKE_SOLID(color) );
112         break;
113     case COLOR_WINDOW:
114         DeleteObject32( sysColorObjects.hbrushWindow );
115         sysColorObjects.hbrushWindow = CreateSolidBrush32( color );
116         break;
117     case COLOR_WINDOWFRAME:
118         DeleteObject32( sysColorObjects.hpenWindowFrame );
119         sysColorObjects.hpenWindowFrame = CreatePen32( PS_SOLID, 1, color );
120         break;
121     case COLOR_MENUTEXT:
122         break;
123     case COLOR_WINDOWTEXT:
124         DeleteObject32( sysColorObjects.hpenWindowText );
125         sysColorObjects.hpenWindowText = CreatePen32( PS_DOT, 1, color );
126         break;
127     case COLOR_CAPTIONTEXT:
128         break;
129     case COLOR_ACTIVEBORDER:
130         DeleteObject32( sysColorObjects.hbrushActiveBorder );
131         sysColorObjects.hbrushActiveBorder = CreateSolidBrush32( color );
132         break;
133     case COLOR_INACTIVEBORDER:
134         DeleteObject32( sysColorObjects.hbrushInactiveBorder );
135         sysColorObjects.hbrushInactiveBorder = CreateSolidBrush32( color );
136         break;
137     case COLOR_APPWORKSPACE:
138         break;
139     case COLOR_HIGHLIGHT:
140         DeleteObject32( sysColorObjects.hbrushHighlight );
141         sysColorObjects.hbrushHighlight = CreateSolidBrush32(MAKE_SOLID(color));
142         break;
143     case COLOR_HIGHLIGHTTEXT:
144         break;
145     case COLOR_BTNFACE:
146         DeleteObject32( sysColorObjects.hbrushBtnFace );
147         sysColorObjects.hbrushBtnFace = CreateSolidBrush32( color );
148         break;
149     case COLOR_BTNSHADOW:
150         DeleteObject32( sysColorObjects.hbrushBtnShadow );
151         sysColorObjects.hbrushBtnShadow = CreateSolidBrush32( color );
152         break;
153     case COLOR_GRAYTEXT:
154     case COLOR_BTNTEXT:
155     case COLOR_INACTIVECAPTIONTEXT:
156         break;
157     case COLOR_BTNHIGHLIGHT:
158         DeleteObject32( sysColorObjects.hbrushBtnHighlight );
159         sysColorObjects.hbrushBtnHighlight = CreateSolidBrush32( color );
160         break;
161     case COLOR_3DDKSHADOW:
162     case COLOR_3DLIGHT:
163     case COLOR_INFOTEXT:
164     case COLOR_INFOBK:
165         break;
166     }
167 }
168
169
170 /*************************************************************************
171  *             SYSCOLOR_Init
172  */
173 void SYSCOLOR_Init(void)
174 {
175     int i, r, g, b;
176     const char * const *p;
177     char buffer[100];
178
179     for (i = 0, p = TWEAK_Win95Look ? DefSysColors95 : DefSysColors;
180          i < NUM_SYS_COLORS; i++, p += 2)
181     {
182         GetProfileString32A( "colors", p[0], p[1], buffer, 100 );
183         if (sscanf( buffer, " %d %d %d", &r, &g, &b ) != 3) r = g = b = 0;
184         SYSCOLOR_SetColor( i, RGB(r,g,b) );
185     }
186 }
187
188
189 /*************************************************************************
190  *             GetSysColor16   (USER.180)
191  */
192 COLORREF WINAPI GetSysColor16( INT16 nIndex )
193 {
194     return GetSysColor32 (nIndex);
195 }
196
197
198 /*************************************************************************
199  *             GetSysColor32   (USER32.288)
200  */
201 COLORREF WINAPI GetSysColor32( INT32 nIndex )
202 {
203     if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
204         return SysColors[nIndex];
205     else
206         return 0;
207 }
208
209
210 /*************************************************************************
211  *             SetSysColors16   (USER.181)
212  */
213 /* FIXME -- check return type and insert comment if correct.  */
214 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
215                             const COLORREF *lpColorValues )
216 {
217     int i;
218
219     for (i = 0; i < nChanges; i++)
220     {
221         SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
222     }
223
224     /* Send WM_SYSCOLORCHANGE message to all windows */
225
226     SendMessage32A( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
227
228     /* Repaint affected portions of all visible windows */
229
230     RedrawWindow32( GetDesktopWindow32(), NULL, 0,
231                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
232 }
233
234
235 /*************************************************************************
236  *             SetSysColors32   (USER32.504)
237  */
238 BOOL32 WINAPI SetSysColors32( INT32 nChanges, const INT32 *lpSysColor,
239                               const COLORREF *lpColorValues )
240 {
241     int i;
242
243     for (i = 0; i < nChanges; i++)
244     {
245         SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
246     }
247
248     /* Send WM_SYSCOLORCHANGE message to all windows */
249
250     SendMessage32A( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
251
252     /* Repaint affected portions of all visible windows */
253
254     RedrawWindow32( GetDesktopWindow32(), NULL, 0,
255                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
256     return TRUE;
257 }