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 BOOL
free_dc_ptr( DC
*dc
)
163 assert( dc
->refcount
== 1 );
164 /* grab the gdi lock again */
165 if (!GDI_GetObjPtr( dc
->hSelf
, MAGIC_DONTCARE
)) return FALSE
; /* shouldn't happen */
166 return GDI_FreeObject( dc
->hSelf
, dc
);
170 /***********************************************************************
173 * Retrieve a DC pointer but release the GDI lock.
175 DC
*get_dc_ptr( HDC hdc
)
177 DC
*dc
= get_dc_obj( hdc
);
178 if (!dc
) return NULL
;
180 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
182 dc
->thread
= GetCurrentThreadId();
184 else if (dc
->thread
!= GetCurrentThreadId())
186 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
187 GDI_ReleaseObj( hdc
);
190 else InterlockedIncrement( &dc
->refcount
);
192 GDI_ReleaseObj( hdc
);
197 /***********************************************************************
200 void release_dc_ptr( DC
*dc
)
205 ref
= InterlockedDecrement( &dc
->refcount
);
207 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
211 /***********************************************************************
214 * Make sure the DC vis region is up to date.
215 * This function may call up to USER so the GDI lock should _not_
216 * be held when calling it.
218 void update_dc( DC
*dc
)
220 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookThunk
)
221 dc
->hookThunk( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
225 /***********************************************************************
228 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
230 GDI_ReleaseObj( handle
);
231 return DeleteDC( handle
);
235 /***********************************************************************
238 * Setup device-specific DC values for a newly created DC.
240 void DC_InitDC( DC
* dc
)
242 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
243 SetTextColor( dc
->hSelf
, dc
->textColor
);
244 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
245 SelectObject( dc
->hSelf
, dc
->hPen
);
246 SelectObject( dc
->hSelf
, dc
->hBrush
);
247 SelectObject( dc
->hSelf
, dc
->hFont
);
248 CLIPPING_UpdateGCRegion( dc
);
252 /***********************************************************************
255 * Computes the inverse of the transformation xformSrc and stores it to
256 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
259 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
263 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
264 xformSrc
->eM12
*xformSrc
->eM21
;
265 if (determinant
> -1e-12 && determinant
< 1e-12)
268 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
269 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
270 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
271 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
272 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
273 xformSrc
->eDy
* xformDest
->eM21
;
274 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
275 xformSrc
->eDy
* xformDest
->eM22
;
281 /***********************************************************************
284 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
285 * fields of the specified DC by creating a transformation that
286 * represents the current mapping mode and combining it with the DC's
287 * world transform. This function should be called whenever the
288 * parameters associated with the mapping mode (window and viewport
289 * extents and origins) or the world transform change.
291 void DC_UpdateXforms( DC
*dc
)
293 XFORM xformWnd2Vport
, oldworld2vport
;
294 FLOAT scaleX
, scaleY
;
296 /* Construct a transformation to do the window-to-viewport conversion */
297 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
298 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
299 xformWnd2Vport
.eM11
= scaleX
;
300 xformWnd2Vport
.eM12
= 0.0;
301 xformWnd2Vport
.eM21
= 0.0;
302 xformWnd2Vport
.eM22
= scaleY
;
303 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
304 scaleX
* (FLOAT
)dc
->wndOrgX
;
305 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
306 scaleY
* (FLOAT
)dc
->wndOrgY
;
308 oldworld2vport
= dc
->xformWorld2Vport
;
309 /* Combine with the world transformation */
310 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
313 /* Create inverse of world-to-viewport transformation */
314 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
315 &dc
->xformVport2World
);
317 /* Reselect the font and pen back into the dc so that the size
319 if(memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)))
321 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
322 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
327 /***********************************************************************
328 * GetDCState (Not a Windows API)
330 HDC WINAPI
GetDCState( HDC hdc
)
335 if (!(dc
= get_dc_ptr( hdc
))) return 0;
336 if (!(newdc
= GDI_AllocObject( sizeof(DC
), GDIMAGIC(dc
->header
.wMagic
), &handle
, &dc_funcs
)))
338 release_dc_ptr( dc
);
341 TRACE("(%p): returning %p\n", hdc
, handle
);
343 newdc
->flags
= dc
->flags
| DC_SAVED
;
344 newdc
->layout
= dc
->layout
;
345 newdc
->hPen
= dc
->hPen
;
346 newdc
->hBrush
= dc
->hBrush
;
347 newdc
->hFont
= dc
->hFont
;
348 newdc
->hBitmap
= dc
->hBitmap
;
349 newdc
->hDevice
= dc
->hDevice
;
350 newdc
->hPalette
= dc
->hPalette
;
351 newdc
->ROPmode
= dc
->ROPmode
;
352 newdc
->polyFillMode
= dc
->polyFillMode
;
353 newdc
->stretchBltMode
= dc
->stretchBltMode
;
354 newdc
->relAbsMode
= dc
->relAbsMode
;
355 newdc
->backgroundMode
= dc
->backgroundMode
;
356 newdc
->backgroundColor
= dc
->backgroundColor
;
357 newdc
->textColor
= dc
->textColor
;
358 newdc
->dcBrushColor
= dc
->dcBrushColor
;
359 newdc
->dcPenColor
= dc
->dcPenColor
;
360 newdc
->brushOrgX
= dc
->brushOrgX
;
361 newdc
->brushOrgY
= dc
->brushOrgY
;
362 newdc
->textAlign
= dc
->textAlign
;
363 newdc
->charExtra
= dc
->charExtra
;
364 newdc
->breakExtra
= dc
->breakExtra
;
365 newdc
->breakRem
= dc
->breakRem
;
366 newdc
->MapMode
= dc
->MapMode
;
367 newdc
->GraphicsMode
= dc
->GraphicsMode
;
368 newdc
->CursPosX
= dc
->CursPosX
;
369 newdc
->CursPosY
= dc
->CursPosY
;
370 newdc
->ArcDirection
= dc
->ArcDirection
;
371 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
372 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
373 newdc
->xformVport2World
= dc
->xformVport2World
;
374 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
375 newdc
->wndOrgX
= dc
->wndOrgX
;
376 newdc
->wndOrgY
= dc
->wndOrgY
;
377 newdc
->wndExtX
= dc
->wndExtX
;
378 newdc
->wndExtY
= dc
->wndExtY
;
379 newdc
->vportOrgX
= dc
->vportOrgX
;
380 newdc
->vportOrgY
= dc
->vportOrgY
;
381 newdc
->vportExtX
= dc
->vportExtX
;
382 newdc
->vportExtY
= dc
->vportExtY
;
383 newdc
->BoundsRect
= dc
->BoundsRect
;
385 newdc
->hSelf
= (HDC
)handle
;
386 newdc
->thread
= GetCurrentThreadId();
388 newdc
->saveLevel
= 0;
390 GDI_ReleaseObj( handle
);
392 PATH_InitGdiPath( &newdc
->path
);
394 newdc
->pAbortProc
= NULL
;
395 newdc
->hookThunk
= NULL
;
397 newdc
->saved_visrgn
= NULL
;
399 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
404 newdc
->hMetaClipRgn
= 0;
407 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
408 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
412 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
413 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
415 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
418 newdc
->gdiFont
= dc
->gdiFont
;
422 release_dc_ptr( newdc
);
423 release_dc_ptr( dc
);
428 /***********************************************************************
429 * SetDCState (Not a Windows API)
431 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
435 if (!(dc
= get_dc_ptr( hdc
))) return;
436 if (!(dcs
= get_dc_ptr( hdcs
)))
438 release_dc_ptr( dc
);
441 if (!(dcs
->flags
& DC_SAVED
))
443 release_dc_ptr( dc
);
444 release_dc_ptr( dcs
);
447 TRACE("%p %p\n", hdc
, hdcs
);
450 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
451 dc
->layout
= dcs
->layout
;
452 dc
->hDevice
= dcs
->hDevice
;
453 dc
->ROPmode
= dcs
->ROPmode
;
454 dc
->polyFillMode
= dcs
->polyFillMode
;
455 dc
->stretchBltMode
= dcs
->stretchBltMode
;
456 dc
->relAbsMode
= dcs
->relAbsMode
;
457 dc
->backgroundMode
= dcs
->backgroundMode
;
458 dc
->backgroundColor
= dcs
->backgroundColor
;
459 dc
->textColor
= dcs
->textColor
;
460 dc
->dcBrushColor
= dcs
->dcBrushColor
;
461 dc
->dcPenColor
= dcs
->dcPenColor
;
462 dc
->brushOrgX
= dcs
->brushOrgX
;
463 dc
->brushOrgY
= dcs
->brushOrgY
;
464 dc
->textAlign
= dcs
->textAlign
;
465 dc
->charExtra
= dcs
->charExtra
;
466 dc
->breakExtra
= dcs
->breakExtra
;
467 dc
->breakRem
= dcs
->breakRem
;
468 dc
->MapMode
= dcs
->MapMode
;
469 dc
->GraphicsMode
= dcs
->GraphicsMode
;
470 dc
->CursPosX
= dcs
->CursPosX
;
471 dc
->CursPosY
= dcs
->CursPosY
;
472 dc
->ArcDirection
= dcs
->ArcDirection
;
473 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
474 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
475 dc
->xformVport2World
= dcs
->xformVport2World
;
476 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
477 dc
->BoundsRect
= dcs
->BoundsRect
;
479 dc
->wndOrgX
= dcs
->wndOrgX
;
480 dc
->wndOrgY
= dcs
->wndOrgY
;
481 dc
->wndExtX
= dcs
->wndExtX
;
482 dc
->wndExtY
= dcs
->wndExtY
;
483 dc
->vportOrgX
= dcs
->vportOrgX
;
484 dc
->vportOrgY
= dcs
->vportOrgY
;
485 dc
->vportExtX
= dcs
->vportExtX
;
486 dc
->vportExtY
= dcs
->vportExtY
;
490 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
491 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
495 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
500 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
501 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
505 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
508 CLIPPING_UpdateGCRegion( dc
);
510 SelectObject( hdc
, dcs
->hBitmap
);
511 SelectObject( hdc
, dcs
->hBrush
);
512 SelectObject( hdc
, dcs
->hFont
);
513 SelectObject( hdc
, dcs
->hPen
);
514 SetBkColor( hdc
, dcs
->backgroundColor
);
515 SetTextColor( hdc
, dcs
->textColor
);
516 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
517 release_dc_ptr( dc
);
518 release_dc_ptr( dcs
);
522 /***********************************************************************
523 * GetDCState (GDI.179)
525 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
527 return HDC_16( GetDCState( HDC_32(hdc
) ));
531 /***********************************************************************
532 * SetDCState (GDI.180)
534 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
536 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
540 /***********************************************************************
543 INT WINAPI
SaveDC( HDC hdc
)
549 dc
= get_dc_ptr( hdc
);
552 if(dc
->funcs
->pSaveDC
)
554 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
556 ret
= ++dc
->saveLevel
;
557 release_dc_ptr( dc
);
561 if (!(hdcs
= GetDCState( hdc
)))
563 release_dc_ptr( dc
);
566 dcs
= get_dc_ptr( hdcs
);
568 /* Copy path. The reason why path saving / restoring is in SaveDC/
569 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
570 * functions are only in Win16 (which doesn't have paths) and that
571 * SetDCState doesn't allow us to signal an error (which can happen
572 * when copying paths).
574 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
576 release_dc_ptr( dc
);
577 release_dc_ptr( dcs
);
582 dcs
->saved_dc
= dc
->saved_dc
;
584 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
585 ret
= ++dc
->saveLevel
;
586 release_dc_ptr( dcs
);
587 release_dc_ptr( dc
);
592 /***********************************************************************
593 * RestoreDC (GDI32.@)
595 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
600 TRACE("%p %d\n", hdc
, level
);
601 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
603 if(abs(level
) > dc
->saveLevel
|| level
== 0)
605 release_dc_ptr( dc
);
611 if(dc
->funcs
->pRestoreDC
)
613 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
614 if(level
< 0) level
= dc
->saveLevel
+ level
+ 1;
616 dc
->saveLevel
= level
- 1;
617 release_dc_ptr( dc
);
621 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
623 while (dc
->saveLevel
>= level
)
625 HDC hdcs
= dc
->saved_dc
;
626 if (!(dcs
= get_dc_ptr( hdcs
)))
631 dc
->saved_dc
= dcs
->saved_dc
;
633 if (--dc
->saveLevel
< level
)
635 SetDCState( hdc
, hdcs
);
636 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
637 /* FIXME: This might not be quite right, since we're
638 * returning FALSE but still destroying the saved DC state */
641 release_dc_ptr( dcs
);
644 release_dc_ptr( dc
);
649 /***********************************************************************
650 * CreateDCW (GDI32.@)
652 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
653 const DEVMODEW
*initData
)
657 const DC_FUNCTIONS
*funcs
;
662 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
666 ERR( "no device found for %s\n", debugstr_w(device
) );
669 strcpyW(buf
, driver
);
672 if (!(funcs
= DRIVER_load_driver( buf
)))
674 ERR( "no driver found for %s\n", debugstr_w(buf
) );
677 if (!(dc
= alloc_dc_ptr( funcs
, DC_MAGIC
))) goto error
;
680 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
681 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
683 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
684 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
686 if (dc
->funcs
->pCreateDC
&&
687 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
689 WARN("creation aborted by device\n" );
693 SetRectRgn( dc
->hVisRgn
, 0, 0,
694 GetDeviceCaps( hdc
, DESKTOPHORZRES
), GetDeviceCaps( hdc
, DESKTOPVERTRES
) );
697 release_dc_ptr( dc
);
701 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
702 if (dc
) free_dc_ptr( dc
);
703 DRIVER_release_driver( funcs
);
708 /***********************************************************************
709 * CreateDCA (GDI32.@)
711 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
712 const DEVMODEA
*initData
)
714 UNICODE_STRING driverW
, deviceW
, outputW
;
718 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
719 else driverW
.Buffer
= NULL
;
721 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
722 else deviceW
.Buffer
= NULL
;
724 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
725 else outputW
.Buffer
= NULL
;
730 /* don't convert initData for DISPLAY driver, it's not used */
731 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
732 initDataW
= GdiConvertToDevmodeW(initData
);
735 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
737 RtlFreeUnicodeString(&driverW
);
738 RtlFreeUnicodeString(&deviceW
);
739 RtlFreeUnicodeString(&outputW
);
740 HeapFree(GetProcessHeap(), 0, initDataW
);
745 /***********************************************************************
746 * CreateICA (GDI32.@)
748 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
749 const DEVMODEA
* initData
)
751 /* Nothing special yet for ICs */
752 return CreateDCA( driver
, device
, output
, initData
);
756 /***********************************************************************
757 * CreateICW (GDI32.@)
759 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
760 const DEVMODEW
* initData
)
762 /* Nothing special yet for ICs */
763 return CreateDCW( driver
, device
, output
, initData
);
767 /***********************************************************************
768 * CreateCompatibleDC (GDI32.@)
770 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
774 const DC_FUNCTIONS
*funcs
= NULL
;
775 PHYSDEV physDev
= NULL
;
779 if ((origDC
= get_dc_ptr( hdc
)))
781 if (GetObjectType( hdc
) == OBJ_DC
)
783 funcs
= origDC
->funcs
;
784 physDev
= origDC
->physDev
;
786 release_dc_ptr( origDC
);
787 if (funcs
) funcs
= DRIVER_get_driver( funcs
);
790 if (!funcs
&& !(funcs
= DRIVER_load_driver( displayW
))) return 0;
792 if (!(dc
= alloc_dc_ptr( funcs
, MEMORY_DC_MAGIC
))) goto error
;
794 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
796 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
797 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
799 /* Copy the driver-specific physical device info into
800 * the new DC. The driver may use this read-only info
801 * while creating the compatible DC below. */
802 dc
->physDev
= physDev
;
805 if (dc
->funcs
->pCreateDC
&&
806 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
808 WARN("creation aborted by device\n");
813 release_dc_ptr( dc
);
817 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
818 if (dc
) free_dc_ptr( dc
);
819 DRIVER_release_driver( funcs
);
824 /***********************************************************************
827 BOOL WINAPI
DeleteDC( HDC hdc
)
829 const DC_FUNCTIONS
*funcs
= NULL
;
836 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
837 if (dc
->refcount
!= 1)
839 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
840 release_dc_ptr( dc
);
844 /* Call hook procedure to check whether is it OK to delete this DC */
845 if (dc
->hookThunk
&& !dc
->hookThunk( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
847 release_dc_ptr( dc
);
851 while (dc
->saveLevel
)
854 HDC hdcs
= dc
->saved_dc
;
855 if (!(dcs
= get_dc_ptr( hdcs
))) break;
856 dc
->saved_dc
= dcs
->saved_dc
;
858 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
859 if (dcs
->hMetaRgn
) DeleteObject( dcs
->hMetaRgn
);
860 if (dcs
->hMetaClipRgn
) DeleteObject( dcs
->hMetaClipRgn
);
861 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
862 PATH_DestroyGdiPath(&dcs
->path
);
866 if (!(dc
->flags
& DC_SAVED
))
868 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
869 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
870 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
871 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
873 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
877 while (dc
->saved_visrgn
)
879 struct saved_visrgn
*next
= dc
->saved_visrgn
->next
;
880 DeleteObject( dc
->saved_visrgn
->hrgn
);
881 HeapFree( GetProcessHeap(), 0, dc
->saved_visrgn
);
882 dc
->saved_visrgn
= next
;
884 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
885 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
886 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
887 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
888 PATH_DestroyGdiPath(&dc
->path
);
891 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
896 /***********************************************************************
899 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
904 if ((dc
= get_dc_ptr( hdc
)))
906 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
907 release_dc_ptr( dc
);
913 /***********************************************************************
916 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
921 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
922 else devmodeW
= NULL
;
924 ret
= ResetDCW(hdc
, devmodeW
);
926 HeapFree(GetProcessHeap(), 0, devmodeW
);
931 /***********************************************************************
932 * GetDeviceCaps (GDI32.@)
934 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
939 if ((dc
= get_dc_ptr( hdc
)))
941 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
942 else switch(cap
) /* return meaningful values for some entries */
944 case HORZRES
: ret
= 640; break;
945 case VERTRES
: ret
= 480; break;
946 case BITSPIXEL
: ret
= 1; break;
947 case PLANES
: ret
= 1; break;
948 case NUMCOLORS
: ret
= 2; break;
949 case ASPECTX
: ret
= 36; break;
950 case ASPECTY
: ret
= 36; break;
951 case ASPECTXY
: ret
= 51; break;
952 case LOGPIXELSX
: ret
= 72; break;
953 case LOGPIXELSY
: ret
= 72; break;
954 case SIZEPALETTE
: ret
= 2; break;
956 release_dc_ptr( dc
);
962 /***********************************************************************
963 * GetBkColor (GDI32.@)
965 COLORREF WINAPI
GetBkColor( HDC hdc
)
968 DC
* dc
= get_dc_ptr( hdc
);
971 ret
= dc
->backgroundColor
;
972 release_dc_ptr( dc
);
978 /***********************************************************************
979 * SetBkColor (GDI32.@)
981 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
984 DC
* dc
= get_dc_ptr( hdc
);
986 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
988 if (!dc
) return CLR_INVALID
;
989 oldColor
= dc
->backgroundColor
;
990 if (dc
->funcs
->pSetBkColor
)
992 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
993 if (color
== CLR_INVALID
) /* don't change it */
996 oldColor
= CLR_INVALID
;
999 dc
->backgroundColor
= color
;
1000 release_dc_ptr( dc
);
1005 /***********************************************************************
1006 * GetTextColor (GDI32.@)
1008 COLORREF WINAPI
GetTextColor( HDC hdc
)
1011 DC
* dc
= get_dc_ptr( hdc
);
1014 ret
= dc
->textColor
;
1015 release_dc_ptr( dc
);
1021 /***********************************************************************
1022 * SetTextColor (GDI32.@)
1024 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
1027 DC
* dc
= get_dc_ptr( hdc
);
1029 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
1031 if (!dc
) return CLR_INVALID
;
1032 oldColor
= dc
->textColor
;
1033 if (dc
->funcs
->pSetTextColor
)
1035 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
1036 if (color
== CLR_INVALID
) /* don't change it */
1039 oldColor
= CLR_INVALID
;
1042 dc
->textColor
= color
;
1043 release_dc_ptr( dc
);
1048 /***********************************************************************
1049 * GetTextAlign (GDI32.@)
1051 UINT WINAPI
GetTextAlign( HDC hdc
)
1054 DC
* dc
= get_dc_ptr( hdc
);
1057 ret
= dc
->textAlign
;
1058 release_dc_ptr( dc
);
1064 /***********************************************************************
1065 * SetTextAlign (GDI32.@)
1067 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1070 DC
*dc
= get_dc_ptr( hdc
);
1072 TRACE("hdc=%p align=%d\n", hdc
, align
);
1074 if (!dc
) return 0x0;
1075 ret
= dc
->textAlign
;
1076 if (dc
->funcs
->pSetTextAlign
)
1077 if (!dc
->funcs
->pSetTextAlign(dc
->physDev
, align
))
1079 if (ret
!= GDI_ERROR
)
1080 dc
->textAlign
= align
;
1081 release_dc_ptr( dc
);
1085 /***********************************************************************
1086 * GetDCOrgEx (GDI32.@)
1088 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1092 if (!lpp
) return FALSE
;
1093 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1095 lpp
->x
= lpp
->y
= 0;
1096 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
1097 release_dc_ptr( dc
);
1102 /***********************************************************************
1103 * SetDCOrg (GDI.117)
1105 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
1108 HDC hdc
= HDC_32( hdc16
);
1109 DC
*dc
= get_dc_ptr( hdc
);
1111 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
1112 release_dc_ptr( dc
);
1117 /***********************************************************************
1118 * GetGraphicsMode (GDI32.@)
1120 INT WINAPI
GetGraphicsMode( HDC hdc
)
1123 DC
* dc
= get_dc_ptr( hdc
);
1126 ret
= dc
->GraphicsMode
;
1127 release_dc_ptr( dc
);
1133 /***********************************************************************
1134 * SetGraphicsMode (GDI32.@)
1136 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1139 DC
*dc
= get_dc_ptr( hdc
);
1141 /* One would think that setting the graphics mode to GM_COMPATIBLE
1142 * would also reset the world transformation matrix to the unity
1143 * matrix. However, in Windows, this is not the case. This doesn't
1144 * make a lot of sense to me, but that's the way it is.
1147 if ((mode
> 0) && (mode
<= GM_LAST
))
1149 ret
= dc
->GraphicsMode
;
1150 dc
->GraphicsMode
= mode
;
1152 release_dc_ptr( dc
);
1157 /***********************************************************************
1158 * GetArcDirection (GDI32.@)
1160 INT WINAPI
GetArcDirection( HDC hdc
)
1163 DC
* dc
= get_dc_ptr( hdc
);
1166 ret
= dc
->ArcDirection
;
1167 release_dc_ptr( dc
);
1173 /***********************************************************************
1174 * SetArcDirection (GDI32.@)
1176 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1179 INT nOldDirection
= 0;
1181 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1183 SetLastError(ERROR_INVALID_PARAMETER
);
1187 if ((dc
= get_dc_ptr( hdc
)))
1189 if (dc
->funcs
->pSetArcDirection
)
1191 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1193 nOldDirection
= dc
->ArcDirection
;
1194 dc
->ArcDirection
= nDirection
;
1195 release_dc_ptr( dc
);
1197 return nOldDirection
;
1201 /***********************************************************************
1202 * GetWorldTransform (GDI32.@)
1204 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1207 if (!xform
) return FALSE
;
1208 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1209 *xform
= dc
->xformWorld2Wnd
;
1210 release_dc_ptr( dc
);
1215 /***********************************************************************
1216 * GetTransform (GDI32.@)
1218 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1220 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1221 FIXME("stub: don't know what to do for code %x\n", unknown
);
1226 /***********************************************************************
1227 * SetWorldTransform (GDI32.@)
1229 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1232 DC
*dc
= get_dc_ptr( hdc
);
1234 if (!dc
) return FALSE
;
1235 if (!xform
) goto done
;
1237 /* Check that graphics mode is GM_ADVANCED */
1238 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1240 if (dc
->funcs
->pSetWorldTransform
)
1242 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1243 if (!ret
) goto done
;
1246 dc
->xformWorld2Wnd
= *xform
;
1247 DC_UpdateXforms( dc
);
1250 release_dc_ptr( dc
);
1255 /****************************************************************************
1256 * ModifyWorldTransform [GDI32.@]
1257 * Modifies the world transformation for a device context.
1260 * hdc [I] Handle to device context
1261 * xform [I] XFORM structure that will be used to modify the world
1263 * iMode [I] Specifies in what way to modify the world transformation
1266 * Resets the world transformation to the identity matrix.
1267 * The parameter xform is ignored.
1269 * Multiplies xform into the world transformation matrix from
1272 * Multiplies xform into the world transformation matrix from
1277 * Failure: FALSE. Use GetLastError() to determine the cause.
1279 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1283 DC
*dc
= get_dc_ptr( hdc
);
1285 /* Check for illegal parameters */
1286 if (!dc
) return FALSE
;
1287 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1289 /* Check that graphics mode is GM_ADVANCED */
1290 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1292 if (dc
->funcs
->pModifyWorldTransform
)
1294 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1295 if (!ret
) goto done
;
1301 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1302 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1303 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1304 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1305 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1306 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1308 case MWT_LEFTMULTIPLY
:
1309 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1310 &dc
->xformWorld2Wnd
);
1312 case MWT_RIGHTMULTIPLY
:
1313 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1320 DC_UpdateXforms( dc
);
1323 release_dc_ptr( dc
);
1328 /****************************************************************************
1329 * CombineTransform [GDI32.@]
1330 * Combines two transformation matrices.
1333 * xformResult [O] Stores the result of combining the two matrices
1334 * xform1 [I] Specifies the first matrix to apply
1335 * xform2 [I] Specifies the second matrix to apply
1338 * The same matrix can be passed in for more than one of the parameters.
1342 * Failure: FALSE. Use GetLastError() to determine the cause.
1344 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1345 const XFORM
*xform2
)
1349 /* Check for illegal parameters */
1350 if (!xformResult
|| !xform1
|| !xform2
)
1353 /* Create the result in a temporary XFORM, since xformResult may be
1354 * equal to xform1 or xform2 */
1355 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1356 xform1
->eM12
* xform2
->eM21
;
1357 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1358 xform1
->eM12
* xform2
->eM22
;
1359 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1360 xform1
->eM22
* xform2
->eM21
;
1361 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1362 xform1
->eM22
* xform2
->eM22
;
1363 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1364 xform1
->eDy
* xform2
->eM21
+
1366 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1367 xform1
->eDy
* xform2
->eM22
+
1370 /* Copy the result to xformResult */
1371 *xformResult
= xformTemp
;
1377 /***********************************************************************
1378 * SetDCHook (GDI32.@)
1380 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1382 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1384 DC
*dc
= get_dc_ptr( hdc
);
1386 if (!dc
) return FALSE
;
1388 if (!(dc
->flags
& DC_SAVED
))
1390 dc
->dwHookData
= dwHookData
;
1391 dc
->hookThunk
= hookProc
;
1393 release_dc_ptr( dc
);
1398 /***********************************************************************
1399 * GetDCHook (GDI32.@)
1401 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1403 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1405 DC
*dc
= get_dc_ptr( hdc
);
1409 if (proc
) *proc
= dc
->hookThunk
;
1410 ret
= dc
->dwHookData
;
1411 release_dc_ptr( dc
);
1416 /* relay function to call the 16-bit DC hook proc */
1417 static BOOL WINAPI
call_dc_hook16( HDC hdc
, WORD code
, DWORD_PTR data
, LPARAM lParam
)
1421 DC
*dc
= get_dc_ptr( hdc
);
1423 if (!dc
) return FALSE
;
1426 args
[5] = HDC_16(hdc
);
1428 args
[3] = HIWORD(data
);
1429 args
[2] = LOWORD(data
);
1430 args
[1] = HIWORD(lParam
);
1431 args
[0] = LOWORD(lParam
);
1432 WOWCallback16Ex( (DWORD
)dc
->hookProc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1434 release_dc_ptr( dc
);
1438 /***********************************************************************
1439 * SetDCHook (GDI.190)
1441 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1443 DC
*dc
= get_dc_ptr( HDC_32(hdc16
) );
1445 if (!dc
) return FALSE
;
1446 if (!(dc
->flags
& DC_SAVED
))
1448 dc
->dwHookData
= dwHookData
;
1449 dc
->hookThunk
= call_dc_hook16
;
1450 dc
->hookProc
= hookProc
;
1452 release_dc_ptr( dc
);
1457 /***********************************************************************
1458 * GetDCHook (GDI.191)
1460 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1462 HDC hdc
= HDC_32( hdc16
);
1463 DC
*dc
= get_dc_ptr( hdc
);
1467 *phookProc
= dc
->hookProc
;
1468 ret
= dc
->dwHookData
;
1469 release_dc_ptr( dc
);
1474 /***********************************************************************
1475 * SetHookFlags (GDI32.@)
1477 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1479 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1481 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1486 /* "Undocumented Windows" info is slightly confusing. */
1488 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1490 if (flags
& DCHF_INVALIDATEVISRGN
)
1491 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1492 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1493 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1495 GDI_ReleaseObj( dc
);
1499 /***********************************************************************
1500 * SetICMMode (GDI32.@)
1502 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1504 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1505 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1506 if (iEnableICM
== ICM_ON
) return 0;
1507 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1511 /***********************************************************************
1512 * GetDeviceGammaRamp (GDI32.@)
1514 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1517 DC
*dc
= get_dc_ptr( hDC
);
1521 if (dc
->funcs
->pGetDeviceGammaRamp
)
1522 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1523 release_dc_ptr( dc
);
1528 /***********************************************************************
1529 * SetDeviceGammaRamp (GDI32.@)
1531 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1534 DC
*dc
= get_dc_ptr( hDC
);
1538 if (dc
->funcs
->pSetDeviceGammaRamp
)
1539 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1540 release_dc_ptr( dc
);
1545 /***********************************************************************
1546 * GetColorSpace (GDI32.@)
1548 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1550 /*FIXME Need to to whatever GetColorSpace actually does */
1554 /***********************************************************************
1555 * CreateColorSpaceA (GDI32.@)
1557 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1563 /***********************************************************************
1564 * CreateColorSpaceW (GDI32.@)
1566 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1572 /***********************************************************************
1573 * DeleteColorSpace (GDI32.@)
1575 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1582 /***********************************************************************
1583 * SetColorSpace (GDI32.@)
1585 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1592 /***********************************************************************
1593 * GetBoundsRect (GDI32.@)
1595 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1598 DC
*dc
= get_dc_ptr( hdc
);
1600 if ( !dc
) return 0;
1602 if (rect
) *rect
= dc
->BoundsRect
;
1604 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1606 if (flags
& DCB_RESET
)
1608 dc
->BoundsRect
.left
= 0;
1609 dc
->BoundsRect
.top
= 0;
1610 dc
->BoundsRect
.right
= 0;
1611 dc
->BoundsRect
.bottom
= 0;
1612 dc
->flags
&= ~DC_BOUNDS_SET
;
1614 release_dc_ptr( dc
);
1619 /***********************************************************************
1620 * SetBoundsRect (GDI32.@)
1622 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1627 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1628 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1630 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1631 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1633 if (flags
& DCB_RESET
)
1635 dc
->BoundsRect
.left
= 0;
1636 dc
->BoundsRect
.top
= 0;
1637 dc
->BoundsRect
.right
= 0;
1638 dc
->BoundsRect
.bottom
= 0;
1639 dc
->flags
&= ~DC_BOUNDS_SET
;
1642 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1644 if (dc
->flags
& DC_BOUNDS_SET
)
1646 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1647 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1648 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1649 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1653 dc
->BoundsRect
= *rect
;
1654 dc
->flags
|= DC_BOUNDS_SET
;
1658 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1659 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1661 release_dc_ptr( dc
);
1666 /***********************************************************************
1667 * GetRelAbs (GDI32.@)
1669 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1672 DC
*dc
= get_dc_ptr( hdc
);
1675 ret
= dc
->relAbsMode
;
1676 release_dc_ptr( dc
);
1684 /***********************************************************************
1685 * GetBkMode (GDI32.@)
1687 INT WINAPI
GetBkMode( HDC hdc
)
1690 DC
* dc
= get_dc_ptr( hdc
);
1693 ret
= dc
->backgroundMode
;
1694 release_dc_ptr( dc
);
1700 /***********************************************************************
1701 * SetBkMode (GDI32.@)
1703 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1707 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1709 SetLastError(ERROR_INVALID_PARAMETER
);
1712 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1714 ret
= dc
->backgroundMode
;
1715 if (dc
->funcs
->pSetBkMode
)
1716 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1719 dc
->backgroundMode
= mode
;
1720 release_dc_ptr( dc
);
1725 /***********************************************************************
1728 INT WINAPI
GetROP2( HDC hdc
)
1731 DC
* dc
= get_dc_ptr( hdc
);
1735 release_dc_ptr( dc
);
1741 /***********************************************************************
1744 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1748 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1750 SetLastError(ERROR_INVALID_PARAMETER
);
1753 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1755 if (dc
->funcs
->pSetROP2
)
1756 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1760 release_dc_ptr( dc
);
1765 /***********************************************************************
1766 * SetRelAbs (GDI32.@)
1768 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1772 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1774 SetLastError(ERROR_INVALID_PARAMETER
);
1777 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1778 if (dc
->funcs
->pSetRelAbs
)
1779 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1782 ret
= dc
->relAbsMode
;
1783 dc
->relAbsMode
= mode
;
1785 release_dc_ptr( dc
);
1790 /***********************************************************************
1791 * GetPolyFillMode (GDI32.@)
1793 INT WINAPI
GetPolyFillMode( HDC hdc
)
1796 DC
* dc
= get_dc_ptr( hdc
);
1799 ret
= dc
->polyFillMode
;
1800 release_dc_ptr( dc
);
1806 /***********************************************************************
1807 * SetPolyFillMode (GDI32.@)
1809 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1813 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1815 SetLastError(ERROR_INVALID_PARAMETER
);
1818 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1819 ret
= dc
->polyFillMode
;
1820 if (dc
->funcs
->pSetPolyFillMode
)
1821 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1824 dc
->polyFillMode
= mode
;
1825 release_dc_ptr( dc
);
1830 /***********************************************************************
1831 * GetStretchBltMode (GDI32.@)
1833 INT WINAPI
GetStretchBltMode( HDC hdc
)
1836 DC
* dc
= get_dc_ptr( hdc
);
1839 ret
= dc
->stretchBltMode
;
1840 release_dc_ptr( dc
);
1846 /***********************************************************************
1847 * SetStretchBltMode (GDI32.@)
1849 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1853 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1855 SetLastError(ERROR_INVALID_PARAMETER
);
1858 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1859 ret
= dc
->stretchBltMode
;
1860 if (dc
->funcs
->pSetStretchBltMode
)
1861 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1864 dc
->stretchBltMode
= mode
;
1865 release_dc_ptr( dc
);
1870 /***********************************************************************
1871 * GetMapMode (GDI32.@)
1873 INT WINAPI
GetMapMode( HDC hdc
)
1876 DC
* dc
= get_dc_ptr( hdc
);
1880 release_dc_ptr( dc
);
1886 /***********************************************************************
1887 * GetBrushOrgEx (GDI32.@)
1889 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1891 DC
* dc
= get_dc_ptr( hdc
);
1892 if (!dc
) return FALSE
;
1893 pt
->x
= dc
->brushOrgX
;
1894 pt
->y
= dc
->brushOrgY
;
1895 release_dc_ptr( dc
);
1900 /***********************************************************************
1901 * GetCurrentPositionEx (GDI32.@)
1903 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1905 DC
* dc
= get_dc_ptr( hdc
);
1906 if (!dc
) return FALSE
;
1907 pt
->x
= dc
->CursPosX
;
1908 pt
->y
= dc
->CursPosY
;
1909 release_dc_ptr( dc
);
1914 /***********************************************************************
1915 * GetViewportExtEx (GDI32.@)
1917 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1919 DC
* dc
= get_dc_ptr( hdc
);
1920 if (!dc
) return FALSE
;
1921 size
->cx
= dc
->vportExtX
;
1922 size
->cy
= dc
->vportExtY
;
1923 release_dc_ptr( dc
);
1928 /***********************************************************************
1929 * GetViewportOrgEx (GDI32.@)
1931 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1933 DC
* dc
= get_dc_ptr( hdc
);
1934 if (!dc
) return FALSE
;
1935 pt
->x
= dc
->vportOrgX
;
1936 pt
->y
= dc
->vportOrgY
;
1937 release_dc_ptr( dc
);
1942 /***********************************************************************
1943 * GetWindowExtEx (GDI32.@)
1945 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1947 DC
* dc
= get_dc_ptr( hdc
);
1948 if (!dc
) return FALSE
;
1949 size
->cx
= dc
->wndExtX
;
1950 size
->cy
= dc
->wndExtY
;
1951 release_dc_ptr( dc
);
1956 /***********************************************************************
1957 * GetWindowOrgEx (GDI32.@)
1959 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1961 DC
* dc
= get_dc_ptr( hdc
);
1962 if (!dc
) return FALSE
;
1963 pt
->x
= dc
->wndOrgX
;
1964 pt
->y
= dc
->wndOrgY
;
1965 release_dc_ptr( dc
);
1970 /***********************************************************************
1971 * InquireVisRgn (GDI.131)
1973 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1976 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1979 ret
= HRGN_16(dc
->hVisRgn
);
1980 release_dc_ptr( dc
);
1986 /***********************************************************************
1987 * GetClipRgn (GDI.173)
1989 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1992 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1995 ret
= HRGN_16(dc
->hClipRgn
);
1996 release_dc_ptr( dc
);
2002 /***********************************************************************
2003 * GetLayout (GDI32.@)
2005 * Gets left->right or right->left text layout flags of a dc.
2008 DWORD WINAPI
GetLayout(HDC hdc
)
2010 DWORD layout
= GDI_ERROR
;
2012 DC
* dc
= get_dc_ptr( hdc
);
2015 layout
= dc
->layout
;
2016 release_dc_ptr( dc
);
2019 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
2024 /***********************************************************************
2025 * SetLayout (GDI32.@)
2027 * Sets left->right or right->left text layout flags of a dc.
2030 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
2032 DWORD oldlayout
= GDI_ERROR
;
2034 DC
* dc
= get_dc_ptr( hdc
);
2037 oldlayout
= dc
->layout
;
2038 dc
->layout
= layout
;
2039 release_dc_ptr( dc
);
2042 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
2047 /***********************************************************************
2048 * GetDCBrushColor (GDI32.@)
2050 * Retrieves the current brush color for the specified device
2054 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
2057 COLORREF dcBrushColor
= CLR_INVALID
;
2059 TRACE("hdc(%p)\n", hdc
);
2061 dc
= get_dc_ptr( hdc
);
2064 dcBrushColor
= dc
->dcBrushColor
;
2065 release_dc_ptr( dc
);
2068 return dcBrushColor
;
2071 /***********************************************************************
2072 * SetDCBrushColor (GDI32.@)
2074 * Sets the current device context (DC) brush color to the specified
2075 * color value. If the device cannot represent the specified color
2076 * value, the color is set to the nearest physical color.
2079 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2082 COLORREF oldClr
= CLR_INVALID
;
2084 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2086 dc
= get_dc_ptr( hdc
);
2089 if (dc
->funcs
->pSetDCBrushColor
)
2090 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2091 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2093 /* If DC_BRUSH is selected, update driver pen color */
2094 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2095 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2096 DeleteObject( hBrush
);
2099 if (crColor
!= CLR_INVALID
)
2101 oldClr
= dc
->dcBrushColor
;
2102 dc
->dcBrushColor
= crColor
;
2105 release_dc_ptr( dc
);
2111 /***********************************************************************
2112 * GetDCPenColor (GDI32.@)
2114 * Retrieves the current pen color for the specified device
2118 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2121 COLORREF dcPenColor
= CLR_INVALID
;
2123 TRACE("hdc(%p)\n", hdc
);
2125 dc
= get_dc_ptr( hdc
);
2128 dcPenColor
= dc
->dcPenColor
;
2129 release_dc_ptr( dc
);
2135 /***********************************************************************
2136 * SetDCPenColor (GDI32.@)
2138 * Sets the current device context (DC) pen color to the specified
2139 * color value. If the device cannot represent the specified color
2140 * value, the color is set to the nearest physical color.
2143 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2146 COLORREF oldClr
= CLR_INVALID
;
2148 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2150 dc
= get_dc_ptr( hdc
);
2153 if (dc
->funcs
->pSetDCPenColor
)
2154 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2155 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2157 /* If DC_PEN is selected, update the driver pen color */
2158 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2159 HPEN hPen
= CreatePenIndirect( &logpen
);
2160 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2161 DeleteObject( hPen
);
2164 if (crColor
!= CLR_INVALID
)
2166 oldClr
= dc
->dcPenColor
;
2167 dc
->dcPenColor
= crColor
;
2170 release_dc_ptr( dc
);
2176 /***********************************************************************
2177 * CancelDC (GDI32.@)
2179 BOOL WINAPI
CancelDC(HDC hdc
)
2185 /***********************************************************************
2186 * SetVirtualResolution (GDI32.@)
2188 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2190 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2192 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);
2196 /*******************************************************************
2197 * GetMiterLimit [GDI32.@]
2201 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2206 TRACE("(%p,%p)\n", hdc
, peLimit
);
2208 dc
= get_dc_ptr( hdc
);
2212 *peLimit
= dc
->miterLimit
;
2214 release_dc_ptr( dc
);
2220 /*******************************************************************
2221 * SetMiterLimit [GDI32.@]
2225 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2230 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2232 dc
= get_dc_ptr( hdc
);
2236 *peOldLimit
= dc
->miterLimit
;
2237 dc
->miterLimit
= eNewLimit
;
2238 release_dc_ptr( dc
);
2244 /*******************************************************************
2245 * GdiIsMetaPrintDC [GDI32.@]
2247 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2253 /*******************************************************************
2254 * GdiIsMetaFileDC [GDI32.@]
2256 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2260 switch( GetObjectType( hdc
) )
2269 /*******************************************************************
2270 * GdiIsPlayMetafileDC [GDI32.@]
2272 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)