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;
106 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
107 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
108 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
111 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
113 dc->font_code_page = CP_ACP;
114 dc->ROPmode = R2_COPYPEN;
115 dc->polyFillMode = ALTERNATE;
116 dc->stretchBltMode = BLACKONWHITE;
117 dc->relAbsMode = ABSOLUTE;
118 dc->backgroundMode = OPAQUE;
119 dc->backgroundColor = RGB( 255, 255, 255 );
120 dc->dcBrushColor = RGB( 255, 255, 255 );
121 dc->dcPenColor = RGB( 0, 0, 0 );
122 dc->textColor = RGB( 0, 0, 0 );
126 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
130 dc->MapMode = MM_TEXT;
131 dc->GraphicsMode = GM_COMPATIBLE;
132 dc->pAbortProc = NULL;
135 dc->ArcDirection = AD_COUNTERCLOCKWISE;
136 dc->xformWorld2Wnd.eM11 = 1.0f;
137 dc->xformWorld2Wnd.eM12 = 0.0f;
138 dc->xformWorld2Wnd.eM21 = 0.0f;
139 dc->xformWorld2Wnd.eM22 = 1.0f;
140 dc->xformWorld2Wnd.eDx = 0.0f;
141 dc->xformWorld2Wnd.eDy = 0.0f;
142 dc->xformWorld2Vport = dc->xformWorld2Wnd;
143 dc->xformVport2World = dc->xformWorld2Wnd;
144 dc->vport2WorldValid = TRUE;
145 dc->BoundsRect.left = 0;
146 dc->BoundsRect.top = 0;
147 dc->BoundsRect.right = 0;
148 dc->BoundsRect.bottom = 0;
149 PATH_InitGdiPath(&dc->path);
151 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
153 HeapFree( GetProcessHeap(), 0, dc );
156 dc->nulldrv.hdc = dc->hSelf;
158 if (font_driver && !font_driver->pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL ))
168 /***********************************************************************
171 static void free_dc_state( DC *dc )
173 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
174 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
175 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
176 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
177 PATH_DestroyGdiPath( &dc->path );
178 HeapFree( GetProcessHeap(), 0, dc );
182 /***********************************************************************
185 void free_dc_ptr( DC *dc )
187 assert( dc->refcount == 1 );
189 while (dc->physDev != &dc->nulldrv)
191 PHYSDEV physdev = pop_dc_driver( &dc->physDev );
192 physdev->funcs->pDeleteDC( physdev );
193 if (physdev == dc->dibdrv) dc->dibdrv = NULL;
195 if (dc->dibdrv) dc->dibdrv->funcs->pDeleteDC( dc->dibdrv );
196 free_gdi_handle( dc->hSelf );
201 /***********************************************************************
204 * Retrieve a DC pointer but release the GDI lock.
206 DC *get_dc_ptr( HDC hdc )
208 DC *dc = get_dc_obj( hdc );
209 if (!dc) return NULL;
211 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
213 dc->thread = GetCurrentThreadId();
215 else if (dc->thread != GetCurrentThreadId())
217 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
218 GDI_ReleaseObj( hdc );
221 else InterlockedIncrement( &dc->refcount );
223 GDI_ReleaseObj( hdc );
228 /***********************************************************************
231 void release_dc_ptr( DC *dc )
236 ref = InterlockedDecrement( &dc->refcount );
238 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
242 /***********************************************************************
245 * Make sure the DC vis region is up to date.
246 * This function may call up to USER so the GDI lock should _not_
247 * be held when calling it.
249 void update_dc( DC *dc )
251 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
252 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
256 /***********************************************************************
259 static BOOL DC_DeleteObject( HGDIOBJ handle )
261 return DeleteDC( handle );
265 /***********************************************************************
268 * Setup device-specific DC values for a newly created DC.
270 void DC_InitDC( DC* dc )
272 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
273 physdev->funcs->pRealizeDefaultPalette( physdev );
274 SetTextColor( dc->hSelf, dc->textColor );
275 SetBkColor( dc->hSelf, dc->backgroundColor );
276 SelectObject( dc->hSelf, dc->hPen );
277 SelectObject( dc->hSelf, dc->hBrush );
278 SelectObject( dc->hSelf, dc->hFont );
279 CLIPPING_UpdateGCRegion( dc );
280 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
284 /***********************************************************************
287 * Computes the inverse of the transformation xformSrc and stores it to
288 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
291 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
295 determinant = xformSrc->eM11*xformSrc->eM22 -
296 xformSrc->eM12*xformSrc->eM21;
297 if (determinant > -1e-12 && determinant < 1e-12)
300 xformDest->eM11 = xformSrc->eM22 / determinant;
301 xformDest->eM12 = -xformSrc->eM12 / determinant;
302 xformDest->eM21 = -xformSrc->eM21 / determinant;
303 xformDest->eM22 = xformSrc->eM11 / determinant;
304 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
305 xformSrc->eDy * xformDest->eM21;
306 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
307 xformSrc->eDy * xformDest->eM22;
312 /* Construct a transformation to do the window-to-viewport conversion */
313 static void construct_window_to_viewport(DC *dc, XFORM *xform)
315 double scaleX, scaleY;
316 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
317 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
319 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
320 xform->eM11 = scaleX;
323 xform->eM22 = scaleY;
324 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
325 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
326 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
329 /***********************************************************************
332 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
333 * fields of the specified DC by creating a transformation that
334 * represents the current mapping mode and combining it with the DC's
335 * world transform. This function should be called whenever the
336 * parameters associated with the mapping mode (window and viewport
337 * extents and origins) or the world transform change.
339 void DC_UpdateXforms( DC *dc )
341 XFORM xformWnd2Vport, oldworld2vport;
343 construct_window_to_viewport(dc, &xformWnd2Vport);
345 oldworld2vport = dc->xformWorld2Vport;
346 /* Combine with the world transformation */
347 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
350 /* Create inverse of world-to-viewport transformation */
351 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
352 &dc->xformVport2World );
354 /* Reselect the font and pen back into the dc so that the size
356 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
357 !GdiIsMetaFileDC(dc->hSelf))
359 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
360 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
365 /***********************************************************************
368 INT nulldrv_SaveDC( PHYSDEV dev )
370 DC *newdc, *dc = get_nulldrv_dc( dev );
372 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc )))) return 0;
373 newdc->flags = dc->flags;
374 newdc->layout = dc->layout;
375 newdc->hPen = dc->hPen;
376 newdc->hBrush = dc->hBrush;
377 newdc->hFont = dc->hFont;
378 newdc->hBitmap = dc->hBitmap;
379 newdc->hDevice = dc->hDevice;
380 newdc->hPalette = dc->hPalette;
381 newdc->ROPmode = dc->ROPmode;
382 newdc->polyFillMode = dc->polyFillMode;
383 newdc->stretchBltMode = dc->stretchBltMode;
384 newdc->relAbsMode = dc->relAbsMode;
385 newdc->backgroundMode = dc->backgroundMode;
386 newdc->backgroundColor = dc->backgroundColor;
387 newdc->textColor = dc->textColor;
388 newdc->dcBrushColor = dc->dcBrushColor;
389 newdc->dcPenColor = dc->dcPenColor;
390 newdc->brushOrgX = dc->brushOrgX;
391 newdc->brushOrgY = dc->brushOrgY;
392 newdc->mapperFlags = dc->mapperFlags;
393 newdc->textAlign = dc->textAlign;
394 newdc->charExtra = dc->charExtra;
395 newdc->breakExtra = dc->breakExtra;
396 newdc->breakRem = dc->breakRem;
397 newdc->MapMode = dc->MapMode;
398 newdc->GraphicsMode = dc->GraphicsMode;
399 newdc->CursPosX = dc->CursPosX;
400 newdc->CursPosY = dc->CursPosY;
401 newdc->ArcDirection = dc->ArcDirection;
402 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
403 newdc->xformWorld2Vport = dc->xformWorld2Vport;
404 newdc->xformVport2World = dc->xformVport2World;
405 newdc->vport2WorldValid = dc->vport2WorldValid;
406 newdc->wndOrgX = dc->wndOrgX;
407 newdc->wndOrgY = dc->wndOrgY;
408 newdc->wndExtX = dc->wndExtX;
409 newdc->wndExtY = dc->wndExtY;
410 newdc->vportOrgX = dc->vportOrgX;
411 newdc->vportOrgY = dc->vportOrgY;
412 newdc->vportExtX = dc->vportExtX;
413 newdc->vportExtY = dc->vportExtY;
414 newdc->virtual_res = dc->virtual_res;
415 newdc->virtual_size = dc->virtual_size;
416 newdc->BoundsRect = dc->BoundsRect;
417 newdc->gdiFont = dc->gdiFont;
419 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
424 newdc->hMetaClipRgn = 0;
427 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
432 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
433 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
436 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
438 if (!PATH_SavePath( newdc, dc ))
440 release_dc_ptr( dc );
441 free_dc_state( newdc );
445 newdc->saved_dc = dc->saved_dc;
446 dc->saved_dc = newdc;
447 return ++dc->saveLevel;
451 /***********************************************************************
454 BOOL nulldrv_RestoreDC( PHYSDEV dev, INT level )
456 DC *dcs, *first_dcs, *dc = get_nulldrv_dc( dev );
459 /* find the state level to restore */
461 if (abs(level) > dc->saveLevel || level == 0) return FALSE;
462 if (level < 0) level = dc->saveLevel + level + 1;
463 first_dcs = dc->saved_dc;
464 for (dcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
467 /* restore the state */
469 if (!PATH_RestorePath( dc, dcs )) return FALSE;
471 dc->flags = dcs->flags;
472 dc->layout = dcs->layout;
473 dc->hDevice = dcs->hDevice;
474 dc->ROPmode = dcs->ROPmode;
475 dc->polyFillMode = dcs->polyFillMode;
476 dc->stretchBltMode = dcs->stretchBltMode;
477 dc->relAbsMode = dcs->relAbsMode;
478 dc->backgroundMode = dcs->backgroundMode;
479 dc->backgroundColor = dcs->backgroundColor;
480 dc->textColor = dcs->textColor;
481 dc->dcBrushColor = dcs->dcBrushColor;
482 dc->dcPenColor = dcs->dcPenColor;
483 dc->brushOrgX = dcs->brushOrgX;
484 dc->brushOrgY = dcs->brushOrgY;
485 dc->mapperFlags = dcs->mapperFlags;
486 dc->textAlign = dcs->textAlign;
487 dc->charExtra = dcs->charExtra;
488 dc->breakExtra = dcs->breakExtra;
489 dc->breakRem = dcs->breakRem;
490 dc->MapMode = dcs->MapMode;
491 dc->GraphicsMode = dcs->GraphicsMode;
492 dc->CursPosX = dcs->CursPosX;
493 dc->CursPosY = dcs->CursPosY;
494 dc->ArcDirection = dcs->ArcDirection;
495 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
496 dc->xformWorld2Vport = dcs->xformWorld2Vport;
497 dc->xformVport2World = dcs->xformVport2World;
498 dc->vport2WorldValid = dcs->vport2WorldValid;
499 dc->BoundsRect = dcs->BoundsRect;
501 dc->wndOrgX = dcs->wndOrgX;
502 dc->wndOrgY = dcs->wndOrgY;
503 dc->wndExtX = dcs->wndExtX;
504 dc->wndExtY = dcs->wndExtY;
505 dc->vportOrgX = dcs->vportOrgX;
506 dc->vportOrgY = dcs->vportOrgY;
507 dc->vportExtX = dcs->vportExtX;
508 dc->vportExtY = dcs->vportExtY;
509 dc->virtual_res = dcs->virtual_res;
510 dc->virtual_size = dcs->virtual_size;
514 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
515 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
519 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
524 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
525 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
529 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
532 DC_UpdateXforms( dc );
533 CLIPPING_UpdateGCRegion( dc );
535 SelectObject( dev->hdc, dcs->hBitmap );
536 SelectObject( dev->hdc, dcs->hBrush );
537 SelectObject( dev->hdc, dcs->hFont );
538 SelectObject( dev->hdc, dcs->hPen );
539 SetBkColor( dev->hdc, dcs->backgroundColor);
540 SetTextColor( dev->hdc, dcs->textColor);
541 GDISelectPalette( dev->hdc, dcs->hPalette, FALSE );
543 dc->saved_dc = dcs->saved_dc;
545 dc->saveLevel = save_level - 1;
547 /* now destroy all the saved DCs */
551 DC *next = first_dcs->saved_dc;
552 free_dc_state( first_dcs );
559 /***********************************************************************
562 INT WINAPI SaveDC( HDC hdc )
567 if ((dc = get_dc_ptr( hdc )))
569 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSaveDC );
570 ret = physdev->funcs->pSaveDC( physdev );
571 release_dc_ptr( dc );
577 /***********************************************************************
578 * RestoreDC (GDI32.@)
580 BOOL WINAPI RestoreDC( HDC hdc, INT level )
583 BOOL success = FALSE;
585 TRACE("%p %d\n", hdc, level );
586 if ((dc = get_dc_ptr( hdc )))
588 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRestoreDC );
590 success = physdev->funcs->pRestoreDC( physdev, level );
591 release_dc_ptr( dc );
597 /***********************************************************************
598 * CreateDCW (GDI32.@)
600 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
601 const DEVMODEW *initData )
605 const struct gdi_dc_funcs *funcs;
610 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
614 ERR( "no device found for %s\n", debugstr_w(device) );
617 strcpyW(buf, driver);
620 if (!(funcs = DRIVER_load_driver( buf )))
622 ERR( "no driver found for %s\n", debugstr_w(buf) );
625 if (!(dc = alloc_dc_ptr( OBJ_DC ))) goto error;
628 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
629 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
631 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
632 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
634 if (funcs->pCreateDC)
636 if (!funcs->pCreateDC( &dc->physDev, buf, device, output, initData ))
638 WARN("creation aborted by device\n" );
643 dc->vis_rect.left = 0;
644 dc->vis_rect.top = 0;
645 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
646 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
647 SetRectRgn(dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top, dc->vis_rect.right, dc->vis_rect.bottom);
650 release_dc_ptr( dc );
654 if (dc) free_dc_ptr( dc );
659 /***********************************************************************
660 * CreateDCA (GDI32.@)
662 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
663 const DEVMODEA *initData )
665 UNICODE_STRING driverW, deviceW, outputW;
669 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
670 else driverW.Buffer = NULL;
672 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
673 else deviceW.Buffer = NULL;
675 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
676 else outputW.Buffer = NULL;
681 /* don't convert initData for DISPLAY driver, it's not used */
682 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
683 initDataW = GdiConvertToDevmodeW(initData);
686 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
688 RtlFreeUnicodeString(&driverW);
689 RtlFreeUnicodeString(&deviceW);
690 RtlFreeUnicodeString(&outputW);
691 HeapFree(GetProcessHeap(), 0, initDataW);
696 /***********************************************************************
697 * CreateICA (GDI32.@)
699 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
700 const DEVMODEA* initData )
702 /* Nothing special yet for ICs */
703 return CreateDCA( driver, device, output, initData );
707 /***********************************************************************
708 * CreateICW (GDI32.@)
710 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
711 const DEVMODEW* initData )
713 /* Nothing special yet for ICs */
714 return CreateDCW( driver, device, output, initData );
718 /***********************************************************************
719 * CreateCompatibleDC (GDI32.@)
721 HDC WINAPI CreateCompatibleDC( HDC hdc )
725 const struct gdi_dc_funcs *funcs = &null_driver;
726 PHYSDEV physDev = NULL;
732 if (!(origDC = get_dc_ptr( hdc ))) return 0;
733 physDev = GET_DC_PHYSDEV( origDC, pCreateCompatibleDC );
734 funcs = physDev->funcs;
735 release_dc_ptr( origDC );
738 if (!(dc = alloc_dc_ptr( OBJ_MEMDC ))) goto error;
740 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
742 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
743 dc->vis_rect.left = 0;
744 dc->vis_rect.top = 0;
745 dc->vis_rect.right = 1;
746 dc->vis_rect.bottom = 1;
747 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
751 if (!funcs->pCreateCompatibleDC( physDev, &dc->physDev ))
753 WARN("creation aborted by device\n");
757 release_dc_ptr( dc );
761 if (dc) free_dc_ptr( dc );
766 /***********************************************************************
769 BOOL WINAPI DeleteDC( HDC hdc )
777 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
778 if (dc->refcount != 1)
780 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
781 release_dc_ptr( dc );
785 /* Call hook procedure to check whether is it OK to delete this DC */
786 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
788 release_dc_ptr( dc );
792 while (dc->saveLevel)
794 DC *dcs = dc->saved_dc;
795 dc->saved_dc = dcs->saved_dc;
797 free_dc_state( dcs );
801 SelectObject( hdc, GetStockObject(BLACK_PEN) );
802 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
803 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
804 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
811 /***********************************************************************
814 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
819 if ((dc = get_dc_ptr( hdc )))
821 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
822 ret = physdev->funcs->pResetDC( physdev, devmode );
823 if (ret) /* reset the visible region */
826 dc->vis_rect.left = 0;
827 dc->vis_rect.top = 0;
828 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
829 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
830 SetRectRgn( dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top,
831 dc->vis_rect.right, dc->vis_rect.bottom );
832 CLIPPING_UpdateGCRegion( dc );
834 release_dc_ptr( dc );
840 /***********************************************************************
843 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
848 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
849 else devmodeW = NULL;
851 ret = ResetDCW(hdc, devmodeW);
853 HeapFree(GetProcessHeap(), 0, devmodeW);
858 /***********************************************************************
859 * GetDeviceCaps (GDI32.@)
861 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
866 if ((dc = get_dc_ptr( hdc )))
868 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
869 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
870 release_dc_ptr( dc );
876 /***********************************************************************
877 * GetBkColor (GDI32.@)
879 COLORREF WINAPI GetBkColor( HDC hdc )
882 DC * dc = get_dc_ptr( hdc );
885 ret = dc->backgroundColor;
886 release_dc_ptr( dc );
892 /***********************************************************************
893 * SetBkColor (GDI32.@)
895 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
897 COLORREF ret = CLR_INVALID;
898 DC * dc = get_dc_ptr( hdc );
900 TRACE("hdc=%p color=0x%08x\n", hdc, color);
904 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
905 color = physdev->funcs->pSetBkColor( physdev, color );
906 if (color != CLR_INVALID)
908 ret = dc->backgroundColor;
909 dc->backgroundColor = color;
911 release_dc_ptr( dc );
917 /***********************************************************************
918 * GetTextColor (GDI32.@)
920 COLORREF WINAPI GetTextColor( HDC hdc )
923 DC * dc = get_dc_ptr( hdc );
927 release_dc_ptr( dc );
933 /***********************************************************************
934 * SetTextColor (GDI32.@)
936 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
938 COLORREF ret = CLR_INVALID;
939 DC * dc = get_dc_ptr( hdc );
941 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
945 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
946 color = physdev->funcs->pSetTextColor( physdev, color );
947 if (color != CLR_INVALID)
950 dc->textColor = color;
952 release_dc_ptr( dc );
958 /***********************************************************************
959 * GetTextAlign (GDI32.@)
961 UINT WINAPI GetTextAlign( HDC hdc )
964 DC * dc = get_dc_ptr( hdc );
968 release_dc_ptr( dc );
974 /***********************************************************************
975 * SetTextAlign (GDI32.@)
977 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
979 UINT ret = GDI_ERROR;
980 DC *dc = get_dc_ptr( hdc );
982 TRACE("hdc=%p align=%d\n", hdc, align);
986 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
987 align = physdev->funcs->pSetTextAlign( physdev, align );
988 if (align != GDI_ERROR)
991 dc->textAlign = align;
993 release_dc_ptr( dc );
998 /***********************************************************************
999 * GetDCOrgEx (GDI32.@)
1001 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1005 if (!lpp) return FALSE;
1006 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1007 lpp->x = dc->vis_rect.left;
1008 lpp->y = dc->vis_rect.top;
1009 release_dc_ptr( dc );
1014 /***********************************************************************
1015 * GetGraphicsMode (GDI32.@)
1017 INT WINAPI GetGraphicsMode( HDC hdc )
1020 DC * dc = get_dc_ptr( hdc );
1023 ret = dc->GraphicsMode;
1024 release_dc_ptr( dc );
1030 /***********************************************************************
1031 * SetGraphicsMode (GDI32.@)
1033 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1036 DC *dc = get_dc_ptr( hdc );
1038 /* One would think that setting the graphics mode to GM_COMPATIBLE
1039 * would also reset the world transformation matrix to the unity
1040 * matrix. However, in Windows, this is not the case. This doesn't
1041 * make a lot of sense to me, but that's the way it is.
1044 if ((mode > 0) && (mode <= GM_LAST))
1046 ret = dc->GraphicsMode;
1047 dc->GraphicsMode = mode;
1049 release_dc_ptr( dc );
1054 /***********************************************************************
1055 * GetArcDirection (GDI32.@)
1057 INT WINAPI GetArcDirection( HDC hdc )
1060 DC * dc = get_dc_ptr( hdc );
1063 ret = dc->ArcDirection;
1064 release_dc_ptr( dc );
1070 /***********************************************************************
1071 * SetArcDirection (GDI32.@)
1073 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1078 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1080 SetLastError(ERROR_INVALID_PARAMETER);
1084 if ((dc = get_dc_ptr( hdc )))
1086 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1087 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1090 ret = dc->ArcDirection;
1091 dc->ArcDirection = dir;
1093 release_dc_ptr( dc );
1099 /***********************************************************************
1100 * GetWorldTransform (GDI32.@)
1102 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1105 if (!xform) return FALSE;
1106 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1107 *xform = dc->xformWorld2Wnd;
1108 release_dc_ptr( dc );
1113 /***********************************************************************
1114 * GetTransform (GDI32.@)
1118 * Returns one of the co-ordinate space transforms
1121 * hdc [I] Device context.
1122 * which [I] Which xform to return:
1123 * 0x203 World -> Page transform (that set by SetWorldTransform).
1124 * 0x304 Page -> Device transform (the mapping mode transform).
1125 * 0x204 World -> Device transform (the combination of the above two).
1126 * 0x402 Device -> World transform (the inversion of the above).
1127 * xform [O] The xform.
1130 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1133 DC *dc = get_dc_ptr( hdc );
1134 if (!dc) return FALSE;
1139 *xform = dc->xformWorld2Wnd;
1143 construct_window_to_viewport(dc, xform);
1147 *xform = dc->xformWorld2Vport;
1151 *xform = dc->xformVport2World;
1155 FIXME("Unknown code %x\n", which);
1159 release_dc_ptr( dc );
1164 /****************************************************************************
1165 * CombineTransform [GDI32.@]
1166 * Combines two transformation matrices.
1169 * xformResult [O] Stores the result of combining the two matrices
1170 * xform1 [I] Specifies the first matrix to apply
1171 * xform2 [I] Specifies the second matrix to apply
1174 * The same matrix can be passed in for more than one of the parameters.
1178 * Failure: FALSE. Use GetLastError() to determine the cause.
1180 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1181 const XFORM *xform2 )
1185 /* Check for illegal parameters */
1186 if (!xformResult || !xform1 || !xform2)
1189 /* Create the result in a temporary XFORM, since xformResult may be
1190 * equal to xform1 or xform2 */
1191 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1192 xform1->eM12 * xform2->eM21;
1193 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1194 xform1->eM12 * xform2->eM22;
1195 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1196 xform1->eM22 * xform2->eM21;
1197 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1198 xform1->eM22 * xform2->eM22;
1199 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1200 xform1->eDy * xform2->eM21 +
1202 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1203 xform1->eDy * xform2->eM22 +
1206 /* Copy the result to xformResult */
1207 *xformResult = xformTemp;
1213 /***********************************************************************
1214 * SetDCHook (GDI32.@)
1216 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1218 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1220 DC *dc = get_dc_ptr( hdc );
1222 if (!dc) return FALSE;
1224 dc->dwHookData = dwHookData;
1225 dc->hookProc = hookProc;
1226 release_dc_ptr( dc );
1231 /***********************************************************************
1232 * GetDCHook (GDI32.@)
1234 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1236 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1238 DC *dc = get_dc_ptr( hdc );
1242 if (proc) *proc = dc->hookProc;
1243 ret = dc->dwHookData;
1244 release_dc_ptr( dc );
1249 /***********************************************************************
1250 * SetHookFlags (GDI32.@)
1252 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1254 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1256 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1261 /* "Undocumented Windows" info is slightly confusing. */
1263 TRACE("hDC %p, flags %04x\n",hdc,flags);
1265 if (flags & DCHF_INVALIDATEVISRGN)
1266 ret = InterlockedExchange( &dc->dirty, 1 );
1267 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1268 ret = InterlockedExchange( &dc->dirty, 0 );
1270 GDI_ReleaseObj( hdc );
1274 /***********************************************************************
1275 * SetICMMode (GDI32.@)
1277 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1279 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1280 if (iEnableICM == ICM_OFF) return ICM_OFF;
1281 if (iEnableICM == ICM_ON) return 0;
1282 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1286 /***********************************************************************
1287 * GetDeviceGammaRamp (GDI32.@)
1289 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1292 DC *dc = get_dc_ptr( hDC );
1294 TRACE("%p, %p\n", hDC, ptr);
1297 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1298 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1299 release_dc_ptr( dc );
1304 /***********************************************************************
1305 * SetDeviceGammaRamp (GDI32.@)
1307 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1310 DC *dc = get_dc_ptr( hDC );
1312 TRACE("%p, %p\n", hDC, ptr);
1315 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1316 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1317 release_dc_ptr( dc );
1322 /***********************************************************************
1323 * GetColorSpace (GDI32.@)
1325 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1327 /*FIXME Need to do whatever GetColorSpace actually does */
1331 /***********************************************************************
1332 * CreateColorSpaceA (GDI32.@)
1334 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1340 /***********************************************************************
1341 * CreateColorSpaceW (GDI32.@)
1343 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1349 /***********************************************************************
1350 * DeleteColorSpace (GDI32.@)
1352 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1359 /***********************************************************************
1360 * SetColorSpace (GDI32.@)
1362 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1369 /***********************************************************************
1370 * GetBoundsRect (GDI32.@)
1372 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1375 DC *dc = get_dc_ptr( hdc );
1377 if ( !dc ) return 0;
1381 *rect = dc->BoundsRect;
1382 ret = is_rect_empty( rect ) ? DCB_RESET : DCB_SET;
1383 DPtoLP( hdc, (POINT *)rect, 2 );
1385 if (flags & DCB_RESET)
1387 dc->BoundsRect.left = 0;
1388 dc->BoundsRect.top = 0;
1389 dc->BoundsRect.right = 0;
1390 dc->BoundsRect.bottom = 0;
1392 release_dc_ptr( dc );
1397 /***********************************************************************
1398 * SetBoundsRect (GDI32.@)
1400 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1405 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1406 if (!(dc = get_dc_ptr( hdc ))) return 0;
1408 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1409 (is_rect_empty( &dc->BoundsRect ) ? DCB_RESET : DCB_SET);
1411 if (flags & DCB_RESET)
1413 dc->BoundsRect.left = 0;
1414 dc->BoundsRect.top = 0;
1415 dc->BoundsRect.right = 0;
1416 dc->BoundsRect.bottom = 0;
1419 if ((flags & DCB_ACCUMULATE) && rect)
1423 LPtoDP( hdc, (POINT *)&rc, 2 );
1424 if (!is_rect_empty( &rc ))
1426 if (!is_rect_empty( &dc->BoundsRect))
1428 dc->BoundsRect.left = min( dc->BoundsRect.left, rc.left );
1429 dc->BoundsRect.top = min( dc->BoundsRect.top, rc.top );
1430 dc->BoundsRect.right = max( dc->BoundsRect.right, rc.right );
1431 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rc.bottom );
1433 else dc->BoundsRect = rc;
1437 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1438 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1440 release_dc_ptr( dc );
1445 /***********************************************************************
1446 * GetRelAbs (GDI32.@)
1448 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1451 DC *dc = get_dc_ptr( hdc );
1454 ret = dc->relAbsMode;
1455 release_dc_ptr( dc );
1463 /***********************************************************************
1464 * GetBkMode (GDI32.@)
1466 INT WINAPI GetBkMode( HDC hdc )
1469 DC * dc = get_dc_ptr( hdc );
1472 ret = dc->backgroundMode;
1473 release_dc_ptr( dc );
1479 /***********************************************************************
1480 * SetBkMode (GDI32.@)
1482 INT WINAPI SetBkMode( HDC hdc, INT mode )
1487 if ((mode <= 0) || (mode > BKMODE_LAST))
1489 SetLastError(ERROR_INVALID_PARAMETER);
1492 if ((dc = get_dc_ptr( hdc )))
1494 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1495 mode = physdev->funcs->pSetBkMode( physdev, mode );
1498 ret = dc->backgroundMode;
1499 dc->backgroundMode = mode;
1501 release_dc_ptr( dc );
1507 /***********************************************************************
1510 INT WINAPI GetROP2( HDC hdc )
1513 DC * dc = get_dc_ptr( hdc );
1517 release_dc_ptr( dc );
1523 /***********************************************************************
1526 INT WINAPI SetROP2( HDC hdc, INT mode )
1531 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1533 SetLastError(ERROR_INVALID_PARAMETER);
1536 if ((dc = get_dc_ptr( hdc )))
1538 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1539 mode = physdev->funcs->pSetROP2( physdev, mode );
1545 release_dc_ptr( dc );
1551 /***********************************************************************
1552 * SetRelAbs (GDI32.@)
1554 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1559 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1561 SetLastError(ERROR_INVALID_PARAMETER);
1564 if ((dc = get_dc_ptr( hdc )))
1566 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1567 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1570 ret = dc->relAbsMode;
1571 dc->relAbsMode = mode;
1573 release_dc_ptr( dc );
1579 /***********************************************************************
1580 * GetPolyFillMode (GDI32.@)
1582 INT WINAPI GetPolyFillMode( HDC hdc )
1585 DC * dc = get_dc_ptr( hdc );
1588 ret = dc->polyFillMode;
1589 release_dc_ptr( dc );
1595 /***********************************************************************
1596 * SetPolyFillMode (GDI32.@)
1598 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1603 if ((mode <= 0) || (mode > POLYFILL_LAST))
1605 SetLastError(ERROR_INVALID_PARAMETER);
1608 if ((dc = get_dc_ptr( hdc )))
1610 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1611 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1614 ret = dc->polyFillMode;
1615 dc->polyFillMode = mode;
1617 release_dc_ptr( dc );
1623 /***********************************************************************
1624 * GetStretchBltMode (GDI32.@)
1626 INT WINAPI GetStretchBltMode( HDC hdc )
1629 DC * dc = get_dc_ptr( hdc );
1632 ret = dc->stretchBltMode;
1633 release_dc_ptr( dc );
1639 /***********************************************************************
1640 * SetStretchBltMode (GDI32.@)
1642 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1647 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1649 SetLastError(ERROR_INVALID_PARAMETER);
1652 if ((dc = get_dc_ptr( hdc )))
1654 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1655 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1658 ret = dc->stretchBltMode;
1659 dc->stretchBltMode = mode;
1661 release_dc_ptr( dc );
1667 /***********************************************************************
1668 * GetMapMode (GDI32.@)
1670 INT WINAPI GetMapMode( HDC hdc )
1673 DC * dc = get_dc_ptr( hdc );
1677 release_dc_ptr( dc );
1683 /***********************************************************************
1684 * GetBrushOrgEx (GDI32.@)
1686 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1688 DC * dc = get_dc_ptr( hdc );
1689 if (!dc) return FALSE;
1690 pt->x = dc->brushOrgX;
1691 pt->y = dc->brushOrgY;
1692 release_dc_ptr( dc );
1697 /***********************************************************************
1698 * GetCurrentPositionEx (GDI32.@)
1700 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1702 DC * dc = get_dc_ptr( hdc );
1703 if (!dc) return FALSE;
1704 pt->x = dc->CursPosX;
1705 pt->y = dc->CursPosY;
1706 release_dc_ptr( dc );
1711 /***********************************************************************
1712 * GetViewportExtEx (GDI32.@)
1714 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1716 DC * dc = get_dc_ptr( hdc );
1717 if (!dc) return FALSE;
1718 size->cx = dc->vportExtX;
1719 size->cy = dc->vportExtY;
1720 release_dc_ptr( dc );
1725 /***********************************************************************
1726 * GetViewportOrgEx (GDI32.@)
1728 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1730 DC * dc = get_dc_ptr( hdc );
1731 if (!dc) return FALSE;
1732 pt->x = dc->vportOrgX;
1733 pt->y = dc->vportOrgY;
1734 release_dc_ptr( dc );
1739 /***********************************************************************
1740 * GetWindowExtEx (GDI32.@)
1742 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1744 DC * dc = get_dc_ptr( hdc );
1745 if (!dc) return FALSE;
1746 size->cx = dc->wndExtX;
1747 size->cy = dc->wndExtY;
1748 release_dc_ptr( dc );
1753 /***********************************************************************
1754 * GetWindowOrgEx (GDI32.@)
1756 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1758 DC * dc = get_dc_ptr( hdc );
1759 if (!dc) return FALSE;
1760 pt->x = dc->wndOrgX;
1761 pt->y = dc->wndOrgY;
1762 release_dc_ptr( dc );
1767 /***********************************************************************
1768 * GetLayout (GDI32.@)
1770 * Gets left->right or right->left text layout flags of a dc.
1773 DWORD WINAPI GetLayout(HDC hdc)
1775 DWORD layout = GDI_ERROR;
1777 DC * dc = get_dc_ptr( hdc );
1780 layout = dc->layout;
1781 release_dc_ptr( dc );
1784 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1789 /***********************************************************************
1790 * SetLayout (GDI32.@)
1792 * Sets left->right or right->left text layout flags of a dc.
1795 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1797 DWORD oldlayout = GDI_ERROR;
1799 DC * dc = get_dc_ptr( hdc );
1802 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1803 layout = physdev->funcs->pSetLayout( physdev, layout );
1804 if (layout != GDI_ERROR)
1806 oldlayout = dc->layout;
1807 dc->layout = layout;
1808 if (layout != oldlayout)
1810 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1811 DC_UpdateXforms( dc );
1814 release_dc_ptr( dc );
1817 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1822 /***********************************************************************
1823 * GetDCBrushColor (GDI32.@)
1825 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1828 COLORREF dcBrushColor = CLR_INVALID;
1830 TRACE("hdc(%p)\n", hdc);
1832 dc = get_dc_ptr( hdc );
1835 dcBrushColor = dc->dcBrushColor;
1836 release_dc_ptr( dc );
1839 return dcBrushColor;
1842 /***********************************************************************
1843 * SetDCBrushColor (GDI32.@)
1845 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1848 COLORREF oldClr = CLR_INVALID;
1850 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1852 dc = get_dc_ptr( hdc );
1855 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCBrushColor );
1856 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1857 if (crColor != CLR_INVALID)
1859 oldClr = dc->dcBrushColor;
1860 dc->dcBrushColor = crColor;
1862 release_dc_ptr( dc );
1868 /***********************************************************************
1869 * GetDCPenColor (GDI32.@)
1871 COLORREF WINAPI GetDCPenColor(HDC hdc)
1874 COLORREF dcPenColor = CLR_INVALID;
1876 TRACE("hdc(%p)\n", hdc);
1878 dc = get_dc_ptr( hdc );
1881 dcPenColor = dc->dcPenColor;
1882 release_dc_ptr( dc );
1888 /***********************************************************************
1889 * SetDCPenColor (GDI32.@)
1891 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1894 COLORREF oldClr = CLR_INVALID;
1896 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1898 dc = get_dc_ptr( hdc );
1901 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1902 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1903 if (crColor != CLR_INVALID)
1905 oldClr = dc->dcPenColor;
1906 dc->dcPenColor = crColor;
1908 release_dc_ptr( dc );
1914 /***********************************************************************
1915 * CancelDC (GDI32.@)
1917 BOOL WINAPI CancelDC(HDC hdc)
1923 /*******************************************************************
1924 * GetMiterLimit [GDI32.@]
1928 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1933 TRACE("(%p,%p)\n", hdc, peLimit);
1935 dc = get_dc_ptr( hdc );
1939 *peLimit = dc->miterLimit;
1941 release_dc_ptr( dc );
1947 /*******************************************************************
1948 * SetMiterLimit [GDI32.@]
1952 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1957 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1959 dc = get_dc_ptr( hdc );
1963 *peOldLimit = dc->miterLimit;
1964 dc->miterLimit = eNewLimit;
1965 release_dc_ptr( dc );
1971 /*******************************************************************
1972 * GdiIsMetaPrintDC [GDI32.@]
1974 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
1980 /*******************************************************************
1981 * GdiIsMetaFileDC [GDI32.@]
1983 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
1987 switch( GetObjectType( hdc ) )
1996 /*******************************************************************
1997 * GdiIsPlayMetafileDC [GDI32.@]
1999 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)