2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
40 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
42 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
);
44 static const struct gdi_obj_funcs dc_funcs
=
46 NULL
, /* pSelectObject */
47 NULL
, /* pGetObject16 */
48 NULL
, /* pGetObjectA */
49 NULL
, /* pGetObjectW */
50 NULL
, /* pUnrealizeObject */
51 DC_DeleteObject
/* pDeleteObject */
55 static inline DC
*get_dc_obj( HDC hdc
)
57 DC
*dc
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
60 if ((GDIMAGIC(dc
->header
.wMagic
) != DC_MAGIC
) &&
61 (GDIMAGIC(dc
->header
.wMagic
) != MEMORY_DC_MAGIC
) &&
62 (GDIMAGIC(dc
->header
.wMagic
) != METAFILE_DC_MAGIC
) &&
63 (GDIMAGIC(dc
->header
.wMagic
) != ENHMETAFILE_DC_MAGIC
))
65 GDI_ReleaseObj( hdc
);
66 SetLastError( ERROR_INVALID_HANDLE
);
73 /***********************************************************************
76 DC
*alloc_dc_ptr( const DC_FUNCTIONS
*funcs
, WORD magic
)
81 if (!(dc
= GDI_AllocObject( sizeof(*dc
), magic
, (HGDIOBJ
*)&hdc
, &dc_funcs
))) return NULL
;
86 dc
->thread
= GetCurrentThreadId();
102 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
107 dc
->hMetaClipRgn
= 0;
109 dc
->hPen
= GetStockObject( BLACK_PEN
);
110 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
111 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
114 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
116 dc
->ROPmode
= R2_COPYPEN
;
117 dc
->polyFillMode
= ALTERNATE
;
118 dc
->stretchBltMode
= BLACKONWHITE
;
119 dc
->relAbsMode
= ABSOLUTE
;
120 dc
->backgroundMode
= OPAQUE
;
121 dc
->backgroundColor
= RGB( 255, 255, 255 );
122 dc
->dcBrushColor
= RGB( 255, 255, 255 );
123 dc
->dcPenColor
= RGB( 0, 0, 0 );
124 dc
->textColor
= RGB( 0, 0, 0 );
127 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
131 dc
->MapMode
= MM_TEXT
;
132 dc
->GraphicsMode
= GM_COMPATIBLE
;
133 dc
->pAbortProc
= NULL
;
136 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
137 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
138 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
139 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
140 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
141 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
142 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
143 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
144 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
145 dc
->vport2WorldValid
= TRUE
;
146 dc
->BoundsRect
.left
= 0;
147 dc
->BoundsRect
.top
= 0;
148 dc
->BoundsRect
.right
= 0;
149 dc
->BoundsRect
.bottom
= 0;
150 dc
->saved_visrgn
= NULL
;
151 PATH_InitGdiPath(&dc
->path
);
152 GDI_ReleaseObj( dc
->hSelf
);
158 /***********************************************************************
161 DC
*DC_GetDCPtr( HDC hdc
)
163 DC
*dc
= get_dc_obj( hdc
);
164 if (!dc
) return NULL
;
166 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
168 dc
->thread
= GetCurrentThreadId();
170 else if (dc
->thread
!= GetCurrentThreadId())
172 GDI_ReleaseObj( hdc
);
173 SetLastError( ERROR_ACCESS_DENIED
);
176 else InterlockedIncrement( &dc
->refcount
);
182 /***********************************************************************
185 void DC_ReleaseDCPtr( DC
*dc
)
187 release_dc_ptr( dc
);
188 GDI_ReleaseObj( dc
->hSelf
);
192 /***********************************************************************
195 BOOL
free_dc_ptr( DC
*dc
)
197 assert( dc
->refcount
== 1 );
198 /* grab the gdi lock again */
199 if (!GDI_GetObjPtr( dc
->hSelf
, MAGIC_DONTCARE
)) return FALSE
; /* shouldn't happen */
200 return GDI_FreeObject( dc
->hSelf
, dc
);
204 /***********************************************************************
207 * Retrieve a DC pointer but release the GDI lock.
209 DC
*get_dc_ptr( HDC hdc
)
211 DC
*dc
= get_dc_obj( hdc
);
212 if (!dc
) return NULL
;
214 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
216 dc
->thread
= GetCurrentThreadId();
218 else if (dc
->thread
!= GetCurrentThreadId())
220 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
221 GDI_ReleaseObj( hdc
);
224 else InterlockedIncrement( &dc
->refcount
);
226 GDI_ReleaseObj( hdc
);
231 /***********************************************************************
234 void release_dc_ptr( DC
*dc
)
239 ref
= InterlockedDecrement( &dc
->refcount
);
241 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
245 /***********************************************************************
248 * Make sure the DC vis region is up to date.
249 * This function may call up to USER so the GDI lock should _not_
250 * be held when calling it.
252 void update_dc( DC
*dc
)
254 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookThunk
)
255 dc
->hookThunk( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
259 /***********************************************************************
262 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
264 GDI_ReleaseObj( handle
);
265 return DeleteDC( handle
);
269 /***********************************************************************
272 * Setup device-specific DC values for a newly created DC.
274 void DC_InitDC( DC
* dc
)
276 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
277 SetTextColor( dc
->hSelf
, dc
->textColor
);
278 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
279 SelectObject( dc
->hSelf
, dc
->hPen
);
280 SelectObject( dc
->hSelf
, dc
->hBrush
);
281 SelectObject( dc
->hSelf
, dc
->hFont
);
282 CLIPPING_UpdateGCRegion( dc
);
286 /***********************************************************************
289 * Computes the inverse of the transformation xformSrc and stores it to
290 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
293 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
297 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
298 xformSrc
->eM12
*xformSrc
->eM21
;
299 if (determinant
> -1e-12 && determinant
< 1e-12)
302 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
303 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
304 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
305 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
306 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
307 xformSrc
->eDy
* xformDest
->eM21
;
308 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
309 xformSrc
->eDy
* xformDest
->eM22
;
315 /***********************************************************************
318 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
319 * fields of the specified DC by creating a transformation that
320 * represents the current mapping mode and combining it with the DC's
321 * world transform. This function should be called whenever the
322 * parameters associated with the mapping mode (window and viewport
323 * extents and origins) or the world transform change.
325 void DC_UpdateXforms( DC
*dc
)
327 XFORM xformWnd2Vport
, oldworld2vport
;
328 FLOAT scaleX
, scaleY
;
330 /* Construct a transformation to do the window-to-viewport conversion */
331 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
332 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
333 xformWnd2Vport
.eM11
= scaleX
;
334 xformWnd2Vport
.eM12
= 0.0;
335 xformWnd2Vport
.eM21
= 0.0;
336 xformWnd2Vport
.eM22
= scaleY
;
337 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
338 scaleX
* (FLOAT
)dc
->wndOrgX
;
339 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
340 scaleY
* (FLOAT
)dc
->wndOrgY
;
342 oldworld2vport
= dc
->xformWorld2Vport
;
343 /* Combine with the world transformation */
344 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
347 /* Create inverse of world-to-viewport transformation */
348 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
349 &dc
->xformVport2World
);
351 /* Reselect the font and pen back into the dc so that the size
353 if(memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)))
355 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
356 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
361 /***********************************************************************
362 * GetDCState (Not a Windows API)
364 HDC WINAPI
GetDCState( HDC hdc
)
369 if (!(dc
= get_dc_ptr( hdc
))) return 0;
370 if (!(newdc
= GDI_AllocObject( sizeof(DC
), GDIMAGIC(dc
->header
.wMagic
), &handle
, &dc_funcs
)))
372 release_dc_ptr( dc
);
375 TRACE("(%p): returning %p\n", hdc
, handle
);
377 newdc
->flags
= dc
->flags
| DC_SAVED
;
378 newdc
->layout
= dc
->layout
;
379 newdc
->hPen
= dc
->hPen
;
380 newdc
->hBrush
= dc
->hBrush
;
381 newdc
->hFont
= dc
->hFont
;
382 newdc
->hBitmap
= dc
->hBitmap
;
383 newdc
->hDevice
= dc
->hDevice
;
384 newdc
->hPalette
= dc
->hPalette
;
385 newdc
->ROPmode
= dc
->ROPmode
;
386 newdc
->polyFillMode
= dc
->polyFillMode
;
387 newdc
->stretchBltMode
= dc
->stretchBltMode
;
388 newdc
->relAbsMode
= dc
->relAbsMode
;
389 newdc
->backgroundMode
= dc
->backgroundMode
;
390 newdc
->backgroundColor
= dc
->backgroundColor
;
391 newdc
->textColor
= dc
->textColor
;
392 newdc
->dcBrushColor
= dc
->dcBrushColor
;
393 newdc
->dcPenColor
= dc
->dcPenColor
;
394 newdc
->brushOrgX
= dc
->brushOrgX
;
395 newdc
->brushOrgY
= dc
->brushOrgY
;
396 newdc
->textAlign
= dc
->textAlign
;
397 newdc
->charExtra
= dc
->charExtra
;
398 newdc
->breakExtra
= dc
->breakExtra
;
399 newdc
->breakRem
= dc
->breakRem
;
400 newdc
->MapMode
= dc
->MapMode
;
401 newdc
->GraphicsMode
= dc
->GraphicsMode
;
402 newdc
->CursPosX
= dc
->CursPosX
;
403 newdc
->CursPosY
= dc
->CursPosY
;
404 newdc
->ArcDirection
= dc
->ArcDirection
;
405 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
406 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
407 newdc
->xformVport2World
= dc
->xformVport2World
;
408 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
409 newdc
->wndOrgX
= dc
->wndOrgX
;
410 newdc
->wndOrgY
= dc
->wndOrgY
;
411 newdc
->wndExtX
= dc
->wndExtX
;
412 newdc
->wndExtY
= dc
->wndExtY
;
413 newdc
->vportOrgX
= dc
->vportOrgX
;
414 newdc
->vportOrgY
= dc
->vportOrgY
;
415 newdc
->vportExtX
= dc
->vportExtX
;
416 newdc
->vportExtY
= dc
->vportExtY
;
417 newdc
->BoundsRect
= dc
->BoundsRect
;
419 newdc
->hSelf
= (HDC
)handle
;
420 newdc
->thread
= GetCurrentThreadId();
422 newdc
->saveLevel
= 0;
424 GDI_ReleaseObj( handle
);
426 PATH_InitGdiPath( &newdc
->path
);
428 newdc
->pAbortProc
= NULL
;
429 newdc
->hookThunk
= NULL
;
431 newdc
->saved_visrgn
= NULL
;
433 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
438 newdc
->hMetaClipRgn
= 0;
441 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
442 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
446 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
447 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
449 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
452 newdc
->gdiFont
= dc
->gdiFont
;
456 release_dc_ptr( newdc
);
457 release_dc_ptr( dc
);
462 /***********************************************************************
463 * SetDCState (Not a Windows API)
465 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
469 if (!(dc
= get_dc_ptr( hdc
))) return;
470 if (!(dcs
= get_dc_ptr( hdcs
)))
472 release_dc_ptr( dc
);
475 if (!dcs
->flags
& DC_SAVED
)
477 release_dc_ptr( dc
);
478 release_dc_ptr( dcs
);
481 TRACE("%p %p\n", hdc
, hdcs
);
484 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
485 dc
->layout
= dcs
->layout
;
486 dc
->hDevice
= dcs
->hDevice
;
487 dc
->ROPmode
= dcs
->ROPmode
;
488 dc
->polyFillMode
= dcs
->polyFillMode
;
489 dc
->stretchBltMode
= dcs
->stretchBltMode
;
490 dc
->relAbsMode
= dcs
->relAbsMode
;
491 dc
->backgroundMode
= dcs
->backgroundMode
;
492 dc
->backgroundColor
= dcs
->backgroundColor
;
493 dc
->textColor
= dcs
->textColor
;
494 dc
->dcBrushColor
= dcs
->dcBrushColor
;
495 dc
->dcPenColor
= dcs
->dcPenColor
;
496 dc
->brushOrgX
= dcs
->brushOrgX
;
497 dc
->brushOrgY
= dcs
->brushOrgY
;
498 dc
->textAlign
= dcs
->textAlign
;
499 dc
->charExtra
= dcs
->charExtra
;
500 dc
->breakExtra
= dcs
->breakExtra
;
501 dc
->breakRem
= dcs
->breakRem
;
502 dc
->MapMode
= dcs
->MapMode
;
503 dc
->GraphicsMode
= dcs
->GraphicsMode
;
504 dc
->CursPosX
= dcs
->CursPosX
;
505 dc
->CursPosY
= dcs
->CursPosY
;
506 dc
->ArcDirection
= dcs
->ArcDirection
;
507 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
508 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
509 dc
->xformVport2World
= dcs
->xformVport2World
;
510 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
511 dc
->BoundsRect
= dcs
->BoundsRect
;
513 dc
->wndOrgX
= dcs
->wndOrgX
;
514 dc
->wndOrgY
= dcs
->wndOrgY
;
515 dc
->wndExtX
= dcs
->wndExtX
;
516 dc
->wndExtY
= dcs
->wndExtY
;
517 dc
->vportOrgX
= dcs
->vportOrgX
;
518 dc
->vportOrgY
= dcs
->vportOrgY
;
519 dc
->vportExtX
= dcs
->vportExtX
;
520 dc
->vportExtY
= dcs
->vportExtY
;
524 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
525 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
529 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
534 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
535 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
539 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
542 CLIPPING_UpdateGCRegion( dc
);
544 SelectObject( hdc
, dcs
->hBitmap
);
545 SelectObject( hdc
, dcs
->hBrush
);
546 SelectObject( hdc
, dcs
->hFont
);
547 SelectObject( hdc
, dcs
->hPen
);
548 SetBkColor( hdc
, dcs
->backgroundColor
);
549 SetTextColor( hdc
, dcs
->textColor
);
550 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
551 release_dc_ptr( dc
);
552 release_dc_ptr( dcs
);
556 /***********************************************************************
557 * GetDCState (GDI.179)
559 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
561 return HDC_16( GetDCState( HDC_32(hdc
) ));
565 /***********************************************************************
566 * SetDCState (GDI.180)
568 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
570 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
574 /***********************************************************************
577 INT WINAPI
SaveDC( HDC hdc
)
583 dc
= get_dc_ptr( hdc
);
586 if(dc
->funcs
->pSaveDC
)
588 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
590 ret
= ++dc
->saveLevel
;
591 release_dc_ptr( dc
);
595 if (!(hdcs
= GetDCState( hdc
)))
597 release_dc_ptr( dc
);
600 dcs
= get_dc_ptr( hdcs
);
602 /* Copy path. The reason why path saving / restoring is in SaveDC/
603 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
604 * functions are only in Win16 (which doesn't have paths) and that
605 * SetDCState doesn't allow us to signal an error (which can happen
606 * when copying paths).
608 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
610 release_dc_ptr( dc
);
611 release_dc_ptr( dcs
);
616 dcs
->saved_dc
= dc
->saved_dc
;
618 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
619 ret
= ++dc
->saveLevel
;
620 release_dc_ptr( dcs
);
621 release_dc_ptr( dc
);
626 /***********************************************************************
627 * RestoreDC (GDI32.@)
629 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
634 TRACE("%p %d\n", hdc
, level
);
635 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
637 if(abs(level
) > dc
->saveLevel
|| level
== 0)
639 release_dc_ptr( dc
);
645 if(dc
->funcs
->pRestoreDC
)
647 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
648 if(level
< 0) level
= dc
->saveLevel
+ level
+ 1;
650 dc
->saveLevel
= level
- 1;
651 release_dc_ptr( dc
);
655 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
657 while (dc
->saveLevel
>= level
)
659 HDC hdcs
= dc
->saved_dc
;
660 if (!(dcs
= get_dc_ptr( hdcs
)))
665 dc
->saved_dc
= dcs
->saved_dc
;
667 if (--dc
->saveLevel
< level
)
669 SetDCState( hdc
, hdcs
);
670 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
671 /* FIXME: This might not be quite right, since we're
672 * returning FALSE but still destroying the saved DC state */
675 release_dc_ptr( dcs
);
678 release_dc_ptr( dc
);
683 /***********************************************************************
684 * CreateDCW (GDI32.@)
686 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
687 const DEVMODEW
*initData
)
691 const DC_FUNCTIONS
*funcs
;
696 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
700 ERR( "no device found for %s\n", debugstr_w(device
) );
703 strcpyW(buf
, driver
);
706 if (!(funcs
= DRIVER_load_driver( buf
)))
708 ERR( "no driver found for %s\n", debugstr_w(buf
) );
711 if (!(dc
= alloc_dc_ptr( funcs
, DC_MAGIC
))) goto error
;
714 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
715 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
717 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
718 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
720 if (dc
->funcs
->pCreateDC
&&
721 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
723 WARN("creation aborted by device\n" );
727 SetRectRgn( dc
->hVisRgn
, 0, 0,
728 GetDeviceCaps( hdc
, DESKTOPHORZRES
), GetDeviceCaps( hdc
, DESKTOPVERTRES
) );
731 release_dc_ptr( dc
);
735 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
736 if (dc
) free_dc_ptr( dc
);
737 DRIVER_release_driver( funcs
);
742 /***********************************************************************
743 * CreateDCA (GDI32.@)
745 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
746 const DEVMODEA
*initData
)
748 UNICODE_STRING driverW
, deviceW
, outputW
;
752 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
753 else driverW
.Buffer
= NULL
;
755 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
756 else deviceW
.Buffer
= NULL
;
758 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
759 else outputW
.Buffer
= NULL
;
764 /* don't convert initData for DISPLAY driver, it's not used */
765 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
766 initDataW
= GdiConvertToDevmodeW(initData
);
769 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
771 RtlFreeUnicodeString(&driverW
);
772 RtlFreeUnicodeString(&deviceW
);
773 RtlFreeUnicodeString(&outputW
);
774 HeapFree(GetProcessHeap(), 0, initDataW
);
779 /***********************************************************************
780 * CreateICA (GDI32.@)
782 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
783 const DEVMODEA
* initData
)
785 /* Nothing special yet for ICs */
786 return CreateDCA( driver
, device
, output
, initData
);
790 /***********************************************************************
791 * CreateICW (GDI32.@)
793 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
794 const DEVMODEW
* initData
)
796 /* Nothing special yet for ICs */
797 return CreateDCW( driver
, device
, output
, initData
);
801 /***********************************************************************
802 * CreateCompatibleDC (GDI32.@)
804 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
808 const DC_FUNCTIONS
*funcs
= NULL
;
809 PHYSDEV physDev
= NULL
;
813 if ((origDC
= get_dc_ptr( hdc
)))
815 if (GetObjectType( hdc
) == OBJ_DC
)
817 funcs
= origDC
->funcs
;
818 physDev
= origDC
->physDev
;
820 release_dc_ptr( origDC
);
821 if (funcs
) funcs
= DRIVER_get_driver( funcs
);
824 if (!funcs
&& !(funcs
= DRIVER_load_driver( displayW
))) return 0;
826 if (!(dc
= alloc_dc_ptr( funcs
, MEMORY_DC_MAGIC
))) goto error
;
828 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
830 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
831 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
833 /* Copy the driver-specific physical device info into
834 * the new DC. The driver may use this read-only info
835 * while creating the compatible DC below. */
836 dc
->physDev
= physDev
;
839 if (dc
->funcs
->pCreateDC
&&
840 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
842 WARN("creation aborted by device\n");
847 release_dc_ptr( dc
);
851 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
852 if (dc
) free_dc_ptr( dc
);
853 DRIVER_release_driver( funcs
);
858 /***********************************************************************
861 BOOL WINAPI
DeleteDC( HDC hdc
)
863 const DC_FUNCTIONS
*funcs
= NULL
;
870 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
871 if (dc
->refcount
!= 1)
873 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
874 release_dc_ptr( dc
);
878 /* Call hook procedure to check whether is it OK to delete this DC */
879 if (dc
->hookThunk
&& !dc
->hookThunk( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
881 release_dc_ptr( dc
);
885 while (dc
->saveLevel
)
888 HDC hdcs
= dc
->saved_dc
;
889 if (!(dcs
= get_dc_ptr( hdcs
))) break;
890 dc
->saved_dc
= dcs
->saved_dc
;
892 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
893 if (dcs
->hMetaRgn
) DeleteObject( dcs
->hMetaRgn
);
894 if (dcs
->hMetaClipRgn
) DeleteObject( dcs
->hMetaClipRgn
);
895 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
896 PATH_DestroyGdiPath(&dcs
->path
);
900 if (!(dc
->flags
& DC_SAVED
))
902 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
903 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
904 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
905 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
907 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
911 while (dc
->saved_visrgn
)
913 struct saved_visrgn
*next
= dc
->saved_visrgn
->next
;
914 DeleteObject( dc
->saved_visrgn
->hrgn
);
915 HeapFree( GetProcessHeap(), 0, dc
->saved_visrgn
);
916 dc
->saved_visrgn
= next
;
918 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
919 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
920 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
921 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
922 PATH_DestroyGdiPath(&dc
->path
);
925 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
930 /***********************************************************************
933 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
938 if ((dc
= get_dc_ptr( hdc
)))
940 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
941 release_dc_ptr( dc
);
947 /***********************************************************************
950 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
955 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
956 else devmodeW
= NULL
;
958 ret
= ResetDCW(hdc
, devmodeW
);
960 HeapFree(GetProcessHeap(), 0, devmodeW
);
965 /***********************************************************************
966 * GetDeviceCaps (GDI32.@)
968 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
973 if ((dc
= get_dc_ptr( hdc
)))
975 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
976 else switch(cap
) /* return meaningful values for some entries */
978 case HORZRES
: ret
= 640; break;
979 case VERTRES
: ret
= 480; break;
980 case BITSPIXEL
: ret
= 1; break;
981 case PLANES
: ret
= 1; break;
982 case NUMCOLORS
: ret
= 2; break;
983 case ASPECTX
: ret
= 36; break;
984 case ASPECTY
: ret
= 36; break;
985 case ASPECTXY
: ret
= 51; break;
986 case LOGPIXELSX
: ret
= 72; break;
987 case LOGPIXELSY
: ret
= 72; break;
988 case SIZEPALETTE
: ret
= 2; break;
990 release_dc_ptr( dc
);
996 /***********************************************************************
997 * GetBkColor (GDI32.@)
999 COLORREF WINAPI
GetBkColor( HDC hdc
)
1002 DC
* dc
= get_dc_ptr( hdc
);
1005 ret
= dc
->backgroundColor
;
1006 release_dc_ptr( dc
);
1012 /***********************************************************************
1013 * SetBkColor (GDI32.@)
1015 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
1018 DC
* dc
= get_dc_ptr( hdc
);
1020 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
1022 if (!dc
) return CLR_INVALID
;
1023 oldColor
= dc
->backgroundColor
;
1024 if (dc
->funcs
->pSetBkColor
)
1026 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
1027 if (color
== CLR_INVALID
) /* don't change it */
1030 oldColor
= CLR_INVALID
;
1033 dc
->backgroundColor
= color
;
1034 release_dc_ptr( dc
);
1039 /***********************************************************************
1040 * GetTextColor (GDI32.@)
1042 COLORREF WINAPI
GetTextColor( HDC hdc
)
1045 DC
* dc
= get_dc_ptr( hdc
);
1048 ret
= dc
->textColor
;
1049 release_dc_ptr( dc
);
1055 /***********************************************************************
1056 * SetTextColor (GDI32.@)
1058 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
1061 DC
* dc
= get_dc_ptr( hdc
);
1063 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
1065 if (!dc
) return CLR_INVALID
;
1066 oldColor
= dc
->textColor
;
1067 if (dc
->funcs
->pSetTextColor
)
1069 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
1070 if (color
== CLR_INVALID
) /* don't change it */
1073 oldColor
= CLR_INVALID
;
1076 dc
->textColor
= color
;
1077 release_dc_ptr( dc
);
1082 /***********************************************************************
1083 * GetTextAlign (GDI32.@)
1085 UINT WINAPI
GetTextAlign( HDC hdc
)
1088 DC
* dc
= get_dc_ptr( hdc
);
1091 ret
= dc
->textAlign
;
1092 release_dc_ptr( dc
);
1098 /***********************************************************************
1099 * SetTextAlign (GDI32.@)
1101 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1104 DC
*dc
= get_dc_ptr( hdc
);
1106 TRACE("hdc=%p align=%d\n", hdc
, align
);
1108 if (!dc
) return 0x0;
1109 ret
= dc
->textAlign
;
1110 if (dc
->funcs
->pSetTextAlign
)
1111 if (!dc
->funcs
->pSetTextAlign(dc
->physDev
, align
))
1113 if (ret
!= GDI_ERROR
)
1114 dc
->textAlign
= align
;
1115 release_dc_ptr( dc
);
1119 /***********************************************************************
1120 * GetDCOrgEx (GDI32.@)
1122 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1126 if (!lpp
) return FALSE
;
1127 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1129 lpp
->x
= lpp
->y
= 0;
1130 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
1131 release_dc_ptr( dc
);
1136 /***********************************************************************
1137 * SetDCOrg (GDI.117)
1139 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
1142 HDC hdc
= HDC_32( hdc16
);
1143 DC
*dc
= get_dc_ptr( hdc
);
1145 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
1146 release_dc_ptr( dc
);
1151 /***********************************************************************
1152 * GetGraphicsMode (GDI32.@)
1154 INT WINAPI
GetGraphicsMode( HDC hdc
)
1157 DC
* dc
= get_dc_ptr( hdc
);
1160 ret
= dc
->GraphicsMode
;
1161 release_dc_ptr( dc
);
1167 /***********************************************************************
1168 * SetGraphicsMode (GDI32.@)
1170 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1173 DC
*dc
= get_dc_ptr( hdc
);
1175 /* One would think that setting the graphics mode to GM_COMPATIBLE
1176 * would also reset the world transformation matrix to the unity
1177 * matrix. However, in Windows, this is not the case. This doesn't
1178 * make a lot of sense to me, but that's the way it is.
1181 if ((mode
> 0) && (mode
<= GM_LAST
))
1183 ret
= dc
->GraphicsMode
;
1184 dc
->GraphicsMode
= mode
;
1186 release_dc_ptr( dc
);
1191 /***********************************************************************
1192 * GetArcDirection (GDI32.@)
1194 INT WINAPI
GetArcDirection( HDC hdc
)
1197 DC
* dc
= get_dc_ptr( hdc
);
1200 ret
= dc
->ArcDirection
;
1201 release_dc_ptr( dc
);
1207 /***********************************************************************
1208 * SetArcDirection (GDI32.@)
1210 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1213 INT nOldDirection
= 0;
1215 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1217 SetLastError(ERROR_INVALID_PARAMETER
);
1221 if ((dc
= get_dc_ptr( hdc
)))
1223 if (dc
->funcs
->pSetArcDirection
)
1225 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1227 nOldDirection
= dc
->ArcDirection
;
1228 dc
->ArcDirection
= nDirection
;
1229 release_dc_ptr( dc
);
1231 return nOldDirection
;
1235 /***********************************************************************
1236 * GetWorldTransform (GDI32.@)
1238 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1241 if (!xform
) return FALSE
;
1242 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1243 *xform
= dc
->xformWorld2Wnd
;
1244 release_dc_ptr( dc
);
1249 /***********************************************************************
1250 * GetTransform (GDI32.@)
1252 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1254 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1255 FIXME("stub: don't know what to do for code %x\n", unknown
);
1260 /***********************************************************************
1261 * SetWorldTransform (GDI32.@)
1263 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1266 DC
*dc
= get_dc_ptr( hdc
);
1268 if (!dc
) return FALSE
;
1269 if (!xform
) goto done
;
1271 /* Check that graphics mode is GM_ADVANCED */
1272 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1274 if (dc
->funcs
->pSetWorldTransform
)
1276 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1277 if (!ret
) goto done
;
1280 dc
->xformWorld2Wnd
= *xform
;
1281 DC_UpdateXforms( dc
);
1284 release_dc_ptr( dc
);
1289 /****************************************************************************
1290 * ModifyWorldTransform [GDI32.@]
1291 * Modifies the world transformation for a device context.
1294 * hdc [I] Handle to device context
1295 * xform [I] XFORM structure that will be used to modify the world
1297 * iMode [I] Specifies in what way to modify the world transformation
1300 * Resets the world transformation to the identity matrix.
1301 * The parameter xform is ignored.
1303 * Multiplies xform into the world transformation matrix from
1306 * Multiplies xform into the world transformation matrix from
1311 * Failure: FALSE. Use GetLastError() to determine the cause.
1313 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1317 DC
*dc
= get_dc_ptr( hdc
);
1319 /* Check for illegal parameters */
1320 if (!dc
) return FALSE
;
1321 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1323 /* Check that graphics mode is GM_ADVANCED */
1324 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1326 if (dc
->funcs
->pModifyWorldTransform
)
1328 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1329 if (!ret
) goto done
;
1335 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1336 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1337 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1338 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1339 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1340 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1342 case MWT_LEFTMULTIPLY
:
1343 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1344 &dc
->xformWorld2Wnd
);
1346 case MWT_RIGHTMULTIPLY
:
1347 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1354 DC_UpdateXforms( dc
);
1357 release_dc_ptr( dc
);
1362 /****************************************************************************
1363 * CombineTransform [GDI32.@]
1364 * Combines two transformation matrices.
1367 * xformResult [O] Stores the result of combining the two matrices
1368 * xform1 [I] Specifies the first matrix to apply
1369 * xform2 [I] Specifies the second matrix to apply
1372 * The same matrix can be passed in for more than one of the parameters.
1376 * Failure: FALSE. Use GetLastError() to determine the cause.
1378 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1379 const XFORM
*xform2
)
1383 /* Check for illegal parameters */
1384 if (!xformResult
|| !xform1
|| !xform2
)
1387 /* Create the result in a temporary XFORM, since xformResult may be
1388 * equal to xform1 or xform2 */
1389 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1390 xform1
->eM12
* xform2
->eM21
;
1391 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1392 xform1
->eM12
* xform2
->eM22
;
1393 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1394 xform1
->eM22
* xform2
->eM21
;
1395 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1396 xform1
->eM22
* xform2
->eM22
;
1397 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1398 xform1
->eDy
* xform2
->eM21
+
1400 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1401 xform1
->eDy
* xform2
->eM22
+
1404 /* Copy the result to xformResult */
1405 *xformResult
= xformTemp
;
1411 /***********************************************************************
1412 * SetDCHook (GDI32.@)
1414 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1416 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1418 DC
*dc
= get_dc_ptr( hdc
);
1420 if (!dc
) return FALSE
;
1422 if (!(dc
->flags
& DC_SAVED
))
1424 dc
->dwHookData
= dwHookData
;
1425 dc
->hookThunk
= hookProc
;
1427 release_dc_ptr( dc
);
1432 /* relay function to call the 16-bit DC hook proc */
1433 static BOOL WINAPI
call_dc_hook16( HDC hdc
, WORD code
, DWORD_PTR data
, LPARAM lParam
)
1437 DC
*dc
= get_dc_ptr( hdc
);
1439 if (!dc
) return FALSE
;
1442 args
[5] = HDC_16(hdc
);
1444 args
[3] = HIWORD(data
);
1445 args
[2] = LOWORD(data
);
1446 args
[1] = HIWORD(lParam
);
1447 args
[0] = LOWORD(lParam
);
1448 WOWCallback16Ex( (DWORD
)dc
->hookProc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1450 release_dc_ptr( dc
);
1454 /***********************************************************************
1455 * SetDCHook (GDI.190)
1457 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1459 DC
*dc
= get_dc_ptr( HDC_32(hdc16
) );
1461 if (!dc
) return FALSE
;
1462 if (!(dc
->flags
& DC_SAVED
))
1464 dc
->dwHookData
= dwHookData
;
1465 dc
->hookThunk
= call_dc_hook16
;
1466 dc
->hookProc
= hookProc
;
1468 release_dc_ptr( dc
);
1473 /***********************************************************************
1474 * GetDCHook (GDI.191)
1476 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1478 HDC hdc
= HDC_32( hdc16
);
1479 DC
*dc
= get_dc_ptr( hdc
);
1483 *phookProc
= dc
->hookProc
;
1484 ret
= dc
->dwHookData
;
1485 release_dc_ptr( dc
);
1490 /***********************************************************************
1491 * SetHookFlags (GDI.192)
1493 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1495 HDC hdc
= HDC_32( hdc16
);
1496 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1501 /* "Undocumented Windows" info is slightly confusing. */
1503 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1505 if (flags
& DCHF_INVALIDATEVISRGN
)
1506 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1507 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1508 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1510 GDI_ReleaseObj( dc
);
1514 /***********************************************************************
1515 * SetICMMode (GDI32.@)
1517 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1519 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1520 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1521 if (iEnableICM
== ICM_ON
) return 0;
1522 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1526 /***********************************************************************
1527 * GetDeviceGammaRamp (GDI32.@)
1529 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1532 DC
*dc
= get_dc_ptr( hDC
);
1536 if (dc
->funcs
->pGetDeviceGammaRamp
)
1537 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1538 release_dc_ptr( dc
);
1543 /***********************************************************************
1544 * SetDeviceGammaRamp (GDI32.@)
1546 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1549 DC
*dc
= get_dc_ptr( hDC
);
1553 if (dc
->funcs
->pSetDeviceGammaRamp
)
1554 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1555 release_dc_ptr( dc
);
1560 /***********************************************************************
1561 * GetColorSpace (GDI32.@)
1563 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1565 /*FIXME Need to to whatever GetColorSpace actually does */
1569 /***********************************************************************
1570 * CreateColorSpaceA (GDI32.@)
1572 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1578 /***********************************************************************
1579 * CreateColorSpaceW (GDI32.@)
1581 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1587 /***********************************************************************
1588 * DeleteColorSpace (GDI32.@)
1590 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1597 /***********************************************************************
1598 * SetColorSpace (GDI32.@)
1600 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1607 /***********************************************************************
1608 * GetBoundsRect (GDI32.@)
1610 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1613 DC
*dc
= get_dc_ptr( hdc
);
1615 if ( !dc
) return 0;
1617 if (rect
) *rect
= dc
->BoundsRect
;
1619 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1621 if (flags
& DCB_RESET
)
1623 dc
->BoundsRect
.left
= 0;
1624 dc
->BoundsRect
.top
= 0;
1625 dc
->BoundsRect
.right
= 0;
1626 dc
->BoundsRect
.bottom
= 0;
1627 dc
->flags
&= ~DC_BOUNDS_SET
;
1629 release_dc_ptr( dc
);
1634 /***********************************************************************
1635 * SetBoundsRect (GDI32.@)
1637 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1642 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1643 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1645 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1646 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1648 if (flags
& DCB_RESET
)
1650 dc
->BoundsRect
.left
= 0;
1651 dc
->BoundsRect
.top
= 0;
1652 dc
->BoundsRect
.right
= 0;
1653 dc
->BoundsRect
.bottom
= 0;
1654 dc
->flags
&= ~DC_BOUNDS_SET
;
1657 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1659 if (dc
->flags
& DC_BOUNDS_SET
)
1661 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1662 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1663 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1664 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1668 dc
->BoundsRect
= *rect
;
1669 dc
->flags
|= DC_BOUNDS_SET
;
1673 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1674 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1676 release_dc_ptr( dc
);
1681 /***********************************************************************
1682 * GetRelAbs (GDI32.@)
1684 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1687 DC
*dc
= get_dc_ptr( hdc
);
1690 ret
= dc
->relAbsMode
;
1691 release_dc_ptr( dc
);
1699 /***********************************************************************
1700 * GetBkMode (GDI32.@)
1702 INT WINAPI
GetBkMode( HDC hdc
)
1705 DC
* dc
= get_dc_ptr( hdc
);
1708 ret
= dc
->backgroundMode
;
1709 release_dc_ptr( dc
);
1715 /***********************************************************************
1716 * SetBkMode (GDI32.@)
1718 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1722 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1724 SetLastError(ERROR_INVALID_PARAMETER
);
1727 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1729 ret
= dc
->backgroundMode
;
1730 if (dc
->funcs
->pSetBkMode
)
1731 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1734 dc
->backgroundMode
= mode
;
1735 release_dc_ptr( dc
);
1740 /***********************************************************************
1743 INT WINAPI
GetROP2( HDC hdc
)
1746 DC
* dc
= get_dc_ptr( hdc
);
1750 release_dc_ptr( dc
);
1756 /***********************************************************************
1759 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1763 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1765 SetLastError(ERROR_INVALID_PARAMETER
);
1768 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1770 if (dc
->funcs
->pSetROP2
)
1771 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1775 release_dc_ptr( dc
);
1780 /***********************************************************************
1781 * SetRelAbs (GDI32.@)
1783 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1787 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1789 SetLastError(ERROR_INVALID_PARAMETER
);
1792 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1793 if (dc
->funcs
->pSetRelAbs
)
1794 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1797 ret
= dc
->relAbsMode
;
1798 dc
->relAbsMode
= mode
;
1800 release_dc_ptr( dc
);
1805 /***********************************************************************
1806 * GetPolyFillMode (GDI32.@)
1808 INT WINAPI
GetPolyFillMode( HDC hdc
)
1811 DC
* dc
= get_dc_ptr( hdc
);
1814 ret
= dc
->polyFillMode
;
1815 release_dc_ptr( dc
);
1821 /***********************************************************************
1822 * SetPolyFillMode (GDI32.@)
1824 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1828 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1830 SetLastError(ERROR_INVALID_PARAMETER
);
1833 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1834 ret
= dc
->polyFillMode
;
1835 if (dc
->funcs
->pSetPolyFillMode
)
1836 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1839 dc
->polyFillMode
= mode
;
1840 release_dc_ptr( dc
);
1845 /***********************************************************************
1846 * GetStretchBltMode (GDI32.@)
1848 INT WINAPI
GetStretchBltMode( HDC hdc
)
1851 DC
* dc
= get_dc_ptr( hdc
);
1854 ret
= dc
->stretchBltMode
;
1855 release_dc_ptr( dc
);
1861 /***********************************************************************
1862 * SetStretchBltMode (GDI32.@)
1864 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1868 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1870 SetLastError(ERROR_INVALID_PARAMETER
);
1873 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1874 ret
= dc
->stretchBltMode
;
1875 if (dc
->funcs
->pSetStretchBltMode
)
1876 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1879 dc
->stretchBltMode
= mode
;
1880 release_dc_ptr( dc
);
1885 /***********************************************************************
1886 * GetMapMode (GDI32.@)
1888 INT WINAPI
GetMapMode( HDC hdc
)
1891 DC
* dc
= get_dc_ptr( hdc
);
1895 release_dc_ptr( dc
);
1901 /***********************************************************************
1902 * GetBrushOrgEx (GDI32.@)
1904 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1906 DC
* dc
= get_dc_ptr( hdc
);
1907 if (!dc
) return FALSE
;
1908 pt
->x
= dc
->brushOrgX
;
1909 pt
->y
= dc
->brushOrgY
;
1910 release_dc_ptr( dc
);
1915 /***********************************************************************
1916 * GetCurrentPositionEx (GDI32.@)
1918 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1920 DC
* dc
= get_dc_ptr( hdc
);
1921 if (!dc
) return FALSE
;
1922 pt
->x
= dc
->CursPosX
;
1923 pt
->y
= dc
->CursPosY
;
1924 release_dc_ptr( dc
);
1929 /***********************************************************************
1930 * GetViewportExtEx (GDI32.@)
1932 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1934 DC
* dc
= get_dc_ptr( hdc
);
1935 if (!dc
) return FALSE
;
1936 size
->cx
= dc
->vportExtX
;
1937 size
->cy
= dc
->vportExtY
;
1938 release_dc_ptr( dc
);
1943 /***********************************************************************
1944 * GetViewportOrgEx (GDI32.@)
1946 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1948 DC
* dc
= get_dc_ptr( hdc
);
1949 if (!dc
) return FALSE
;
1950 pt
->x
= dc
->vportOrgX
;
1951 pt
->y
= dc
->vportOrgY
;
1952 release_dc_ptr( dc
);
1957 /***********************************************************************
1958 * GetWindowExtEx (GDI32.@)
1960 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1962 DC
* dc
= get_dc_ptr( hdc
);
1963 if (!dc
) return FALSE
;
1964 size
->cx
= dc
->wndExtX
;
1965 size
->cy
= dc
->wndExtY
;
1966 release_dc_ptr( dc
);
1971 /***********************************************************************
1972 * GetWindowOrgEx (GDI32.@)
1974 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1976 DC
* dc
= get_dc_ptr( hdc
);
1977 if (!dc
) return FALSE
;
1978 pt
->x
= dc
->wndOrgX
;
1979 pt
->y
= dc
->wndOrgY
;
1980 release_dc_ptr( dc
);
1985 /***********************************************************************
1986 * InquireVisRgn (GDI.131)
1988 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1991 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1994 ret
= HRGN_16(dc
->hVisRgn
);
1995 release_dc_ptr( dc
);
2001 /***********************************************************************
2002 * GetClipRgn (GDI.173)
2004 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
2007 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
2010 ret
= HRGN_16(dc
->hClipRgn
);
2011 release_dc_ptr( dc
);
2017 /***********************************************************************
2018 * GetLayout (GDI32.@)
2020 * Gets left->right or right->left text layout flags of a dc.
2023 DWORD WINAPI
GetLayout(HDC hdc
)
2025 DWORD layout
= GDI_ERROR
;
2027 DC
* dc
= get_dc_ptr( hdc
);
2030 layout
= dc
->layout
;
2031 release_dc_ptr( dc
);
2034 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
2039 /***********************************************************************
2040 * SetLayout (GDI32.@)
2042 * Sets left->right or right->left text layout flags of a dc.
2045 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
2047 DWORD oldlayout
= GDI_ERROR
;
2049 DC
* dc
= get_dc_ptr( hdc
);
2052 oldlayout
= dc
->layout
;
2053 dc
->layout
= layout
;
2054 release_dc_ptr( dc
);
2057 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
2062 /***********************************************************************
2063 * GetDCBrushColor (GDI32.@)
2065 * Retrieves the current brush color for the specified device
2069 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
2072 COLORREF dcBrushColor
= CLR_INVALID
;
2074 TRACE("hdc(%p)\n", hdc
);
2076 dc
= get_dc_ptr( hdc
);
2079 dcBrushColor
= dc
->dcBrushColor
;
2080 release_dc_ptr( dc
);
2083 return dcBrushColor
;
2086 /***********************************************************************
2087 * SetDCBrushColor (GDI32.@)
2089 * Sets the current device context (DC) brush color to the specified
2090 * color value. If the device cannot represent the specified color
2091 * value, the color is set to the nearest physical color.
2094 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2097 COLORREF oldClr
= CLR_INVALID
;
2099 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2101 dc
= get_dc_ptr( hdc
);
2104 if (dc
->funcs
->pSetDCBrushColor
)
2105 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2106 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2108 /* If DC_BRUSH is selected, update driver pen color */
2109 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2110 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2111 DeleteObject( hBrush
);
2114 if (crColor
!= CLR_INVALID
)
2116 oldClr
= dc
->dcBrushColor
;
2117 dc
->dcBrushColor
= crColor
;
2120 release_dc_ptr( dc
);
2126 /***********************************************************************
2127 * GetDCPenColor (GDI32.@)
2129 * Retrieves the current pen color for the specified device
2133 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2136 COLORREF dcPenColor
= CLR_INVALID
;
2138 TRACE("hdc(%p)\n", hdc
);
2140 dc
= get_dc_ptr( hdc
);
2143 dcPenColor
= dc
->dcPenColor
;
2144 release_dc_ptr( dc
);
2150 /***********************************************************************
2151 * SetDCPenColor (GDI32.@)
2153 * Sets the current device context (DC) pen color to the specified
2154 * color value. If the device cannot represent the specified color
2155 * value, the color is set to the nearest physical color.
2158 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2161 COLORREF oldClr
= CLR_INVALID
;
2163 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2165 dc
= get_dc_ptr( hdc
);
2168 if (dc
->funcs
->pSetDCPenColor
)
2169 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2170 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2172 /* If DC_PEN is selected, update the driver pen color */
2173 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2174 HPEN hPen
= CreatePenIndirect( &logpen
);
2175 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2176 DeleteObject( hPen
);
2179 if (crColor
!= CLR_INVALID
)
2181 oldClr
= dc
->dcPenColor
;
2182 dc
->dcPenColor
= crColor
;
2185 release_dc_ptr( dc
);
2191 /***********************************************************************
2192 * CancelDC (GDI32.@)
2194 BOOL WINAPI
CancelDC(HDC hdc
)
2200 /***********************************************************************
2201 * SetVirtualResolution (GDI32.@)
2203 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2205 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2207 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);
2211 /*******************************************************************
2212 * GetMiterLimit [GDI32.@]
2216 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2221 TRACE("(%p,%p)\n", hdc
, peLimit
);
2223 dc
= get_dc_ptr( hdc
);
2227 *peLimit
= dc
->miterLimit
;
2229 release_dc_ptr( dc
);
2235 /*******************************************************************
2236 * SetMiterLimit [GDI32.@]
2240 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2245 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2247 dc
= get_dc_ptr( hdc
);
2251 *peOldLimit
= dc
->miterLimit
;
2252 dc
->miterLimit
= eNewLimit
;
2253 release_dc_ptr( dc
);
2259 /*******************************************************************
2260 * GdiIsMetaPrintDC [GDI32.@]
2262 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2268 /*******************************************************************
2269 * GdiIsMetaFileDC [GDI32.@]
2271 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2275 switch( GetObjectType( hdc
) )
2284 /*******************************************************************
2285 * GdiIsPlayMetafileDC [GDI32.@]
2287 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)