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;
162 /***********************************************************************
165 static void free_dc_state( DC *dc )
167 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
168 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
169 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
170 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
171 PATH_DestroyGdiPath( &dc->path );
172 HeapFree( GetProcessHeap(), 0, dc );
176 /***********************************************************************
179 void free_dc_ptr( DC *dc )
181 assert( dc->refcount == 1 );
183 while (dc->physDev != &dc->nulldrv)
185 PHYSDEV physdev = pop_dc_driver( &dc->physDev );
186 physdev->funcs->pDeleteDC( physdev );
187 if (physdev == dc->dibdrv) dc->dibdrv = NULL;
189 if (dc->dibdrv) dc->dibdrv->funcs->pDeleteDC( dc->dibdrv );
190 free_gdi_handle( dc->hSelf );
195 /***********************************************************************
198 * Retrieve a DC pointer but release the GDI lock.
200 DC *get_dc_ptr( HDC hdc )
202 DC *dc = get_dc_obj( hdc );
203 if (!dc) return NULL;
205 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
207 dc->thread = GetCurrentThreadId();
209 else if (dc->thread != GetCurrentThreadId())
211 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
212 GDI_ReleaseObj( hdc );
215 else InterlockedIncrement( &dc->refcount );
217 GDI_ReleaseObj( hdc );
222 /***********************************************************************
225 void release_dc_ptr( DC *dc )
230 ref = InterlockedDecrement( &dc->refcount );
232 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
236 /***********************************************************************
239 * Make sure the DC vis region is up to date.
240 * This function may call up to USER so the GDI lock should _not_
241 * be held when calling it.
243 void update_dc( DC *dc )
245 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
246 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
250 /***********************************************************************
253 static BOOL DC_DeleteObject( HGDIOBJ handle )
255 return DeleteDC( handle );
259 /***********************************************************************
262 * Setup device-specific DC values for a newly created DC.
264 void DC_InitDC( DC* dc )
266 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
267 physdev->funcs->pRealizeDefaultPalette( physdev );
268 SetTextColor( dc->hSelf, dc->textColor );
269 SetBkColor( dc->hSelf, dc->backgroundColor );
270 SelectObject( dc->hSelf, dc->hPen );
271 SelectObject( dc->hSelf, dc->hBrush );
272 SelectObject( dc->hSelf, dc->hFont );
273 CLIPPING_UpdateGCRegion( dc );
274 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
278 /***********************************************************************
281 * Computes the inverse of the transformation xformSrc and stores it to
282 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
285 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
289 determinant = xformSrc->eM11*xformSrc->eM22 -
290 xformSrc->eM12*xformSrc->eM21;
291 if (determinant > -1e-12 && determinant < 1e-12)
294 xformDest->eM11 = xformSrc->eM22 / determinant;
295 xformDest->eM12 = -xformSrc->eM12 / determinant;
296 xformDest->eM21 = -xformSrc->eM21 / determinant;
297 xformDest->eM22 = xformSrc->eM11 / determinant;
298 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
299 xformSrc->eDy * xformDest->eM21;
300 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
301 xformSrc->eDy * xformDest->eM22;
306 /* Construct a transformation to do the window-to-viewport conversion */
307 static void construct_window_to_viewport(DC *dc, XFORM *xform)
309 double scaleX, scaleY;
310 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
311 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
313 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
314 xform->eM11 = scaleX;
317 xform->eM22 = scaleY;
318 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
319 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
320 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
323 /***********************************************************************
326 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
327 * fields of the specified DC by creating a transformation that
328 * represents the current mapping mode and combining it with the DC's
329 * world transform. This function should be called whenever the
330 * parameters associated with the mapping mode (window and viewport
331 * extents and origins) or the world transform change.
333 void DC_UpdateXforms( DC *dc )
335 XFORM xformWnd2Vport, oldworld2vport;
337 construct_window_to_viewport(dc, &xformWnd2Vport);
339 oldworld2vport = dc->xformWorld2Vport;
340 /* Combine with the world transformation */
341 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
344 /* Create inverse of world-to-viewport transformation */
345 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
346 &dc->xformVport2World );
348 /* Reselect the font and pen back into the dc so that the size
350 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
351 !GdiIsMetaFileDC(dc->hSelf))
353 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
354 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
359 /***********************************************************************
362 INT nulldrv_SaveDC( PHYSDEV dev )
364 DC *newdc, *dc = get_nulldrv_dc( dev );
366 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc )))) return 0;
367 newdc->flags = dc->flags;
368 newdc->layout = dc->layout;
369 newdc->hPen = dc->hPen;
370 newdc->hBrush = dc->hBrush;
371 newdc->hFont = dc->hFont;
372 newdc->hBitmap = dc->hBitmap;
373 newdc->hDevice = dc->hDevice;
374 newdc->hPalette = dc->hPalette;
375 newdc->ROPmode = dc->ROPmode;
376 newdc->polyFillMode = dc->polyFillMode;
377 newdc->stretchBltMode = dc->stretchBltMode;
378 newdc->relAbsMode = dc->relAbsMode;
379 newdc->backgroundMode = dc->backgroundMode;
380 newdc->backgroundColor = dc->backgroundColor;
381 newdc->textColor = dc->textColor;
382 newdc->dcBrushColor = dc->dcBrushColor;
383 newdc->dcPenColor = dc->dcPenColor;
384 newdc->brushOrgX = dc->brushOrgX;
385 newdc->brushOrgY = dc->brushOrgY;
386 newdc->mapperFlags = dc->mapperFlags;
387 newdc->textAlign = dc->textAlign;
388 newdc->charExtra = dc->charExtra;
389 newdc->breakExtra = dc->breakExtra;
390 newdc->breakRem = dc->breakRem;
391 newdc->MapMode = dc->MapMode;
392 newdc->GraphicsMode = dc->GraphicsMode;
393 newdc->CursPosX = dc->CursPosX;
394 newdc->CursPosY = dc->CursPosY;
395 newdc->ArcDirection = dc->ArcDirection;
396 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
397 newdc->xformWorld2Vport = dc->xformWorld2Vport;
398 newdc->xformVport2World = dc->xformVport2World;
399 newdc->vport2WorldValid = dc->vport2WorldValid;
400 newdc->wndOrgX = dc->wndOrgX;
401 newdc->wndOrgY = dc->wndOrgY;
402 newdc->wndExtX = dc->wndExtX;
403 newdc->wndExtY = dc->wndExtY;
404 newdc->vportOrgX = dc->vportOrgX;
405 newdc->vportOrgY = dc->vportOrgY;
406 newdc->vportExtX = dc->vportExtX;
407 newdc->vportExtY = dc->vportExtY;
408 newdc->virtual_res = dc->virtual_res;
409 newdc->virtual_size = dc->virtual_size;
410 newdc->BoundsRect = dc->BoundsRect;
411 newdc->gdiFont = dc->gdiFont;
413 PATH_InitGdiPath( &newdc->path );
415 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
420 newdc->hMetaClipRgn = 0;
423 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
424 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
428 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
429 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
432 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
434 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
436 release_dc_ptr( dc );
437 free_dc_state( newdc );
441 newdc->saved_dc = dc->saved_dc;
442 dc->saved_dc = newdc;
443 return ++dc->saveLevel;
447 /***********************************************************************
450 BOOL nulldrv_RestoreDC( PHYSDEV dev, INT level )
452 DC *dcs, *first_dcs, *dc = get_nulldrv_dc( dev );
455 /* find the state level to restore */
457 if (abs(level) > dc->saveLevel || level == 0) return FALSE;
458 if (level < 0) level = dc->saveLevel + level + 1;
459 first_dcs = dc->saved_dc;
460 for (dcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
463 /* restore the state */
465 if (!PATH_AssignGdiPath( &dc->path, &dcs->path )) return FALSE;
467 dc->flags = dcs->flags;
468 dc->layout = dcs->layout;
469 dc->hDevice = dcs->hDevice;
470 dc->ROPmode = dcs->ROPmode;
471 dc->polyFillMode = dcs->polyFillMode;
472 dc->stretchBltMode = dcs->stretchBltMode;
473 dc->relAbsMode = dcs->relAbsMode;
474 dc->backgroundMode = dcs->backgroundMode;
475 dc->backgroundColor = dcs->backgroundColor;
476 dc->textColor = dcs->textColor;
477 dc->dcBrushColor = dcs->dcBrushColor;
478 dc->dcPenColor = dcs->dcPenColor;
479 dc->brushOrgX = dcs->brushOrgX;
480 dc->brushOrgY = dcs->brushOrgY;
481 dc->mapperFlags = dcs->mapperFlags;
482 dc->textAlign = dcs->textAlign;
483 dc->charExtra = dcs->charExtra;
484 dc->breakExtra = dcs->breakExtra;
485 dc->breakRem = dcs->breakRem;
486 dc->MapMode = dcs->MapMode;
487 dc->GraphicsMode = dcs->GraphicsMode;
488 dc->CursPosX = dcs->CursPosX;
489 dc->CursPosY = dcs->CursPosY;
490 dc->ArcDirection = dcs->ArcDirection;
491 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
492 dc->xformWorld2Vport = dcs->xformWorld2Vport;
493 dc->xformVport2World = dcs->xformVport2World;
494 dc->vport2WorldValid = dcs->vport2WorldValid;
495 dc->BoundsRect = dcs->BoundsRect;
497 dc->wndOrgX = dcs->wndOrgX;
498 dc->wndOrgY = dcs->wndOrgY;
499 dc->wndExtX = dcs->wndExtX;
500 dc->wndExtY = dcs->wndExtY;
501 dc->vportOrgX = dcs->vportOrgX;
502 dc->vportOrgY = dcs->vportOrgY;
503 dc->vportExtX = dcs->vportExtX;
504 dc->vportExtY = dcs->vportExtY;
505 dc->virtual_res = dcs->virtual_res;
506 dc->virtual_size = dcs->virtual_size;
510 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
511 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
515 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
520 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
521 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
525 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
528 DC_UpdateXforms( dc );
529 CLIPPING_UpdateGCRegion( dc );
531 SelectObject( dev->hdc, dcs->hBitmap );
532 SelectObject( dev->hdc, dcs->hBrush );
533 SelectObject( dev->hdc, dcs->hFont );
534 SelectObject( dev->hdc, dcs->hPen );
535 SetBkColor( dev->hdc, dcs->backgroundColor);
536 SetTextColor( dev->hdc, dcs->textColor);
537 GDISelectPalette( dev->hdc, dcs->hPalette, FALSE );
539 dc->saved_dc = dcs->saved_dc;
541 dc->saveLevel = save_level - 1;
543 /* now destroy all the saved DCs */
547 DC *next = first_dcs->saved_dc;
548 free_dc_state( first_dcs );
555 /***********************************************************************
558 INT WINAPI SaveDC( HDC hdc )
563 if ((dc = get_dc_ptr( hdc )))
565 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSaveDC );
566 ret = physdev->funcs->pSaveDC( physdev );
567 release_dc_ptr( dc );
573 /***********************************************************************
574 * RestoreDC (GDI32.@)
576 BOOL WINAPI RestoreDC( HDC hdc, INT level )
579 BOOL success = FALSE;
581 TRACE("%p %d\n", hdc, level );
582 if ((dc = get_dc_ptr( hdc )))
584 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRestoreDC );
586 success = physdev->funcs->pRestoreDC( physdev, level );
587 release_dc_ptr( dc );
593 /***********************************************************************
594 * CreateDCW (GDI32.@)
596 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
597 const DEVMODEW *initData )
601 const DC_FUNCTIONS *funcs;
606 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
610 ERR( "no device found for %s\n", debugstr_w(device) );
613 strcpyW(buf, driver);
616 if (!(funcs = DRIVER_load_driver( buf )))
618 ERR( "no driver found for %s\n", debugstr_w(buf) );
621 if (!(dc = alloc_dc_ptr( OBJ_DC ))) goto error;
624 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
625 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
627 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
628 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
630 if (funcs->pCreateDC)
632 if (!funcs->pCreateDC( &dc->physDev, buf, device, output, initData ))
634 WARN("creation aborted by device\n" );
639 dc->vis_rect.left = 0;
640 dc->vis_rect.top = 0;
641 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
642 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
643 SetRectRgn(dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top, dc->vis_rect.right, dc->vis_rect.bottom);
646 release_dc_ptr( dc );
650 if (dc) free_dc_ptr( dc );
655 /***********************************************************************
656 * CreateDCA (GDI32.@)
658 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
659 const DEVMODEA *initData )
661 UNICODE_STRING driverW, deviceW, outputW;
665 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
666 else driverW.Buffer = NULL;
668 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
669 else deviceW.Buffer = NULL;
671 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
672 else outputW.Buffer = NULL;
677 /* don't convert initData for DISPLAY driver, it's not used */
678 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
679 initDataW = GdiConvertToDevmodeW(initData);
682 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
684 RtlFreeUnicodeString(&driverW);
685 RtlFreeUnicodeString(&deviceW);
686 RtlFreeUnicodeString(&outputW);
687 HeapFree(GetProcessHeap(), 0, initDataW);
692 /***********************************************************************
693 * CreateICA (GDI32.@)
695 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
696 const DEVMODEA* initData )
698 /* Nothing special yet for ICs */
699 return CreateDCA( driver, device, output, initData );
703 /***********************************************************************
704 * CreateICW (GDI32.@)
706 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
707 const DEVMODEW* initData )
709 /* Nothing special yet for ICs */
710 return CreateDCW( driver, device, output, initData );
714 /***********************************************************************
715 * CreateCompatibleDC (GDI32.@)
717 HDC WINAPI CreateCompatibleDC( HDC hdc )
721 const struct gdi_dc_funcs *funcs = &null_driver;
722 PHYSDEV physDev = NULL;
728 if (!(origDC = get_dc_ptr( hdc ))) return 0;
729 physDev = GET_DC_PHYSDEV( origDC, pCreateCompatibleDC );
730 funcs = physDev->funcs;
731 release_dc_ptr( origDC );
734 if (!(dc = alloc_dc_ptr( OBJ_MEMDC ))) goto error;
736 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
738 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
739 dc->vis_rect.left = 0;
740 dc->vis_rect.top = 0;
741 dc->vis_rect.right = 1;
742 dc->vis_rect.bottom = 1;
743 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
747 if (!funcs->pCreateCompatibleDC( physDev, &dc->physDev ))
749 WARN("creation aborted by device\n");
753 release_dc_ptr( dc );
757 if (dc) free_dc_ptr( dc );
762 /***********************************************************************
765 BOOL WINAPI DeleteDC( HDC hdc )
773 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
774 if (dc->refcount != 1)
776 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
777 release_dc_ptr( dc );
781 /* Call hook procedure to check whether is it OK to delete this DC */
782 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
784 release_dc_ptr( dc );
788 while (dc->saveLevel)
790 DC *dcs = dc->saved_dc;
791 dc->saved_dc = dcs->saved_dc;
793 free_dc_state( dcs );
796 SelectObject( hdc, GetStockObject(BLACK_PEN) );
797 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
798 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
799 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
806 /***********************************************************************
809 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
814 if ((dc = get_dc_ptr( hdc )))
816 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
817 ret = physdev->funcs->pResetDC( physdev, devmode );
818 if (ret) /* reset the visible region */
821 dc->vis_rect.left = 0;
822 dc->vis_rect.top = 0;
823 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
824 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
825 SetRectRgn( dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top,
826 dc->vis_rect.right, dc->vis_rect.bottom );
827 CLIPPING_UpdateGCRegion( dc );
829 release_dc_ptr( dc );
835 /***********************************************************************
838 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
843 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
844 else devmodeW = NULL;
846 ret = ResetDCW(hdc, devmodeW);
848 HeapFree(GetProcessHeap(), 0, devmodeW);
853 /***********************************************************************
854 * GetDeviceCaps (GDI32.@)
856 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
861 if ((dc = get_dc_ptr( hdc )))
863 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
864 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
865 release_dc_ptr( dc );
871 /***********************************************************************
872 * GetBkColor (GDI32.@)
874 COLORREF WINAPI GetBkColor( HDC hdc )
877 DC * dc = get_dc_ptr( hdc );
880 ret = dc->backgroundColor;
881 release_dc_ptr( dc );
887 /***********************************************************************
888 * SetBkColor (GDI32.@)
890 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
892 COLORREF ret = CLR_INVALID;
893 DC * dc = get_dc_ptr( hdc );
895 TRACE("hdc=%p color=0x%08x\n", hdc, color);
899 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
900 color = physdev->funcs->pSetBkColor( physdev, color );
901 if (color != CLR_INVALID)
903 ret = dc->backgroundColor;
904 dc->backgroundColor = color;
906 release_dc_ptr( dc );
912 /***********************************************************************
913 * GetTextColor (GDI32.@)
915 COLORREF WINAPI GetTextColor( HDC hdc )
918 DC * dc = get_dc_ptr( hdc );
922 release_dc_ptr( dc );
928 /***********************************************************************
929 * SetTextColor (GDI32.@)
931 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
933 COLORREF ret = CLR_INVALID;
934 DC * dc = get_dc_ptr( hdc );
936 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
940 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
941 color = physdev->funcs->pSetTextColor( physdev, color );
942 if (color != CLR_INVALID)
945 dc->textColor = color;
947 release_dc_ptr( dc );
953 /***********************************************************************
954 * GetTextAlign (GDI32.@)
956 UINT WINAPI GetTextAlign( HDC hdc )
959 DC * dc = get_dc_ptr( hdc );
963 release_dc_ptr( dc );
969 /***********************************************************************
970 * SetTextAlign (GDI32.@)
972 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
974 UINT ret = GDI_ERROR;
975 DC *dc = get_dc_ptr( hdc );
977 TRACE("hdc=%p align=%d\n", hdc, align);
981 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
982 align = physdev->funcs->pSetTextAlign( physdev, align );
983 if (align != GDI_ERROR)
986 dc->textAlign = align;
988 release_dc_ptr( dc );
993 /***********************************************************************
994 * GetDCOrgEx (GDI32.@)
996 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1000 if (!lpp) return FALSE;
1001 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1002 lpp->x = dc->vis_rect.left;
1003 lpp->y = dc->vis_rect.top;
1004 release_dc_ptr( dc );
1009 /***********************************************************************
1010 * GetGraphicsMode (GDI32.@)
1012 INT WINAPI GetGraphicsMode( HDC hdc )
1015 DC * dc = get_dc_ptr( hdc );
1018 ret = dc->GraphicsMode;
1019 release_dc_ptr( dc );
1025 /***********************************************************************
1026 * SetGraphicsMode (GDI32.@)
1028 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1031 DC *dc = get_dc_ptr( hdc );
1033 /* One would think that setting the graphics mode to GM_COMPATIBLE
1034 * would also reset the world transformation matrix to the unity
1035 * matrix. However, in Windows, this is not the case. This doesn't
1036 * make a lot of sense to me, but that's the way it is.
1039 if ((mode > 0) && (mode <= GM_LAST))
1041 ret = dc->GraphicsMode;
1042 dc->GraphicsMode = mode;
1044 release_dc_ptr( dc );
1049 /***********************************************************************
1050 * GetArcDirection (GDI32.@)
1052 INT WINAPI GetArcDirection( HDC hdc )
1055 DC * dc = get_dc_ptr( hdc );
1058 ret = dc->ArcDirection;
1059 release_dc_ptr( dc );
1065 /***********************************************************************
1066 * SetArcDirection (GDI32.@)
1068 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1073 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1075 SetLastError(ERROR_INVALID_PARAMETER);
1079 if ((dc = get_dc_ptr( hdc )))
1081 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1082 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1085 ret = dc->ArcDirection;
1086 dc->ArcDirection = dir;
1088 release_dc_ptr( dc );
1094 /***********************************************************************
1095 * GetWorldTransform (GDI32.@)
1097 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1100 if (!xform) return FALSE;
1101 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1102 *xform = dc->xformWorld2Wnd;
1103 release_dc_ptr( dc );
1108 /***********************************************************************
1109 * GetTransform (GDI32.@)
1113 * Returns one of the co-ordinate space transforms
1116 * hdc [I] Device context.
1117 * which [I] Which xform to return:
1118 * 0x203 World -> Page transform (that set by SetWorldTransform).
1119 * 0x304 Page -> Device transform (the mapping mode transform).
1120 * 0x204 World -> Device transform (the combination of the above two).
1121 * 0x402 Device -> World transform (the inversion of the above).
1122 * xform [O] The xform.
1125 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1128 DC *dc = get_dc_ptr( hdc );
1129 if (!dc) return FALSE;
1134 *xform = dc->xformWorld2Wnd;
1138 construct_window_to_viewport(dc, xform);
1142 *xform = dc->xformWorld2Vport;
1146 *xform = dc->xformVport2World;
1150 FIXME("Unknown code %x\n", which);
1154 release_dc_ptr( dc );
1159 /****************************************************************************
1160 * CombineTransform [GDI32.@]
1161 * Combines two transformation matrices.
1164 * xformResult [O] Stores the result of combining the two matrices
1165 * xform1 [I] Specifies the first matrix to apply
1166 * xform2 [I] Specifies the second matrix to apply
1169 * The same matrix can be passed in for more than one of the parameters.
1173 * Failure: FALSE. Use GetLastError() to determine the cause.
1175 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1176 const XFORM *xform2 )
1180 /* Check for illegal parameters */
1181 if (!xformResult || !xform1 || !xform2)
1184 /* Create the result in a temporary XFORM, since xformResult may be
1185 * equal to xform1 or xform2 */
1186 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1187 xform1->eM12 * xform2->eM21;
1188 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1189 xform1->eM12 * xform2->eM22;
1190 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1191 xform1->eM22 * xform2->eM21;
1192 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1193 xform1->eM22 * xform2->eM22;
1194 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1195 xform1->eDy * xform2->eM21 +
1197 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1198 xform1->eDy * xform2->eM22 +
1201 /* Copy the result to xformResult */
1202 *xformResult = xformTemp;
1208 /***********************************************************************
1209 * SetDCHook (GDI32.@)
1211 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1213 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1215 DC *dc = get_dc_ptr( hdc );
1217 if (!dc) return FALSE;
1219 dc->dwHookData = dwHookData;
1220 dc->hookProc = hookProc;
1221 release_dc_ptr( dc );
1226 /***********************************************************************
1227 * GetDCHook (GDI32.@)
1229 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1231 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1233 DC *dc = get_dc_ptr( hdc );
1237 if (proc) *proc = dc->hookProc;
1238 ret = dc->dwHookData;
1239 release_dc_ptr( dc );
1244 /***********************************************************************
1245 * SetHookFlags (GDI32.@)
1247 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1249 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1251 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1256 /* "Undocumented Windows" info is slightly confusing. */
1258 TRACE("hDC %p, flags %04x\n",hdc,flags);
1260 if (flags & DCHF_INVALIDATEVISRGN)
1261 ret = InterlockedExchange( &dc->dirty, 1 );
1262 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1263 ret = InterlockedExchange( &dc->dirty, 0 );
1265 GDI_ReleaseObj( hdc );
1269 /***********************************************************************
1270 * SetICMMode (GDI32.@)
1272 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1274 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1275 if (iEnableICM == ICM_OFF) return ICM_OFF;
1276 if (iEnableICM == ICM_ON) return 0;
1277 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1281 /***********************************************************************
1282 * GetDeviceGammaRamp (GDI32.@)
1284 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1287 DC *dc = get_dc_ptr( hDC );
1291 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1292 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1293 release_dc_ptr( dc );
1298 /***********************************************************************
1299 * SetDeviceGammaRamp (GDI32.@)
1301 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1304 DC *dc = get_dc_ptr( hDC );
1308 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1309 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1310 release_dc_ptr( dc );
1315 /***********************************************************************
1316 * GetColorSpace (GDI32.@)
1318 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1320 /*FIXME Need to to whatever GetColorSpace actually does */
1324 /***********************************************************************
1325 * CreateColorSpaceA (GDI32.@)
1327 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1333 /***********************************************************************
1334 * CreateColorSpaceW (GDI32.@)
1336 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1342 /***********************************************************************
1343 * DeleteColorSpace (GDI32.@)
1345 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1352 /***********************************************************************
1353 * SetColorSpace (GDI32.@)
1355 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1362 /***********************************************************************
1363 * GetBoundsRect (GDI32.@)
1365 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1368 DC *dc = get_dc_ptr( hdc );
1370 if ( !dc ) return 0;
1374 *rect = dc->BoundsRect;
1375 ret = is_rect_empty( rect ) ? DCB_RESET : DCB_SET;
1376 DPtoLP( hdc, (POINT *)rect, 2 );
1378 if (flags & DCB_RESET)
1380 dc->BoundsRect.left = 0;
1381 dc->BoundsRect.top = 0;
1382 dc->BoundsRect.right = 0;
1383 dc->BoundsRect.bottom = 0;
1385 release_dc_ptr( dc );
1390 /***********************************************************************
1391 * SetBoundsRect (GDI32.@)
1393 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1398 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1399 if (!(dc = get_dc_ptr( hdc ))) return 0;
1401 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1402 (is_rect_empty( &dc->BoundsRect ) ? DCB_RESET : DCB_SET);
1404 if (flags & DCB_RESET)
1406 dc->BoundsRect.left = 0;
1407 dc->BoundsRect.top = 0;
1408 dc->BoundsRect.right = 0;
1409 dc->BoundsRect.bottom = 0;
1412 if ((flags & DCB_ACCUMULATE) && rect)
1416 LPtoDP( hdc, (POINT *)&rc, 2 );
1417 if (!is_rect_empty( &rc ))
1419 if (!is_rect_empty( &dc->BoundsRect))
1421 dc->BoundsRect.left = min( dc->BoundsRect.left, rc.left );
1422 dc->BoundsRect.top = min( dc->BoundsRect.top, rc.top );
1423 dc->BoundsRect.right = max( dc->BoundsRect.right, rc.right );
1424 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rc.bottom );
1426 else dc->BoundsRect = rc;
1430 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1431 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1433 release_dc_ptr( dc );
1438 /***********************************************************************
1439 * GetRelAbs (GDI32.@)
1441 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1444 DC *dc = get_dc_ptr( hdc );
1447 ret = dc->relAbsMode;
1448 release_dc_ptr( dc );
1456 /***********************************************************************
1457 * GetBkMode (GDI32.@)
1459 INT WINAPI GetBkMode( HDC hdc )
1462 DC * dc = get_dc_ptr( hdc );
1465 ret = dc->backgroundMode;
1466 release_dc_ptr( dc );
1472 /***********************************************************************
1473 * SetBkMode (GDI32.@)
1475 INT WINAPI SetBkMode( HDC hdc, INT mode )
1480 if ((mode <= 0) || (mode > BKMODE_LAST))
1482 SetLastError(ERROR_INVALID_PARAMETER);
1485 if ((dc = get_dc_ptr( hdc )))
1487 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1488 mode = physdev->funcs->pSetBkMode( physdev, mode );
1491 ret = dc->backgroundMode;
1492 dc->backgroundMode = mode;
1494 release_dc_ptr( dc );
1500 /***********************************************************************
1503 INT WINAPI GetROP2( HDC hdc )
1506 DC * dc = get_dc_ptr( hdc );
1510 release_dc_ptr( dc );
1516 /***********************************************************************
1519 INT WINAPI SetROP2( HDC hdc, INT mode )
1524 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1526 SetLastError(ERROR_INVALID_PARAMETER);
1529 if ((dc = get_dc_ptr( hdc )))
1531 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1532 mode = physdev->funcs->pSetROP2( physdev, mode );
1538 release_dc_ptr( dc );
1544 /***********************************************************************
1545 * SetRelAbs (GDI32.@)
1547 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1552 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1554 SetLastError(ERROR_INVALID_PARAMETER);
1557 if ((dc = get_dc_ptr( hdc )))
1559 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1560 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1563 ret = dc->relAbsMode;
1564 dc->relAbsMode = mode;
1566 release_dc_ptr( dc );
1572 /***********************************************************************
1573 * GetPolyFillMode (GDI32.@)
1575 INT WINAPI GetPolyFillMode( HDC hdc )
1578 DC * dc = get_dc_ptr( hdc );
1581 ret = dc->polyFillMode;
1582 release_dc_ptr( dc );
1588 /***********************************************************************
1589 * SetPolyFillMode (GDI32.@)
1591 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1596 if ((mode <= 0) || (mode > POLYFILL_LAST))
1598 SetLastError(ERROR_INVALID_PARAMETER);
1601 if ((dc = get_dc_ptr( hdc )))
1603 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1604 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1607 ret = dc->polyFillMode;
1608 dc->polyFillMode = mode;
1610 release_dc_ptr( dc );
1616 /***********************************************************************
1617 * GetStretchBltMode (GDI32.@)
1619 INT WINAPI GetStretchBltMode( HDC hdc )
1622 DC * dc = get_dc_ptr( hdc );
1625 ret = dc->stretchBltMode;
1626 release_dc_ptr( dc );
1632 /***********************************************************************
1633 * SetStretchBltMode (GDI32.@)
1635 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1640 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1642 SetLastError(ERROR_INVALID_PARAMETER);
1645 if ((dc = get_dc_ptr( hdc )))
1647 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1648 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1651 ret = dc->stretchBltMode;
1652 dc->stretchBltMode = mode;
1654 release_dc_ptr( dc );
1660 /***********************************************************************
1661 * GetMapMode (GDI32.@)
1663 INT WINAPI GetMapMode( HDC hdc )
1666 DC * dc = get_dc_ptr( hdc );
1670 release_dc_ptr( dc );
1676 /***********************************************************************
1677 * GetBrushOrgEx (GDI32.@)
1679 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1681 DC * dc = get_dc_ptr( hdc );
1682 if (!dc) return FALSE;
1683 pt->x = dc->brushOrgX;
1684 pt->y = dc->brushOrgY;
1685 release_dc_ptr( dc );
1690 /***********************************************************************
1691 * GetCurrentPositionEx (GDI32.@)
1693 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1695 DC * dc = get_dc_ptr( hdc );
1696 if (!dc) return FALSE;
1697 pt->x = dc->CursPosX;
1698 pt->y = dc->CursPosY;
1699 release_dc_ptr( dc );
1704 /***********************************************************************
1705 * GetViewportExtEx (GDI32.@)
1707 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1709 DC * dc = get_dc_ptr( hdc );
1710 if (!dc) return FALSE;
1711 size->cx = dc->vportExtX;
1712 size->cy = dc->vportExtY;
1713 release_dc_ptr( dc );
1718 /***********************************************************************
1719 * GetViewportOrgEx (GDI32.@)
1721 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1723 DC * dc = get_dc_ptr( hdc );
1724 if (!dc) return FALSE;
1725 pt->x = dc->vportOrgX;
1726 pt->y = dc->vportOrgY;
1727 release_dc_ptr( dc );
1732 /***********************************************************************
1733 * GetWindowExtEx (GDI32.@)
1735 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1737 DC * dc = get_dc_ptr( hdc );
1738 if (!dc) return FALSE;
1739 size->cx = dc->wndExtX;
1740 size->cy = dc->wndExtY;
1741 release_dc_ptr( dc );
1746 /***********************************************************************
1747 * GetWindowOrgEx (GDI32.@)
1749 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1751 DC * dc = get_dc_ptr( hdc );
1752 if (!dc) return FALSE;
1753 pt->x = dc->wndOrgX;
1754 pt->y = dc->wndOrgY;
1755 release_dc_ptr( dc );
1760 /***********************************************************************
1761 * GetLayout (GDI32.@)
1763 * Gets left->right or right->left text layout flags of a dc.
1766 DWORD WINAPI GetLayout(HDC hdc)
1768 DWORD layout = GDI_ERROR;
1770 DC * dc = get_dc_ptr( hdc );
1773 layout = dc->layout;
1774 release_dc_ptr( dc );
1777 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1782 /***********************************************************************
1783 * SetLayout (GDI32.@)
1785 * Sets left->right or right->left text layout flags of a dc.
1788 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1790 DWORD oldlayout = GDI_ERROR;
1792 DC * dc = get_dc_ptr( hdc );
1795 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1796 layout = physdev->funcs->pSetLayout( physdev, layout );
1797 if (layout != GDI_ERROR)
1799 oldlayout = dc->layout;
1800 dc->layout = layout;
1801 if (layout != oldlayout)
1803 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1804 DC_UpdateXforms( dc );
1807 release_dc_ptr( dc );
1810 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1815 /***********************************************************************
1816 * GetDCBrushColor (GDI32.@)
1818 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1821 COLORREF dcBrushColor = CLR_INVALID;
1823 TRACE("hdc(%p)\n", hdc);
1825 dc = get_dc_ptr( hdc );
1828 dcBrushColor = dc->dcBrushColor;
1829 release_dc_ptr( dc );
1832 return dcBrushColor;
1835 /***********************************************************************
1836 * SetDCBrushColor (GDI32.@)
1838 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1841 COLORREF oldClr = CLR_INVALID;
1843 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1845 dc = get_dc_ptr( hdc );
1848 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCBrushColor );
1849 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1850 if (crColor != CLR_INVALID)
1852 oldClr = dc->dcBrushColor;
1853 dc->dcBrushColor = crColor;
1855 release_dc_ptr( dc );
1861 /***********************************************************************
1862 * GetDCPenColor (GDI32.@)
1864 COLORREF WINAPI GetDCPenColor(HDC hdc)
1867 COLORREF dcPenColor = CLR_INVALID;
1869 TRACE("hdc(%p)\n", hdc);
1871 dc = get_dc_ptr( hdc );
1874 dcPenColor = dc->dcPenColor;
1875 release_dc_ptr( dc );
1881 /***********************************************************************
1882 * SetDCPenColor (GDI32.@)
1884 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1887 COLORREF oldClr = CLR_INVALID;
1889 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1891 dc = get_dc_ptr( hdc );
1894 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1895 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1896 if (crColor != CLR_INVALID)
1898 oldClr = dc->dcPenColor;
1899 dc->dcPenColor = crColor;
1901 release_dc_ptr( dc );
1907 /***********************************************************************
1908 * CancelDC (GDI32.@)
1910 BOOL WINAPI CancelDC(HDC hdc)
1916 /*******************************************************************
1917 * GetMiterLimit [GDI32.@]
1921 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1926 TRACE("(%p,%p)\n", hdc, peLimit);
1928 dc = get_dc_ptr( hdc );
1932 *peLimit = dc->miterLimit;
1934 release_dc_ptr( dc );
1940 /*******************************************************************
1941 * SetMiterLimit [GDI32.@]
1945 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1950 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1952 dc = get_dc_ptr( hdc );
1956 *peOldLimit = dc->miterLimit;
1957 dc->miterLimit = eNewLimit;
1958 release_dc_ptr( dc );
1964 /*******************************************************************
1965 * GdiIsMetaPrintDC [GDI32.@]
1967 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
1973 /*******************************************************************
1974 * GdiIsMetaFileDC [GDI32.@]
1976 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
1980 switch( GetObjectType( hdc ) )
1989 /*******************************************************************
1990 * GdiIsPlayMetafileDC [GDI32.@]
1992 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)