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 double scaleX
, scaleY
;
295 /* Construct a transformation to do the window-to-viewport conversion */
296 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
297 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
298 xformWnd2Vport
.eM11
= scaleX
;
299 xformWnd2Vport
.eM12
= 0.0;
300 xformWnd2Vport
.eM21
= 0.0;
301 xformWnd2Vport
.eM22
= scaleY
;
302 xformWnd2Vport
.eDx
= (double)dc
->vportOrgX
-
303 scaleX
* (double)dc
->wndOrgX
;
304 xformWnd2Vport
.eDy
= (double)dc
->vportOrgY
-
305 scaleY
* (double)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 (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
319 !GdiIsMetaFileDC(dc
->hSelf
))
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 static HDC
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 static void 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 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1242 xform
->eM11
, xform
->eM12
, xform
->eM21
, xform
->eM22
, xform
->eDx
, xform
->eDy
);
1244 if (dc
->funcs
->pSetWorldTransform
)
1246 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1247 if (!ret
) goto done
;
1250 dc
->xformWorld2Wnd
= *xform
;
1251 DC_UpdateXforms( dc
);
1254 release_dc_ptr( dc
);
1259 /****************************************************************************
1260 * ModifyWorldTransform [GDI32.@]
1261 * Modifies the world transformation for a device context.
1264 * hdc [I] Handle to device context
1265 * xform [I] XFORM structure that will be used to modify the world
1267 * iMode [I] Specifies in what way to modify the world transformation
1270 * Resets the world transformation to the identity matrix.
1271 * The parameter xform is ignored.
1273 * Multiplies xform into the world transformation matrix from
1276 * Multiplies xform into the world transformation matrix from
1281 * Failure: FALSE. Use GetLastError() to determine the cause.
1283 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1287 DC
*dc
= get_dc_ptr( hdc
);
1289 /* Check for illegal parameters */
1290 if (!dc
) return FALSE
;
1291 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1293 /* Check that graphics mode is GM_ADVANCED */
1294 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1296 if (dc
->funcs
->pModifyWorldTransform
)
1298 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1299 if (!ret
) goto done
;
1305 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1306 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1307 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1308 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1309 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1310 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1312 case MWT_LEFTMULTIPLY
:
1313 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1314 &dc
->xformWorld2Wnd
);
1316 case MWT_RIGHTMULTIPLY
:
1317 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1324 DC_UpdateXforms( dc
);
1327 release_dc_ptr( dc
);
1332 /****************************************************************************
1333 * CombineTransform [GDI32.@]
1334 * Combines two transformation matrices.
1337 * xformResult [O] Stores the result of combining the two matrices
1338 * xform1 [I] Specifies the first matrix to apply
1339 * xform2 [I] Specifies the second matrix to apply
1342 * The same matrix can be passed in for more than one of the parameters.
1346 * Failure: FALSE. Use GetLastError() to determine the cause.
1348 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1349 const XFORM
*xform2
)
1353 /* Check for illegal parameters */
1354 if (!xformResult
|| !xform1
|| !xform2
)
1357 /* Create the result in a temporary XFORM, since xformResult may be
1358 * equal to xform1 or xform2 */
1359 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1360 xform1
->eM12
* xform2
->eM21
;
1361 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1362 xform1
->eM12
* xform2
->eM22
;
1363 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1364 xform1
->eM22
* xform2
->eM21
;
1365 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1366 xform1
->eM22
* xform2
->eM22
;
1367 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1368 xform1
->eDy
* xform2
->eM21
+
1370 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1371 xform1
->eDy
* xform2
->eM22
+
1374 /* Copy the result to xformResult */
1375 *xformResult
= xformTemp
;
1381 /***********************************************************************
1382 * SetDCHook (GDI32.@)
1384 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1386 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1388 DC
*dc
= get_dc_ptr( hdc
);
1390 if (!dc
) return FALSE
;
1392 if (!(dc
->flags
& DC_SAVED
))
1394 dc
->dwHookData
= dwHookData
;
1395 dc
->hookThunk
= hookProc
;
1397 release_dc_ptr( dc
);
1402 /***********************************************************************
1403 * GetDCHook (GDI32.@)
1405 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1407 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1409 DC
*dc
= get_dc_ptr( hdc
);
1413 if (proc
) *proc
= dc
->hookThunk
;
1414 ret
= dc
->dwHookData
;
1415 release_dc_ptr( dc
);
1420 /* relay function to call the 16-bit DC hook proc */
1421 static BOOL WINAPI
call_dc_hook16( HDC hdc
, WORD code
, DWORD_PTR data
, LPARAM lParam
)
1425 DC
*dc
= get_dc_ptr( hdc
);
1427 if (!dc
) return FALSE
;
1430 args
[5] = HDC_16(hdc
);
1432 args
[3] = HIWORD(data
);
1433 args
[2] = LOWORD(data
);
1434 args
[1] = HIWORD(lParam
);
1435 args
[0] = LOWORD(lParam
);
1436 WOWCallback16Ex( (DWORD
)dc
->hookProc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1438 release_dc_ptr( dc
);
1442 /***********************************************************************
1443 * SetDCHook (GDI.190)
1445 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1447 DC
*dc
= get_dc_ptr( HDC_32(hdc16
) );
1449 if (!dc
) return FALSE
;
1450 if (!(dc
->flags
& DC_SAVED
))
1452 dc
->dwHookData
= dwHookData
;
1453 dc
->hookThunk
= call_dc_hook16
;
1454 dc
->hookProc
= hookProc
;
1456 release_dc_ptr( dc
);
1461 /***********************************************************************
1462 * GetDCHook (GDI.191)
1464 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1466 HDC hdc
= HDC_32( hdc16
);
1467 DC
*dc
= get_dc_ptr( hdc
);
1471 *phookProc
= dc
->hookProc
;
1472 ret
= dc
->dwHookData
;
1473 release_dc_ptr( dc
);
1478 /***********************************************************************
1479 * SetHookFlags (GDI32.@)
1481 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1483 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1485 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1490 /* "Undocumented Windows" info is slightly confusing. */
1492 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1494 if (flags
& DCHF_INVALIDATEVISRGN
)
1495 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1496 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1497 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1499 GDI_ReleaseObj( dc
);
1503 /***********************************************************************
1504 * SetICMMode (GDI32.@)
1506 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1508 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1509 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1510 if (iEnableICM
== ICM_ON
) return 0;
1511 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1515 /***********************************************************************
1516 * GetDeviceGammaRamp (GDI32.@)
1518 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1521 DC
*dc
= get_dc_ptr( hDC
);
1525 if (dc
->funcs
->pGetDeviceGammaRamp
)
1526 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1527 release_dc_ptr( dc
);
1532 /***********************************************************************
1533 * SetDeviceGammaRamp (GDI32.@)
1535 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1538 DC
*dc
= get_dc_ptr( hDC
);
1542 if (dc
->funcs
->pSetDeviceGammaRamp
)
1543 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1544 release_dc_ptr( dc
);
1549 /***********************************************************************
1550 * GetColorSpace (GDI32.@)
1552 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1554 /*FIXME Need to to whatever GetColorSpace actually does */
1558 /***********************************************************************
1559 * CreateColorSpaceA (GDI32.@)
1561 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1567 /***********************************************************************
1568 * CreateColorSpaceW (GDI32.@)
1570 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1576 /***********************************************************************
1577 * DeleteColorSpace (GDI32.@)
1579 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1586 /***********************************************************************
1587 * SetColorSpace (GDI32.@)
1589 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1596 /***********************************************************************
1597 * GetBoundsRect (GDI32.@)
1599 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1602 DC
*dc
= get_dc_ptr( hdc
);
1604 if ( !dc
) return 0;
1606 if (rect
) *rect
= dc
->BoundsRect
;
1608 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1610 if (flags
& DCB_RESET
)
1612 dc
->BoundsRect
.left
= 0;
1613 dc
->BoundsRect
.top
= 0;
1614 dc
->BoundsRect
.right
= 0;
1615 dc
->BoundsRect
.bottom
= 0;
1616 dc
->flags
&= ~DC_BOUNDS_SET
;
1618 release_dc_ptr( dc
);
1623 /***********************************************************************
1624 * SetBoundsRect (GDI32.@)
1626 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1631 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1632 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1634 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1635 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1637 if (flags
& DCB_RESET
)
1639 dc
->BoundsRect
.left
= 0;
1640 dc
->BoundsRect
.top
= 0;
1641 dc
->BoundsRect
.right
= 0;
1642 dc
->BoundsRect
.bottom
= 0;
1643 dc
->flags
&= ~DC_BOUNDS_SET
;
1646 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1648 if (dc
->flags
& DC_BOUNDS_SET
)
1650 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1651 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1652 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1653 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1657 dc
->BoundsRect
= *rect
;
1658 dc
->flags
|= DC_BOUNDS_SET
;
1662 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1663 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1665 release_dc_ptr( dc
);
1670 /***********************************************************************
1671 * GetRelAbs (GDI32.@)
1673 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1676 DC
*dc
= get_dc_ptr( hdc
);
1679 ret
= dc
->relAbsMode
;
1680 release_dc_ptr( dc
);
1688 /***********************************************************************
1689 * GetBkMode (GDI32.@)
1691 INT WINAPI
GetBkMode( HDC hdc
)
1694 DC
* dc
= get_dc_ptr( hdc
);
1697 ret
= dc
->backgroundMode
;
1698 release_dc_ptr( dc
);
1704 /***********************************************************************
1705 * SetBkMode (GDI32.@)
1707 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1711 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1713 SetLastError(ERROR_INVALID_PARAMETER
);
1716 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1718 ret
= dc
->backgroundMode
;
1719 if (dc
->funcs
->pSetBkMode
)
1720 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1723 dc
->backgroundMode
= mode
;
1724 release_dc_ptr( dc
);
1729 /***********************************************************************
1732 INT WINAPI
GetROP2( HDC hdc
)
1735 DC
* dc
= get_dc_ptr( hdc
);
1739 release_dc_ptr( dc
);
1745 /***********************************************************************
1748 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1752 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1754 SetLastError(ERROR_INVALID_PARAMETER
);
1757 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1759 if (dc
->funcs
->pSetROP2
)
1760 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1764 release_dc_ptr( dc
);
1769 /***********************************************************************
1770 * SetRelAbs (GDI32.@)
1772 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1776 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1778 SetLastError(ERROR_INVALID_PARAMETER
);
1781 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1782 if (dc
->funcs
->pSetRelAbs
)
1783 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1786 ret
= dc
->relAbsMode
;
1787 dc
->relAbsMode
= mode
;
1789 release_dc_ptr( dc
);
1794 /***********************************************************************
1795 * GetPolyFillMode (GDI32.@)
1797 INT WINAPI
GetPolyFillMode( HDC hdc
)
1800 DC
* dc
= get_dc_ptr( hdc
);
1803 ret
= dc
->polyFillMode
;
1804 release_dc_ptr( dc
);
1810 /***********************************************************************
1811 * SetPolyFillMode (GDI32.@)
1813 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1817 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1819 SetLastError(ERROR_INVALID_PARAMETER
);
1822 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1823 ret
= dc
->polyFillMode
;
1824 if (dc
->funcs
->pSetPolyFillMode
)
1825 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1828 dc
->polyFillMode
= mode
;
1829 release_dc_ptr( dc
);
1834 /***********************************************************************
1835 * GetStretchBltMode (GDI32.@)
1837 INT WINAPI
GetStretchBltMode( HDC hdc
)
1840 DC
* dc
= get_dc_ptr( hdc
);
1843 ret
= dc
->stretchBltMode
;
1844 release_dc_ptr( dc
);
1850 /***********************************************************************
1851 * SetStretchBltMode (GDI32.@)
1853 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1857 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1859 SetLastError(ERROR_INVALID_PARAMETER
);
1862 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1863 ret
= dc
->stretchBltMode
;
1864 if (dc
->funcs
->pSetStretchBltMode
)
1865 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1868 dc
->stretchBltMode
= mode
;
1869 release_dc_ptr( dc
);
1874 /***********************************************************************
1875 * GetMapMode (GDI32.@)
1877 INT WINAPI
GetMapMode( HDC hdc
)
1880 DC
* dc
= get_dc_ptr( hdc
);
1884 release_dc_ptr( dc
);
1890 /***********************************************************************
1891 * GetBrushOrgEx (GDI32.@)
1893 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1895 DC
* dc
= get_dc_ptr( hdc
);
1896 if (!dc
) return FALSE
;
1897 pt
->x
= dc
->brushOrgX
;
1898 pt
->y
= dc
->brushOrgY
;
1899 release_dc_ptr( dc
);
1904 /***********************************************************************
1905 * GetCurrentPositionEx (GDI32.@)
1907 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1909 DC
* dc
= get_dc_ptr( hdc
);
1910 if (!dc
) return FALSE
;
1911 pt
->x
= dc
->CursPosX
;
1912 pt
->y
= dc
->CursPosY
;
1913 release_dc_ptr( dc
);
1918 /***********************************************************************
1919 * GetViewportExtEx (GDI32.@)
1921 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1923 DC
* dc
= get_dc_ptr( hdc
);
1924 if (!dc
) return FALSE
;
1925 size
->cx
= dc
->vportExtX
;
1926 size
->cy
= dc
->vportExtY
;
1927 release_dc_ptr( dc
);
1932 /***********************************************************************
1933 * GetViewportOrgEx (GDI32.@)
1935 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1937 DC
* dc
= get_dc_ptr( hdc
);
1938 if (!dc
) return FALSE
;
1939 pt
->x
= dc
->vportOrgX
;
1940 pt
->y
= dc
->vportOrgY
;
1941 release_dc_ptr( dc
);
1946 /***********************************************************************
1947 * GetWindowExtEx (GDI32.@)
1949 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1951 DC
* dc
= get_dc_ptr( hdc
);
1952 if (!dc
) return FALSE
;
1953 size
->cx
= dc
->wndExtX
;
1954 size
->cy
= dc
->wndExtY
;
1955 release_dc_ptr( dc
);
1960 /***********************************************************************
1961 * GetWindowOrgEx (GDI32.@)
1963 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1965 DC
* dc
= get_dc_ptr( hdc
);
1966 if (!dc
) return FALSE
;
1967 pt
->x
= dc
->wndOrgX
;
1968 pt
->y
= dc
->wndOrgY
;
1969 release_dc_ptr( dc
);
1974 /***********************************************************************
1975 * InquireVisRgn (GDI.131)
1977 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1980 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1983 ret
= HRGN_16(dc
->hVisRgn
);
1984 release_dc_ptr( dc
);
1990 /***********************************************************************
1991 * GetClipRgn (GDI.173)
1993 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1996 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1999 ret
= HRGN_16(dc
->hClipRgn
);
2000 release_dc_ptr( dc
);
2006 /***********************************************************************
2007 * GetLayout (GDI32.@)
2009 * Gets left->right or right->left text layout flags of a dc.
2012 DWORD WINAPI
GetLayout(HDC hdc
)
2014 DWORD layout
= GDI_ERROR
;
2016 DC
* dc
= get_dc_ptr( hdc
);
2019 layout
= dc
->layout
;
2020 release_dc_ptr( dc
);
2023 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
2028 /***********************************************************************
2029 * SetLayout (GDI32.@)
2031 * Sets left->right or right->left text layout flags of a dc.
2034 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
2036 DWORD oldlayout
= GDI_ERROR
;
2038 DC
* dc
= get_dc_ptr( hdc
);
2041 oldlayout
= dc
->layout
;
2042 dc
->layout
= layout
;
2043 release_dc_ptr( dc
);
2046 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
2051 /***********************************************************************
2052 * GetDCBrushColor (GDI32.@)
2054 * Retrieves the current brush color for the specified device
2058 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
2061 COLORREF dcBrushColor
= CLR_INVALID
;
2063 TRACE("hdc(%p)\n", hdc
);
2065 dc
= get_dc_ptr( hdc
);
2068 dcBrushColor
= dc
->dcBrushColor
;
2069 release_dc_ptr( dc
);
2072 return dcBrushColor
;
2075 /***********************************************************************
2076 * SetDCBrushColor (GDI32.@)
2078 * Sets the current device context (DC) brush color to the specified
2079 * color value. If the device cannot represent the specified color
2080 * value, the color is set to the nearest physical color.
2083 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2086 COLORREF oldClr
= CLR_INVALID
;
2088 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2090 dc
= get_dc_ptr( hdc
);
2093 if (dc
->funcs
->pSetDCBrushColor
)
2094 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2095 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2097 /* If DC_BRUSH is selected, update driver pen color */
2098 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2099 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2100 DeleteObject( hBrush
);
2103 if (crColor
!= CLR_INVALID
)
2105 oldClr
= dc
->dcBrushColor
;
2106 dc
->dcBrushColor
= crColor
;
2109 release_dc_ptr( dc
);
2115 /***********************************************************************
2116 * GetDCPenColor (GDI32.@)
2118 * Retrieves the current pen color for the specified device
2122 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2125 COLORREF dcPenColor
= CLR_INVALID
;
2127 TRACE("hdc(%p)\n", hdc
);
2129 dc
= get_dc_ptr( hdc
);
2132 dcPenColor
= dc
->dcPenColor
;
2133 release_dc_ptr( dc
);
2139 /***********************************************************************
2140 * SetDCPenColor (GDI32.@)
2142 * Sets the current device context (DC) pen color to the specified
2143 * color value. If the device cannot represent the specified color
2144 * value, the color is set to the nearest physical color.
2147 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2150 COLORREF oldClr
= CLR_INVALID
;
2152 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2154 dc
= get_dc_ptr( hdc
);
2157 if (dc
->funcs
->pSetDCPenColor
)
2158 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2159 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2161 /* If DC_PEN is selected, update the driver pen color */
2162 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2163 HPEN hPen
= CreatePenIndirect( &logpen
);
2164 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2165 DeleteObject( hPen
);
2168 if (crColor
!= CLR_INVALID
)
2170 oldClr
= dc
->dcPenColor
;
2171 dc
->dcPenColor
= crColor
;
2174 release_dc_ptr( dc
);
2180 /***********************************************************************
2181 * CancelDC (GDI32.@)
2183 BOOL WINAPI
CancelDC(HDC hdc
)
2189 /***********************************************************************
2190 * SetVirtualResolution (GDI32.@)
2192 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2194 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2196 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);
2200 /*******************************************************************
2201 * GetMiterLimit [GDI32.@]
2205 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2210 TRACE("(%p,%p)\n", hdc
, peLimit
);
2212 dc
= get_dc_ptr( hdc
);
2216 *peLimit
= dc
->miterLimit
;
2218 release_dc_ptr( dc
);
2224 /*******************************************************************
2225 * SetMiterLimit [GDI32.@]
2229 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2234 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2236 dc
= get_dc_ptr( hdc
);
2240 *peOldLimit
= dc
->miterLimit
;
2241 dc
->miterLimit
= eNewLimit
;
2242 release_dc_ptr( dc
);
2248 /*******************************************************************
2249 * GdiIsMetaPrintDC [GDI32.@]
2251 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2257 /*******************************************************************
2258 * GdiIsMetaFileDC [GDI32.@]
2260 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2264 switch( GetObjectType( hdc
) )
2273 /*******************************************************************
2274 * GdiIsPlayMetafileDC [GDI32.@]
2276 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)