xref: /reactos/win32ss/gdi/ntgdi/stockobj.c (revision cbfe4d02)
1 /*
2  * PROJECT:         ReactOS win32 kernel mode subsystem
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            win32ss/gdi/ntgdi/stockobj.c
5  * PURPOSE:         Stock objects functions
6  * PROGRAMMERS:     Colin Finck <colin@reactos.org>
7  *                  Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
8  */
9 
10 #include <win32k.h>
11 
12 #define NDEBUG
13 #include <debug.h>
14 
15 
16 static const COLORREF SysColors[] =
17 {
18     RGB(212, 208, 200), /* COLOR_SCROLLBAR  */
19     RGB(58, 110, 165),  /* COLOR_BACKGROUND  */
20     RGB(10, 36, 106),   /* COLOR_ACTIVECAPTION  */
21     RGB(128, 128, 128), /* COLOR_INACTIVECAPTION  */
22     RGB(212, 208, 200), /* COLOR_MENU  */
23     RGB(255, 255, 255), /* COLOR_WINDOW  */
24     RGB(0, 0, 0),       /* COLOR_WINDOWFRAME  */
25     RGB(0, 0, 0),       /* COLOR_MENUTEXT  */
26     RGB(0, 0, 0),       /* COLOR_WINDOWTEXT  */
27     RGB(255, 255, 255), /* COLOR_CAPTIONTEXT  */
28     RGB(212, 208, 200), /* COLOR_ACTIVEBORDER  */
29     RGB(212, 208, 200), /* COLOR_INACTIVEBORDER  */
30     RGB(128, 128, 128), /* COLOR_APPWORKSPACE  */
31     RGB(10, 36, 106),   /* COLOR_HIGHLIGHT  */
32     RGB(255, 255, 255), /* COLOR_HIGHLIGHTTEXT  */
33     RGB(212, 208, 200), /* COLOR_BTNFACE  */
34     RGB(128, 128, 128), /* COLOR_BTNSHADOW  */
35     RGB(128, 128, 128), /* COLOR_GRAYTEXT  */
36     RGB(0, 0, 0),       /* COLOR_BTNTEXT  */
37     RGB(212, 208, 200), /* COLOR_INACTIVECAPTIONTEXT  */
38     RGB(255, 255, 255), /* COLOR_BTNHIGHLIGHT  */
39     RGB(64, 64, 64),    /* COLOR_3DDKSHADOW  */
40     RGB(212, 208, 200), /* COLOR_3DLIGHT  */
41     RGB(0, 0, 0),       /* COLOR_INFOTEXT  */
42     RGB(255, 255, 225), /* COLOR_INFOBK  */
43     RGB(181, 181, 181), /* COLOR_UNKNOWN  */
44     RGB(0, 0, 128),     /* COLOR_HOTLIGHT  */
45     RGB(166, 202, 240), /* COLOR_GRADIENTACTIVECAPTION  */
46     RGB(192, 192, 192), /* COLOR_GRADIENTINACTIVECAPTION  */
47     RGB(49, 106, 197),  /* COLOR_MENUHILIGHT  */
48     RGB(236, 233, 216)  /* COLOR_MENUBAR  */
49 };
50 
51 // System Bitmap DC
52 HDC hSystemBM;
53 
54 /*  GDI stock objects */
55 
56 static LOGPEN WhitePen =
57     { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
58 
59 static LOGPEN BlackPen =
60     { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
61 
62 static LOGPEN NullPen =
63     { PS_NULL, { 0, 0 }, 0 };
64 
65 static LOGFONTW OEMFixedFont =
66     { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
67       OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | FIXED_PITCH, L"Terminal"
68     };
69 
70 static LOGFONTW AnsiFixedFont =
71     { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
72       OUT_DEFAULT_PRECIS, /*CLIP_DEFAULT_PRECIS*/ CLIP_STROKE_PRECIS, /*DEFAULT_QUALITY*/ PROOF_QUALITY, FF_DONTCARE | FIXED_PITCH, L"Courier"
73     };
74 
75 static LOGFONTW AnsiVarFont =
76     { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
77       OUT_DEFAULT_PRECIS, /*CLIP_DEFAULT_PRECIS*/ CLIP_STROKE_PRECIS, /*DEFAULT_QUALITY*/ PROOF_QUALITY, FF_DONTCARE | VARIABLE_PITCH, L"MS Sans Serif"
78     };
79 
80 static LOGFONTW SystemFont =
81     { 16, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
82       OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | VARIABLE_PITCH, L"System"
83     };
84 
85 static LOGFONTW DeviceDefaultFont =
86     { 16, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
87       OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_SWISS | VARIABLE_PITCH, L"System"
88     };
89 
90 static LOGFONTW SystemFixedFont =
91     { 15, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
92       OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | FIXED_PITCH, L"Fixedsys"
93     };
94 
95 static LOGFONTW DefaultGuiFont =
96     { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
97       OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, /*DEFAULT_QUALITY*/ PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"MS Shell Dlg"
98     };
99 
100 HGDIOBJ StockObjects[NB_STOCK_OBJECTS];
101 
102 static
103 HPEN
104 FASTCALL
IntCreateStockPen(DWORD dwPenStyle,DWORD dwWidth,ULONG ulBrushStyle,ULONG ulColor)105 IntCreateStockPen(DWORD dwPenStyle,
106                   DWORD dwWidth,
107                   ULONG ulBrushStyle,
108                   ULONG ulColor)
109 {
110     HPEN hPen;
111     PBRUSH pbrushPen;
112 
113     pbrushPen = PEN_AllocPenWithHandle();
114     if (pbrushPen == NULL) return NULL;
115 
116     if ((dwPenStyle & PS_STYLE_MASK) == PS_NULL) dwWidth = 1;
117 
118     pbrushPen->iHatch = 0;
119     pbrushPen->lWidth = abs(dwWidth);
120     FLOATOBJ_SetLong(&pbrushPen->eWidth, pbrushPen->lWidth);
121     pbrushPen->ulPenStyle = dwPenStyle;
122     pbrushPen->BrushAttr.lbColor = ulColor;
123     pbrushPen->iBrushStyle = ulBrushStyle;
124     pbrushPen->hbmClient = (HANDLE)NULL;
125     pbrushPen->dwStyleCount = 0;
126     pbrushPen->pStyle = 0;
127     pbrushPen->flAttrs = BR_IS_OLDSTYLEPEN;
128 
129     switch (dwPenStyle & PS_STYLE_MASK)
130     {
131         case PS_NULL:
132             pbrushPen->flAttrs |= BR_IS_NULL;
133             break;
134 
135         case PS_SOLID:
136             pbrushPen->flAttrs |= BR_IS_SOLID;
137             break;
138     }
139     hPen = pbrushPen->BaseObject.hHmgr;
140     PEN_UnlockPen(pbrushPen);
141     return hPen;
142 }
143 
144 static VOID FASTCALL
CreateStockFonts(void)145 CreateStockFonts(void)
146 {
147     USHORT ActiveCodePage, OemCodePage;
148     BYTE bActiveCharSet, bOemCharSet;
149     BOOL bIsCJK;
150     static const WCHAR SimSun[] = { 0x5B8B, 0x4F53, 0 };
151     static const WCHAR MingLiU[] = { 0x7D30, 0x660E, 0x9AD4, 0 };
152     static const WCHAR Batang[] = { 0xBC14, 0xD0D5, 0 };
153 
154     RtlGetDefaultCodePage(&ActiveCodePage, &OemCodePage);
155     bActiveCharSet = IntCharSetFromCodePage(ActiveCodePage);
156     bOemCharSet = IntCharSetFromCodePage(OemCodePage);
157 
158     if (bOemCharSet == DEFAULT_CHARSET)
159         bOemCharSet = OEM_CHARSET;
160 
161     switch (ActiveCodePage)
162     {
163         case 936:
164             /* Simplified Chinese */
165             bIsCJK = TRUE;
166             wcscpy(DefaultGuiFont.lfFaceName, SimSun);
167             break;
168 
169         case 950:
170             /* Traditional Chinese */
171             bIsCJK = TRUE;
172             wcscpy(DefaultGuiFont.lfFaceName, MingLiU);
173             break;
174 
175         case 932:
176             /* Japanese */
177             bIsCJK = TRUE;
178             wcscpy(DefaultGuiFont.lfFaceName, L"MS UI Gothic");
179             break;
180 
181         case 949:
182         case 1361:
183             /* Korean */
184             bIsCJK = TRUE;
185             wcscpy(DefaultGuiFont.lfFaceName, Batang);
186             break;
187 
188         default:
189             /* Otherwise */
190             bIsCJK = FALSE;
191             wcscpy(DefaultGuiFont.lfFaceName, L"MS Shell Dlg");
192             break;
193     }
194 
195     if (bIsCJK)
196     {
197         OEMFixedFont.lfHeight = 18;
198         OEMFixedFont.lfPitchAndFamily = FF_DONTCARE | FIXED_PITCH;
199         SystemFont.lfHeight = 18;
200         SystemFont.lfPitchAndFamily = FF_DONTCARE | VARIABLE_PITCH;
201         DeviceDefaultFont.lfHeight = 18;
202         DeviceDefaultFont.lfPitchAndFamily = FF_DONTCARE | VARIABLE_PITCH;
203         SystemFixedFont.lfHeight = 18;
204         SystemFixedFont.lfPitchAndFamily = FF_DONTCARE | FIXED_PITCH;
205         DefaultGuiFont.lfHeight = -12;
206     }
207     else
208     {
209         OEMFixedFont.lfHeight = 12;
210         OEMFixedFont.lfPitchAndFamily = FF_MODERN | FIXED_PITCH;
211         SystemFont.lfHeight = 16;
212         SystemFont.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
213         DeviceDefaultFont.lfHeight = 16;
214         DeviceDefaultFont.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
215         if (bActiveCharSet == RUSSIAN_CHARSET)
216         {
217             SystemFixedFont.lfHeight = 16;
218             SystemFixedFont.lfPitchAndFamily = FF_SWISS | FIXED_PITCH;
219         }
220         else
221         {
222             SystemFixedFont.lfHeight = 15;
223             SystemFixedFont.lfPitchAndFamily = FF_MODERN | FIXED_PITCH;
224         }
225         DefaultGuiFont.lfHeight = -11;
226     }
227 
228     OEMFixedFont.lfCharSet = bOemCharSet;
229     SystemFont.lfCharSet = bActiveCharSet;
230     DeviceDefaultFont.lfCharSet = bActiveCharSet;
231     SystemFixedFont.lfCharSet = bActiveCharSet;
232     DefaultGuiFont.lfCharSet = bActiveCharSet;
233 
234     TextIntCreateFontIndirect(&OEMFixedFont, (HFONT*)&StockObjects[OEM_FIXED_FONT]);
235     TextIntCreateFontIndirect(&AnsiFixedFont, (HFONT*)&StockObjects[ANSI_FIXED_FONT]);
236     TextIntCreateFontIndirect(&AnsiVarFont, (HFONT*)&StockObjects[ANSI_VAR_FONT]);
237     TextIntCreateFontIndirect(&SystemFont, (HFONT*)&StockObjects[SYSTEM_FONT]);
238     TextIntCreateFontIndirect(&DeviceDefaultFont, (HFONT*)&StockObjects[DEVICE_DEFAULT_FONT]);
239     TextIntCreateFontIndirect(&SystemFixedFont, (HFONT*)&StockObjects[SYSTEM_FIXED_FONT]);
240     TextIntCreateFontIndirect(&DefaultGuiFont, (HFONT*)&StockObjects[DEFAULT_GUI_FONT]);
241 }
242 
243 /*!
244  * Creates a bunch of stock objects: brushes, pens, fonts.
245 */
246 VOID FASTCALL
CreateStockObjects(void)247 CreateStockObjects(void)
248 {
249     UINT Object;
250 
251     DPRINT("Beginning creation of stock objects\n");
252 
253     /* Create GDI Stock Objects from the logical structures we've defined */
254 
255     StockObjects[WHITE_BRUSH] =  IntGdiCreateSolidBrush(RGB(255,255,255));
256     StockObjects[DC_BRUSH]    =  IntGdiCreateSolidBrush(RGB(255,255,255));
257     StockObjects[LTGRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(192,192,192));
258     StockObjects[GRAY_BRUSH] =   IntGdiCreateSolidBrush(RGB(128,128,128));
259     StockObjects[DKGRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(64,64,64));
260     StockObjects[BLACK_BRUSH] =  IntGdiCreateSolidBrush(RGB(0,0,0));
261     StockObjects[NULL_BRUSH] =   IntGdiCreateNullBrush();
262 
263     StockObjects[WHITE_PEN] = IntCreateStockPen(WhitePen.lopnStyle, WhitePen.lopnWidth.x, BS_SOLID, WhitePen.lopnColor);
264     StockObjects[BLACK_PEN] = IntCreateStockPen(BlackPen.lopnStyle, BlackPen.lopnWidth.x, BS_SOLID, BlackPen.lopnColor);
265     StockObjects[DC_PEN]    = IntCreateStockPen(BlackPen.lopnStyle, BlackPen.lopnWidth.x, BS_SOLID, BlackPen.lopnColor);
266     StockObjects[NULL_PEN]  = IntCreateStockPen(NullPen.lopnStyle, NullPen.lopnWidth.x, BS_SOLID, NullPen.lopnColor);
267 
268     StockObjects[20] = NULL; /* TODO: Unknown internal stock object */
269     StockObjects[DEFAULT_BITMAP] = GreCreateBitmap(1, 1, 1, 1, NULL);
270 
271     CreateStockFonts();
272 
273     StockObjects[DEFAULT_PALETTE] = (HGDIOBJ)gppalDefault->BaseObject.hHmgr;
274 
275     for (Object = 0; Object < NB_STOCK_OBJECTS; Object++)
276     {
277         if (NULL != StockObjects[Object])
278         {
279             GDIOBJ_ConvertToStockObj(&StockObjects[Object]);
280         }
281     }
282 
283     DPRINT("Completed creation of stock objects\n");
284 }
285 
286 /*!
287  * Return stock object.
288  * \param	Object - stock object id.
289  * \return	Handle to the object.
290 */
291 HGDIOBJ APIENTRY
NtGdiGetStockObject(INT Object)292 NtGdiGetStockObject(INT Object)
293 {
294     DPRINT("NtGdiGetStockObject index %d\n", Object);
295 
296     return ((Object < 0) || (NB_STOCK_OBJECTS <= Object)) ? NULL : StockObjects[Object];
297 }
298 
299 VOID FASTCALL
IntSetSysColors(UINT nColors,CONST INT * Elements,CONST COLORREF * Colors)300 IntSetSysColors(UINT nColors, CONST INT *Elements, CONST COLORREF *Colors)
301 {
302     UINT i;
303 
304     for (i = 0; i < nColors; i++)
305     {
306         if ((UINT)(*Elements) < NUM_SYSCOLORS)
307         {
308             gpsi->argbSystem[*Elements] = *Colors;
309             IntGdiSetSolidBrushColor(gpsi->ahbrSystem[*Elements], *Colors);
310         }
311         Elements++;
312         Colors++;
313     }
314 }
315 
316 HGDIOBJ FASTCALL
IntGetSysColorBrush(INT Object)317 IntGetSysColorBrush(INT Object)
318 {
319     return ((Object < 0) || (NUM_SYSCOLORS <= Object)) ? NULL : gpsi->ahbrSystem[Object];
320 }
321 
322 DWORD FASTCALL
IntGetSysColor(INT nIndex)323 IntGetSysColor(INT nIndex)
324 {
325     return (NUM_SYSCOLORS <= (UINT)nIndex) ? 0 : gpsi->argbSystem[nIndex];
326 }
327 
328 VOID FASTCALL
CreateSysColorObjects(VOID)329 CreateSysColorObjects(VOID)
330 {
331     UINT i;
332 
333     for (i = 0; i < NUM_SYSCOLORS; i++)
334     {
335         gpsi->argbSystem[i] = SysColors[i];
336     }
337 
338     /* Create the syscolor brushes */
339     for (i = 0; i < NUM_SYSCOLORS; i++)
340     {
341         if (gpsi->ahbrSystem[i] == NULL)
342         {
343             gpsi->ahbrSystem[i] = IntGdiCreateSolidBrush(SysColors[i]);
344             if (gpsi->ahbrSystem[i] != NULL)
345             {
346                 GDIOBJ_ConvertToStockObj((HGDIOBJ*)&gpsi->ahbrSystem[i]);
347             }
348         }
349     }
350 }
351 
352 /* EOF */
353