XQueryKeymap -> TSXQueryKeymap (fixes the XIO errors reported).
[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 "debug.h"
13 #include "gdi.h"
14 #include "tweak.h"
15
16 static const char * const DefSysColors[] =
17 {
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              */
43     "AlternateButtonFace", "184 180 184",  /* COLOR_ALTERNATEBTNFACE */
44     "HotTrackingColor", "0 0 255",         /* COLOR_HOTLIGHT */
45     "GradientActiveTitle", "16 132 208",   /* COLOR_GRADIENTACTIVECAPTION */
46     "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
47 };
48
49 static const char * const DefSysColors95[] =
50 {
51     "Scrollbar", "223 223 223",      /* COLOR_SCROLLBAR           */
52     "Background", "192 192 192",     /* COLOR_BACKGROUND          */
53     "ActiveTitle", "0 0 128",        /* COLOR_ACTIVECAPTION       */
54     "InactiveTitle", "128 128 128",  /* 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", "192 192 192",   /* COLOR_ACTIVEBORDER        */
62     "InactiveBorder", "192 192 192", /* COLOR_INACTIVEBORDER      */
63     "AppWorkspace", "128 128 128",   /* COLOR_APPWORKSPACE        */
64     "Hilight", "0 0 128",            /* COLOR_HIGHLIGHT           */
65     "HilightText", "255 255 255",    /* 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", "0 0 0",         /* COLOR_3DDKSHADOW          */
73     "3DLight", "223 223 223",        /* COLOR_3DLIGHT             */
74     "InfoText", "0 0 0",             /* COLOR_INFOTEXT            */
75     "InfoBackground", "255 255 192", /* COLOR_INFOBK              */
76     "AlternateButtonFace", "184 180 184",  /* COLOR_ALTERNATEBTNFACE */
77     "HotTrackingColor", "0 0 255",         /* COLOR_HOTLIGHT */
78     "GradientActiveTitle", "16 132 208",   /* COLOR_GRADIENTACTIVECAPTION */
79     "GradientInactiveTitle", "184 180 184" /* COLOR_GRADIENTINACTIVECAPTION */
80 };
81
82
83 #define NUM_SYS_COLORS     (COLOR_GRADIENTINACTIVECAPTION+1)
84
85 static COLORREF SysColors[NUM_SYS_COLORS];
86 static HBRUSH32 SysColorBrushes[NUM_SYS_COLORS];
87 static HPEN32   SysColorPens[NUM_SYS_COLORS];
88
89 #define MAKE_SOLID(color) \
90        (PALETTEINDEX(GetNearestPaletteIndex32(STOCK_DEFAULT_PALETTE,(color))))
91
92 /*************************************************************************
93  *             SYSCOLOR_SetColor
94  */
95 static void SYSCOLOR_SetColor( int index, COLORREF color )
96 {
97     if (index < 0 || index >= NUM_SYS_COLORS) return;
98     SysColors[index] = color;
99     if (SysColorBrushes[index]) DeleteObject32( SysColorBrushes[index] );
100     SysColorBrushes[index] = CreateSolidBrush32( color );
101     if (SysColorPens[index]) DeleteObject32( SysColorPens[index] ); 
102     SysColorPens[index] = CreatePen32( PS_SOLID, 1, color );
103 }
104
105
106 /*************************************************************************
107  *             SYSCOLOR_Init
108  */
109 void SYSCOLOR_Init(void)
110 {
111     int i, r, g, b;
112     const char * const *p;
113     char buffer[100];
114
115     p = (TWEAK_WineLook == WIN31_LOOK) ? DefSysColors : DefSysColors95;
116     for (i = 0; i < NUM_SYS_COLORS; i++, p += 2)
117     {
118         GetProfileString32A( "colors", p[0], p[1], buffer, 100 );
119         if (sscanf( buffer, " %d %d %d", &r, &g, &b ) != 3) r = g = b = 0;
120         SYSCOLOR_SetColor( i, RGB(r,g,b) );
121     }
122 }
123
124
125 /*************************************************************************
126  *             GetSysColor16   (USER.180)
127  */
128 COLORREF WINAPI GetSysColor16( INT16 nIndex )
129 {
130     return GetSysColor32 (nIndex);
131 }
132
133
134 /*************************************************************************
135  *             GetSysColor32   (USER32.289)
136  */
137 COLORREF WINAPI GetSysColor32( INT32 nIndex )
138 {
139     if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
140         return SysColors[nIndex];
141     else
142         return 0;
143 }
144
145
146 /*************************************************************************
147  *             SetSysColors16   (USER.181)
148  */
149 VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
150                             const COLORREF *lpColorValues )
151 {
152     int i;
153
154     for (i = 0; i < nChanges; i++)
155     {
156         SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
157     }
158
159     /* Send WM_SYSCOLORCHANGE message to all windows */
160
161     SendMessage32A( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
162
163     /* Repaint affected portions of all visible windows */
164
165     RedrawWindow32( GetDesktopWindow32(), NULL, 0,
166                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
167 }
168
169
170 /*************************************************************************
171  *             SetSysColors32   (USER32.505)
172  */
173 BOOL32 WINAPI SetSysColors32( INT32 nChanges, const INT32 *lpSysColor,
174                               const COLORREF *lpColorValues )
175 {
176     int i;
177
178     for (i = 0; i < nChanges; i++)
179     {
180         SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] );
181     }
182
183     /* Send WM_SYSCOLORCHANGE message to all windows */
184
185     SendMessage32A( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
186
187     /* Repaint affected portions of all visible windows */
188
189     RedrawWindow32( GetDesktopWindow32(), NULL, 0,
190                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
191     return TRUE;
192 }
193
194
195 /***********************************************************************
196  *           GetSysColorBrush16    (USER.281)
197  */
198 HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
199 {
200     return (HBRUSH16)GetSysColorBrush32(index);
201 }
202
203
204 /***********************************************************************
205  *           GetSysColorBrush32    (USER32.290)
206  */
207 HBRUSH32 WINAPI GetSysColorBrush32( INT32 index )
208 {
209     if (0 <= index && index < NUM_SYS_COLORS)
210         return SysColorBrushes[index];
211     WARN(syscolor, "Unknown index(%d)\n", index );
212     return GetStockObject32(LTGRAY_BRUSH);
213 }
214
215
216 /***********************************************************************
217  *           GetSysColorPen16    (Not a Windows API)
218  */
219 HPEN16 WINAPI GetSysColorPen16( INT16 index )
220 {
221     return (HPEN16)GetSysColorPen32(index);
222 }
223
224
225 /***********************************************************************
226  *           GetSysColorPen32    (Not a Windows API)
227  *
228  * This function is new to the Wine lib -- it does not exist in 
229  * Windows. However, it is a natural complement for GetSysColorBrush
230  * in the Win32 API and is needed quite a bit inside Wine.
231  */
232 HPEN32 WINAPI GetSysColorPen32( INT32 index )
233 {
234     /* We can assert here, because this function is internal to Wine */
235     assert (0 <= index && index < NUM_SYS_COLORS);
236     return SysColorPens[index];
237
238 }