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 double scaleX, scaleY;
295 /* Construct a transformation to do the window-to-viewport conversion */
296 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
297 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
298 xformWnd2Vport.eM11 = scaleX;
299 xformWnd2Vport.eM12 = 0.0;
300 xformWnd2Vport.eM21 = 0.0;
301 xformWnd2Vport.eM22 = scaleY;
302 xformWnd2Vport.eDx = (double)dc->vportOrgX -
303 scaleX * (double)dc->wndOrgX;
304 xformWnd2Vport.eDy = (double)dc->vportOrgY -
305 scaleY * (double)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 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1243 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1245 if (dc->funcs->pSetWorldTransform)
1247 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1248 if (!ret) goto done;
1251 dc->xformWorld2Wnd = *xform;
1252 DC_UpdateXforms( dc );
1255 release_dc_ptr( dc );
1260 /****************************************************************************
1261 * ModifyWorldTransform [GDI32.@]
1262 * Modifies the world transformation for a device context.
1265 * hdc [I] Handle to device context
1266 * xform [I] XFORM structure that will be used to modify the world
1268 * iMode [I] Specifies in what way to modify the world transformation
1271 * Resets the world transformation to the identity matrix.
1272 * The parameter xform is ignored.
1274 * Multiplies xform into the world transformation matrix from
1277 * Multiplies xform into the world transformation matrix from
1282 * Failure: FALSE. Use GetLastError() to determine the cause.
1284 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1288 DC *dc = get_dc_ptr( hdc );
1290 /* Check for illegal parameters */
1291 if (!dc) return FALSE;
1292 if (!xform && iMode != MWT_IDENTITY) goto done;
1294 /* Check that graphics mode is GM_ADVANCED */
1295 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1297 if (dc->funcs->pModifyWorldTransform)
1299 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1300 if (!ret) goto done;
1306 dc->xformWorld2Wnd.eM11 = 1.0f;
1307 dc->xformWorld2Wnd.eM12 = 0.0f;
1308 dc->xformWorld2Wnd.eM21 = 0.0f;
1309 dc->xformWorld2Wnd.eM22 = 1.0f;
1310 dc->xformWorld2Wnd.eDx = 0.0f;
1311 dc->xformWorld2Wnd.eDy = 0.0f;
1313 case MWT_LEFTMULTIPLY:
1314 CombineTransform( &dc->xformWorld2Wnd, xform,
1315 &dc->xformWorld2Wnd );
1317 case MWT_RIGHTMULTIPLY:
1318 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1325 DC_UpdateXforms( dc );
1328 release_dc_ptr( dc );
1333 /****************************************************************************
1334 * CombineTransform [GDI32.@]
1335 * Combines two transformation matrices.
1338 * xformResult [O] Stores the result of combining the two matrices
1339 * xform1 [I] Specifies the first matrix to apply
1340 * xform2 [I] Specifies the second matrix to apply
1343 * The same matrix can be passed in for more than one of the parameters.
1347 * Failure: FALSE. Use GetLastError() to determine the cause.
1349 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1350 const XFORM *xform2 )
1354 /* Check for illegal parameters */
1355 if (!xformResult || !xform1 || !xform2)
1358 /* Create the result in a temporary XFORM, since xformResult may be
1359 * equal to xform1 or xform2 */
1360 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1361 xform1->eM12 * xform2->eM21;
1362 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1363 xform1->eM12 * xform2->eM22;
1364 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1365 xform1->eM22 * xform2->eM21;
1366 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1367 xform1->eM22 * xform2->eM22;
1368 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1369 xform1->eDy * xform2->eM21 +
1371 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1372 xform1->eDy * xform2->eM22 +
1375 /* Copy the result to xformResult */
1376 *xformResult = xformTemp;
1382 /***********************************************************************
1383 * SetDCHook (GDI32.@)
1385 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1387 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1389 DC *dc = get_dc_ptr( hdc );
1391 if (!dc) return FALSE;
1393 if (!(dc->flags & DC_SAVED))
1395 dc->dwHookData = dwHookData;
1396 dc->hookThunk = hookProc;
1398 release_dc_ptr( dc );
1403 /***********************************************************************
1404 * GetDCHook (GDI32.@)
1406 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1408 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1410 DC *dc = get_dc_ptr( hdc );
1414 if (proc) *proc = dc->hookThunk;
1415 ret = dc->dwHookData;
1416 release_dc_ptr( dc );
1421 /* relay function to call the 16-bit DC hook proc */
1422 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1426 DC *dc = get_dc_ptr( hdc );
1428 if (!dc) return FALSE;
1431 args[5] = HDC_16(hdc);
1433 args[3] = HIWORD(data);
1434 args[2] = LOWORD(data);
1435 args[1] = HIWORD(lParam);
1436 args[0] = LOWORD(lParam);
1437 WOWCallback16Ex( (DWORD)dc->hookProc, WCB16_PASCAL, sizeof(args), args, &ret );
1439 release_dc_ptr( dc );
1443 /***********************************************************************
1444 * SetDCHook (GDI.190)
1446 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1448 DC *dc = get_dc_ptr( HDC_32(hdc16) );
1450 if (!dc) return FALSE;
1451 if (!(dc->flags & DC_SAVED))
1453 dc->dwHookData = dwHookData;
1454 dc->hookThunk = call_dc_hook16;
1455 dc->hookProc = hookProc;
1457 release_dc_ptr( dc );
1462 /***********************************************************************
1463 * GetDCHook (GDI.191)
1465 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1467 HDC hdc = HDC_32( hdc16 );
1468 DC *dc = get_dc_ptr( hdc );
1472 *phookProc = dc->hookProc;
1473 ret = dc->dwHookData;
1474 release_dc_ptr( dc );
1479 /***********************************************************************
1480 * SetHookFlags (GDI32.@)
1482 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1484 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1486 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1491 /* "Undocumented Windows" info is slightly confusing. */
1493 TRACE("hDC %p, flags %04x\n",hdc,flags);
1495 if (flags & DCHF_INVALIDATEVISRGN)
1496 ret = InterlockedExchange( &dc->dirty, 1 );
1497 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1498 ret = InterlockedExchange( &dc->dirty, 0 );
1500 GDI_ReleaseObj( dc );
1504 /***********************************************************************
1505 * SetICMMode (GDI32.@)
1507 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1509 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1510 if (iEnableICM == ICM_OFF) return ICM_OFF;
1511 if (iEnableICM == ICM_ON) return 0;
1512 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1516 /***********************************************************************
1517 * GetDeviceGammaRamp (GDI32.@)
1519 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1522 DC *dc = get_dc_ptr( hDC );
1526 if (dc->funcs->pGetDeviceGammaRamp)
1527 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1528 release_dc_ptr( dc );
1533 /***********************************************************************
1534 * SetDeviceGammaRamp (GDI32.@)
1536 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1539 DC *dc = get_dc_ptr( hDC );
1543 if (dc->funcs->pSetDeviceGammaRamp)
1544 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1545 release_dc_ptr( dc );
1550 /***********************************************************************
1551 * GetColorSpace (GDI32.@)
1553 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1555 /*FIXME Need to to whatever GetColorSpace actually does */
1559 /***********************************************************************
1560 * CreateColorSpaceA (GDI32.@)
1562 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1568 /***********************************************************************
1569 * CreateColorSpaceW (GDI32.@)
1571 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1577 /***********************************************************************
1578 * DeleteColorSpace (GDI32.@)
1580 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1587 /***********************************************************************
1588 * SetColorSpace (GDI32.@)
1590 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1597 /***********************************************************************
1598 * GetBoundsRect (GDI32.@)
1600 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1603 DC *dc = get_dc_ptr( hdc );
1605 if ( !dc ) return 0;
1607 if (rect) *rect = dc->BoundsRect;
1609 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1611 if (flags & DCB_RESET)
1613 dc->BoundsRect.left = 0;
1614 dc->BoundsRect.top = 0;
1615 dc->BoundsRect.right = 0;
1616 dc->BoundsRect.bottom = 0;
1617 dc->flags &= ~DC_BOUNDS_SET;
1619 release_dc_ptr( dc );
1624 /***********************************************************************
1625 * SetBoundsRect (GDI32.@)
1627 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1632 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1633 if (!(dc = get_dc_ptr( hdc ))) return 0;
1635 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1636 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1638 if (flags & DCB_RESET)
1640 dc->BoundsRect.left = 0;
1641 dc->BoundsRect.top = 0;
1642 dc->BoundsRect.right = 0;
1643 dc->BoundsRect.bottom = 0;
1644 dc->flags &= ~DC_BOUNDS_SET;
1647 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1649 if (dc->flags & DC_BOUNDS_SET)
1651 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1652 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1653 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1654 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1658 dc->BoundsRect = *rect;
1659 dc->flags |= DC_BOUNDS_SET;
1663 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1664 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1666 release_dc_ptr( dc );
1671 /***********************************************************************
1672 * GetRelAbs (GDI32.@)
1674 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1677 DC *dc = get_dc_ptr( hdc );
1680 ret = dc->relAbsMode;
1681 release_dc_ptr( dc );
1689 /***********************************************************************
1690 * GetBkMode (GDI32.@)
1692 INT WINAPI GetBkMode( HDC hdc )
1695 DC * dc = get_dc_ptr( hdc );
1698 ret = dc->backgroundMode;
1699 release_dc_ptr( dc );
1705 /***********************************************************************
1706 * SetBkMode (GDI32.@)
1708 INT WINAPI SetBkMode( HDC hdc, INT mode )
1712 if ((mode <= 0) || (mode > BKMODE_LAST))
1714 SetLastError(ERROR_INVALID_PARAMETER);
1717 if (!(dc = get_dc_ptr( hdc ))) return 0;
1719 ret = dc->backgroundMode;
1720 if (dc->funcs->pSetBkMode)
1721 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1724 dc->backgroundMode = mode;
1725 release_dc_ptr( dc );
1730 /***********************************************************************
1733 INT WINAPI GetROP2( HDC hdc )
1736 DC * dc = get_dc_ptr( hdc );
1740 release_dc_ptr( dc );
1746 /***********************************************************************
1749 INT WINAPI SetROP2( HDC hdc, INT mode )
1753 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1755 SetLastError(ERROR_INVALID_PARAMETER);
1758 if (!(dc = get_dc_ptr( hdc ))) return 0;
1760 if (dc->funcs->pSetROP2)
1761 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1765 release_dc_ptr( dc );
1770 /***********************************************************************
1771 * SetRelAbs (GDI32.@)
1773 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1777 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1779 SetLastError(ERROR_INVALID_PARAMETER);
1782 if (!(dc = get_dc_ptr( hdc ))) return 0;
1783 if (dc->funcs->pSetRelAbs)
1784 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1787 ret = dc->relAbsMode;
1788 dc->relAbsMode = mode;
1790 release_dc_ptr( dc );
1795 /***********************************************************************
1796 * GetPolyFillMode (GDI32.@)
1798 INT WINAPI GetPolyFillMode( HDC hdc )
1801 DC * dc = get_dc_ptr( hdc );
1804 ret = dc->polyFillMode;
1805 release_dc_ptr( dc );
1811 /***********************************************************************
1812 * SetPolyFillMode (GDI32.@)
1814 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1818 if ((mode <= 0) || (mode > POLYFILL_LAST))
1820 SetLastError(ERROR_INVALID_PARAMETER);
1823 if (!(dc = get_dc_ptr( hdc ))) return 0;
1824 ret = dc->polyFillMode;
1825 if (dc->funcs->pSetPolyFillMode)
1826 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1829 dc->polyFillMode = mode;
1830 release_dc_ptr( dc );
1835 /***********************************************************************
1836 * GetStretchBltMode (GDI32.@)
1838 INT WINAPI GetStretchBltMode( HDC hdc )
1841 DC * dc = get_dc_ptr( hdc );
1844 ret = dc->stretchBltMode;
1845 release_dc_ptr( dc );
1851 /***********************************************************************
1852 * SetStretchBltMode (GDI32.@)
1854 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1858 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1860 SetLastError(ERROR_INVALID_PARAMETER);
1863 if (!(dc = get_dc_ptr( hdc ))) return 0;
1864 ret = dc->stretchBltMode;
1865 if (dc->funcs->pSetStretchBltMode)
1866 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1869 dc->stretchBltMode = mode;
1870 release_dc_ptr( dc );
1875 /***********************************************************************
1876 * GetMapMode (GDI32.@)
1878 INT WINAPI GetMapMode( HDC hdc )
1881 DC * dc = get_dc_ptr( hdc );
1885 release_dc_ptr( dc );
1891 /***********************************************************************
1892 * GetBrushOrgEx (GDI32.@)
1894 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1896 DC * dc = get_dc_ptr( hdc );
1897 if (!dc) return FALSE;
1898 pt->x = dc->brushOrgX;
1899 pt->y = dc->brushOrgY;
1900 release_dc_ptr( dc );
1905 /***********************************************************************
1906 * GetCurrentPositionEx (GDI32.@)
1908 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1910 DC * dc = get_dc_ptr( hdc );
1911 if (!dc) return FALSE;
1912 pt->x = dc->CursPosX;
1913 pt->y = dc->CursPosY;
1914 release_dc_ptr( dc );
1919 /***********************************************************************
1920 * GetViewportExtEx (GDI32.@)
1922 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1924 DC * dc = get_dc_ptr( hdc );
1925 if (!dc) return FALSE;
1926 size->cx = dc->vportExtX;
1927 size->cy = dc->vportExtY;
1928 release_dc_ptr( dc );
1933 /***********************************************************************
1934 * GetViewportOrgEx (GDI32.@)
1936 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1938 DC * dc = get_dc_ptr( hdc );
1939 if (!dc) return FALSE;
1940 pt->x = dc->vportOrgX;
1941 pt->y = dc->vportOrgY;
1942 release_dc_ptr( dc );
1947 /***********************************************************************
1948 * GetWindowExtEx (GDI32.@)
1950 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1952 DC * dc = get_dc_ptr( hdc );
1953 if (!dc) return FALSE;
1954 size->cx = dc->wndExtX;
1955 size->cy = dc->wndExtY;
1956 release_dc_ptr( dc );
1961 /***********************************************************************
1962 * GetWindowOrgEx (GDI32.@)
1964 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1966 DC * dc = get_dc_ptr( hdc );
1967 if (!dc) return FALSE;
1968 pt->x = dc->wndOrgX;
1969 pt->y = dc->wndOrgY;
1970 release_dc_ptr( dc );
1975 /***********************************************************************
1976 * InquireVisRgn (GDI.131)
1978 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1981 DC * dc = get_dc_ptr( HDC_32(hdc) );
1984 ret = HRGN_16(dc->hVisRgn);
1985 release_dc_ptr( dc );
1991 /***********************************************************************
1992 * GetClipRgn (GDI.173)
1994 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
1997 DC * dc = get_dc_ptr( HDC_32(hdc) );
2000 ret = HRGN_16(dc->hClipRgn);
2001 release_dc_ptr( dc );
2007 /***********************************************************************
2008 * GetLayout (GDI32.@)
2010 * Gets left->right or right->left text layout flags of a dc.
2013 DWORD WINAPI GetLayout(HDC hdc)
2015 DWORD layout = GDI_ERROR;
2017 DC * dc = get_dc_ptr( hdc );
2020 layout = dc->layout;
2021 release_dc_ptr( dc );
2024 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
2029 /***********************************************************************
2030 * SetLayout (GDI32.@)
2032 * Sets left->right or right->left text layout flags of a dc.
2035 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
2037 DWORD oldlayout = GDI_ERROR;
2039 DC * dc = get_dc_ptr( hdc );
2042 oldlayout = dc->layout;
2043 dc->layout = layout;
2044 release_dc_ptr( dc );
2047 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
2052 /***********************************************************************
2053 * GetDCBrushColor (GDI32.@)
2055 * Retrieves the current brush color for the specified device
2059 COLORREF WINAPI GetDCBrushColor(HDC hdc)
2062 COLORREF dcBrushColor = CLR_INVALID;
2064 TRACE("hdc(%p)\n", hdc);
2066 dc = get_dc_ptr( hdc );
2069 dcBrushColor = dc->dcBrushColor;
2070 release_dc_ptr( dc );
2073 return dcBrushColor;
2076 /***********************************************************************
2077 * SetDCBrushColor (GDI32.@)
2079 * Sets the current device context (DC) brush color to the specified
2080 * color value. If the device cannot represent the specified color
2081 * value, the color is set to the nearest physical color.
2084 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2087 COLORREF oldClr = CLR_INVALID;
2089 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2091 dc = get_dc_ptr( hdc );
2094 if (dc->funcs->pSetDCBrushColor)
2095 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2096 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2098 /* If DC_BRUSH is selected, update driver pen color */
2099 HBRUSH hBrush = CreateSolidBrush( crColor );
2100 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2101 DeleteObject( hBrush );
2104 if (crColor != CLR_INVALID)
2106 oldClr = dc->dcBrushColor;
2107 dc->dcBrushColor = crColor;
2110 release_dc_ptr( dc );
2116 /***********************************************************************
2117 * GetDCPenColor (GDI32.@)
2119 * Retrieves the current pen color for the specified device
2123 COLORREF WINAPI GetDCPenColor(HDC hdc)
2126 COLORREF dcPenColor = CLR_INVALID;
2128 TRACE("hdc(%p)\n", hdc);
2130 dc = get_dc_ptr( hdc );
2133 dcPenColor = dc->dcPenColor;
2134 release_dc_ptr( dc );
2140 /***********************************************************************
2141 * SetDCPenColor (GDI32.@)
2143 * Sets the current device context (DC) pen color to the specified
2144 * color value. If the device cannot represent the specified color
2145 * value, the color is set to the nearest physical color.
2148 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2151 COLORREF oldClr = CLR_INVALID;
2153 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2155 dc = get_dc_ptr( hdc );
2158 if (dc->funcs->pSetDCPenColor)
2159 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2160 else if (dc->hPen == GetStockObject( DC_PEN ))
2162 /* If DC_PEN is selected, update the driver pen color */
2163 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2164 HPEN hPen = CreatePenIndirect( &logpen );
2165 dc->funcs->pSelectPen( dc->physDev, hPen );
2166 DeleteObject( hPen );
2169 if (crColor != CLR_INVALID)
2171 oldClr = dc->dcPenColor;
2172 dc->dcPenColor = crColor;
2175 release_dc_ptr( dc );
2181 /***********************************************************************
2182 * CancelDC (GDI32.@)
2184 BOOL WINAPI CancelDC(HDC hdc)
2190 /***********************************************************************
2191 * SetVirtualResolution (GDI32.@)
2193 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2195 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2197 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2201 /*******************************************************************
2202 * GetMiterLimit [GDI32.@]
2206 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2211 TRACE("(%p,%p)\n", hdc, peLimit);
2213 dc = get_dc_ptr( hdc );
2217 *peLimit = dc->miterLimit;
2219 release_dc_ptr( dc );
2225 /*******************************************************************
2226 * SetMiterLimit [GDI32.@]
2230 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2235 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2237 dc = get_dc_ptr( hdc );
2241 *peOldLimit = dc->miterLimit;
2242 dc->miterLimit = eNewLimit;
2243 release_dc_ptr( dc );
2249 /*******************************************************************
2250 * GdiIsMetaPrintDC [GDI32.@]
2252 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2258 /*******************************************************************
2259 * GdiIsMetaFileDC [GDI32.@]
2261 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2265 switch( GetObjectType( hdc ) )
2274 /*******************************************************************
2275 * GdiIsPlayMetafileDC [GDI32.@]
2277 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)