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
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc);
40 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
42 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
44 static const struct gdi_obj_funcs dc_funcs =
46 NULL, /* pSelectObject */
47 NULL, /* pGetObject16 */
48 NULL, /* pGetObjectA */
49 NULL, /* pGetObjectW */
50 NULL, /* pUnrealizeObject */
51 DC_DeleteObject /* pDeleteObject */
55 static inline DC *get_dc_obj( HDC hdc )
57 DC *dc = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
60 if ((GDIMAGIC(dc->header.wMagic) != DC_MAGIC) &&
61 (GDIMAGIC(dc->header.wMagic) != MEMORY_DC_MAGIC) &&
62 (GDIMAGIC(dc->header.wMagic) != METAFILE_DC_MAGIC) &&
63 (GDIMAGIC(dc->header.wMagic) != ENHMETAFILE_DC_MAGIC))
65 GDI_ReleaseObj( hdc );
66 SetLastError( ERROR_INVALID_HANDLE );
73 /***********************************************************************
76 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
81 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
86 dc->thread = GetCurrentThreadId();
102 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
107 dc->hMetaClipRgn = 0;
109 dc->hPen = GetStockObject( BLACK_PEN );
110 dc->hBrush = GetStockObject( WHITE_BRUSH );
111 dc->hFont = GetStockObject( SYSTEM_FONT );
114 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
116 dc->ROPmode = R2_COPYPEN;
117 dc->polyFillMode = ALTERNATE;
118 dc->stretchBltMode = BLACKONWHITE;
119 dc->relAbsMode = ABSOLUTE;
120 dc->backgroundMode = OPAQUE;
121 dc->backgroundColor = RGB( 255, 255, 255 );
122 dc->dcBrushColor = RGB( 255, 255, 255 );
123 dc->dcPenColor = RGB( 0, 0, 0 );
124 dc->textColor = RGB( 0, 0, 0 );
127 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
131 dc->MapMode = MM_TEXT;
132 dc->GraphicsMode = GM_COMPATIBLE;
133 dc->pAbortProc = NULL;
136 dc->ArcDirection = AD_COUNTERCLOCKWISE;
137 dc->xformWorld2Wnd.eM11 = 1.0f;
138 dc->xformWorld2Wnd.eM12 = 0.0f;
139 dc->xformWorld2Wnd.eM21 = 0.0f;
140 dc->xformWorld2Wnd.eM22 = 1.0f;
141 dc->xformWorld2Wnd.eDx = 0.0f;
142 dc->xformWorld2Wnd.eDy = 0.0f;
143 dc->xformWorld2Vport = dc->xformWorld2Wnd;
144 dc->xformVport2World = dc->xformWorld2Wnd;
145 dc->vport2WorldValid = TRUE;
146 dc->BoundsRect.left = 0;
147 dc->BoundsRect.top = 0;
148 dc->BoundsRect.right = 0;
149 dc->BoundsRect.bottom = 0;
150 dc->saved_visrgn = NULL;
151 PATH_InitGdiPath(&dc->path);
157 /***********************************************************************
160 DC *DC_GetDCPtr( HDC hdc )
162 DC *dc = get_dc_obj( hdc );
163 if (!dc) return NULL;
165 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
167 dc->thread = GetCurrentThreadId();
169 else if (dc->thread != GetCurrentThreadId())
171 GDI_ReleaseObj( hdc );
172 SetLastError( ERROR_ACCESS_DENIED );
175 else InterlockedIncrement( &dc->refcount );
181 /***********************************************************************
184 void DC_ReleaseDCPtr( DC *dc )
186 release_dc_ptr( dc );
187 GDI_ReleaseObj( dc->hSelf );
191 /***********************************************************************
194 BOOL DC_FreeDCPtr( DC *dc )
196 assert( dc->refcount == 1 );
197 return GDI_FreeObject( dc->hSelf, dc );
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->hookThunk)
252 dc->hookThunk( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
256 /***********************************************************************
259 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
261 GDI_ReleaseObj( handle );
262 return DeleteDC( handle );
266 /***********************************************************************
269 * Setup device-specific DC values for a newly created DC.
271 void DC_InitDC( DC* dc )
273 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->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 );
283 /***********************************************************************
286 * Computes the inverse of the transformation xformSrc and stores it to
287 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
290 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
294 determinant = xformSrc->eM11*xformSrc->eM22 -
295 xformSrc->eM12*xformSrc->eM21;
296 if (determinant > -1e-12 && determinant < 1e-12)
299 xformDest->eM11 = xformSrc->eM22 / determinant;
300 xformDest->eM12 = -xformSrc->eM12 / determinant;
301 xformDest->eM21 = -xformSrc->eM21 / determinant;
302 xformDest->eM22 = xformSrc->eM11 / determinant;
303 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
304 xformSrc->eDy * xformDest->eM21;
305 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
306 xformSrc->eDy * xformDest->eM22;
312 /***********************************************************************
315 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
316 * fields of the specified DC by creating a transformation that
317 * represents the current mapping mode and combining it with the DC's
318 * world transform. This function should be called whenever the
319 * parameters associated with the mapping mode (window and viewport
320 * extents and origins) or the world transform change.
322 void DC_UpdateXforms( DC *dc )
324 XFORM xformWnd2Vport, oldworld2vport;
325 FLOAT scaleX, scaleY;
327 /* Construct a transformation to do the window-to-viewport conversion */
328 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
329 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
330 xformWnd2Vport.eM11 = scaleX;
331 xformWnd2Vport.eM12 = 0.0;
332 xformWnd2Vport.eM21 = 0.0;
333 xformWnd2Vport.eM22 = scaleY;
334 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
335 scaleX * (FLOAT)dc->wndOrgX;
336 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
337 scaleY * (FLOAT)dc->wndOrgY;
339 oldworld2vport = dc->xformWorld2Vport;
340 /* Combine with the world transformation */
341 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
344 /* Create inverse of world-to-viewport transformation */
345 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
346 &dc->xformVport2World );
348 /* Reselect the font and pen back into the dc so that the size
350 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
352 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
353 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
358 /***********************************************************************
359 * GetDCState (Not a Windows API)
361 HDC WINAPI GetDCState( HDC hdc )
366 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
367 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
369 DC_ReleaseDCPtr( dc );
372 TRACE("(%p): returning %p\n", hdc, handle );
374 newdc->flags = dc->flags | DC_SAVED;
375 newdc->layout = dc->layout;
376 newdc->hPen = dc->hPen;
377 newdc->hBrush = dc->hBrush;
378 newdc->hFont = dc->hFont;
379 newdc->hBitmap = dc->hBitmap;
380 newdc->hDevice = dc->hDevice;
381 newdc->hPalette = dc->hPalette;
382 newdc->ROPmode = dc->ROPmode;
383 newdc->polyFillMode = dc->polyFillMode;
384 newdc->stretchBltMode = dc->stretchBltMode;
385 newdc->relAbsMode = dc->relAbsMode;
386 newdc->backgroundMode = dc->backgroundMode;
387 newdc->backgroundColor = dc->backgroundColor;
388 newdc->textColor = dc->textColor;
389 newdc->dcBrushColor = dc->dcBrushColor;
390 newdc->dcPenColor = dc->dcPenColor;
391 newdc->brushOrgX = dc->brushOrgX;
392 newdc->brushOrgY = dc->brushOrgY;
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->BoundsRect = dc->BoundsRect;
416 newdc->hSelf = (HDC)handle;
417 newdc->thread = GetCurrentThreadId();
419 newdc->saveLevel = 0;
422 PATH_InitGdiPath( &newdc->path );
424 newdc->pAbortProc = NULL;
425 newdc->hookThunk = NULL;
427 newdc->saved_visrgn = NULL;
429 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
434 newdc->hMetaClipRgn = 0;
437 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
438 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
442 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
443 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
445 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
448 newdc->gdiFont = dc->gdiFont;
452 DC_ReleaseDCPtr( newdc );
453 DC_ReleaseDCPtr( dc );
458 /***********************************************************************
459 * SetDCState (Not a Windows API)
461 void WINAPI SetDCState( HDC hdc, HDC hdcs )
465 if (!(dc = get_dc_ptr( hdc ))) return;
466 if (!(dcs = get_dc_ptr( hdcs )))
468 release_dc_ptr( dc );
471 if (!dcs->flags & DC_SAVED)
473 release_dc_ptr( dc );
474 release_dc_ptr( dcs );
477 TRACE("%p %p\n", hdc, hdcs );
480 dc->flags = dcs->flags & ~DC_SAVED;
481 dc->layout = dcs->layout;
482 dc->hDevice = dcs->hDevice;
483 dc->ROPmode = dcs->ROPmode;
484 dc->polyFillMode = dcs->polyFillMode;
485 dc->stretchBltMode = dcs->stretchBltMode;
486 dc->relAbsMode = dcs->relAbsMode;
487 dc->backgroundMode = dcs->backgroundMode;
488 dc->backgroundColor = dcs->backgroundColor;
489 dc->textColor = dcs->textColor;
490 dc->dcBrushColor = dcs->dcBrushColor;
491 dc->dcPenColor = dcs->dcPenColor;
492 dc->brushOrgX = dcs->brushOrgX;
493 dc->brushOrgY = dcs->brushOrgY;
494 dc->textAlign = dcs->textAlign;
495 dc->charExtra = dcs->charExtra;
496 dc->breakExtra = dcs->breakExtra;
497 dc->breakRem = dcs->breakRem;
498 dc->MapMode = dcs->MapMode;
499 dc->GraphicsMode = dcs->GraphicsMode;
500 dc->CursPosX = dcs->CursPosX;
501 dc->CursPosY = dcs->CursPosY;
502 dc->ArcDirection = dcs->ArcDirection;
503 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
504 dc->xformWorld2Vport = dcs->xformWorld2Vport;
505 dc->xformVport2World = dcs->xformVport2World;
506 dc->vport2WorldValid = dcs->vport2WorldValid;
507 dc->BoundsRect = dcs->BoundsRect;
509 dc->wndOrgX = dcs->wndOrgX;
510 dc->wndOrgY = dcs->wndOrgY;
511 dc->wndExtX = dcs->wndExtX;
512 dc->wndExtY = dcs->wndExtY;
513 dc->vportOrgX = dcs->vportOrgX;
514 dc->vportOrgY = dcs->vportOrgY;
515 dc->vportExtX = dcs->vportExtX;
516 dc->vportExtY = dcs->vportExtY;
520 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
521 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
525 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
530 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
531 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
535 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
538 CLIPPING_UpdateGCRegion( dc );
540 SelectObject( hdc, dcs->hBitmap );
541 SelectObject( hdc, dcs->hBrush );
542 SelectObject( hdc, dcs->hFont );
543 SelectObject( hdc, dcs->hPen );
544 SetBkColor( hdc, dcs->backgroundColor);
545 SetTextColor( hdc, dcs->textColor);
546 GDISelectPalette( hdc, dcs->hPalette, FALSE );
547 release_dc_ptr( dc );
548 release_dc_ptr( dcs );
552 /***********************************************************************
553 * GetDCState (GDI.179)
555 HDC16 WINAPI GetDCState16( HDC16 hdc )
557 return HDC_16( GetDCState( HDC_32(hdc) ));
561 /***********************************************************************
562 * SetDCState (GDI.180)
564 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
566 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
570 /***********************************************************************
573 INT WINAPI SaveDC( HDC hdc )
579 dc = DC_GetDCPtr( hdc );
582 if(dc->funcs->pSaveDC)
584 ret = dc->funcs->pSaveDC( dc->physDev );
586 ret = ++dc->saveLevel;
587 DC_ReleaseDCPtr( dc );
591 if (!(hdcs = GetDCState( hdc )))
593 DC_ReleaseDCPtr( dc );
596 dcs = DC_GetDCPtr( hdcs );
598 /* Copy path. The reason why path saving / restoring is in SaveDC/
599 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
600 * functions are only in Win16 (which doesn't have paths) and that
601 * SetDCState doesn't allow us to signal an error (which can happen
602 * when copying paths).
604 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
606 DC_ReleaseDCPtr( dc );
607 DC_ReleaseDCPtr( dcs );
612 dcs->saved_dc = dc->saved_dc;
614 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
615 ret = ++dc->saveLevel;
616 DC_ReleaseDCPtr( dcs );
617 DC_ReleaseDCPtr( dc );
622 /***********************************************************************
623 * RestoreDC (GDI32.@)
625 BOOL WINAPI RestoreDC( HDC hdc, INT level )
630 TRACE("%p %d\n", hdc, level );
631 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
633 if(abs(level) > dc->saveLevel || level == 0)
635 release_dc_ptr( dc );
641 if(dc->funcs->pRestoreDC)
643 success = dc->funcs->pRestoreDC( dc->physDev, level );
644 if(level < 0) level = dc->saveLevel + level + 1;
646 dc->saveLevel = level - 1;
647 release_dc_ptr( dc );
651 if (level < 0) level = dc->saveLevel + level + 1;
653 while (dc->saveLevel >= level)
655 HDC hdcs = dc->saved_dc;
656 if (!(dcs = get_dc_ptr( hdcs )))
661 dc->saved_dc = dcs->saved_dc;
663 if (--dc->saveLevel < level)
665 SetDCState( hdc, hdcs );
666 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
667 /* FIXME: This might not be quite right, since we're
668 * returning FALSE but still destroying the saved DC state */
671 release_dc_ptr( dcs );
674 release_dc_ptr( dc );
679 /***********************************************************************
680 * CreateDCW (GDI32.@)
682 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
683 const DEVMODEW *initData )
687 const DC_FUNCTIONS *funcs;
692 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
696 ERR( "no device found for %s\n", debugstr_w(device) );
699 strcpyW(buf, driver);
702 if (!(funcs = DRIVER_load_driver( buf )))
704 ERR( "no driver found for %s\n", debugstr_w(buf) );
707 if (!(dc = DC_AllocDC( funcs, DC_MAGIC ))) goto error;
710 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
711 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
713 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
714 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
716 if (dc->funcs->pCreateDC &&
717 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
719 WARN("creation aborted by device\n" );
723 SetRectRgn( dc->hVisRgn, 0, 0,
724 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
727 DC_ReleaseDCPtr( dc );
731 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
732 if (dc) DC_FreeDCPtr( dc );
733 DRIVER_release_driver( funcs );
738 /***********************************************************************
739 * CreateDCA (GDI32.@)
741 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
742 const DEVMODEA *initData )
744 UNICODE_STRING driverW, deviceW, outputW;
748 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
749 else driverW.Buffer = NULL;
751 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
752 else deviceW.Buffer = NULL;
754 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
755 else outputW.Buffer = NULL;
760 /* don't convert initData for DISPLAY driver, it's not used */
761 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
762 initDataW = GdiConvertToDevmodeW(initData);
765 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
767 RtlFreeUnicodeString(&driverW);
768 RtlFreeUnicodeString(&deviceW);
769 RtlFreeUnicodeString(&outputW);
770 HeapFree(GetProcessHeap(), 0, initDataW);
775 /***********************************************************************
776 * CreateICA (GDI32.@)
778 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
779 const DEVMODEA* initData )
781 /* Nothing special yet for ICs */
782 return CreateDCA( driver, device, output, initData );
786 /***********************************************************************
787 * CreateICW (GDI32.@)
789 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
790 const DEVMODEW* initData )
792 /* Nothing special yet for ICs */
793 return CreateDCW( driver, device, output, initData );
797 /***********************************************************************
798 * CreateCompatibleDC (GDI32.@)
800 HDC WINAPI CreateCompatibleDC( HDC hdc )
803 const DC_FUNCTIONS *funcs = NULL;
804 PHYSDEV physDev = NULL;
808 if ((origDC = DC_GetDCPtr( hdc )))
810 if (GetObjectType( hdc ) == OBJ_DC)
812 funcs = origDC->funcs;
813 physDev = origDC->physDev;
815 DC_ReleaseDCPtr( origDC ); /* can't hold the lock while loading the driver */
816 if (funcs) funcs = DRIVER_get_driver( funcs );
819 if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
821 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC ))) goto error;
823 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
825 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
826 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
828 /* Copy the driver-specific physical device info into
829 * the new DC. The driver may use this read-only info
830 * while creating the compatible DC below. */
831 dc->physDev = physDev;
833 if (dc->funcs->pCreateDC &&
834 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
836 WARN("creation aborted by device\n");
841 DC_ReleaseDCPtr( dc );
845 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
846 if (dc) DC_FreeDCPtr( dc );
847 DRIVER_release_driver( funcs );
852 /***********************************************************************
855 BOOL WINAPI DeleteDC( HDC hdc )
857 const DC_FUNCTIONS *funcs = NULL;
864 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
865 if (dc->refcount != 1)
867 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
868 DC_ReleaseDCPtr( dc );
872 /* Call hook procedure to check whether is it OK to delete this DC */
875 DCHOOKPROC proc = dc->hookThunk;
876 DWORD_PTR data = dc->dwHookData;
877 DC_ReleaseDCPtr( dc );
878 if (!proc( hdc, DCHC_DELETEDC, data, 0 )) return FALSE;
879 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
882 while (dc->saveLevel)
885 HDC hdcs = dc->saved_dc;
886 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
887 dc->saved_dc = dcs->saved_dc;
889 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
890 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
891 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
892 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
893 PATH_DestroyGdiPath(&dcs->path);
897 if (!(dc->flags & DC_SAVED))
899 SelectObject( hdc, GetStockObject(BLACK_PEN) );
900 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
901 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
902 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
904 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
908 while (dc->saved_visrgn)
910 struct saved_visrgn *next = dc->saved_visrgn->next;
911 DeleteObject( dc->saved_visrgn->hrgn );
912 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
913 dc->saved_visrgn = next;
915 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
916 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
917 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
918 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
919 PATH_DestroyGdiPath(&dc->path);
922 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
927 /***********************************************************************
930 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
935 if ((dc = DC_GetDCPtr( hdc )))
937 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
938 DC_ReleaseDCPtr( dc );
944 /***********************************************************************
947 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
952 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
953 else devmodeW = NULL;
955 ret = ResetDCW(hdc, devmodeW);
957 HeapFree(GetProcessHeap(), 0, devmodeW);
962 /***********************************************************************
963 * GetDeviceCaps (GDI32.@)
965 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
970 if ((dc = DC_GetDCPtr( hdc )))
972 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
973 else switch(cap) /* return meaningful values for some entries */
975 case HORZRES: ret = 640; break;
976 case VERTRES: ret = 480; break;
977 case BITSPIXEL: ret = 1; break;
978 case PLANES: ret = 1; break;
979 case NUMCOLORS: ret = 2; break;
980 case ASPECTX: ret = 36; break;
981 case ASPECTY: ret = 36; break;
982 case ASPECTXY: ret = 51; break;
983 case LOGPIXELSX: ret = 72; break;
984 case LOGPIXELSY: ret = 72; break;
985 case SIZEPALETTE: ret = 2; break;
987 DC_ReleaseDCPtr( dc );
993 /***********************************************************************
994 * GetBkColor (GDI32.@)
996 COLORREF WINAPI GetBkColor( HDC hdc )
999 DC * dc = DC_GetDCPtr( hdc );
1002 ret = dc->backgroundColor;
1003 DC_ReleaseDCPtr( dc );
1009 /***********************************************************************
1010 * SetBkColor (GDI32.@)
1012 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
1015 DC * dc = DC_GetDCPtr( hdc );
1017 TRACE("hdc=%p color=0x%08x\n", hdc, color);
1019 if (!dc) return CLR_INVALID;
1020 oldColor = dc->backgroundColor;
1021 if (dc->funcs->pSetBkColor)
1023 color = dc->funcs->pSetBkColor(dc->physDev, color);
1024 if (color == CLR_INVALID) /* don't change it */
1027 oldColor = CLR_INVALID;
1030 dc->backgroundColor = color;
1031 DC_ReleaseDCPtr( dc );
1036 /***********************************************************************
1037 * GetTextColor (GDI32.@)
1039 COLORREF WINAPI GetTextColor( HDC hdc )
1042 DC * dc = DC_GetDCPtr( hdc );
1045 ret = dc->textColor;
1046 DC_ReleaseDCPtr( dc );
1052 /***********************************************************************
1053 * SetTextColor (GDI32.@)
1055 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
1058 DC * dc = DC_GetDCPtr( hdc );
1060 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
1062 if (!dc) return CLR_INVALID;
1063 oldColor = dc->textColor;
1064 if (dc->funcs->pSetTextColor)
1066 color = dc->funcs->pSetTextColor(dc->physDev, color);
1067 if (color == CLR_INVALID) /* don't change it */
1070 oldColor = CLR_INVALID;
1073 dc->textColor = color;
1074 DC_ReleaseDCPtr( dc );
1079 /***********************************************************************
1080 * GetTextAlign (GDI32.@)
1082 UINT WINAPI GetTextAlign( HDC hdc )
1085 DC * dc = DC_GetDCPtr( hdc );
1088 ret = dc->textAlign;
1089 DC_ReleaseDCPtr( dc );
1095 /***********************************************************************
1096 * SetTextAlign (GDI32.@)
1098 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1101 DC *dc = DC_GetDCPtr( hdc );
1103 TRACE("hdc=%p align=%d\n", hdc, align);
1105 if (!dc) return 0x0;
1106 ret = dc->textAlign;
1107 if (dc->funcs->pSetTextAlign)
1108 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1110 if (ret != GDI_ERROR)
1111 dc->textAlign = align;
1112 DC_ReleaseDCPtr( dc );
1116 /***********************************************************************
1117 * GetDCOrgEx (GDI32.@)
1119 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1123 if (!lpp) return FALSE;
1124 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
1126 lpp->x = lpp->y = 0;
1127 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1128 DC_ReleaseDCPtr( dc );
1133 /***********************************************************************
1134 * SetDCOrg (GDI.117)
1136 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1139 HDC hdc = HDC_32( hdc16 );
1140 DC *dc = DC_GetDCPtr( hdc );
1142 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1143 DC_ReleaseDCPtr( dc );
1148 /***********************************************************************
1149 * GetGraphicsMode (GDI32.@)
1151 INT WINAPI GetGraphicsMode( HDC hdc )
1154 DC * dc = DC_GetDCPtr( hdc );
1157 ret = dc->GraphicsMode;
1158 DC_ReleaseDCPtr( dc );
1164 /***********************************************************************
1165 * SetGraphicsMode (GDI32.@)
1167 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1170 DC *dc = DC_GetDCPtr( hdc );
1172 /* One would think that setting the graphics mode to GM_COMPATIBLE
1173 * would also reset the world transformation matrix to the unity
1174 * matrix. However, in Windows, this is not the case. This doesn't
1175 * make a lot of sense to me, but that's the way it is.
1178 if ((mode > 0) && (mode <= GM_LAST))
1180 ret = dc->GraphicsMode;
1181 dc->GraphicsMode = mode;
1183 DC_ReleaseDCPtr( dc );
1188 /***********************************************************************
1189 * GetArcDirection (GDI32.@)
1191 INT WINAPI GetArcDirection( HDC hdc )
1194 DC * dc = DC_GetDCPtr( hdc );
1197 ret = dc->ArcDirection;
1198 DC_ReleaseDCPtr( dc );
1204 /***********************************************************************
1205 * SetArcDirection (GDI32.@)
1207 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1210 INT nOldDirection = 0;
1212 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1214 SetLastError(ERROR_INVALID_PARAMETER);
1218 if ((dc = DC_GetDCPtr( hdc )))
1220 if (dc->funcs->pSetArcDirection)
1222 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1224 nOldDirection = dc->ArcDirection;
1225 dc->ArcDirection = nDirection;
1226 DC_ReleaseDCPtr( dc );
1228 return nOldDirection;
1232 /***********************************************************************
1233 * GetWorldTransform (GDI32.@)
1235 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1238 if (!xform) return FALSE;
1239 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1240 *xform = dc->xformWorld2Wnd;
1241 DC_ReleaseDCPtr( dc );
1246 /***********************************************************************
1247 * GetTransform (GDI32.@)
1249 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1251 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1252 FIXME("stub: don't know what to do for code %x\n", unknown );
1257 /***********************************************************************
1258 * SetWorldTransform (GDI32.@)
1260 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1263 DC *dc = DC_GetDCPtr( hdc );
1265 if (!dc) return FALSE;
1266 if (!xform) goto done;
1268 /* Check that graphics mode is GM_ADVANCED */
1269 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1271 if (dc->funcs->pSetWorldTransform)
1273 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1274 if (!ret) goto done;
1277 dc->xformWorld2Wnd = *xform;
1278 DC_UpdateXforms( dc );
1281 DC_ReleaseDCPtr( dc );
1286 /****************************************************************************
1287 * ModifyWorldTransform [GDI32.@]
1288 * Modifies the world transformation for a device context.
1291 * hdc [I] Handle to device context
1292 * xform [I] XFORM structure that will be used to modify the world
1294 * iMode [I] Specifies in what way to modify the world transformation
1297 * Resets the world transformation to the identity matrix.
1298 * The parameter xform is ignored.
1300 * Multiplies xform into the world transformation matrix from
1303 * Multiplies xform into the world transformation matrix from
1308 * Failure: FALSE. Use GetLastError() to determine the cause.
1310 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1314 DC *dc = DC_GetDCPtr( hdc );
1316 /* Check for illegal parameters */
1317 if (!dc) return FALSE;
1318 if (!xform && iMode != MWT_IDENTITY) goto done;
1320 /* Check that graphics mode is GM_ADVANCED */
1321 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1323 if (dc->funcs->pModifyWorldTransform)
1325 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1326 if (!ret) goto done;
1332 dc->xformWorld2Wnd.eM11 = 1.0f;
1333 dc->xformWorld2Wnd.eM12 = 0.0f;
1334 dc->xformWorld2Wnd.eM21 = 0.0f;
1335 dc->xformWorld2Wnd.eM22 = 1.0f;
1336 dc->xformWorld2Wnd.eDx = 0.0f;
1337 dc->xformWorld2Wnd.eDy = 0.0f;
1339 case MWT_LEFTMULTIPLY:
1340 CombineTransform( &dc->xformWorld2Wnd, xform,
1341 &dc->xformWorld2Wnd );
1343 case MWT_RIGHTMULTIPLY:
1344 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1351 DC_UpdateXforms( dc );
1354 DC_ReleaseDCPtr( dc );
1359 /****************************************************************************
1360 * CombineTransform [GDI32.@]
1361 * Combines two transformation matrices.
1364 * xformResult [O] Stores the result of combining the two matrices
1365 * xform1 [I] Specifies the first matrix to apply
1366 * xform2 [I] Specifies the second matrix to apply
1369 * The same matrix can be passed in for more than one of the parameters.
1373 * Failure: FALSE. Use GetLastError() to determine the cause.
1375 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1376 const XFORM *xform2 )
1380 /* Check for illegal parameters */
1381 if (!xformResult || !xform1 || !xform2)
1384 /* Create the result in a temporary XFORM, since xformResult may be
1385 * equal to xform1 or xform2 */
1386 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1387 xform1->eM12 * xform2->eM21;
1388 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1389 xform1->eM12 * xform2->eM22;
1390 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1391 xform1->eM22 * xform2->eM21;
1392 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1393 xform1->eM22 * xform2->eM22;
1394 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1395 xform1->eDy * xform2->eM21 +
1397 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1398 xform1->eDy * xform2->eM22 +
1401 /* Copy the result to xformResult */
1402 *xformResult = xformTemp;
1408 /***********************************************************************
1409 * SetDCHook (GDI32.@)
1411 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1413 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1415 DC *dc = DC_GetDCPtr( hdc );
1417 if (!dc) return FALSE;
1419 if (!(dc->flags & DC_SAVED))
1421 dc->dwHookData = dwHookData;
1422 dc->hookThunk = hookProc;
1424 DC_ReleaseDCPtr( dc );
1429 /* relay function to call the 16-bit DC hook proc */
1430 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1434 FARPROC16 proc = NULL;
1435 DC *dc = DC_GetDCPtr( hdc );
1437 if (!dc) return FALSE;
1438 proc = dc->hookProc;
1439 DC_ReleaseDCPtr( dc );
1440 if (!proc) return FALSE;
1441 args[5] = HDC_16(hdc);
1443 args[3] = HIWORD(data);
1444 args[2] = LOWORD(data);
1445 args[1] = HIWORD(lParam);
1446 args[0] = LOWORD(lParam);
1447 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1451 /***********************************************************************
1452 * SetDCHook (GDI.190)
1454 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1456 HDC hdc = HDC_32( hdc16 );
1457 DC *dc = DC_GetDCPtr( hdc );
1458 if (!dc) return FALSE;
1460 dc->hookProc = hookProc;
1461 DC_ReleaseDCPtr( dc );
1462 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1466 /***********************************************************************
1467 * GetDCHook (GDI.191)
1469 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1471 HDC hdc = HDC_32( hdc16 );
1472 DC *dc = DC_GetDCPtr( hdc );
1476 *phookProc = dc->hookProc;
1477 ret = dc->dwHookData;
1478 DC_ReleaseDCPtr( dc );
1483 /***********************************************************************
1484 * SetHookFlags (GDI.192)
1486 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1488 HDC hdc = HDC_32( hdc16 );
1489 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1494 /* "Undocumented Windows" info is slightly confusing. */
1496 TRACE("hDC %p, flags %04x\n",hdc,flags);
1498 if (flags & DCHF_INVALIDATEVISRGN)
1499 ret = InterlockedExchange( &dc->dirty, 1 );
1500 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1501 ret = InterlockedExchange( &dc->dirty, 0 );
1503 GDI_ReleaseObj( dc );
1507 /***********************************************************************
1508 * SetICMMode (GDI32.@)
1510 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1512 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1513 if (iEnableICM == ICM_OFF) return ICM_OFF;
1514 if (iEnableICM == ICM_ON) return 0;
1515 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1519 /***********************************************************************
1520 * GetDeviceGammaRamp (GDI32.@)
1522 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1525 DC *dc = DC_GetDCPtr( hDC );
1529 if (dc->funcs->pGetDeviceGammaRamp)
1530 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1531 DC_ReleaseDCPtr( dc );
1536 /***********************************************************************
1537 * SetDeviceGammaRamp (GDI32.@)
1539 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1542 DC *dc = DC_GetDCPtr( hDC );
1546 if (dc->funcs->pSetDeviceGammaRamp)
1547 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1548 DC_ReleaseDCPtr( dc );
1553 /***********************************************************************
1554 * GetColorSpace (GDI32.@)
1556 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1558 /*FIXME Need to to whatever GetColorSpace actually does */
1562 /***********************************************************************
1563 * CreateColorSpaceA (GDI32.@)
1565 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1571 /***********************************************************************
1572 * CreateColorSpaceW (GDI32.@)
1574 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1580 /***********************************************************************
1581 * DeleteColorSpace (GDI32.@)
1583 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1590 /***********************************************************************
1591 * SetColorSpace (GDI32.@)
1593 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1600 /***********************************************************************
1601 * GetBoundsRect (GDI32.@)
1603 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1606 DC *dc = DC_GetDCPtr( hdc );
1608 if ( !dc ) return 0;
1610 if (rect) *rect = dc->BoundsRect;
1612 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1614 if (flags & DCB_RESET)
1616 dc->BoundsRect.left = 0;
1617 dc->BoundsRect.top = 0;
1618 dc->BoundsRect.right = 0;
1619 dc->BoundsRect.bottom = 0;
1620 dc->flags &= ~DC_BOUNDS_SET;
1622 DC_ReleaseDCPtr( dc );
1627 /***********************************************************************
1628 * SetBoundsRect (GDI32.@)
1630 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1635 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1636 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1638 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1639 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1641 if (flags & DCB_RESET)
1643 dc->BoundsRect.left = 0;
1644 dc->BoundsRect.top = 0;
1645 dc->BoundsRect.right = 0;
1646 dc->BoundsRect.bottom = 0;
1647 dc->flags &= ~DC_BOUNDS_SET;
1650 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1652 if (dc->flags & DC_BOUNDS_SET)
1654 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1655 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1656 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1657 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1661 dc->BoundsRect = *rect;
1662 dc->flags |= DC_BOUNDS_SET;
1666 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1667 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1669 DC_ReleaseDCPtr( dc );
1674 /***********************************************************************
1675 * GetRelAbs (GDI32.@)
1677 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1680 DC *dc = DC_GetDCPtr( hdc );
1683 ret = dc->relAbsMode;
1684 DC_ReleaseDCPtr( dc );
1692 /***********************************************************************
1693 * GetBkMode (GDI32.@)
1695 INT WINAPI GetBkMode( HDC hdc )
1698 DC * dc = DC_GetDCPtr( hdc );
1701 ret = dc->backgroundMode;
1702 DC_ReleaseDCPtr( dc );
1708 /***********************************************************************
1709 * SetBkMode (GDI32.@)
1711 INT WINAPI SetBkMode( HDC hdc, INT mode )
1715 if ((mode <= 0) || (mode > BKMODE_LAST))
1717 SetLastError(ERROR_INVALID_PARAMETER);
1720 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1722 ret = dc->backgroundMode;
1723 if (dc->funcs->pSetBkMode)
1724 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1727 dc->backgroundMode = mode;
1728 DC_ReleaseDCPtr( dc );
1733 /***********************************************************************
1736 INT WINAPI GetROP2( HDC hdc )
1739 DC * dc = DC_GetDCPtr( hdc );
1743 DC_ReleaseDCPtr( dc );
1749 /***********************************************************************
1752 INT WINAPI SetROP2( HDC hdc, INT mode )
1756 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1758 SetLastError(ERROR_INVALID_PARAMETER);
1761 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1763 if (dc->funcs->pSetROP2)
1764 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1768 DC_ReleaseDCPtr( dc );
1773 /***********************************************************************
1774 * SetRelAbs (GDI32.@)
1776 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1780 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1782 SetLastError(ERROR_INVALID_PARAMETER);
1785 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1786 if (dc->funcs->pSetRelAbs)
1787 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1790 ret = dc->relAbsMode;
1791 dc->relAbsMode = mode;
1793 DC_ReleaseDCPtr( dc );
1798 /***********************************************************************
1799 * GetPolyFillMode (GDI32.@)
1801 INT WINAPI GetPolyFillMode( HDC hdc )
1804 DC * dc = DC_GetDCPtr( hdc );
1807 ret = dc->polyFillMode;
1808 DC_ReleaseDCPtr( dc );
1814 /***********************************************************************
1815 * SetPolyFillMode (GDI32.@)
1817 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1821 if ((mode <= 0) || (mode > POLYFILL_LAST))
1823 SetLastError(ERROR_INVALID_PARAMETER);
1826 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1827 ret = dc->polyFillMode;
1828 if (dc->funcs->pSetPolyFillMode)
1829 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1832 dc->polyFillMode = mode;
1833 DC_ReleaseDCPtr( dc );
1838 /***********************************************************************
1839 * GetStretchBltMode (GDI32.@)
1841 INT WINAPI GetStretchBltMode( HDC hdc )
1844 DC * dc = DC_GetDCPtr( hdc );
1847 ret = dc->stretchBltMode;
1848 DC_ReleaseDCPtr( dc );
1854 /***********************************************************************
1855 * SetStretchBltMode (GDI32.@)
1857 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1861 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1863 SetLastError(ERROR_INVALID_PARAMETER);
1866 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1867 ret = dc->stretchBltMode;
1868 if (dc->funcs->pSetStretchBltMode)
1869 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1872 dc->stretchBltMode = mode;
1873 DC_ReleaseDCPtr( dc );
1878 /***********************************************************************
1879 * GetMapMode (GDI32.@)
1881 INT WINAPI GetMapMode( HDC hdc )
1884 DC * dc = DC_GetDCPtr( hdc );
1888 DC_ReleaseDCPtr( dc );
1894 /***********************************************************************
1895 * GetBrushOrgEx (GDI32.@)
1897 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1899 DC * dc = DC_GetDCPtr( hdc );
1900 if (!dc) return FALSE;
1901 pt->x = dc->brushOrgX;
1902 pt->y = dc->brushOrgY;
1903 DC_ReleaseDCPtr( dc );
1908 /***********************************************************************
1909 * GetCurrentPositionEx (GDI32.@)
1911 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1913 DC * dc = DC_GetDCPtr( hdc );
1914 if (!dc) return FALSE;
1915 pt->x = dc->CursPosX;
1916 pt->y = dc->CursPosY;
1917 DC_ReleaseDCPtr( dc );
1922 /***********************************************************************
1923 * GetViewportExtEx (GDI32.@)
1925 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1927 DC * dc = DC_GetDCPtr( hdc );
1928 if (!dc) return FALSE;
1929 size->cx = dc->vportExtX;
1930 size->cy = dc->vportExtY;
1931 DC_ReleaseDCPtr( dc );
1936 /***********************************************************************
1937 * GetViewportOrgEx (GDI32.@)
1939 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1941 DC * dc = DC_GetDCPtr( hdc );
1942 if (!dc) return FALSE;
1943 pt->x = dc->vportOrgX;
1944 pt->y = dc->vportOrgY;
1945 DC_ReleaseDCPtr( dc );
1950 /***********************************************************************
1951 * GetWindowExtEx (GDI32.@)
1953 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1955 DC * dc = DC_GetDCPtr( hdc );
1956 if (!dc) return FALSE;
1957 size->cx = dc->wndExtX;
1958 size->cy = dc->wndExtY;
1959 DC_ReleaseDCPtr( dc );
1964 /***********************************************************************
1965 * GetWindowOrgEx (GDI32.@)
1967 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1969 DC * dc = DC_GetDCPtr( hdc );
1970 if (!dc) return FALSE;
1971 pt->x = dc->wndOrgX;
1972 pt->y = dc->wndOrgY;
1973 DC_ReleaseDCPtr( dc );
1978 /***********************************************************************
1979 * InquireVisRgn (GDI.131)
1981 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1984 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1987 ret = HRGN_16(dc->hVisRgn);
1988 DC_ReleaseDCPtr( dc );
1994 /***********************************************************************
1995 * GetClipRgn (GDI.173)
1997 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
2000 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
2003 ret = HRGN_16(dc->hClipRgn);
2004 DC_ReleaseDCPtr( dc );
2010 /***********************************************************************
2011 * GetLayout (GDI32.@)
2013 * Gets left->right or right->left text layout flags of a dc.
2016 DWORD WINAPI GetLayout(HDC hdc)
2018 DWORD layout = GDI_ERROR;
2020 DC * dc = DC_GetDCPtr( hdc );
2023 layout = dc->layout;
2024 DC_ReleaseDCPtr( dc );
2027 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
2032 /***********************************************************************
2033 * SetLayout (GDI32.@)
2035 * Sets left->right or right->left text layout flags of a dc.
2038 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
2040 DWORD oldlayout = GDI_ERROR;
2042 DC * dc = DC_GetDCPtr( hdc );
2045 oldlayout = dc->layout;
2046 dc->layout = layout;
2047 DC_ReleaseDCPtr( dc );
2050 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
2055 /***********************************************************************
2056 * GetDCBrushColor (GDI32.@)
2058 * Retrieves the current brush color for the specified device
2062 COLORREF WINAPI GetDCBrushColor(HDC hdc)
2065 COLORREF dcBrushColor = CLR_INVALID;
2067 TRACE("hdc(%p)\n", hdc);
2069 dc = DC_GetDCPtr( hdc );
2072 dcBrushColor = dc->dcBrushColor;
2073 DC_ReleaseDCPtr( dc );
2076 return dcBrushColor;
2079 /***********************************************************************
2080 * SetDCBrushColor (GDI32.@)
2082 * Sets the current device context (DC) brush color to the specified
2083 * color value. If the device cannot represent the specified color
2084 * value, the color is set to the nearest physical color.
2087 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2090 COLORREF oldClr = CLR_INVALID;
2092 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2094 dc = DC_GetDCPtr( hdc );
2097 if (dc->funcs->pSetDCBrushColor)
2098 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2099 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2101 /* If DC_BRUSH is selected, update driver pen color */
2102 HBRUSH hBrush = CreateSolidBrush( crColor );
2103 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2104 DeleteObject( hBrush );
2107 if (crColor != CLR_INVALID)
2109 oldClr = dc->dcBrushColor;
2110 dc->dcBrushColor = crColor;
2113 DC_ReleaseDCPtr( dc );
2119 /***********************************************************************
2120 * GetDCPenColor (GDI32.@)
2122 * Retrieves the current pen color for the specified device
2126 COLORREF WINAPI GetDCPenColor(HDC hdc)
2129 COLORREF dcPenColor = CLR_INVALID;
2131 TRACE("hdc(%p)\n", hdc);
2133 dc = DC_GetDCPtr( hdc );
2136 dcPenColor = dc->dcPenColor;
2137 DC_ReleaseDCPtr( dc );
2143 /***********************************************************************
2144 * SetDCPenColor (GDI32.@)
2146 * Sets the current device context (DC) pen color to the specified
2147 * color value. If the device cannot represent the specified color
2148 * value, the color is set to the nearest physical color.
2151 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2154 COLORREF oldClr = CLR_INVALID;
2156 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2158 dc = DC_GetDCPtr( hdc );
2161 if (dc->funcs->pSetDCPenColor)
2162 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2163 else if (dc->hPen == GetStockObject( DC_PEN ))
2165 /* If DC_PEN is selected, update the driver pen color */
2166 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2167 HPEN hPen = CreatePenIndirect( &logpen );
2168 dc->funcs->pSelectPen( dc->physDev, hPen );
2169 DeleteObject( hPen );
2172 if (crColor != CLR_INVALID)
2174 oldClr = dc->dcPenColor;
2175 dc->dcPenColor = crColor;
2178 DC_ReleaseDCPtr( dc );
2184 /***********************************************************************
2185 * CancelDC (GDI32.@)
2187 BOOL WINAPI CancelDC(HDC hdc)
2193 /***********************************************************************
2194 * SetVirtualResolution (GDI32.@)
2196 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2198 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2200 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2204 /*******************************************************************
2205 * GetMiterLimit [GDI32.@]
2209 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2214 TRACE("(%p,%p)\n", hdc, peLimit);
2216 dc = DC_GetDCPtr( hdc );
2220 *peLimit = dc->miterLimit;
2222 DC_ReleaseDCPtr( dc );
2228 /*******************************************************************
2229 * SetMiterLimit [GDI32.@]
2233 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2238 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2240 dc = DC_GetDCPtr( hdc );
2244 *peOldLimit = dc->miterLimit;
2245 dc->miterLimit = eNewLimit;
2246 DC_ReleaseDCPtr( dc );
2252 /*******************************************************************
2253 * GdiIsMetaPrintDC [GDI32.@]
2255 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2261 /*******************************************************************
2262 * GdiIsMetaFileDC [GDI32.@]
2264 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2268 switch( GetObjectType( hdc ) )
2277 /*******************************************************************
2278 * GdiIsPlayMetafileDC [GDI32.@]
2280 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)