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, /* pGetObjectA */
48 NULL, /* pGetObjectW */
49 NULL, /* pUnrealizeObject */
50 DC_DeleteObject /* pDeleteObject */
54 static inline DC *get_dc_obj( HDC hdc )
56 DC *dc = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
59 if ((GDIMAGIC(dc->header.wMagic) != DC_MAGIC) &&
60 (GDIMAGIC(dc->header.wMagic) != MEMORY_DC_MAGIC) &&
61 (GDIMAGIC(dc->header.wMagic) != METAFILE_DC_MAGIC) &&
62 (GDIMAGIC(dc->header.wMagic) != ENHMETAFILE_DC_MAGIC))
64 GDI_ReleaseObj( hdc );
65 SetLastError( ERROR_INVALID_HANDLE );
72 /***********************************************************************
75 DC *alloc_dc_ptr( const DC_FUNCTIONS *funcs, WORD magic )
80 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
85 dc->thread = GetCurrentThreadId();
101 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
106 dc->hMetaClipRgn = 0;
108 dc->hPen = GetStockObject( BLACK_PEN );
109 dc->hBrush = GetStockObject( WHITE_BRUSH );
110 dc->hFont = GetStockObject( SYSTEM_FONT );
113 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
115 dc->ROPmode = R2_COPYPEN;
116 dc->polyFillMode = ALTERNATE;
117 dc->stretchBltMode = BLACKONWHITE;
118 dc->relAbsMode = ABSOLUTE;
119 dc->backgroundMode = OPAQUE;
120 dc->backgroundColor = RGB( 255, 255, 255 );
121 dc->dcBrushColor = RGB( 255, 255, 255 );
122 dc->dcPenColor = RGB( 0, 0, 0 );
123 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 dc->saved_visrgn = NULL;
150 PATH_InitGdiPath(&dc->path);
151 GDI_ReleaseObj( dc->hSelf );
157 /***********************************************************************
160 BOOL free_dc_ptr( DC *dc )
162 assert( dc->refcount == 1 );
163 /* grab the gdi lock again */
164 if (!GDI_GetObjPtr( dc->hSelf, MAGIC_DONTCARE )) return FALSE; /* shouldn't happen */
165 return GDI_FreeObject( dc->hSelf, dc );
169 /***********************************************************************
172 * Retrieve a DC pointer but release the GDI lock.
174 DC *get_dc_ptr( HDC hdc )
176 DC *dc = get_dc_obj( hdc );
177 if (!dc) return NULL;
179 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
181 dc->thread = GetCurrentThreadId();
183 else if (dc->thread != GetCurrentThreadId())
185 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
186 GDI_ReleaseObj( hdc );
189 else InterlockedIncrement( &dc->refcount );
191 GDI_ReleaseObj( hdc );
196 /***********************************************************************
199 void release_dc_ptr( DC *dc )
204 ref = InterlockedDecrement( &dc->refcount );
206 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
210 /***********************************************************************
213 * Make sure the DC vis region is up to date.
214 * This function may call up to USER so the GDI lock should _not_
215 * be held when calling it.
217 void update_dc( DC *dc )
219 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookThunk)
220 dc->hookThunk( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
224 /***********************************************************************
227 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
229 GDI_ReleaseObj( handle );
230 return DeleteDC( handle );
234 /***********************************************************************
237 * Setup device-specific DC values for a newly created DC.
239 void DC_InitDC( DC* dc )
241 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
242 SetTextColor( dc->hSelf, dc->textColor );
243 SetBkColor( dc->hSelf, dc->backgroundColor );
244 SelectObject( dc->hSelf, dc->hPen );
245 SelectObject( dc->hSelf, dc->hBrush );
246 SelectObject( dc->hSelf, dc->hFont );
247 CLIPPING_UpdateGCRegion( dc );
251 /***********************************************************************
254 * Computes the inverse of the transformation xformSrc and stores it to
255 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
258 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
262 determinant = xformSrc->eM11*xformSrc->eM22 -
263 xformSrc->eM12*xformSrc->eM21;
264 if (determinant > -1e-12 && determinant < 1e-12)
267 xformDest->eM11 = xformSrc->eM22 / determinant;
268 xformDest->eM12 = -xformSrc->eM12 / determinant;
269 xformDest->eM21 = -xformSrc->eM21 / determinant;
270 xformDest->eM22 = xformSrc->eM11 / determinant;
271 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
272 xformSrc->eDy * xformDest->eM21;
273 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
274 xformSrc->eDy * xformDest->eM22;
280 /***********************************************************************
283 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
284 * fields of the specified DC by creating a transformation that
285 * represents the current mapping mode and combining it with the DC's
286 * world transform. This function should be called whenever the
287 * parameters associated with the mapping mode (window and viewport
288 * extents and origins) or the world transform change.
290 void DC_UpdateXforms( DC *dc )
292 XFORM xformWnd2Vport, oldworld2vport;
293 FLOAT scaleX, scaleY;
295 /* Construct a transformation to do the window-to-viewport conversion */
296 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
297 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
298 xformWnd2Vport.eM11 = scaleX;
299 xformWnd2Vport.eM12 = 0.0;
300 xformWnd2Vport.eM21 = 0.0;
301 xformWnd2Vport.eM22 = scaleY;
302 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
303 scaleX * (FLOAT)dc->wndOrgX;
304 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
305 scaleY * (FLOAT)dc->wndOrgY;
307 oldworld2vport = dc->xformWorld2Vport;
308 /* Combine with the world transformation */
309 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
312 /* Create inverse of world-to-viewport transformation */
313 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
314 &dc->xformVport2World );
316 /* Reselect the font and pen back into the dc so that the size
318 if ((oldworld2vport.eM11 != dc->xformWorld2Vport.eM11 ||
319 oldworld2vport.eM22 != dc->xformWorld2Vport.eM22) &&
320 !GdiIsMetaFileDC(dc->hSelf))
322 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
323 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
328 /***********************************************************************
329 * GetDCState (Not a Windows API)
331 HDC WINAPI GetDCState( HDC hdc )
336 if (!(dc = get_dc_ptr( hdc ))) return 0;
337 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
339 release_dc_ptr( dc );
342 TRACE("(%p): returning %p\n", hdc, handle );
344 newdc->flags = dc->flags | DC_SAVED;
345 newdc->layout = dc->layout;
346 newdc->hPen = dc->hPen;
347 newdc->hBrush = dc->hBrush;
348 newdc->hFont = dc->hFont;
349 newdc->hBitmap = dc->hBitmap;
350 newdc->hDevice = dc->hDevice;
351 newdc->hPalette = dc->hPalette;
352 newdc->ROPmode = dc->ROPmode;
353 newdc->polyFillMode = dc->polyFillMode;
354 newdc->stretchBltMode = dc->stretchBltMode;
355 newdc->relAbsMode = dc->relAbsMode;
356 newdc->backgroundMode = dc->backgroundMode;
357 newdc->backgroundColor = dc->backgroundColor;
358 newdc->textColor = dc->textColor;
359 newdc->dcBrushColor = dc->dcBrushColor;
360 newdc->dcPenColor = dc->dcPenColor;
361 newdc->brushOrgX = dc->brushOrgX;
362 newdc->brushOrgY = dc->brushOrgY;
363 newdc->textAlign = dc->textAlign;
364 newdc->charExtra = dc->charExtra;
365 newdc->breakExtra = dc->breakExtra;
366 newdc->breakRem = dc->breakRem;
367 newdc->MapMode = dc->MapMode;
368 newdc->GraphicsMode = dc->GraphicsMode;
369 newdc->CursPosX = dc->CursPosX;
370 newdc->CursPosY = dc->CursPosY;
371 newdc->ArcDirection = dc->ArcDirection;
372 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
373 newdc->xformWorld2Vport = dc->xformWorld2Vport;
374 newdc->xformVport2World = dc->xformVport2World;
375 newdc->vport2WorldValid = dc->vport2WorldValid;
376 newdc->wndOrgX = dc->wndOrgX;
377 newdc->wndOrgY = dc->wndOrgY;
378 newdc->wndExtX = dc->wndExtX;
379 newdc->wndExtY = dc->wndExtY;
380 newdc->vportOrgX = dc->vportOrgX;
381 newdc->vportOrgY = dc->vportOrgY;
382 newdc->vportExtX = dc->vportExtX;
383 newdc->vportExtY = dc->vportExtY;
384 newdc->BoundsRect = dc->BoundsRect;
386 newdc->hSelf = (HDC)handle;
387 newdc->thread = GetCurrentThreadId();
389 newdc->saveLevel = 0;
391 GDI_ReleaseObj( handle );
393 PATH_InitGdiPath( &newdc->path );
395 newdc->pAbortProc = NULL;
396 newdc->hookThunk = NULL;
398 newdc->saved_visrgn = NULL;
400 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
405 newdc->hMetaClipRgn = 0;
408 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
409 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
413 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
414 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
416 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
419 newdc->gdiFont = dc->gdiFont;
423 release_dc_ptr( newdc );
424 release_dc_ptr( dc );
429 /***********************************************************************
430 * SetDCState (Not a Windows API)
432 void WINAPI SetDCState( HDC hdc, HDC hdcs )
436 if (!(dc = get_dc_ptr( hdc ))) return;
437 if (!(dcs = get_dc_ptr( hdcs )))
439 release_dc_ptr( dc );
442 if (!(dcs->flags & DC_SAVED))
444 release_dc_ptr( dc );
445 release_dc_ptr( dcs );
448 TRACE("%p %p\n", hdc, hdcs );
451 dc->flags = dcs->flags & ~DC_SAVED;
452 dc->layout = dcs->layout;
453 dc->hDevice = dcs->hDevice;
454 dc->ROPmode = dcs->ROPmode;
455 dc->polyFillMode = dcs->polyFillMode;
456 dc->stretchBltMode = dcs->stretchBltMode;
457 dc->relAbsMode = dcs->relAbsMode;
458 dc->backgroundMode = dcs->backgroundMode;
459 dc->backgroundColor = dcs->backgroundColor;
460 dc->textColor = dcs->textColor;
461 dc->dcBrushColor = dcs->dcBrushColor;
462 dc->dcPenColor = dcs->dcPenColor;
463 dc->brushOrgX = dcs->brushOrgX;
464 dc->brushOrgY = dcs->brushOrgY;
465 dc->textAlign = dcs->textAlign;
466 dc->charExtra = dcs->charExtra;
467 dc->breakExtra = dcs->breakExtra;
468 dc->breakRem = dcs->breakRem;
469 dc->MapMode = dcs->MapMode;
470 dc->GraphicsMode = dcs->GraphicsMode;
471 dc->CursPosX = dcs->CursPosX;
472 dc->CursPosY = dcs->CursPosY;
473 dc->ArcDirection = dcs->ArcDirection;
474 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
475 dc->xformWorld2Vport = dcs->xformWorld2Vport;
476 dc->xformVport2World = dcs->xformVport2World;
477 dc->vport2WorldValid = dcs->vport2WorldValid;
478 dc->BoundsRect = dcs->BoundsRect;
480 dc->wndOrgX = dcs->wndOrgX;
481 dc->wndOrgY = dcs->wndOrgY;
482 dc->wndExtX = dcs->wndExtX;
483 dc->wndExtY = dcs->wndExtY;
484 dc->vportOrgX = dcs->vportOrgX;
485 dc->vportOrgY = dcs->vportOrgY;
486 dc->vportExtX = dcs->vportExtX;
487 dc->vportExtY = dcs->vportExtY;
491 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
492 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
496 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
501 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
502 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
506 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
509 CLIPPING_UpdateGCRegion( dc );
511 SelectObject( hdc, dcs->hBitmap );
512 SelectObject( hdc, dcs->hBrush );
513 SelectObject( hdc, dcs->hFont );
514 SelectObject( hdc, dcs->hPen );
515 SetBkColor( hdc, dcs->backgroundColor);
516 SetTextColor( hdc, dcs->textColor);
517 GDISelectPalette( hdc, dcs->hPalette, FALSE );
518 release_dc_ptr( dc );
519 release_dc_ptr( dcs );
523 /***********************************************************************
524 * GetDCState (GDI.179)
526 HDC16 WINAPI GetDCState16( HDC16 hdc )
528 return HDC_16( GetDCState( HDC_32(hdc) ));
532 /***********************************************************************
533 * SetDCState (GDI.180)
535 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
537 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
541 /***********************************************************************
544 INT WINAPI SaveDC( HDC hdc )
550 dc = get_dc_ptr( hdc );
553 if(dc->funcs->pSaveDC)
555 ret = dc->funcs->pSaveDC( dc->physDev );
557 ret = ++dc->saveLevel;
558 release_dc_ptr( dc );
562 if (!(hdcs = GetDCState( hdc )))
564 release_dc_ptr( dc );
567 dcs = get_dc_ptr( hdcs );
569 /* Copy path. The reason why path saving / restoring is in SaveDC/
570 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
571 * functions are only in Win16 (which doesn't have paths) and that
572 * SetDCState doesn't allow us to signal an error (which can happen
573 * when copying paths).
575 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
577 release_dc_ptr( dc );
578 release_dc_ptr( dcs );
583 dcs->saved_dc = dc->saved_dc;
585 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
586 ret = ++dc->saveLevel;
587 release_dc_ptr( dcs );
588 release_dc_ptr( dc );
593 /***********************************************************************
594 * RestoreDC (GDI32.@)
596 BOOL WINAPI RestoreDC( HDC hdc, INT level )
601 TRACE("%p %d\n", hdc, level );
602 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
604 if(abs(level) > dc->saveLevel || level == 0)
606 release_dc_ptr( dc );
612 if(dc->funcs->pRestoreDC)
614 success = dc->funcs->pRestoreDC( dc->physDev, level );
615 if(level < 0) level = dc->saveLevel + level + 1;
617 dc->saveLevel = level - 1;
618 release_dc_ptr( dc );
622 if (level < 0) level = dc->saveLevel + level + 1;
624 while (dc->saveLevel >= level)
626 HDC hdcs = dc->saved_dc;
627 if (!(dcs = get_dc_ptr( hdcs )))
632 dc->saved_dc = dcs->saved_dc;
634 if (--dc->saveLevel < level)
636 SetDCState( hdc, hdcs );
637 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
638 /* FIXME: This might not be quite right, since we're
639 * returning FALSE but still destroying the saved DC state */
642 release_dc_ptr( dcs );
645 release_dc_ptr( dc );
650 /***********************************************************************
651 * CreateDCW (GDI32.@)
653 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
654 const DEVMODEW *initData )
658 const DC_FUNCTIONS *funcs;
663 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
667 ERR( "no device found for %s\n", debugstr_w(device) );
670 strcpyW(buf, driver);
673 if (!(funcs = DRIVER_load_driver( buf )))
675 ERR( "no driver found for %s\n", debugstr_w(buf) );
678 if (!(dc = alloc_dc_ptr( funcs, DC_MAGIC ))) goto error;
681 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
682 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
684 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
685 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
687 if (dc->funcs->pCreateDC &&
688 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
690 WARN("creation aborted by device\n" );
694 SetRectRgn( dc->hVisRgn, 0, 0,
695 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
698 release_dc_ptr( dc );
702 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
703 if (dc) free_dc_ptr( dc );
704 DRIVER_release_driver( funcs );
709 /***********************************************************************
710 * CreateDCA (GDI32.@)
712 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
713 const DEVMODEA *initData )
715 UNICODE_STRING driverW, deviceW, outputW;
719 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
720 else driverW.Buffer = NULL;
722 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
723 else deviceW.Buffer = NULL;
725 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
726 else outputW.Buffer = NULL;
731 /* don't convert initData for DISPLAY driver, it's not used */
732 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
733 initDataW = GdiConvertToDevmodeW(initData);
736 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
738 RtlFreeUnicodeString(&driverW);
739 RtlFreeUnicodeString(&deviceW);
740 RtlFreeUnicodeString(&outputW);
741 HeapFree(GetProcessHeap(), 0, initDataW);
746 /***********************************************************************
747 * CreateICA (GDI32.@)
749 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
750 const DEVMODEA* initData )
752 /* Nothing special yet for ICs */
753 return CreateDCA( driver, device, output, initData );
757 /***********************************************************************
758 * CreateICW (GDI32.@)
760 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
761 const DEVMODEW* initData )
763 /* Nothing special yet for ICs */
764 return CreateDCW( driver, device, output, initData );
768 /***********************************************************************
769 * CreateCompatibleDC (GDI32.@)
771 HDC WINAPI CreateCompatibleDC( HDC hdc )
775 const DC_FUNCTIONS *funcs = NULL;
776 PHYSDEV physDev = NULL;
780 if ((origDC = get_dc_ptr( hdc )))
782 if (GetObjectType( hdc ) == OBJ_DC)
784 funcs = origDC->funcs;
785 physDev = origDC->physDev;
787 release_dc_ptr( origDC );
788 if (funcs) funcs = DRIVER_get_driver( funcs );
790 else if (hdc) return 0;
792 if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
794 if (!(dc = alloc_dc_ptr( funcs, MEMORY_DC_MAGIC ))) goto error;
796 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
798 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
799 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
801 /* Copy the driver-specific physical device info into
802 * the new DC. The driver may use this read-only info
803 * while creating the compatible DC below. */
804 dc->physDev = physDev;
807 if (dc->funcs->pCreateDC &&
808 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
810 WARN("creation aborted by device\n");
815 release_dc_ptr( dc );
819 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
820 if (dc) free_dc_ptr( dc );
821 DRIVER_release_driver( funcs );
826 /***********************************************************************
829 BOOL WINAPI DeleteDC( HDC hdc )
831 const DC_FUNCTIONS *funcs = NULL;
838 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
839 if (dc->refcount != 1)
841 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
842 release_dc_ptr( dc );
846 /* Call hook procedure to check whether is it OK to delete this DC */
847 if (dc->hookThunk && !dc->hookThunk( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
849 release_dc_ptr( dc );
853 while (dc->saveLevel)
856 HDC hdcs = dc->saved_dc;
857 if (!(dcs = get_dc_ptr( hdcs ))) break;
858 dc->saved_dc = dcs->saved_dc;
860 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
861 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
862 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
863 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
864 PATH_DestroyGdiPath(&dcs->path);
868 if (!(dc->flags & DC_SAVED))
870 SelectObject( hdc, GetStockObject(BLACK_PEN) );
871 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
872 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
873 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
875 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
879 while (dc->saved_visrgn)
881 struct saved_visrgn *next = dc->saved_visrgn->next;
882 DeleteObject( dc->saved_visrgn->hrgn );
883 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
884 dc->saved_visrgn = next;
886 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
887 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
888 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
889 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
890 PATH_DestroyGdiPath(&dc->path);
893 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
898 /***********************************************************************
901 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
906 if ((dc = get_dc_ptr( hdc )))
908 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
909 release_dc_ptr( dc );
915 /***********************************************************************
918 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
923 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
924 else devmodeW = NULL;
926 ret = ResetDCW(hdc, devmodeW);
928 HeapFree(GetProcessHeap(), 0, devmodeW);
933 /***********************************************************************
934 * GetDeviceCaps (GDI32.@)
936 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
941 if ((dc = get_dc_ptr( hdc )))
943 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
944 else switch(cap) /* return meaningful values for some entries */
946 case HORZRES: ret = 640; break;
947 case VERTRES: ret = 480; break;
948 case BITSPIXEL: ret = 1; break;
949 case PLANES: ret = 1; break;
950 case NUMCOLORS: ret = 2; break;
951 case ASPECTX: ret = 36; break;
952 case ASPECTY: ret = 36; break;
953 case ASPECTXY: ret = 51; break;
954 case LOGPIXELSX: ret = 72; break;
955 case LOGPIXELSY: ret = 72; break;
956 case SIZEPALETTE: ret = 2; break;
958 release_dc_ptr( dc );
964 /***********************************************************************
965 * GetBkColor (GDI32.@)
967 COLORREF WINAPI GetBkColor( HDC hdc )
970 DC * dc = get_dc_ptr( hdc );
973 ret = dc->backgroundColor;
974 release_dc_ptr( dc );
980 /***********************************************************************
981 * SetBkColor (GDI32.@)
983 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
986 DC * dc = get_dc_ptr( hdc );
988 TRACE("hdc=%p color=0x%08x\n", hdc, color);
990 if (!dc) return CLR_INVALID;
991 oldColor = dc->backgroundColor;
992 if (dc->funcs->pSetBkColor)
994 color = dc->funcs->pSetBkColor(dc->physDev, color);
995 if (color == CLR_INVALID) /* don't change it */
998 oldColor = CLR_INVALID;
1001 dc->backgroundColor = color;
1002 release_dc_ptr( dc );
1007 /***********************************************************************
1008 * GetTextColor (GDI32.@)
1010 COLORREF WINAPI GetTextColor( HDC hdc )
1013 DC * dc = get_dc_ptr( hdc );
1016 ret = dc->textColor;
1017 release_dc_ptr( dc );
1023 /***********************************************************************
1024 * SetTextColor (GDI32.@)
1026 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
1029 DC * dc = get_dc_ptr( hdc );
1031 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
1033 if (!dc) return CLR_INVALID;
1034 oldColor = dc->textColor;
1035 if (dc->funcs->pSetTextColor)
1037 color = dc->funcs->pSetTextColor(dc->physDev, color);
1038 if (color == CLR_INVALID) /* don't change it */
1041 oldColor = CLR_INVALID;
1044 dc->textColor = color;
1045 release_dc_ptr( dc );
1050 /***********************************************************************
1051 * GetTextAlign (GDI32.@)
1053 UINT WINAPI GetTextAlign( HDC hdc )
1056 DC * dc = get_dc_ptr( hdc );
1059 ret = dc->textAlign;
1060 release_dc_ptr( dc );
1066 /***********************************************************************
1067 * SetTextAlign (GDI32.@)
1069 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1072 DC *dc = get_dc_ptr( hdc );
1074 TRACE("hdc=%p align=%d\n", hdc, align);
1076 if (!dc) return 0x0;
1077 ret = dc->textAlign;
1078 if (dc->funcs->pSetTextAlign)
1079 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1081 if (ret != GDI_ERROR)
1082 dc->textAlign = align;
1083 release_dc_ptr( dc );
1087 /***********************************************************************
1088 * GetDCOrgEx (GDI32.@)
1090 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1094 if (!lpp) return FALSE;
1095 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1097 lpp->x = lpp->y = 0;
1098 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1099 release_dc_ptr( dc );
1104 /***********************************************************************
1105 * SetDCOrg (GDI.117)
1107 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1110 HDC hdc = HDC_32( hdc16 );
1111 DC *dc = get_dc_ptr( hdc );
1113 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1114 release_dc_ptr( dc );
1119 /***********************************************************************
1120 * GetGraphicsMode (GDI32.@)
1122 INT WINAPI GetGraphicsMode( HDC hdc )
1125 DC * dc = get_dc_ptr( hdc );
1128 ret = dc->GraphicsMode;
1129 release_dc_ptr( dc );
1135 /***********************************************************************
1136 * SetGraphicsMode (GDI32.@)
1138 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1141 DC *dc = get_dc_ptr( hdc );
1143 /* One would think that setting the graphics mode to GM_COMPATIBLE
1144 * would also reset the world transformation matrix to the unity
1145 * matrix. However, in Windows, this is not the case. This doesn't
1146 * make a lot of sense to me, but that's the way it is.
1149 if ((mode > 0) && (mode <= GM_LAST))
1151 ret = dc->GraphicsMode;
1152 dc->GraphicsMode = mode;
1154 release_dc_ptr( dc );
1159 /***********************************************************************
1160 * GetArcDirection (GDI32.@)
1162 INT WINAPI GetArcDirection( HDC hdc )
1165 DC * dc = get_dc_ptr( hdc );
1168 ret = dc->ArcDirection;
1169 release_dc_ptr( dc );
1175 /***********************************************************************
1176 * SetArcDirection (GDI32.@)
1178 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1181 INT nOldDirection = 0;
1183 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1185 SetLastError(ERROR_INVALID_PARAMETER);
1189 if ((dc = get_dc_ptr( hdc )))
1191 if (dc->funcs->pSetArcDirection)
1193 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1195 nOldDirection = dc->ArcDirection;
1196 dc->ArcDirection = nDirection;
1197 release_dc_ptr( dc );
1199 return nOldDirection;
1203 /***********************************************************************
1204 * GetWorldTransform (GDI32.@)
1206 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1209 if (!xform) return FALSE;
1210 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1211 *xform = dc->xformWorld2Wnd;
1212 release_dc_ptr( dc );
1217 /***********************************************************************
1218 * GetTransform (GDI32.@)
1220 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1222 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1223 FIXME("stub: don't know what to do for code %x\n", unknown );
1228 /***********************************************************************
1229 * SetWorldTransform (GDI32.@)
1231 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1234 DC *dc = get_dc_ptr( hdc );
1236 if (!dc) return FALSE;
1237 if (!xform) goto done;
1239 /* Check that graphics mode is GM_ADVANCED */
1240 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1242 if (dc->funcs->pSetWorldTransform)
1244 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1245 if (!ret) goto done;
1248 dc->xformWorld2Wnd = *xform;
1249 DC_UpdateXforms( dc );
1252 release_dc_ptr( dc );
1257 /****************************************************************************
1258 * ModifyWorldTransform [GDI32.@]
1259 * Modifies the world transformation for a device context.
1262 * hdc [I] Handle to device context
1263 * xform [I] XFORM structure that will be used to modify the world
1265 * iMode [I] Specifies in what way to modify the world transformation
1268 * Resets the world transformation to the identity matrix.
1269 * The parameter xform is ignored.
1271 * Multiplies xform into the world transformation matrix from
1274 * Multiplies xform into the world transformation matrix from
1279 * Failure: FALSE. Use GetLastError() to determine the cause.
1281 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1285 DC *dc = get_dc_ptr( hdc );
1287 /* Check for illegal parameters */
1288 if (!dc) return FALSE;
1289 if (!xform && iMode != MWT_IDENTITY) goto done;
1291 /* Check that graphics mode is GM_ADVANCED */
1292 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1294 if (dc->funcs->pModifyWorldTransform)
1296 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1297 if (!ret) goto done;
1303 dc->xformWorld2Wnd.eM11 = 1.0f;
1304 dc->xformWorld2Wnd.eM12 = 0.0f;
1305 dc->xformWorld2Wnd.eM21 = 0.0f;
1306 dc->xformWorld2Wnd.eM22 = 1.0f;
1307 dc->xformWorld2Wnd.eDx = 0.0f;
1308 dc->xformWorld2Wnd.eDy = 0.0f;
1310 case MWT_LEFTMULTIPLY:
1311 CombineTransform( &dc->xformWorld2Wnd, xform,
1312 &dc->xformWorld2Wnd );
1314 case MWT_RIGHTMULTIPLY:
1315 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1322 DC_UpdateXforms( dc );
1325 release_dc_ptr( dc );
1330 /****************************************************************************
1331 * CombineTransform [GDI32.@]
1332 * Combines two transformation matrices.
1335 * xformResult [O] Stores the result of combining the two matrices
1336 * xform1 [I] Specifies the first matrix to apply
1337 * xform2 [I] Specifies the second matrix to apply
1340 * The same matrix can be passed in for more than one of the parameters.
1344 * Failure: FALSE. Use GetLastError() to determine the cause.
1346 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1347 const XFORM *xform2 )
1351 /* Check for illegal parameters */
1352 if (!xformResult || !xform1 || !xform2)
1355 /* Create the result in a temporary XFORM, since xformResult may be
1356 * equal to xform1 or xform2 */
1357 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1358 xform1->eM12 * xform2->eM21;
1359 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1360 xform1->eM12 * xform2->eM22;
1361 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1362 xform1->eM22 * xform2->eM21;
1363 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1364 xform1->eM22 * xform2->eM22;
1365 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1366 xform1->eDy * xform2->eM21 +
1368 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1369 xform1->eDy * xform2->eM22 +
1372 /* Copy the result to xformResult */
1373 *xformResult = xformTemp;
1379 /***********************************************************************
1380 * SetDCHook (GDI32.@)
1382 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1384 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1386 DC *dc = get_dc_ptr( hdc );
1388 if (!dc) return FALSE;
1390 if (!(dc->flags & DC_SAVED))
1392 dc->dwHookData = dwHookData;
1393 dc->hookThunk = hookProc;
1395 release_dc_ptr( dc );
1400 /***********************************************************************
1401 * GetDCHook (GDI32.@)
1403 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1405 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1407 DC *dc = get_dc_ptr( hdc );
1411 if (proc) *proc = dc->hookThunk;
1412 ret = dc->dwHookData;
1413 release_dc_ptr( dc );
1418 /* relay function to call the 16-bit DC hook proc */
1419 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1423 DC *dc = get_dc_ptr( hdc );
1425 if (!dc) return FALSE;
1428 args[5] = HDC_16(hdc);
1430 args[3] = HIWORD(data);
1431 args[2] = LOWORD(data);
1432 args[1] = HIWORD(lParam);
1433 args[0] = LOWORD(lParam);
1434 WOWCallback16Ex( (DWORD)dc->hookProc, WCB16_PASCAL, sizeof(args), args, &ret );
1436 release_dc_ptr( dc );
1440 /***********************************************************************
1441 * SetDCHook (GDI.190)
1443 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1445 DC *dc = get_dc_ptr( HDC_32(hdc16) );
1447 if (!dc) return FALSE;
1448 if (!(dc->flags & DC_SAVED))
1450 dc->dwHookData = dwHookData;
1451 dc->hookThunk = call_dc_hook16;
1452 dc->hookProc = hookProc;
1454 release_dc_ptr( dc );
1459 /***********************************************************************
1460 * GetDCHook (GDI.191)
1462 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1464 HDC hdc = HDC_32( hdc16 );
1465 DC *dc = get_dc_ptr( hdc );
1469 *phookProc = dc->hookProc;
1470 ret = dc->dwHookData;
1471 release_dc_ptr( dc );
1476 /***********************************************************************
1477 * SetHookFlags (GDI32.@)
1479 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1481 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1483 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1488 /* "Undocumented Windows" info is slightly confusing. */
1490 TRACE("hDC %p, flags %04x\n",hdc,flags);
1492 if (flags & DCHF_INVALIDATEVISRGN)
1493 ret = InterlockedExchange( &dc->dirty, 1 );
1494 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1495 ret = InterlockedExchange( &dc->dirty, 0 );
1497 GDI_ReleaseObj( dc );
1501 /***********************************************************************
1502 * SetICMMode (GDI32.@)
1504 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1506 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1507 if (iEnableICM == ICM_OFF) return ICM_OFF;
1508 if (iEnableICM == ICM_ON) return 0;
1509 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1513 /***********************************************************************
1514 * GetDeviceGammaRamp (GDI32.@)
1516 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1519 DC *dc = get_dc_ptr( hDC );
1523 if (dc->funcs->pGetDeviceGammaRamp)
1524 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1525 release_dc_ptr( dc );
1530 /***********************************************************************
1531 * SetDeviceGammaRamp (GDI32.@)
1533 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1536 DC *dc = get_dc_ptr( hDC );
1540 if (dc->funcs->pSetDeviceGammaRamp)
1541 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1542 release_dc_ptr( dc );
1547 /***********************************************************************
1548 * GetColorSpace (GDI32.@)
1550 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1552 /*FIXME Need to to whatever GetColorSpace actually does */
1556 /***********************************************************************
1557 * CreateColorSpaceA (GDI32.@)
1559 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1565 /***********************************************************************
1566 * CreateColorSpaceW (GDI32.@)
1568 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1574 /***********************************************************************
1575 * DeleteColorSpace (GDI32.@)
1577 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1584 /***********************************************************************
1585 * SetColorSpace (GDI32.@)
1587 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1594 /***********************************************************************
1595 * GetBoundsRect (GDI32.@)
1597 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1600 DC *dc = get_dc_ptr( hdc );
1602 if ( !dc ) return 0;
1604 if (rect) *rect = dc->BoundsRect;
1606 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1608 if (flags & DCB_RESET)
1610 dc->BoundsRect.left = 0;
1611 dc->BoundsRect.top = 0;
1612 dc->BoundsRect.right = 0;
1613 dc->BoundsRect.bottom = 0;
1614 dc->flags &= ~DC_BOUNDS_SET;
1616 release_dc_ptr( dc );
1621 /***********************************************************************
1622 * SetBoundsRect (GDI32.@)
1624 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1629 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1630 if (!(dc = get_dc_ptr( hdc ))) return 0;
1632 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1633 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1635 if (flags & DCB_RESET)
1637 dc->BoundsRect.left = 0;
1638 dc->BoundsRect.top = 0;
1639 dc->BoundsRect.right = 0;
1640 dc->BoundsRect.bottom = 0;
1641 dc->flags &= ~DC_BOUNDS_SET;
1644 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1646 if (dc->flags & DC_BOUNDS_SET)
1648 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1649 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1650 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1651 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1655 dc->BoundsRect = *rect;
1656 dc->flags |= DC_BOUNDS_SET;
1660 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1661 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1663 release_dc_ptr( dc );
1668 /***********************************************************************
1669 * GetRelAbs (GDI32.@)
1671 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1674 DC *dc = get_dc_ptr( hdc );
1677 ret = dc->relAbsMode;
1678 release_dc_ptr( dc );
1686 /***********************************************************************
1687 * GetBkMode (GDI32.@)
1689 INT WINAPI GetBkMode( HDC hdc )
1692 DC * dc = get_dc_ptr( hdc );
1695 ret = dc->backgroundMode;
1696 release_dc_ptr( dc );
1702 /***********************************************************************
1703 * SetBkMode (GDI32.@)
1705 INT WINAPI SetBkMode( HDC hdc, INT mode )
1709 if ((mode <= 0) || (mode > BKMODE_LAST))
1711 SetLastError(ERROR_INVALID_PARAMETER);
1714 if (!(dc = get_dc_ptr( hdc ))) return 0;
1716 ret = dc->backgroundMode;
1717 if (dc->funcs->pSetBkMode)
1718 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1721 dc->backgroundMode = mode;
1722 release_dc_ptr( dc );
1727 /***********************************************************************
1730 INT WINAPI GetROP2( HDC hdc )
1733 DC * dc = get_dc_ptr( hdc );
1737 release_dc_ptr( dc );
1743 /***********************************************************************
1746 INT WINAPI SetROP2( HDC hdc, INT mode )
1750 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1752 SetLastError(ERROR_INVALID_PARAMETER);
1755 if (!(dc = get_dc_ptr( hdc ))) return 0;
1757 if (dc->funcs->pSetROP2)
1758 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1762 release_dc_ptr( dc );
1767 /***********************************************************************
1768 * SetRelAbs (GDI32.@)
1770 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1774 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1776 SetLastError(ERROR_INVALID_PARAMETER);
1779 if (!(dc = get_dc_ptr( hdc ))) return 0;
1780 if (dc->funcs->pSetRelAbs)
1781 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1784 ret = dc->relAbsMode;
1785 dc->relAbsMode = mode;
1787 release_dc_ptr( dc );
1792 /***********************************************************************
1793 * GetPolyFillMode (GDI32.@)
1795 INT WINAPI GetPolyFillMode( HDC hdc )
1798 DC * dc = get_dc_ptr( hdc );
1801 ret = dc->polyFillMode;
1802 release_dc_ptr( dc );
1808 /***********************************************************************
1809 * SetPolyFillMode (GDI32.@)
1811 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1815 if ((mode <= 0) || (mode > POLYFILL_LAST))
1817 SetLastError(ERROR_INVALID_PARAMETER);
1820 if (!(dc = get_dc_ptr( hdc ))) return 0;
1821 ret = dc->polyFillMode;
1822 if (dc->funcs->pSetPolyFillMode)
1823 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1826 dc->polyFillMode = mode;
1827 release_dc_ptr( dc );
1832 /***********************************************************************
1833 * GetStretchBltMode (GDI32.@)
1835 INT WINAPI GetStretchBltMode( HDC hdc )
1838 DC * dc = get_dc_ptr( hdc );
1841 ret = dc->stretchBltMode;
1842 release_dc_ptr( dc );
1848 /***********************************************************************
1849 * SetStretchBltMode (GDI32.@)
1851 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1855 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1857 SetLastError(ERROR_INVALID_PARAMETER);
1860 if (!(dc = get_dc_ptr( hdc ))) return 0;
1861 ret = dc->stretchBltMode;
1862 if (dc->funcs->pSetStretchBltMode)
1863 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1866 dc->stretchBltMode = mode;
1867 release_dc_ptr( dc );
1872 /***********************************************************************
1873 * GetMapMode (GDI32.@)
1875 INT WINAPI GetMapMode( HDC hdc )
1878 DC * dc = get_dc_ptr( hdc );
1882 release_dc_ptr( dc );
1888 /***********************************************************************
1889 * GetBrushOrgEx (GDI32.@)
1891 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1893 DC * dc = get_dc_ptr( hdc );
1894 if (!dc) return FALSE;
1895 pt->x = dc->brushOrgX;
1896 pt->y = dc->brushOrgY;
1897 release_dc_ptr( dc );
1902 /***********************************************************************
1903 * GetCurrentPositionEx (GDI32.@)
1905 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1907 DC * dc = get_dc_ptr( hdc );
1908 if (!dc) return FALSE;
1909 pt->x = dc->CursPosX;
1910 pt->y = dc->CursPosY;
1911 release_dc_ptr( dc );
1916 /***********************************************************************
1917 * GetViewportExtEx (GDI32.@)
1919 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1921 DC * dc = get_dc_ptr( hdc );
1922 if (!dc) return FALSE;
1923 size->cx = dc->vportExtX;
1924 size->cy = dc->vportExtY;
1925 release_dc_ptr( dc );
1930 /***********************************************************************
1931 * GetViewportOrgEx (GDI32.@)
1933 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1935 DC * dc = get_dc_ptr( hdc );
1936 if (!dc) return FALSE;
1937 pt->x = dc->vportOrgX;
1938 pt->y = dc->vportOrgY;
1939 release_dc_ptr( dc );
1944 /***********************************************************************
1945 * GetWindowExtEx (GDI32.@)
1947 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1949 DC * dc = get_dc_ptr( hdc );
1950 if (!dc) return FALSE;
1951 size->cx = dc->wndExtX;
1952 size->cy = dc->wndExtY;
1953 release_dc_ptr( dc );
1958 /***********************************************************************
1959 * GetWindowOrgEx (GDI32.@)
1961 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1963 DC * dc = get_dc_ptr( hdc );
1964 if (!dc) return FALSE;
1965 pt->x = dc->wndOrgX;
1966 pt->y = dc->wndOrgY;
1967 release_dc_ptr( dc );
1972 /***********************************************************************
1973 * InquireVisRgn (GDI.131)
1975 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1978 DC * dc = get_dc_ptr( HDC_32(hdc) );
1981 ret = HRGN_16(dc->hVisRgn);
1982 release_dc_ptr( dc );
1988 /***********************************************************************
1989 * GetClipRgn (GDI.173)
1991 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
1994 DC * dc = get_dc_ptr( HDC_32(hdc) );
1997 ret = HRGN_16(dc->hClipRgn);
1998 release_dc_ptr( dc );
2004 /***********************************************************************
2005 * GetLayout (GDI32.@)
2007 * Gets left->right or right->left text layout flags of a dc.
2010 DWORD WINAPI GetLayout(HDC hdc)
2012 DWORD layout = GDI_ERROR;
2014 DC * dc = get_dc_ptr( hdc );
2017 layout = dc->layout;
2018 release_dc_ptr( dc );
2021 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
2026 /***********************************************************************
2027 * SetLayout (GDI32.@)
2029 * Sets left->right or right->left text layout flags of a dc.
2032 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
2034 DWORD oldlayout = GDI_ERROR;
2036 DC * dc = get_dc_ptr( hdc );
2039 oldlayout = dc->layout;
2040 dc->layout = layout;
2041 release_dc_ptr( dc );
2044 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
2049 /***********************************************************************
2050 * GetDCBrushColor (GDI32.@)
2052 * Retrieves the current brush color for the specified device
2056 COLORREF WINAPI GetDCBrushColor(HDC hdc)
2059 COLORREF dcBrushColor = CLR_INVALID;
2061 TRACE("hdc(%p)\n", hdc);
2063 dc = get_dc_ptr( hdc );
2066 dcBrushColor = dc->dcBrushColor;
2067 release_dc_ptr( dc );
2070 return dcBrushColor;
2073 /***********************************************************************
2074 * SetDCBrushColor (GDI32.@)
2076 * Sets the current device context (DC) brush color to the specified
2077 * color value. If the device cannot represent the specified color
2078 * value, the color is set to the nearest physical color.
2081 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2084 COLORREF oldClr = CLR_INVALID;
2086 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2088 dc = get_dc_ptr( hdc );
2091 if (dc->funcs->pSetDCBrushColor)
2092 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2093 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2095 /* If DC_BRUSH is selected, update driver pen color */
2096 HBRUSH hBrush = CreateSolidBrush( crColor );
2097 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2098 DeleteObject( hBrush );
2101 if (crColor != CLR_INVALID)
2103 oldClr = dc->dcBrushColor;
2104 dc->dcBrushColor = crColor;
2107 release_dc_ptr( dc );
2113 /***********************************************************************
2114 * GetDCPenColor (GDI32.@)
2116 * Retrieves the current pen color for the specified device
2120 COLORREF WINAPI GetDCPenColor(HDC hdc)
2123 COLORREF dcPenColor = CLR_INVALID;
2125 TRACE("hdc(%p)\n", hdc);
2127 dc = get_dc_ptr( hdc );
2130 dcPenColor = dc->dcPenColor;
2131 release_dc_ptr( dc );
2137 /***********************************************************************
2138 * SetDCPenColor (GDI32.@)
2140 * Sets the current device context (DC) pen color to the specified
2141 * color value. If the device cannot represent the specified color
2142 * value, the color is set to the nearest physical color.
2145 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2148 COLORREF oldClr = CLR_INVALID;
2150 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2152 dc = get_dc_ptr( hdc );
2155 if (dc->funcs->pSetDCPenColor)
2156 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2157 else if (dc->hPen == GetStockObject( DC_PEN ))
2159 /* If DC_PEN is selected, update the driver pen color */
2160 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2161 HPEN hPen = CreatePenIndirect( &logpen );
2162 dc->funcs->pSelectPen( dc->physDev, hPen );
2163 DeleteObject( hPen );
2166 if (crColor != CLR_INVALID)
2168 oldClr = dc->dcPenColor;
2169 dc->dcPenColor = crColor;
2172 release_dc_ptr( dc );
2178 /***********************************************************************
2179 * CancelDC (GDI32.@)
2181 BOOL WINAPI CancelDC(HDC hdc)
2187 /***********************************************************************
2188 * SetVirtualResolution (GDI32.@)
2190 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2192 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2194 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2198 /*******************************************************************
2199 * GetMiterLimit [GDI32.@]
2203 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2208 TRACE("(%p,%p)\n", hdc, peLimit);
2210 dc = get_dc_ptr( hdc );
2214 *peLimit = dc->miterLimit;
2216 release_dc_ptr( dc );
2222 /*******************************************************************
2223 * SetMiterLimit [GDI32.@]
2227 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2232 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2234 dc = get_dc_ptr( hdc );
2238 *peOldLimit = dc->miterLimit;
2239 dc->miterLimit = eNewLimit;
2240 release_dc_ptr( dc );
2246 /*******************************************************************
2247 * GdiIsMetaPrintDC [GDI32.@]
2249 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2255 /*******************************************************************
2256 * GdiIsMetaFileDC [GDI32.@]
2258 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2262 switch( GetObjectType( hdc ) )
2271 /*******************************************************************
2272 * GdiIsPlayMetafileDC [GDI32.@]
2274 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)