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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "gdi_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dc);
39 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
41 static BOOL DC_DeleteObject( HGDIOBJ handle );
43 static const struct gdi_obj_funcs dc_funcs =
45 NULL, /* pSelectObject */
46 NULL, /* pGetObjectA */
47 NULL, /* pGetObjectW */
48 NULL, /* pUnrealizeObject */
49 DC_DeleteObject /* pDeleteObject */
53 static inline DC *get_dc_obj( HDC hdc )
55 DC *dc = GDI_GetObjPtr( hdc, 0 );
58 if ((dc->header.type != OBJ_DC) &&
59 (dc->header.type != OBJ_MEMDC) &&
60 (dc->header.type != OBJ_METADC) &&
61 (dc->header.type != OBJ_ENHMETADC))
63 GDI_ReleaseObj( hdc );
64 SetLastError( ERROR_INVALID_HANDLE );
71 /***********************************************************************
74 DC *alloc_dc_ptr( WORD magic )
78 if (!(dc = HeapAlloc( GetProcessHeap(), 0, sizeof(*dc) ))) return NULL;
80 dc->nulldrv.funcs = &null_driver;
81 dc->nulldrv.next = NULL;
83 dc->physDev = &dc->nulldrv;
84 dc->thread = GetCurrentThreadId();
99 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
104 dc->hMetaClipRgn = 0;
107 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
108 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
109 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
112 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
115 dc->font_code_page = CP_ACP;
116 dc->ROPmode = R2_COPYPEN;
117 dc->polyFillMode = ALTERNATE;
118 dc->stretchBltMode = BLACKONWHITE;
119 dc->relAbsMode = ABSOLUTE;
120 dc->backgroundMode = OPAQUE;
121 dc->backgroundColor = RGB( 255, 255, 255 );
122 dc->dcBrushColor = RGB( 255, 255, 255 );
123 dc->dcPenColor = RGB( 0, 0, 0 );
124 dc->textColor = RGB( 0, 0, 0 );
128 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
132 dc->MapMode = MM_TEXT;
133 dc->GraphicsMode = GM_COMPATIBLE;
134 dc->pAbortProc = NULL;
137 dc->ArcDirection = AD_COUNTERCLOCKWISE;
138 dc->xformWorld2Wnd.eM11 = 1.0f;
139 dc->xformWorld2Wnd.eM12 = 0.0f;
140 dc->xformWorld2Wnd.eM21 = 0.0f;
141 dc->xformWorld2Wnd.eM22 = 1.0f;
142 dc->xformWorld2Wnd.eDx = 0.0f;
143 dc->xformWorld2Wnd.eDy = 0.0f;
144 dc->xformWorld2Vport = dc->xformWorld2Wnd;
145 dc->xformVport2World = dc->xformWorld2Wnd;
146 dc->vport2WorldValid = TRUE;
147 dc->BoundsRect.left = 0;
148 dc->BoundsRect.top = 0;
149 dc->BoundsRect.right = 0;
150 dc->BoundsRect.bottom = 0;
152 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
154 HeapFree( GetProcessHeap(), 0, dc );
157 dc->nulldrv.hdc = dc->hSelf;
159 if (font_driver && !font_driver->pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL ))
169 /***********************************************************************
172 static void free_dc_state( DC *dc )
174 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
175 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
176 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
177 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
178 if (dc->region) DeleteObject( dc->region );
179 if (dc->path) free_gdi_path( dc->path );
180 HeapFree( GetProcessHeap(), 0, dc );
184 /***********************************************************************
187 void free_dc_ptr( DC *dc )
189 assert( dc->refcount == 1 );
191 while (dc->physDev != &dc->nulldrv)
193 PHYSDEV physdev = pop_dc_driver( &dc->physDev );
194 physdev->funcs->pDeleteDC( physdev );
195 if (physdev == dc->dibdrv) dc->dibdrv = NULL;
197 if (dc->dibdrv) dc->dibdrv->funcs->pDeleteDC( dc->dibdrv );
198 free_gdi_handle( dc->hSelf );
203 /***********************************************************************
206 * Retrieve a DC pointer but release the GDI lock.
208 DC *get_dc_ptr( HDC hdc )
210 DC *dc = get_dc_obj( hdc );
211 if (!dc) return NULL;
213 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
215 dc->thread = GetCurrentThreadId();
217 else if (dc->thread != GetCurrentThreadId())
219 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
220 GDI_ReleaseObj( hdc );
223 else InterlockedIncrement( &dc->refcount );
225 GDI_ReleaseObj( hdc );
230 /***********************************************************************
233 void release_dc_ptr( DC *dc )
238 ref = InterlockedDecrement( &dc->refcount );
240 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
244 /***********************************************************************
247 * Make sure the DC vis region is up to date.
248 * This function may call up to USER so the GDI lock should _not_
249 * be held when calling it.
251 void update_dc( DC *dc )
253 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
254 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
258 /***********************************************************************
261 static BOOL DC_DeleteObject( HGDIOBJ handle )
263 return DeleteDC( handle );
267 /***********************************************************************
270 * Setup device-specific DC values for a newly created DC.
272 void DC_InitDC( DC* dc )
274 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
275 physdev->funcs->pRealizeDefaultPalette( physdev );
276 SetTextColor( dc->hSelf, dc->textColor );
277 SetBkColor( dc->hSelf, dc->backgroundColor );
278 SelectObject( dc->hSelf, dc->hPen );
279 SelectObject( dc->hSelf, dc->hBrush );
280 SelectObject( dc->hSelf, dc->hFont );
281 CLIPPING_UpdateGCRegion( dc );
282 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
286 /***********************************************************************
289 * Computes the inverse of the transformation xformSrc and stores it to
290 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
293 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
297 determinant = xformSrc->eM11*xformSrc->eM22 -
298 xformSrc->eM12*xformSrc->eM21;
299 if (determinant > -1e-12 && determinant < 1e-12)
302 xformDest->eM11 = xformSrc->eM22 / determinant;
303 xformDest->eM12 = -xformSrc->eM12 / determinant;
304 xformDest->eM21 = -xformSrc->eM21 / determinant;
305 xformDest->eM22 = xformSrc->eM11 / determinant;
306 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
307 xformSrc->eDy * xformDest->eM21;
308 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
309 xformSrc->eDy * xformDest->eM22;
314 /* Construct a transformation to do the window-to-viewport conversion */
315 static void construct_window_to_viewport(DC *dc, XFORM *xform)
317 double scaleX, scaleY;
318 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
319 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
321 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
322 xform->eM11 = scaleX;
325 xform->eM22 = scaleY;
326 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
327 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
328 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
331 /***********************************************************************
334 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
335 * fields of the specified DC by creating a transformation that
336 * represents the current mapping mode and combining it with the DC's
337 * world transform. This function should be called whenever the
338 * parameters associated with the mapping mode (window and viewport
339 * extents and origins) or the world transform change.
341 void DC_UpdateXforms( DC *dc )
343 XFORM xformWnd2Vport, oldworld2vport;
345 construct_window_to_viewport(dc, &xformWnd2Vport);
347 oldworld2vport = dc->xformWorld2Vport;
348 /* Combine with the world transformation */
349 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
352 /* Create inverse of world-to-viewport transformation */
353 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
354 &dc->xformVport2World );
356 /* Reselect the font and pen back into the dc so that the size
358 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
359 !GdiIsMetaFileDC(dc->hSelf))
361 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
362 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
367 /***********************************************************************
370 INT nulldrv_SaveDC( PHYSDEV dev )
372 DC *newdc, *dc = get_nulldrv_dc( dev );
374 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc )))) return 0;
375 newdc->flags = dc->flags;
376 newdc->layout = dc->layout;
377 newdc->hPen = dc->hPen;
378 newdc->hBrush = dc->hBrush;
379 newdc->hFont = dc->hFont;
380 newdc->hBitmap = dc->hBitmap;
381 newdc->hDevice = dc->hDevice;
382 newdc->hPalette = dc->hPalette;
383 newdc->ROPmode = dc->ROPmode;
384 newdc->polyFillMode = dc->polyFillMode;
385 newdc->stretchBltMode = dc->stretchBltMode;
386 newdc->relAbsMode = dc->relAbsMode;
387 newdc->backgroundMode = dc->backgroundMode;
388 newdc->backgroundColor = dc->backgroundColor;
389 newdc->textColor = dc->textColor;
390 newdc->dcBrushColor = dc->dcBrushColor;
391 newdc->dcPenColor = dc->dcPenColor;
392 newdc->brushOrgX = dc->brushOrgX;
393 newdc->brushOrgY = dc->brushOrgY;
394 newdc->mapperFlags = dc->mapperFlags;
395 newdc->textAlign = dc->textAlign;
396 newdc->charExtra = dc->charExtra;
397 newdc->breakExtra = dc->breakExtra;
398 newdc->breakRem = dc->breakRem;
399 newdc->MapMode = dc->MapMode;
400 newdc->GraphicsMode = dc->GraphicsMode;
401 newdc->CursPosX = dc->CursPosX;
402 newdc->CursPosY = dc->CursPosY;
403 newdc->ArcDirection = dc->ArcDirection;
404 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
405 newdc->xformWorld2Vport = dc->xformWorld2Vport;
406 newdc->xformVport2World = dc->xformVport2World;
407 newdc->vport2WorldValid = dc->vport2WorldValid;
408 newdc->wndOrgX = dc->wndOrgX;
409 newdc->wndOrgY = dc->wndOrgY;
410 newdc->wndExtX = dc->wndExtX;
411 newdc->wndExtY = dc->wndExtY;
412 newdc->vportOrgX = dc->vportOrgX;
413 newdc->vportOrgY = dc->vportOrgY;
414 newdc->vportExtX = dc->vportExtX;
415 newdc->vportExtY = dc->vportExtY;
416 newdc->virtual_res = dc->virtual_res;
417 newdc->virtual_size = dc->virtual_size;
418 newdc->BoundsRect = dc->BoundsRect;
419 newdc->gdiFont = dc->gdiFont;
421 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
427 newdc->hMetaClipRgn = 0;
430 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
431 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
435 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
436 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
439 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
441 if (!PATH_SavePath( newdc, dc ))
443 release_dc_ptr( dc );
444 free_dc_state( newdc );
448 newdc->saved_dc = dc->saved_dc;
449 dc->saved_dc = newdc;
450 return ++dc->saveLevel;
454 /***********************************************************************
457 BOOL nulldrv_RestoreDC( PHYSDEV dev, INT level )
459 DC *dcs, *first_dcs, *dc = get_nulldrv_dc( dev );
462 /* find the state level to restore */
464 if (abs(level) > dc->saveLevel || level == 0) return FALSE;
465 if (level < 0) level = dc->saveLevel + level + 1;
466 first_dcs = dc->saved_dc;
467 for (dcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
470 /* restore the state */
472 if (!PATH_RestorePath( dc, dcs )) return FALSE;
474 dc->flags = dcs->flags;
475 dc->layout = dcs->layout;
476 dc->hDevice = dcs->hDevice;
477 dc->ROPmode = dcs->ROPmode;
478 dc->polyFillMode = dcs->polyFillMode;
479 dc->stretchBltMode = dcs->stretchBltMode;
480 dc->relAbsMode = dcs->relAbsMode;
481 dc->backgroundMode = dcs->backgroundMode;
482 dc->backgroundColor = dcs->backgroundColor;
483 dc->textColor = dcs->textColor;
484 dc->dcBrushColor = dcs->dcBrushColor;
485 dc->dcPenColor = dcs->dcPenColor;
486 dc->brushOrgX = dcs->brushOrgX;
487 dc->brushOrgY = dcs->brushOrgY;
488 dc->mapperFlags = dcs->mapperFlags;
489 dc->textAlign = dcs->textAlign;
490 dc->charExtra = dcs->charExtra;
491 dc->breakExtra = dcs->breakExtra;
492 dc->breakRem = dcs->breakRem;
493 dc->MapMode = dcs->MapMode;
494 dc->GraphicsMode = dcs->GraphicsMode;
495 dc->CursPosX = dcs->CursPosX;
496 dc->CursPosY = dcs->CursPosY;
497 dc->ArcDirection = dcs->ArcDirection;
498 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
499 dc->xformWorld2Vport = dcs->xformWorld2Vport;
500 dc->xformVport2World = dcs->xformVport2World;
501 dc->vport2WorldValid = dcs->vport2WorldValid;
502 dc->BoundsRect = dcs->BoundsRect;
504 dc->wndOrgX = dcs->wndOrgX;
505 dc->wndOrgY = dcs->wndOrgY;
506 dc->wndExtX = dcs->wndExtX;
507 dc->wndExtY = dcs->wndExtY;
508 dc->vportOrgX = dcs->vportOrgX;
509 dc->vportOrgY = dcs->vportOrgY;
510 dc->vportExtX = dcs->vportExtX;
511 dc->vportExtY = dcs->vportExtY;
512 dc->virtual_res = dcs->virtual_res;
513 dc->virtual_size = dcs->virtual_size;
517 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
518 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
522 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
527 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
528 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
532 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
535 DC_UpdateXforms( dc );
536 CLIPPING_UpdateGCRegion( dc );
538 SelectObject( dev->hdc, dcs->hBitmap );
539 SelectObject( dev->hdc, dcs->hBrush );
540 SelectObject( dev->hdc, dcs->hFont );
541 SelectObject( dev->hdc, dcs->hPen );
542 SetBkColor( dev->hdc, dcs->backgroundColor);
543 SetTextColor( dev->hdc, dcs->textColor);
544 GDISelectPalette( dev->hdc, dcs->hPalette, FALSE );
546 dc->saved_dc = dcs->saved_dc;
548 dc->saveLevel = save_level - 1;
550 /* now destroy all the saved DCs */
554 DC *next = first_dcs->saved_dc;
555 free_dc_state( first_dcs );
562 /***********************************************************************
565 INT WINAPI SaveDC( HDC hdc )
570 if ((dc = get_dc_ptr( hdc )))
572 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSaveDC );
573 ret = physdev->funcs->pSaveDC( physdev );
574 release_dc_ptr( dc );
580 /***********************************************************************
581 * RestoreDC (GDI32.@)
583 BOOL WINAPI RestoreDC( HDC hdc, INT level )
586 BOOL success = FALSE;
588 TRACE("%p %d\n", hdc, level );
589 if ((dc = get_dc_ptr( hdc )))
591 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRestoreDC );
593 success = physdev->funcs->pRestoreDC( physdev, level );
594 release_dc_ptr( dc );
600 /***********************************************************************
601 * CreateDCW (GDI32.@)
603 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
604 const DEVMODEW *initData )
608 const struct gdi_dc_funcs *funcs;
613 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
617 ERR( "no device found for %s\n", debugstr_w(device) );
620 strcpyW(buf, driver);
623 if (!(funcs = DRIVER_load_driver( buf )))
625 ERR( "no driver found for %s\n", debugstr_w(buf) );
628 if (!(dc = alloc_dc_ptr( OBJ_DC ))) goto error;
631 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
632 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
634 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
635 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
637 if (funcs->pCreateDC)
639 if (!funcs->pCreateDC( &dc->physDev, buf, device, output, initData ))
641 WARN("creation aborted by device\n" );
646 dc->vis_rect.left = 0;
647 dc->vis_rect.top = 0;
648 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
649 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
650 SetRectRgn(dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top, dc->vis_rect.right, dc->vis_rect.bottom);
653 release_dc_ptr( dc );
657 if (dc) free_dc_ptr( dc );
662 /***********************************************************************
663 * CreateDCA (GDI32.@)
665 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
666 const DEVMODEA *initData )
668 UNICODE_STRING driverW, deviceW, outputW;
672 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
673 else driverW.Buffer = NULL;
675 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
676 else deviceW.Buffer = NULL;
678 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
679 else outputW.Buffer = NULL;
684 /* don't convert initData for DISPLAY driver, it's not used */
685 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
686 initDataW = GdiConvertToDevmodeW(initData);
689 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
691 RtlFreeUnicodeString(&driverW);
692 RtlFreeUnicodeString(&deviceW);
693 RtlFreeUnicodeString(&outputW);
694 HeapFree(GetProcessHeap(), 0, initDataW);
699 /***********************************************************************
700 * CreateICA (GDI32.@)
702 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
703 const DEVMODEA* initData )
705 /* Nothing special yet for ICs */
706 return CreateDCA( driver, device, output, initData );
710 /***********************************************************************
711 * CreateICW (GDI32.@)
713 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
714 const DEVMODEW* initData )
716 /* Nothing special yet for ICs */
717 return CreateDCW( driver, device, output, initData );
721 /***********************************************************************
722 * CreateCompatibleDC (GDI32.@)
724 HDC WINAPI CreateCompatibleDC( HDC hdc )
728 const struct gdi_dc_funcs *funcs = &null_driver;
729 PHYSDEV physDev = NULL;
735 if (!(origDC = get_dc_ptr( hdc ))) return 0;
736 physDev = GET_DC_PHYSDEV( origDC, pCreateCompatibleDC );
737 funcs = physDev->funcs;
738 release_dc_ptr( origDC );
741 if (!(dc = alloc_dc_ptr( OBJ_MEMDC ))) goto error;
743 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
745 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
746 dc->vis_rect.left = 0;
747 dc->vis_rect.top = 0;
748 dc->vis_rect.right = 1;
749 dc->vis_rect.bottom = 1;
750 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
754 if (!funcs->pCreateCompatibleDC( physDev, &dc->physDev ))
756 WARN("creation aborted by device\n");
760 release_dc_ptr( dc );
764 if (dc) free_dc_ptr( dc );
769 /***********************************************************************
772 BOOL WINAPI DeleteDC( HDC hdc )
780 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
781 if (dc->refcount != 1)
783 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
784 release_dc_ptr( dc );
788 /* Call hook procedure to check whether is it OK to delete this DC */
789 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
791 release_dc_ptr( dc );
795 while (dc->saveLevel)
797 DC *dcs = dc->saved_dc;
798 dc->saved_dc = dcs->saved_dc;
800 free_dc_state( dcs );
804 SelectObject( hdc, GetStockObject(BLACK_PEN) );
805 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
806 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
807 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
814 /***********************************************************************
817 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
822 if ((dc = get_dc_ptr( hdc )))
824 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
825 ret = physdev->funcs->pResetDC( physdev, devmode );
826 if (ret) /* reset the visible region */
829 dc->vis_rect.left = 0;
830 dc->vis_rect.top = 0;
831 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
832 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
833 SetRectRgn( dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top,
834 dc->vis_rect.right, dc->vis_rect.bottom );
835 CLIPPING_UpdateGCRegion( dc );
837 release_dc_ptr( dc );
843 /***********************************************************************
846 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
851 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
852 else devmodeW = NULL;
854 ret = ResetDCW(hdc, devmodeW);
856 HeapFree(GetProcessHeap(), 0, devmodeW);
861 /***********************************************************************
862 * GetDeviceCaps (GDI32.@)
864 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
869 if ((dc = get_dc_ptr( hdc )))
871 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
872 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
873 release_dc_ptr( dc );
879 /***********************************************************************
880 * GetBkColor (GDI32.@)
882 COLORREF WINAPI GetBkColor( HDC hdc )
885 DC * dc = get_dc_ptr( hdc );
888 ret = dc->backgroundColor;
889 release_dc_ptr( dc );
895 /***********************************************************************
896 * SetBkColor (GDI32.@)
898 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
900 COLORREF ret = CLR_INVALID;
901 DC * dc = get_dc_ptr( hdc );
903 TRACE("hdc=%p color=0x%08x\n", hdc, color);
907 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
908 color = physdev->funcs->pSetBkColor( physdev, color );
909 if (color != CLR_INVALID)
911 ret = dc->backgroundColor;
912 dc->backgroundColor = color;
914 release_dc_ptr( dc );
920 /***********************************************************************
921 * GetTextColor (GDI32.@)
923 COLORREF WINAPI GetTextColor( HDC hdc )
926 DC * dc = get_dc_ptr( hdc );
930 release_dc_ptr( dc );
936 /***********************************************************************
937 * SetTextColor (GDI32.@)
939 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
941 COLORREF ret = CLR_INVALID;
942 DC * dc = get_dc_ptr( hdc );
944 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
948 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
949 color = physdev->funcs->pSetTextColor( physdev, color );
950 if (color != CLR_INVALID)
953 dc->textColor = color;
955 release_dc_ptr( dc );
961 /***********************************************************************
962 * GetTextAlign (GDI32.@)
964 UINT WINAPI GetTextAlign( HDC hdc )
967 DC * dc = get_dc_ptr( hdc );
971 release_dc_ptr( dc );
977 /***********************************************************************
978 * SetTextAlign (GDI32.@)
980 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
982 UINT ret = GDI_ERROR;
983 DC *dc = get_dc_ptr( hdc );
985 TRACE("hdc=%p align=%d\n", hdc, align);
989 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
990 align = physdev->funcs->pSetTextAlign( physdev, align );
991 if (align != GDI_ERROR)
994 dc->textAlign = align;
996 release_dc_ptr( dc );
1001 /***********************************************************************
1002 * GetDCOrgEx (GDI32.@)
1004 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1008 if (!lpp) return FALSE;
1009 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1010 lpp->x = dc->vis_rect.left;
1011 lpp->y = dc->vis_rect.top;
1012 release_dc_ptr( dc );
1017 /***********************************************************************
1018 * GetGraphicsMode (GDI32.@)
1020 INT WINAPI GetGraphicsMode( HDC hdc )
1023 DC * dc = get_dc_ptr( hdc );
1026 ret = dc->GraphicsMode;
1027 release_dc_ptr( dc );
1033 /***********************************************************************
1034 * SetGraphicsMode (GDI32.@)
1036 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1039 DC *dc = get_dc_ptr( hdc );
1041 /* One would think that setting the graphics mode to GM_COMPATIBLE
1042 * would also reset the world transformation matrix to the unity
1043 * matrix. However, in Windows, this is not the case. This doesn't
1044 * make a lot of sense to me, but that's the way it is.
1047 if ((mode > 0) && (mode <= GM_LAST))
1049 ret = dc->GraphicsMode;
1050 dc->GraphicsMode = mode;
1052 release_dc_ptr( dc );
1057 /***********************************************************************
1058 * GetArcDirection (GDI32.@)
1060 INT WINAPI GetArcDirection( HDC hdc )
1063 DC * dc = get_dc_ptr( hdc );
1066 ret = dc->ArcDirection;
1067 release_dc_ptr( dc );
1073 /***********************************************************************
1074 * SetArcDirection (GDI32.@)
1076 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1081 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1083 SetLastError(ERROR_INVALID_PARAMETER);
1087 if ((dc = get_dc_ptr( hdc )))
1089 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1090 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1093 ret = dc->ArcDirection;
1094 dc->ArcDirection = dir;
1096 release_dc_ptr( dc );
1102 /***********************************************************************
1103 * GetWorldTransform (GDI32.@)
1105 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1108 if (!xform) return FALSE;
1109 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1110 *xform = dc->xformWorld2Wnd;
1111 release_dc_ptr( dc );
1116 /***********************************************************************
1117 * GetTransform (GDI32.@)
1121 * Returns one of the co-ordinate space transforms
1124 * hdc [I] Device context.
1125 * which [I] Which xform to return:
1126 * 0x203 World -> Page transform (that set by SetWorldTransform).
1127 * 0x304 Page -> Device transform (the mapping mode transform).
1128 * 0x204 World -> Device transform (the combination of the above two).
1129 * 0x402 Device -> World transform (the inversion of the above).
1130 * xform [O] The xform.
1133 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1136 DC *dc = get_dc_ptr( hdc );
1137 if (!dc) return FALSE;
1142 *xform = dc->xformWorld2Wnd;
1146 construct_window_to_viewport(dc, xform);
1150 *xform = dc->xformWorld2Vport;
1154 *xform = dc->xformVport2World;
1158 FIXME("Unknown code %x\n", which);
1162 release_dc_ptr( dc );
1167 /****************************************************************************
1168 * CombineTransform [GDI32.@]
1169 * Combines two transformation matrices.
1172 * xformResult [O] Stores the result of combining the two matrices
1173 * xform1 [I] Specifies the first matrix to apply
1174 * xform2 [I] Specifies the second matrix to apply
1177 * The same matrix can be passed in for more than one of the parameters.
1181 * Failure: FALSE. Use GetLastError() to determine the cause.
1183 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1184 const XFORM *xform2 )
1188 /* Check for illegal parameters */
1189 if (!xformResult || !xform1 || !xform2)
1192 /* Create the result in a temporary XFORM, since xformResult may be
1193 * equal to xform1 or xform2 */
1194 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1195 xform1->eM12 * xform2->eM21;
1196 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1197 xform1->eM12 * xform2->eM22;
1198 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1199 xform1->eM22 * xform2->eM21;
1200 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1201 xform1->eM22 * xform2->eM22;
1202 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1203 xform1->eDy * xform2->eM21 +
1205 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1206 xform1->eDy * xform2->eM22 +
1209 /* Copy the result to xformResult */
1210 *xformResult = xformTemp;
1216 /***********************************************************************
1217 * SetDCHook (GDI32.@)
1219 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1221 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1223 DC *dc = get_dc_ptr( hdc );
1225 if (!dc) return FALSE;
1227 dc->dwHookData = dwHookData;
1228 dc->hookProc = hookProc;
1229 release_dc_ptr( dc );
1234 /***********************************************************************
1235 * GetDCHook (GDI32.@)
1237 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1239 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1241 DC *dc = get_dc_ptr( hdc );
1245 if (proc) *proc = dc->hookProc;
1246 ret = dc->dwHookData;
1247 release_dc_ptr( dc );
1252 /***********************************************************************
1253 * SetHookFlags (GDI32.@)
1255 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1257 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1259 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1264 /* "Undocumented Windows" info is slightly confusing. */
1266 TRACE("hDC %p, flags %04x\n",hdc,flags);
1268 if (flags & DCHF_INVALIDATEVISRGN)
1269 ret = InterlockedExchange( &dc->dirty, 1 );
1270 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1271 ret = InterlockedExchange( &dc->dirty, 0 );
1273 GDI_ReleaseObj( hdc );
1277 /***********************************************************************
1278 * SetICMMode (GDI32.@)
1280 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1282 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1283 if (iEnableICM == ICM_OFF) return ICM_OFF;
1284 if (iEnableICM == ICM_ON) return 0;
1285 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1289 /***********************************************************************
1290 * GetDeviceGammaRamp (GDI32.@)
1292 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1295 DC *dc = get_dc_ptr( hDC );
1297 TRACE("%p, %p\n", hDC, ptr);
1300 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1301 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1302 release_dc_ptr( dc );
1307 /***********************************************************************
1308 * SetDeviceGammaRamp (GDI32.@)
1310 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1313 DC *dc = get_dc_ptr( hDC );
1315 TRACE("%p, %p\n", hDC, ptr);
1318 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1319 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1320 release_dc_ptr( dc );
1325 /***********************************************************************
1326 * GetColorSpace (GDI32.@)
1328 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1330 /*FIXME Need to do whatever GetColorSpace actually does */
1334 /***********************************************************************
1335 * CreateColorSpaceA (GDI32.@)
1337 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1343 /***********************************************************************
1344 * CreateColorSpaceW (GDI32.@)
1346 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1352 /***********************************************************************
1353 * DeleteColorSpace (GDI32.@)
1355 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1362 /***********************************************************************
1363 * SetColorSpace (GDI32.@)
1365 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1372 /***********************************************************************
1373 * GetBoundsRect (GDI32.@)
1375 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1378 DC *dc = get_dc_ptr( hdc );
1380 if ( !dc ) return 0;
1384 *rect = dc->BoundsRect;
1385 ret = is_rect_empty( rect ) ? DCB_RESET : DCB_SET;
1386 DPtoLP( hdc, (POINT *)rect, 2 );
1388 if (flags & DCB_RESET)
1390 dc->BoundsRect.left = 0;
1391 dc->BoundsRect.top = 0;
1392 dc->BoundsRect.right = 0;
1393 dc->BoundsRect.bottom = 0;
1395 release_dc_ptr( dc );
1400 /***********************************************************************
1401 * SetBoundsRect (GDI32.@)
1403 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1408 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1409 if (!(dc = get_dc_ptr( hdc ))) return 0;
1411 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1412 (is_rect_empty( &dc->BoundsRect ) ? DCB_RESET : DCB_SET);
1414 if (flags & DCB_RESET)
1416 dc->BoundsRect.left = 0;
1417 dc->BoundsRect.top = 0;
1418 dc->BoundsRect.right = 0;
1419 dc->BoundsRect.bottom = 0;
1422 if ((flags & DCB_ACCUMULATE) && rect)
1426 LPtoDP( hdc, (POINT *)&rc, 2 );
1427 if (!is_rect_empty( &rc ))
1429 if (!is_rect_empty( &dc->BoundsRect))
1431 dc->BoundsRect.left = min( dc->BoundsRect.left, rc.left );
1432 dc->BoundsRect.top = min( dc->BoundsRect.top, rc.top );
1433 dc->BoundsRect.right = max( dc->BoundsRect.right, rc.right );
1434 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rc.bottom );
1436 else dc->BoundsRect = rc;
1440 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1441 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1443 release_dc_ptr( dc );
1448 /***********************************************************************
1449 * GetRelAbs (GDI32.@)
1451 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1454 DC *dc = get_dc_ptr( hdc );
1457 ret = dc->relAbsMode;
1458 release_dc_ptr( dc );
1466 /***********************************************************************
1467 * GetBkMode (GDI32.@)
1469 INT WINAPI GetBkMode( HDC hdc )
1472 DC * dc = get_dc_ptr( hdc );
1475 ret = dc->backgroundMode;
1476 release_dc_ptr( dc );
1482 /***********************************************************************
1483 * SetBkMode (GDI32.@)
1485 INT WINAPI SetBkMode( HDC hdc, INT mode )
1490 if ((mode <= 0) || (mode > BKMODE_LAST))
1492 SetLastError(ERROR_INVALID_PARAMETER);
1495 if ((dc = get_dc_ptr( hdc )))
1497 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1498 mode = physdev->funcs->pSetBkMode( physdev, mode );
1501 ret = dc->backgroundMode;
1502 dc->backgroundMode = mode;
1504 release_dc_ptr( dc );
1510 /***********************************************************************
1513 INT WINAPI GetROP2( HDC hdc )
1516 DC * dc = get_dc_ptr( hdc );
1520 release_dc_ptr( dc );
1526 /***********************************************************************
1529 INT WINAPI SetROP2( HDC hdc, INT mode )
1534 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1536 SetLastError(ERROR_INVALID_PARAMETER);
1539 if ((dc = get_dc_ptr( hdc )))
1541 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1542 mode = physdev->funcs->pSetROP2( physdev, mode );
1548 release_dc_ptr( dc );
1554 /***********************************************************************
1555 * SetRelAbs (GDI32.@)
1557 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1562 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1564 SetLastError(ERROR_INVALID_PARAMETER);
1567 if ((dc = get_dc_ptr( hdc )))
1569 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1570 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1573 ret = dc->relAbsMode;
1574 dc->relAbsMode = mode;
1576 release_dc_ptr( dc );
1582 /***********************************************************************
1583 * GetPolyFillMode (GDI32.@)
1585 INT WINAPI GetPolyFillMode( HDC hdc )
1588 DC * dc = get_dc_ptr( hdc );
1591 ret = dc->polyFillMode;
1592 release_dc_ptr( dc );
1598 /***********************************************************************
1599 * SetPolyFillMode (GDI32.@)
1601 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1606 if ((mode <= 0) || (mode > POLYFILL_LAST))
1608 SetLastError(ERROR_INVALID_PARAMETER);
1611 if ((dc = get_dc_ptr( hdc )))
1613 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1614 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1617 ret = dc->polyFillMode;
1618 dc->polyFillMode = mode;
1620 release_dc_ptr( dc );
1626 /***********************************************************************
1627 * GetStretchBltMode (GDI32.@)
1629 INT WINAPI GetStretchBltMode( HDC hdc )
1632 DC * dc = get_dc_ptr( hdc );
1635 ret = dc->stretchBltMode;
1636 release_dc_ptr( dc );
1642 /***********************************************************************
1643 * SetStretchBltMode (GDI32.@)
1645 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1650 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1652 SetLastError(ERROR_INVALID_PARAMETER);
1655 if ((dc = get_dc_ptr( hdc )))
1657 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1658 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1661 ret = dc->stretchBltMode;
1662 dc->stretchBltMode = mode;
1664 release_dc_ptr( dc );
1670 /***********************************************************************
1671 * GetMapMode (GDI32.@)
1673 INT WINAPI GetMapMode( HDC hdc )
1676 DC * dc = get_dc_ptr( hdc );
1680 release_dc_ptr( dc );
1686 /***********************************************************************
1687 * GetBrushOrgEx (GDI32.@)
1689 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1691 DC * dc = get_dc_ptr( hdc );
1692 if (!dc) return FALSE;
1693 pt->x = dc->brushOrgX;
1694 pt->y = dc->brushOrgY;
1695 release_dc_ptr( dc );
1700 /***********************************************************************
1701 * GetCurrentPositionEx (GDI32.@)
1703 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1705 DC * dc = get_dc_ptr( hdc );
1706 if (!dc) return FALSE;
1707 pt->x = dc->CursPosX;
1708 pt->y = dc->CursPosY;
1709 release_dc_ptr( dc );
1714 /***********************************************************************
1715 * GetViewportExtEx (GDI32.@)
1717 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1719 DC * dc = get_dc_ptr( hdc );
1720 if (!dc) return FALSE;
1721 size->cx = dc->vportExtX;
1722 size->cy = dc->vportExtY;
1723 release_dc_ptr( dc );
1728 /***********************************************************************
1729 * GetViewportOrgEx (GDI32.@)
1731 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1733 DC * dc = get_dc_ptr( hdc );
1734 if (!dc) return FALSE;
1735 pt->x = dc->vportOrgX;
1736 pt->y = dc->vportOrgY;
1737 release_dc_ptr( dc );
1742 /***********************************************************************
1743 * GetWindowExtEx (GDI32.@)
1745 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1747 DC * dc = get_dc_ptr( hdc );
1748 if (!dc) return FALSE;
1749 size->cx = dc->wndExtX;
1750 size->cy = dc->wndExtY;
1751 release_dc_ptr( dc );
1756 /***********************************************************************
1757 * GetWindowOrgEx (GDI32.@)
1759 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1761 DC * dc = get_dc_ptr( hdc );
1762 if (!dc) return FALSE;
1763 pt->x = dc->wndOrgX;
1764 pt->y = dc->wndOrgY;
1765 release_dc_ptr( dc );
1770 /***********************************************************************
1771 * GetLayout (GDI32.@)
1773 * Gets left->right or right->left text layout flags of a dc.
1776 DWORD WINAPI GetLayout(HDC hdc)
1778 DWORD layout = GDI_ERROR;
1780 DC * dc = get_dc_ptr( hdc );
1783 layout = dc->layout;
1784 release_dc_ptr( dc );
1787 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1792 /***********************************************************************
1793 * SetLayout (GDI32.@)
1795 * Sets left->right or right->left text layout flags of a dc.
1798 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1800 DWORD oldlayout = GDI_ERROR;
1802 DC * dc = get_dc_ptr( hdc );
1805 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1806 layout = physdev->funcs->pSetLayout( physdev, layout );
1807 if (layout != GDI_ERROR)
1809 oldlayout = dc->layout;
1810 dc->layout = layout;
1811 if (layout != oldlayout)
1813 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1814 DC_UpdateXforms( dc );
1817 release_dc_ptr( dc );
1820 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1825 /***********************************************************************
1826 * GetDCBrushColor (GDI32.@)
1828 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1831 COLORREF dcBrushColor = CLR_INVALID;
1833 TRACE("hdc(%p)\n", hdc);
1835 dc = get_dc_ptr( hdc );
1838 dcBrushColor = dc->dcBrushColor;
1839 release_dc_ptr( dc );
1842 return dcBrushColor;
1845 /***********************************************************************
1846 * SetDCBrushColor (GDI32.@)
1848 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1851 COLORREF oldClr = CLR_INVALID;
1853 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1855 dc = get_dc_ptr( hdc );
1858 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCBrushColor );
1859 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1860 if (crColor != CLR_INVALID)
1862 oldClr = dc->dcBrushColor;
1863 dc->dcBrushColor = crColor;
1865 release_dc_ptr( dc );
1871 /***********************************************************************
1872 * GetDCPenColor (GDI32.@)
1874 COLORREF WINAPI GetDCPenColor(HDC hdc)
1877 COLORREF dcPenColor = CLR_INVALID;
1879 TRACE("hdc(%p)\n", hdc);
1881 dc = get_dc_ptr( hdc );
1884 dcPenColor = dc->dcPenColor;
1885 release_dc_ptr( dc );
1891 /***********************************************************************
1892 * SetDCPenColor (GDI32.@)
1894 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1897 COLORREF oldClr = CLR_INVALID;
1899 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1901 dc = get_dc_ptr( hdc );
1904 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1905 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1906 if (crColor != CLR_INVALID)
1908 oldClr = dc->dcPenColor;
1909 dc->dcPenColor = crColor;
1911 release_dc_ptr( dc );
1917 /***********************************************************************
1918 * CancelDC (GDI32.@)
1920 BOOL WINAPI CancelDC(HDC hdc)
1926 /*******************************************************************
1927 * GetMiterLimit [GDI32.@]
1931 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1936 TRACE("(%p,%p)\n", hdc, peLimit);
1938 dc = get_dc_ptr( hdc );
1942 *peLimit = dc->miterLimit;
1944 release_dc_ptr( dc );
1950 /*******************************************************************
1951 * SetMiterLimit [GDI32.@]
1955 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1960 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1962 dc = get_dc_ptr( hdc );
1966 *peOldLimit = dc->miterLimit;
1967 dc->miterLimit = eNewLimit;
1968 release_dc_ptr( dc );
1974 /*******************************************************************
1975 * GdiIsMetaPrintDC [GDI32.@]
1977 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
1983 /*******************************************************************
1984 * GdiIsMetaFileDC [GDI32.@]
1986 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
1990 switch( GetObjectType( hdc ) )
1999 /*******************************************************************
2000 * GdiIsPlayMetafileDC [GDI32.@]
2002 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)