Fixed some warnings. removed some unneccessary includes, removed one
[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 <assert.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "winbase.h"
13 #include "winuser.h"
14 #include "debug.h"
15 #include "gdi.h"
16 #include "tweak.h"
17
18 static const char * const DefSysColors[] =
19 {
20     "Scrollbar", "224 224 224",      /* COLOR_SCROLLBAR           */
21     "Background", "192 192 192",     /* COLOR_BACKGROUND          */
22     "ActiveTitle", "0 64 128",       /* COLOR_ACTIVECAPTION       */
23     "InactiveTitle", "255 255 255",  /* COLOR_INACTIVECAPTION     */
24     "Menu", "255 255 255",           /* COLOR_MENU                */
25     "Window", "255 255 255",         /* COLOR_WINDOW              */
26     "WindowFrame", "0 0 0",          /* COLOR_WINDOWFRAME         */
27     "MenuText", "0 0 0",             /* COLOR_MENUTEXT            */
28     "WindowText", "0 0 0",           /* COLOR_WINDOWTEXT          */
29     "TitleText", "255 255 255",      /* COLOR_CAPTIONTEXT         */
30     "ActiveBorder", "128 128 128",   /* COLOR_ACTIVEBORDER        */
31     "InactiveBorder", "255 255 255", /* COLOR_INACTIVEBORDER      */
32     "AppWorkspace", "255 255 232",   /* COLOR_APPWORKSPACE        */
33     "Hilight", "224 224 224",        /* COLOR_HIGHLIGHT           */
34     "HilightText", "0 0 0",          /* COLOR_HIGHLIGHTTEXT       */
35     "ButtonFace", "192 192 192",     /* COLOR_BTNFACE             */
36     "ButtonShadow", "128 128 128",   /* COLOR_BTNSHADOW           */
37     "GrayText", "192 192 192",       /* COLOR_GRAYTEXT            */
38     "ButtonText", "0 0 0",           /* COLOR_BTNTEXT             */
39     "InactiveTitleText", "0 0 0",    /* COLOR_INACTIVECAPTIONTEXT */
40     "ButtonHilight", "255 255 255",  /* COLOR_BTNHIGHLIGHT        */
41     "3DDarkShadow", "32 32 32",      /* COLOR_3DDKSHADOW          */
42     "3DLight", "192 192 192",        /* COLOR_3DLIGHT             */
43     "InfoText", "0 0 0",             /* COLOR_INFOTEXT            */
44     "InfoBackground", "255 255 192", /* COLOR_INFOBK              */
45     "AlternateButtonFace", "184 180 184",  /* COLOR_ALTERNATEBTNFACE */
46     "HotTrackingColor", "0 0 255",         /* COLOR_HOTLIGHT */
47     "GradientActiveTitle", "16 132 208",   /* COLOR_GRADIENTACTIVECAPTION */
48     "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
49 };
50
51 static const char * const DefSysColors95[] =
52 {
53     "Scrollbar", "223 223 223",      /* COLOR_SCROLLBAR           */
54     "Background", "192 192 192",     /* COLOR_BACKGROUND          */
55     "ActiveTitle", "0 0 128",        /* COLOR_ACTIVECAPTION       */
56     "InactiveTitle", "128 128 128",  /* COLOR_INACTIVECAPTION     */
57     "Menu", "192 192 192",           /* COLOR_MENU                */
58     "Window", "255 255 255",         /* COLOR_WINDOW              */
59     "WindowFrame", "0 0 0",          /* COLOR_WINDOWFRAME         */
60     "MenuText", "0 0 0",             /* COLOR_MENUTEXT            */
61     "WindowText", "0 0 0",           /* COLOR_WINDOWTEXT          */
62     "TitleText", "255 255 255",      /* COLOR_CAPTIONTEXT         */
63     "ActiveBorder", "192 192 192",   /* COLOR_ACTIVEBORDER        */
64     "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER      */
65     "AppWorkspace", "128 128 128",   /* COLOR_APPWORKSPACE        */
66     "Hilight", "0 0 128",            /* COLOR_HIGHLIGHT           */
67     "HilightText", "255 255 255",    /* COLOR_HIGHLIGHTTEXT       */
68     "ButtonFace", "192 192 192",     /* COLOR_BTNFACE             */
69     "ButtonShadow", "128 128 128",   /* COLOR_BTNSHADOW           */
70     "GrayText", "192 192 192",       /* COLOR_GRAYTEXT            */
71     "ButtonText", "0 0 0",           /* COLOR_BTNTEXT             */
72     "InactiveTitleText", "0 0 0",    /* COLOR_INACTIVECAPTIONTEXT */
73     "ButtonHilight", "255 255 255",  /* COLOR_BTNHIGHLIGHT        */
74     "3DDarkShadow", "0 0 0",         /* COLOR_3DDKSHADOW          */
75     "3DLight", "223 223 223",        /* COLOR_3DLIGHT             */
76     "InfoText", "0 0 0",             /* COLOR_INFOTEXT            */
77     "InfoBackground", "255 255 192", /* COLOR_INFOBK              */
78     "AlternateButtonFace", "184 180 184",  /* COLOR_ALTERNATEBTNFACE */
79     "HotTrackingColor", "0 0 255",         /* COLOR_HOTLIGHT */
80     "GradientActiveTitle", "16 132 208",   /* COLOR_GRADIENTACTIVECAPTION */
81     "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
82 };
83
84
85 #define NUM_SYS_COLORS     (COLOR_GRADIENTINACTIVECAPTION+1)
86
87 static COLORREF SysColors[NUM_SYS_COLORS];
88 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
89 static HPEN   SysColorPens[NUM_SYS_COLORS];
90
91 #define MAKE_SOLID(color) \
92        (PALETTEINDEX(GetNearestPaletteIndex(STOCK_DEFAULT_PALETTE,(color))))
93
94 /*************************************************************************
95  *             SYSCOLOR_SetColor
96  */
97 static void SYSCOLOR_SetColor( int index, COLORREF color )
98 {
99     if (index < 0 || index >= NUM_SYS_COLORS) return;
100     SysColors[index] = color;
101     if (SysColorBrushes[index]) DeleteObject( SysColorBrushes[index] );
102     SysColorBrushes[index] = CreateSolidBrush( color );
103     if (SysColorPens[index]) DeleteObject( SysColorPens[index] ); 
104     SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
105 }
106
107
108 /*************************************************************************
109  *             SYSCOLOR_Init
110  */
111 void SYSCOLOR_Init(void)
112 {
113     int i, r, g, b;
114     const char * const *p;
115     char buffer[100];
116
117     p = (TWEAK_WineLook == WIN31_LOOK) ? DefSysColors : DefSysColors95;
118     for (i = 0; i < NUM_SYS_COLORS; i++, p += 2)
119     {
120         GetProfileStringA( "colors", p[0], p[1], buffer, 100 );
121         if (sscanf( buffer, " %d %d %d", &r, &g, &b ) != 3) r = g = b = 0;
122         SYSCOLOR_SetColor( i, RGB(r,g,b) );
123     }
124 }
125
126
127 /*************************************************************************
128  *             GetSysColor16   (USER.180)
129  */
130 COLORREF WINAPI GetSysColor16( INT16 nIndex )
131 {
132     return GetSysColor (nIndex);
133 }
134
135
136 /*************************************************************************
137  *             GetSysColor32   (USER32.289)
138  */
139 COLORREF WINAPI GetSysColor( INT nIndex )
140 {
141     if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
142         return SysColors[nIndex];
143     else
144         return 0;
145 }
146
147
148 /*************************************************************************
149  *             SetSysColors16   (USER.181)
150  */
151 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
152                             const COLORREF *lpColorValues )
153 {
154     int i;
155
156     for (i = 0; i < nChanges; i++)
157     {
158         SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
159     }
160
161     /* Send WM_SYSCOLORCHANGE message to all windows */
162
163     SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
164
165     /* Repaint affected portions of all visible windows */
166
167     RedrawWindow( GetDesktopWindow(), NULL, 0,
168                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
169 }
170
171
172 /*************************************************************************
173  *             SetSysColors32   (USER32.505)
174  */
175 BOOL WINAPI SetSysColors( INT nChanges, const INT *lpSysColor,
176                               const COLORREF *lpColorValues )
177 {
178     int i;
179
180     for (i = 0; i < nChanges; i++)
181     {
182         SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
183     }
184
185     /* Send WM_SYSCOLORCHANGE message to all windows */
186
187     SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
188
189     /* Repaint affected portions of all visible windows */
190
191     RedrawWindow( GetDesktopWindow(), NULL, 0,
192                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
193     return TRUE;
194 }
195
196
197 /***********************************************************************
198  *           GetSysColorBrush16    (USER.281)
199  */
200 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
201 {
202     return (HBRUSH16)GetSysColorBrush(index);
203 }
204
205
206 /***********************************************************************
207  *           GetSysColorBrush32    (USER32.290)
208  */
209 HBRUSH WINAPI GetSysColorBrush( INT index )
210 {
211     if (0 <= index && index < NUM_SYS_COLORS)
212         return SysColorBrushes[index];
213     WARN(syscolor, "Unknown index(%d)\n", index );
214     return GetStockObject(LTGRAY_BRUSH);
215 }
216
217
218 /***********************************************************************
219  *           GetSysColorPen16    (Not a Windows API)
220  */
221 HPEN16 WINAPI GetSysColorPen16( INT16 index )
222 {
223     return (HPEN16)GetSysColorPen(index);
224 }
225
226
227 /***********************************************************************
228  *           GetSysColorPen32    (Not a Windows API)
229  *
230  * This function is new to the Wine lib -- it does not exist in 
231  * Windows. However, it is a natural complement for GetSysColorBrush
232  * in the Win32 API and is needed quite a bit inside Wine.
233  */
234 HPEN WINAPI GetSysColorPen( INT index )
235 {
236     /* We can assert here, because this function is internal to Wine */
237     assert (0 <= index && index < NUM_SYS_COLORS);
238     return SysColorPens[index];
239
240 }