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 * PROGRAMMER: 7 */ 8 9 #include <win32k.h> 10 11 #define NDEBUG 12 #include <debug.h> 13 14 15 static const COLORREF SysColors[] = 16 { 17 RGB(212, 208, 200), /* COLOR_SCROLLBAR */ 18 RGB(58, 110, 165), /* COLOR_BACKGROUND */ 19 RGB(10, 36, 106), /* COLOR_ACTIVECAPTION */ 20 RGB(128, 128, 128), /* COLOR_INACTIVECAPTION */ 21 RGB(212, 208, 200), /* COLOR_MENU */ 22 RGB(255, 255, 255), /* COLOR_WINDOW */ 23 RGB(0, 0, 0), /* COLOR_WINDOWFRAME */ 24 RGB(0, 0, 0), /* COLOR_MENUTEXT */ 25 RGB(0, 0, 0), /* COLOR_WINDOWTEXT */ 26 RGB(255, 255, 255), /* COLOR_CAPTIONTEXT */ 27 RGB(212, 208, 200), /* COLOR_ACTIVEBORDER */ 28 RGB(212, 208, 200), /* COLOR_INACTIVEBORDER */ 29 RGB(128, 128, 128), /* COLOR_APPWORKSPACE */ 30 RGB(10, 36, 106), /* COLOR_HIGHLIGHT */ 31 RGB(255, 255, 255), /* COLOR_HIGHLIGHTTEXT */ 32 RGB(212, 208, 200), /* COLOR_BTNFACE */ 33 RGB(128, 128, 128), /* COLOR_BTNSHADOW */ 34 RGB(128, 128, 128), /* COLOR_GRAYTEXT */ 35 RGB(0, 0, 0), /* COLOR_BTNTEXT */ 36 RGB(212, 208, 200), /* COLOR_INACTIVECAPTIONTEXT */ 37 RGB(255, 255, 255), /* COLOR_BTNHIGHLIGHT */ 38 RGB(64, 64, 64), /* COLOR_3DDKSHADOW */ 39 RGB(212, 208, 200), /* COLOR_3DLIGHT */ 40 RGB(0, 0, 0), /* COLOR_INFOTEXT */ 41 RGB(255, 255, 225), /* COLOR_INFOBK */ 42 RGB(181, 181, 181), /* COLOR_UNKNOWN */ 43 RGB(0, 0, 128), /* COLOR_HOTLIGHT */ 44 RGB(166, 202, 240), /* COLOR_GRADIENTACTIVECAPTION */ 45 RGB(192, 192, 192), /* COLOR_GRADIENTINACTIVECAPTION */ 46 RGB(49, 106, 197), /* COLOR_MENUHILIGHT */ 47 RGB(236, 233, 216) /* COLOR_MENUBAR */ 48 }; 49 50 // System Bitmap DC 51 HDC hSystemBM; 52 53 /* GDI stock objects */ 54 55 static LOGPEN WhitePen = 56 { PS_SOLID, { 0, 0 }, RGB(255,255,255) }; 57 58 static LOGPEN BlackPen = 59 { PS_SOLID, { 0, 0 }, RGB(0,0,0) }; 60 61 static LOGPEN NullPen = 62 { PS_NULL, { 0, 0 }, 0 }; 63 64 static LOGFONTW OEMFixedFont = 65 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET, 66 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | FIXED_PITCH, L"Terminal" 67 }; 68 69 static LOGFONTW AnsiFixedFont = 70 { 14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 71 OUT_DEFAULT_PRECIS, /*CLIP_DEFAULT_PRECIS*/ CLIP_STROKE_PRECIS, /*DEFAULT_QUALITY*/ PROOF_QUALITY, FF_DONTCARE | FIXED_PITCH, L"Courier" 72 }; 73 74 static LOGFONTW AnsiVarFont = 75 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 76 OUT_DEFAULT_PRECIS, /*CLIP_DEFAULT_PRECIS*/ CLIP_STROKE_PRECIS, /*DEFAULT_QUALITY*/ PROOF_QUALITY, FF_DONTCARE | VARIABLE_PITCH, L"MS Sans Serif" 77 }; 78 79 static LOGFONTW SystemFont = 80 { 12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, 81 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | VARIABLE_PITCH, L"System" 82 }; 83 84 static LOGFONTW DeviceDefaultFont = 85 { 12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, 86 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | VARIABLE_PITCH, L"System" 87 }; 88 89 static LOGFONTW SystemFixedFont = 90 { 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 91 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | FIXED_PITCH, L"Fixedsys" 92 }; 93 94 static LOGFONTW DefaultGuiFont = 95 { 11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, 96 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, /*DEFAULT_QUALITY*/ PROOF_QUALITY, VARIABLE_PITCH | FF_SWISS, L"MS Shell Dlg" 97 }; 98 99 HGDIOBJ StockObjects[NB_STOCK_OBJECTS]; 100 101 static 102 HPEN 103 FASTCALL 104 IntCreateStockPen(DWORD dwPenStyle, 105 DWORD dwWidth, 106 ULONG ulBrushStyle, 107 ULONG ulColor) 108 { 109 HPEN hPen; 110 PBRUSH pbrushPen; 111 112 pbrushPen = PEN_AllocPenWithHandle(); 113 if (pbrushPen == NULL) return NULL; 114 115 if ((dwPenStyle & PS_STYLE_MASK) == PS_NULL) dwWidth = 1; 116 117 pbrushPen->iHatch = 0; 118 pbrushPen->lWidth = abs(dwWidth); 119 FLOATOBJ_SetLong(&pbrushPen->eWidth, pbrushPen->lWidth); 120 pbrushPen->ulPenStyle = dwPenStyle; 121 pbrushPen->BrushAttr.lbColor = ulColor; 122 pbrushPen->iBrushStyle = ulBrushStyle; 123 pbrushPen->hbmClient = (HANDLE)NULL; 124 pbrushPen->dwStyleCount = 0; 125 pbrushPen->pStyle = 0; 126 pbrushPen->flAttrs = BR_IS_OLDSTYLEPEN; 127 128 switch (dwPenStyle & PS_STYLE_MASK) 129 { 130 case PS_NULL: 131 pbrushPen->flAttrs |= BR_IS_NULL; 132 break; 133 134 case PS_SOLID: 135 pbrushPen->flAttrs |= BR_IS_SOLID; 136 break; 137 } 138 hPen = pbrushPen->BaseObject.hHmgr; 139 PEN_UnlockPen(pbrushPen); 140 return hPen; 141 } 142 143 /*! 144 * Creates a bunch of stock objects: brushes, pens, fonts. 145 */ 146 VOID FASTCALL 147 CreateStockObjects(void) 148 { 149 UINT Object; 150 151 DPRINT("Beginning creation of stock objects\n"); 152 153 /* Create GDI Stock Objects from the logical structures we've defined */ 154 155 StockObjects[WHITE_BRUSH] = IntGdiCreateSolidBrush(RGB(255,255,255)); 156 StockObjects[DC_BRUSH] = IntGdiCreateSolidBrush(RGB(255,255,255)); 157 StockObjects[LTGRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(192,192,192)); 158 StockObjects[GRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(128,128,128)); 159 StockObjects[DKGRAY_BRUSH] = IntGdiCreateSolidBrush(RGB(64,64,64)); 160 StockObjects[BLACK_BRUSH] = IntGdiCreateSolidBrush(RGB(0,0,0)); 161 StockObjects[NULL_BRUSH] = IntGdiCreateNullBrush(); 162 163 StockObjects[WHITE_PEN] = IntCreateStockPen(WhitePen.lopnStyle, WhitePen.lopnWidth.x, BS_SOLID, WhitePen.lopnColor); 164 StockObjects[BLACK_PEN] = IntCreateStockPen(BlackPen.lopnStyle, BlackPen.lopnWidth.x, BS_SOLID, BlackPen.lopnColor); 165 StockObjects[DC_PEN] = IntCreateStockPen(BlackPen.lopnStyle, BlackPen.lopnWidth.x, BS_SOLID, BlackPen.lopnColor); 166 StockObjects[NULL_PEN] = IntCreateStockPen(NullPen.lopnStyle, NullPen.lopnWidth.x, BS_SOLID, NullPen.lopnColor); 167 168 StockObjects[20] = NULL; /* TODO: Unknown internal stock object */ 169 StockObjects[DEFAULT_BITMAP] = GreCreateBitmap(1, 1, 1, 1, NULL); 170 171 (void) TextIntCreateFontIndirect(&OEMFixedFont, (HFONT*)&StockObjects[OEM_FIXED_FONT]); 172 (void) TextIntCreateFontIndirect(&AnsiFixedFont, (HFONT*)&StockObjects[ANSI_FIXED_FONT]); 173 (void) TextIntCreateFontIndirect(&AnsiVarFont, (HFONT*)&StockObjects[ANSI_VAR_FONT]); 174 (void) TextIntCreateFontIndirect(&SystemFont, (HFONT*)&StockObjects[SYSTEM_FONT]); 175 (void) TextIntCreateFontIndirect(&DeviceDefaultFont, (HFONT*)&StockObjects[DEVICE_DEFAULT_FONT]); 176 (void) TextIntCreateFontIndirect(&SystemFixedFont, (HFONT*)&StockObjects[SYSTEM_FIXED_FONT]); 177 (void) TextIntCreateFontIndirect(&DefaultGuiFont, (HFONT*)&StockObjects[DEFAULT_GUI_FONT]); 178 179 StockObjects[DEFAULT_PALETTE] = (HGDIOBJ)gppalDefault->BaseObject.hHmgr; 180 181 for (Object = 0; Object < NB_STOCK_OBJECTS; Object++) 182 { 183 if (NULL != StockObjects[Object]) 184 { 185 GDIOBJ_ConvertToStockObj(&StockObjects[Object]); 186 } 187 } 188 189 DPRINT("Completed creation of stock objects\n"); 190 } 191 192 /*! 193 * Return stock object. 194 * \param Object - stock object id. 195 * \return Handle to the object. 196 */ 197 HGDIOBJ APIENTRY 198 NtGdiGetStockObject(INT Object) 199 { 200 DPRINT("NtGdiGetStockObject index %d\n", Object); 201 202 return ((Object < 0) || (NB_STOCK_OBJECTS <= Object)) ? NULL : StockObjects[Object]; 203 } 204 205 VOID FASTCALL 206 IntSetSysColors(UINT nColors, CONST INT *Elements, CONST COLORREF *Colors) 207 { 208 UINT i; 209 210 for (i = 0; i < nColors; i++) 211 { 212 if ((UINT)(*Elements) < NUM_SYSCOLORS) 213 { 214 gpsi->argbSystem[*Elements] = *Colors; 215 IntGdiSetSolidBrushColor(gpsi->ahbrSystem[*Elements], *Colors); 216 } 217 Elements++; 218 Colors++; 219 } 220 } 221 222 HGDIOBJ FASTCALL 223 IntGetSysColorBrush(INT Object) 224 { 225 return ((Object < 0) || (NUM_SYSCOLORS <= Object)) ? NULL : gpsi->ahbrSystem[Object]; 226 } 227 228 DWORD FASTCALL 229 IntGetSysColor(INT nIndex) 230 { 231 return (NUM_SYSCOLORS <= (UINT)nIndex) ? 0 : gpsi->argbSystem[nIndex]; 232 } 233 234 VOID FASTCALL 235 CreateSysColorObjects(VOID) 236 { 237 UINT i; 238 239 for (i = 0; i < NUM_SYSCOLORS; i++) 240 { 241 gpsi->argbSystem[i] = SysColors[i]; 242 } 243 244 /* Create the syscolor brushes */ 245 for (i = 0; i < NUM_SYSCOLORS; i++) 246 { 247 if (gpsi->ahbrSystem[i] == NULL) 248 { 249 gpsi->ahbrSystem[i] = IntGdiCreateSolidBrush(SysColors[i]); 250 if (gpsi->ahbrSystem[i] != NULL) 251 { 252 GDIOBJ_ConvertToStockObj((HGDIOBJ*)&gpsi->ahbrSystem[i]); 253 } 254 } 255 } 256 } 257 258 /* EOF */ 259