[YAROTOWS] Reintegrate the branch. For a brighter future.
[reactos.git] / reactos / subsystems / win32 / win32k / objects / stockobj.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998 - 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * STOCKOBJ.C - GDI Stock Objects
21 *
22 *
23 */
24
25 #include <win32k.h>
26
27 #define NDEBUG
28 #include <debug.h>
29
30
31 static const COLORREF SysColors[] =
32 {
33 RGB(212, 208, 200), /* COLOR_SCROLLBAR */
34 RGB(58, 110, 165), /* COLOR_BACKGROUND */
35 RGB(10, 36, 106), /* COLOR_ACTIVECAPTION */
36 RGB(128, 128, 128), /* COLOR_INACTIVECAPTION */
37 RGB(212, 208, 200), /* COLOR_MENU */
38 RGB(255, 255, 255), /* COLOR_WINDOW */
39 RGB(0, 0, 0), /* COLOR_WINDOWFRAME */
40 RGB(0, 0, 0), /* COLOR_MENUTEXT */
41 RGB(0, 0, 0), /* COLOR_WINDOWTEXT */
42 RGB(255, 255, 255), /* COLOR_CAPTIONTEXT */
43 RGB(212, 208, 200), /* COLOR_ACTIVEBORDER */
44 RGB(212, 208, 200), /* COLOR_INACTIVEBORDER */
45 RGB(128, 128, 128), /* COLOR_APPWORKSPACE */
46 RGB(10, 36, 106), /* COLOR_HIGHLIGHT */
47 RGB(255, 255, 255), /* COLOR_HIGHLIGHTTEXT */
48 RGB(212, 208, 200), /* COLOR_BTNFACE */
49 RGB(128, 128, 128), /* COLOR_BTNSHADOW */
50 RGB(128, 128, 128), /* COLOR_GRAYTEXT */
51 RGB(0, 0, 0), /* COLOR_BTNTEXT */
52 RGB(212, 208, 200), /* COLOR_INACTIVECAPTIONTEXT */
53 RGB(255, 255, 255), /* COLOR_BTNHIGHLIGHT */
54 RGB(64, 64, 64), /* COLOR_3DDKSHADOW */
55 RGB(212, 208, 200), /* COLOR_3DLIGHT */
56 RGB(0, 0, 0), /* COLOR_INFOTEXT */
57 RGB(255, 255, 225), /* COLOR_INFOBK */
58 RGB(181, 181, 181), /* COLOR_UNKNOWN */
59 RGB(0, 0, 128), /* COLOR_HOTLIGHT */
60 RGB(166, 202, 240), /* COLOR_GRADIENTACTIVECAPTION */
61 RGB(192, 192, 192), /* COLOR_GRADIENTINACTIVECAPTION */
62 RGB(49, 106, 197), /* COLOR_MENUHILIGHT */
63 RGB(236, 233, 216) /* COLOR_MENUBAR */
64 };
65 #define NUM_SYSCOLORS (sizeof(SysColors) / sizeof(SysColors[0]))
66
67 // System Bitmap DC
68 HDC hSystemBM;
69
70 /* GDI stock objects */
71
72 static LOGPEN WhitePen =
73 { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
74
75 static LOGPEN BlackPen =
76 { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
77
78 static LOGPEN NullPen =
79 { PS_NULL, { 0, 0 }, 0 };
80
81 static LOGFONTW OEMFixedFont =
82 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
83 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, L"Courier New"
84 }; //Bitstream Vera Sans Mono
85
86 static LOGFONTW AnsiFixedFont =
87 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
88 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, L"Courier New"
89 }; //Bitstream Vera Sans Mono
90
91 static LOGFONTW AnsiVarFont =
92 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
93 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, L"MS Sans Serif"
94 };
95
96 static LOGFONTW SystemFont =
97 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
98 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, L"Courier New"
99 }; //Bitstream Vera Sans
100
101 static LOGFONTW DeviceDefaultFont =
102 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
103 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, L"MS Sans Serif"
104 }; //Bitstream Vera Sans
105
106 static LOGFONTW SystemFixedFont =
107 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
108 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, L"Courier New"
109 }; //Bitstream Vera Sans Mono
110
111 /* FIXME: Is this correct? */
112 static LOGFONTW DefaultGuiFont =
113 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
114 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, L"MS Sans Serif"
115 }; //Bitstream Vera Sans
116
117 HGDIOBJ StockObjects[NB_STOCK_OBJECTS];
118
119 static
120 HPEN
121 FASTCALL
122 IntCreateStockPen(DWORD dwPenStyle,
123 DWORD dwWidth,
124 ULONG ulBrushStyle,
125 ULONG ulColor)
126 {
127 HPEN hPen;
128 PBRUSH pbrushPen = PEN_AllocPenWithHandle();
129
130 if ((dwPenStyle & PS_STYLE_MASK) == PS_NULL) dwWidth = 1;
131
132 pbrushPen->ptPenWidth.x = abs(dwWidth);
133 pbrushPen->ptPenWidth.y = 0;
134 pbrushPen->ulPenStyle = dwPenStyle;
135 pbrushPen->BrushAttr.lbColor = ulColor;
136 pbrushPen->ulStyle = ulBrushStyle;
137 pbrushPen->hbmClient = (HANDLE)NULL;
138 pbrushPen->dwStyleCount = 0;
139 pbrushPen->pStyle = 0;
140 pbrushPen->flAttrs = GDIBRUSH_IS_OLDSTYLEPEN;
141
142 switch (dwPenStyle & PS_STYLE_MASK)
143 {
144 case PS_NULL:
145 pbrushPen->flAttrs |= GDIBRUSH_IS_NULL;
146 break;
147
148 case PS_SOLID:
149 pbrushPen->flAttrs |= GDIBRUSH_IS_SOLID;
150 break;
151 }
152 hPen = pbrushPen->BaseObject.hHmgr;
153 PEN_UnlockPen(pbrushPen);
154 return hPen;
155 }
156
157 /*!
158 * Creates a bunch of stock objects: brushes, pens, fonts.
159 */
160 VOID FASTCALL
161 CreateStockObjects(void)
162 {
163 UINT Object;
164
165 DPRINT("Beginning creation of stock objects\n");
166
167 /* Create GDI Stock Objects from the logical structures we've defined */
168
169 StockObjects[WHITE_BRUSH] = IntGdiCreateSolidBrush(RGB(255,255,255));
170 StockObjects[DC_BRUSH] = IntGdiCreateSolidBrush(RGB(255,255,255));
171 StockObjects[LTGRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(192,192,192));
172 StockObjects[GRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(128,128,128));
173 StockObjects[DKGRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(64,64,64));
174 StockObjects[BLACK_BRUSH] = IntGdiCreateSolidBrush(RGB(0,0,0));
175 StockObjects[NULL_BRUSH] = IntGdiCreateNullBrush();
176
177 StockObjects[WHITE_PEN] = IntCreateStockPen(WhitePen.lopnStyle, WhitePen.lopnWidth.x, BS_SOLID, WhitePen.lopnColor);
178 StockObjects[BLACK_PEN] = IntCreateStockPen(BlackPen.lopnStyle, BlackPen.lopnWidth.x, BS_SOLID, BlackPen.lopnColor);
179 StockObjects[DC_PEN] = IntCreateStockPen(BlackPen.lopnStyle, BlackPen.lopnWidth.x, BS_SOLID, BlackPen.lopnColor);
180 StockObjects[NULL_PEN] = IntCreateStockPen(NullPen.lopnStyle, NullPen.lopnWidth.x, BS_SOLID, NullPen.lopnColor);
181
182 StockObjects[20] = NULL; /* TODO: Unknown internal stock object */
183 StockObjects[DEFAULT_BITMAP] = GreCreateBitmap(1, 1, 1, 1, NULL);
184
185 (void) TextIntCreateFontIndirect(&OEMFixedFont, (HFONT*)&StockObjects[OEM_FIXED_FONT]);
186 (void) TextIntCreateFontIndirect(&AnsiFixedFont, (HFONT*)&StockObjects[ANSI_FIXED_FONT]);
187 (void) TextIntCreateFontIndirect(&AnsiVarFont, (HFONT*)&StockObjects[ANSI_VAR_FONT]);
188 (void) TextIntCreateFontIndirect(&SystemFont, (HFONT*)&StockObjects[SYSTEM_FONT]);
189 (void) TextIntCreateFontIndirect(&DeviceDefaultFont, (HFONT*)&StockObjects[DEVICE_DEFAULT_FONT]);
190 (void) TextIntCreateFontIndirect(&SystemFixedFont, (HFONT*)&StockObjects[SYSTEM_FIXED_FONT]);
191 (void) TextIntCreateFontIndirect(&DefaultGuiFont, (HFONT*)&StockObjects[DEFAULT_GUI_FONT]);
192
193 StockObjects[DEFAULT_PALETTE] = (HGDIOBJ)gppalDefault->BaseObject.hHmgr;
194
195 for (Object = 0; Object < NB_STOCK_OBJECTS; Object++)
196 {
197 if (NULL != StockObjects[Object])
198 {
199 GDIOBJ_ConvertToStockObj(&StockObjects[Object]);
200 }
201 }
202
203 DPRINT("Completed creation of stock objects\n");
204 }
205
206 /*!
207 * Return stock object.
208 * \param Object - stock object id.
209 * \return Handle to the object.
210 */
211 HGDIOBJ APIENTRY
212 NtGdiGetStockObject(INT Object)
213 {
214 DPRINT("NtGdiGetStockObject index %d\n", Object);
215
216 return ((Object < 0) || (NB_STOCK_OBJECTS <= Object)) ? NULL : StockObjects[Object];
217 }
218
219 BOOL FASTCALL
220 IntSetSysColors(UINT nColors, INT *Elements, COLORREF *Colors)
221 {
222 UINT i;
223
224 ASSERT(Elements);
225 ASSERT(Colors);
226
227 for (i = 0; i < nColors; i++)
228 {
229 if ((UINT)(*Elements) < NUM_SYSCOLORS)
230 {
231 gpsi->argbSystem[*Elements] = *Colors;
232 IntGdiSetSolidBrushColor(gpsi->ahbrSystem[*Elements], *Colors);
233 }
234 Elements++;
235 Colors++;
236 }
237 return nColors > 0;
238 }
239
240 HGDIOBJ FASTCALL
241 IntGetSysColorBrush(INT Object)
242 {
243 return ((Object < 0) || (NUM_SYSCOLORS <= Object)) ? NULL : gpsi->ahbrSystem[Object];
244 }
245
246 DWORD FASTCALL
247 IntGetSysColor(INT nIndex)
248 {
249 return (NUM_SYSCOLORS <= (UINT)nIndex) ? 0 : gpsi->argbSystem[nIndex];
250 }
251
252 VOID FASTCALL
253 CreateSysColorObjects(VOID)
254 {
255 UINT i;
256
257 for (i = 0; i < NUM_SYSCOLORS; i++)
258 {
259 gpsi->argbSystem[i] = SysColors[i];
260 }
261
262 /* Create the syscolor brushes */
263 for (i = 0; i < NUM_SYSCOLORS; i++)
264 {
265 if (gpsi->ahbrSystem[i] == NULL)
266 {
267 gpsi->ahbrSystem[i] = IntGdiCreateSolidBrush(SysColors[i]);
268 if (gpsi->ahbrSystem[i] != NULL)
269 {
270 GDIOBJ_ConvertToStockObj((HGDIOBJ*)&gpsi->ahbrSystem[i]);
271 }
272 }
273 }
274 }
275
276 /* EOF */