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->funcs = &null_driver;
81 dc->nulldrv.funcs = &null_driver;
82 dc->nulldrv.next = NULL;
83 dc->physDev = &dc->nulldrv;
84 dc->thread = GetCurrentThreadId();
99 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
104 dc->hMetaClipRgn = 0;
106 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
107 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
108 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
111 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
113 dc->font_code_page = CP_ACP;
114 dc->ROPmode = R2_COPYPEN;
115 dc->polyFillMode = ALTERNATE;
116 dc->stretchBltMode = BLACKONWHITE;
117 dc->relAbsMode = ABSOLUTE;
118 dc->backgroundMode = OPAQUE;
119 dc->backgroundColor = RGB( 255, 255, 255 );
120 dc->dcBrushColor = RGB( 255, 255, 255 );
121 dc->dcPenColor = RGB( 0, 0, 0 );
122 dc->textColor = RGB( 0, 0, 0 );
126 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
130 dc->MapMode = MM_TEXT;
131 dc->GraphicsMode = GM_COMPATIBLE;
132 dc->pAbortProc = NULL;
135 dc->ArcDirection = AD_COUNTERCLOCKWISE;
136 dc->xformWorld2Wnd.eM11 = 1.0f;
137 dc->xformWorld2Wnd.eM12 = 0.0f;
138 dc->xformWorld2Wnd.eM21 = 0.0f;
139 dc->xformWorld2Wnd.eM22 = 1.0f;
140 dc->xformWorld2Wnd.eDx = 0.0f;
141 dc->xformWorld2Wnd.eDy = 0.0f;
142 dc->xformWorld2Vport = dc->xformWorld2Wnd;
143 dc->xformVport2World = dc->xformWorld2Wnd;
144 dc->vport2WorldValid = TRUE;
145 dc->BoundsRect.left = 0;
146 dc->BoundsRect.top = 0;
147 dc->BoundsRect.right = 0;
148 dc->BoundsRect.bottom = 0;
149 PATH_InitGdiPath(&dc->path);
151 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
153 HeapFree( GetProcessHeap(), 0, dc );
156 dc->nulldrv.hdc = dc->hSelf;
162 /***********************************************************************
165 static void free_dc_state( DC *dc )
167 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
168 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
169 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
170 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
171 PATH_DestroyGdiPath( &dc->path );
172 HeapFree( GetProcessHeap(), 0, dc );
176 /***********************************************************************
179 void free_dc_ptr( DC *dc )
181 assert( dc->refcount == 1 );
183 while (dc->physDev != &dc->nulldrv) pop_dc_driver( dc, dc->physDev );
184 free_gdi_handle( dc->hSelf );
189 /***********************************************************************
192 * Retrieve a DC pointer but release the GDI lock.
194 DC *get_dc_ptr( HDC hdc )
196 DC *dc = get_dc_obj( hdc );
197 if (!dc) return NULL;
199 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
201 dc->thread = GetCurrentThreadId();
203 else if (dc->thread != GetCurrentThreadId())
205 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
206 GDI_ReleaseObj( hdc );
209 else InterlockedIncrement( &dc->refcount );
211 GDI_ReleaseObj( hdc );
216 /***********************************************************************
219 void release_dc_ptr( DC *dc )
224 ref = InterlockedDecrement( &dc->refcount );
226 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
230 /***********************************************************************
233 * Make sure the DC vis region is up to date.
234 * This function may call up to USER so the GDI lock should _not_
235 * be held when calling it.
237 void update_dc( DC *dc )
239 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
240 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
244 /***********************************************************************
247 * Push a driver on top of the DC driver stack.
249 void push_dc_driver( DC * dc, PHYSDEV physdev, const DC_FUNCTIONS *funcs )
251 physdev->funcs = funcs;
252 physdev->next = dc->physDev;
253 physdev->hdc = dc->hSelf;
254 dc->physDev = physdev;
255 dc->funcs = physdev->funcs;
259 /***********************************************************************
262 * Pop the top driver from the DC driver stack.
264 void pop_dc_driver( DC * dc, PHYSDEV physdev )
266 assert( physdev == dc->physDev );
267 assert( physdev != &dc->nulldrv );
268 dc->physDev = physdev->next;
269 dc->funcs = dc->physDev->funcs;
270 physdev->funcs->pDeleteDC( physdev );
274 /***********************************************************************
277 static BOOL DC_DeleteObject( HGDIOBJ handle )
279 return DeleteDC( handle );
283 /***********************************************************************
286 * Setup device-specific DC values for a newly created DC.
288 void DC_InitDC( DC* dc )
290 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
291 physdev->funcs->pRealizeDefaultPalette( physdev );
292 SetTextColor( dc->hSelf, dc->textColor );
293 SetBkColor( dc->hSelf, dc->backgroundColor );
294 SelectObject( dc->hSelf, dc->hPen );
295 SelectObject( dc->hSelf, dc->hBrush );
296 SelectObject( dc->hSelf, dc->hFont );
297 CLIPPING_UpdateGCRegion( dc );
298 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
302 /***********************************************************************
305 * Computes the inverse of the transformation xformSrc and stores it to
306 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
309 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
313 determinant = xformSrc->eM11*xformSrc->eM22 -
314 xformSrc->eM12*xformSrc->eM21;
315 if (determinant > -1e-12 && determinant < 1e-12)
318 xformDest->eM11 = xformSrc->eM22 / determinant;
319 xformDest->eM12 = -xformSrc->eM12 / determinant;
320 xformDest->eM21 = -xformSrc->eM21 / determinant;
321 xformDest->eM22 = xformSrc->eM11 / determinant;
322 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
323 xformSrc->eDy * xformDest->eM21;
324 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
325 xformSrc->eDy * xformDest->eM22;
330 /* Construct a transformation to do the window-to-viewport conversion */
331 static void construct_window_to_viewport(DC *dc, XFORM *xform)
333 double scaleX, scaleY;
334 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
335 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
337 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
338 xform->eM11 = scaleX;
341 xform->eM22 = scaleY;
342 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
343 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
344 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
347 /***********************************************************************
350 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
351 * fields of the specified DC by creating a transformation that
352 * represents the current mapping mode and combining it with the DC's
353 * world transform. This function should be called whenever the
354 * parameters associated with the mapping mode (window and viewport
355 * extents and origins) or the world transform change.
357 void DC_UpdateXforms( DC *dc )
359 XFORM xformWnd2Vport, oldworld2vport;
361 construct_window_to_viewport(dc, &xformWnd2Vport);
363 oldworld2vport = dc->xformWorld2Vport;
364 /* Combine with the world transformation */
365 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
368 /* Create inverse of world-to-viewport transformation */
369 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
370 &dc->xformVport2World );
372 /* Reselect the font and pen back into the dc so that the size
374 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
375 !GdiIsMetaFileDC(dc->hSelf))
377 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
378 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
383 /***********************************************************************
386 INT CDECL nulldrv_SaveDC( PHYSDEV dev )
388 DC *newdc, *dc = get_nulldrv_dc( dev );
390 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc )))) return 0;
391 newdc->flags = dc->flags;
392 newdc->layout = dc->layout;
393 newdc->hPen = dc->hPen;
394 newdc->hBrush = dc->hBrush;
395 newdc->hFont = dc->hFont;
396 newdc->hBitmap = dc->hBitmap;
397 newdc->hDevice = dc->hDevice;
398 newdc->hPalette = dc->hPalette;
399 newdc->ROPmode = dc->ROPmode;
400 newdc->polyFillMode = dc->polyFillMode;
401 newdc->stretchBltMode = dc->stretchBltMode;
402 newdc->relAbsMode = dc->relAbsMode;
403 newdc->backgroundMode = dc->backgroundMode;
404 newdc->backgroundColor = dc->backgroundColor;
405 newdc->textColor = dc->textColor;
406 newdc->dcBrushColor = dc->dcBrushColor;
407 newdc->dcPenColor = dc->dcPenColor;
408 newdc->brushOrgX = dc->brushOrgX;
409 newdc->brushOrgY = dc->brushOrgY;
410 newdc->mapperFlags = dc->mapperFlags;
411 newdc->textAlign = dc->textAlign;
412 newdc->charExtra = dc->charExtra;
413 newdc->breakExtra = dc->breakExtra;
414 newdc->breakRem = dc->breakRem;
415 newdc->MapMode = dc->MapMode;
416 newdc->GraphicsMode = dc->GraphicsMode;
417 newdc->CursPosX = dc->CursPosX;
418 newdc->CursPosY = dc->CursPosY;
419 newdc->ArcDirection = dc->ArcDirection;
420 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
421 newdc->xformWorld2Vport = dc->xformWorld2Vport;
422 newdc->xformVport2World = dc->xformVport2World;
423 newdc->vport2WorldValid = dc->vport2WorldValid;
424 newdc->wndOrgX = dc->wndOrgX;
425 newdc->wndOrgY = dc->wndOrgY;
426 newdc->wndExtX = dc->wndExtX;
427 newdc->wndExtY = dc->wndExtY;
428 newdc->vportOrgX = dc->vportOrgX;
429 newdc->vportOrgY = dc->vportOrgY;
430 newdc->vportExtX = dc->vportExtX;
431 newdc->vportExtY = dc->vportExtY;
432 newdc->virtual_res = dc->virtual_res;
433 newdc->virtual_size = dc->virtual_size;
434 newdc->BoundsRect = dc->BoundsRect;
435 newdc->gdiFont = dc->gdiFont;
437 PATH_InitGdiPath( &newdc->path );
439 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
444 newdc->hMetaClipRgn = 0;
447 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
448 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
452 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
453 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
456 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
458 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
460 release_dc_ptr( dc );
461 free_dc_state( newdc );
465 newdc->saved_dc = dc->saved_dc;
466 dc->saved_dc = newdc;
467 return ++dc->saveLevel;
471 /***********************************************************************
474 BOOL CDECL nulldrv_RestoreDC( PHYSDEV dev, INT level )
476 DC *dcs, *first_dcs, *dc = get_nulldrv_dc( dev );
479 /* find the state level to restore */
481 if (abs(level) > dc->saveLevel || level == 0) return FALSE;
482 if (level < 0) level = dc->saveLevel + level + 1;
483 first_dcs = dc->saved_dc;
484 for (dcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
487 /* restore the state */
489 if (!PATH_AssignGdiPath( &dc->path, &dcs->path )) return FALSE;
491 dc->flags = dcs->flags;
492 dc->layout = dcs->layout;
493 dc->hDevice = dcs->hDevice;
494 dc->ROPmode = dcs->ROPmode;
495 dc->polyFillMode = dcs->polyFillMode;
496 dc->stretchBltMode = dcs->stretchBltMode;
497 dc->relAbsMode = dcs->relAbsMode;
498 dc->backgroundMode = dcs->backgroundMode;
499 dc->backgroundColor = dcs->backgroundColor;
500 dc->textColor = dcs->textColor;
501 dc->dcBrushColor = dcs->dcBrushColor;
502 dc->dcPenColor = dcs->dcPenColor;
503 dc->brushOrgX = dcs->brushOrgX;
504 dc->brushOrgY = dcs->brushOrgY;
505 dc->mapperFlags = dcs->mapperFlags;
506 dc->textAlign = dcs->textAlign;
507 dc->charExtra = dcs->charExtra;
508 dc->breakExtra = dcs->breakExtra;
509 dc->breakRem = dcs->breakRem;
510 dc->MapMode = dcs->MapMode;
511 dc->GraphicsMode = dcs->GraphicsMode;
512 dc->CursPosX = dcs->CursPosX;
513 dc->CursPosY = dcs->CursPosY;
514 dc->ArcDirection = dcs->ArcDirection;
515 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
516 dc->xformWorld2Vport = dcs->xformWorld2Vport;
517 dc->xformVport2World = dcs->xformVport2World;
518 dc->vport2WorldValid = dcs->vport2WorldValid;
519 dc->BoundsRect = dcs->BoundsRect;
521 dc->wndOrgX = dcs->wndOrgX;
522 dc->wndOrgY = dcs->wndOrgY;
523 dc->wndExtX = dcs->wndExtX;
524 dc->wndExtY = dcs->wndExtY;
525 dc->vportOrgX = dcs->vportOrgX;
526 dc->vportOrgY = dcs->vportOrgY;
527 dc->vportExtX = dcs->vportExtX;
528 dc->vportExtY = dcs->vportExtY;
529 dc->virtual_res = dcs->virtual_res;
530 dc->virtual_size = dcs->virtual_size;
534 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
535 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
539 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
544 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
545 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
549 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
552 DC_UpdateXforms( dc );
553 CLIPPING_UpdateGCRegion( dc );
555 SelectObject( dev->hdc, dcs->hBitmap );
556 SelectObject( dev->hdc, dcs->hBrush );
557 SelectObject( dev->hdc, dcs->hFont );
558 SelectObject( dev->hdc, dcs->hPen );
559 SetBkColor( dev->hdc, dcs->backgroundColor);
560 SetTextColor( dev->hdc, dcs->textColor);
561 GDISelectPalette( dev->hdc, dcs->hPalette, FALSE );
563 dc->saved_dc = dcs->saved_dc;
565 dc->saveLevel = save_level - 1;
567 /* now destroy all the saved DCs */
571 DC *next = first_dcs->saved_dc;
572 free_dc_state( first_dcs );
579 /***********************************************************************
582 INT WINAPI SaveDC( HDC hdc )
587 if ((dc = get_dc_ptr( hdc )))
589 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSaveDC );
590 ret = physdev->funcs->pSaveDC( physdev );
591 release_dc_ptr( dc );
597 /***********************************************************************
598 * RestoreDC (GDI32.@)
600 BOOL WINAPI RestoreDC( HDC hdc, INT level )
603 BOOL success = FALSE;
605 TRACE("%p %d\n", hdc, level );
606 if ((dc = get_dc_ptr( hdc )))
608 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRestoreDC );
610 success = physdev->funcs->pRestoreDC( physdev, level );
611 release_dc_ptr( dc );
617 /***********************************************************************
618 * CreateDCW (GDI32.@)
620 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
621 const DEVMODEW *initData )
625 const DC_FUNCTIONS *funcs;
630 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
634 ERR( "no device found for %s\n", debugstr_w(device) );
637 strcpyW(buf, driver);
640 if (!(funcs = DRIVER_load_driver( buf )))
642 ERR( "no driver found for %s\n", debugstr_w(buf) );
645 if (!(dc = alloc_dc_ptr( OBJ_DC ))) goto error;
648 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
649 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
651 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
652 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
654 if (funcs->pCreateDC)
657 if (!funcs->pCreateDC( hdc, &physdev, buf, device, output, initData ))
659 WARN("creation aborted by device\n" );
662 push_dc_driver( dc, physdev, funcs );
665 dc->vis_rect.left = 0;
666 dc->vis_rect.top = 0;
667 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
668 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
669 SetRectRgn(dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top, dc->vis_rect.right, dc->vis_rect.bottom);
672 release_dc_ptr( dc );
676 if (dc) free_dc_ptr( dc );
681 /***********************************************************************
682 * CreateDCA (GDI32.@)
684 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
685 const DEVMODEA *initData )
687 UNICODE_STRING driverW, deviceW, outputW;
691 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
692 else driverW.Buffer = NULL;
694 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
695 else deviceW.Buffer = NULL;
697 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
698 else outputW.Buffer = NULL;
703 /* don't convert initData for DISPLAY driver, it's not used */
704 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
705 initDataW = GdiConvertToDevmodeW(initData);
708 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
710 RtlFreeUnicodeString(&driverW);
711 RtlFreeUnicodeString(&deviceW);
712 RtlFreeUnicodeString(&outputW);
713 HeapFree(GetProcessHeap(), 0, initDataW);
718 /***********************************************************************
719 * CreateICA (GDI32.@)
721 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
722 const DEVMODEA* initData )
724 /* Nothing special yet for ICs */
725 return CreateDCA( driver, device, output, initData );
729 /***********************************************************************
730 * CreateICW (GDI32.@)
732 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
733 const DEVMODEW* initData )
735 /* Nothing special yet for ICs */
736 return CreateDCW( driver, device, output, initData );
740 /***********************************************************************
741 * CreateCompatibleDC (GDI32.@)
743 HDC WINAPI CreateCompatibleDC( HDC hdc )
747 const DC_FUNCTIONS *funcs = NULL;
748 PHYSDEV physDev = NULL;
754 if (!(origDC = get_dc_ptr( hdc ))) return 0;
755 if (GetObjectType( hdc ) == OBJ_DC)
757 physDev = origDC->physDev;
758 funcs = physDev->funcs;
760 release_dc_ptr( origDC );
763 if (!funcs && !(funcs = DRIVER_get_display_driver())) return 0;
765 if (!(dc = alloc_dc_ptr( OBJ_MEMDC ))) goto error;
767 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
769 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
770 dc->vis_rect.left = 0;
771 dc->vis_rect.top = 0;
772 dc->vis_rect.right = 1;
773 dc->vis_rect.bottom = 1;
774 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
778 /* Pass the driver-specific physical device info into
779 * the new DC. The driver may use this read-only info
780 * while creating the compatible DC. */
781 if (funcs->pCreateDC)
783 if (!funcs->pCreateDC( dc->hSelf, &physDev, NULL, NULL, NULL, NULL ))
785 WARN("creation aborted by device\n");
788 push_dc_driver( dc, physDev, funcs );
791 release_dc_ptr( dc );
795 if (dc) free_dc_ptr( dc );
800 /***********************************************************************
803 BOOL WINAPI DeleteDC( HDC hdc )
811 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
812 if (dc->refcount != 1)
814 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
815 release_dc_ptr( dc );
819 /* Call hook procedure to check whether is it OK to delete this DC */
820 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
822 release_dc_ptr( dc );
826 while (dc->saveLevel)
828 DC *dcs = dc->saved_dc;
829 dc->saved_dc = dcs->saved_dc;
831 free_dc_state( dcs );
834 SelectObject( hdc, GetStockObject(BLACK_PEN) );
835 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
836 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
837 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
844 /***********************************************************************
847 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
852 if ((dc = get_dc_ptr( hdc )))
854 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
855 ret = physdev->funcs->pResetDC( physdev, devmode );
856 if (ret) /* reset the visible region */
859 dc->vis_rect.left = 0;
860 dc->vis_rect.top = 0;
861 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
862 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
863 SetRectRgn( dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top,
864 dc->vis_rect.right, dc->vis_rect.bottom );
865 CLIPPING_UpdateGCRegion( dc );
867 release_dc_ptr( dc );
873 /***********************************************************************
876 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
881 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
882 else devmodeW = NULL;
884 ret = ResetDCW(hdc, devmodeW);
886 HeapFree(GetProcessHeap(), 0, devmodeW);
891 /***********************************************************************
892 * GetDeviceCaps (GDI32.@)
894 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
899 if ((dc = get_dc_ptr( hdc )))
901 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
902 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
903 release_dc_ptr( dc );
909 /***********************************************************************
910 * GetBkColor (GDI32.@)
912 COLORREF WINAPI GetBkColor( HDC hdc )
915 DC * dc = get_dc_ptr( hdc );
918 ret = dc->backgroundColor;
919 release_dc_ptr( dc );
925 /***********************************************************************
926 * SetBkColor (GDI32.@)
928 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
930 COLORREF ret = CLR_INVALID;
931 DC * dc = get_dc_ptr( hdc );
933 TRACE("hdc=%p color=0x%08x\n", hdc, color);
937 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
938 color = physdev->funcs->pSetBkColor( physdev, color );
939 if (color != CLR_INVALID)
941 ret = dc->backgroundColor;
942 dc->backgroundColor = color;
944 release_dc_ptr( dc );
950 /***********************************************************************
951 * GetTextColor (GDI32.@)
953 COLORREF WINAPI GetTextColor( HDC hdc )
956 DC * dc = get_dc_ptr( hdc );
960 release_dc_ptr( dc );
966 /***********************************************************************
967 * SetTextColor (GDI32.@)
969 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
971 COLORREF ret = CLR_INVALID;
972 DC * dc = get_dc_ptr( hdc );
974 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
978 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
979 color = physdev->funcs->pSetTextColor( physdev, color );
980 if (color != CLR_INVALID)
983 dc->textColor = color;
985 release_dc_ptr( dc );
991 /***********************************************************************
992 * GetTextAlign (GDI32.@)
994 UINT WINAPI GetTextAlign( HDC hdc )
997 DC * dc = get_dc_ptr( hdc );
1000 ret = dc->textAlign;
1001 release_dc_ptr( dc );
1007 /***********************************************************************
1008 * SetTextAlign (GDI32.@)
1010 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1012 UINT ret = GDI_ERROR;
1013 DC *dc = get_dc_ptr( hdc );
1015 TRACE("hdc=%p align=%d\n", hdc, align);
1019 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
1020 align = physdev->funcs->pSetTextAlign( physdev, align );
1021 if (align != GDI_ERROR)
1023 ret = dc->textAlign;
1024 dc->textAlign = align;
1026 release_dc_ptr( dc );
1031 /***********************************************************************
1032 * GetDCOrgEx (GDI32.@)
1034 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1038 if (!lpp) return FALSE;
1039 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1040 lpp->x = dc->vis_rect.left;
1041 lpp->y = dc->vis_rect.top;
1042 release_dc_ptr( dc );
1047 /***********************************************************************
1048 * GetGraphicsMode (GDI32.@)
1050 INT WINAPI GetGraphicsMode( HDC hdc )
1053 DC * dc = get_dc_ptr( hdc );
1056 ret = dc->GraphicsMode;
1057 release_dc_ptr( dc );
1063 /***********************************************************************
1064 * SetGraphicsMode (GDI32.@)
1066 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1069 DC *dc = get_dc_ptr( hdc );
1071 /* One would think that setting the graphics mode to GM_COMPATIBLE
1072 * would also reset the world transformation matrix to the unity
1073 * matrix. However, in Windows, this is not the case. This doesn't
1074 * make a lot of sense to me, but that's the way it is.
1077 if ((mode > 0) && (mode <= GM_LAST))
1079 ret = dc->GraphicsMode;
1080 dc->GraphicsMode = mode;
1082 release_dc_ptr( dc );
1087 /***********************************************************************
1088 * GetArcDirection (GDI32.@)
1090 INT WINAPI GetArcDirection( HDC hdc )
1093 DC * dc = get_dc_ptr( hdc );
1096 ret = dc->ArcDirection;
1097 release_dc_ptr( dc );
1103 /***********************************************************************
1104 * SetArcDirection (GDI32.@)
1106 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1111 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1113 SetLastError(ERROR_INVALID_PARAMETER);
1117 if ((dc = get_dc_ptr( hdc )))
1119 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1120 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1123 ret = dc->ArcDirection;
1124 dc->ArcDirection = dir;
1126 release_dc_ptr( dc );
1132 /***********************************************************************
1133 * GetWorldTransform (GDI32.@)
1135 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1138 if (!xform) return FALSE;
1139 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1140 *xform = dc->xformWorld2Wnd;
1141 release_dc_ptr( dc );
1146 /***********************************************************************
1147 * GetTransform (GDI32.@)
1151 * Returns one of the co-ordinate space transforms
1154 * hdc [I] Device context.
1155 * which [I] Which xform to return:
1156 * 0x203 World -> Page transform (that set by SetWorldTransform).
1157 * 0x304 Page -> Device transform (the mapping mode transform).
1158 * 0x204 World -> Device transform (the combination of the above two).
1159 * 0x402 Device -> World transform (the inversion of the above).
1160 * xform [O] The xform.
1163 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1166 DC *dc = get_dc_ptr( hdc );
1167 if (!dc) return FALSE;
1172 *xform = dc->xformWorld2Wnd;
1176 construct_window_to_viewport(dc, xform);
1180 *xform = dc->xformWorld2Vport;
1184 *xform = dc->xformVport2World;
1188 FIXME("Unknown code %x\n", which);
1192 release_dc_ptr( dc );
1197 /****************************************************************************
1198 * CombineTransform [GDI32.@]
1199 * Combines two transformation matrices.
1202 * xformResult [O] Stores the result of combining the two matrices
1203 * xform1 [I] Specifies the first matrix to apply
1204 * xform2 [I] Specifies the second matrix to apply
1207 * The same matrix can be passed in for more than one of the parameters.
1211 * Failure: FALSE. Use GetLastError() to determine the cause.
1213 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1214 const XFORM *xform2 )
1218 /* Check for illegal parameters */
1219 if (!xformResult || !xform1 || !xform2)
1222 /* Create the result in a temporary XFORM, since xformResult may be
1223 * equal to xform1 or xform2 */
1224 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1225 xform1->eM12 * xform2->eM21;
1226 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1227 xform1->eM12 * xform2->eM22;
1228 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1229 xform1->eM22 * xform2->eM21;
1230 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1231 xform1->eM22 * xform2->eM22;
1232 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1233 xform1->eDy * xform2->eM21 +
1235 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1236 xform1->eDy * xform2->eM22 +
1239 /* Copy the result to xformResult */
1240 *xformResult = xformTemp;
1246 /***********************************************************************
1247 * SetDCHook (GDI32.@)
1249 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1251 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1253 DC *dc = get_dc_ptr( hdc );
1255 if (!dc) return FALSE;
1257 dc->dwHookData = dwHookData;
1258 dc->hookProc = hookProc;
1259 release_dc_ptr( dc );
1264 /***********************************************************************
1265 * GetDCHook (GDI32.@)
1267 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1269 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1271 DC *dc = get_dc_ptr( hdc );
1275 if (proc) *proc = dc->hookProc;
1276 ret = dc->dwHookData;
1277 release_dc_ptr( dc );
1282 /***********************************************************************
1283 * SetHookFlags (GDI32.@)
1285 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1287 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1289 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1294 /* "Undocumented Windows" info is slightly confusing. */
1296 TRACE("hDC %p, flags %04x\n",hdc,flags);
1298 if (flags & DCHF_INVALIDATEVISRGN)
1299 ret = InterlockedExchange( &dc->dirty, 1 );
1300 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1301 ret = InterlockedExchange( &dc->dirty, 0 );
1303 GDI_ReleaseObj( hdc );
1307 /***********************************************************************
1308 * SetICMMode (GDI32.@)
1310 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1312 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1313 if (iEnableICM == ICM_OFF) return ICM_OFF;
1314 if (iEnableICM == ICM_ON) return 0;
1315 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1319 /***********************************************************************
1320 * GetDeviceGammaRamp (GDI32.@)
1322 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1325 DC *dc = get_dc_ptr( hDC );
1329 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1330 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1331 release_dc_ptr( dc );
1336 /***********************************************************************
1337 * SetDeviceGammaRamp (GDI32.@)
1339 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1342 DC *dc = get_dc_ptr( hDC );
1346 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1347 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1348 release_dc_ptr( dc );
1353 /***********************************************************************
1354 * GetColorSpace (GDI32.@)
1356 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1358 /*FIXME Need to to whatever GetColorSpace actually does */
1362 /***********************************************************************
1363 * CreateColorSpaceA (GDI32.@)
1365 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1371 /***********************************************************************
1372 * CreateColorSpaceW (GDI32.@)
1374 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1380 /***********************************************************************
1381 * DeleteColorSpace (GDI32.@)
1383 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1390 /***********************************************************************
1391 * SetColorSpace (GDI32.@)
1393 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1400 /***********************************************************************
1401 * GetBoundsRect (GDI32.@)
1403 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1406 DC *dc = get_dc_ptr( hdc );
1408 if ( !dc ) return 0;
1412 *rect = dc->BoundsRect;
1413 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1418 if (flags & DCB_RESET)
1420 dc->BoundsRect.left = 0;
1421 dc->BoundsRect.top = 0;
1422 dc->BoundsRect.right = 0;
1423 dc->BoundsRect.bottom = 0;
1424 dc->flags &= ~DC_BOUNDS_SET;
1426 release_dc_ptr( dc );
1431 /***********************************************************************
1432 * SetBoundsRect (GDI32.@)
1434 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1439 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1440 if (!(dc = get_dc_ptr( hdc ))) return 0;
1442 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1443 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1445 if (flags & DCB_RESET)
1447 dc->BoundsRect.left = 0;
1448 dc->BoundsRect.top = 0;
1449 dc->BoundsRect.right = 0;
1450 dc->BoundsRect.bottom = 0;
1451 dc->flags &= ~DC_BOUNDS_SET;
1454 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1456 if (dc->flags & DC_BOUNDS_SET)
1458 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1459 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1460 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1461 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1465 dc->BoundsRect = *rect;
1466 dc->flags |= DC_BOUNDS_SET;
1470 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1471 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1473 release_dc_ptr( dc );
1478 /***********************************************************************
1479 * GetRelAbs (GDI32.@)
1481 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1484 DC *dc = get_dc_ptr( hdc );
1487 ret = dc->relAbsMode;
1488 release_dc_ptr( dc );
1496 /***********************************************************************
1497 * GetBkMode (GDI32.@)
1499 INT WINAPI GetBkMode( HDC hdc )
1502 DC * dc = get_dc_ptr( hdc );
1505 ret = dc->backgroundMode;
1506 release_dc_ptr( dc );
1512 /***********************************************************************
1513 * SetBkMode (GDI32.@)
1515 INT WINAPI SetBkMode( HDC hdc, INT mode )
1520 if ((mode <= 0) || (mode > BKMODE_LAST))
1522 SetLastError(ERROR_INVALID_PARAMETER);
1525 if ((dc = get_dc_ptr( hdc )))
1527 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1528 mode = physdev->funcs->pSetBkMode( physdev, mode );
1531 ret = dc->backgroundMode;
1532 dc->backgroundMode = mode;
1534 release_dc_ptr( dc );
1540 /***********************************************************************
1543 INT WINAPI GetROP2( HDC hdc )
1546 DC * dc = get_dc_ptr( hdc );
1550 release_dc_ptr( dc );
1556 /***********************************************************************
1559 INT WINAPI SetROP2( HDC hdc, INT mode )
1564 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1566 SetLastError(ERROR_INVALID_PARAMETER);
1569 if ((dc = get_dc_ptr( hdc )))
1571 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1572 mode = physdev->funcs->pSetROP2( physdev, mode );
1578 release_dc_ptr( dc );
1584 /***********************************************************************
1585 * SetRelAbs (GDI32.@)
1587 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1592 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1594 SetLastError(ERROR_INVALID_PARAMETER);
1597 if ((dc = get_dc_ptr( hdc )))
1599 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1600 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1603 ret = dc->relAbsMode;
1604 dc->relAbsMode = mode;
1606 release_dc_ptr( dc );
1612 /***********************************************************************
1613 * GetPolyFillMode (GDI32.@)
1615 INT WINAPI GetPolyFillMode( HDC hdc )
1618 DC * dc = get_dc_ptr( hdc );
1621 ret = dc->polyFillMode;
1622 release_dc_ptr( dc );
1628 /***********************************************************************
1629 * SetPolyFillMode (GDI32.@)
1631 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1636 if ((mode <= 0) || (mode > POLYFILL_LAST))
1638 SetLastError(ERROR_INVALID_PARAMETER);
1641 if ((dc = get_dc_ptr( hdc )))
1643 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1644 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1647 ret = dc->polyFillMode;
1648 dc->polyFillMode = mode;
1650 release_dc_ptr( dc );
1656 /***********************************************************************
1657 * GetStretchBltMode (GDI32.@)
1659 INT WINAPI GetStretchBltMode( HDC hdc )
1662 DC * dc = get_dc_ptr( hdc );
1665 ret = dc->stretchBltMode;
1666 release_dc_ptr( dc );
1672 /***********************************************************************
1673 * SetStretchBltMode (GDI32.@)
1675 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1680 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1682 SetLastError(ERROR_INVALID_PARAMETER);
1685 if ((dc = get_dc_ptr( hdc )))
1687 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1688 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1691 ret = dc->stretchBltMode;
1692 dc->stretchBltMode = mode;
1694 release_dc_ptr( dc );
1700 /***********************************************************************
1701 * GetMapMode (GDI32.@)
1703 INT WINAPI GetMapMode( HDC hdc )
1706 DC * dc = get_dc_ptr( hdc );
1710 release_dc_ptr( dc );
1716 /***********************************************************************
1717 * GetBrushOrgEx (GDI32.@)
1719 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1721 DC * dc = get_dc_ptr( hdc );
1722 if (!dc) return FALSE;
1723 pt->x = dc->brushOrgX;
1724 pt->y = dc->brushOrgY;
1725 release_dc_ptr( dc );
1730 /***********************************************************************
1731 * GetCurrentPositionEx (GDI32.@)
1733 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1735 DC * dc = get_dc_ptr( hdc );
1736 if (!dc) return FALSE;
1737 pt->x = dc->CursPosX;
1738 pt->y = dc->CursPosY;
1739 release_dc_ptr( dc );
1744 /***********************************************************************
1745 * GetViewportExtEx (GDI32.@)
1747 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1749 DC * dc = get_dc_ptr( hdc );
1750 if (!dc) return FALSE;
1751 size->cx = dc->vportExtX;
1752 size->cy = dc->vportExtY;
1753 release_dc_ptr( dc );
1758 /***********************************************************************
1759 * GetViewportOrgEx (GDI32.@)
1761 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1763 DC * dc = get_dc_ptr( hdc );
1764 if (!dc) return FALSE;
1765 pt->x = dc->vportOrgX;
1766 pt->y = dc->vportOrgY;
1767 release_dc_ptr( dc );
1772 /***********************************************************************
1773 * GetWindowExtEx (GDI32.@)
1775 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1777 DC * dc = get_dc_ptr( hdc );
1778 if (!dc) return FALSE;
1779 size->cx = dc->wndExtX;
1780 size->cy = dc->wndExtY;
1781 release_dc_ptr( dc );
1786 /***********************************************************************
1787 * GetWindowOrgEx (GDI32.@)
1789 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1791 DC * dc = get_dc_ptr( hdc );
1792 if (!dc) return FALSE;
1793 pt->x = dc->wndOrgX;
1794 pt->y = dc->wndOrgY;
1795 release_dc_ptr( dc );
1800 /***********************************************************************
1801 * GetLayout (GDI32.@)
1803 * Gets left->right or right->left text layout flags of a dc.
1806 DWORD WINAPI GetLayout(HDC hdc)
1808 DWORD layout = GDI_ERROR;
1810 DC * dc = get_dc_ptr( hdc );
1813 layout = dc->layout;
1814 release_dc_ptr( dc );
1817 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1822 /***********************************************************************
1823 * SetLayout (GDI32.@)
1825 * Sets left->right or right->left text layout flags of a dc.
1828 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1830 DWORD oldlayout = GDI_ERROR;
1832 DC * dc = get_dc_ptr( hdc );
1835 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1836 layout = physdev->funcs->pSetLayout( physdev, layout );
1837 if (layout != GDI_ERROR)
1839 oldlayout = dc->layout;
1840 dc->layout = layout;
1841 if (layout != oldlayout)
1843 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1844 DC_UpdateXforms( dc );
1847 release_dc_ptr( dc );
1850 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1855 /***********************************************************************
1856 * GetDCBrushColor (GDI32.@)
1858 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1861 COLORREF dcBrushColor = CLR_INVALID;
1863 TRACE("hdc(%p)\n", hdc);
1865 dc = get_dc_ptr( hdc );
1868 dcBrushColor = dc->dcBrushColor;
1869 release_dc_ptr( dc );
1872 return dcBrushColor;
1875 /***********************************************************************
1876 * SetDCBrushColor (GDI32.@)
1878 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1881 COLORREF oldClr = CLR_INVALID;
1883 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1885 dc = get_dc_ptr( hdc );
1888 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCBrushColor );
1889 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1890 if (crColor != CLR_INVALID)
1892 oldClr = dc->dcBrushColor;
1893 dc->dcBrushColor = crColor;
1895 release_dc_ptr( dc );
1901 /***********************************************************************
1902 * GetDCPenColor (GDI32.@)
1904 COLORREF WINAPI GetDCPenColor(HDC hdc)
1907 COLORREF dcPenColor = CLR_INVALID;
1909 TRACE("hdc(%p)\n", hdc);
1911 dc = get_dc_ptr( hdc );
1914 dcPenColor = dc->dcPenColor;
1915 release_dc_ptr( dc );
1921 /***********************************************************************
1922 * SetDCPenColor (GDI32.@)
1924 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1927 COLORREF oldClr = CLR_INVALID;
1929 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1931 dc = get_dc_ptr( hdc );
1934 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1935 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1936 if (crColor != CLR_INVALID)
1938 oldClr = dc->dcPenColor;
1939 dc->dcPenColor = crColor;
1941 release_dc_ptr( dc );
1947 /***********************************************************************
1948 * CancelDC (GDI32.@)
1950 BOOL WINAPI CancelDC(HDC hdc)
1956 /*******************************************************************
1957 * GetMiterLimit [GDI32.@]
1961 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1966 TRACE("(%p,%p)\n", hdc, peLimit);
1968 dc = get_dc_ptr( hdc );
1972 *peLimit = dc->miterLimit;
1974 release_dc_ptr( dc );
1980 /*******************************************************************
1981 * SetMiterLimit [GDI32.@]
1985 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1990 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1992 dc = get_dc_ptr( hdc );
1996 *peOldLimit = dc->miterLimit;
1997 dc->miterLimit = eNewLimit;
1998 release_dc_ptr( dc );
2004 /*******************************************************************
2005 * GdiIsMetaPrintDC [GDI32.@]
2007 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2013 /*******************************************************************
2014 * GdiIsMetaFileDC [GDI32.@]
2016 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2020 switch( GetObjectType( hdc ) )
2029 /*******************************************************************
2030 * GdiIsPlayMetafileDC [GDI32.@]
2032 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)