2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "wine/winuser16.h"
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dc);
41 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
43 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
45 static const struct gdi_obj_funcs dc_funcs =
47 NULL, /* pSelectObject */
48 NULL, /* pGetObject16 */
49 NULL, /* pGetObjectA */
50 NULL, /* pGetObjectW */
51 NULL, /* pUnrealizeObject */
52 DC_DeleteObject /* pDeleteObject */
55 /***********************************************************************
58 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
63 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
81 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
88 dc->hPen = GetStockObject( BLACK_PEN );
89 dc->hBrush = GetStockObject( WHITE_BRUSH );
90 dc->hFont = GetStockObject( SYSTEM_FONT );
93 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
95 dc->ROPmode = R2_COPYPEN;
96 dc->polyFillMode = ALTERNATE;
97 dc->stretchBltMode = BLACKONWHITE;
98 dc->relAbsMode = ABSOLUTE;
99 dc->backgroundMode = OPAQUE;
100 dc->backgroundColor = RGB( 255, 255, 255 );
101 dc->dcBrushColor = RGB( 255, 255, 255 );
102 dc->dcPenColor = RGB( 0, 0, 0 );
103 dc->textColor = RGB( 0, 0, 0 );
106 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
110 dc->MapMode = MM_TEXT;
111 dc->GraphicsMode = GM_COMPATIBLE;
112 dc->pAbortProc = NULL;
115 dc->ArcDirection = AD_COUNTERCLOCKWISE;
116 dc->xformWorld2Wnd.eM11 = 1.0f;
117 dc->xformWorld2Wnd.eM12 = 0.0f;
118 dc->xformWorld2Wnd.eM21 = 0.0f;
119 dc->xformWorld2Wnd.eM22 = 1.0f;
120 dc->xformWorld2Wnd.eDx = 0.0f;
121 dc->xformWorld2Wnd.eDy = 0.0f;
122 dc->xformWorld2Vport = dc->xformWorld2Wnd;
123 dc->xformVport2World = dc->xformWorld2Wnd;
124 dc->vport2WorldValid = TRUE;
125 dc->BoundsRect.left = 0;
126 dc->BoundsRect.top = 0;
127 dc->BoundsRect.right = 0;
128 dc->BoundsRect.bottom = 0;
129 dc->saved_visrgn = NULL;
130 PATH_InitGdiPath(&dc->path);
136 /***********************************************************************
139 DC *DC_GetDCPtr( HDC hdc )
141 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
142 if (!ptr) return NULL;
143 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
144 (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
145 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
146 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
148 GDI_ReleaseObj( hdc );
149 SetLastError( ERROR_INVALID_HANDLE );
153 /***********************************************************************
156 * Retrieve a DC ptr while making sure the visRgn is updated.
157 * This function may call up to USER so the GDI lock should _not_
158 * be held when calling it.
160 DC *DC_GetDCUpdate( HDC hdc )
162 DC *dc = DC_GetDCPtr( hdc );
163 if (!dc) return NULL;
164 while (dc->flags & DC_DIRTY)
166 DCHOOKPROC proc = dc->hookThunk;
167 dc->flags &= ~DC_DIRTY;
170 DWORD data = dc->dwHookData;
171 GDI_ReleaseObj( hdc );
172 proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
173 if (!(dc = DC_GetDCPtr( hdc ))) break;
174 /* otherwise restart the loop in case it became dirty again in the meantime */
181 /***********************************************************************
184 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
186 GDI_ReleaseObj( handle );
187 return DeleteDC( handle );
191 /***********************************************************************
194 * Setup device-specific DC values for a newly created DC.
196 void DC_InitDC( DC* dc )
198 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
199 SetTextColor( dc->hSelf, dc->textColor );
200 SetBkColor( dc->hSelf, dc->backgroundColor );
201 SelectObject( dc->hSelf, dc->hPen );
202 SelectObject( dc->hSelf, dc->hBrush );
203 SelectObject( dc->hSelf, dc->hFont );
204 CLIPPING_UpdateGCRegion( dc );
208 /***********************************************************************
211 * Computes the inverse of the transformation xformSrc and stores it to
212 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
215 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
219 determinant = xformSrc->eM11*xformSrc->eM22 -
220 xformSrc->eM12*xformSrc->eM21;
221 if (determinant > -1e-12 && determinant < 1e-12)
224 xformDest->eM11 = xformSrc->eM22 / determinant;
225 xformDest->eM12 = -xformSrc->eM12 / determinant;
226 xformDest->eM21 = -xformSrc->eM21 / determinant;
227 xformDest->eM22 = xformSrc->eM11 / determinant;
228 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
229 xformSrc->eDy * xformDest->eM21;
230 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
231 xformSrc->eDy * xformDest->eM22;
237 /***********************************************************************
240 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
241 * fields of the specified DC by creating a transformation that
242 * represents the current mapping mode and combining it with the DC's
243 * world transform. This function should be called whenever the
244 * parameters associated with the mapping mode (window and viewport
245 * extents and origins) or the world transform change.
247 void DC_UpdateXforms( DC *dc )
249 XFORM xformWnd2Vport, oldworld2vport;
250 FLOAT scaleX, scaleY;
252 /* Construct a transformation to do the window-to-viewport conversion */
253 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
254 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
255 xformWnd2Vport.eM11 = scaleX;
256 xformWnd2Vport.eM12 = 0.0;
257 xformWnd2Vport.eM21 = 0.0;
258 xformWnd2Vport.eM22 = scaleY;
259 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
260 scaleX * (FLOAT)dc->wndOrgX;
261 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
262 scaleY * (FLOAT)dc->wndOrgY;
264 oldworld2vport = dc->xformWorld2Vport;
265 /* Combine with the world transformation */
266 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
269 /* Create inverse of world-to-viewport transformation */
270 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
271 &dc->xformVport2World );
273 /* Reselect the font and pen back into the dc so that the size
275 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
277 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
278 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
283 /***********************************************************************
284 * GetDCState (Not a Windows API)
286 HDC WINAPI GetDCState( HDC hdc )
291 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
292 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
294 GDI_ReleaseObj( hdc );
297 TRACE("(%p): returning %p\n", hdc, handle );
299 newdc->flags = dc->flags | DC_SAVED;
300 newdc->layout = dc->layout;
301 newdc->hPen = dc->hPen;
302 newdc->hBrush = dc->hBrush;
303 newdc->hFont = dc->hFont;
304 newdc->hBitmap = dc->hBitmap;
305 newdc->hDevice = dc->hDevice;
306 newdc->hPalette = dc->hPalette;
307 newdc->ROPmode = dc->ROPmode;
308 newdc->polyFillMode = dc->polyFillMode;
309 newdc->stretchBltMode = dc->stretchBltMode;
310 newdc->relAbsMode = dc->relAbsMode;
311 newdc->backgroundMode = dc->backgroundMode;
312 newdc->backgroundColor = dc->backgroundColor;
313 newdc->textColor = dc->textColor;
314 newdc->dcBrushColor = dc->dcBrushColor;
315 newdc->dcPenColor = dc->dcPenColor;
316 newdc->brushOrgX = dc->brushOrgX;
317 newdc->brushOrgY = dc->brushOrgY;
318 newdc->textAlign = dc->textAlign;
319 newdc->charExtra = dc->charExtra;
320 newdc->breakExtra = dc->breakExtra;
321 newdc->breakRem = dc->breakRem;
322 newdc->MapMode = dc->MapMode;
323 newdc->GraphicsMode = dc->GraphicsMode;
324 newdc->CursPosX = dc->CursPosX;
325 newdc->CursPosY = dc->CursPosY;
326 newdc->ArcDirection = dc->ArcDirection;
327 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
328 newdc->xformWorld2Vport = dc->xformWorld2Vport;
329 newdc->xformVport2World = dc->xformVport2World;
330 newdc->vport2WorldValid = dc->vport2WorldValid;
331 newdc->wndOrgX = dc->wndOrgX;
332 newdc->wndOrgY = dc->wndOrgY;
333 newdc->wndExtX = dc->wndExtX;
334 newdc->wndExtY = dc->wndExtY;
335 newdc->vportOrgX = dc->vportOrgX;
336 newdc->vportOrgY = dc->vportOrgY;
337 newdc->vportExtX = dc->vportExtX;
338 newdc->vportExtY = dc->vportExtY;
339 newdc->BoundsRect = dc->BoundsRect;
341 newdc->hSelf = (HDC)handle;
342 newdc->saveLevel = 0;
345 PATH_InitGdiPath( &newdc->path );
347 newdc->pAbortProc = NULL;
348 newdc->hookThunk = NULL;
350 newdc->saved_visrgn = NULL;
352 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
357 newdc->hMetaClipRgn = 0;
360 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
361 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
365 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
366 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
368 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
371 newdc->gdiFont = dc->gdiFont;
375 GDI_ReleaseObj( handle );
376 GDI_ReleaseObj( hdc );
381 /***********************************************************************
382 * SetDCState (Not a Windows API)
384 void WINAPI SetDCState( HDC hdc, HDC hdcs )
388 if (!(dc = DC_GetDCUpdate( hdc ))) return;
389 if (!(dcs = DC_GetDCPtr( hdcs )))
391 GDI_ReleaseObj( hdc );
394 if (!dcs->flags & DC_SAVED)
396 GDI_ReleaseObj( hdc );
397 GDI_ReleaseObj( hdcs );
400 TRACE("%p %p\n", hdc, hdcs );
402 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
403 dc->layout = dcs->layout;
404 dc->hDevice = dcs->hDevice;
405 dc->ROPmode = dcs->ROPmode;
406 dc->polyFillMode = dcs->polyFillMode;
407 dc->stretchBltMode = dcs->stretchBltMode;
408 dc->relAbsMode = dcs->relAbsMode;
409 dc->backgroundMode = dcs->backgroundMode;
410 dc->backgroundColor = dcs->backgroundColor;
411 dc->textColor = dcs->textColor;
412 dc->dcBrushColor = dcs->dcBrushColor;
413 dc->dcPenColor = dcs->dcPenColor;
414 dc->brushOrgX = dcs->brushOrgX;
415 dc->brushOrgY = dcs->brushOrgY;
416 dc->textAlign = dcs->textAlign;
417 dc->charExtra = dcs->charExtra;
418 dc->breakExtra = dcs->breakExtra;
419 dc->breakRem = dcs->breakRem;
420 dc->MapMode = dcs->MapMode;
421 dc->GraphicsMode = dcs->GraphicsMode;
422 dc->CursPosX = dcs->CursPosX;
423 dc->CursPosY = dcs->CursPosY;
424 dc->ArcDirection = dcs->ArcDirection;
425 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
426 dc->xformWorld2Vport = dcs->xformWorld2Vport;
427 dc->xformVport2World = dcs->xformVport2World;
428 dc->vport2WorldValid = dcs->vport2WorldValid;
429 dc->BoundsRect = dcs->BoundsRect;
431 dc->wndOrgX = dcs->wndOrgX;
432 dc->wndOrgY = dcs->wndOrgY;
433 dc->wndExtX = dcs->wndExtX;
434 dc->wndExtY = dcs->wndExtY;
435 dc->vportOrgX = dcs->vportOrgX;
436 dc->vportOrgY = dcs->vportOrgY;
437 dc->vportExtX = dcs->vportExtX;
438 dc->vportExtY = dcs->vportExtY;
442 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
443 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
447 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
452 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
453 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
457 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
460 CLIPPING_UpdateGCRegion( dc );
462 SelectObject( hdc, dcs->hBitmap );
463 SelectObject( hdc, dcs->hBrush );
464 SelectObject( hdc, dcs->hFont );
465 SelectObject( hdc, dcs->hPen );
466 SetBkColor( hdc, dcs->backgroundColor);
467 SetTextColor( hdc, dcs->textColor);
468 GDISelectPalette( hdc, dcs->hPalette, FALSE );
469 GDI_ReleaseObj( hdcs );
470 GDI_ReleaseObj( hdc );
474 /***********************************************************************
475 * GetDCState (GDI.179)
477 HDC16 WINAPI GetDCState16( HDC16 hdc )
479 return HDC_16( GetDCState( HDC_32(hdc) ));
483 /***********************************************************************
484 * SetDCState (GDI.180)
486 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
488 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
492 /***********************************************************************
495 INT WINAPI SaveDC( HDC hdc )
501 dc = DC_GetDCPtr( hdc );
504 if(dc->funcs->pSaveDC)
506 ret = dc->funcs->pSaveDC( dc->physDev );
507 GDI_ReleaseObj( hdc );
511 if (!(hdcs = GetDCState( hdc )))
513 GDI_ReleaseObj( hdc );
516 dcs = DC_GetDCPtr( hdcs );
518 /* Copy path. The reason why path saving / restoring is in SaveDC/
519 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
520 * functions are only in Win16 (which doesn't have paths) and that
521 * SetDCState doesn't allow us to signal an error (which can happen
522 * when copying paths).
524 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
526 GDI_ReleaseObj( hdc );
527 GDI_ReleaseObj( hdcs );
532 dcs->saved_dc = dc->saved_dc;
534 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
535 ret = ++dc->saveLevel;
536 GDI_ReleaseObj( hdcs );
537 GDI_ReleaseObj( hdc );
542 /***********************************************************************
543 * RestoreDC (GDI32.@)
545 BOOL WINAPI RestoreDC( HDC hdc, INT level )
550 TRACE("%p %d\n", hdc, level );
551 dc = DC_GetDCUpdate( hdc );
552 if(!dc) return FALSE;
553 if(dc->funcs->pRestoreDC)
555 success = dc->funcs->pRestoreDC( dc->physDev, level );
556 GDI_ReleaseObj( hdc );
560 if (level == -1) level = dc->saveLevel;
562 /* This pair of checks disagrees with MSDN "Platform SDK:
563 Windows GDI" July 2000 which says all negative values
564 for level will be interpreted as an instance relative
565 to the current state. Restricting it to just -1 does
567 || (level > dc->saveLevel))
569 GDI_ReleaseObj( hdc );
574 while (dc->saveLevel >= level)
576 HDC hdcs = dc->saved_dc;
577 if (!(dcs = DC_GetDCPtr( hdcs )))
579 GDI_ReleaseObj( hdc );
582 dc->saved_dc = dcs->saved_dc;
584 if (--dc->saveLevel < level)
586 SetDCState( hdc, hdcs );
587 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
588 /* FIXME: This might not be quite right, since we're
589 * returning FALSE but still destroying the saved DC state */
592 GDI_ReleaseObj( hdcs );
593 GDI_ReleaseObj( hdc );
595 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
597 GDI_ReleaseObj( hdc );
602 /***********************************************************************
603 * CreateDCW (GDI32.@)
605 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
606 const DEVMODEW *initData )
610 const DC_FUNCTIONS *funcs;
615 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
617 if (!driver) return 0;
618 strcpyW(buf, driver);
621 if (!(funcs = DRIVER_load_driver( buf )))
623 ERR( "no driver found for %s\n", debugstr_w(buf) );
626 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
628 DRIVER_release_driver( funcs );
633 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
635 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
636 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
638 if (dc->funcs->pCreateDC &&
639 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
641 WARN("creation aborted by device\n" );
642 GDI_FreeObject( dc->hSelf, dc );
643 DRIVER_release_driver( funcs );
647 dc->hVisRgn = CreateRectRgn( 0, 0, GetDeviceCaps( hdc, HORZRES ),
648 GetDeviceCaps( hdc, VERTRES ) );
651 GDI_ReleaseObj( hdc );
656 /***********************************************************************
657 * CreateDCA (GDI32.@)
659 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
660 const DEVMODEA *initData )
662 UNICODE_STRING driverW, deviceW, outputW;
666 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
667 else driverW.Buffer = NULL;
669 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
670 else deviceW.Buffer = NULL;
672 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
673 else outputW.Buffer = NULL;
678 /* don't convert initData for DISPLAY driver, it's not used */
679 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
680 initDataW = GdiConvertToDevmodeW(initData);
683 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
685 RtlFreeUnicodeString(&driverW);
686 RtlFreeUnicodeString(&deviceW);
687 RtlFreeUnicodeString(&outputW);
688 HeapFree(GetProcessHeap(), 0, initDataW);
693 /***********************************************************************
694 * CreateICA (GDI32.@)
696 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
697 const DEVMODEA* initData )
699 /* Nothing special yet for ICs */
700 return CreateDCA( driver, device, output, initData );
704 /***********************************************************************
705 * CreateICW (GDI32.@)
707 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
708 const DEVMODEW* initData )
710 /* Nothing special yet for ICs */
711 return CreateDCW( driver, device, output, initData );
715 /***********************************************************************
716 * CreateCompatibleDC (GDI32.@)
718 HDC WINAPI CreateCompatibleDC( HDC hdc )
721 const DC_FUNCTIONS *funcs;
726 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
728 funcs = origDC->funcs;
729 physDev = origDC->physDev;
730 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
731 funcs = DRIVER_get_driver( funcs );
735 funcs = DRIVER_load_driver( displayW );
739 if (!funcs) return 0;
741 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
743 DRIVER_release_driver( funcs );
747 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
749 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
751 /* Copy the driver-specific physical device info into
752 * the new DC. The driver may use this read-only info
753 * while creating the compatible DC below. */
754 dc->physDev = physDev;
756 if (dc->funcs->pCreateDC &&
757 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
759 WARN("creation aborted by device\n");
760 GDI_FreeObject( dc->hSelf, dc );
761 DRIVER_release_driver( funcs );
765 dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
768 GDI_ReleaseObj( dc->hSelf );
773 /***********************************************************************
776 BOOL WINAPI DeleteDC( HDC hdc )
778 const DC_FUNCTIONS *funcs = NULL;
785 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
787 /* Call hook procedure to check whether is it OK to delete this DC */
790 DCHOOKPROC proc = dc->hookThunk;
791 DWORD data = dc->dwHookData;
792 GDI_ReleaseObj( hdc );
793 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
794 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
797 while (dc->saveLevel)
800 HDC hdcs = dc->saved_dc;
801 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
802 dc->saved_dc = dcs->saved_dc;
804 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
805 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
806 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
807 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
808 PATH_DestroyGdiPath(&dcs->path);
809 GDI_FreeObject( hdcs, dcs );
812 if (!(dc->flags & DC_SAVED))
814 SelectObject( hdc, GetStockObject(BLACK_PEN) );
815 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
816 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
817 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
819 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
823 while (dc->saved_visrgn)
825 struct saved_visrgn *next = dc->saved_visrgn->next;
826 DeleteObject( dc->saved_visrgn->hrgn );
827 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
828 dc->saved_visrgn = next;
830 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
831 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
832 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
833 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
834 PATH_DestroyGdiPath(&dc->path);
836 GDI_FreeObject( hdc, dc );
837 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
842 /***********************************************************************
845 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
850 if ((dc = DC_GetDCPtr( hdc )))
852 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
853 GDI_ReleaseObj( hdc );
859 /***********************************************************************
862 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
867 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
868 else devmodeW = NULL;
870 ret = ResetDCW(hdc, devmodeW);
872 HeapFree(GetProcessHeap(), 0, devmodeW);
877 /***********************************************************************
878 * GetDeviceCaps (GDI32.@)
880 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
885 if ((dc = DC_GetDCPtr( hdc )))
887 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
888 GDI_ReleaseObj( hdc );
894 /***********************************************************************
895 * GetBkColor (GDI32.@)
897 COLORREF WINAPI GetBkColor( HDC hdc )
900 DC * dc = DC_GetDCPtr( hdc );
903 ret = dc->backgroundColor;
904 GDI_ReleaseObj( hdc );
910 /***********************************************************************
911 * SetBkColor (GDI32.@)
913 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
916 DC * dc = DC_GetDCPtr( hdc );
918 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
920 if (!dc) return CLR_INVALID;
921 oldColor = dc->backgroundColor;
922 if (dc->funcs->pSetBkColor)
924 color = dc->funcs->pSetBkColor(dc->physDev, color);
925 if (color == CLR_INVALID) /* don't change it */
928 oldColor = CLR_INVALID;
931 dc->backgroundColor = color;
932 GDI_ReleaseObj( hdc );
937 /***********************************************************************
938 * GetTextColor (GDI32.@)
940 COLORREF WINAPI GetTextColor( HDC hdc )
943 DC * dc = DC_GetDCPtr( hdc );
947 GDI_ReleaseObj( hdc );
953 /***********************************************************************
954 * SetTextColor (GDI32.@)
956 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
959 DC * dc = DC_GetDCPtr( hdc );
961 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
963 if (!dc) return CLR_INVALID;
964 oldColor = dc->textColor;
965 if (dc->funcs->pSetTextColor)
967 color = dc->funcs->pSetTextColor(dc->physDev, color);
968 if (color == CLR_INVALID) /* don't change it */
971 oldColor = CLR_INVALID;
974 dc->textColor = color;
975 GDI_ReleaseObj( hdc );
980 /***********************************************************************
981 * GetTextAlign (GDI32.@)
983 UINT WINAPI GetTextAlign( HDC hdc )
986 DC * dc = DC_GetDCPtr( hdc );
990 GDI_ReleaseObj( hdc );
996 /***********************************************************************
997 * SetTextAlign (GDI32.@)
999 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1002 DC *dc = DC_GetDCPtr( hdc );
1004 TRACE("hdc=%p align=%d\n", hdc, align);
1006 if (!dc) return 0x0;
1007 if (dc->funcs->pSetTextAlign)
1008 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
1010 prevAlign = dc->textAlign;
1011 dc->textAlign = align;
1013 GDI_ReleaseObj( hdc );
1017 /***********************************************************************
1018 * GetDCOrgEx (GDI32.@)
1020 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1024 if (!lpp) return FALSE;
1025 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
1027 lpp->x = lpp->y = 0;
1028 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1029 GDI_ReleaseObj( hDC );
1034 /***********************************************************************
1035 * SetDCOrg (GDI.117)
1037 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1040 HDC hdc = HDC_32( hdc16 );
1041 DC *dc = DC_GetDCPtr( hdc );
1043 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1044 GDI_ReleaseObj( hdc );
1049 /***********************************************************************
1050 * GetGraphicsMode (GDI32.@)
1052 INT WINAPI GetGraphicsMode( HDC hdc )
1055 DC * dc = DC_GetDCPtr( hdc );
1058 ret = dc->GraphicsMode;
1059 GDI_ReleaseObj( hdc );
1065 /***********************************************************************
1066 * SetGraphicsMode (GDI32.@)
1068 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1071 DC *dc = DC_GetDCPtr( hdc );
1073 /* One would think that setting the graphics mode to GM_COMPATIBLE
1074 * would also reset the world transformation matrix to the unity
1075 * matrix. However, in Windows, this is not the case. This doesn't
1076 * make a lot of sense to me, but that's the way it is.
1079 if ((mode > 0) && (mode <= GM_LAST))
1081 ret = dc->GraphicsMode;
1082 dc->GraphicsMode = mode;
1084 GDI_ReleaseObj( hdc );
1089 /***********************************************************************
1090 * GetArcDirection (GDI32.@)
1092 INT WINAPI GetArcDirection( HDC hdc )
1095 DC * dc = DC_GetDCPtr( hdc );
1098 ret = dc->ArcDirection;
1099 GDI_ReleaseObj( hdc );
1105 /***********************************************************************
1106 * SetArcDirection (GDI32.@)
1108 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1111 INT nOldDirection = 0;
1113 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1115 SetLastError(ERROR_INVALID_PARAMETER);
1119 if ((dc = DC_GetDCPtr( hdc )))
1121 if (dc->funcs->pSetArcDirection)
1123 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1125 nOldDirection = dc->ArcDirection;
1126 dc->ArcDirection = nDirection;
1127 GDI_ReleaseObj( hdc );
1129 return nOldDirection;
1133 /***********************************************************************
1134 * GetWorldTransform (GDI32.@)
1136 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1139 if (!xform) return FALSE;
1140 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1141 *xform = dc->xformWorld2Wnd;
1142 GDI_ReleaseObj( hdc );
1147 /***********************************************************************
1148 * GetTransform (GDI32.@)
1150 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1152 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1153 FIXME("stub: don't know what to do for code %lx\n", unknown );
1158 /***********************************************************************
1159 * SetWorldTransform (GDI32.@)
1161 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1164 DC *dc = DC_GetDCPtr( hdc );
1166 if (!dc) return FALSE;
1167 if (!xform) goto done;
1169 /* Check that graphics mode is GM_ADVANCED */
1170 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1172 if (dc->funcs->pSetWorldTransform)
1174 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1175 if (!ret) goto done;
1178 dc->xformWorld2Wnd = *xform;
1179 DC_UpdateXforms( dc );
1182 GDI_ReleaseObj( hdc );
1187 /****************************************************************************
1188 * ModifyWorldTransform [GDI32.@]
1189 * Modifies the world transformation for a device context.
1192 * hdc [I] Handle to device context
1193 * xform [I] XFORM structure that will be used to modify the world
1195 * iMode [I] Specifies in what way to modify the world transformation
1198 * Resets the world transformation to the identity matrix.
1199 * The parameter xform is ignored.
1201 * Multiplies xform into the world transformation matrix from
1204 * Multiplies xform into the world transformation matrix from
1209 * Failure: FALSE. Use GetLastError() to determine the cause.
1211 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1215 DC *dc = DC_GetDCPtr( hdc );
1217 /* Check for illegal parameters */
1218 if (!dc) return FALSE;
1219 if (!xform) goto done;
1221 /* Check that graphics mode is GM_ADVANCED */
1222 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1224 if (dc->funcs->pModifyWorldTransform)
1226 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1227 if (!ret) goto done;
1233 dc->xformWorld2Wnd.eM11 = 1.0f;
1234 dc->xformWorld2Wnd.eM12 = 0.0f;
1235 dc->xformWorld2Wnd.eM21 = 0.0f;
1236 dc->xformWorld2Wnd.eM22 = 1.0f;
1237 dc->xformWorld2Wnd.eDx = 0.0f;
1238 dc->xformWorld2Wnd.eDy = 0.0f;
1240 case MWT_LEFTMULTIPLY:
1241 CombineTransform( &dc->xformWorld2Wnd, xform,
1242 &dc->xformWorld2Wnd );
1244 case MWT_RIGHTMULTIPLY:
1245 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1252 DC_UpdateXforms( dc );
1255 GDI_ReleaseObj( hdc );
1260 /****************************************************************************
1261 * CombineTransform [GDI32.@]
1262 * Combines two transformation matrices.
1265 * xformResult [O] Stores the result of combining the two matrices
1266 * xform1 [I] Specifies the first matrix to apply
1267 * xform2 [I] Specifies the second matrix to apply
1270 * The same matrix can be passed in for more than one of the parameters.
1274 * Failure: FALSE. Use GetLastError() to determine the cause.
1276 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1277 const XFORM *xform2 )
1281 /* Check for illegal parameters */
1282 if (!xformResult || !xform1 || !xform2)
1285 /* Create the result in a temporary XFORM, since xformResult may be
1286 * equal to xform1 or xform2 */
1287 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1288 xform1->eM12 * xform2->eM21;
1289 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1290 xform1->eM12 * xform2->eM22;
1291 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1292 xform1->eM22 * xform2->eM21;
1293 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1294 xform1->eM22 * xform2->eM22;
1295 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1296 xform1->eDy * xform2->eM21 +
1298 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1299 xform1->eDy * xform2->eM22 +
1302 /* Copy the result to xformResult */
1303 *xformResult = xformTemp;
1309 /***********************************************************************
1310 * SetDCHook (GDI32.@)
1312 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1314 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1316 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1318 if (!dc) return FALSE;
1320 if (!(dc->flags & DC_SAVED))
1322 dc->dwHookData = dwHookData;
1323 dc->hookThunk = hookProc;
1325 GDI_ReleaseObj( hdc );
1330 /* relay function to call the 16-bit DC hook proc */
1331 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1335 FARPROC16 proc = NULL;
1336 HDC hdc = HDC_32( hdc16 );
1337 DC *dc = DC_GetDCPtr( hdc );
1339 if (!dc) return FALSE;
1340 proc = dc->hookProc;
1341 GDI_ReleaseObj( hdc );
1342 if (!proc) return FALSE;
1345 args[3] = HIWORD(data);
1346 args[2] = LOWORD(data);
1347 args[1] = HIWORD(lParam);
1348 args[0] = LOWORD(lParam);
1349 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1353 /***********************************************************************
1354 * SetDCHook (GDI.190)
1356 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1358 HDC hdc = HDC_32( hdc16 );
1359 DC *dc = DC_GetDCPtr( hdc );
1360 if (!dc) return FALSE;
1362 dc->hookProc = hookProc;
1363 GDI_ReleaseObj( hdc );
1364 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1368 /***********************************************************************
1369 * GetDCHook (GDI.191)
1371 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1373 HDC hdc = HDC_32( hdc16 );
1374 DC *dc = DC_GetDCPtr( hdc );
1378 *phookProc = dc->hookProc;
1379 ret = dc->dwHookData;
1380 GDI_ReleaseObj( hdc );
1385 /***********************************************************************
1386 * SetHookFlags (GDI.192)
1388 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1390 HDC hdc = HDC_32( hdc16 );
1391 DC *dc = DC_GetDCPtr( hdc );
1395 WORD wRet = dc->flags & DC_DIRTY;
1397 /* "Undocumented Windows" info is slightly confusing.
1400 TRACE("hDC %p, flags %04x\n",hdc,flags);
1402 if( flags & DCHF_INVALIDATEVISRGN )
1403 dc->flags |= DC_DIRTY;
1404 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1405 dc->flags &= ~DC_DIRTY;
1406 GDI_ReleaseObj( hdc );
1412 /***********************************************************************
1413 * SetICMMode (GDI32.@)
1415 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1417 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1418 if (iEnableICM == ICM_OFF) return ICM_OFF;
1419 if (iEnableICM == ICM_ON) return 0;
1420 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1424 /***********************************************************************
1425 * GetDeviceGammaRamp (GDI32.@)
1427 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1430 DC *dc = DC_GetDCPtr( hDC );
1434 if (dc->funcs->pGetDeviceGammaRamp)
1435 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1436 GDI_ReleaseObj( hDC );
1441 /***********************************************************************
1442 * SetDeviceGammaRamp (GDI32.@)
1444 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1447 DC *dc = DC_GetDCPtr( hDC );
1451 if (dc->funcs->pSetDeviceGammaRamp)
1452 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1453 GDI_ReleaseObj( hDC );
1458 /***********************************************************************
1459 * GetColorSpace (GDI32.@)
1461 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1463 /*FIXME Need to to whatever GetColorSpace actually does */
1467 /***********************************************************************
1468 * CreateColorSpaceA (GDI32.@)
1470 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1476 /***********************************************************************
1477 * CreateColorSpaceW (GDI32.@)
1479 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1485 /***********************************************************************
1486 * DeleteColorSpace (GDI32.@)
1488 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1495 /***********************************************************************
1496 * SetColorSpace (GDI32.@)
1498 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1505 /***********************************************************************
1506 * GetBoundsRect (GDI32.@)
1508 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1511 DC *dc = DC_GetDCPtr( hdc );
1513 if ( !dc ) return 0;
1515 if (rect) *rect = dc->BoundsRect;
1517 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1519 if (flags & DCB_RESET)
1521 dc->BoundsRect.left = 0;
1522 dc->BoundsRect.top = 0;
1523 dc->BoundsRect.right = 0;
1524 dc->BoundsRect.bottom = 0;
1525 dc->flags &= ~DC_BOUNDS_SET;
1527 GDI_ReleaseObj( hdc );
1532 /***********************************************************************
1533 * SetBoundsRect (GDI32.@)
1535 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1540 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1541 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1543 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1544 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1546 if (flags & DCB_RESET)
1548 dc->BoundsRect.left = 0;
1549 dc->BoundsRect.top = 0;
1550 dc->BoundsRect.right = 0;
1551 dc->BoundsRect.bottom = 0;
1552 dc->flags &= ~DC_BOUNDS_SET;
1555 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1557 if (dc->flags & DC_BOUNDS_SET)
1559 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1560 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1561 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1562 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1566 dc->BoundsRect = *rect;
1567 dc->flags |= DC_BOUNDS_SET;
1571 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1572 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1574 GDI_ReleaseObj( hdc );
1579 /***********************************************************************
1580 * GetRelAbs (GDI32.@)
1582 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1585 DC *dc = DC_GetDCPtr( hdc );
1586 if (dc) ret = dc->relAbsMode;
1587 GDI_ReleaseObj( hdc );
1594 /***********************************************************************
1595 * GetBkMode (GDI32.@)
1597 INT WINAPI GetBkMode( HDC hdc )
1600 DC * dc = DC_GetDCPtr( hdc );
1603 ret = dc->backgroundMode;
1604 GDI_ReleaseObj( hdc );
1610 /***********************************************************************
1611 * SetBkMode (GDI32.@)
1613 INT WINAPI SetBkMode( HDC hdc, INT mode )
1617 if ((mode <= 0) || (mode > BKMODE_LAST))
1619 SetLastError(ERROR_INVALID_PARAMETER);
1622 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1623 if (dc->funcs->pSetBkMode)
1624 ret = dc->funcs->pSetBkMode( dc->physDev, mode );
1627 ret = dc->backgroundMode;
1628 dc->backgroundMode = mode;
1630 GDI_ReleaseObj( hdc );
1635 /***********************************************************************
1638 INT WINAPI GetROP2( HDC hdc )
1641 DC * dc = DC_GetDCPtr( hdc );
1645 GDI_ReleaseObj( hdc );
1651 /***********************************************************************
1654 INT WINAPI SetROP2( HDC hdc, INT mode )
1658 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1660 SetLastError(ERROR_INVALID_PARAMETER);
1663 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1664 if (dc->funcs->pSetROP2)
1665 ret = dc->funcs->pSetROP2( dc->physDev, mode );
1671 GDI_ReleaseObj( hdc );
1676 /***********************************************************************
1677 * SetRelAbs (GDI32.@)
1679 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1683 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1685 SetLastError(ERROR_INVALID_PARAMETER);
1688 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1689 if (dc->funcs->pSetRelAbs)
1690 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1693 ret = dc->relAbsMode;
1694 dc->relAbsMode = mode;
1696 GDI_ReleaseObj( hdc );
1701 /***********************************************************************
1702 * GetPolyFillMode (GDI32.@)
1704 INT WINAPI GetPolyFillMode( HDC hdc )
1707 DC * dc = DC_GetDCPtr( hdc );
1710 ret = dc->polyFillMode;
1711 GDI_ReleaseObj( hdc );
1717 /***********************************************************************
1718 * SetPolyFillMode (GDI32.@)
1720 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1724 if ((mode <= 0) || (mode > POLYFILL_LAST))
1726 SetLastError(ERROR_INVALID_PARAMETER);
1729 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1730 if (dc->funcs->pSetPolyFillMode)
1731 ret = dc->funcs->pSetPolyFillMode( dc->physDev, mode );
1734 ret = dc->polyFillMode;
1735 dc->polyFillMode = mode;
1737 GDI_ReleaseObj( hdc );
1742 /***********************************************************************
1743 * GetStretchBltMode (GDI32.@)
1745 INT WINAPI GetStretchBltMode( HDC hdc )
1748 DC * dc = DC_GetDCPtr( hdc );
1751 ret = dc->stretchBltMode;
1752 GDI_ReleaseObj( hdc );
1758 /***********************************************************************
1759 * SetStretchBltMode (GDI32.@)
1761 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1765 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1767 SetLastError(ERROR_INVALID_PARAMETER);
1770 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1771 if (dc->funcs->pSetStretchBltMode)
1772 ret = dc->funcs->pSetStretchBltMode( dc->physDev, mode );
1775 ret = dc->stretchBltMode;
1776 dc->stretchBltMode = mode;
1778 GDI_ReleaseObj( hdc );
1783 /***********************************************************************
1784 * GetMapMode (GDI32.@)
1786 INT WINAPI GetMapMode( HDC hdc )
1789 DC * dc = DC_GetDCPtr( hdc );
1793 GDI_ReleaseObj( hdc );
1799 /***********************************************************************
1800 * GetBrushOrgEx (GDI32.@)
1802 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1804 DC * dc = DC_GetDCPtr( hdc );
1805 if (!dc) return FALSE;
1806 pt->x = dc->brushOrgX;
1807 pt->y = dc->brushOrgY;
1808 GDI_ReleaseObj( hdc );
1813 /***********************************************************************
1814 * GetCurrentPositionEx (GDI32.@)
1816 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1818 DC * dc = DC_GetDCPtr( hdc );
1819 if (!dc) return FALSE;
1820 pt->x = dc->CursPosX;
1821 pt->y = dc->CursPosY;
1822 GDI_ReleaseObj( hdc );
1827 /***********************************************************************
1828 * GetViewportExtEx (GDI32.@)
1830 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1832 DC * dc = DC_GetDCPtr( hdc );
1833 if (!dc) return FALSE;
1834 size->cx = dc->vportExtX;
1835 size->cy = dc->vportExtY;
1836 GDI_ReleaseObj( hdc );
1841 /***********************************************************************
1842 * GetViewportOrgEx (GDI32.@)
1844 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1846 DC * dc = DC_GetDCPtr( hdc );
1847 if (!dc) return FALSE;
1848 pt->x = dc->vportOrgX;
1849 pt->y = dc->vportOrgY;
1850 GDI_ReleaseObj( hdc );
1855 /***********************************************************************
1856 * GetWindowExtEx (GDI32.@)
1858 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1860 DC * dc = DC_GetDCPtr( hdc );
1861 if (!dc) return FALSE;
1862 size->cx = dc->wndExtX;
1863 size->cy = dc->wndExtY;
1864 GDI_ReleaseObj( hdc );
1869 /***********************************************************************
1870 * GetWindowOrgEx (GDI32.@)
1872 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1874 DC * dc = DC_GetDCPtr( hdc );
1875 if (!dc) return FALSE;
1876 pt->x = dc->wndOrgX;
1877 pt->y = dc->wndOrgY;
1878 GDI_ReleaseObj( hdc );
1883 /***********************************************************************
1884 * InquireVisRgn (GDI.131)
1886 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1889 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1892 ret = HRGN_16(dc->hVisRgn);
1893 GDI_ReleaseObj( HDC_32(hdc) );
1899 /***********************************************************************
1900 * GetClipRgn (GDI.173)
1902 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
1905 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1908 ret = HRGN_16(dc->hClipRgn);
1909 GDI_ReleaseObj( HDC_32(hdc) );
1915 /***********************************************************************
1916 * GetLayout (GDI32.@)
1918 * Gets left->right or right->left text layout flags of a dc.
1921 DWORD WINAPI GetLayout(HDC hdc)
1923 DWORD layout = GDI_ERROR;
1925 DC * dc = DC_GetDCPtr( hdc );
1928 layout = dc->layout;
1929 GDI_ReleaseObj( hdc );
1932 TRACE("hdc : %p, layout : %08lx\n", hdc, layout);
1937 /***********************************************************************
1938 * SetLayout (GDI32.@)
1940 * Sets left->right or right->left text layout flags of a dc.
1943 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1945 DWORD oldlayout = GDI_ERROR;
1947 DC * dc = DC_GetDCPtr( hdc );
1950 oldlayout = dc->layout;
1951 dc->layout = layout;
1952 GDI_ReleaseObj( hdc );
1955 TRACE("hdc : %p, old layout : %08lx, new layout : %08lx\n", hdc, oldlayout, layout);
1960 /***********************************************************************
1961 * GetDCBrushColor (GDI32.@)
1963 * Retrieves the current brush color for the specified device
1967 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1970 COLORREF dcBrushColor = CLR_INVALID;
1972 TRACE("hdc(%p)\n", hdc);
1974 dc = DC_GetDCPtr( hdc );
1977 dcBrushColor = dc->dcBrushColor;
1978 GDI_ReleaseObj( hdc );
1981 return dcBrushColor;
1984 /***********************************************************************
1985 * SetDCBrushColor (GDI32.@)
1987 * Sets the current device context (DC) brush color to the specified
1988 * color value. If the device cannot represent the specified color
1989 * value, the color is set to the nearest physical color.
1992 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1995 COLORREF oldClr = CLR_INVALID;
1997 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1999 dc = DC_GetDCPtr( hdc );
2002 if (dc->funcs->pSetDCBrushColor)
2003 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2004 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2006 /* If DC_BRUSH is selected, update driver pen color */
2007 HBRUSH hBrush = CreateSolidBrush( crColor );
2008 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2009 DeleteObject( hBrush );
2012 if (crColor != CLR_INVALID)
2014 oldClr = dc->dcBrushColor;
2015 dc->dcBrushColor = crColor;
2018 GDI_ReleaseObj( hdc );
2024 /***********************************************************************
2025 * GetDCPenColor (GDI32.@)
2027 * Retrieves the current pen color for the specified device
2031 COLORREF WINAPI GetDCPenColor(HDC hdc)
2034 COLORREF dcPenColor = CLR_INVALID;
2036 TRACE("hdc(%p)\n", hdc);
2038 dc = DC_GetDCPtr( hdc );
2041 dcPenColor = dc->dcPenColor;
2042 GDI_ReleaseObj( hdc );
2048 /***********************************************************************
2049 * SetDCPenColor (GDI32.@)
2051 * Sets the current device context (DC) pen color to the specified
2052 * color value. If the device cannot represent the specified color
2053 * value, the color is set to the nearest physical color.
2056 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2059 COLORREF oldClr = CLR_INVALID;
2061 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
2063 dc = DC_GetDCPtr( hdc );
2066 if (dc->funcs->pSetDCPenColor)
2067 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2068 else if (dc->hPen == GetStockObject( DC_PEN ))
2070 /* If DC_PEN is selected, update the driver pen color */
2071 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2072 HPEN hPen = CreatePenIndirect( &logpen );
2073 dc->funcs->pSelectPen( dc->physDev, hPen );
2074 DeleteObject( hPen );
2077 if (crColor != CLR_INVALID)
2079 oldClr = dc->dcPenColor;
2080 dc->dcPenColor = crColor;
2083 GDI_ReleaseObj( hdc );
2089 /***********************************************************************
2090 * SetVirtualResolution (GDI32.@)
2092 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2094 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2096 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
2100 /*******************************************************************
2101 * GetMiterLimit [GDI32.@]
2105 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2110 TRACE("(%p,%p)\n", hdc, peLimit);
2112 dc = DC_GetDCPtr( hdc );
2116 *peLimit = dc->miterLimit;
2118 GDI_ReleaseObj( hdc );
2124 /*******************************************************************
2125 * SetMiterLimit [GDI32.@]
2129 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2134 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2136 dc = DC_GetDCPtr( hdc );
2140 *peOldLimit = dc->miterLimit;
2141 dc->miterLimit = eNewLimit;
2142 GDI_ReleaseObj( hdc );
2148 /*******************************************************************
2149 * GdiIsMetaPrintDC [GDI32.@]
2151 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2157 /*******************************************************************
2158 * GdiIsMetaFileDC [GDI32.@]
2160 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2164 switch( GetObjectType( hdc ) )
2173 /*******************************************************************
2174 * GdiIsPlayMetafileDC [GDI32.@]
2176 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)