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
;
78 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
83 dc
->hPen
= GetStockObject( BLACK_PEN
);
84 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
85 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
88 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
90 dc
->ROPmode
= R2_COPYPEN
;
91 dc
->polyFillMode
= ALTERNATE
;
92 dc
->stretchBltMode
= BLACKONWHITE
;
93 dc
->relAbsMode
= ABSOLUTE
;
94 dc
->backgroundMode
= OPAQUE
;
95 dc
->backgroundColor
= RGB( 255, 255, 255 );
96 dc
->dcBrushColor
= RGB( 255, 255, 255 );
97 dc
->dcPenColor
= RGB( 0, 0, 0 );
98 dc
->textColor
= RGB( 0, 0, 0 );
101 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
105 dc
->MapMode
= MM_TEXT
;
106 dc
->GraphicsMode
= GM_COMPATIBLE
;
107 dc
->pAbortProc
= NULL
;
110 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
111 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
112 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
113 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
114 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
115 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
116 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
117 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
118 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
119 dc
->vport2WorldValid
= TRUE
;
120 dc
->BoundsRect
.left
= 0;
121 dc
->BoundsRect
.top
= 0;
122 dc
->BoundsRect
.right
= 0;
123 dc
->BoundsRect
.bottom
= 0;
124 PATH_InitGdiPath(&dc
->path
);
130 /***********************************************************************
133 DC
*DC_GetDCPtr( HDC hdc
)
135 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
136 if (!ptr
) return NULL
;
137 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
138 (GDIMAGIC(ptr
->wMagic
) == MEMORY_DC_MAGIC
) ||
139 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
140 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
142 GDI_ReleaseObj( hdc
);
143 SetLastError( ERROR_INVALID_HANDLE
);
147 /***********************************************************************
150 * Retrieve a DC ptr while making sure the visRgn is updated.
151 * This function may call up to USER so the GDI lock should _not_
152 * be held when calling it.
154 DC
*DC_GetDCUpdate( HDC hdc
)
156 DC
*dc
= DC_GetDCPtr( hdc
);
157 if (!dc
) return NULL
;
158 while (dc
->flags
& DC_DIRTY
)
160 DCHOOKPROC proc
= dc
->hookThunk
;
161 dc
->flags
&= ~DC_DIRTY
;
164 DWORD data
= dc
->dwHookData
;
165 GDI_ReleaseObj( hdc
);
166 proc( HDC_16(hdc
), DCHC_INVALIDVISRGN
, data
, 0 );
167 if (!(dc
= DC_GetDCPtr( hdc
))) break;
168 /* otherwise restart the loop in case it became dirty again in the meantime */
175 /***********************************************************************
178 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
180 GDI_ReleaseObj( handle
);
181 return DeleteDC( handle
);
185 /***********************************************************************
188 * Setup device-specific DC values for a newly created DC.
190 void DC_InitDC( DC
* dc
)
192 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
193 SetTextColor( dc
->hSelf
, dc
->textColor
);
194 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
195 SelectObject( dc
->hSelf
, dc
->hPen
);
196 SelectObject( dc
->hSelf
, dc
->hBrush
);
197 SelectObject( dc
->hSelf
, dc
->hFont
);
198 CLIPPING_UpdateGCRegion( dc
);
202 /***********************************************************************
205 * Computes the inverse of the transformation xformSrc and stores it to
206 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
209 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
213 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
214 xformSrc
->eM12
*xformSrc
->eM21
;
215 if (determinant
> -1e-12 && determinant
< 1e-12)
218 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
219 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
220 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
221 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
222 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
223 xformSrc
->eDy
* xformDest
->eM21
;
224 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
225 xformSrc
->eDy
* xformDest
->eM22
;
231 /***********************************************************************
234 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
235 * fields of the specified DC by creating a transformation that
236 * represents the current mapping mode and combining it with the DC's
237 * world transform. This function should be called whenever the
238 * parameters associated with the mapping mode (window and viewport
239 * extents and origins) or the world transform change.
241 void DC_UpdateXforms( DC
*dc
)
243 XFORM xformWnd2Vport
, oldworld2vport
;
244 FLOAT scaleX
, scaleY
;
246 /* Construct a transformation to do the window-to-viewport conversion */
247 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
248 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
249 xformWnd2Vport
.eM11
= scaleX
;
250 xformWnd2Vport
.eM12
= 0.0;
251 xformWnd2Vport
.eM21
= 0.0;
252 xformWnd2Vport
.eM22
= scaleY
;
253 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
254 scaleX
* (FLOAT
)dc
->wndOrgX
;
255 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
256 scaleY
* (FLOAT
)dc
->wndOrgY
;
258 oldworld2vport
= dc
->xformWorld2Vport
;
259 /* Combine with the world transformation */
260 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
263 /* Create inverse of world-to-viewport transformation */
264 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
265 &dc
->xformVport2World
);
267 /* Reselect the font and pen back into the dc so that the size
269 if(memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)))
271 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
272 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
277 /***********************************************************************
278 * GetDCState (Not a Windows API)
280 HDC WINAPI
GetDCState( HDC hdc
)
285 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
286 if (!(newdc
= GDI_AllocObject( sizeof(DC
), GDIMAGIC(dc
->header
.wMagic
), &handle
, &dc_funcs
)))
288 GDI_ReleaseObj( hdc
);
291 TRACE("(%p): returning %p\n", hdc
, handle
);
293 newdc
->flags
= dc
->flags
| DC_SAVED
;
294 newdc
->layout
= dc
->layout
;
295 newdc
->hPen
= dc
->hPen
;
296 newdc
->hBrush
= dc
->hBrush
;
297 newdc
->hFont
= dc
->hFont
;
298 newdc
->hBitmap
= dc
->hBitmap
;
299 newdc
->hDevice
= dc
->hDevice
;
300 newdc
->hPalette
= dc
->hPalette
;
301 newdc
->ROPmode
= dc
->ROPmode
;
302 newdc
->polyFillMode
= dc
->polyFillMode
;
303 newdc
->stretchBltMode
= dc
->stretchBltMode
;
304 newdc
->relAbsMode
= dc
->relAbsMode
;
305 newdc
->backgroundMode
= dc
->backgroundMode
;
306 newdc
->backgroundColor
= dc
->backgroundColor
;
307 newdc
->textColor
= dc
->textColor
;
308 newdc
->dcBrushColor
= dc
->dcBrushColor
;
309 newdc
->dcPenColor
= dc
->dcPenColor
;
310 newdc
->brushOrgX
= dc
->brushOrgX
;
311 newdc
->brushOrgY
= dc
->brushOrgY
;
312 newdc
->textAlign
= dc
->textAlign
;
313 newdc
->charExtra
= dc
->charExtra
;
314 newdc
->breakExtra
= dc
->breakExtra
;
315 newdc
->breakRem
= dc
->breakRem
;
316 newdc
->MapMode
= dc
->MapMode
;
317 newdc
->GraphicsMode
= dc
->GraphicsMode
;
318 newdc
->CursPosX
= dc
->CursPosX
;
319 newdc
->CursPosY
= dc
->CursPosY
;
320 newdc
->ArcDirection
= dc
->ArcDirection
;
321 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
322 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
323 newdc
->xformVport2World
= dc
->xformVport2World
;
324 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
325 newdc
->wndOrgX
= dc
->wndOrgX
;
326 newdc
->wndOrgY
= dc
->wndOrgY
;
327 newdc
->wndExtX
= dc
->wndExtX
;
328 newdc
->wndExtY
= dc
->wndExtY
;
329 newdc
->vportOrgX
= dc
->vportOrgX
;
330 newdc
->vportOrgY
= dc
->vportOrgY
;
331 newdc
->vportExtX
= dc
->vportExtX
;
332 newdc
->vportExtY
= dc
->vportExtY
;
333 newdc
->BoundsRect
= dc
->BoundsRect
;
335 newdc
->hSelf
= (HDC
)handle
;
336 newdc
->saveLevel
= 0;
338 PATH_InitGdiPath( &newdc
->path
);
340 newdc
->pAbortProc
= NULL
;
341 newdc
->hookThunk
= NULL
;
344 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
349 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
350 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
356 newdc
->gdiFont
= dc
->gdiFont
;
360 GDI_ReleaseObj( handle
);
361 GDI_ReleaseObj( hdc
);
366 /***********************************************************************
367 * SetDCState (Not a Windows API)
369 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
373 if (!(dc
= DC_GetDCUpdate( hdc
))) return;
374 if (!(dcs
= DC_GetDCPtr( hdcs
)))
376 GDI_ReleaseObj( hdc
);
379 if (!dcs
->flags
& DC_SAVED
)
381 GDI_ReleaseObj( hdc
);
382 GDI_ReleaseObj( hdcs
);
385 TRACE("%p %p\n", hdc
, hdcs
);
387 dc
->flags
= dcs
->flags
& ~(DC_SAVED
| DC_DIRTY
);
388 dc
->layout
= dcs
->layout
;
389 dc
->hDevice
= dcs
->hDevice
;
390 dc
->ROPmode
= dcs
->ROPmode
;
391 dc
->polyFillMode
= dcs
->polyFillMode
;
392 dc
->stretchBltMode
= dcs
->stretchBltMode
;
393 dc
->relAbsMode
= dcs
->relAbsMode
;
394 dc
->backgroundMode
= dcs
->backgroundMode
;
395 dc
->backgroundColor
= dcs
->backgroundColor
;
396 dc
->textColor
= dcs
->textColor
;
397 dc
->dcBrushColor
= dcs
->dcBrushColor
;
398 dc
->dcPenColor
= dcs
->dcPenColor
;
399 dc
->brushOrgX
= dcs
->brushOrgX
;
400 dc
->brushOrgY
= dcs
->brushOrgY
;
401 dc
->textAlign
= dcs
->textAlign
;
402 dc
->charExtra
= dcs
->charExtra
;
403 dc
->breakExtra
= dcs
->breakExtra
;
404 dc
->breakRem
= dcs
->breakRem
;
405 dc
->MapMode
= dcs
->MapMode
;
406 dc
->GraphicsMode
= dcs
->GraphicsMode
;
407 dc
->CursPosX
= dcs
->CursPosX
;
408 dc
->CursPosY
= dcs
->CursPosY
;
409 dc
->ArcDirection
= dcs
->ArcDirection
;
410 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
411 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
412 dc
->xformVport2World
= dcs
->xformVport2World
;
413 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
414 dc
->BoundsRect
= dcs
->BoundsRect
;
416 dc
->wndOrgX
= dcs
->wndOrgX
;
417 dc
->wndOrgY
= dcs
->wndOrgY
;
418 dc
->wndExtX
= dcs
->wndExtX
;
419 dc
->wndExtY
= dcs
->wndExtY
;
420 dc
->vportOrgX
= dcs
->vportOrgX
;
421 dc
->vportOrgY
= dcs
->vportOrgY
;
422 dc
->vportExtX
= dcs
->vportExtX
;
423 dc
->vportExtY
= dcs
->vportExtY
;
427 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
432 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
435 CLIPPING_UpdateGCRegion( dc
);
437 SelectObject( hdc
, dcs
->hBitmap
);
438 SelectObject( hdc
, dcs
->hBrush
);
439 SelectObject( hdc
, dcs
->hFont
);
440 SelectObject( hdc
, dcs
->hPen
);
441 SetBkColor( hdc
, dcs
->backgroundColor
);
442 SetTextColor( hdc
, dcs
->textColor
);
443 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
444 GDI_ReleaseObj( hdcs
);
445 GDI_ReleaseObj( hdc
);
449 /***********************************************************************
450 * GetDCState (GDI.179)
452 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
454 return HDC_16( GetDCState( HDC_32(hdc
) ));
458 /***********************************************************************
459 * SetDCState (GDI.180)
461 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
463 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
467 /***********************************************************************
470 INT WINAPI
SaveDC( HDC hdc
)
476 dc
= DC_GetDCPtr( hdc
);
479 if(dc
->funcs
->pSaveDC
)
481 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
482 GDI_ReleaseObj( hdc
);
486 if (!(hdcs
= GetDCState( hdc
)))
488 GDI_ReleaseObj( hdc
);
491 dcs
= DC_GetDCPtr( hdcs
);
493 /* Copy path. The reason why path saving / restoring is in SaveDC/
494 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
495 * functions are only in Win16 (which doesn't have paths) and that
496 * SetDCState doesn't allow us to signal an error (which can happen
497 * when copying paths).
499 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
501 GDI_ReleaseObj( hdc
);
502 GDI_ReleaseObj( hdcs
);
507 dcs
->header
.hNext
= dc
->header
.hNext
;
508 dc
->header
.hNext
= HDC_16(hdcs
);
509 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
510 ret
= ++dc
->saveLevel
;
511 GDI_ReleaseObj( hdcs
);
512 GDI_ReleaseObj( hdc
);
517 /***********************************************************************
518 * RestoreDC (GDI32.@)
520 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
525 TRACE("%p %d\n", hdc
, level
);
526 dc
= DC_GetDCUpdate( hdc
);
527 if(!dc
) return FALSE
;
528 if(dc
->funcs
->pRestoreDC
)
530 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
531 GDI_ReleaseObj( hdc
);
535 if (level
== -1) level
= dc
->saveLevel
;
537 /* This pair of checks disagrees with MSDN "Platform SDK:
538 Windows GDI" July 2000 which says all negative values
539 for level will be interpreted as an instance relative
540 to the current state. Restricting it to just -1 does
542 || (level
> dc
->saveLevel
))
544 GDI_ReleaseObj( hdc
);
549 while (dc
->saveLevel
>= level
)
551 HDC hdcs
= HDC_32(dc
->header
.hNext
);
552 if (!(dcs
= DC_GetDCPtr( hdcs
)))
554 GDI_ReleaseObj( hdc
);
557 dc
->header
.hNext
= dcs
->header
.hNext
;
558 if (--dc
->saveLevel
< level
)
560 SetDCState( hdc
, hdcs
);
561 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
562 /* FIXME: This might not be quite right, since we're
563 * returning FALSE but still destroying the saved DC state */
566 GDI_ReleaseObj( hdcs
);
567 GDI_ReleaseObj( hdc
);
569 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
571 GDI_ReleaseObj( hdc
);
576 /***********************************************************************
577 * CreateDCW (GDI32.@)
579 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
580 const DEVMODEW
*initData
)
584 const DC_FUNCTIONS
*funcs
;
589 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
591 if (!driver
) return 0;
592 strcpyW(buf
, driver
);
595 if (!(funcs
= DRIVER_load_driver( buf
)))
597 ERR( "no driver found for %s\n", debugstr_w(buf
) );
600 if (!(dc
= DC_AllocDC( funcs
, DC_MAGIC
)))
602 DRIVER_release_driver( funcs
);
607 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
609 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
610 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
612 if (dc
->funcs
->pCreateDC
&&
613 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
615 WARN("creation aborted by device\n" );
616 GDI_FreeObject( dc
->hSelf
, dc
);
617 DRIVER_release_driver( funcs
);
621 dc
->hVisRgn
= CreateRectRgn( 0, 0, GetDeviceCaps( hdc
, HORZRES
),
622 GetDeviceCaps( hdc
, VERTRES
) );
625 GDI_ReleaseObj( hdc
);
630 /***********************************************************************
631 * CreateDCA (GDI32.@)
633 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
634 const DEVMODEA
*initData
)
636 UNICODE_STRING driverW
, deviceW
, outputW
;
640 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
641 else driverW
.Buffer
= NULL
;
643 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
644 else deviceW
.Buffer
= NULL
;
646 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
647 else outputW
.Buffer
= NULL
;
649 if (initData
) initDataW
= GdiConvertToDevmodeW(initData
);
650 else initDataW
= NULL
;
652 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
654 RtlFreeUnicodeString(&driverW
);
655 RtlFreeUnicodeString(&deviceW
);
656 RtlFreeUnicodeString(&outputW
);
657 HeapFree(GetProcessHeap(), 0, initDataW
);
662 /***********************************************************************
663 * CreateICA (GDI32.@)
665 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
666 const DEVMODEA
* initData
)
668 /* Nothing special yet for ICs */
669 return CreateDCA( driver
, device
, output
, initData
);
673 /***********************************************************************
674 * CreateICW (GDI32.@)
676 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
677 const DEVMODEW
* initData
)
679 /* Nothing special yet for ICs */
680 return CreateDCW( driver
, device
, output
, initData
);
684 /***********************************************************************
685 * CreateCompatibleDC (GDI32.@)
687 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
690 const DC_FUNCTIONS
*funcs
;
695 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
697 funcs
= origDC
->funcs
;
698 physDev
= origDC
->physDev
;
699 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
700 funcs
= DRIVER_get_driver( funcs
);
704 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
705 funcs
= DRIVER_load_driver( displayW
);
709 if (!funcs
) return 0;
711 if (!(dc
= DC_AllocDC( funcs
, MEMORY_DC_MAGIC
)))
713 DRIVER_release_driver( funcs
);
717 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
719 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
721 /* Copy the driver-specific physical device info into
722 * the new DC. The driver may use this read-only info
723 * while creating the compatible DC below. */
724 dc
->physDev
= physDev
;
726 if (dc
->funcs
->pCreateDC
&&
727 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
729 WARN("creation aborted by device\n");
730 GDI_FreeObject( dc
->hSelf
, dc
);
731 DRIVER_release_driver( funcs
);
735 dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
738 GDI_ReleaseObj( dc
->hSelf
);
743 /***********************************************************************
746 BOOL WINAPI
DeleteDC( HDC hdc
)
748 const DC_FUNCTIONS
*funcs
= NULL
;
755 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
757 /* Call hook procedure to check whether is it OK to delete this DC */
760 DCHOOKPROC proc
= dc
->hookThunk
;
761 DWORD data
= dc
->dwHookData
;
762 GDI_ReleaseObj( hdc
);
763 if (!proc( HDC_16(hdc
), DCHC_DELETEDC
, data
, 0 )) return FALSE
;
764 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
767 while (dc
->saveLevel
)
770 HDC hdcs
= HDC_32(dc
->header
.hNext
);
771 if (!(dcs
= DC_GetDCPtr( hdcs
))) break;
772 dc
->header
.hNext
= dcs
->header
.hNext
;
774 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
775 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
776 PATH_DestroyGdiPath(&dcs
->path
);
777 GDI_FreeObject( hdcs
, dcs
);
780 if (!(dc
->flags
& DC_SAVED
))
782 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
783 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
784 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
785 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
787 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
791 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
792 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
793 PATH_DestroyGdiPath(&dc
->path
);
795 GDI_FreeObject( hdc
, dc
);
796 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
801 /***********************************************************************
804 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
809 if ((dc
= DC_GetDCPtr( hdc
)))
811 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
812 GDI_ReleaseObj( hdc
);
818 /***********************************************************************
821 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
826 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
827 else devmodeW
= NULL
;
829 ret
= ResetDCW(hdc
, devmodeW
);
831 HeapFree(GetProcessHeap(), 0, devmodeW
);
836 /***********************************************************************
837 * GetDeviceCaps (GDI32.@)
839 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
844 if ((dc
= DC_GetDCPtr( hdc
)))
846 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
847 GDI_ReleaseObj( hdc
);
853 /***********************************************************************
854 * GetBkColor (GDI32.@)
856 COLORREF WINAPI
GetBkColor( HDC hdc
)
859 DC
* dc
= DC_GetDCPtr( hdc
);
862 ret
= dc
->backgroundColor
;
863 GDI_ReleaseObj( hdc
);
869 /***********************************************************************
870 * SetBkColor (GDI32.@)
872 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
875 DC
* dc
= DC_GetDCPtr( hdc
);
877 TRACE("hdc=%p color=0x%08lx\n", hdc
, color
);
879 if (!dc
) return CLR_INVALID
;
880 oldColor
= dc
->backgroundColor
;
881 if (dc
->funcs
->pSetBkColor
)
883 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
884 if (color
== CLR_INVALID
) /* don't change it */
887 oldColor
= CLR_INVALID
;
890 dc
->backgroundColor
= color
;
891 GDI_ReleaseObj( hdc
);
896 /***********************************************************************
897 * GetTextColor (GDI32.@)
899 COLORREF WINAPI
GetTextColor( HDC hdc
)
902 DC
* dc
= DC_GetDCPtr( hdc
);
906 GDI_ReleaseObj( hdc
);
912 /***********************************************************************
913 * SetTextColor (GDI32.@)
915 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
918 DC
* dc
= DC_GetDCPtr( hdc
);
920 TRACE(" hdc=%p color=0x%08lx\n", hdc
, color
);
922 if (!dc
) return CLR_INVALID
;
923 oldColor
= dc
->textColor
;
924 if (dc
->funcs
->pSetTextColor
)
926 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
927 if (color
== CLR_INVALID
) /* don't change it */
930 oldColor
= CLR_INVALID
;
933 dc
->textColor
= color
;
934 GDI_ReleaseObj( hdc
);
939 /***********************************************************************
940 * GetTextAlign (GDI32.@)
942 UINT WINAPI
GetTextAlign( HDC hdc
)
945 DC
* dc
= DC_GetDCPtr( hdc
);
949 GDI_ReleaseObj( hdc
);
955 /***********************************************************************
956 * SetTextAlign (GDI32.@)
958 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
961 DC
*dc
= DC_GetDCPtr( hdc
);
963 TRACE("hdc=%p align=%d\n", hdc
, align
);
966 if (dc
->funcs
->pSetTextAlign
)
967 prevAlign
= dc
->funcs
->pSetTextAlign(dc
->physDev
, align
);
969 prevAlign
= dc
->textAlign
;
970 dc
->textAlign
= align
;
972 GDI_ReleaseObj( hdc
);
976 /***********************************************************************
977 * GetDCOrgEx (GDI32.@)
979 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
983 if (!lpp
) return FALSE
;
984 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
987 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
988 GDI_ReleaseObj( hDC
);
993 /***********************************************************************
996 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
999 HDC hdc
= HDC_32( hdc16
);
1000 DC
*dc
= DC_GetDCPtr( hdc
);
1002 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
1003 GDI_ReleaseObj( hdc
);
1008 /***********************************************************************
1009 * GetGraphicsMode (GDI32.@)
1011 INT WINAPI
GetGraphicsMode( HDC hdc
)
1014 DC
* dc
= DC_GetDCPtr( hdc
);
1017 ret
= dc
->GraphicsMode
;
1018 GDI_ReleaseObj( hdc
);
1024 /***********************************************************************
1025 * SetGraphicsMode (GDI32.@)
1027 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1030 DC
*dc
= DC_GetDCPtr( hdc
);
1032 /* One would think that setting the graphics mode to GM_COMPATIBLE
1033 * would also reset the world transformation matrix to the unity
1034 * matrix. However, in Windows, this is not the case. This doesn't
1035 * make a lot of sense to me, but that's the way it is.
1038 if ((mode
> 0) && (mode
<= GM_LAST
))
1040 ret
= dc
->GraphicsMode
;
1041 dc
->GraphicsMode
= mode
;
1043 GDI_ReleaseObj( hdc
);
1048 /***********************************************************************
1049 * GetArcDirection (GDI32.@)
1051 INT WINAPI
GetArcDirection( HDC hdc
)
1054 DC
* dc
= DC_GetDCPtr( hdc
);
1057 ret
= dc
->ArcDirection
;
1058 GDI_ReleaseObj( hdc
);
1064 /***********************************************************************
1065 * SetArcDirection (GDI32.@)
1067 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1070 INT nOldDirection
= 0;
1072 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1074 SetLastError(ERROR_INVALID_PARAMETER
);
1078 if ((dc
= DC_GetDCPtr( hdc
)))
1080 if (dc
->funcs
->pSetArcDirection
)
1082 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1084 nOldDirection
= dc
->ArcDirection
;
1085 dc
->ArcDirection
= nDirection
;
1086 GDI_ReleaseObj( hdc
);
1088 return nOldDirection
;
1092 /***********************************************************************
1093 * GetWorldTransform (GDI32.@)
1095 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1098 if (!xform
) return FALSE
;
1099 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1100 *xform
= dc
->xformWorld2Wnd
;
1101 GDI_ReleaseObj( hdc
);
1106 /***********************************************************************
1107 * GetTransform (GDI32.@)
1109 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1111 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1112 FIXME("stub: don't know what to do for code %lx\n", unknown
);
1117 /***********************************************************************
1118 * SetWorldTransform (GDI32.@)
1120 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1123 DC
*dc
= DC_GetDCPtr( hdc
);
1125 if (!dc
) return FALSE
;
1126 if (!xform
) goto done
;
1128 /* Check that graphics mode is GM_ADVANCED */
1129 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1131 if (dc
->funcs
->pSetWorldTransform
)
1133 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1134 if (!ret
) goto done
;
1137 dc
->xformWorld2Wnd
= *xform
;
1138 DC_UpdateXforms( dc
);
1141 GDI_ReleaseObj( hdc
);
1146 /****************************************************************************
1147 * ModifyWorldTransform [GDI32.@]
1148 * Modifies the world transformation for a device context.
1151 * hdc [I] Handle to device context
1152 * xform [I] XFORM structure that will be used to modify the world
1154 * iMode [I] Specifies in what way to modify the world transformation
1157 * Resets the world transformation to the identity matrix.
1158 * The parameter xform is ignored.
1160 * Multiplies xform into the world transformation matrix from
1163 * Multiplies xform into the world transformation matrix from
1168 * Failure: FALSE. Use GetLastError() to determine the cause.
1170 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1174 DC
*dc
= DC_GetDCPtr( hdc
);
1176 /* Check for illegal parameters */
1177 if (!dc
) return FALSE
;
1178 if (!xform
) goto done
;
1180 /* Check that graphics mode is GM_ADVANCED */
1181 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1183 if (dc
->funcs
->pModifyWorldTransform
)
1185 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1186 if (!ret
) goto done
;
1192 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1193 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1194 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1195 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1196 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1197 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1199 case MWT_LEFTMULTIPLY
:
1200 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1201 &dc
->xformWorld2Wnd
);
1203 case MWT_RIGHTMULTIPLY
:
1204 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1211 DC_UpdateXforms( dc
);
1214 GDI_ReleaseObj( hdc
);
1219 /****************************************************************************
1220 * CombineTransform [GDI32.@]
1221 * Combines two transformation matrices.
1224 * xformResult [O] Stores the result of combining the two matrices
1225 * xform1 [I] Specifies the first matrix to apply
1226 * xform2 [I] Specifies the second matrix to apply
1229 * The same matrix can be passed in for more than one of the parameters.
1233 * Failure: FALSE. Use GetLastError() to determine the cause.
1235 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1236 const XFORM
*xform2
)
1240 /* Check for illegal parameters */
1241 if (!xformResult
|| !xform1
|| !xform2
)
1244 /* Create the result in a temporary XFORM, since xformResult may be
1245 * equal to xform1 or xform2 */
1246 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1247 xform1
->eM12
* xform2
->eM21
;
1248 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1249 xform1
->eM12
* xform2
->eM22
;
1250 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1251 xform1
->eM22
* xform2
->eM21
;
1252 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1253 xform1
->eM22
* xform2
->eM22
;
1254 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1255 xform1
->eDy
* xform2
->eM21
+
1257 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1258 xform1
->eDy
* xform2
->eM22
+
1261 /* Copy the result to xformResult */
1262 *xformResult
= xformTemp
;
1268 /***********************************************************************
1269 * SetDCHook (GDI32.@)
1271 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1273 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1275 DC
*dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
);
1277 if (!dc
) return FALSE
;
1279 if (!(dc
->flags
& DC_SAVED
))
1281 dc
->dwHookData
= dwHookData
;
1282 dc
->hookThunk
= hookProc
;
1284 GDI_ReleaseObj( hdc
);
1289 /* relay function to call the 16-bit DC hook proc */
1290 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc16
, WORD code
, DWORD data
, LPARAM lParam
)
1294 FARPROC16 proc
= NULL
;
1295 HDC hdc
= HDC_32( hdc16
);
1296 DC
*dc
= DC_GetDCPtr( hdc
);
1298 if (!dc
) return FALSE
;
1299 proc
= dc
->hookProc
;
1300 GDI_ReleaseObj( hdc
);
1301 if (!proc
) return FALSE
;
1304 args
[3] = HIWORD(data
);
1305 args
[2] = LOWORD(data
);
1306 args
[1] = HIWORD(lParam
);
1307 args
[0] = LOWORD(lParam
);
1308 WOWCallback16Ex( (DWORD
)proc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1312 /***********************************************************************
1313 * SetDCHook (GDI.190)
1315 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1317 HDC hdc
= HDC_32( hdc16
);
1318 DC
*dc
= DC_GetDCPtr( hdc
);
1319 if (!dc
) return FALSE
;
1321 dc
->hookProc
= hookProc
;
1322 GDI_ReleaseObj( hdc
);
1323 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1327 /***********************************************************************
1328 * GetDCHook (GDI.191)
1330 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1332 HDC hdc
= HDC_32( hdc16
);
1333 DC
*dc
= DC_GetDCPtr( hdc
);
1337 *phookProc
= dc
->hookProc
;
1338 ret
= dc
->dwHookData
;
1339 GDI_ReleaseObj( hdc
);
1344 /***********************************************************************
1345 * SetHookFlags (GDI.192)
1347 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1349 HDC hdc
= HDC_32( hdc16
);
1350 DC
*dc
= DC_GetDCPtr( hdc
);
1354 WORD wRet
= dc
->flags
& DC_DIRTY
;
1356 /* "Undocumented Windows" info is slightly confusing.
1359 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1361 if( flags
& DCHF_INVALIDATEVISRGN
)
1362 dc
->flags
|= DC_DIRTY
;
1363 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1364 dc
->flags
&= ~DC_DIRTY
;
1365 GDI_ReleaseObj( hdc
);
1371 /***********************************************************************
1372 * SetICMMode (GDI32.@)
1374 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1376 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1377 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1378 if (iEnableICM
== ICM_ON
) return 0;
1379 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1383 /***********************************************************************
1384 * GetDeviceGammaRamp (GDI32.@)
1386 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1389 DC
*dc
= DC_GetDCPtr( hDC
);
1393 if (dc
->funcs
->pGetDeviceGammaRamp
)
1394 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1395 GDI_ReleaseObj( hDC
);
1400 /***********************************************************************
1401 * SetDeviceGammaRamp (GDI32.@)
1403 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1406 DC
*dc
= DC_GetDCPtr( hDC
);
1410 if (dc
->funcs
->pSetDeviceGammaRamp
)
1411 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1412 GDI_ReleaseObj( hDC
);
1417 /***********************************************************************
1418 * GetColorSpace (GDI32.@)
1420 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1422 /*FIXME Need to to whatever GetColorSpace actually does */
1426 /***********************************************************************
1427 * CreateColorSpaceA (GDI32.@)
1429 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1435 /***********************************************************************
1436 * CreateColorSpaceW (GDI32.@)
1438 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1444 /***********************************************************************
1445 * DeleteColorSpace (GDI32.@)
1447 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1454 /***********************************************************************
1455 * SetColorSpace (GDI32.@)
1457 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1464 /***********************************************************************
1465 * GetBoundsRect (GDI32.@)
1467 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1470 DC
*dc
= DC_GetDCPtr( hdc
);
1472 if ( !dc
) return 0;
1474 if (rect
) *rect
= dc
->BoundsRect
;
1476 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1478 if (flags
& DCB_RESET
)
1480 dc
->BoundsRect
.left
= 0;
1481 dc
->BoundsRect
.top
= 0;
1482 dc
->BoundsRect
.right
= 0;
1483 dc
->BoundsRect
.bottom
= 0;
1484 dc
->flags
&= ~DC_BOUNDS_SET
;
1486 GDI_ReleaseObj( hdc
);
1491 /***********************************************************************
1492 * SetBoundsRect (GDI32.@)
1494 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1499 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1500 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1502 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1503 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1505 if (flags
& DCB_RESET
)
1507 dc
->BoundsRect
.left
= 0;
1508 dc
->BoundsRect
.top
= 0;
1509 dc
->BoundsRect
.right
= 0;
1510 dc
->BoundsRect
.bottom
= 0;
1511 dc
->flags
&= ~DC_BOUNDS_SET
;
1514 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1516 if (dc
->flags
& DC_BOUNDS_SET
)
1518 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1519 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1520 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1521 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1525 dc
->BoundsRect
= *rect
;
1526 dc
->flags
|= DC_BOUNDS_SET
;
1530 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1531 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1533 GDI_ReleaseObj( hdc
);
1538 /***********************************************************************
1539 * GetRelAbs (GDI32.@)
1541 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1544 DC
*dc
= DC_GetDCPtr( hdc
);
1545 if (dc
) ret
= dc
->relAbsMode
;
1546 GDI_ReleaseObj( hdc
);
1553 /***********************************************************************
1554 * GetBkMode (GDI32.@)
1556 INT WINAPI
GetBkMode( HDC hdc
)
1559 DC
* dc
= DC_GetDCPtr( hdc
);
1562 ret
= dc
->backgroundMode
;
1563 GDI_ReleaseObj( hdc
);
1569 /***********************************************************************
1570 * SetBkMode (GDI32.@)
1572 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1576 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1578 SetLastError(ERROR_INVALID_PARAMETER
);
1581 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1582 if (dc
->funcs
->pSetBkMode
)
1583 ret
= dc
->funcs
->pSetBkMode( dc
->physDev
, mode
);
1586 ret
= dc
->backgroundMode
;
1587 dc
->backgroundMode
= mode
;
1589 GDI_ReleaseObj( hdc
);
1594 /***********************************************************************
1597 INT WINAPI
GetROP2( HDC hdc
)
1600 DC
* dc
= DC_GetDCPtr( hdc
);
1604 GDI_ReleaseObj( hdc
);
1610 /***********************************************************************
1613 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1617 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1619 SetLastError(ERROR_INVALID_PARAMETER
);
1622 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1623 if (dc
->funcs
->pSetROP2
)
1624 ret
= dc
->funcs
->pSetROP2( dc
->physDev
, mode
);
1630 GDI_ReleaseObj( hdc
);
1635 /***********************************************************************
1636 * SetRelAbs (GDI32.@)
1638 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1642 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1644 SetLastError(ERROR_INVALID_PARAMETER
);
1647 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1648 if (dc
->funcs
->pSetRelAbs
)
1649 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1652 ret
= dc
->relAbsMode
;
1653 dc
->relAbsMode
= mode
;
1655 GDI_ReleaseObj( hdc
);
1660 /***********************************************************************
1661 * GetPolyFillMode (GDI32.@)
1663 INT WINAPI
GetPolyFillMode( HDC hdc
)
1666 DC
* dc
= DC_GetDCPtr( hdc
);
1669 ret
= dc
->polyFillMode
;
1670 GDI_ReleaseObj( hdc
);
1676 /***********************************************************************
1677 * SetPolyFillMode (GDI32.@)
1679 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1683 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1685 SetLastError(ERROR_INVALID_PARAMETER
);
1688 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1689 if (dc
->funcs
->pSetPolyFillMode
)
1690 ret
= dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
);
1693 ret
= dc
->polyFillMode
;
1694 dc
->polyFillMode
= mode
;
1696 GDI_ReleaseObj( hdc
);
1701 /***********************************************************************
1702 * GetStretchBltMode (GDI32.@)
1704 INT WINAPI
GetStretchBltMode( HDC hdc
)
1707 DC
* dc
= DC_GetDCPtr( hdc
);
1710 ret
= dc
->stretchBltMode
;
1711 GDI_ReleaseObj( hdc
);
1717 /***********************************************************************
1718 * SetStretchBltMode (GDI32.@)
1720 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1724 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1726 SetLastError(ERROR_INVALID_PARAMETER
);
1729 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1730 if (dc
->funcs
->pSetStretchBltMode
)
1731 ret
= dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
);
1734 ret
= dc
->stretchBltMode
;
1735 dc
->stretchBltMode
= mode
;
1737 GDI_ReleaseObj( hdc
);
1742 /***********************************************************************
1743 * GetMapMode (GDI32.@)
1745 INT WINAPI
GetMapMode( HDC hdc
)
1748 DC
* dc
= DC_GetDCPtr( hdc
);
1752 GDI_ReleaseObj( hdc
);
1758 /***********************************************************************
1759 * GetBrushOrgEx (GDI32.@)
1761 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1763 DC
* dc
= DC_GetDCPtr( hdc
);
1764 if (!dc
) return FALSE
;
1765 pt
->x
= dc
->brushOrgX
;
1766 pt
->y
= dc
->brushOrgY
;
1767 GDI_ReleaseObj( hdc
);
1772 /***********************************************************************
1773 * GetCurrentPositionEx (GDI32.@)
1775 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1777 DC
* dc
= DC_GetDCPtr( hdc
);
1778 if (!dc
) return FALSE
;
1779 pt
->x
= dc
->CursPosX
;
1780 pt
->y
= dc
->CursPosY
;
1781 GDI_ReleaseObj( hdc
);
1786 /***********************************************************************
1787 * GetViewportExtEx (GDI32.@)
1789 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1791 DC
* dc
= DC_GetDCPtr( hdc
);
1792 if (!dc
) return FALSE
;
1793 size
->cx
= dc
->vportExtX
;
1794 size
->cy
= dc
->vportExtY
;
1795 GDI_ReleaseObj( hdc
);
1800 /***********************************************************************
1801 * GetViewportOrgEx (GDI32.@)
1803 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1805 DC
* dc
= DC_GetDCPtr( hdc
);
1806 if (!dc
) return FALSE
;
1807 pt
->x
= dc
->vportOrgX
;
1808 pt
->y
= dc
->vportOrgY
;
1809 GDI_ReleaseObj( hdc
);
1814 /***********************************************************************
1815 * GetWindowExtEx (GDI32.@)
1817 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1819 DC
* dc
= DC_GetDCPtr( hdc
);
1820 if (!dc
) return FALSE
;
1821 size
->cx
= dc
->wndExtX
;
1822 size
->cy
= dc
->wndExtY
;
1823 GDI_ReleaseObj( hdc
);
1828 /***********************************************************************
1829 * GetWindowOrgEx (GDI32.@)
1831 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1833 DC
* dc
= DC_GetDCPtr( hdc
);
1834 if (!dc
) return FALSE
;
1835 pt
->x
= dc
->wndOrgX
;
1836 pt
->y
= dc
->wndOrgY
;
1837 GDI_ReleaseObj( hdc
);
1842 /***********************************************************************
1843 * InquireVisRgn (GDI.131)
1845 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1848 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1851 ret
= HRGN_16(dc
->hVisRgn
);
1852 GDI_ReleaseObj( HDC_32(hdc
) );
1858 /***********************************************************************
1859 * GetClipRgn (GDI.173)
1861 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1864 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1867 ret
= HRGN_16(dc
->hClipRgn
);
1868 GDI_ReleaseObj( HDC_32(hdc
) );
1874 /***********************************************************************
1875 * GetLayout (GDI32.@)
1877 * Gets left->right or right->left text layout flags of a dc.
1880 DWORD WINAPI
GetLayout(HDC hdc
)
1882 DWORD layout
= GDI_ERROR
;
1884 DC
* dc
= DC_GetDCPtr( hdc
);
1887 layout
= dc
->layout
;
1888 GDI_ReleaseObj( hdc
);
1891 TRACE("hdc : %p, layout : %08lx\n", hdc
, layout
);
1896 /***********************************************************************
1897 * SetLayout (GDI32.@)
1899 * Sets left->right or right->left text layout flags of a dc.
1902 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1904 DWORD oldlayout
= GDI_ERROR
;
1906 DC
* dc
= DC_GetDCPtr( hdc
);
1909 oldlayout
= dc
->layout
;
1910 dc
->layout
= layout
;
1911 GDI_ReleaseObj( hdc
);
1914 TRACE("hdc : %p, old layout : %08lx, new layout : %08lx\n", hdc
, oldlayout
, layout
);
1919 /***********************************************************************
1920 * GetDCBrushColor (GDI32.@)
1922 * Retrieves the current brush color for the specified device
1926 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1929 COLORREF dcBrushColor
= CLR_INVALID
;
1931 TRACE("hdc(%p)\n", hdc
);
1933 dc
= DC_GetDCPtr( hdc
);
1936 dcBrushColor
= dc
->dcBrushColor
;
1937 GDI_ReleaseObj( hdc
);
1940 return dcBrushColor
;
1943 /***********************************************************************
1944 * SetDCBrushColor (GDI32.@)
1946 * Sets the current device context (DC) brush color to the specified
1947 * color value. If the device cannot represent the specified color
1948 * value, the color is set to the nearest physical color.
1951 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1954 COLORREF oldClr
= CLR_INVALID
;
1956 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
1958 dc
= DC_GetDCPtr( hdc
);
1961 if (dc
->funcs
->pSetDCBrushColor
)
1962 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
1963 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
1965 /* If DC_BRUSH is selected, update driver pen color */
1966 HBRUSH hBrush
= CreateSolidBrush( crColor
);
1967 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
1968 DeleteObject( hBrush
);
1971 if (crColor
!= CLR_INVALID
)
1973 oldClr
= dc
->dcBrushColor
;
1974 dc
->dcBrushColor
= crColor
;
1977 GDI_ReleaseObj( hdc
);
1983 /***********************************************************************
1984 * GetDCPenColor (GDI32.@)
1986 * Retrieves the current pen color for the specified device
1990 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1993 COLORREF dcPenColor
= CLR_INVALID
;
1995 TRACE("hdc(%p)\n", hdc
);
1997 dc
= DC_GetDCPtr( hdc
);
2000 dcPenColor
= dc
->dcPenColor
;
2001 GDI_ReleaseObj( hdc
);
2007 /***********************************************************************
2008 * SetDCPenColor (GDI32.@)
2010 * Sets the current device context (DC) pen color to the specified
2011 * color value. If the device cannot represent the specified color
2012 * value, the color is set to the nearest physical color.
2015 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2018 COLORREF oldClr
= CLR_INVALID
;
2020 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
2022 dc
= DC_GetDCPtr( hdc
);
2025 if (dc
->funcs
->pSetDCPenColor
)
2026 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2027 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2029 /* If DC_PEN is selected, update the driver pen color */
2030 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2031 HPEN hPen
= CreatePenIndirect( &logpen
);
2032 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2033 DeleteObject( hPen
);
2036 if (crColor
!= CLR_INVALID
)
2038 oldClr
= dc
->dcPenColor
;
2039 dc
->dcPenColor
= crColor
;
2042 GDI_ReleaseObj( hdc
);
2048 /***********************************************************************
2049 * SetVirtualResolution (GDI32.@)
2051 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2053 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2055 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);
2059 /*******************************************************************
2060 * GetMiterLimit [GDI32.@]
2064 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2069 TRACE("(%p,%p)\n", hdc
, peLimit
);
2071 dc
= DC_GetDCPtr( hdc
);
2075 *peLimit
= dc
->miterLimit
;
2077 GDI_ReleaseObj( hdc
);
2083 /*******************************************************************
2084 * SetMiterLimit [GDI32.@]
2088 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2093 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2095 dc
= DC_GetDCPtr( hdc
);
2099 *peOldLimit
= dc
->miterLimit
;
2100 dc
->miterLimit
= eNewLimit
;
2101 GDI_ReleaseObj( hdc
);