2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "gdi_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dc);
39 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
41 static BOOL DC_DeleteObject( HGDIOBJ handle );
43 static const struct gdi_obj_funcs dc_funcs =
45 NULL, /* pSelectObject */
46 NULL, /* pGetObjectA */
47 NULL, /* pGetObjectW */
48 NULL, /* pUnrealizeObject */
49 DC_DeleteObject /* pDeleteObject */
53 static inline DC *get_dc_obj( HDC hdc )
55 DC *dc = GDI_GetObjPtr( hdc, 0 );
58 if ((dc->header.type != OBJ_DC) &&
59 (dc->header.type != OBJ_MEMDC) &&
60 (dc->header.type != OBJ_METADC) &&
61 (dc->header.type != OBJ_ENHMETADC))
63 GDI_ReleaseObj( hdc );
64 SetLastError( ERROR_INVALID_HANDLE );
71 /***********************************************************************
74 DC *alloc_dc_ptr( WORD magic )
78 if (!(dc = HeapAlloc( GetProcessHeap(), 0, sizeof(*dc) ))) return NULL;
80 dc->nulldrv.funcs = &null_driver;
81 dc->nulldrv.next = NULL;
83 dc->physDev = &dc->nulldrv;
84 dc->thread = GetCurrentThreadId();
99 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
104 dc->hMetaClipRgn = 0;
106 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
107 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
108 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
111 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
113 dc->font_code_page = CP_ACP;
114 dc->ROPmode = R2_COPYPEN;
115 dc->polyFillMode = ALTERNATE;
116 dc->stretchBltMode = BLACKONWHITE;
117 dc->relAbsMode = ABSOLUTE;
118 dc->backgroundMode = OPAQUE;
119 dc->backgroundColor = RGB( 255, 255, 255 );
120 dc->dcBrushColor = RGB( 255, 255, 255 );
121 dc->dcPenColor = RGB( 0, 0, 0 );
122 dc->textColor = RGB( 0, 0, 0 );
126 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
130 dc->MapMode = MM_TEXT;
131 dc->GraphicsMode = GM_COMPATIBLE;
132 dc->pAbortProc = NULL;
135 dc->ArcDirection = AD_COUNTERCLOCKWISE;
136 dc->xformWorld2Wnd.eM11 = 1.0f;
137 dc->xformWorld2Wnd.eM12 = 0.0f;
138 dc->xformWorld2Wnd.eM21 = 0.0f;
139 dc->xformWorld2Wnd.eM22 = 1.0f;
140 dc->xformWorld2Wnd.eDx = 0.0f;
141 dc->xformWorld2Wnd.eDy = 0.0f;
142 dc->xformWorld2Vport = dc->xformWorld2Wnd;
143 dc->xformVport2World = dc->xformWorld2Wnd;
144 dc->vport2WorldValid = TRUE;
145 dc->BoundsRect.left = 0;
146 dc->BoundsRect.top = 0;
147 dc->BoundsRect.right = 0;
148 dc->BoundsRect.bottom = 0;
149 PATH_InitGdiPath(&dc->path);
151 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
153 HeapFree( GetProcessHeap(), 0, dc );
156 dc->nulldrv.hdc = dc->hSelf;
158 if (font_driver && !font_driver->pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL ))
168 /***********************************************************************
171 static void free_dc_state( DC *dc )
173 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
174 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
175 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
176 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
177 PATH_DestroyGdiPath( &dc->path );
178 HeapFree( GetProcessHeap(), 0, dc );
182 /***********************************************************************
185 void free_dc_ptr( DC *dc )
187 assert( dc->refcount == 1 );
189 while (dc->physDev != &dc->nulldrv)
191 PHYSDEV physdev = pop_dc_driver( &dc->physDev );
192 physdev->funcs->pDeleteDC( physdev );
193 if (physdev == dc->dibdrv) dc->dibdrv = NULL;
195 if (dc->dibdrv) dc->dibdrv->funcs->pDeleteDC( dc->dibdrv );
196 free_gdi_handle( dc->hSelf );
201 /***********************************************************************
204 * Retrieve a DC pointer but release the GDI lock.
206 DC *get_dc_ptr( HDC hdc )
208 DC *dc = get_dc_obj( hdc );
209 if (!dc) return NULL;
211 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
213 dc->thread = GetCurrentThreadId();
215 else if (dc->thread != GetCurrentThreadId())
217 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
218 GDI_ReleaseObj( hdc );
221 else InterlockedIncrement( &dc->refcount );
223 GDI_ReleaseObj( hdc );
228 /***********************************************************************
231 void release_dc_ptr( DC *dc )
236 ref = InterlockedDecrement( &dc->refcount );
238 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
242 /***********************************************************************
245 * Make sure the DC vis region is up to date.
246 * This function may call up to USER so the GDI lock should _not_
247 * be held when calling it.
249 void update_dc( DC *dc )
251 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
252 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
256 /***********************************************************************
259 static BOOL DC_DeleteObject( HGDIOBJ handle )
261 return DeleteDC( handle );
265 /***********************************************************************
268 * Setup device-specific DC values for a newly created DC.
270 void DC_InitDC( DC* dc )
272 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
273 physdev->funcs->pRealizeDefaultPalette( physdev );
274 SetTextColor( dc->hSelf, dc->textColor );
275 SetBkColor( dc->hSelf, dc->backgroundColor );
276 SelectObject( dc->hSelf, dc->hPen );
277 SelectObject( dc->hSelf, dc->hBrush );
278 SelectObject( dc->hSelf, dc->hFont );
279 CLIPPING_UpdateGCRegion( dc );
280 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
284 /***********************************************************************
287 * Computes the inverse of the transformation xformSrc and stores it to
288 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
291 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
295 determinant = xformSrc->eM11*xformSrc->eM22 -
296 xformSrc->eM12*xformSrc->eM21;
297 if (determinant > -1e-12 && determinant < 1e-12)
300 xformDest->eM11 = xformSrc->eM22 / determinant;
301 xformDest->eM12 = -xformSrc->eM12 / determinant;
302 xformDest->eM21 = -xformSrc->eM21 / determinant;
303 xformDest->eM22 = xformSrc->eM11 / determinant;
304 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
305 xformSrc->eDy * xformDest->eM21;
306 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
307 xformSrc->eDy * xformDest->eM22;
312 /* Construct a transformation to do the window-to-viewport conversion */
313 static void construct_window_to_viewport(DC *dc, XFORM *xform)
315 double scaleX, scaleY;
316 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
317 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
319 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
320 xform->eM11 = scaleX;
323 xform->eM22 = scaleY;
324 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
325 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
326 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
329 /***********************************************************************
332 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
333 * fields of the specified DC by creating a transformation that
334 * represents the current mapping mode and combining it with the DC's
335 * world transform. This function should be called whenever the
336 * parameters associated with the mapping mode (window and viewport
337 * extents and origins) or the world transform change.
339 void DC_UpdateXforms( DC *dc )
341 XFORM xformWnd2Vport, oldworld2vport;
343 construct_window_to_viewport(dc, &xformWnd2Vport);
345 oldworld2vport = dc->xformWorld2Vport;
346 /* Combine with the world transformation */
347 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
350 /* Create inverse of world-to-viewport transformation */
351 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
352 &dc->xformVport2World );
354 /* Reselect the font and pen back into the dc so that the size
356 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
357 !GdiIsMetaFileDC(dc->hSelf))
359 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
360 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
365 /***********************************************************************
368 INT nulldrv_SaveDC( PHYSDEV dev )
370 DC *newdc, *dc = get_nulldrv_dc( dev );
372 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc )))) return 0;
373 newdc->flags = dc->flags;
374 newdc->layout = dc->layout;
375 newdc->hPen = dc->hPen;
376 newdc->hBrush = dc->hBrush;
377 newdc->hFont = dc->hFont;
378 newdc->hBitmap = dc->hBitmap;
379 newdc->hDevice = dc->hDevice;
380 newdc->hPalette = dc->hPalette;
381 newdc->ROPmode = dc->ROPmode;
382 newdc->polyFillMode = dc->polyFillMode;
383 newdc->stretchBltMode = dc->stretchBltMode;
384 newdc->relAbsMode = dc->relAbsMode;
385 newdc->backgroundMode = dc->backgroundMode;
386 newdc->backgroundColor = dc->backgroundColor;
387 newdc->textColor = dc->textColor;
388 newdc->dcBrushColor = dc->dcBrushColor;
389 newdc->dcPenColor = dc->dcPenColor;
390 newdc->brushOrgX = dc->brushOrgX;
391 newdc->brushOrgY = dc->brushOrgY;
392 newdc->mapperFlags = dc->mapperFlags;
393 newdc->textAlign = dc->textAlign;
394 newdc->charExtra = dc->charExtra;
395 newdc->breakExtra = dc->breakExtra;
396 newdc->breakRem = dc->breakRem;
397 newdc->MapMode = dc->MapMode;
398 newdc->GraphicsMode = dc->GraphicsMode;
399 newdc->CursPosX = dc->CursPosX;
400 newdc->CursPosY = dc->CursPosY;
401 newdc->ArcDirection = dc->ArcDirection;
402 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
403 newdc->xformWorld2Vport = dc->xformWorld2Vport;
404 newdc->xformVport2World = dc->xformVport2World;
405 newdc->vport2WorldValid = dc->vport2WorldValid;
406 newdc->wndOrgX = dc->wndOrgX;
407 newdc->wndOrgY = dc->wndOrgY;
408 newdc->wndExtX = dc->wndExtX;
409 newdc->wndExtY = dc->wndExtY;
410 newdc->vportOrgX = dc->vportOrgX;
411 newdc->vportOrgY = dc->vportOrgY;
412 newdc->vportExtX = dc->vportExtX;
413 newdc->vportExtY = dc->vportExtY;
414 newdc->virtual_res = dc->virtual_res;
415 newdc->virtual_size = dc->virtual_size;
416 newdc->BoundsRect = dc->BoundsRect;
417 newdc->gdiFont = dc->gdiFont;
419 PATH_InitGdiPath( &newdc->path );
421 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
426 newdc->hMetaClipRgn = 0;
429 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
430 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
434 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
435 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
438 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
440 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
442 release_dc_ptr( dc );
443 free_dc_state( newdc );
447 newdc->saved_dc = dc->saved_dc;
448 dc->saved_dc = newdc;
449 return ++dc->saveLevel;
453 /***********************************************************************
456 BOOL nulldrv_RestoreDC( PHYSDEV dev, INT level )
458 DC *dcs, *first_dcs, *dc = get_nulldrv_dc( dev );
461 /* find the state level to restore */
463 if (abs(level) > dc->saveLevel || level == 0) return FALSE;
464 if (level < 0) level = dc->saveLevel + level + 1;
465 first_dcs = dc->saved_dc;
466 for (dcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
469 /* restore the state */
471 if (!PATH_AssignGdiPath( &dc->path, &dcs->path )) return FALSE;
473 dc->flags = dcs->flags;
474 dc->layout = dcs->layout;
475 dc->hDevice = dcs->hDevice;
476 dc->ROPmode = dcs->ROPmode;
477 dc->polyFillMode = dcs->polyFillMode;
478 dc->stretchBltMode = dcs->stretchBltMode;
479 dc->relAbsMode = dcs->relAbsMode;
480 dc->backgroundMode = dcs->backgroundMode;
481 dc->backgroundColor = dcs->backgroundColor;
482 dc->textColor = dcs->textColor;
483 dc->dcBrushColor = dcs->dcBrushColor;
484 dc->dcPenColor = dcs->dcPenColor;
485 dc->brushOrgX = dcs->brushOrgX;
486 dc->brushOrgY = dcs->brushOrgY;
487 dc->mapperFlags = dcs->mapperFlags;
488 dc->textAlign = dcs->textAlign;
489 dc->charExtra = dcs->charExtra;
490 dc->breakExtra = dcs->breakExtra;
491 dc->breakRem = dcs->breakRem;
492 dc->MapMode = dcs->MapMode;
493 dc->GraphicsMode = dcs->GraphicsMode;
494 dc->CursPosX = dcs->CursPosX;
495 dc->CursPosY = dcs->CursPosY;
496 dc->ArcDirection = dcs->ArcDirection;
497 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
498 dc->xformWorld2Vport = dcs->xformWorld2Vport;
499 dc->xformVport2World = dcs->xformVport2World;
500 dc->vport2WorldValid = dcs->vport2WorldValid;
501 dc->BoundsRect = dcs->BoundsRect;
503 dc->wndOrgX = dcs->wndOrgX;
504 dc->wndOrgY = dcs->wndOrgY;
505 dc->wndExtX = dcs->wndExtX;
506 dc->wndExtY = dcs->wndExtY;
507 dc->vportOrgX = dcs->vportOrgX;
508 dc->vportOrgY = dcs->vportOrgY;
509 dc->vportExtX = dcs->vportExtX;
510 dc->vportExtY = dcs->vportExtY;
511 dc->virtual_res = dcs->virtual_res;
512 dc->virtual_size = dcs->virtual_size;
516 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
517 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
521 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
526 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
527 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
531 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
534 DC_UpdateXforms( dc );
535 CLIPPING_UpdateGCRegion( dc );
537 SelectObject( dev->hdc, dcs->hBitmap );
538 SelectObject( dev->hdc, dcs->hBrush );
539 SelectObject( dev->hdc, dcs->hFont );
540 SelectObject( dev->hdc, dcs->hPen );
541 SetBkColor( dev->hdc, dcs->backgroundColor);
542 SetTextColor( dev->hdc, dcs->textColor);
543 GDISelectPalette( dev->hdc, dcs->hPalette, FALSE );
545 dc->saved_dc = dcs->saved_dc;
547 dc->saveLevel = save_level - 1;
549 /* now destroy all the saved DCs */
553 DC *next = first_dcs->saved_dc;
554 free_dc_state( first_dcs );
561 /***********************************************************************
564 INT WINAPI SaveDC( HDC hdc )
569 if ((dc = get_dc_ptr( hdc )))
571 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSaveDC );
572 ret = physdev->funcs->pSaveDC( physdev );
573 release_dc_ptr( dc );
579 /***********************************************************************
580 * RestoreDC (GDI32.@)
582 BOOL WINAPI RestoreDC( HDC hdc, INT level )
585 BOOL success = FALSE;
587 TRACE("%p %d\n", hdc, level );
588 if ((dc = get_dc_ptr( hdc )))
590 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRestoreDC );
592 success = physdev->funcs->pRestoreDC( physdev, level );
593 release_dc_ptr( dc );
599 /***********************************************************************
600 * CreateDCW (GDI32.@)
602 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
603 const DEVMODEW *initData )
607 const struct gdi_dc_funcs *funcs;
612 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
616 ERR( "no device found for %s\n", debugstr_w(device) );
619 strcpyW(buf, driver);
622 if (!(funcs = DRIVER_load_driver( buf )))
624 ERR( "no driver found for %s\n", debugstr_w(buf) );
627 if (!(dc = alloc_dc_ptr( OBJ_DC ))) goto error;
630 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
631 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
633 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
634 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
636 if (funcs->pCreateDC)
638 if (!funcs->pCreateDC( &dc->physDev, buf, device, output, initData ))
640 WARN("creation aborted by device\n" );
645 dc->vis_rect.left = 0;
646 dc->vis_rect.top = 0;
647 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
648 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
649 SetRectRgn(dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top, dc->vis_rect.right, dc->vis_rect.bottom);
652 release_dc_ptr( dc );
656 if (dc) free_dc_ptr( dc );
661 /***********************************************************************
662 * CreateDCA (GDI32.@)
664 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
665 const DEVMODEA *initData )
667 UNICODE_STRING driverW, deviceW, outputW;
671 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
672 else driverW.Buffer = NULL;
674 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
675 else deviceW.Buffer = NULL;
677 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
678 else outputW.Buffer = NULL;
683 /* don't convert initData for DISPLAY driver, it's not used */
684 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
685 initDataW = GdiConvertToDevmodeW(initData);
688 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
690 RtlFreeUnicodeString(&driverW);
691 RtlFreeUnicodeString(&deviceW);
692 RtlFreeUnicodeString(&outputW);
693 HeapFree(GetProcessHeap(), 0, initDataW);
698 /***********************************************************************
699 * CreateICA (GDI32.@)
701 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
702 const DEVMODEA* initData )
704 /* Nothing special yet for ICs */
705 return CreateDCA( driver, device, output, initData );
709 /***********************************************************************
710 * CreateICW (GDI32.@)
712 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
713 const DEVMODEW* initData )
715 /* Nothing special yet for ICs */
716 return CreateDCW( driver, device, output, initData );
720 /***********************************************************************
721 * CreateCompatibleDC (GDI32.@)
723 HDC WINAPI CreateCompatibleDC( HDC hdc )
727 const struct gdi_dc_funcs *funcs = &null_driver;
728 PHYSDEV physDev = NULL;
734 if (!(origDC = get_dc_ptr( hdc ))) return 0;
735 physDev = GET_DC_PHYSDEV( origDC, pCreateCompatibleDC );
736 funcs = physDev->funcs;
737 release_dc_ptr( origDC );
740 if (!(dc = alloc_dc_ptr( OBJ_MEMDC ))) goto error;
742 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
744 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
745 dc->vis_rect.left = 0;
746 dc->vis_rect.top = 0;
747 dc->vis_rect.right = 1;
748 dc->vis_rect.bottom = 1;
749 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
753 if (!funcs->pCreateCompatibleDC( physDev, &dc->physDev ))
755 WARN("creation aborted by device\n");
759 release_dc_ptr( dc );
763 if (dc) free_dc_ptr( dc );
768 /***********************************************************************
771 BOOL WINAPI DeleteDC( HDC hdc )
779 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
780 if (dc->refcount != 1)
782 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
783 release_dc_ptr( dc );
787 /* Call hook procedure to check whether is it OK to delete this DC */
788 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
790 release_dc_ptr( dc );
794 while (dc->saveLevel)
796 DC *dcs = dc->saved_dc;
797 dc->saved_dc = dcs->saved_dc;
799 free_dc_state( dcs );
802 SelectObject( hdc, GetStockObject(BLACK_PEN) );
803 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
804 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
805 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
812 /***********************************************************************
815 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
820 if ((dc = get_dc_ptr( hdc )))
822 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
823 ret = physdev->funcs->pResetDC( physdev, devmode );
824 if (ret) /* reset the visible region */
827 dc->vis_rect.left = 0;
828 dc->vis_rect.top = 0;
829 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
830 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
831 SetRectRgn( dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top,
832 dc->vis_rect.right, dc->vis_rect.bottom );
833 CLIPPING_UpdateGCRegion( dc );
835 release_dc_ptr( dc );
841 /***********************************************************************
844 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
849 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
850 else devmodeW = NULL;
852 ret = ResetDCW(hdc, devmodeW);
854 HeapFree(GetProcessHeap(), 0, devmodeW);
859 /***********************************************************************
860 * GetDeviceCaps (GDI32.@)
862 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
867 if ((dc = get_dc_ptr( hdc )))
869 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
870 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
871 release_dc_ptr( dc );
877 /***********************************************************************
878 * GetBkColor (GDI32.@)
880 COLORREF WINAPI GetBkColor( HDC hdc )
883 DC * dc = get_dc_ptr( hdc );
886 ret = dc->backgroundColor;
887 release_dc_ptr( dc );
893 /***********************************************************************
894 * SetBkColor (GDI32.@)
896 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
898 COLORREF ret = CLR_INVALID;
899 DC * dc = get_dc_ptr( hdc );
901 TRACE("hdc=%p color=0x%08x\n", hdc, color);
905 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
906 color = physdev->funcs->pSetBkColor( physdev, color );
907 if (color != CLR_INVALID)
909 ret = dc->backgroundColor;
910 dc->backgroundColor = color;
912 release_dc_ptr( dc );
918 /***********************************************************************
919 * GetTextColor (GDI32.@)
921 COLORREF WINAPI GetTextColor( HDC hdc )
924 DC * dc = get_dc_ptr( hdc );
928 release_dc_ptr( dc );
934 /***********************************************************************
935 * SetTextColor (GDI32.@)
937 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
939 COLORREF ret = CLR_INVALID;
940 DC * dc = get_dc_ptr( hdc );
942 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
946 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
947 color = physdev->funcs->pSetTextColor( physdev, color );
948 if (color != CLR_INVALID)
951 dc->textColor = color;
953 release_dc_ptr( dc );
959 /***********************************************************************
960 * GetTextAlign (GDI32.@)
962 UINT WINAPI GetTextAlign( HDC hdc )
965 DC * dc = get_dc_ptr( hdc );
969 release_dc_ptr( dc );
975 /***********************************************************************
976 * SetTextAlign (GDI32.@)
978 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
980 UINT ret = GDI_ERROR;
981 DC *dc = get_dc_ptr( hdc );
983 TRACE("hdc=%p align=%d\n", hdc, align);
987 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
988 align = physdev->funcs->pSetTextAlign( physdev, align );
989 if (align != GDI_ERROR)
992 dc->textAlign = align;
994 release_dc_ptr( dc );
999 /***********************************************************************
1000 * GetDCOrgEx (GDI32.@)
1002 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1006 if (!lpp) return FALSE;
1007 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1008 lpp->x = dc->vis_rect.left;
1009 lpp->y = dc->vis_rect.top;
1010 release_dc_ptr( dc );
1015 /***********************************************************************
1016 * GetGraphicsMode (GDI32.@)
1018 INT WINAPI GetGraphicsMode( HDC hdc )
1021 DC * dc = get_dc_ptr( hdc );
1024 ret = dc->GraphicsMode;
1025 release_dc_ptr( dc );
1031 /***********************************************************************
1032 * SetGraphicsMode (GDI32.@)
1034 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1037 DC *dc = get_dc_ptr( hdc );
1039 /* One would think that setting the graphics mode to GM_COMPATIBLE
1040 * would also reset the world transformation matrix to the unity
1041 * matrix. However, in Windows, this is not the case. This doesn't
1042 * make a lot of sense to me, but that's the way it is.
1045 if ((mode > 0) && (mode <= GM_LAST))
1047 ret = dc->GraphicsMode;
1048 dc->GraphicsMode = mode;
1050 release_dc_ptr( dc );
1055 /***********************************************************************
1056 * GetArcDirection (GDI32.@)
1058 INT WINAPI GetArcDirection( HDC hdc )
1061 DC * dc = get_dc_ptr( hdc );
1064 ret = dc->ArcDirection;
1065 release_dc_ptr( dc );
1071 /***********************************************************************
1072 * SetArcDirection (GDI32.@)
1074 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1079 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1081 SetLastError(ERROR_INVALID_PARAMETER);
1085 if ((dc = get_dc_ptr( hdc )))
1087 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1088 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1091 ret = dc->ArcDirection;
1092 dc->ArcDirection = dir;
1094 release_dc_ptr( dc );
1100 /***********************************************************************
1101 * GetWorldTransform (GDI32.@)
1103 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1106 if (!xform) return FALSE;
1107 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1108 *xform = dc->xformWorld2Wnd;
1109 release_dc_ptr( dc );
1114 /***********************************************************************
1115 * GetTransform (GDI32.@)
1119 * Returns one of the co-ordinate space transforms
1122 * hdc [I] Device context.
1123 * which [I] Which xform to return:
1124 * 0x203 World -> Page transform (that set by SetWorldTransform).
1125 * 0x304 Page -> Device transform (the mapping mode transform).
1126 * 0x204 World -> Device transform (the combination of the above two).
1127 * 0x402 Device -> World transform (the inversion of the above).
1128 * xform [O] The xform.
1131 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1134 DC *dc = get_dc_ptr( hdc );
1135 if (!dc) return FALSE;
1140 *xform = dc->xformWorld2Wnd;
1144 construct_window_to_viewport(dc, xform);
1148 *xform = dc->xformWorld2Vport;
1152 *xform = dc->xformVport2World;
1156 FIXME("Unknown code %x\n", which);
1160 release_dc_ptr( dc );
1165 /****************************************************************************
1166 * CombineTransform [GDI32.@]
1167 * Combines two transformation matrices.
1170 * xformResult [O] Stores the result of combining the two matrices
1171 * xform1 [I] Specifies the first matrix to apply
1172 * xform2 [I] Specifies the second matrix to apply
1175 * The same matrix can be passed in for more than one of the parameters.
1179 * Failure: FALSE. Use GetLastError() to determine the cause.
1181 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1182 const XFORM *xform2 )
1186 /* Check for illegal parameters */
1187 if (!xformResult || !xform1 || !xform2)
1190 /* Create the result in a temporary XFORM, since xformResult may be
1191 * equal to xform1 or xform2 */
1192 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1193 xform1->eM12 * xform2->eM21;
1194 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1195 xform1->eM12 * xform2->eM22;
1196 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1197 xform1->eM22 * xform2->eM21;
1198 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1199 xform1->eM22 * xform2->eM22;
1200 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1201 xform1->eDy * xform2->eM21 +
1203 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1204 xform1->eDy * xform2->eM22 +
1207 /* Copy the result to xformResult */
1208 *xformResult = xformTemp;
1214 /***********************************************************************
1215 * SetDCHook (GDI32.@)
1217 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1219 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1221 DC *dc = get_dc_ptr( hdc );
1223 if (!dc) return FALSE;
1225 dc->dwHookData = dwHookData;
1226 dc->hookProc = hookProc;
1227 release_dc_ptr( dc );
1232 /***********************************************************************
1233 * GetDCHook (GDI32.@)
1235 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1237 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1239 DC *dc = get_dc_ptr( hdc );
1243 if (proc) *proc = dc->hookProc;
1244 ret = dc->dwHookData;
1245 release_dc_ptr( dc );
1250 /***********************************************************************
1251 * SetHookFlags (GDI32.@)
1253 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1255 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1257 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1262 /* "Undocumented Windows" info is slightly confusing. */
1264 TRACE("hDC %p, flags %04x\n",hdc,flags);
1266 if (flags & DCHF_INVALIDATEVISRGN)
1267 ret = InterlockedExchange( &dc->dirty, 1 );
1268 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1269 ret = InterlockedExchange( &dc->dirty, 0 );
1271 GDI_ReleaseObj( hdc );
1275 /***********************************************************************
1276 * SetICMMode (GDI32.@)
1278 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1280 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1281 if (iEnableICM == ICM_OFF) return ICM_OFF;
1282 if (iEnableICM == ICM_ON) return 0;
1283 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1287 /***********************************************************************
1288 * GetDeviceGammaRamp (GDI32.@)
1290 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1293 DC *dc = get_dc_ptr( hDC );
1295 TRACE("%p, %p\n", hDC, ptr);
1298 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1299 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1300 release_dc_ptr( dc );
1305 /***********************************************************************
1306 * SetDeviceGammaRamp (GDI32.@)
1308 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1311 DC *dc = get_dc_ptr( hDC );
1313 TRACE("%p, %p\n", hDC, ptr);
1316 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1317 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1318 release_dc_ptr( dc );
1323 /***********************************************************************
1324 * GetColorSpace (GDI32.@)
1326 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1328 /*FIXME Need to do whatever GetColorSpace actually does */
1332 /***********************************************************************
1333 * CreateColorSpaceA (GDI32.@)
1335 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1341 /***********************************************************************
1342 * CreateColorSpaceW (GDI32.@)
1344 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1350 /***********************************************************************
1351 * DeleteColorSpace (GDI32.@)
1353 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1360 /***********************************************************************
1361 * SetColorSpace (GDI32.@)
1363 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1370 /***********************************************************************
1371 * GetBoundsRect (GDI32.@)
1373 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1376 DC *dc = get_dc_ptr( hdc );
1378 if ( !dc ) return 0;
1382 *rect = dc->BoundsRect;
1383 ret = is_rect_empty( rect ) ? DCB_RESET : DCB_SET;
1384 DPtoLP( hdc, (POINT *)rect, 2 );
1386 if (flags & DCB_RESET)
1388 dc->BoundsRect.left = 0;
1389 dc->BoundsRect.top = 0;
1390 dc->BoundsRect.right = 0;
1391 dc->BoundsRect.bottom = 0;
1393 release_dc_ptr( dc );
1398 /***********************************************************************
1399 * SetBoundsRect (GDI32.@)
1401 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1406 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1407 if (!(dc = get_dc_ptr( hdc ))) return 0;
1409 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1410 (is_rect_empty( &dc->BoundsRect ) ? DCB_RESET : DCB_SET);
1412 if (flags & DCB_RESET)
1414 dc->BoundsRect.left = 0;
1415 dc->BoundsRect.top = 0;
1416 dc->BoundsRect.right = 0;
1417 dc->BoundsRect.bottom = 0;
1420 if ((flags & DCB_ACCUMULATE) && rect)
1424 LPtoDP( hdc, (POINT *)&rc, 2 );
1425 if (!is_rect_empty( &rc ))
1427 if (!is_rect_empty( &dc->BoundsRect))
1429 dc->BoundsRect.left = min( dc->BoundsRect.left, rc.left );
1430 dc->BoundsRect.top = min( dc->BoundsRect.top, rc.top );
1431 dc->BoundsRect.right = max( dc->BoundsRect.right, rc.right );
1432 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rc.bottom );
1434 else dc->BoundsRect = rc;
1438 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1439 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1441 release_dc_ptr( dc );
1446 /***********************************************************************
1447 * GetRelAbs (GDI32.@)
1449 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1452 DC *dc = get_dc_ptr( hdc );
1455 ret = dc->relAbsMode;
1456 release_dc_ptr( dc );
1464 /***********************************************************************
1465 * GetBkMode (GDI32.@)
1467 INT WINAPI GetBkMode( HDC hdc )
1470 DC * dc = get_dc_ptr( hdc );
1473 ret = dc->backgroundMode;
1474 release_dc_ptr( dc );
1480 /***********************************************************************
1481 * SetBkMode (GDI32.@)
1483 INT WINAPI SetBkMode( HDC hdc, INT mode )
1488 if ((mode <= 0) || (mode > BKMODE_LAST))
1490 SetLastError(ERROR_INVALID_PARAMETER);
1493 if ((dc = get_dc_ptr( hdc )))
1495 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1496 mode = physdev->funcs->pSetBkMode( physdev, mode );
1499 ret = dc->backgroundMode;
1500 dc->backgroundMode = mode;
1502 release_dc_ptr( dc );
1508 /***********************************************************************
1511 INT WINAPI GetROP2( HDC hdc )
1514 DC * dc = get_dc_ptr( hdc );
1518 release_dc_ptr( dc );
1524 /***********************************************************************
1527 INT WINAPI SetROP2( HDC hdc, INT mode )
1532 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1534 SetLastError(ERROR_INVALID_PARAMETER);
1537 if ((dc = get_dc_ptr( hdc )))
1539 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1540 mode = physdev->funcs->pSetROP2( physdev, mode );
1546 release_dc_ptr( dc );
1552 /***********************************************************************
1553 * SetRelAbs (GDI32.@)
1555 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1560 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1562 SetLastError(ERROR_INVALID_PARAMETER);
1565 if ((dc = get_dc_ptr( hdc )))
1567 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1568 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1571 ret = dc->relAbsMode;
1572 dc->relAbsMode = mode;
1574 release_dc_ptr( dc );
1580 /***********************************************************************
1581 * GetPolyFillMode (GDI32.@)
1583 INT WINAPI GetPolyFillMode( HDC hdc )
1586 DC * dc = get_dc_ptr( hdc );
1589 ret = dc->polyFillMode;
1590 release_dc_ptr( dc );
1596 /***********************************************************************
1597 * SetPolyFillMode (GDI32.@)
1599 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1604 if ((mode <= 0) || (mode > POLYFILL_LAST))
1606 SetLastError(ERROR_INVALID_PARAMETER);
1609 if ((dc = get_dc_ptr( hdc )))
1611 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1612 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1615 ret = dc->polyFillMode;
1616 dc->polyFillMode = mode;
1618 release_dc_ptr( dc );
1624 /***********************************************************************
1625 * GetStretchBltMode (GDI32.@)
1627 INT WINAPI GetStretchBltMode( HDC hdc )
1630 DC * dc = get_dc_ptr( hdc );
1633 ret = dc->stretchBltMode;
1634 release_dc_ptr( dc );
1640 /***********************************************************************
1641 * SetStretchBltMode (GDI32.@)
1643 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1648 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1650 SetLastError(ERROR_INVALID_PARAMETER);
1653 if ((dc = get_dc_ptr( hdc )))
1655 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1656 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1659 ret = dc->stretchBltMode;
1660 dc->stretchBltMode = mode;
1662 release_dc_ptr( dc );
1668 /***********************************************************************
1669 * GetMapMode (GDI32.@)
1671 INT WINAPI GetMapMode( HDC hdc )
1674 DC * dc = get_dc_ptr( hdc );
1678 release_dc_ptr( dc );
1684 /***********************************************************************
1685 * GetBrushOrgEx (GDI32.@)
1687 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1689 DC * dc = get_dc_ptr( hdc );
1690 if (!dc) return FALSE;
1691 pt->x = dc->brushOrgX;
1692 pt->y = dc->brushOrgY;
1693 release_dc_ptr( dc );
1698 /***********************************************************************
1699 * GetCurrentPositionEx (GDI32.@)
1701 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1703 DC * dc = get_dc_ptr( hdc );
1704 if (!dc) return FALSE;
1705 pt->x = dc->CursPosX;
1706 pt->y = dc->CursPosY;
1707 release_dc_ptr( dc );
1712 /***********************************************************************
1713 * GetViewportExtEx (GDI32.@)
1715 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1717 DC * dc = get_dc_ptr( hdc );
1718 if (!dc) return FALSE;
1719 size->cx = dc->vportExtX;
1720 size->cy = dc->vportExtY;
1721 release_dc_ptr( dc );
1726 /***********************************************************************
1727 * GetViewportOrgEx (GDI32.@)
1729 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1731 DC * dc = get_dc_ptr( hdc );
1732 if (!dc) return FALSE;
1733 pt->x = dc->vportOrgX;
1734 pt->y = dc->vportOrgY;
1735 release_dc_ptr( dc );
1740 /***********************************************************************
1741 * GetWindowExtEx (GDI32.@)
1743 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1745 DC * dc = get_dc_ptr( hdc );
1746 if (!dc) return FALSE;
1747 size->cx = dc->wndExtX;
1748 size->cy = dc->wndExtY;
1749 release_dc_ptr( dc );
1754 /***********************************************************************
1755 * GetWindowOrgEx (GDI32.@)
1757 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1759 DC * dc = get_dc_ptr( hdc );
1760 if (!dc) return FALSE;
1761 pt->x = dc->wndOrgX;
1762 pt->y = dc->wndOrgY;
1763 release_dc_ptr( dc );
1768 /***********************************************************************
1769 * GetLayout (GDI32.@)
1771 * Gets left->right or right->left text layout flags of a dc.
1774 DWORD WINAPI GetLayout(HDC hdc)
1776 DWORD layout = GDI_ERROR;
1778 DC * dc = get_dc_ptr( hdc );
1781 layout = dc->layout;
1782 release_dc_ptr( dc );
1785 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1790 /***********************************************************************
1791 * SetLayout (GDI32.@)
1793 * Sets left->right or right->left text layout flags of a dc.
1796 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1798 DWORD oldlayout = GDI_ERROR;
1800 DC * dc = get_dc_ptr( hdc );
1803 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1804 layout = physdev->funcs->pSetLayout( physdev, layout );
1805 if (layout != GDI_ERROR)
1807 oldlayout = dc->layout;
1808 dc->layout = layout;
1809 if (layout != oldlayout)
1811 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1812 DC_UpdateXforms( dc );
1815 release_dc_ptr( dc );
1818 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1823 /***********************************************************************
1824 * GetDCBrushColor (GDI32.@)
1826 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1829 COLORREF dcBrushColor = CLR_INVALID;
1831 TRACE("hdc(%p)\n", hdc);
1833 dc = get_dc_ptr( hdc );
1836 dcBrushColor = dc->dcBrushColor;
1837 release_dc_ptr( dc );
1840 return dcBrushColor;
1843 /***********************************************************************
1844 * SetDCBrushColor (GDI32.@)
1846 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1849 COLORREF oldClr = CLR_INVALID;
1851 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1853 dc = get_dc_ptr( hdc );
1856 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCBrushColor );
1857 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1858 if (crColor != CLR_INVALID)
1860 oldClr = dc->dcBrushColor;
1861 dc->dcBrushColor = crColor;
1863 release_dc_ptr( dc );
1869 /***********************************************************************
1870 * GetDCPenColor (GDI32.@)
1872 COLORREF WINAPI GetDCPenColor(HDC hdc)
1875 COLORREF dcPenColor = CLR_INVALID;
1877 TRACE("hdc(%p)\n", hdc);
1879 dc = get_dc_ptr( hdc );
1882 dcPenColor = dc->dcPenColor;
1883 release_dc_ptr( dc );
1889 /***********************************************************************
1890 * SetDCPenColor (GDI32.@)
1892 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1895 COLORREF oldClr = CLR_INVALID;
1897 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1899 dc = get_dc_ptr( hdc );
1902 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1903 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1904 if (crColor != CLR_INVALID)
1906 oldClr = dc->dcPenColor;
1907 dc->dcPenColor = crColor;
1909 release_dc_ptr( dc );
1915 /***********************************************************************
1916 * CancelDC (GDI32.@)
1918 BOOL WINAPI CancelDC(HDC hdc)
1924 /*******************************************************************
1925 * GetMiterLimit [GDI32.@]
1929 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1934 TRACE("(%p,%p)\n", hdc, peLimit);
1936 dc = get_dc_ptr( hdc );
1940 *peLimit = dc->miterLimit;
1942 release_dc_ptr( dc );
1948 /*******************************************************************
1949 * SetMiterLimit [GDI32.@]
1953 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1958 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1960 dc = get_dc_ptr( hdc );
1964 *peOldLimit = dc->miterLimit;
1965 dc->miterLimit = eNewLimit;
1966 release_dc_ptr( dc );
1972 /*******************************************************************
1973 * GdiIsMetaPrintDC [GDI32.@]
1975 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
1981 /*******************************************************************
1982 * GdiIsMetaFileDC [GDI32.@]
1984 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
1988 switch( GetObjectType( hdc ) )
1997 /*******************************************************************
1998 * GdiIsPlayMetafileDC [GDI32.@]
2000 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)