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 switch (GetObjectType( hdc ))
66 GDI_ReleaseObj( hdc );
67 SetLastError( ERROR_INVALID_HANDLE );
73 /***********************************************************************
74 * set_initial_dc_state
76 static void set_initial_dc_state( DC *dc )
86 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
88 dc->font_code_page = CP_ACP;
89 dc->ROPmode = R2_COPYPEN;
90 dc->polyFillMode = ALTERNATE;
91 dc->stretchBltMode = BLACKONWHITE;
92 dc->relAbsMode = ABSOLUTE;
93 dc->backgroundMode = OPAQUE;
94 dc->backgroundColor = RGB( 255, 255, 255 );
95 dc->dcBrushColor = RGB( 255, 255, 255 );
96 dc->dcPenColor = RGB( 0, 0, 0 );
97 dc->textColor = RGB( 0, 0, 0 );
101 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
105 dc->MapMode = MM_TEXT;
106 dc->GraphicsMode = GM_COMPATIBLE;
109 dc->ArcDirection = AD_COUNTERCLOCKWISE;
110 dc->xformWorld2Wnd.eM11 = 1.0f;
111 dc->xformWorld2Wnd.eM12 = 0.0f;
112 dc->xformWorld2Wnd.eM21 = 0.0f;
113 dc->xformWorld2Wnd.eM22 = 1.0f;
114 dc->xformWorld2Wnd.eDx = 0.0f;
115 dc->xformWorld2Wnd.eDy = 0.0f;
116 dc->xformWorld2Vport = dc->xformWorld2Wnd;
117 dc->xformVport2World = dc->xformWorld2Wnd;
118 dc->vport2WorldValid = TRUE;
120 reset_bounds( &dc->bounds );
123 /***********************************************************************
126 DC *alloc_dc_ptr( WORD magic )
130 if (!(dc = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dc) ))) return NULL;
132 dc->nulldrv.funcs = &null_driver;
133 dc->physDev = &dc->nulldrv;
134 dc->module = gdi32_module;
135 dc->thread = GetCurrentThreadId();
137 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
138 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
139 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
140 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
142 set_initial_dc_state( dc );
144 if (!(dc->hSelf = alloc_gdi_handle( dc, magic, &dc_funcs )))
146 HeapFree( GetProcessHeap(), 0, dc );
149 dc->nulldrv.hdc = dc->hSelf;
151 if (font_driver && !font_driver->pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL ))
161 /***********************************************************************
164 static void free_dc_state( DC *dc )
166 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
167 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
168 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
169 if (dc->region) DeleteObject( dc->region );
170 if (dc->path) free_gdi_path( dc->path );
171 HeapFree( GetProcessHeap(), 0, dc );
175 /***********************************************************************
178 void free_dc_ptr( DC *dc )
180 assert( dc->refcount == 1 );
182 while (dc->physDev != &dc->nulldrv)
184 PHYSDEV physdev = dc->physDev;
185 dc->physDev = physdev->next;
186 physdev->funcs->pDeleteDC( physdev );
188 GDI_dec_ref_count( dc->hPen );
189 GDI_dec_ref_count( dc->hBrush );
190 GDI_dec_ref_count( dc->hFont );
191 if (dc->hBitmap) GDI_dec_ref_count( dc->hBitmap );
192 free_gdi_handle( dc->hSelf );
197 /***********************************************************************
200 * Retrieve a DC pointer but release the GDI lock.
202 DC *get_dc_ptr( HDC hdc )
204 DC *dc = get_dc_obj( hdc );
205 if (!dc) return NULL;
207 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
209 dc->thread = GetCurrentThreadId();
211 else if (dc->thread != GetCurrentThreadId())
213 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
214 GDI_ReleaseObj( hdc );
217 else InterlockedIncrement( &dc->refcount );
219 GDI_ReleaseObj( hdc );
224 /***********************************************************************
227 void release_dc_ptr( DC *dc )
232 ref = InterlockedDecrement( &dc->refcount );
234 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
238 /***********************************************************************
241 * Make sure the DC vis region is up to date.
242 * This function may call up to USER so the GDI lock should _not_
243 * be held when calling it.
245 void update_dc( DC *dc )
247 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
248 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
252 /***********************************************************************
255 static BOOL DC_DeleteObject( HGDIOBJ handle )
257 return DeleteDC( handle );
261 /***********************************************************************
264 * Setup device-specific DC values for a newly created DC.
266 void DC_InitDC( DC* dc )
268 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
269 physdev->funcs->pRealizeDefaultPalette( physdev );
270 SetTextColor( dc->hSelf, dc->textColor );
271 SetBkColor( dc->hSelf, dc->backgroundColor );
272 SelectObject( dc->hSelf, dc->hPen );
273 SelectObject( dc->hSelf, dc->hBrush );
274 SelectObject( dc->hSelf, dc->hFont );
275 update_dc_clipping( dc );
276 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
277 physdev = GET_DC_PHYSDEV( dc, pSetBoundsRect );
278 physdev->funcs->pSetBoundsRect( physdev, &dc->bounds, dc->bounds_enabled ? DCB_ENABLE : DCB_DISABLE );
282 /***********************************************************************
285 * Computes the inverse of the transformation xformSrc and stores it to
286 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
289 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
293 determinant = xformSrc->eM11*xformSrc->eM22 -
294 xformSrc->eM12*xformSrc->eM21;
295 if (determinant > -1e-12 && determinant < 1e-12)
298 xformDest->eM11 = xformSrc->eM22 / determinant;
299 xformDest->eM12 = -xformSrc->eM12 / determinant;
300 xformDest->eM21 = -xformSrc->eM21 / determinant;
301 xformDest->eM22 = xformSrc->eM11 / determinant;
302 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
303 xformSrc->eDy * xformDest->eM21;
304 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
305 xformSrc->eDy * xformDest->eM22;
310 /* Construct a transformation to do the window-to-viewport conversion */
311 static void construct_window_to_viewport(DC *dc, XFORM *xform)
313 double scaleX, scaleY;
314 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
315 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
317 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
318 xform->eM11 = scaleX;
321 xform->eM22 = scaleY;
322 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
323 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
324 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
327 /***********************************************************************
330 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
331 * fields of the specified DC by creating a transformation that
332 * represents the current mapping mode and combining it with the DC's
333 * world transform. This function should be called whenever the
334 * parameters associated with the mapping mode (window and viewport
335 * extents and origins) or the world transform change.
337 void DC_UpdateXforms( DC *dc )
339 XFORM xformWnd2Vport, oldworld2vport;
341 construct_window_to_viewport(dc, &xformWnd2Vport);
343 oldworld2vport = dc->xformWorld2Vport;
344 /* Combine with the world transformation */
345 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
348 /* Create inverse of world-to-viewport transformation */
349 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
350 &dc->xformVport2World );
352 /* Reselect the font and pen back into the dc so that the size
354 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
355 !GdiIsMetaFileDC(dc->hSelf))
357 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
358 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
363 /***********************************************************************
366 INT nulldrv_SaveDC( PHYSDEV dev )
368 DC *newdc, *dc = get_nulldrv_dc( dev );
370 if (!(newdc = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*newdc )))) return 0;
371 newdc->layout = dc->layout;
372 newdc->hPen = dc->hPen;
373 newdc->hBrush = dc->hBrush;
374 newdc->hFont = dc->hFont;
375 newdc->hBitmap = dc->hBitmap;
376 newdc->hPalette = dc->hPalette;
377 newdc->ROPmode = dc->ROPmode;
378 newdc->polyFillMode = dc->polyFillMode;
379 newdc->stretchBltMode = dc->stretchBltMode;
380 newdc->relAbsMode = dc->relAbsMode;
381 newdc->backgroundMode = dc->backgroundMode;
382 newdc->backgroundColor = dc->backgroundColor;
383 newdc->textColor = dc->textColor;
384 newdc->dcBrushColor = dc->dcBrushColor;
385 newdc->dcPenColor = dc->dcPenColor;
386 newdc->brushOrgX = dc->brushOrgX;
387 newdc->brushOrgY = dc->brushOrgY;
388 newdc->mapperFlags = dc->mapperFlags;
389 newdc->textAlign = dc->textAlign;
390 newdc->charExtra = dc->charExtra;
391 newdc->breakExtra = dc->breakExtra;
392 newdc->breakRem = dc->breakRem;
393 newdc->MapMode = dc->MapMode;
394 newdc->GraphicsMode = dc->GraphicsMode;
395 newdc->CursPosX = dc->CursPosX;
396 newdc->CursPosY = dc->CursPosY;
397 newdc->ArcDirection = dc->ArcDirection;
398 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
399 newdc->xformWorld2Vport = dc->xformWorld2Vport;
400 newdc->xformVport2World = dc->xformVport2World;
401 newdc->vport2WorldValid = dc->vport2WorldValid;
402 newdc->wndOrgX = dc->wndOrgX;
403 newdc->wndOrgY = dc->wndOrgY;
404 newdc->wndExtX = dc->wndExtX;
405 newdc->wndExtY = dc->wndExtY;
406 newdc->vportOrgX = dc->vportOrgX;
407 newdc->vportOrgY = dc->vportOrgY;
408 newdc->vportExtX = dc->vportExtX;
409 newdc->vportExtY = dc->vportExtY;
410 newdc->virtual_res = dc->virtual_res;
411 newdc->virtual_size = dc->virtual_size;
412 newdc->gdiFont = dc->gdiFont;
414 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
418 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
419 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
423 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
424 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
427 if (!PATH_SavePath( newdc, dc ))
429 release_dc_ptr( dc );
430 free_dc_state( newdc );
434 newdc->saved_dc = dc->saved_dc;
435 dc->saved_dc = newdc;
436 return ++dc->saveLevel;
440 /***********************************************************************
443 BOOL nulldrv_RestoreDC( PHYSDEV dev, INT level )
445 DC *dcs, *first_dcs, *dc = get_nulldrv_dc( dev );
448 /* find the state level to restore */
450 if (abs(level) > dc->saveLevel || level == 0) return FALSE;
451 if (level < 0) level = dc->saveLevel + level + 1;
452 first_dcs = dc->saved_dc;
453 for (dcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
456 /* restore the state */
458 if (!PATH_RestorePath( dc, dcs )) return FALSE;
460 dc->layout = dcs->layout;
461 dc->ROPmode = dcs->ROPmode;
462 dc->polyFillMode = dcs->polyFillMode;
463 dc->stretchBltMode = dcs->stretchBltMode;
464 dc->relAbsMode = dcs->relAbsMode;
465 dc->backgroundMode = dcs->backgroundMode;
466 dc->backgroundColor = dcs->backgroundColor;
467 dc->textColor = dcs->textColor;
468 dc->dcBrushColor = dcs->dcBrushColor;
469 dc->dcPenColor = dcs->dcPenColor;
470 dc->brushOrgX = dcs->brushOrgX;
471 dc->brushOrgY = dcs->brushOrgY;
472 dc->mapperFlags = dcs->mapperFlags;
473 dc->textAlign = dcs->textAlign;
474 dc->charExtra = dcs->charExtra;
475 dc->breakExtra = dcs->breakExtra;
476 dc->breakRem = dcs->breakRem;
477 dc->MapMode = dcs->MapMode;
478 dc->GraphicsMode = dcs->GraphicsMode;
479 dc->CursPosX = dcs->CursPosX;
480 dc->CursPosY = dcs->CursPosY;
481 dc->ArcDirection = dcs->ArcDirection;
482 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
483 dc->xformWorld2Vport = dcs->xformWorld2Vport;
484 dc->xformVport2World = dcs->xformVport2World;
485 dc->vport2WorldValid = dcs->vport2WorldValid;
486 dc->wndOrgX = dcs->wndOrgX;
487 dc->wndOrgY = dcs->wndOrgY;
488 dc->wndExtX = dcs->wndExtX;
489 dc->wndExtY = dcs->wndExtY;
490 dc->vportOrgX = dcs->vportOrgX;
491 dc->vportOrgY = dcs->vportOrgY;
492 dc->vportExtX = dcs->vportExtX;
493 dc->vportExtY = dcs->vportExtY;
494 dc->virtual_res = dcs->virtual_res;
495 dc->virtual_size = dcs->virtual_size;
499 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
500 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
504 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
509 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
510 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
514 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
517 DC_UpdateXforms( dc );
518 update_dc_clipping( dc );
520 SelectObject( dev->hdc, dcs->hBitmap );
521 SelectObject( dev->hdc, dcs->hBrush );
522 SelectObject( dev->hdc, dcs->hFont );
523 SelectObject( dev->hdc, dcs->hPen );
524 SetBkColor( dev->hdc, dcs->backgroundColor);
525 SetTextColor( dev->hdc, dcs->textColor);
526 GDISelectPalette( dev->hdc, dcs->hPalette, FALSE );
528 dc->saved_dc = dcs->saved_dc;
530 dc->saveLevel = save_level - 1;
532 /* now destroy all the saved DCs */
536 DC *next = first_dcs->saved_dc;
537 free_dc_state( first_dcs );
544 /***********************************************************************
547 static BOOL reset_dc_state( HDC hdc )
551 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
553 set_initial_dc_state( dc );
554 SetBkColor( hdc, RGB( 255, 255, 255 ));
555 SetTextColor( hdc, RGB( 0, 0, 0 ));
556 SelectObject( hdc, GetStockObject( WHITE_BRUSH ));
557 SelectObject( hdc, GetStockObject( SYSTEM_FONT ));
558 SelectObject( hdc, GetStockObject( BLACK_PEN ));
559 SetVirtualResolution( hdc, 0, 0, 0, 0 );
560 GDISelectPalette( hdc, GetStockObject( DEFAULT_PALETTE ), FALSE );
561 SetBoundsRect( hdc, NULL, DCB_DISABLE );
564 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
565 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
568 update_dc_clipping( dc );
570 for (dcs = dc->saved_dc; dcs; dcs = next)
572 next = dcs->saved_dc;
573 free_dc_state( dcs );
577 release_dc_ptr( dc );
582 /***********************************************************************
585 INT WINAPI SaveDC( HDC hdc )
590 if ((dc = get_dc_ptr( hdc )))
592 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSaveDC );
593 ret = physdev->funcs->pSaveDC( physdev );
594 release_dc_ptr( dc );
600 /***********************************************************************
601 * RestoreDC (GDI32.@)
603 BOOL WINAPI RestoreDC( HDC hdc, INT level )
607 BOOL success = FALSE;
609 TRACE("%p %d\n", hdc, level );
610 if ((dc = get_dc_ptr( hdc )))
613 physdev = GET_DC_PHYSDEV( dc, pRestoreDC );
614 success = physdev->funcs->pRestoreDC( physdev, level );
615 release_dc_ptr( dc );
621 /***********************************************************************
622 * CreateDCW (GDI32.@)
624 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
625 const DEVMODEW *initData )
629 const struct gdi_dc_funcs *funcs;
635 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
639 ERR( "no device found for %s\n", debugstr_w(device) );
642 strcpyW(buf, driver);
645 if (!(funcs = DRIVER_load_driver( buf, &module )))
647 ERR( "no driver found for %s\n", debugstr_w(buf) );
650 if (!(dc = alloc_dc_ptr( OBJ_DC ))) return 0;
654 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
656 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
657 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
659 if (funcs->pCreateDC)
661 if (!funcs->pCreateDC( &dc->physDev, buf, device, output, initData ))
663 WARN("creation aborted by device\n" );
669 dc->vis_rect.left = 0;
670 dc->vis_rect.top = 0;
671 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
672 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
675 release_dc_ptr( dc );
680 /***********************************************************************
681 * CreateDCA (GDI32.@)
683 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
684 const DEVMODEA *initData )
686 UNICODE_STRING driverW, deviceW, outputW;
690 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
691 else driverW.Buffer = NULL;
693 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
694 else deviceW.Buffer = NULL;
696 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
697 else outputW.Buffer = NULL;
702 /* don't convert initData for DISPLAY driver, it's not used */
703 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
704 initDataW = GdiConvertToDevmodeW(initData);
707 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
709 RtlFreeUnicodeString(&driverW);
710 RtlFreeUnicodeString(&deviceW);
711 RtlFreeUnicodeString(&outputW);
712 HeapFree(GetProcessHeap(), 0, initDataW);
717 /***********************************************************************
718 * CreateICA (GDI32.@)
720 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
721 const DEVMODEA* initData )
723 /* Nothing special yet for ICs */
724 return CreateDCA( driver, device, output, initData );
728 /***********************************************************************
729 * CreateICW (GDI32.@)
731 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
732 const DEVMODEW* initData )
734 /* Nothing special yet for ICs */
735 return CreateDCW( driver, device, output, initData );
739 /***********************************************************************
740 * CreateCompatibleDC (GDI32.@)
742 HDC WINAPI CreateCompatibleDC( HDC hdc )
746 const struct gdi_dc_funcs *funcs = &null_driver;
747 PHYSDEV physDev = NULL;
753 if (!(origDC = get_dc_ptr( hdc ))) return 0;
754 physDev = GET_DC_PHYSDEV( origDC, pCreateCompatibleDC );
755 funcs = physDev->funcs;
756 release_dc_ptr( origDC );
759 if (!(dc = alloc_dc_ptr( OBJ_MEMDC ))) return 0;
761 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
763 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
764 dc->vis_rect.left = 0;
765 dc->vis_rect.top = 0;
766 dc->vis_rect.right = 1;
767 dc->vis_rect.bottom = 1;
768 dc->device_rect = dc->vis_rect;
772 if (!funcs->pCreateCompatibleDC( physDev, &dc->physDev ))
774 WARN("creation aborted by device\n");
779 if (!dib_driver.pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL ))
784 physDev = GET_DC_PHYSDEV( dc, pSelectBitmap );
785 physDev->funcs->pSelectBitmap( physDev, dc->hBitmap );
788 release_dc_ptr( dc );
793 /***********************************************************************
796 BOOL WINAPI DeleteDC( HDC hdc )
804 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
805 if (dc->refcount != 1)
807 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
808 release_dc_ptr( dc );
812 /* Call hook procedure to check whether is it OK to delete this DC */
813 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
815 release_dc_ptr( dc );
819 while (dc->saveLevel)
821 DC *dcs = dc->saved_dc;
822 dc->saved_dc = dcs->saved_dc;
824 free_dc_state( dcs );
828 SelectObject( hdc, GetStockObject(BLACK_PEN) );
829 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
830 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
831 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
838 /***********************************************************************
841 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
846 if ((dc = get_dc_ptr( hdc )))
848 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
849 ret = physdev->funcs->pResetDC( physdev, devmode );
850 if (ret) /* reset the visible region */
853 dc->vis_rect.left = 0;
854 dc->vis_rect.top = 0;
855 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
856 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
857 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
859 update_dc_clipping( dc );
861 release_dc_ptr( dc );
867 /***********************************************************************
870 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
875 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
876 else devmodeW = NULL;
878 ret = ResetDCW(hdc, devmodeW);
880 HeapFree(GetProcessHeap(), 0, devmodeW);
885 /***********************************************************************
886 * GetDeviceCaps (GDI32.@)
888 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
893 if ((dc = get_dc_ptr( hdc )))
895 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
896 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
897 release_dc_ptr( dc );
903 /***********************************************************************
904 * GetBkColor (GDI32.@)
906 COLORREF WINAPI GetBkColor( HDC hdc )
909 DC * dc = get_dc_ptr( hdc );
912 ret = dc->backgroundColor;
913 release_dc_ptr( dc );
919 /***********************************************************************
920 * SetBkColor (GDI32.@)
922 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
924 COLORREF ret = CLR_INVALID;
925 DC * dc = get_dc_ptr( hdc );
927 TRACE("hdc=%p color=0x%08x\n", hdc, color);
931 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
932 ret = dc->backgroundColor;
933 dc->backgroundColor = physdev->funcs->pSetBkColor( physdev, color );
934 release_dc_ptr( dc );
940 /***********************************************************************
941 * GetTextColor (GDI32.@)
943 COLORREF WINAPI GetTextColor( HDC hdc )
946 DC * dc = get_dc_ptr( hdc );
950 release_dc_ptr( dc );
956 /***********************************************************************
957 * SetTextColor (GDI32.@)
959 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
961 COLORREF ret = CLR_INVALID;
962 DC * dc = get_dc_ptr( hdc );
964 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
968 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
970 dc->textColor = physdev->funcs->pSetTextColor( physdev, color );
971 release_dc_ptr( dc );
977 /***********************************************************************
978 * GetTextAlign (GDI32.@)
980 UINT WINAPI GetTextAlign( HDC hdc )
983 DC * dc = get_dc_ptr( hdc );
987 release_dc_ptr( dc );
993 /***********************************************************************
994 * SetTextAlign (GDI32.@)
996 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
998 UINT ret = GDI_ERROR;
999 DC *dc = get_dc_ptr( hdc );
1001 TRACE("hdc=%p align=%d\n", hdc, align);
1005 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
1006 align = physdev->funcs->pSetTextAlign( physdev, align );
1007 if (align != GDI_ERROR)
1009 ret = dc->textAlign;
1010 dc->textAlign = align;
1012 release_dc_ptr( dc );
1017 /***********************************************************************
1018 * GetDCOrgEx (GDI32.@)
1020 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1024 if (!lpp) return FALSE;
1025 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1026 lpp->x = dc->vis_rect.left;
1027 lpp->y = dc->vis_rect.top;
1028 release_dc_ptr( dc );
1033 /***********************************************************************
1034 * GetGraphicsMode (GDI32.@)
1036 INT WINAPI GetGraphicsMode( HDC hdc )
1039 DC * dc = get_dc_ptr( hdc );
1042 ret = dc->GraphicsMode;
1043 release_dc_ptr( dc );
1049 /***********************************************************************
1050 * SetGraphicsMode (GDI32.@)
1052 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1055 DC *dc = get_dc_ptr( hdc );
1057 /* One would think that setting the graphics mode to GM_COMPATIBLE
1058 * would also reset the world transformation matrix to the unity
1059 * matrix. However, in Windows, this is not the case. This doesn't
1060 * make a lot of sense to me, but that's the way it is.
1063 if ((mode > 0) && (mode <= GM_LAST))
1065 ret = dc->GraphicsMode;
1066 dc->GraphicsMode = mode;
1068 release_dc_ptr( dc );
1073 /***********************************************************************
1074 * GetArcDirection (GDI32.@)
1076 INT WINAPI GetArcDirection( HDC hdc )
1079 DC * dc = get_dc_ptr( hdc );
1082 ret = dc->ArcDirection;
1083 release_dc_ptr( dc );
1089 /***********************************************************************
1090 * SetArcDirection (GDI32.@)
1092 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1097 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1099 SetLastError(ERROR_INVALID_PARAMETER);
1103 if ((dc = get_dc_ptr( hdc )))
1105 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1106 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1109 ret = dc->ArcDirection;
1110 dc->ArcDirection = dir;
1112 release_dc_ptr( dc );
1118 /***********************************************************************
1119 * GetWorldTransform (GDI32.@)
1121 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1124 if (!xform) return FALSE;
1125 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1126 *xform = dc->xformWorld2Wnd;
1127 release_dc_ptr( dc );
1132 /***********************************************************************
1133 * GetTransform (GDI32.@)
1137 * Returns one of the co-ordinate space transforms
1140 * hdc [I] Device context.
1141 * which [I] Which xform to return:
1142 * 0x203 World -> Page transform (that set by SetWorldTransform).
1143 * 0x304 Page -> Device transform (the mapping mode transform).
1144 * 0x204 World -> Device transform (the combination of the above two).
1145 * 0x402 Device -> World transform (the inversion of the above).
1146 * xform [O] The xform.
1149 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1152 DC *dc = get_dc_ptr( hdc );
1153 if (!dc) return FALSE;
1158 *xform = dc->xformWorld2Wnd;
1162 construct_window_to_viewport(dc, xform);
1166 *xform = dc->xformWorld2Vport;
1170 *xform = dc->xformVport2World;
1174 FIXME("Unknown code %x\n", which);
1178 release_dc_ptr( dc );
1183 /****************************************************************************
1184 * CombineTransform [GDI32.@]
1185 * Combines two transformation matrices.
1188 * xformResult [O] Stores the result of combining the two matrices
1189 * xform1 [I] Specifies the first matrix to apply
1190 * xform2 [I] Specifies the second matrix to apply
1193 * The same matrix can be passed in for more than one of the parameters.
1197 * Failure: FALSE. Use GetLastError() to determine the cause.
1199 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1200 const XFORM *xform2 )
1204 /* Check for illegal parameters */
1205 if (!xformResult || !xform1 || !xform2)
1208 /* Create the result in a temporary XFORM, since xformResult may be
1209 * equal to xform1 or xform2 */
1210 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1211 xform1->eM12 * xform2->eM21;
1212 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1213 xform1->eM12 * xform2->eM22;
1214 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1215 xform1->eM22 * xform2->eM21;
1216 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1217 xform1->eM22 * xform2->eM22;
1218 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1219 xform1->eDy * xform2->eM21 +
1221 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1222 xform1->eDy * xform2->eM22 +
1225 /* Copy the result to xformResult */
1226 *xformResult = xformTemp;
1232 /***********************************************************************
1233 * SetDCHook (GDI32.@)
1235 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1237 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1239 DC *dc = get_dc_ptr( hdc );
1241 if (!dc) return FALSE;
1243 dc->dwHookData = dwHookData;
1244 dc->hookProc = hookProc;
1245 release_dc_ptr( dc );
1250 /***********************************************************************
1251 * GetDCHook (GDI32.@)
1253 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1255 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1257 DC *dc = get_dc_ptr( hdc );
1261 if (proc) *proc = dc->hookProc;
1262 ret = dc->dwHookData;
1263 release_dc_ptr( dc );
1268 /***********************************************************************
1269 * SetHookFlags (GDI32.@)
1271 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1273 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1275 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1280 TRACE("hDC %p, flags %04x\n",hdc,flags);
1282 if (flags & DCHF_INVALIDATEVISRGN)
1283 ret = InterlockedExchange( &dc->dirty, 1 );
1284 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1285 ret = InterlockedExchange( &dc->dirty, 0 );
1287 GDI_ReleaseObj( hdc );
1289 if (flags & DCHF_RESETDC) ret = reset_dc_state( hdc );
1293 /***********************************************************************
1294 * SetICMMode (GDI32.@)
1296 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1298 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1299 if (iEnableICM == ICM_OFF) return ICM_OFF;
1300 if (iEnableICM == ICM_ON) return 0;
1301 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1305 /***********************************************************************
1306 * GetDeviceGammaRamp (GDI32.@)
1308 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1311 DC *dc = get_dc_ptr( hDC );
1313 TRACE("%p, %p\n", hDC, ptr);
1316 if (GetObjectType( hDC ) != OBJ_MEMDC)
1318 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1319 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1321 else SetLastError( ERROR_INVALID_PARAMETER );
1322 release_dc_ptr( dc );
1327 /***********************************************************************
1328 * SetDeviceGammaRamp (GDI32.@)
1330 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1333 DC *dc = get_dc_ptr( hDC );
1335 TRACE("%p, %p\n", hDC, ptr);
1338 if (GetObjectType( hDC ) != OBJ_MEMDC)
1340 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1341 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1343 else SetLastError( ERROR_INVALID_PARAMETER );
1344 release_dc_ptr( dc );
1349 /***********************************************************************
1350 * GetColorSpace (GDI32.@)
1352 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1354 /*FIXME Need to do whatever GetColorSpace actually does */
1358 /***********************************************************************
1359 * CreateColorSpaceA (GDI32.@)
1361 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1367 /***********************************************************************
1368 * CreateColorSpaceW (GDI32.@)
1370 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1376 /***********************************************************************
1377 * DeleteColorSpace (GDI32.@)
1379 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1386 /***********************************************************************
1387 * SetColorSpace (GDI32.@)
1389 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1396 /***********************************************************************
1397 * GetBoundsRect (GDI32.@)
1399 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1404 DC *dc = get_dc_ptr( hdc );
1406 if ( !dc ) return 0;
1408 physdev = GET_DC_PHYSDEV( dc, pGetBoundsRect );
1409 ret = physdev->funcs->pGetBoundsRect( physdev, &device_rect, DCB_RESET );
1412 release_dc_ptr( dc );
1415 if (dc->bounds_enabled && ret == DCB_SET) add_bounds_rect( &dc->bounds, &device_rect );
1419 if (is_rect_empty( &dc->bounds ))
1421 rect->left = rect->top = rect->right = rect->bottom = 0;
1427 rect->left = max( rect->left, 0 );
1428 rect->top = max( rect->top, 0 );
1429 rect->right = min( rect->right, dc->vis_rect.right - dc->vis_rect.left );
1430 rect->bottom = min( rect->bottom, dc->vis_rect.bottom - dc->vis_rect.top );
1433 DPtoLP( hdc, (POINT *)rect, 2 );
1437 if (flags & DCB_RESET) reset_bounds( &dc->bounds );
1438 release_dc_ptr( dc );
1443 /***********************************************************************
1444 * SetBoundsRect (GDI32.@)
1446 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1452 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1453 if (!(dc = get_dc_ptr( hdc ))) return 0;
1455 physdev = GET_DC_PHYSDEV( dc, pSetBoundsRect );
1456 ret = physdev->funcs->pSetBoundsRect( physdev, &dc->bounds, flags );
1459 release_dc_ptr( dc );
1463 ret = (dc->bounds_enabled ? DCB_ENABLE : DCB_DISABLE) |
1464 (is_rect_empty( &dc->bounds ) ? ret & DCB_SET : DCB_SET);
1466 if (flags & DCB_RESET) reset_bounds( &dc->bounds );
1468 if ((flags & DCB_ACCUMULATE) && rect)
1472 LPtoDP( hdc, (POINT *)&rc, 2 );
1473 add_bounds_rect( &dc->bounds, &rc );
1476 if (flags & DCB_ENABLE) dc->bounds_enabled = TRUE;
1477 if (flags & DCB_DISABLE) dc->bounds_enabled = FALSE;
1479 release_dc_ptr( dc );
1484 /***********************************************************************
1485 * GetRelAbs (GDI32.@)
1487 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1490 DC *dc = get_dc_ptr( hdc );
1493 ret = dc->relAbsMode;
1494 release_dc_ptr( dc );
1502 /***********************************************************************
1503 * GetBkMode (GDI32.@)
1505 INT WINAPI GetBkMode( HDC hdc )
1508 DC * dc = get_dc_ptr( hdc );
1511 ret = dc->backgroundMode;
1512 release_dc_ptr( dc );
1518 /***********************************************************************
1519 * SetBkMode (GDI32.@)
1521 INT WINAPI SetBkMode( HDC hdc, INT mode )
1526 if ((mode <= 0) || (mode > BKMODE_LAST))
1528 SetLastError(ERROR_INVALID_PARAMETER);
1531 if ((dc = get_dc_ptr( hdc )))
1533 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1534 mode = physdev->funcs->pSetBkMode( physdev, mode );
1537 ret = dc->backgroundMode;
1538 dc->backgroundMode = mode;
1540 release_dc_ptr( dc );
1546 /***********************************************************************
1549 INT WINAPI GetROP2( HDC hdc )
1552 DC * dc = get_dc_ptr( hdc );
1556 release_dc_ptr( dc );
1562 /***********************************************************************
1565 INT WINAPI SetROP2( HDC hdc, INT mode )
1570 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1572 SetLastError(ERROR_INVALID_PARAMETER);
1575 if ((dc = get_dc_ptr( hdc )))
1577 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1578 mode = physdev->funcs->pSetROP2( physdev, mode );
1584 release_dc_ptr( dc );
1590 /***********************************************************************
1591 * SetRelAbs (GDI32.@)
1593 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1598 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1600 SetLastError(ERROR_INVALID_PARAMETER);
1603 if ((dc = get_dc_ptr( hdc )))
1605 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1606 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1609 ret = dc->relAbsMode;
1610 dc->relAbsMode = mode;
1612 release_dc_ptr( dc );
1618 /***********************************************************************
1619 * GetPolyFillMode (GDI32.@)
1621 INT WINAPI GetPolyFillMode( HDC hdc )
1624 DC * dc = get_dc_ptr( hdc );
1627 ret = dc->polyFillMode;
1628 release_dc_ptr( dc );
1634 /***********************************************************************
1635 * SetPolyFillMode (GDI32.@)
1637 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1642 if ((mode <= 0) || (mode > POLYFILL_LAST))
1644 SetLastError(ERROR_INVALID_PARAMETER);
1647 if ((dc = get_dc_ptr( hdc )))
1649 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1650 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1653 ret = dc->polyFillMode;
1654 dc->polyFillMode = mode;
1656 release_dc_ptr( dc );
1662 /***********************************************************************
1663 * GetStretchBltMode (GDI32.@)
1665 INT WINAPI GetStretchBltMode( HDC hdc )
1668 DC * dc = get_dc_ptr( hdc );
1671 ret = dc->stretchBltMode;
1672 release_dc_ptr( dc );
1678 /***********************************************************************
1679 * SetStretchBltMode (GDI32.@)
1681 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1686 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1688 SetLastError(ERROR_INVALID_PARAMETER);
1691 if ((dc = get_dc_ptr( hdc )))
1693 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1694 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1697 ret = dc->stretchBltMode;
1698 dc->stretchBltMode = mode;
1700 release_dc_ptr( dc );
1706 /***********************************************************************
1707 * GetMapMode (GDI32.@)
1709 INT WINAPI GetMapMode( HDC hdc )
1712 DC * dc = get_dc_ptr( hdc );
1716 release_dc_ptr( dc );
1722 /***********************************************************************
1723 * GetBrushOrgEx (GDI32.@)
1725 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1727 DC * dc = get_dc_ptr( hdc );
1728 if (!dc) return FALSE;
1729 pt->x = dc->brushOrgX;
1730 pt->y = dc->brushOrgY;
1731 release_dc_ptr( dc );
1736 /***********************************************************************
1737 * GetCurrentPositionEx (GDI32.@)
1739 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1741 DC * dc = get_dc_ptr( hdc );
1742 if (!dc) return FALSE;
1743 pt->x = dc->CursPosX;
1744 pt->y = dc->CursPosY;
1745 release_dc_ptr( dc );
1750 /***********************************************************************
1751 * GetViewportExtEx (GDI32.@)
1753 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1755 DC * dc = get_dc_ptr( hdc );
1756 if (!dc) return FALSE;
1757 size->cx = dc->vportExtX;
1758 size->cy = dc->vportExtY;
1759 release_dc_ptr( dc );
1764 /***********************************************************************
1765 * GetViewportOrgEx (GDI32.@)
1767 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1769 DC * dc = get_dc_ptr( hdc );
1770 if (!dc) return FALSE;
1771 pt->x = dc->vportOrgX;
1772 pt->y = dc->vportOrgY;
1773 release_dc_ptr( dc );
1778 /***********************************************************************
1779 * GetWindowExtEx (GDI32.@)
1781 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1783 DC * dc = get_dc_ptr( hdc );
1784 if (!dc) return FALSE;
1785 size->cx = dc->wndExtX;
1786 size->cy = dc->wndExtY;
1787 release_dc_ptr( dc );
1792 /***********************************************************************
1793 * GetWindowOrgEx (GDI32.@)
1795 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1797 DC * dc = get_dc_ptr( hdc );
1798 if (!dc) return FALSE;
1799 pt->x = dc->wndOrgX;
1800 pt->y = dc->wndOrgY;
1801 release_dc_ptr( dc );
1806 /***********************************************************************
1807 * GetLayout (GDI32.@)
1809 * Gets left->right or right->left text layout flags of a dc.
1812 DWORD WINAPI GetLayout(HDC hdc)
1814 DWORD layout = GDI_ERROR;
1816 DC * dc = get_dc_ptr( hdc );
1819 layout = dc->layout;
1820 release_dc_ptr( dc );
1823 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1828 /***********************************************************************
1829 * SetLayout (GDI32.@)
1831 * Sets left->right or right->left text layout flags of a dc.
1834 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1836 DWORD oldlayout = GDI_ERROR;
1838 DC * dc = get_dc_ptr( hdc );
1841 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1842 layout = physdev->funcs->pSetLayout( physdev, layout );
1843 if (layout != GDI_ERROR)
1845 oldlayout = dc->layout;
1846 dc->layout = layout;
1847 if (layout != oldlayout)
1849 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1850 DC_UpdateXforms( dc );
1853 release_dc_ptr( dc );
1856 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1861 /***********************************************************************
1862 * GetDCBrushColor (GDI32.@)
1864 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1867 COLORREF dcBrushColor = CLR_INVALID;
1869 TRACE("hdc(%p)\n", hdc);
1871 dc = get_dc_ptr( hdc );
1874 dcBrushColor = dc->dcBrushColor;
1875 release_dc_ptr( dc );
1878 return dcBrushColor;
1881 /***********************************************************************
1882 * SetDCBrushColor (GDI32.@)
1884 COLORREF WINAPI SetDCBrushColor(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, pSetDCBrushColor );
1895 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1896 if (crColor != CLR_INVALID)
1898 oldClr = dc->dcBrushColor;
1899 dc->dcBrushColor = crColor;
1901 release_dc_ptr( dc );
1907 /***********************************************************************
1908 * GetDCPenColor (GDI32.@)
1910 COLORREF WINAPI GetDCPenColor(HDC hdc)
1913 COLORREF dcPenColor = CLR_INVALID;
1915 TRACE("hdc(%p)\n", hdc);
1917 dc = get_dc_ptr( hdc );
1920 dcPenColor = dc->dcPenColor;
1921 release_dc_ptr( dc );
1927 /***********************************************************************
1928 * SetDCPenColor (GDI32.@)
1930 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1933 COLORREF oldClr = CLR_INVALID;
1935 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1937 dc = get_dc_ptr( hdc );
1940 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1941 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1942 if (crColor != CLR_INVALID)
1944 oldClr = dc->dcPenColor;
1945 dc->dcPenColor = crColor;
1947 release_dc_ptr( dc );
1953 /***********************************************************************
1954 * CancelDC (GDI32.@)
1956 BOOL WINAPI CancelDC(HDC hdc)
1962 /*******************************************************************
1963 * GetMiterLimit [GDI32.@]
1967 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1972 TRACE("(%p,%p)\n", hdc, peLimit);
1974 dc = get_dc_ptr( hdc );
1978 *peLimit = dc->miterLimit;
1980 release_dc_ptr( dc );
1986 /*******************************************************************
1987 * SetMiterLimit [GDI32.@]
1991 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1996 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1998 dc = get_dc_ptr( hdc );
2002 *peOldLimit = dc->miterLimit;
2003 dc->miterLimit = eNewLimit;
2004 release_dc_ptr( dc );
2010 /*******************************************************************
2011 * GdiIsMetaPrintDC [GDI32.@]
2013 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2019 /*******************************************************************
2020 * GdiIsMetaFileDC [GDI32.@]
2022 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2026 switch( GetObjectType( hdc ) )
2035 /*******************************************************************
2036 * GdiIsPlayMetafileDC [GDI32.@]
2038 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)