2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
40 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
42 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
);
44 static const struct gdi_obj_funcs dc_funcs
=
46 NULL
, /* pSelectObject */
47 NULL
, /* pGetObjectA */
48 NULL
, /* pGetObjectW */
49 NULL
, /* pUnrealizeObject */
50 DC_DeleteObject
/* pDeleteObject */
54 static inline DC
*get_dc_obj( HDC hdc
)
56 DC
*dc
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
59 if ((GDIMAGIC(dc
->header
.wMagic
) != DC_MAGIC
) &&
60 (GDIMAGIC(dc
->header
.wMagic
) != MEMORY_DC_MAGIC
) &&
61 (GDIMAGIC(dc
->header
.wMagic
) != METAFILE_DC_MAGIC
) &&
62 (GDIMAGIC(dc
->header
.wMagic
) != ENHMETAFILE_DC_MAGIC
))
64 GDI_ReleaseObj( hdc
);
65 SetLastError( ERROR_INVALID_HANDLE
);
72 /***********************************************************************
75 DC
*alloc_dc_ptr( const DC_FUNCTIONS
*funcs
, WORD magic
)
80 if (!(dc
= GDI_AllocObject( sizeof(*dc
), magic
, (HGDIOBJ
*)&hdc
, &dc_funcs
))) return NULL
;
85 dc
->thread
= GetCurrentThreadId();
101 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
106 dc
->hMetaClipRgn
= 0;
108 dc
->hPen
= GetStockObject( BLACK_PEN
);
109 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
110 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
113 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
115 dc
->ROPmode
= R2_COPYPEN
;
116 dc
->polyFillMode
= ALTERNATE
;
117 dc
->stretchBltMode
= BLACKONWHITE
;
118 dc
->relAbsMode
= ABSOLUTE
;
119 dc
->backgroundMode
= OPAQUE
;
120 dc
->backgroundColor
= RGB( 255, 255, 255 );
121 dc
->dcBrushColor
= RGB( 255, 255, 255 );
122 dc
->dcPenColor
= RGB( 0, 0, 0 );
123 dc
->textColor
= RGB( 0, 0, 0 );
126 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
130 dc
->MapMode
= MM_TEXT
;
131 dc
->GraphicsMode
= GM_COMPATIBLE
;
132 dc
->pAbortProc
= NULL
;
135 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
136 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
137 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
138 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
139 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
140 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
141 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
142 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
143 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
144 dc
->vport2WorldValid
= TRUE
;
145 dc
->BoundsRect
.left
= 0;
146 dc
->BoundsRect
.top
= 0;
147 dc
->BoundsRect
.right
= 0;
148 dc
->BoundsRect
.bottom
= 0;
149 dc
->saved_visrgn
= NULL
;
150 PATH_InitGdiPath(&dc
->path
);
151 GDI_ReleaseObj( dc
->hSelf
);
157 /***********************************************************************
160 BOOL
free_dc_ptr( DC
*dc
)
162 assert( dc
->refcount
== 1 );
163 /* grab the gdi lock again */
164 if (!GDI_GetObjPtr( dc
->hSelf
, MAGIC_DONTCARE
)) return FALSE
; /* shouldn't happen */
165 return GDI_FreeObject( dc
->hSelf
, dc
);
169 /***********************************************************************
172 * Retrieve a DC pointer but release the GDI lock.
174 DC
*get_dc_ptr( HDC hdc
)
176 DC
*dc
= get_dc_obj( hdc
);
177 if (!dc
) return NULL
;
179 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
181 dc
->thread
= GetCurrentThreadId();
183 else if (dc
->thread
!= GetCurrentThreadId())
185 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
186 GDI_ReleaseObj( hdc
);
189 else InterlockedIncrement( &dc
->refcount
);
191 GDI_ReleaseObj( hdc
);
196 /***********************************************************************
199 void release_dc_ptr( DC
*dc
)
204 ref
= InterlockedDecrement( &dc
->refcount
);
206 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
210 /***********************************************************************
213 * Make sure the DC vis region is up to date.
214 * This function may call up to USER so the GDI lock should _not_
215 * be held when calling it.
217 void update_dc( DC
*dc
)
219 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookThunk
)
220 dc
->hookThunk( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
224 /***********************************************************************
227 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
229 GDI_ReleaseObj( handle
);
230 return DeleteDC( handle
);
234 /***********************************************************************
237 * Setup device-specific DC values for a newly created DC.
239 void DC_InitDC( DC
* dc
)
241 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
242 SetTextColor( dc
->hSelf
, dc
->textColor
);
243 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
244 SelectObject( dc
->hSelf
, dc
->hPen
);
245 SelectObject( dc
->hSelf
, dc
->hBrush
);
246 SelectObject( dc
->hSelf
, dc
->hFont
);
247 CLIPPING_UpdateGCRegion( dc
);
251 /***********************************************************************
254 * Computes the inverse of the transformation xformSrc and stores it to
255 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
258 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
262 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
263 xformSrc
->eM12
*xformSrc
->eM21
;
264 if (determinant
> -1e-12 && determinant
< 1e-12)
267 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
268 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
269 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
270 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
271 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
272 xformSrc
->eDy
* xformDest
->eM21
;
273 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
274 xformSrc
->eDy
* xformDest
->eM22
;
280 /***********************************************************************
283 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
284 * fields of the specified DC by creating a transformation that
285 * represents the current mapping mode and combining it with the DC's
286 * world transform. This function should be called whenever the
287 * parameters associated with the mapping mode (window and viewport
288 * extents and origins) or the world transform change.
290 void DC_UpdateXforms( DC
*dc
)
292 XFORM xformWnd2Vport
, oldworld2vport
;
293 FLOAT scaleX
, scaleY
;
295 /* Construct a transformation to do the window-to-viewport conversion */
296 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
297 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
298 xformWnd2Vport
.eM11
= scaleX
;
299 xformWnd2Vport
.eM12
= 0.0;
300 xformWnd2Vport
.eM21
= 0.0;
301 xformWnd2Vport
.eM22
= scaleY
;
302 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
303 scaleX
* (FLOAT
)dc
->wndOrgX
;
304 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
305 scaleY
* (FLOAT
)dc
->wndOrgY
;
307 oldworld2vport
= dc
->xformWorld2Vport
;
308 /* Combine with the world transformation */
309 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
312 /* Create inverse of world-to-viewport transformation */
313 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
314 &dc
->xformVport2World
);
316 /* Reselect the font and pen back into the dc so that the size
318 if (oldworld2vport
.eM11
!= dc
->xformWorld2Vport
.eM11
||
319 oldworld2vport
.eM22
!= dc
->xformWorld2Vport
.eM22
)
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
);
789 else if (hdc
) return 0;
791 if (!funcs
&& !(funcs
= DRIVER_load_driver( displayW
))) return 0;
793 if (!(dc
= alloc_dc_ptr( funcs
, MEMORY_DC_MAGIC
))) goto error
;
795 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
797 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
798 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
800 /* Copy the driver-specific physical device info into
801 * the new DC. The driver may use this read-only info
802 * while creating the compatible DC below. */
803 dc
->physDev
= physDev
;
806 if (dc
->funcs
->pCreateDC
&&
807 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
809 WARN("creation aborted by device\n");
814 release_dc_ptr( dc
);
818 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
819 if (dc
) free_dc_ptr( dc
);
820 DRIVER_release_driver( funcs
);
825 /***********************************************************************
828 BOOL WINAPI
DeleteDC( HDC hdc
)
830 const DC_FUNCTIONS
*funcs
= NULL
;
837 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
838 if (dc
->refcount
!= 1)
840 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
841 release_dc_ptr( dc
);
845 /* Call hook procedure to check whether is it OK to delete this DC */
846 if (dc
->hookThunk
&& !dc
->hookThunk( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
848 release_dc_ptr( dc
);
852 while (dc
->saveLevel
)
855 HDC hdcs
= dc
->saved_dc
;
856 if (!(dcs
= get_dc_ptr( hdcs
))) break;
857 dc
->saved_dc
= dcs
->saved_dc
;
859 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
860 if (dcs
->hMetaRgn
) DeleteObject( dcs
->hMetaRgn
);
861 if (dcs
->hMetaClipRgn
) DeleteObject( dcs
->hMetaClipRgn
);
862 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
863 PATH_DestroyGdiPath(&dcs
->path
);
867 if (!(dc
->flags
& DC_SAVED
))
869 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
870 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
871 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
872 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
874 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
878 while (dc
->saved_visrgn
)
880 struct saved_visrgn
*next
= dc
->saved_visrgn
->next
;
881 DeleteObject( dc
->saved_visrgn
->hrgn
);
882 HeapFree( GetProcessHeap(), 0, dc
->saved_visrgn
);
883 dc
->saved_visrgn
= next
;
885 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
886 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
887 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
888 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
889 PATH_DestroyGdiPath(&dc
->path
);
892 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
897 /***********************************************************************
900 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
905 if ((dc
= get_dc_ptr( hdc
)))
907 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
908 release_dc_ptr( dc
);
914 /***********************************************************************
917 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
922 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
923 else devmodeW
= NULL
;
925 ret
= ResetDCW(hdc
, devmodeW
);
927 HeapFree(GetProcessHeap(), 0, devmodeW
);
932 /***********************************************************************
933 * GetDeviceCaps (GDI32.@)
935 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
940 if ((dc
= get_dc_ptr( hdc
)))
942 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
943 else switch(cap
) /* return meaningful values for some entries */
945 case HORZRES
: ret
= 640; break;
946 case VERTRES
: ret
= 480; break;
947 case BITSPIXEL
: ret
= 1; break;
948 case PLANES
: ret
= 1; break;
949 case NUMCOLORS
: ret
= 2; break;
950 case ASPECTX
: ret
= 36; break;
951 case ASPECTY
: ret
= 36; break;
952 case ASPECTXY
: ret
= 51; break;
953 case LOGPIXELSX
: ret
= 72; break;
954 case LOGPIXELSY
: ret
= 72; break;
955 case SIZEPALETTE
: ret
= 2; break;
957 release_dc_ptr( dc
);
963 /***********************************************************************
964 * GetBkColor (GDI32.@)
966 COLORREF WINAPI
GetBkColor( HDC hdc
)
969 DC
* dc
= get_dc_ptr( hdc
);
972 ret
= dc
->backgroundColor
;
973 release_dc_ptr( dc
);
979 /***********************************************************************
980 * SetBkColor (GDI32.@)
982 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
985 DC
* dc
= get_dc_ptr( hdc
);
987 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
989 if (!dc
) return CLR_INVALID
;
990 oldColor
= dc
->backgroundColor
;
991 if (dc
->funcs
->pSetBkColor
)
993 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
994 if (color
== CLR_INVALID
) /* don't change it */
997 oldColor
= CLR_INVALID
;
1000 dc
->backgroundColor
= color
;
1001 release_dc_ptr( dc
);
1006 /***********************************************************************
1007 * GetTextColor (GDI32.@)
1009 COLORREF WINAPI
GetTextColor( HDC hdc
)
1012 DC
* dc
= get_dc_ptr( hdc
);
1015 ret
= dc
->textColor
;
1016 release_dc_ptr( dc
);
1022 /***********************************************************************
1023 * SetTextColor (GDI32.@)
1025 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
1028 DC
* dc
= get_dc_ptr( hdc
);
1030 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
1032 if (!dc
) return CLR_INVALID
;
1033 oldColor
= dc
->textColor
;
1034 if (dc
->funcs
->pSetTextColor
)
1036 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
1037 if (color
== CLR_INVALID
) /* don't change it */
1040 oldColor
= CLR_INVALID
;
1043 dc
->textColor
= color
;
1044 release_dc_ptr( dc
);
1049 /***********************************************************************
1050 * GetTextAlign (GDI32.@)
1052 UINT WINAPI
GetTextAlign( HDC hdc
)
1055 DC
* dc
= get_dc_ptr( hdc
);
1058 ret
= dc
->textAlign
;
1059 release_dc_ptr( dc
);
1065 /***********************************************************************
1066 * SetTextAlign (GDI32.@)
1068 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1071 DC
*dc
= get_dc_ptr( hdc
);
1073 TRACE("hdc=%p align=%d\n", hdc
, align
);
1075 if (!dc
) return 0x0;
1076 ret
= dc
->textAlign
;
1077 if (dc
->funcs
->pSetTextAlign
)
1078 if (!dc
->funcs
->pSetTextAlign(dc
->physDev
, align
))
1080 if (ret
!= GDI_ERROR
)
1081 dc
->textAlign
= align
;
1082 release_dc_ptr( dc
);
1086 /***********************************************************************
1087 * GetDCOrgEx (GDI32.@)
1089 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1093 if (!lpp
) return FALSE
;
1094 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1096 lpp
->x
= lpp
->y
= 0;
1097 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
1098 release_dc_ptr( dc
);
1103 /***********************************************************************
1104 * SetDCOrg (GDI.117)
1106 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
1109 HDC hdc
= HDC_32( hdc16
);
1110 DC
*dc
= get_dc_ptr( hdc
);
1112 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
1113 release_dc_ptr( dc
);
1118 /***********************************************************************
1119 * GetGraphicsMode (GDI32.@)
1121 INT WINAPI
GetGraphicsMode( HDC hdc
)
1124 DC
* dc
= get_dc_ptr( hdc
);
1127 ret
= dc
->GraphicsMode
;
1128 release_dc_ptr( dc
);
1134 /***********************************************************************
1135 * SetGraphicsMode (GDI32.@)
1137 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1140 DC
*dc
= get_dc_ptr( hdc
);
1142 /* One would think that setting the graphics mode to GM_COMPATIBLE
1143 * would also reset the world transformation matrix to the unity
1144 * matrix. However, in Windows, this is not the case. This doesn't
1145 * make a lot of sense to me, but that's the way it is.
1148 if ((mode
> 0) && (mode
<= GM_LAST
))
1150 ret
= dc
->GraphicsMode
;
1151 dc
->GraphicsMode
= mode
;
1153 release_dc_ptr( dc
);
1158 /***********************************************************************
1159 * GetArcDirection (GDI32.@)
1161 INT WINAPI
GetArcDirection( HDC hdc
)
1164 DC
* dc
= get_dc_ptr( hdc
);
1167 ret
= dc
->ArcDirection
;
1168 release_dc_ptr( dc
);
1174 /***********************************************************************
1175 * SetArcDirection (GDI32.@)
1177 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1180 INT nOldDirection
= 0;
1182 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1184 SetLastError(ERROR_INVALID_PARAMETER
);
1188 if ((dc
= get_dc_ptr( hdc
)))
1190 if (dc
->funcs
->pSetArcDirection
)
1192 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1194 nOldDirection
= dc
->ArcDirection
;
1195 dc
->ArcDirection
= nDirection
;
1196 release_dc_ptr( dc
);
1198 return nOldDirection
;
1202 /***********************************************************************
1203 * GetWorldTransform (GDI32.@)
1205 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1208 if (!xform
) return FALSE
;
1209 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1210 *xform
= dc
->xformWorld2Wnd
;
1211 release_dc_ptr( dc
);
1216 /***********************************************************************
1217 * GetTransform (GDI32.@)
1219 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1221 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1222 FIXME("stub: don't know what to do for code %x\n", unknown
);
1227 /***********************************************************************
1228 * SetWorldTransform (GDI32.@)
1230 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1233 DC
*dc
= get_dc_ptr( hdc
);
1235 if (!dc
) return FALSE
;
1236 if (!xform
) goto done
;
1238 /* Check that graphics mode is GM_ADVANCED */
1239 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1241 if (dc
->funcs
->pSetWorldTransform
)
1243 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1244 if (!ret
) goto done
;
1247 dc
->xformWorld2Wnd
= *xform
;
1248 DC_UpdateXforms( dc
);
1251 release_dc_ptr( dc
);
1256 /****************************************************************************
1257 * ModifyWorldTransform [GDI32.@]
1258 * Modifies the world transformation for a device context.
1261 * hdc [I] Handle to device context
1262 * xform [I] XFORM structure that will be used to modify the world
1264 * iMode [I] Specifies in what way to modify the world transformation
1267 * Resets the world transformation to the identity matrix.
1268 * The parameter xform is ignored.
1270 * Multiplies xform into the world transformation matrix from
1273 * Multiplies xform into the world transformation matrix from
1278 * Failure: FALSE. Use GetLastError() to determine the cause.
1280 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1284 DC
*dc
= get_dc_ptr( hdc
);
1286 /* Check for illegal parameters */
1287 if (!dc
) return FALSE
;
1288 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1290 /* Check that graphics mode is GM_ADVANCED */
1291 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1293 if (dc
->funcs
->pModifyWorldTransform
)
1295 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1296 if (!ret
) goto done
;
1302 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1303 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1304 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1305 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1306 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1307 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1309 case MWT_LEFTMULTIPLY
:
1310 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1311 &dc
->xformWorld2Wnd
);
1313 case MWT_RIGHTMULTIPLY
:
1314 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1321 DC_UpdateXforms( dc
);
1324 release_dc_ptr( dc
);
1329 /****************************************************************************
1330 * CombineTransform [GDI32.@]
1331 * Combines two transformation matrices.
1334 * xformResult [O] Stores the result of combining the two matrices
1335 * xform1 [I] Specifies the first matrix to apply
1336 * xform2 [I] Specifies the second matrix to apply
1339 * The same matrix can be passed in for more than one of the parameters.
1343 * Failure: FALSE. Use GetLastError() to determine the cause.
1345 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1346 const XFORM
*xform2
)
1350 /* Check for illegal parameters */
1351 if (!xformResult
|| !xform1
|| !xform2
)
1354 /* Create the result in a temporary XFORM, since xformResult may be
1355 * equal to xform1 or xform2 */
1356 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1357 xform1
->eM12
* xform2
->eM21
;
1358 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1359 xform1
->eM12
* xform2
->eM22
;
1360 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1361 xform1
->eM22
* xform2
->eM21
;
1362 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1363 xform1
->eM22
* xform2
->eM22
;
1364 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1365 xform1
->eDy
* xform2
->eM21
+
1367 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1368 xform1
->eDy
* xform2
->eM22
+
1371 /* Copy the result to xformResult */
1372 *xformResult
= xformTemp
;
1378 /***********************************************************************
1379 * SetDCHook (GDI32.@)
1381 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1383 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1385 DC
*dc
= get_dc_ptr( hdc
);
1387 if (!dc
) return FALSE
;
1389 if (!(dc
->flags
& DC_SAVED
))
1391 dc
->dwHookData
= dwHookData
;
1392 dc
->hookThunk
= hookProc
;
1394 release_dc_ptr( dc
);
1399 /***********************************************************************
1400 * GetDCHook (GDI32.@)
1402 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1404 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1406 DC
*dc
= get_dc_ptr( hdc
);
1410 if (proc
) *proc
= dc
->hookThunk
;
1411 ret
= dc
->dwHookData
;
1412 release_dc_ptr( dc
);
1417 /* relay function to call the 16-bit DC hook proc */
1418 static BOOL WINAPI
call_dc_hook16( HDC hdc
, WORD code
, DWORD_PTR data
, LPARAM lParam
)
1422 DC
*dc
= get_dc_ptr( hdc
);
1424 if (!dc
) return FALSE
;
1427 args
[5] = HDC_16(hdc
);
1429 args
[3] = HIWORD(data
);
1430 args
[2] = LOWORD(data
);
1431 args
[1] = HIWORD(lParam
);
1432 args
[0] = LOWORD(lParam
);
1433 WOWCallback16Ex( (DWORD
)dc
->hookProc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1435 release_dc_ptr( dc
);
1439 /***********************************************************************
1440 * SetDCHook (GDI.190)
1442 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1444 DC
*dc
= get_dc_ptr( HDC_32(hdc16
) );
1446 if (!dc
) return FALSE
;
1447 if (!(dc
->flags
& DC_SAVED
))
1449 dc
->dwHookData
= dwHookData
;
1450 dc
->hookThunk
= call_dc_hook16
;
1451 dc
->hookProc
= hookProc
;
1453 release_dc_ptr( dc
);
1458 /***********************************************************************
1459 * GetDCHook (GDI.191)
1461 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1463 HDC hdc
= HDC_32( hdc16
);
1464 DC
*dc
= get_dc_ptr( hdc
);
1468 *phookProc
= dc
->hookProc
;
1469 ret
= dc
->dwHookData
;
1470 release_dc_ptr( dc
);
1475 /***********************************************************************
1476 * SetHookFlags (GDI32.@)
1478 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1480 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1482 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1487 /* "Undocumented Windows" info is slightly confusing. */
1489 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1491 if (flags
& DCHF_INVALIDATEVISRGN
)
1492 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1493 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1494 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1496 GDI_ReleaseObj( dc
);
1500 /***********************************************************************
1501 * SetICMMode (GDI32.@)
1503 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1505 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1506 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1507 if (iEnableICM
== ICM_ON
) return 0;
1508 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1512 /***********************************************************************
1513 * GetDeviceGammaRamp (GDI32.@)
1515 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1518 DC
*dc
= get_dc_ptr( hDC
);
1522 if (dc
->funcs
->pGetDeviceGammaRamp
)
1523 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1524 release_dc_ptr( dc
);
1529 /***********************************************************************
1530 * SetDeviceGammaRamp (GDI32.@)
1532 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1535 DC
*dc
= get_dc_ptr( hDC
);
1539 if (dc
->funcs
->pSetDeviceGammaRamp
)
1540 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1541 release_dc_ptr( dc
);
1546 /***********************************************************************
1547 * GetColorSpace (GDI32.@)
1549 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1551 /*FIXME Need to to whatever GetColorSpace actually does */
1555 /***********************************************************************
1556 * CreateColorSpaceA (GDI32.@)
1558 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1564 /***********************************************************************
1565 * CreateColorSpaceW (GDI32.@)
1567 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1573 /***********************************************************************
1574 * DeleteColorSpace (GDI32.@)
1576 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1583 /***********************************************************************
1584 * SetColorSpace (GDI32.@)
1586 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1593 /***********************************************************************
1594 * GetBoundsRect (GDI32.@)
1596 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1599 DC
*dc
= get_dc_ptr( hdc
);
1601 if ( !dc
) return 0;
1603 if (rect
) *rect
= dc
->BoundsRect
;
1605 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1607 if (flags
& DCB_RESET
)
1609 dc
->BoundsRect
.left
= 0;
1610 dc
->BoundsRect
.top
= 0;
1611 dc
->BoundsRect
.right
= 0;
1612 dc
->BoundsRect
.bottom
= 0;
1613 dc
->flags
&= ~DC_BOUNDS_SET
;
1615 release_dc_ptr( dc
);
1620 /***********************************************************************
1621 * SetBoundsRect (GDI32.@)
1623 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1628 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1629 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1631 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1632 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1634 if (flags
& DCB_RESET
)
1636 dc
->BoundsRect
.left
= 0;
1637 dc
->BoundsRect
.top
= 0;
1638 dc
->BoundsRect
.right
= 0;
1639 dc
->BoundsRect
.bottom
= 0;
1640 dc
->flags
&= ~DC_BOUNDS_SET
;
1643 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1645 if (dc
->flags
& DC_BOUNDS_SET
)
1647 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1648 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1649 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1650 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1654 dc
->BoundsRect
= *rect
;
1655 dc
->flags
|= DC_BOUNDS_SET
;
1659 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1660 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1662 release_dc_ptr( dc
);
1667 /***********************************************************************
1668 * GetRelAbs (GDI32.@)
1670 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1673 DC
*dc
= get_dc_ptr( hdc
);
1676 ret
= dc
->relAbsMode
;
1677 release_dc_ptr( dc
);
1685 /***********************************************************************
1686 * GetBkMode (GDI32.@)
1688 INT WINAPI
GetBkMode( HDC hdc
)
1691 DC
* dc
= get_dc_ptr( hdc
);
1694 ret
= dc
->backgroundMode
;
1695 release_dc_ptr( dc
);
1701 /***********************************************************************
1702 * SetBkMode (GDI32.@)
1704 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1708 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1710 SetLastError(ERROR_INVALID_PARAMETER
);
1713 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1715 ret
= dc
->backgroundMode
;
1716 if (dc
->funcs
->pSetBkMode
)
1717 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1720 dc
->backgroundMode
= mode
;
1721 release_dc_ptr( dc
);
1726 /***********************************************************************
1729 INT WINAPI
GetROP2( HDC hdc
)
1732 DC
* dc
= get_dc_ptr( hdc
);
1736 release_dc_ptr( dc
);
1742 /***********************************************************************
1745 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1749 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1751 SetLastError(ERROR_INVALID_PARAMETER
);
1754 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1756 if (dc
->funcs
->pSetROP2
)
1757 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1761 release_dc_ptr( dc
);
1766 /***********************************************************************
1767 * SetRelAbs (GDI32.@)
1769 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1773 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1775 SetLastError(ERROR_INVALID_PARAMETER
);
1778 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1779 if (dc
->funcs
->pSetRelAbs
)
1780 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1783 ret
= dc
->relAbsMode
;
1784 dc
->relAbsMode
= mode
;
1786 release_dc_ptr( dc
);
1791 /***********************************************************************
1792 * GetPolyFillMode (GDI32.@)
1794 INT WINAPI
GetPolyFillMode( HDC hdc
)
1797 DC
* dc
= get_dc_ptr( hdc
);
1800 ret
= dc
->polyFillMode
;
1801 release_dc_ptr( dc
);
1807 /***********************************************************************
1808 * SetPolyFillMode (GDI32.@)
1810 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1814 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1816 SetLastError(ERROR_INVALID_PARAMETER
);
1819 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1820 ret
= dc
->polyFillMode
;
1821 if (dc
->funcs
->pSetPolyFillMode
)
1822 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1825 dc
->polyFillMode
= mode
;
1826 release_dc_ptr( dc
);
1831 /***********************************************************************
1832 * GetStretchBltMode (GDI32.@)
1834 INT WINAPI
GetStretchBltMode( HDC hdc
)
1837 DC
* dc
= get_dc_ptr( hdc
);
1840 ret
= dc
->stretchBltMode
;
1841 release_dc_ptr( dc
);
1847 /***********************************************************************
1848 * SetStretchBltMode (GDI32.@)
1850 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1854 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1856 SetLastError(ERROR_INVALID_PARAMETER
);
1859 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1860 ret
= dc
->stretchBltMode
;
1861 if (dc
->funcs
->pSetStretchBltMode
)
1862 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1865 dc
->stretchBltMode
= mode
;
1866 release_dc_ptr( dc
);
1871 /***********************************************************************
1872 * GetMapMode (GDI32.@)
1874 INT WINAPI
GetMapMode( HDC hdc
)
1877 DC
* dc
= get_dc_ptr( hdc
);
1881 release_dc_ptr( dc
);
1887 /***********************************************************************
1888 * GetBrushOrgEx (GDI32.@)
1890 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1892 DC
* dc
= get_dc_ptr( hdc
);
1893 if (!dc
) return FALSE
;
1894 pt
->x
= dc
->brushOrgX
;
1895 pt
->y
= dc
->brushOrgY
;
1896 release_dc_ptr( dc
);
1901 /***********************************************************************
1902 * GetCurrentPositionEx (GDI32.@)
1904 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1906 DC
* dc
= get_dc_ptr( hdc
);
1907 if (!dc
) return FALSE
;
1908 pt
->x
= dc
->CursPosX
;
1909 pt
->y
= dc
->CursPosY
;
1910 release_dc_ptr( dc
);
1915 /***********************************************************************
1916 * GetViewportExtEx (GDI32.@)
1918 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1920 DC
* dc
= get_dc_ptr( hdc
);
1921 if (!dc
) return FALSE
;
1922 size
->cx
= dc
->vportExtX
;
1923 size
->cy
= dc
->vportExtY
;
1924 release_dc_ptr( dc
);
1929 /***********************************************************************
1930 * GetViewportOrgEx (GDI32.@)
1932 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1934 DC
* dc
= get_dc_ptr( hdc
);
1935 if (!dc
) return FALSE
;
1936 pt
->x
= dc
->vportOrgX
;
1937 pt
->y
= dc
->vportOrgY
;
1938 release_dc_ptr( dc
);
1943 /***********************************************************************
1944 * GetWindowExtEx (GDI32.@)
1946 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1948 DC
* dc
= get_dc_ptr( hdc
);
1949 if (!dc
) return FALSE
;
1950 size
->cx
= dc
->wndExtX
;
1951 size
->cy
= dc
->wndExtY
;
1952 release_dc_ptr( dc
);
1957 /***********************************************************************
1958 * GetWindowOrgEx (GDI32.@)
1960 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1962 DC
* dc
= get_dc_ptr( hdc
);
1963 if (!dc
) return FALSE
;
1964 pt
->x
= dc
->wndOrgX
;
1965 pt
->y
= dc
->wndOrgY
;
1966 release_dc_ptr( dc
);
1971 /***********************************************************************
1972 * InquireVisRgn (GDI.131)
1974 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1977 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1980 ret
= HRGN_16(dc
->hVisRgn
);
1981 release_dc_ptr( dc
);
1987 /***********************************************************************
1988 * GetClipRgn (GDI.173)
1990 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1993 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1996 ret
= HRGN_16(dc
->hClipRgn
);
1997 release_dc_ptr( dc
);
2003 /***********************************************************************
2004 * GetLayout (GDI32.@)
2006 * Gets left->right or right->left text layout flags of a dc.
2009 DWORD WINAPI
GetLayout(HDC hdc
)
2011 DWORD layout
= GDI_ERROR
;
2013 DC
* dc
= get_dc_ptr( hdc
);
2016 layout
= dc
->layout
;
2017 release_dc_ptr( dc
);
2020 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
2025 /***********************************************************************
2026 * SetLayout (GDI32.@)
2028 * Sets left->right or right->left text layout flags of a dc.
2031 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
2033 DWORD oldlayout
= GDI_ERROR
;
2035 DC
* dc
= get_dc_ptr( hdc
);
2038 oldlayout
= dc
->layout
;
2039 dc
->layout
= layout
;
2040 release_dc_ptr( dc
);
2043 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
2048 /***********************************************************************
2049 * GetDCBrushColor (GDI32.@)
2051 * Retrieves the current brush color for the specified device
2055 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
2058 COLORREF dcBrushColor
= CLR_INVALID
;
2060 TRACE("hdc(%p)\n", hdc
);
2062 dc
= get_dc_ptr( hdc
);
2065 dcBrushColor
= dc
->dcBrushColor
;
2066 release_dc_ptr( dc
);
2069 return dcBrushColor
;
2072 /***********************************************************************
2073 * SetDCBrushColor (GDI32.@)
2075 * Sets the current device context (DC) brush color to the specified
2076 * color value. If the device cannot represent the specified color
2077 * value, the color is set to the nearest physical color.
2080 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2083 COLORREF oldClr
= CLR_INVALID
;
2085 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2087 dc
= get_dc_ptr( hdc
);
2090 if (dc
->funcs
->pSetDCBrushColor
)
2091 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2092 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2094 /* If DC_BRUSH is selected, update driver pen color */
2095 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2096 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2097 DeleteObject( hBrush
);
2100 if (crColor
!= CLR_INVALID
)
2102 oldClr
= dc
->dcBrushColor
;
2103 dc
->dcBrushColor
= crColor
;
2106 release_dc_ptr( dc
);
2112 /***********************************************************************
2113 * GetDCPenColor (GDI32.@)
2115 * Retrieves the current pen color for the specified device
2119 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2122 COLORREF dcPenColor
= CLR_INVALID
;
2124 TRACE("hdc(%p)\n", hdc
);
2126 dc
= get_dc_ptr( hdc
);
2129 dcPenColor
= dc
->dcPenColor
;
2130 release_dc_ptr( dc
);
2136 /***********************************************************************
2137 * SetDCPenColor (GDI32.@)
2139 * Sets the current device context (DC) pen color to the specified
2140 * color value. If the device cannot represent the specified color
2141 * value, the color is set to the nearest physical color.
2144 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2147 COLORREF oldClr
= CLR_INVALID
;
2149 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2151 dc
= get_dc_ptr( hdc
);
2154 if (dc
->funcs
->pSetDCPenColor
)
2155 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2156 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2158 /* If DC_PEN is selected, update the driver pen color */
2159 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2160 HPEN hPen
= CreatePenIndirect( &logpen
);
2161 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2162 DeleteObject( hPen
);
2165 if (crColor
!= CLR_INVALID
)
2167 oldClr
= dc
->dcPenColor
;
2168 dc
->dcPenColor
= crColor
;
2171 release_dc_ptr( dc
);
2177 /***********************************************************************
2178 * CancelDC (GDI32.@)
2180 BOOL WINAPI
CancelDC(HDC hdc
)
2186 /***********************************************************************
2187 * SetVirtualResolution (GDI32.@)
2189 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2191 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2193 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);
2197 /*******************************************************************
2198 * GetMiterLimit [GDI32.@]
2202 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2207 TRACE("(%p,%p)\n", hdc
, peLimit
);
2209 dc
= get_dc_ptr( hdc
);
2213 *peLimit
= dc
->miterLimit
;
2215 release_dc_ptr( dc
);
2221 /*******************************************************************
2222 * SetMiterLimit [GDI32.@]
2226 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2231 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2233 dc
= get_dc_ptr( hdc
);
2237 *peOldLimit
= dc
->miterLimit
;
2238 dc
->miterLimit
= eNewLimit
;
2239 release_dc_ptr( dc
);
2245 /*******************************************************************
2246 * GdiIsMetaPrintDC [GDI32.@]
2248 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2254 /*******************************************************************
2255 * GdiIsMetaFileDC [GDI32.@]
2257 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2261 switch( GetObjectType( hdc
) )
2270 /*******************************************************************
2271 * GdiIsPlayMetafileDC [GDI32.@]
2273 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)