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 );
818 reset_dc_state( hdc );
824 /***********************************************************************
827 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
832 if ((dc = get_dc_ptr( hdc )))
834 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
835 ret = physdev->funcs->pResetDC( physdev, devmode );
836 if (ret) /* reset the visible region */
839 dc->vis_rect.left = 0;
840 dc->vis_rect.top = 0;
841 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
842 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
843 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
845 update_dc_clipping( dc );
847 release_dc_ptr( dc );
853 /***********************************************************************
856 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
861 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
862 else devmodeW = NULL;
864 ret = ResetDCW(hdc, devmodeW);
866 HeapFree(GetProcessHeap(), 0, devmodeW);
871 /***********************************************************************
872 * GetDeviceCaps (GDI32.@)
874 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
879 if ((dc = get_dc_ptr( hdc )))
881 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
882 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
883 release_dc_ptr( dc );
889 /***********************************************************************
890 * GetBkColor (GDI32.@)
892 COLORREF WINAPI GetBkColor( HDC hdc )
895 DC * dc = get_dc_ptr( hdc );
898 ret = dc->backgroundColor;
899 release_dc_ptr( dc );
905 /***********************************************************************
906 * SetBkColor (GDI32.@)
908 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
910 COLORREF ret = CLR_INVALID;
911 DC * dc = get_dc_ptr( hdc );
913 TRACE("hdc=%p color=0x%08x\n", hdc, color);
917 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
918 ret = dc->backgroundColor;
919 dc->backgroundColor = physdev->funcs->pSetBkColor( physdev, color );
920 release_dc_ptr( dc );
926 /***********************************************************************
927 * GetTextColor (GDI32.@)
929 COLORREF WINAPI GetTextColor( HDC hdc )
932 DC * dc = get_dc_ptr( hdc );
936 release_dc_ptr( dc );
942 /***********************************************************************
943 * SetTextColor (GDI32.@)
945 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
947 COLORREF ret = CLR_INVALID;
948 DC * dc = get_dc_ptr( hdc );
950 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
954 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
956 dc->textColor = physdev->funcs->pSetTextColor( physdev, color );
957 release_dc_ptr( dc );
963 /***********************************************************************
964 * GetTextAlign (GDI32.@)
966 UINT WINAPI GetTextAlign( HDC hdc )
969 DC * dc = get_dc_ptr( hdc );
973 release_dc_ptr( dc );
979 /***********************************************************************
980 * SetTextAlign (GDI32.@)
982 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
984 UINT ret = GDI_ERROR;
985 DC *dc = get_dc_ptr( hdc );
987 TRACE("hdc=%p align=%d\n", hdc, align);
991 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
992 align = physdev->funcs->pSetTextAlign( physdev, align );
993 if (align != GDI_ERROR)
996 dc->textAlign = align;
998 release_dc_ptr( dc );
1003 /***********************************************************************
1004 * GetDCOrgEx (GDI32.@)
1006 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1010 if (!lpp) return FALSE;
1011 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1012 lpp->x = dc->vis_rect.left;
1013 lpp->y = dc->vis_rect.top;
1014 release_dc_ptr( dc );
1019 /***********************************************************************
1020 * GetGraphicsMode (GDI32.@)
1022 INT WINAPI GetGraphicsMode( HDC hdc )
1025 DC * dc = get_dc_ptr( hdc );
1028 ret = dc->GraphicsMode;
1029 release_dc_ptr( dc );
1035 /***********************************************************************
1036 * SetGraphicsMode (GDI32.@)
1038 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1041 DC *dc = get_dc_ptr( hdc );
1043 /* One would think that setting the graphics mode to GM_COMPATIBLE
1044 * would also reset the world transformation matrix to the unity
1045 * matrix. However, in Windows, this is not the case. This doesn't
1046 * make a lot of sense to me, but that's the way it is.
1049 if ((mode > 0) && (mode <= GM_LAST))
1051 ret = dc->GraphicsMode;
1052 dc->GraphicsMode = mode;
1054 release_dc_ptr( dc );
1059 /***********************************************************************
1060 * GetArcDirection (GDI32.@)
1062 INT WINAPI GetArcDirection( HDC hdc )
1065 DC * dc = get_dc_ptr( hdc );
1068 ret = dc->ArcDirection;
1069 release_dc_ptr( dc );
1075 /***********************************************************************
1076 * SetArcDirection (GDI32.@)
1078 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1083 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1085 SetLastError(ERROR_INVALID_PARAMETER);
1089 if ((dc = get_dc_ptr( hdc )))
1091 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1092 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1095 ret = dc->ArcDirection;
1096 dc->ArcDirection = dir;
1098 release_dc_ptr( dc );
1104 /***********************************************************************
1105 * GetWorldTransform (GDI32.@)
1107 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1110 if (!xform) return FALSE;
1111 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1112 *xform = dc->xformWorld2Wnd;
1113 release_dc_ptr( dc );
1118 /***********************************************************************
1119 * GetTransform (GDI32.@)
1123 * Returns one of the co-ordinate space transforms
1126 * hdc [I] Device context.
1127 * which [I] Which xform to return:
1128 * 0x203 World -> Page transform (that set by SetWorldTransform).
1129 * 0x304 Page -> Device transform (the mapping mode transform).
1130 * 0x204 World -> Device transform (the combination of the above two).
1131 * 0x402 Device -> World transform (the inversion of the above).
1132 * xform [O] The xform.
1135 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1138 DC *dc = get_dc_ptr( hdc );
1139 if (!dc) return FALSE;
1144 *xform = dc->xformWorld2Wnd;
1148 construct_window_to_viewport(dc, xform);
1152 *xform = dc->xformWorld2Vport;
1156 *xform = dc->xformVport2World;
1160 FIXME("Unknown code %x\n", which);
1164 release_dc_ptr( dc );
1169 /****************************************************************************
1170 * CombineTransform [GDI32.@]
1171 * Combines two transformation matrices.
1174 * xformResult [O] Stores the result of combining the two matrices
1175 * xform1 [I] Specifies the first matrix to apply
1176 * xform2 [I] Specifies the second matrix to apply
1179 * The same matrix can be passed in for more than one of the parameters.
1183 * Failure: FALSE. Use GetLastError() to determine the cause.
1185 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1186 const XFORM *xform2 )
1190 /* Check for illegal parameters */
1191 if (!xformResult || !xform1 || !xform2)
1194 /* Create the result in a temporary XFORM, since xformResult may be
1195 * equal to xform1 or xform2 */
1196 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1197 xform1->eM12 * xform2->eM21;
1198 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1199 xform1->eM12 * xform2->eM22;
1200 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1201 xform1->eM22 * xform2->eM21;
1202 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1203 xform1->eM22 * xform2->eM22;
1204 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1205 xform1->eDy * xform2->eM21 +
1207 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1208 xform1->eDy * xform2->eM22 +
1211 /* Copy the result to xformResult */
1212 *xformResult = xformTemp;
1218 /***********************************************************************
1219 * SetDCHook (GDI32.@)
1221 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1223 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1225 DC *dc = get_dc_ptr( hdc );
1227 if (!dc) return FALSE;
1229 dc->dwHookData = dwHookData;
1230 dc->hookProc = hookProc;
1231 release_dc_ptr( dc );
1236 /***********************************************************************
1237 * GetDCHook (GDI32.@)
1239 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1241 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1243 DC *dc = get_dc_ptr( hdc );
1247 if (proc) *proc = dc->hookProc;
1248 ret = dc->dwHookData;
1249 release_dc_ptr( dc );
1254 /***********************************************************************
1255 * SetHookFlags (GDI32.@)
1257 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1259 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1261 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1266 TRACE("hDC %p, flags %04x\n",hdc,flags);
1268 if (flags & DCHF_INVALIDATEVISRGN)
1269 ret = InterlockedExchange( &dc->dirty, 1 );
1270 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1271 ret = InterlockedExchange( &dc->dirty, 0 );
1273 GDI_ReleaseObj( hdc );
1275 if (flags & DCHF_RESETDC) ret = reset_dc_state( hdc );
1279 /***********************************************************************
1280 * SetICMMode (GDI32.@)
1282 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1284 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1285 if (iEnableICM == ICM_OFF) return ICM_OFF;
1286 if (iEnableICM == ICM_ON) return 0;
1287 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1291 /***********************************************************************
1292 * GetDeviceGammaRamp (GDI32.@)
1294 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1297 DC *dc = get_dc_ptr( hDC );
1299 TRACE("%p, %p\n", hDC, ptr);
1302 if (GetObjectType( hDC ) != OBJ_MEMDC)
1304 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1305 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1307 else SetLastError( ERROR_INVALID_PARAMETER );
1308 release_dc_ptr( dc );
1313 /***********************************************************************
1314 * SetDeviceGammaRamp (GDI32.@)
1316 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1319 DC *dc = get_dc_ptr( hDC );
1321 TRACE("%p, %p\n", hDC, ptr);
1324 if (GetObjectType( hDC ) != OBJ_MEMDC)
1326 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1327 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1329 else SetLastError( ERROR_INVALID_PARAMETER );
1330 release_dc_ptr( dc );
1335 /***********************************************************************
1336 * GetColorSpace (GDI32.@)
1338 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1340 /*FIXME Need to do whatever GetColorSpace actually does */
1344 /***********************************************************************
1345 * CreateColorSpaceA (GDI32.@)
1347 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1353 /***********************************************************************
1354 * CreateColorSpaceW (GDI32.@)
1356 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1362 /***********************************************************************
1363 * DeleteColorSpace (GDI32.@)
1365 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1372 /***********************************************************************
1373 * SetColorSpace (GDI32.@)
1375 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1382 /***********************************************************************
1383 * GetBoundsRect (GDI32.@)
1385 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1390 DC *dc = get_dc_ptr( hdc );
1392 if ( !dc ) return 0;
1394 physdev = GET_DC_PHYSDEV( dc, pGetBoundsRect );
1395 ret = physdev->funcs->pGetBoundsRect( physdev, &device_rect, DCB_RESET );
1398 release_dc_ptr( dc );
1401 if (dc->bounds_enabled && ret == DCB_SET) add_bounds_rect( &dc->bounds, &device_rect );
1405 if (is_rect_empty( &dc->bounds ))
1407 rect->left = rect->top = rect->right = rect->bottom = 0;
1413 rect->left = max( rect->left, 0 );
1414 rect->top = max( rect->top, 0 );
1415 rect->right = min( rect->right, dc->vis_rect.right - dc->vis_rect.left );
1416 rect->bottom = min( rect->bottom, dc->vis_rect.bottom - dc->vis_rect.top );
1419 DPtoLP( hdc, (POINT *)rect, 2 );
1423 if (flags & DCB_RESET) reset_bounds( &dc->bounds );
1424 release_dc_ptr( dc );
1429 /***********************************************************************
1430 * SetBoundsRect (GDI32.@)
1432 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1438 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1439 if (!(dc = get_dc_ptr( hdc ))) return 0;
1441 physdev = GET_DC_PHYSDEV( dc, pSetBoundsRect );
1442 ret = physdev->funcs->pSetBoundsRect( physdev, &dc->bounds, flags );
1445 release_dc_ptr( dc );
1449 ret = (dc->bounds_enabled ? DCB_ENABLE : DCB_DISABLE) |
1450 (is_rect_empty( &dc->bounds ) ? ret & DCB_SET : DCB_SET);
1452 if (flags & DCB_RESET) reset_bounds( &dc->bounds );
1454 if ((flags & DCB_ACCUMULATE) && rect)
1458 LPtoDP( hdc, (POINT *)&rc, 2 );
1459 add_bounds_rect( &dc->bounds, &rc );
1462 if (flags & DCB_ENABLE) dc->bounds_enabled = TRUE;
1463 if (flags & DCB_DISABLE) dc->bounds_enabled = FALSE;
1465 release_dc_ptr( dc );
1470 /***********************************************************************
1471 * GetRelAbs (GDI32.@)
1473 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1476 DC *dc = get_dc_ptr( hdc );
1479 ret = dc->relAbsMode;
1480 release_dc_ptr( dc );
1488 /***********************************************************************
1489 * GetBkMode (GDI32.@)
1491 INT WINAPI GetBkMode( HDC hdc )
1494 DC * dc = get_dc_ptr( hdc );
1497 ret = dc->backgroundMode;
1498 release_dc_ptr( dc );
1504 /***********************************************************************
1505 * SetBkMode (GDI32.@)
1507 INT WINAPI SetBkMode( HDC hdc, INT mode )
1512 if ((mode <= 0) || (mode > BKMODE_LAST))
1514 SetLastError(ERROR_INVALID_PARAMETER);
1517 if ((dc = get_dc_ptr( hdc )))
1519 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1520 mode = physdev->funcs->pSetBkMode( physdev, mode );
1523 ret = dc->backgroundMode;
1524 dc->backgroundMode = mode;
1526 release_dc_ptr( dc );
1532 /***********************************************************************
1535 INT WINAPI GetROP2( HDC hdc )
1538 DC * dc = get_dc_ptr( hdc );
1542 release_dc_ptr( dc );
1548 /***********************************************************************
1551 INT WINAPI SetROP2( HDC hdc, INT mode )
1556 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1558 SetLastError(ERROR_INVALID_PARAMETER);
1561 if ((dc = get_dc_ptr( hdc )))
1563 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1564 mode = physdev->funcs->pSetROP2( physdev, mode );
1570 release_dc_ptr( dc );
1576 /***********************************************************************
1577 * SetRelAbs (GDI32.@)
1579 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1584 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1586 SetLastError(ERROR_INVALID_PARAMETER);
1589 if ((dc = get_dc_ptr( hdc )))
1591 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1592 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1595 ret = dc->relAbsMode;
1596 dc->relAbsMode = mode;
1598 release_dc_ptr( dc );
1604 /***********************************************************************
1605 * GetPolyFillMode (GDI32.@)
1607 INT WINAPI GetPolyFillMode( HDC hdc )
1610 DC * dc = get_dc_ptr( hdc );
1613 ret = dc->polyFillMode;
1614 release_dc_ptr( dc );
1620 /***********************************************************************
1621 * SetPolyFillMode (GDI32.@)
1623 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1628 if ((mode <= 0) || (mode > POLYFILL_LAST))
1630 SetLastError(ERROR_INVALID_PARAMETER);
1633 if ((dc = get_dc_ptr( hdc )))
1635 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1636 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1639 ret = dc->polyFillMode;
1640 dc->polyFillMode = mode;
1642 release_dc_ptr( dc );
1648 /***********************************************************************
1649 * GetStretchBltMode (GDI32.@)
1651 INT WINAPI GetStretchBltMode( HDC hdc )
1654 DC * dc = get_dc_ptr( hdc );
1657 ret = dc->stretchBltMode;
1658 release_dc_ptr( dc );
1664 /***********************************************************************
1665 * SetStretchBltMode (GDI32.@)
1667 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1672 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1674 SetLastError(ERROR_INVALID_PARAMETER);
1677 if ((dc = get_dc_ptr( hdc )))
1679 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1680 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1683 ret = dc->stretchBltMode;
1684 dc->stretchBltMode = mode;
1686 release_dc_ptr( dc );
1692 /***********************************************************************
1693 * GetMapMode (GDI32.@)
1695 INT WINAPI GetMapMode( HDC hdc )
1698 DC * dc = get_dc_ptr( hdc );
1702 release_dc_ptr( dc );
1708 /***********************************************************************
1709 * GetBrushOrgEx (GDI32.@)
1711 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1713 DC * dc = get_dc_ptr( hdc );
1714 if (!dc) return FALSE;
1715 pt->x = dc->brushOrgX;
1716 pt->y = dc->brushOrgY;
1717 release_dc_ptr( dc );
1722 /***********************************************************************
1723 * GetCurrentPositionEx (GDI32.@)
1725 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1727 DC * dc = get_dc_ptr( hdc );
1728 if (!dc) return FALSE;
1729 pt->x = dc->CursPosX;
1730 pt->y = dc->CursPosY;
1731 release_dc_ptr( dc );
1736 /***********************************************************************
1737 * GetViewportExtEx (GDI32.@)
1739 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1741 DC * dc = get_dc_ptr( hdc );
1742 if (!dc) return FALSE;
1743 size->cx = dc->vportExtX;
1744 size->cy = dc->vportExtY;
1745 release_dc_ptr( dc );
1750 /***********************************************************************
1751 * GetViewportOrgEx (GDI32.@)
1753 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1755 DC * dc = get_dc_ptr( hdc );
1756 if (!dc) return FALSE;
1757 pt->x = dc->vportOrgX;
1758 pt->y = dc->vportOrgY;
1759 release_dc_ptr( dc );
1764 /***********************************************************************
1765 * GetWindowExtEx (GDI32.@)
1767 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1769 DC * dc = get_dc_ptr( hdc );
1770 if (!dc) return FALSE;
1771 size->cx = dc->wndExtX;
1772 size->cy = dc->wndExtY;
1773 release_dc_ptr( dc );
1778 /***********************************************************************
1779 * GetWindowOrgEx (GDI32.@)
1781 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1783 DC * dc = get_dc_ptr( hdc );
1784 if (!dc) return FALSE;
1785 pt->x = dc->wndOrgX;
1786 pt->y = dc->wndOrgY;
1787 release_dc_ptr( dc );
1792 /***********************************************************************
1793 * GetLayout (GDI32.@)
1795 * Gets left->right or right->left text layout flags of a dc.
1798 DWORD WINAPI GetLayout(HDC hdc)
1800 DWORD layout = GDI_ERROR;
1802 DC * dc = get_dc_ptr( hdc );
1805 layout = dc->layout;
1806 release_dc_ptr( dc );
1809 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1814 /***********************************************************************
1815 * SetLayout (GDI32.@)
1817 * Sets left->right or right->left text layout flags of a dc.
1820 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1822 DWORD oldlayout = GDI_ERROR;
1824 DC * dc = get_dc_ptr( hdc );
1827 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1828 layout = physdev->funcs->pSetLayout( physdev, layout );
1829 if (layout != GDI_ERROR)
1831 oldlayout = dc->layout;
1832 dc->layout = layout;
1833 if (layout != oldlayout)
1835 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1836 DC_UpdateXforms( dc );
1839 release_dc_ptr( dc );
1842 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1847 /***********************************************************************
1848 * GetDCBrushColor (GDI32.@)
1850 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1853 COLORREF dcBrushColor = CLR_INVALID;
1855 TRACE("hdc(%p)\n", hdc);
1857 dc = get_dc_ptr( hdc );
1860 dcBrushColor = dc->dcBrushColor;
1861 release_dc_ptr( dc );
1864 return dcBrushColor;
1867 /***********************************************************************
1868 * SetDCBrushColor (GDI32.@)
1870 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1873 COLORREF oldClr = CLR_INVALID;
1875 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1877 dc = get_dc_ptr( hdc );
1880 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCBrushColor );
1881 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1882 if (crColor != CLR_INVALID)
1884 oldClr = dc->dcBrushColor;
1885 dc->dcBrushColor = crColor;
1887 release_dc_ptr( dc );
1893 /***********************************************************************
1894 * GetDCPenColor (GDI32.@)
1896 COLORREF WINAPI GetDCPenColor(HDC hdc)
1899 COLORREF dcPenColor = CLR_INVALID;
1901 TRACE("hdc(%p)\n", hdc);
1903 dc = get_dc_ptr( hdc );
1906 dcPenColor = dc->dcPenColor;
1907 release_dc_ptr( dc );
1913 /***********************************************************************
1914 * SetDCPenColor (GDI32.@)
1916 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1919 COLORREF oldClr = CLR_INVALID;
1921 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1923 dc = get_dc_ptr( hdc );
1926 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1927 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1928 if (crColor != CLR_INVALID)
1930 oldClr = dc->dcPenColor;
1931 dc->dcPenColor = crColor;
1933 release_dc_ptr( dc );
1939 /***********************************************************************
1940 * CancelDC (GDI32.@)
1942 BOOL WINAPI CancelDC(HDC hdc)
1948 /*******************************************************************
1949 * GetMiterLimit [GDI32.@]
1953 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1958 TRACE("(%p,%p)\n", hdc, peLimit);
1960 dc = get_dc_ptr( hdc );
1964 *peLimit = dc->miterLimit;
1966 release_dc_ptr( dc );
1972 /*******************************************************************
1973 * SetMiterLimit [GDI32.@]
1977 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1982 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1984 dc = get_dc_ptr( hdc );
1988 *peOldLimit = dc->miterLimit;
1989 dc->miterLimit = eNewLimit;
1990 release_dc_ptr( dc );
1996 /*******************************************************************
1997 * GdiIsMetaPrintDC [GDI32.@]
1999 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2005 /*******************************************************************
2006 * GdiIsMetaFileDC [GDI32.@]
2008 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2012 switch( GetObjectType( hdc ) )
2021 /*******************************************************************
2022 * GdiIsPlayMetafileDC [GDI32.@]
2024 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)