Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

mngray.c

Go to the documentation of this file.
00001 /**************************** Module Header ********************************\ 00002 * Module Name: mngray.c 00003 * 00004 * Copyright (c) 1985 - 1999, Microsoft Corporation 00005 * 00006 * Server-side version of DrawState 00007 * 00008 * History: 00009 * 06-Jan-1993 FritzS Created 00010 \***************************************************************************/ 00011 00012 #include "precomp.h" 00013 #pragma hdrstop 00014 00015 #define PATOR 0x00FA0089L 00016 #define SRCSTENCIL 0x00B8074AL 00017 #define SRCINVSTENCIL 0x00E20746L 00018 00019 /***************************************************************************\ 00020 * 00021 * CreateCompatiblePublicDC 00022 * 00023 * This is used in several callback routines to the lpk(s). We can't 00024 * pass G_TERM(pDispInfo)->hdcGray or HDCBITS() to the client since they are public DCs. 00025 * We can't just change the owner since we're about to leave the 00026 * critical section. Some other thread may enter before we return 00027 * and use hdcGray or HDCBITS(). Instead, we create a compatible dc with the same 00028 * font and bitmap that are currently selected in hdcGray (or HDCBITS()). Pass that 00029 * to the client lpk. 00030 * 00031 * If the function returns successfully , then the dc and bitmap object are 00032 * guaranteed to be successfully created. 00033 * 00034 * History: 00035 * 00036 * Dec-16-1997 Samer Arafeh [samera] 00037 * Jan-20-1998 Samer Arafeh [samera] Add support for both hdcGray and HDCBITS() 00038 * 00039 \***************************************************************************/ 00040 HDC CreateCompatiblePublicDC( 00041 HDC hdcPublic, 00042 HBITMAP *pbmPublicDC) 00043 { 00044 HDC hdcCompatible = 0; 00045 HBITMAP hbmCompatible; 00046 HFONT hFont; 00047 int cx,cy; 00048 00049 if ((hdcPublic != gpDispInfo->hdcGray) && (hdcPublic != HDCBITS())) { 00050 return hdcPublic; 00051 } 00052 00053 if ((hdcCompatible = GreCreateCompatibleDC(hdcPublic)) == NULL) { 00054 RIPMSG1(RIP_WARNING, "CreateCompatiblePublicDC: GreCreateCompatibleDC Failed %lX", hdcPublic); 00055 return (HDC)NULL; 00056 } 00057 if (!GreSetDCOwner(hdcCompatible, OBJECT_OWNER_CURRENT)) { 00058 RIPMSG1(RIP_WARNING, "CreateCompatiblePublicDC: SetDCOwner Failed %lX", hdcCompatible); 00059 GreDeleteDC(hdcCompatible); 00060 return (HDC)NULL; 00061 } 00062 00063 if (hdcPublic == gpDispInfo->hdcGray) { 00064 cx = gpDispInfo->cxGray; 00065 cy = gpDispInfo->cxGray; 00066 } else { 00067 if (hdcPublic == HDCBITS()) { 00068 BITMAP bmBits; 00069 00070 GreExtGetObjectW(ghbmBits, sizeof(BITMAP), &bmBits); 00071 cx = bmBits.bmWidth; 00072 cy = bmBits.bmHeight; 00073 } else { 00074 00075 // 00076 // We should not reach here. 00077 // 00078 RIPMSG1(RIP_ERROR, "CreateCompatiblePublicDC: GreCreateCompatibleDC Failed %lX", hdcPublic); 00079 } 00080 00081 } 00082 00083 hbmCompatible = GreCreateCompatibleBitmap(hdcPublic, 00084 cx, 00085 cy); 00086 00087 // 00088 // Check whether bitmap couldn't be created or can't 00089 // be set to OBJECT_OWNER_CURRENT, then fail and 00090 // do necessary cleanup now! 00091 // 00092 00093 if( (hbmCompatible == NULL) || 00094 (!GreSetBitmapOwner(hbmCompatible, OBJECT_OWNER_CURRENT)) ) { 00095 00096 RIPMSG1(RIP_WARNING, "CreateCompatiblePublicDC: GreCreateCompatibleBitmap Failed %lX", hbmCompatible); 00097 GreDeleteDC( hdcCompatible ); 00098 00099 if( hbmCompatible ) { 00100 GreDeleteObject( hbmCompatible ); 00101 } 00102 00103 return (HDC)NULL; 00104 } 00105 00106 GreSelectBitmap(hdcCompatible, hbmCompatible); 00107 /* 00108 * Make sure we use the same font and text alignment. 00109 */ 00110 hFont = GreSelectFont(hdcPublic, ghFontSys); 00111 GreSelectFont(hdcPublic, hFont); 00112 GreSelectFont(hdcCompatible, hFont); 00113 GreSetTextAlign(hdcCompatible, GreGetTextAlign(hdcPublic)); 00114 /* 00115 * Copy any information already written into G_TERM(pDispInfo)->hdcGray. 00116 */ 00117 00118 #ifdef USE_MIRRORING 00119 // 00120 // Mirror the created DC if the hdcGray is currently mirrored, 00121 // so that TextOut won't get mirrored on User Client DCs 00122 // 00123 if (GreGetLayout(hdcPublic) & LAYOUT_RTL) 00124 GreSetLayout(hdcCompatible, cx - 1, LAYOUT_RTL); 00125 #endif 00126 GreBitBlt(hdcCompatible, 0, 0, cx, cy, hdcPublic, 0, 0, SRCCOPY, 0); 00127 00128 *pbmPublicDC = hbmCompatible ; // for later deletion, by the server side 00129 00130 return hdcCompatible; 00131 } 00132 00133 00134 00135 /***************************************************************************\ 00136 * 00137 * xxxDrawState() 00138 * 00139 * Generic state drawing routine. Does simple drawing into same DC if 00140 * normal state; uses offscreen bitmap otherwise. 00141 * 00142 * We do drawing for these simple types ourselves: 00143 * (1) Text 00144 * lData is string pointer. 00145 * wData is string length 00146 * (2) Icon 00147 * LOWORD(lData) is hIcon 00148 * (3) Bitmap 00149 * LOWORD(lData) is hBitmap 00150 * (4) Glyph (internal) 00151 * LOWORD(lData) is OBI_ value, one of 00152 * OBI_CHECKMARK 00153 * OBI_BULLET 00154 * OBI_MENUARROW 00155 * right now 00156 * 00157 * Other types are required to draw via the callback function, and are 00158 * allowed to stick whatever they want in lData and wData. 00159 * 00160 * We apply the following effects onto the image: 00161 * (1) Normal (nothing) 00162 * (2) Default (drop shadow) 00163 * (3) Union (gray string dither) 00164 * (4) Disabled (embossed) 00165 * 00166 * Note that we do NOT stretch anything. We just clip. 00167 * 00168 \***************************************************************************/ 00169 BOOL xxxDrawState( 00170 HDC hdcDraw, 00171 HBRUSH hbrFore, 00172 LPARAM lData, 00173 int x, 00174 int y, 00175 int cx, 00176 int cy, 00177 UINT uFlags) 00178 { 00179 HFONT hFont; 00180 HFONT hFontSave = NULL; 00181 HDC hdcT; 00182 HBITMAP hbmpT; 00183 POINT ptOrg; 00184 BOOL fResult; 00185 int oldAlign; 00186 #ifdef USE_MIRRORING 00187 DWORD dwOldLayout=0; 00188 #endif 00189 00190 /* 00191 * These require monochrome conversion 00192 * 00193 * Enforce monochrome: embossed doesn't look great with 2 color displays 00194 */ 00195 if ((uFlags & DSS_DISABLED) && 00196 ((gpsi->BitCount == 1) || SYSMET(SLOWMACHINE))) { 00197 00198 uFlags &= ~DSS_DISABLED; 00199 uFlags |= DSS_UNION; 00200 } 00201 00202 if (uFlags & (DSS_INACTIVE | DSS_DISABLED | DSS_DEFAULT | DSS_UNION)) 00203 uFlags |= DSS_MONO; 00204 00205 /* 00206 * Validate flags - we only support DST_COMPLEX in kernel 00207 */ 00208 if ((uFlags & DST_TYPEMASK) != DST_COMPLEX) { 00209 RIPMSG1(RIP_ERROR, "xxxDrawState: invalid DST_ type %x", (uFlags & DST_TYPEMASK)); 00210 return FALSE; 00211 } 00212 00213 /* 00214 * Optimize: nothing to draw 00215 */ 00216 if (!cx || !cy) { 00217 return TRUE; 00218 } 00219 00220 /* 00221 * Setup drawing dc 00222 */ 00223 if (uFlags & DSS_MONO) { 00224 00225 hdcT = gpDispInfo->hdcGray; 00226 #ifdef USE_MIRRORING 00227 /* 00228 * First turn off mirroring on hdcGray if any. 00229 */ 00230 GreSetLayout(hdcT, -1, 0); 00231 /* 00232 * Set the hdcGray layout to be equal to the screen hdcDraw layout. 00233 */ 00234 dwOldLayout = GreGetLayout(hdcDraw); 00235 if (dwOldLayout != GDI_ERROR) { 00236 GreSetLayout(hdcT, cx, dwOldLayout); 00237 } 00238 #endif 00239 00240 /* 00241 * Is our scratch bitmap big enough? We need potentially 00242 * cx+1 by cy pixels for default etc. 00243 */ 00244 if ((gpDispInfo->cxGray < cx + 1) || (gpDispInfo->cyGray < cy)) { 00245 00246 if (hbmpT = GreCreateBitmap(max(gpDispInfo->cxGray, cx + 1), max(gpDispInfo->cyGray, cy), 1, 1, 0L)) { 00247 00248 HBITMAP hbmGray; 00249 00250 hbmGray = GreSelectBitmap(gpDispInfo->hdcGray, hbmpT); 00251 GreDeleteObject(hbmGray); 00252 00253 GreSetBitmapOwner(hbmpT, OBJECT_OWNER_PUBLIC); 00254 00255 gpDispInfo->cxGray = max(gpDispInfo->cxGray, cx + 1); 00256 gpDispInfo->cyGray = max(gpDispInfo->cyGray, cy); 00257 00258 } else { 00259 cx = gpDispInfo->cxGray - 1; 00260 cy = gpDispInfo->cyGray; 00261 } 00262 } 00263 00264 GrePatBlt(gpDispInfo->hdcGray, 00265 0, 00266 0, 00267 gpDispInfo->cxGray, 00268 gpDispInfo->cyGray, 00269 WHITENESS); 00270 00271 GreSetTextCharacterExtra(gpDispInfo->hdcGray, 00272 GreGetTextCharacterExtra(hdcDraw)); 00273 00274 oldAlign = GreGetTextAlign(hdcT); 00275 GreSetTextAlign(hdcT, (oldAlign & ~(TA_RTLREADING |TA_CENTER |TA_RIGHT)) 00276 | (GreGetTextAlign(hdcDraw) & (TA_RTLREADING |TA_CENTER |TA_RIGHT))); 00277 /* 00278 * Setup font 00279 */ 00280 if (GreGetHFONT(hdcDraw) != ghFontSys) { 00281 hFont = GreSelectFont(hdcDraw, ghFontSys); 00282 GreSelectFont(hdcDraw, hFont); 00283 hFontSave = GreSelectFont(gpDispInfo->hdcGray, hFont); 00284 } 00285 } else { 00286 hdcT = hdcDraw; 00287 /* 00288 * Adjust viewport 00289 */ 00290 GreGetViewportOrg(hdcT, &ptOrg); 00291 GreSetViewportOrg(hdcT, ptOrg.x+x, ptOrg.y+y, NULL); 00292 00293 } 00294 00295 /* 00296 * Now, draw original image 00297 */ 00298 fResult = xxxRealDrawMenuItem(hdcT, (PGRAYMENU)lData, cx, cy); 00299 00300 /* 00301 * The callbacks could have altered the attributes of hdcGray 00302 */ 00303 if (hdcT == gpDispInfo->hdcGray) { 00304 GreSetBkColor(gpDispInfo->hdcGray, RGB(255, 255, 255)); 00305 GreSetTextColor(gpDispInfo->hdcGray, RGB(0, 0, 0)); 00306 GreSelectBrush(gpDispInfo->hdcGray, ghbrBlack); 00307 GreSetBkMode(gpDispInfo->hdcGray, OPAQUE); 00308 } 00309 00310 /* 00311 * Clean up 00312 */ 00313 if (uFlags & DSS_MONO) { 00314 00315 /* 00316 * Reset font 00317 */ 00318 if (hFontSave) 00319 GreSelectFont(hdcT, hFontSave); 00320 GreSetTextAlign(hdcT, oldAlign); 00321 } else { 00322 /* 00323 * Reset DC. 00324 */ 00325 GreSetViewportOrg(hdcT, ptOrg.x, ptOrg.y, NULL); 00326 return TRUE; 00327 } 00328 00329 /* 00330 * UNION state 00331 * Dither over image 00332 * We want white pixels to stay white, in either dest or pattern. 00333 */ 00334 if (uFlags & DSS_UNION) { 00335 00336 POLYPATBLT PolyData; 00337 00338 PolyData.x = 0; 00339 PolyData.y = 0; 00340 PolyData.cx = cx; 00341 PolyData.cy = cy; 00342 PolyData.BrClr.hbr = gpsi->hbrGray; 00343 00344 GrePolyPatBlt(gpDispInfo->hdcGray, PATOR, &PolyData, 1, PPB_BRUSH); 00345 } 00346 00347 if (uFlags & DSS_INACTIVE) { 00348 00349 BltColor(hdcDraw, 00350 SYSHBR(3DSHADOW), 00351 gpDispInfo->hdcGray, 00352 x, 00353 y, 00354 cx, 00355 cy, 00356 0, 00357 0, 00358 BC_INVERT); 00359 00360 } else if (uFlags & DSS_DISABLED) { 00361 00362 /* 00363 * Emboss 00364 * Draw over-1/down-1 in hilight color, and in same position in shadow. 00365 */ 00366 00367 BltColor(hdcDraw, 00368 SYSHBR(3DHILIGHT), 00369 gpDispInfo->hdcGray, 00370 x+1, 00371 y+1, 00372 cx, 00373 cy, 00374 0, 00375 0, 00376 BC_INVERT); 00377 00378 BltColor(hdcDraw, 00379 SYSHBR(3DSHADOW), 00380 gpDispInfo->hdcGray, 00381 x, 00382 y, 00383 cx, 00384 cy, 00385 0, 00386 0, 00387 BC_INVERT); 00388 00389 } else if (uFlags & DSS_DEFAULT) { 00390 00391 BltColor(hdcDraw, 00392 hbrFore, 00393 gpDispInfo->hdcGray, 00394 x, 00395 y, 00396 cx, 00397 cy, 00398 0, 00399 0, 00400 BC_INVERT); 00401 00402 BltColor(hdcDraw, 00403 hbrFore, 00404 gpDispInfo->hdcGray, 00405 x+1, 00406 y, 00407 cx, 00408 cy, 00409 0, 00410 0, 00411 BC_INVERT); 00412 00413 } else { 00414 00415 BltColor(hdcDraw, 00416 hbrFore, 00417 gpDispInfo->hdcGray, 00418 x, 00419 y, 00420 cx, 00421 cy, 00422 0, 00423 0, 00424 BC_INVERT); 00425 } 00426 00427 00428 #ifdef USE_MIRRORING 00429 if ((uFlags & DSS_MONO)){ 00430 /* 00431 * Set the hdcGray layout to 0, it is a public DC. 00432 */ 00433 GreSetLayout(hdcT, -1, 0); 00434 } 00435 #endif 00436 return fResult; 00437 } 00438 00439 /***************************************************************************\ 00440 * BltColor 00441 * 00442 * <brief description> 00443 * 00444 * History: 00445 * 13-Nov-1990 JimA Ported from Win3. 00446 \***************************************************************************/ 00447 00448 VOID BltColor( 00449 HDC hdc, 00450 HBRUSH hbr, 00451 HDC hdcSrce, 00452 int xO, 00453 int yO, 00454 int cx, 00455 int cy, 00456 int xO1, 00457 int yO1, 00458 UINT uBltFlags) 00459 { 00460 HBRUSH hbrSave; 00461 DWORD textColorSave; 00462 DWORD bkColorSave; 00463 DWORD ROP; 00464 00465 /* 00466 * Set the Text and Background colors so that bltColor handles the 00467 * background of buttons (and other bitmaps) properly. 00468 * Save the HDC's old Text and Background colors. This causes problems 00469 * with Omega (and probably other apps) when calling GrayString which 00470 * uses this routine... 00471 */ 00472 textColorSave = GreSetTextColor(hdc, 0x00000000L); 00473 bkColorSave = GreSetBkColor(hdc, 0x00FFFFFFL); 00474 00475 if (hbr != NULL) 00476 hbrSave = GreSelectBrush(hdc, hbr); 00477 if (uBltFlags & BC_INVERT) 00478 ROP = 0xB8074AL; 00479 else 00480 ROP = 0xE20746L; 00481 00482 if (uBltFlags & BC_NOMIRROR) 00483 ROP |= NOMIRRORBITMAP; 00484 00485 GreBitBlt(hdc, 00486 xO, 00487 yO, 00488 cx, 00489 cy, 00490 hdcSrce ? hdcSrce : gpDispInfo->hdcGray, 00491 xO1, 00492 yO1, 00493 ROP, 00494 0x00FFFFFF); 00495 00496 if (hbr != NULL) 00497 GreSelectBrush(hdc, hbrSave); 00498 00499 /* 00500 * Restore saved colors 00501 */ 00502 GreSetTextColor(hdc, textColorSave); 00503 GreSetBkColor(hdc, bkColorSave); 00504 }

Generated on Sat May 15 19:40:51 2004 for test by doxygen 1.3.7