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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "wine/winuser16.h"
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dc);
41 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
43 static const struct gdi_obj_funcs dc_funcs =
45 NULL, /* pSelectObject */
46 NULL, /* pGetObject16 */
47 NULL, /* pGetObjectA */
48 NULL, /* pGetObjectW */
49 NULL, /* pUnrealizeObject */
50 DC_DeleteObject /* pDeleteObject */
53 /***********************************************************************
56 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
61 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
79 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
86 dc->hPen = GetStockObject( BLACK_PEN );
87 dc->hBrush = GetStockObject( WHITE_BRUSH );
88 dc->hFont = GetStockObject( SYSTEM_FONT );
91 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
93 dc->ROPmode = R2_COPYPEN;
94 dc->polyFillMode = ALTERNATE;
95 dc->stretchBltMode = BLACKONWHITE;
96 dc->relAbsMode = ABSOLUTE;
97 dc->backgroundMode = OPAQUE;
98 dc->backgroundColor = RGB( 255, 255, 255 );
99 dc->dcBrushColor = RGB( 255, 255, 255 );
100 dc->dcPenColor = RGB( 0, 0, 0 );
101 dc->textColor = RGB( 0, 0, 0 );
104 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
108 dc->MapMode = MM_TEXT;
109 dc->GraphicsMode = GM_COMPATIBLE;
110 dc->pAbortProc = NULL;
113 dc->ArcDirection = AD_COUNTERCLOCKWISE;
114 dc->xformWorld2Wnd.eM11 = 1.0f;
115 dc->xformWorld2Wnd.eM12 = 0.0f;
116 dc->xformWorld2Wnd.eM21 = 0.0f;
117 dc->xformWorld2Wnd.eM22 = 1.0f;
118 dc->xformWorld2Wnd.eDx = 0.0f;
119 dc->xformWorld2Wnd.eDy = 0.0f;
120 dc->xformWorld2Vport = dc->xformWorld2Wnd;
121 dc->xformVport2World = dc->xformWorld2Wnd;
122 dc->vport2WorldValid = TRUE;
123 dc->BoundsRect.left = 0;
124 dc->BoundsRect.top = 0;
125 dc->BoundsRect.right = 0;
126 dc->BoundsRect.bottom = 0;
127 dc->saved_visrgn = NULL;
128 PATH_InitGdiPath(&dc->path);
134 /***********************************************************************
137 DC *DC_GetDCPtr( HDC hdc )
139 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
140 if (!ptr) return NULL;
141 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
142 (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
143 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
144 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
146 GDI_ReleaseObj( hdc );
147 SetLastError( ERROR_INVALID_HANDLE );
151 /***********************************************************************
154 * Retrieve a DC ptr while making sure the visRgn is updated.
155 * This function may call up to USER so the GDI lock should _not_
156 * be held when calling it.
158 DC *DC_GetDCUpdate( HDC hdc )
160 DC *dc = DC_GetDCPtr( hdc );
161 if (!dc) return NULL;
162 while (dc->flags & DC_DIRTY)
164 DCHOOKPROC proc = dc->hookThunk;
165 dc->flags &= ~DC_DIRTY;
168 DWORD data = dc->dwHookData;
169 GDI_ReleaseObj( hdc );
170 proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
171 if (!(dc = DC_GetDCPtr( hdc ))) break;
172 /* otherwise restart the loop in case it became dirty again in the meantime */
179 /***********************************************************************
182 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
184 GDI_ReleaseObj( handle );
185 return DeleteDC( handle );
189 /***********************************************************************
192 * Setup device-specific DC values for a newly created DC.
194 void DC_InitDC( DC* dc )
196 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
197 SetTextColor( dc->hSelf, dc->textColor );
198 SetBkColor( dc->hSelf, dc->backgroundColor );
199 SelectObject( dc->hSelf, dc->hPen );
200 SelectObject( dc->hSelf, dc->hBrush );
201 SelectObject( dc->hSelf, dc->hFont );
202 CLIPPING_UpdateGCRegion( dc );
206 /***********************************************************************
209 * Computes the inverse of the transformation xformSrc and stores it to
210 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
213 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
217 determinant = xformSrc->eM11*xformSrc->eM22 -
218 xformSrc->eM12*xformSrc->eM21;
219 if (determinant > -1e-12 && determinant < 1e-12)
222 xformDest->eM11 = xformSrc->eM22 / determinant;
223 xformDest->eM12 = -xformSrc->eM12 / determinant;
224 xformDest->eM21 = -xformSrc->eM21 / determinant;
225 xformDest->eM22 = xformSrc->eM11 / determinant;
226 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
227 xformSrc->eDy * xformDest->eM21;
228 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
229 xformSrc->eDy * xformDest->eM22;
235 /***********************************************************************
238 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
239 * fields of the specified DC by creating a transformation that
240 * represents the current mapping mode and combining it with the DC's
241 * world transform. This function should be called whenever the
242 * parameters associated with the mapping mode (window and viewport
243 * extents and origins) or the world transform change.
245 void DC_UpdateXforms( DC *dc )
247 XFORM xformWnd2Vport, oldworld2vport;
248 FLOAT scaleX, scaleY;
250 /* Construct a transformation to do the window-to-viewport conversion */
251 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
252 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
253 xformWnd2Vport.eM11 = scaleX;
254 xformWnd2Vport.eM12 = 0.0;
255 xformWnd2Vport.eM21 = 0.0;
256 xformWnd2Vport.eM22 = scaleY;
257 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
258 scaleX * (FLOAT)dc->wndOrgX;
259 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
260 scaleY * (FLOAT)dc->wndOrgY;
262 oldworld2vport = dc->xformWorld2Vport;
263 /* Combine with the world transformation */
264 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
267 /* Create inverse of world-to-viewport transformation */
268 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
269 &dc->xformVport2World );
271 /* Reselect the font and pen back into the dc so that the size
273 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
275 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
276 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
281 /***********************************************************************
282 * GetDCState (Not a Windows API)
284 HDC WINAPI GetDCState( HDC hdc )
289 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
290 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
292 GDI_ReleaseObj( hdc );
295 TRACE("(%p): returning %p\n", hdc, handle );
297 newdc->flags = dc->flags | DC_SAVED;
298 newdc->layout = dc->layout;
299 newdc->hPen = dc->hPen;
300 newdc->hBrush = dc->hBrush;
301 newdc->hFont = dc->hFont;
302 newdc->hBitmap = dc->hBitmap;
303 newdc->hDevice = dc->hDevice;
304 newdc->hPalette = dc->hPalette;
305 newdc->ROPmode = dc->ROPmode;
306 newdc->polyFillMode = dc->polyFillMode;
307 newdc->stretchBltMode = dc->stretchBltMode;
308 newdc->relAbsMode = dc->relAbsMode;
309 newdc->backgroundMode = dc->backgroundMode;
310 newdc->backgroundColor = dc->backgroundColor;
311 newdc->textColor = dc->textColor;
312 newdc->dcBrushColor = dc->dcBrushColor;
313 newdc->dcPenColor = dc->dcPenColor;
314 newdc->brushOrgX = dc->brushOrgX;
315 newdc->brushOrgY = dc->brushOrgY;
316 newdc->textAlign = dc->textAlign;
317 newdc->charExtra = dc->charExtra;
318 newdc->breakExtra = dc->breakExtra;
319 newdc->breakRem = dc->breakRem;
320 newdc->MapMode = dc->MapMode;
321 newdc->GraphicsMode = dc->GraphicsMode;
322 newdc->CursPosX = dc->CursPosX;
323 newdc->CursPosY = dc->CursPosY;
324 newdc->ArcDirection = dc->ArcDirection;
325 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
326 newdc->xformWorld2Vport = dc->xformWorld2Vport;
327 newdc->xformVport2World = dc->xformVport2World;
328 newdc->vport2WorldValid = dc->vport2WorldValid;
329 newdc->wndOrgX = dc->wndOrgX;
330 newdc->wndOrgY = dc->wndOrgY;
331 newdc->wndExtX = dc->wndExtX;
332 newdc->wndExtY = dc->wndExtY;
333 newdc->vportOrgX = dc->vportOrgX;
334 newdc->vportOrgY = dc->vportOrgY;
335 newdc->vportExtX = dc->vportExtX;
336 newdc->vportExtY = dc->vportExtY;
337 newdc->BoundsRect = dc->BoundsRect;
339 newdc->hSelf = (HDC)handle;
340 newdc->saveLevel = 0;
343 PATH_InitGdiPath( &newdc->path );
345 newdc->pAbortProc = NULL;
346 newdc->hookThunk = NULL;
348 newdc->saved_visrgn = NULL;
350 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
355 newdc->hMetaClipRgn = 0;
358 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
359 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
363 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
364 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
366 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
369 newdc->gdiFont = dc->gdiFont;
373 GDI_ReleaseObj( handle );
374 GDI_ReleaseObj( hdc );
379 /***********************************************************************
380 * SetDCState (Not a Windows API)
382 void WINAPI SetDCState( HDC hdc, HDC hdcs )
386 if (!(dc = DC_GetDCUpdate( hdc ))) return;
387 if (!(dcs = DC_GetDCPtr( hdcs )))
389 GDI_ReleaseObj( hdc );
392 if (!dcs->flags & DC_SAVED)
394 GDI_ReleaseObj( hdc );
395 GDI_ReleaseObj( hdcs );
398 TRACE("%p %p\n", hdc, hdcs );
400 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
401 dc->layout = dcs->layout;
402 dc->hDevice = dcs->hDevice;
403 dc->ROPmode = dcs->ROPmode;
404 dc->polyFillMode = dcs->polyFillMode;
405 dc->stretchBltMode = dcs->stretchBltMode;
406 dc->relAbsMode = dcs->relAbsMode;
407 dc->backgroundMode = dcs->backgroundMode;
408 dc->backgroundColor = dcs->backgroundColor;
409 dc->textColor = dcs->textColor;
410 dc->dcBrushColor = dcs->dcBrushColor;
411 dc->dcPenColor = dcs->dcPenColor;
412 dc->brushOrgX = dcs->brushOrgX;
413 dc->brushOrgY = dcs->brushOrgY;
414 dc->textAlign = dcs->textAlign;
415 dc->charExtra = dcs->charExtra;
416 dc->breakExtra = dcs->breakExtra;
417 dc->breakRem = dcs->breakRem;
418 dc->MapMode = dcs->MapMode;
419 dc->GraphicsMode = dcs->GraphicsMode;
420 dc->CursPosX = dcs->CursPosX;
421 dc->CursPosY = dcs->CursPosY;
422 dc->ArcDirection = dcs->ArcDirection;
423 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
424 dc->xformWorld2Vport = dcs->xformWorld2Vport;
425 dc->xformVport2World = dcs->xformVport2World;
426 dc->vport2WorldValid = dcs->vport2WorldValid;
427 dc->BoundsRect = dcs->BoundsRect;
429 dc->wndOrgX = dcs->wndOrgX;
430 dc->wndOrgY = dcs->wndOrgY;
431 dc->wndExtX = dcs->wndExtX;
432 dc->wndExtY = dcs->wndExtY;
433 dc->vportOrgX = dcs->vportOrgX;
434 dc->vportOrgY = dcs->vportOrgY;
435 dc->vportExtX = dcs->vportExtX;
436 dc->vportExtY = dcs->vportExtY;
440 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
441 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
445 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
450 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
451 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
455 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
458 CLIPPING_UpdateGCRegion( dc );
460 SelectObject( hdc, dcs->hBitmap );
461 SelectObject( hdc, dcs->hBrush );
462 SelectObject( hdc, dcs->hFont );
463 SelectObject( hdc, dcs->hPen );
464 SetBkColor( hdc, dcs->backgroundColor);
465 SetTextColor( hdc, dcs->textColor);
466 GDISelectPalette( hdc, dcs->hPalette, FALSE );
467 GDI_ReleaseObj( hdcs );
468 GDI_ReleaseObj( hdc );
472 /***********************************************************************
473 * GetDCState (GDI.179)
475 HDC16 WINAPI GetDCState16( HDC16 hdc )
477 return HDC_16( GetDCState( HDC_32(hdc) ));
481 /***********************************************************************
482 * SetDCState (GDI.180)
484 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
486 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
490 /***********************************************************************
493 INT WINAPI SaveDC( HDC hdc )
499 dc = DC_GetDCPtr( hdc );
502 if(dc->funcs->pSaveDC)
504 ret = dc->funcs->pSaveDC( dc->physDev );
505 GDI_ReleaseObj( hdc );
509 if (!(hdcs = GetDCState( hdc )))
511 GDI_ReleaseObj( hdc );
514 dcs = DC_GetDCPtr( hdcs );
516 /* Copy path. The reason why path saving / restoring is in SaveDC/
517 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
518 * functions are only in Win16 (which doesn't have paths) and that
519 * SetDCState doesn't allow us to signal an error (which can happen
520 * when copying paths).
522 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
524 GDI_ReleaseObj( hdc );
525 GDI_ReleaseObj( hdcs );
530 dcs->saved_dc = dc->saved_dc;
532 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
533 ret = ++dc->saveLevel;
534 GDI_ReleaseObj( hdcs );
535 GDI_ReleaseObj( hdc );
540 /***********************************************************************
541 * RestoreDC (GDI32.@)
543 BOOL WINAPI RestoreDC( HDC hdc, INT level )
548 TRACE("%p %d\n", hdc, level );
549 dc = DC_GetDCUpdate( hdc );
550 if(!dc) return FALSE;
551 if(dc->funcs->pRestoreDC)
553 success = dc->funcs->pRestoreDC( dc->physDev, level );
554 GDI_ReleaseObj( hdc );
558 if (level == -1) level = dc->saveLevel;
560 /* This pair of checks disagrees with MSDN "Platform SDK:
561 Windows GDI" July 2000 which says all negative values
562 for level will be interpreted as an instance relative
563 to the current state. Restricting it to just -1 does
565 || (level > dc->saveLevel))
567 GDI_ReleaseObj( hdc );
572 while (dc->saveLevel >= level)
574 HDC hdcs = dc->saved_dc;
575 if (!(dcs = DC_GetDCPtr( hdcs )))
577 GDI_ReleaseObj( hdc );
580 dc->saved_dc = dcs->saved_dc;
582 if (--dc->saveLevel < level)
584 SetDCState( hdc, hdcs );
585 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
586 /* FIXME: This might not be quite right, since we're
587 * returning FALSE but still destroying the saved DC state */
590 GDI_ReleaseObj( hdcs );
591 GDI_ReleaseObj( hdc );
593 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
595 GDI_ReleaseObj( hdc );
600 /***********************************************************************
601 * CreateDCW (GDI32.@)
603 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
604 const DEVMODEW *initData )
608 const DC_FUNCTIONS *funcs;
613 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
615 if (!driver) return 0;
616 strcpyW(buf, driver);
619 if (!(funcs = DRIVER_load_driver( buf )))
621 ERR( "no driver found for %s\n", debugstr_w(buf) );
624 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
626 DRIVER_release_driver( funcs );
631 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
633 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
634 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
636 if (dc->funcs->pCreateDC &&
637 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
639 WARN("creation aborted by device\n" );
640 GDI_FreeObject( dc->hSelf, dc );
641 DRIVER_release_driver( funcs );
645 dc->hVisRgn = CreateRectRgn( 0, 0, GetDeviceCaps( hdc, HORZRES ),
646 GetDeviceCaps( hdc, VERTRES ) );
649 GDI_ReleaseObj( hdc );
654 /***********************************************************************
655 * CreateDCA (GDI32.@)
657 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
658 const DEVMODEA *initData )
660 UNICODE_STRING driverW, deviceW, outputW;
664 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
665 else driverW.Buffer = NULL;
667 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
668 else deviceW.Buffer = NULL;
670 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
671 else outputW.Buffer = NULL;
673 if (initData) initDataW = GdiConvertToDevmodeW(initData);
674 else initDataW = NULL;
676 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
678 RtlFreeUnicodeString(&driverW);
679 RtlFreeUnicodeString(&deviceW);
680 RtlFreeUnicodeString(&outputW);
681 HeapFree(GetProcessHeap(), 0, initDataW);
686 /***********************************************************************
687 * CreateICA (GDI32.@)
689 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
690 const DEVMODEA* initData )
692 /* Nothing special yet for ICs */
693 return CreateDCA( driver, device, output, initData );
697 /***********************************************************************
698 * CreateICW (GDI32.@)
700 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
701 const DEVMODEW* initData )
703 /* Nothing special yet for ICs */
704 return CreateDCW( driver, device, output, initData );
708 /***********************************************************************
709 * CreateCompatibleDC (GDI32.@)
711 HDC WINAPI CreateCompatibleDC( HDC hdc )
714 const DC_FUNCTIONS *funcs;
719 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
721 funcs = origDC->funcs;
722 physDev = origDC->physDev;
723 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
724 funcs = DRIVER_get_driver( funcs );
728 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
729 funcs = DRIVER_load_driver( displayW );
733 if (!funcs) return 0;
735 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
737 DRIVER_release_driver( funcs );
741 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
743 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
745 /* Copy the driver-specific physical device info into
746 * the new DC. The driver may use this read-only info
747 * while creating the compatible DC below. */
748 dc->physDev = physDev;
750 if (dc->funcs->pCreateDC &&
751 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
753 WARN("creation aborted by device\n");
754 GDI_FreeObject( dc->hSelf, dc );
755 DRIVER_release_driver( funcs );
759 dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
762 GDI_ReleaseObj( dc->hSelf );
767 /***********************************************************************
770 BOOL WINAPI DeleteDC( HDC hdc )
772 const DC_FUNCTIONS *funcs = NULL;
779 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
781 /* Call hook procedure to check whether is it OK to delete this DC */
784 DCHOOKPROC proc = dc->hookThunk;
785 DWORD data = dc->dwHookData;
786 GDI_ReleaseObj( hdc );
787 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
788 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
791 while (dc->saveLevel)
794 HDC hdcs = dc->saved_dc;
795 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
796 dc->saved_dc = dcs->saved_dc;
798 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
799 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
800 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
801 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
802 PATH_DestroyGdiPath(&dcs->path);
803 GDI_FreeObject( hdcs, dcs );
806 if (!(dc->flags & DC_SAVED))
808 SelectObject( hdc, GetStockObject(BLACK_PEN) );
809 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
810 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
811 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
813 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
817 while (dc->saved_visrgn)
819 struct saved_visrgn *next = dc->saved_visrgn->next;
820 DeleteObject( dc->saved_visrgn->hrgn );
821 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
822 dc->saved_visrgn = next;
824 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
825 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
826 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
827 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
828 PATH_DestroyGdiPath(&dc->path);
830 GDI_FreeObject( hdc, dc );
831 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
836 /***********************************************************************
839 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
844 if ((dc = DC_GetDCPtr( hdc )))
846 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
847 GDI_ReleaseObj( hdc );
853 /***********************************************************************
856 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
861 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
862 else devmodeW = NULL;
864 ret = ResetDCW(hdc, devmodeW);
866 HeapFree(GetProcessHeap(), 0, devmodeW);
871 /***********************************************************************
872 * GetDeviceCaps (GDI32.@)
874 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
879 if ((dc = DC_GetDCPtr( hdc )))
881 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
882 GDI_ReleaseObj( hdc );
888 /***********************************************************************
889 * GetBkColor (GDI32.@)
891 COLORREF WINAPI GetBkColor( HDC hdc )
894 DC * dc = DC_GetDCPtr( hdc );
897 ret = dc->backgroundColor;
898 GDI_ReleaseObj( hdc );
904 /***********************************************************************
905 * SetBkColor (GDI32.@)
907 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
910 DC * dc = DC_GetDCPtr( hdc );
912 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
914 if (!dc) return CLR_INVALID;
915 oldColor = dc->backgroundColor;
916 if (dc->funcs->pSetBkColor)
918 color = dc->funcs->pSetBkColor(dc->physDev, color);
919 if (color == CLR_INVALID) /* don't change it */
922 oldColor = CLR_INVALID;
925 dc->backgroundColor = color;
926 GDI_ReleaseObj( hdc );
931 /***********************************************************************
932 * GetTextColor (GDI32.@)
934 COLORREF WINAPI GetTextColor( HDC hdc )
937 DC * dc = DC_GetDCPtr( hdc );
941 GDI_ReleaseObj( hdc );
947 /***********************************************************************
948 * SetTextColor (GDI32.@)
950 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
953 DC * dc = DC_GetDCPtr( hdc );
955 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
957 if (!dc) return CLR_INVALID;
958 oldColor = dc->textColor;
959 if (dc->funcs->pSetTextColor)
961 color = dc->funcs->pSetTextColor(dc->physDev, color);
962 if (color == CLR_INVALID) /* don't change it */
965 oldColor = CLR_INVALID;
968 dc->textColor = color;
969 GDI_ReleaseObj( hdc );
974 /***********************************************************************
975 * GetTextAlign (GDI32.@)
977 UINT WINAPI GetTextAlign( HDC hdc )
980 DC * dc = DC_GetDCPtr( hdc );
984 GDI_ReleaseObj( hdc );
990 /***********************************************************************
991 * SetTextAlign (GDI32.@)
993 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
996 DC *dc = DC_GetDCPtr( hdc );
998 TRACE("hdc=%p align=%d\n", hdc, align);
1000 if (!dc) return 0x0;
1001 if (dc->funcs->pSetTextAlign)
1002 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
1004 prevAlign = dc->textAlign;
1005 dc->textAlign = align;
1007 GDI_ReleaseObj( hdc );
1011 /***********************************************************************
1012 * GetDCOrgEx (GDI32.@)
1014 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1018 if (!lpp) return FALSE;
1019 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
1021 lpp->x = lpp->y = 0;
1022 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1023 GDI_ReleaseObj( hDC );
1028 /***********************************************************************
1029 * SetDCOrg (GDI.117)
1031 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1034 HDC hdc = HDC_32( hdc16 );
1035 DC *dc = DC_GetDCPtr( hdc );
1037 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1038 GDI_ReleaseObj( hdc );
1043 /***********************************************************************
1044 * GetGraphicsMode (GDI32.@)
1046 INT WINAPI GetGraphicsMode( HDC hdc )
1049 DC * dc = DC_GetDCPtr( hdc );
1052 ret = dc->GraphicsMode;
1053 GDI_ReleaseObj( hdc );
1059 /***********************************************************************
1060 * SetGraphicsMode (GDI32.@)
1062 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1065 DC *dc = DC_GetDCPtr( hdc );
1067 /* One would think that setting the graphics mode to GM_COMPATIBLE
1068 * would also reset the world transformation matrix to the unity
1069 * matrix. However, in Windows, this is not the case. This doesn't
1070 * make a lot of sense to me, but that's the way it is.
1073 if ((mode > 0) && (mode <= GM_LAST))
1075 ret = dc->GraphicsMode;
1076 dc->GraphicsMode = mode;
1078 GDI_ReleaseObj( hdc );
1083 /***********************************************************************
1084 * GetArcDirection (GDI32.@)
1086 INT WINAPI GetArcDirection( HDC hdc )
1089 DC * dc = DC_GetDCPtr( hdc );
1092 ret = dc->ArcDirection;
1093 GDI_ReleaseObj( hdc );
1099 /***********************************************************************
1100 * SetArcDirection (GDI32.@)
1102 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1105 INT nOldDirection = 0;
1107 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1109 SetLastError(ERROR_INVALID_PARAMETER);
1113 if ((dc = DC_GetDCPtr( hdc )))
1115 if (dc->funcs->pSetArcDirection)
1117 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1119 nOldDirection = dc->ArcDirection;
1120 dc->ArcDirection = nDirection;
1121 GDI_ReleaseObj( hdc );
1123 return nOldDirection;
1127 /***********************************************************************
1128 * GetWorldTransform (GDI32.@)
1130 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1133 if (!xform) return FALSE;
1134 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1135 *xform = dc->xformWorld2Wnd;
1136 GDI_ReleaseObj( hdc );
1141 /***********************************************************************
1142 * GetTransform (GDI32.@)
1144 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1146 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1147 FIXME("stub: don't know what to do for code %lx\n", unknown );
1152 /***********************************************************************
1153 * SetWorldTransform (GDI32.@)
1155 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1158 DC *dc = DC_GetDCPtr( hdc );
1160 if (!dc) return FALSE;
1161 if (!xform) goto done;
1163 /* Check that graphics mode is GM_ADVANCED */
1164 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1166 if (dc->funcs->pSetWorldTransform)
1168 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1169 if (!ret) goto done;
1172 dc->xformWorld2Wnd = *xform;
1173 DC_UpdateXforms( dc );
1176 GDI_ReleaseObj( hdc );
1181 /****************************************************************************
1182 * ModifyWorldTransform [GDI32.@]
1183 * Modifies the world transformation for a device context.
1186 * hdc [I] Handle to device context
1187 * xform [I] XFORM structure that will be used to modify the world
1189 * iMode [I] Specifies in what way to modify the world transformation
1192 * Resets the world transformation to the identity matrix.
1193 * The parameter xform is ignored.
1195 * Multiplies xform into the world transformation matrix from
1198 * Multiplies xform into the world transformation matrix from
1203 * Failure: FALSE. Use GetLastError() to determine the cause.
1205 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1209 DC *dc = DC_GetDCPtr( hdc );
1211 /* Check for illegal parameters */
1212 if (!dc) return FALSE;
1213 if (!xform) goto done;
1215 /* Check that graphics mode is GM_ADVANCED */
1216 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1218 if (dc->funcs->pModifyWorldTransform)
1220 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1221 if (!ret) goto done;
1227 dc->xformWorld2Wnd.eM11 = 1.0f;
1228 dc->xformWorld2Wnd.eM12 = 0.0f;
1229 dc->xformWorld2Wnd.eM21 = 0.0f;
1230 dc->xformWorld2Wnd.eM22 = 1.0f;
1231 dc->xformWorld2Wnd.eDx = 0.0f;
1232 dc->xformWorld2Wnd.eDy = 0.0f;
1234 case MWT_LEFTMULTIPLY:
1235 CombineTransform( &dc->xformWorld2Wnd, xform,
1236 &dc->xformWorld2Wnd );
1238 case MWT_RIGHTMULTIPLY:
1239 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1246 DC_UpdateXforms( dc );
1249 GDI_ReleaseObj( hdc );
1254 /****************************************************************************
1255 * CombineTransform [GDI32.@]
1256 * Combines two transformation matrices.
1259 * xformResult [O] Stores the result of combining the two matrices
1260 * xform1 [I] Specifies the first matrix to apply
1261 * xform2 [I] Specifies the second matrix to apply
1264 * The same matrix can be passed in for more than one of the parameters.
1268 * Failure: FALSE. Use GetLastError() to determine the cause.
1270 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1271 const XFORM *xform2 )
1275 /* Check for illegal parameters */
1276 if (!xformResult || !xform1 || !xform2)
1279 /* Create the result in a temporary XFORM, since xformResult may be
1280 * equal to xform1 or xform2 */
1281 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1282 xform1->eM12 * xform2->eM21;
1283 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1284 xform1->eM12 * xform2->eM22;
1285 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1286 xform1->eM22 * xform2->eM21;
1287 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1288 xform1->eM22 * xform2->eM22;
1289 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1290 xform1->eDy * xform2->eM21 +
1292 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1293 xform1->eDy * xform2->eM22 +
1296 /* Copy the result to xformResult */
1297 *xformResult = xformTemp;
1303 /***********************************************************************
1304 * SetDCHook (GDI32.@)
1306 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1308 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1310 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1312 if (!dc) return FALSE;
1314 if (!(dc->flags & DC_SAVED))
1316 dc->dwHookData = dwHookData;
1317 dc->hookThunk = hookProc;
1319 GDI_ReleaseObj( hdc );
1324 /* relay function to call the 16-bit DC hook proc */
1325 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1329 FARPROC16 proc = NULL;
1330 HDC hdc = HDC_32( hdc16 );
1331 DC *dc = DC_GetDCPtr( hdc );
1333 if (!dc) return FALSE;
1334 proc = dc->hookProc;
1335 GDI_ReleaseObj( hdc );
1336 if (!proc) return FALSE;
1339 args[3] = HIWORD(data);
1340 args[2] = LOWORD(data);
1341 args[1] = HIWORD(lParam);
1342 args[0] = LOWORD(lParam);
1343 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1347 /***********************************************************************
1348 * SetDCHook (GDI.190)
1350 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1352 HDC hdc = HDC_32( hdc16 );
1353 DC *dc = DC_GetDCPtr( hdc );
1354 if (!dc) return FALSE;
1356 dc->hookProc = hookProc;
1357 GDI_ReleaseObj( hdc );
1358 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1362 /***********************************************************************
1363 * GetDCHook (GDI.191)
1365 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1367 HDC hdc = HDC_32( hdc16 );
1368 DC *dc = DC_GetDCPtr( hdc );
1372 *phookProc = dc->hookProc;
1373 ret = dc->dwHookData;
1374 GDI_ReleaseObj( hdc );
1379 /***********************************************************************
1380 * SetHookFlags (GDI.192)
1382 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1384 HDC hdc = HDC_32( hdc16 );
1385 DC *dc = DC_GetDCPtr( hdc );
1389 WORD wRet = dc->flags & DC_DIRTY;
1391 /* "Undocumented Windows" info is slightly confusing.
1394 TRACE("hDC %p, flags %04x\n",hdc,flags);
1396 if( flags & DCHF_INVALIDATEVISRGN )
1397 dc->flags |= DC_DIRTY;
1398 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1399 dc->flags &= ~DC_DIRTY;
1400 GDI_ReleaseObj( hdc );
1406 /***********************************************************************
1407 * SetICMMode (GDI32.@)
1409 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1411 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1412 if (iEnableICM == ICM_OFF) return ICM_OFF;
1413 if (iEnableICM == ICM_ON) return 0;
1414 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1418 /***********************************************************************
1419 * GetDeviceGammaRamp (GDI32.@)
1421 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1424 DC *dc = DC_GetDCPtr( hDC );
1428 if (dc->funcs->pGetDeviceGammaRamp)
1429 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1430 GDI_ReleaseObj( hDC );
1435 /***********************************************************************
1436 * SetDeviceGammaRamp (GDI32.@)
1438 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1441 DC *dc = DC_GetDCPtr( hDC );
1445 if (dc->funcs->pSetDeviceGammaRamp)
1446 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1447 GDI_ReleaseObj( hDC );
1452 /***********************************************************************
1453 * GetColorSpace (GDI32.@)
1455 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1457 /*FIXME Need to to whatever GetColorSpace actually does */
1461 /***********************************************************************
1462 * CreateColorSpaceA (GDI32.@)
1464 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1470 /***********************************************************************
1471 * CreateColorSpaceW (GDI32.@)
1473 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1479 /***********************************************************************
1480 * DeleteColorSpace (GDI32.@)
1482 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1489 /***********************************************************************
1490 * SetColorSpace (GDI32.@)
1492 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1499 /***********************************************************************
1500 * GetBoundsRect (GDI32.@)
1502 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1505 DC *dc = DC_GetDCPtr( hdc );
1507 if ( !dc ) return 0;
1509 if (rect) *rect = dc->BoundsRect;
1511 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1513 if (flags & DCB_RESET)
1515 dc->BoundsRect.left = 0;
1516 dc->BoundsRect.top = 0;
1517 dc->BoundsRect.right = 0;
1518 dc->BoundsRect.bottom = 0;
1519 dc->flags &= ~DC_BOUNDS_SET;
1521 GDI_ReleaseObj( hdc );
1526 /***********************************************************************
1527 * SetBoundsRect (GDI32.@)
1529 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1534 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1535 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1537 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1538 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1540 if (flags & DCB_RESET)
1542 dc->BoundsRect.left = 0;
1543 dc->BoundsRect.top = 0;
1544 dc->BoundsRect.right = 0;
1545 dc->BoundsRect.bottom = 0;
1546 dc->flags &= ~DC_BOUNDS_SET;
1549 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1551 if (dc->flags & DC_BOUNDS_SET)
1553 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1554 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1555 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1556 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1560 dc->BoundsRect = *rect;
1561 dc->flags |= DC_BOUNDS_SET;
1565 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1566 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1568 GDI_ReleaseObj( hdc );
1573 /***********************************************************************
1574 * GetRelAbs (GDI32.@)
1576 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1579 DC *dc = DC_GetDCPtr( hdc );
1580 if (dc) ret = dc->relAbsMode;
1581 GDI_ReleaseObj( hdc );
1588 /***********************************************************************
1589 * GetBkMode (GDI32.@)
1591 INT WINAPI GetBkMode( HDC hdc )
1594 DC * dc = DC_GetDCPtr( hdc );
1597 ret = dc->backgroundMode;
1598 GDI_ReleaseObj( hdc );
1604 /***********************************************************************
1605 * SetBkMode (GDI32.@)
1607 INT WINAPI SetBkMode( HDC hdc, INT mode )
1611 if ((mode <= 0) || (mode > BKMODE_LAST))
1613 SetLastError(ERROR_INVALID_PARAMETER);
1616 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1617 if (dc->funcs->pSetBkMode)
1618 ret = dc->funcs->pSetBkMode( dc->physDev, mode );
1621 ret = dc->backgroundMode;
1622 dc->backgroundMode = mode;
1624 GDI_ReleaseObj( hdc );
1629 /***********************************************************************
1632 INT WINAPI GetROP2( HDC hdc )
1635 DC * dc = DC_GetDCPtr( hdc );
1639 GDI_ReleaseObj( hdc );
1645 /***********************************************************************
1648 INT WINAPI SetROP2( HDC hdc, INT mode )
1652 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1654 SetLastError(ERROR_INVALID_PARAMETER);
1657 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1658 if (dc->funcs->pSetROP2)
1659 ret = dc->funcs->pSetROP2( dc->physDev, mode );
1665 GDI_ReleaseObj( hdc );
1670 /***********************************************************************
1671 * SetRelAbs (GDI32.@)
1673 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1677 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1679 SetLastError(ERROR_INVALID_PARAMETER);
1682 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1683 if (dc->funcs->pSetRelAbs)
1684 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1687 ret = dc->relAbsMode;
1688 dc->relAbsMode = mode;
1690 GDI_ReleaseObj( hdc );
1695 /***********************************************************************
1696 * GetPolyFillMode (GDI32.@)
1698 INT WINAPI GetPolyFillMode( HDC hdc )
1701 DC * dc = DC_GetDCPtr( hdc );
1704 ret = dc->polyFillMode;
1705 GDI_ReleaseObj( hdc );
1711 /***********************************************************************
1712 * SetPolyFillMode (GDI32.@)
1714 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1718 if ((mode <= 0) || (mode > POLYFILL_LAST))
1720 SetLastError(ERROR_INVALID_PARAMETER);
1723 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1724 if (dc->funcs->pSetPolyFillMode)
1725 ret = dc->funcs->pSetPolyFillMode( dc->physDev, mode );
1728 ret = dc->polyFillMode;
1729 dc->polyFillMode = mode;
1731 GDI_ReleaseObj( hdc );
1736 /***********************************************************************
1737 * GetStretchBltMode (GDI32.@)
1739 INT WINAPI GetStretchBltMode( HDC hdc )
1742 DC * dc = DC_GetDCPtr( hdc );
1745 ret = dc->stretchBltMode;
1746 GDI_ReleaseObj( hdc );
1752 /***********************************************************************
1753 * SetStretchBltMode (GDI32.@)
1755 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1759 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1761 SetLastError(ERROR_INVALID_PARAMETER);
1764 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1765 if (dc->funcs->pSetStretchBltMode)
1766 ret = dc->funcs->pSetStretchBltMode( dc->physDev, mode );
1769 ret = dc->stretchBltMode;
1770 dc->stretchBltMode = mode;
1772 GDI_ReleaseObj( hdc );
1777 /***********************************************************************
1778 * GetMapMode (GDI32.@)
1780 INT WINAPI GetMapMode( HDC hdc )
1783 DC * dc = DC_GetDCPtr( hdc );
1787 GDI_ReleaseObj( hdc );
1793 /***********************************************************************
1794 * GetBrushOrgEx (GDI32.@)
1796 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1798 DC * dc = DC_GetDCPtr( hdc );
1799 if (!dc) return FALSE;
1800 pt->x = dc->brushOrgX;
1801 pt->y = dc->brushOrgY;
1802 GDI_ReleaseObj( hdc );
1807 /***********************************************************************
1808 * GetCurrentPositionEx (GDI32.@)
1810 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1812 DC * dc = DC_GetDCPtr( hdc );
1813 if (!dc) return FALSE;
1814 pt->x = dc->CursPosX;
1815 pt->y = dc->CursPosY;
1816 GDI_ReleaseObj( hdc );
1821 /***********************************************************************
1822 * GetViewportExtEx (GDI32.@)
1824 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1826 DC * dc = DC_GetDCPtr( hdc );
1827 if (!dc) return FALSE;
1828 size->cx = dc->vportExtX;
1829 size->cy = dc->vportExtY;
1830 GDI_ReleaseObj( hdc );
1835 /***********************************************************************
1836 * GetViewportOrgEx (GDI32.@)
1838 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1840 DC * dc = DC_GetDCPtr( hdc );
1841 if (!dc) return FALSE;
1842 pt->x = dc->vportOrgX;
1843 pt->y = dc->vportOrgY;
1844 GDI_ReleaseObj( hdc );
1849 /***********************************************************************
1850 * GetWindowExtEx (GDI32.@)
1852 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1854 DC * dc = DC_GetDCPtr( hdc );
1855 if (!dc) return FALSE;
1856 size->cx = dc->wndExtX;
1857 size->cy = dc->wndExtY;
1858 GDI_ReleaseObj( hdc );
1863 /***********************************************************************
1864 * GetWindowOrgEx (GDI32.@)
1866 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1868 DC * dc = DC_GetDCPtr( hdc );
1869 if (!dc) return FALSE;
1870 pt->x = dc->wndOrgX;
1871 pt->y = dc->wndOrgY;
1872 GDI_ReleaseObj( hdc );
1877 /***********************************************************************
1878 * InquireVisRgn (GDI.131)
1880 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1883 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1886 ret = HRGN_16(dc->hVisRgn);
1887 GDI_ReleaseObj( HDC_32(hdc) );
1893 /***********************************************************************
1894 * GetClipRgn (GDI.173)
1896 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
1899 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1902 ret = HRGN_16(dc->hClipRgn);
1903 GDI_ReleaseObj( HDC_32(hdc) );
1909 /***********************************************************************
1910 * GetLayout (GDI32.@)
1912 * Gets left->right or right->left text layout flags of a dc.
1915 DWORD WINAPI GetLayout(HDC hdc)
1917 DWORD layout = GDI_ERROR;
1919 DC * dc = DC_GetDCPtr( hdc );
1922 layout = dc->layout;
1923 GDI_ReleaseObj( hdc );
1926 TRACE("hdc : %p, layout : %08lx\n", hdc, layout);
1931 /***********************************************************************
1932 * SetLayout (GDI32.@)
1934 * Sets left->right or right->left text layout flags of a dc.
1937 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1939 DWORD oldlayout = GDI_ERROR;
1941 DC * dc = DC_GetDCPtr( hdc );
1944 oldlayout = dc->layout;
1945 dc->layout = layout;
1946 GDI_ReleaseObj( hdc );
1949 TRACE("hdc : %p, old layout : %08lx, new layout : %08lx\n", hdc, oldlayout, layout);
1954 /***********************************************************************
1955 * GetDCBrushColor (GDI32.@)
1957 * Retrieves the current brush color for the specified device
1961 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1964 COLORREF dcBrushColor = CLR_INVALID;
1966 TRACE("hdc(%p)\n", hdc);
1968 dc = DC_GetDCPtr( hdc );
1971 dcBrushColor = dc->dcBrushColor;
1972 GDI_ReleaseObj( hdc );
1975 return dcBrushColor;
1978 /***********************************************************************
1979 * SetDCBrushColor (GDI32.@)
1981 * Sets the current device context (DC) brush color to the specified
1982 * color value. If the device cannot represent the specified color
1983 * value, the color is set to the nearest physical color.
1986 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1989 COLORREF oldClr = CLR_INVALID;
1991 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1993 dc = DC_GetDCPtr( hdc );
1996 if (dc->funcs->pSetDCBrushColor)
1997 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
1998 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2000 /* If DC_BRUSH is selected, update driver pen color */
2001 HBRUSH hBrush = CreateSolidBrush( crColor );
2002 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2003 DeleteObject( hBrush );
2006 if (crColor != CLR_INVALID)
2008 oldClr = dc->dcBrushColor;
2009 dc->dcBrushColor = crColor;
2012 GDI_ReleaseObj( hdc );
2018 /***********************************************************************
2019 * GetDCPenColor (GDI32.@)
2021 * Retrieves the current pen color for the specified device
2025 COLORREF WINAPI GetDCPenColor(HDC hdc)
2028 COLORREF dcPenColor = CLR_INVALID;
2030 TRACE("hdc(%p)\n", hdc);
2032 dc = DC_GetDCPtr( hdc );
2035 dcPenColor = dc->dcPenColor;
2036 GDI_ReleaseObj( hdc );
2042 /***********************************************************************
2043 * SetDCPenColor (GDI32.@)
2045 * Sets the current device context (DC) pen color to the specified
2046 * color value. If the device cannot represent the specified color
2047 * value, the color is set to the nearest physical color.
2050 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2053 COLORREF oldClr = CLR_INVALID;
2055 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
2057 dc = DC_GetDCPtr( hdc );
2060 if (dc->funcs->pSetDCPenColor)
2061 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2062 else if (dc->hPen == GetStockObject( DC_PEN ))
2064 /* If DC_PEN is selected, update the driver pen color */
2065 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2066 HPEN hPen = CreatePenIndirect( &logpen );
2067 dc->funcs->pSelectPen( dc->physDev, hPen );
2068 DeleteObject( hPen );
2071 if (crColor != CLR_INVALID)
2073 oldClr = dc->dcPenColor;
2074 dc->dcPenColor = crColor;
2077 GDI_ReleaseObj( hdc );
2083 /***********************************************************************
2084 * SetVirtualResolution (GDI32.@)
2086 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2088 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2090 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
2094 /*******************************************************************
2095 * GetMiterLimit [GDI32.@]
2099 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2104 TRACE("(%p,%p)\n", hdc, peLimit);
2106 dc = DC_GetDCPtr( hdc );
2110 *peLimit = dc->miterLimit;
2112 GDI_ReleaseObj( hdc );
2118 /*******************************************************************
2119 * SetMiterLimit [GDI32.@]
2123 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2128 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2130 dc = DC_GetDCPtr( hdc );
2134 *peOldLimit = dc->miterLimit;
2135 dc->miterLimit = eNewLimit;
2136 GDI_ReleaseObj( hdc );