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
);
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
, 0 );
59 if ((dc
->header
.type
!= OBJ_DC
) &&
60 (dc
->header
.type
!= OBJ_MEMDC
) &&
61 (dc
->header
.type
!= OBJ_METADC
) &&
62 (dc
->header
.type
!= OBJ_ENHMETADC
))
64 GDI_ReleaseObj( hdc
);
65 SetLastError( ERROR_INVALID_HANDLE
);
72 /***********************************************************************
75 DC
*alloc_dc_ptr( const DC_FUNCTIONS
*funcs
, WORD magic
)
79 if (!(dc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dc
) ))) return NULL
;
83 dc
->thread
= GetCurrentThreadId();
99 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
104 dc
->hMetaClipRgn
= 0;
106 dc
->hPen
= GetStockObject( BLACK_PEN
);
107 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
108 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
111 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
113 dc
->ROPmode
= R2_COPYPEN
;
114 dc
->polyFillMode
= ALTERNATE
;
115 dc
->stretchBltMode
= BLACKONWHITE
;
116 dc
->relAbsMode
= ABSOLUTE
;
117 dc
->backgroundMode
= OPAQUE
;
118 dc
->backgroundColor
= RGB( 255, 255, 255 );
119 dc
->dcBrushColor
= RGB( 255, 255, 255 );
120 dc
->dcPenColor
= RGB( 0, 0, 0 );
121 dc
->textColor
= RGB( 0, 0, 0 );
124 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
128 dc
->MapMode
= MM_TEXT
;
129 dc
->GraphicsMode
= GM_COMPATIBLE
;
130 dc
->pAbortProc
= NULL
;
133 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
134 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
135 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
136 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
137 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
138 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
139 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
140 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
141 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
142 dc
->vport2WorldValid
= TRUE
;
143 dc
->BoundsRect
.left
= 0;
144 dc
->BoundsRect
.top
= 0;
145 dc
->BoundsRect
.right
= 0;
146 dc
->BoundsRect
.bottom
= 0;
147 dc
->saved_visrgn
= NULL
;
148 PATH_InitGdiPath(&dc
->path
);
150 if (!(dc
->hSelf
= alloc_gdi_handle( &dc
->header
, magic
, &dc_funcs
)))
152 HeapFree( GetProcessHeap(), 0, dc
);
160 /***********************************************************************
163 BOOL
free_dc_ptr( DC
*dc
)
165 assert( dc
->refcount
== 1 );
166 if (free_gdi_handle( dc
->hSelf
) != dc
) return FALSE
; /* shouldn't happen */
167 return HeapFree( GetProcessHeap(), 0, dc
);
171 /***********************************************************************
174 * Retrieve a DC pointer but release the GDI lock.
176 DC
*get_dc_ptr( HDC hdc
)
178 DC
*dc
= get_dc_obj( hdc
);
179 if (!dc
) return NULL
;
181 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
183 dc
->thread
= GetCurrentThreadId();
185 else if (dc
->thread
!= GetCurrentThreadId())
187 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
188 GDI_ReleaseObj( hdc
);
191 else InterlockedIncrement( &dc
->refcount
);
193 GDI_ReleaseObj( hdc
);
198 /***********************************************************************
201 void release_dc_ptr( DC
*dc
)
206 ref
= InterlockedDecrement( &dc
->refcount
);
208 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
212 /***********************************************************************
215 * Make sure the DC vis region is up to date.
216 * This function may call up to USER so the GDI lock should _not_
217 * be held when calling it.
219 void update_dc( DC
*dc
)
221 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookThunk
)
222 dc
->hookThunk( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
226 /***********************************************************************
229 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
231 return DeleteDC( handle
);
235 /***********************************************************************
238 * Setup device-specific DC values for a newly created DC.
240 void DC_InitDC( DC
* dc
)
242 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
243 SetTextColor( dc
->hSelf
, dc
->textColor
);
244 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
245 SelectObject( dc
->hSelf
, dc
->hPen
);
246 SelectObject( dc
->hSelf
, dc
->hBrush
);
247 SelectObject( dc
->hSelf
, dc
->hFont
);
248 CLIPPING_UpdateGCRegion( dc
);
252 /***********************************************************************
255 * Computes the inverse of the transformation xformSrc and stores it to
256 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
259 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
263 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
264 xformSrc
->eM12
*xformSrc
->eM21
;
265 if (determinant
> -1e-12 && determinant
< 1e-12)
268 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
269 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
270 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
271 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
272 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
273 xformSrc
->eDy
* xformDest
->eM21
;
274 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
275 xformSrc
->eDy
* xformDest
->eM22
;
281 /***********************************************************************
284 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
285 * fields of the specified DC by creating a transformation that
286 * represents the current mapping mode and combining it with the DC's
287 * world transform. This function should be called whenever the
288 * parameters associated with the mapping mode (window and viewport
289 * extents and origins) or the world transform change.
291 void DC_UpdateXforms( DC
*dc
)
293 XFORM xformWnd2Vport
, oldworld2vport
;
294 double scaleX
, scaleY
;
296 /* Construct a transformation to do the window-to-viewport conversion */
297 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
298 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
299 xformWnd2Vport
.eM11
= scaleX
;
300 xformWnd2Vport
.eM12
= 0.0;
301 xformWnd2Vport
.eM21
= 0.0;
302 xformWnd2Vport
.eM22
= scaleY
;
303 xformWnd2Vport
.eDx
= (double)dc
->vportOrgX
-
304 scaleX
* (double)dc
->wndOrgX
;
305 xformWnd2Vport
.eDy
= (double)dc
->vportOrgY
-
306 scaleY
* (double)dc
->wndOrgY
;
308 oldworld2vport
= dc
->xformWorld2Vport
;
309 /* Combine with the world transformation */
310 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
313 /* Create inverse of world-to-viewport transformation */
314 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
315 &dc
->xformVport2World
);
317 /* Reselect the font and pen back into the dc so that the size
319 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
320 !GdiIsMetaFileDC(dc
->hSelf
))
322 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
323 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
328 /***********************************************************************
329 * GetDCState (Not a Windows API)
331 static HDC
GetDCState( HDC hdc
)
336 if (!(dc
= get_dc_ptr( hdc
))) return 0;
337 if (!(newdc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc
))))
339 release_dc_ptr( dc
);
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
;
384 newdc
->gdiFont
= dc
->gdiFont
;
386 newdc
->thread
= GetCurrentThreadId();
388 newdc
->saveLevel
= 0;
391 PATH_InitGdiPath( &newdc
->path
);
393 newdc
->pAbortProc
= NULL
;
394 newdc
->hookThunk
= NULL
;
396 newdc
->saved_visrgn
= NULL
;
398 if (!(newdc
->hSelf
= alloc_gdi_handle( &newdc
->header
, dc
->header
.type
, &dc_funcs
)))
400 HeapFree( GetProcessHeap(), 0, newdc
);
401 release_dc_ptr( dc
);
404 handle
= newdc
->hSelf
;
405 TRACE("(%p): returning %p\n", hdc
, handle
);
407 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
412 newdc
->hMetaClipRgn
= 0;
415 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
416 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
420 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
421 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
423 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
425 release_dc_ptr( newdc
);
426 release_dc_ptr( dc
);
431 /***********************************************************************
432 * SetDCState (Not a Windows API)
434 static void SetDCState( HDC hdc
, HDC hdcs
)
438 if (!(dc
= get_dc_ptr( hdc
))) return;
439 if (!(dcs
= get_dc_ptr( hdcs
)))
441 release_dc_ptr( dc
);
444 if (!(dcs
->flags
& DC_SAVED
))
446 release_dc_ptr( dc
);
447 release_dc_ptr( dcs
);
450 TRACE("%p %p\n", hdc
, hdcs
);
453 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
454 dc
->layout
= dcs
->layout
;
455 dc
->hDevice
= dcs
->hDevice
;
456 dc
->ROPmode
= dcs
->ROPmode
;
457 dc
->polyFillMode
= dcs
->polyFillMode
;
458 dc
->stretchBltMode
= dcs
->stretchBltMode
;
459 dc
->relAbsMode
= dcs
->relAbsMode
;
460 dc
->backgroundMode
= dcs
->backgroundMode
;
461 dc
->backgroundColor
= dcs
->backgroundColor
;
462 dc
->textColor
= dcs
->textColor
;
463 dc
->dcBrushColor
= dcs
->dcBrushColor
;
464 dc
->dcPenColor
= dcs
->dcPenColor
;
465 dc
->brushOrgX
= dcs
->brushOrgX
;
466 dc
->brushOrgY
= dcs
->brushOrgY
;
467 dc
->textAlign
= dcs
->textAlign
;
468 dc
->charExtra
= dcs
->charExtra
;
469 dc
->breakExtra
= dcs
->breakExtra
;
470 dc
->breakRem
= dcs
->breakRem
;
471 dc
->MapMode
= dcs
->MapMode
;
472 dc
->GraphicsMode
= dcs
->GraphicsMode
;
473 dc
->CursPosX
= dcs
->CursPosX
;
474 dc
->CursPosY
= dcs
->CursPosY
;
475 dc
->ArcDirection
= dcs
->ArcDirection
;
476 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
477 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
478 dc
->xformVport2World
= dcs
->xformVport2World
;
479 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
480 dc
->BoundsRect
= dcs
->BoundsRect
;
482 dc
->wndOrgX
= dcs
->wndOrgX
;
483 dc
->wndOrgY
= dcs
->wndOrgY
;
484 dc
->wndExtX
= dcs
->wndExtX
;
485 dc
->wndExtY
= dcs
->wndExtY
;
486 dc
->vportOrgX
= dcs
->vportOrgX
;
487 dc
->vportOrgY
= dcs
->vportOrgY
;
488 dc
->vportExtX
= dcs
->vportExtX
;
489 dc
->vportExtY
= dcs
->vportExtY
;
493 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
494 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
498 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
503 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
504 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
508 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
511 CLIPPING_UpdateGCRegion( dc
);
513 SelectObject( hdc
, dcs
->hBitmap
);
514 SelectObject( hdc
, dcs
->hBrush
);
515 SelectObject( hdc
, dcs
->hFont
);
516 SelectObject( hdc
, dcs
->hPen
);
517 SetBkColor( hdc
, dcs
->backgroundColor
);
518 SetTextColor( hdc
, dcs
->textColor
);
519 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
520 release_dc_ptr( dc
);
521 release_dc_ptr( dcs
);
525 /***********************************************************************
526 * GetDCState (GDI.179)
528 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
530 return HDC_16( GetDCState( HDC_32(hdc
) ));
534 /***********************************************************************
535 * SetDCState (GDI.180)
537 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
539 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
543 /***********************************************************************
546 INT WINAPI
SaveDC( HDC hdc
)
552 dc
= get_dc_ptr( hdc
);
555 if(dc
->funcs
->pSaveDC
)
557 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
559 ret
= ++dc
->saveLevel
;
560 release_dc_ptr( dc
);
564 if (!(hdcs
= GetDCState( hdc
)))
566 release_dc_ptr( dc
);
569 dcs
= get_dc_ptr( hdcs
);
571 /* Copy path. The reason why path saving / restoring is in SaveDC/
572 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
573 * functions are only in Win16 (which doesn't have paths) and that
574 * SetDCState doesn't allow us to signal an error (which can happen
575 * when copying paths).
577 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
579 release_dc_ptr( dc
);
580 release_dc_ptr( dcs
);
585 dcs
->saved_dc
= dc
->saved_dc
;
587 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
588 ret
= ++dc
->saveLevel
;
589 release_dc_ptr( dcs
);
590 release_dc_ptr( dc
);
595 /***********************************************************************
596 * RestoreDC (GDI32.@)
598 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
603 TRACE("%p %d\n", hdc
, level
);
604 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
606 if(abs(level
) > dc
->saveLevel
|| level
== 0)
608 release_dc_ptr( dc
);
614 if(dc
->funcs
->pRestoreDC
)
616 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
617 if(level
< 0) level
= dc
->saveLevel
+ level
+ 1;
619 dc
->saveLevel
= level
- 1;
620 release_dc_ptr( dc
);
624 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
626 while (dc
->saveLevel
>= level
)
628 HDC hdcs
= dc
->saved_dc
;
629 if (!(dcs
= get_dc_ptr( hdcs
)))
634 dc
->saved_dc
= dcs
->saved_dc
;
636 if (--dc
->saveLevel
< level
)
638 SetDCState( hdc
, hdcs
);
639 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
640 /* FIXME: This might not be quite right, since we're
641 * returning FALSE but still destroying the saved DC state */
644 release_dc_ptr( dcs
);
647 release_dc_ptr( dc
);
652 /***********************************************************************
653 * CreateDCW (GDI32.@)
655 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
656 const DEVMODEW
*initData
)
660 const DC_FUNCTIONS
*funcs
;
665 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
669 ERR( "no device found for %s\n", debugstr_w(device
) );
672 strcpyW(buf
, driver
);
675 if (!(funcs
= DRIVER_load_driver( buf
)))
677 ERR( "no driver found for %s\n", debugstr_w(buf
) );
680 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_DC
))) goto error
;
683 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
684 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
686 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
687 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
689 if (dc
->funcs
->pCreateDC
&&
690 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
692 WARN("creation aborted by device\n" );
696 SetRectRgn( dc
->hVisRgn
, 0, 0,
697 GetDeviceCaps( hdc
, DESKTOPHORZRES
), GetDeviceCaps( hdc
, DESKTOPVERTRES
) );
700 release_dc_ptr( dc
);
704 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
705 if (dc
) free_dc_ptr( dc
);
706 DRIVER_release_driver( funcs
);
711 /***********************************************************************
712 * CreateDCA (GDI32.@)
714 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
715 const DEVMODEA
*initData
)
717 UNICODE_STRING driverW
, deviceW
, outputW
;
721 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
722 else driverW
.Buffer
= NULL
;
724 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
725 else deviceW
.Buffer
= NULL
;
727 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
728 else outputW
.Buffer
= NULL
;
733 /* don't convert initData for DISPLAY driver, it's not used */
734 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
735 initDataW
= GdiConvertToDevmodeW(initData
);
738 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
740 RtlFreeUnicodeString(&driverW
);
741 RtlFreeUnicodeString(&deviceW
);
742 RtlFreeUnicodeString(&outputW
);
743 HeapFree(GetProcessHeap(), 0, initDataW
);
748 /***********************************************************************
749 * CreateICA (GDI32.@)
751 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
752 const DEVMODEA
* initData
)
754 /* Nothing special yet for ICs */
755 return CreateDCA( driver
, device
, output
, initData
);
759 /***********************************************************************
760 * CreateICW (GDI32.@)
762 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
763 const DEVMODEW
* initData
)
765 /* Nothing special yet for ICs */
766 return CreateDCW( driver
, device
, output
, initData
);
770 /***********************************************************************
771 * CreateCompatibleDC (GDI32.@)
773 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
777 const DC_FUNCTIONS
*funcs
= NULL
;
778 PHYSDEV physDev
= NULL
;
782 if ((origDC
= get_dc_ptr( hdc
)))
784 if (GetObjectType( hdc
) == OBJ_DC
)
786 funcs
= origDC
->funcs
;
787 physDev
= origDC
->physDev
;
789 release_dc_ptr( origDC
);
790 if (funcs
) funcs
= DRIVER_get_driver( funcs
);
792 else if (hdc
) return 0;
794 if (!funcs
&& !(funcs
= DRIVER_load_driver( displayW
))) return 0;
796 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_MEMDC
))) goto error
;
798 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
800 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
801 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
803 /* Copy the driver-specific physical device info into
804 * the new DC. The driver may use this read-only info
805 * while creating the compatible DC below. */
806 dc
->physDev
= physDev
;
809 if (dc
->funcs
->pCreateDC
&&
810 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
812 WARN("creation aborted by device\n");
817 release_dc_ptr( dc
);
821 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
822 if (dc
) free_dc_ptr( dc
);
823 DRIVER_release_driver( funcs
);
828 /***********************************************************************
831 BOOL WINAPI
DeleteDC( HDC hdc
)
833 const DC_FUNCTIONS
*funcs
= NULL
;
840 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
841 if (dc
->refcount
!= 1)
843 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
844 release_dc_ptr( dc
);
848 /* Call hook procedure to check whether is it OK to delete this DC */
849 if (dc
->hookThunk
&& !dc
->hookThunk( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
851 release_dc_ptr( dc
);
855 while (dc
->saveLevel
)
858 HDC hdcs
= dc
->saved_dc
;
859 if (!(dcs
= get_dc_ptr( hdcs
))) break;
860 dc
->saved_dc
= dcs
->saved_dc
;
862 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
863 if (dcs
->hMetaRgn
) DeleteObject( dcs
->hMetaRgn
);
864 if (dcs
->hMetaClipRgn
) DeleteObject( dcs
->hMetaClipRgn
);
865 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
866 PATH_DestroyGdiPath(&dcs
->path
);
870 if (!(dc
->flags
& DC_SAVED
))
872 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
873 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
874 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
875 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
877 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
881 while (dc
->saved_visrgn
)
883 struct saved_visrgn
*next
= dc
->saved_visrgn
->next
;
884 DeleteObject( dc
->saved_visrgn
->hrgn
);
885 HeapFree( GetProcessHeap(), 0, dc
->saved_visrgn
);
886 dc
->saved_visrgn
= next
;
888 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
889 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
890 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
891 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
892 PATH_DestroyGdiPath(&dc
->path
);
895 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
900 /***********************************************************************
903 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
908 if ((dc
= get_dc_ptr( hdc
)))
910 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
911 release_dc_ptr( dc
);
917 /***********************************************************************
920 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
925 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
926 else devmodeW
= NULL
;
928 ret
= ResetDCW(hdc
, devmodeW
);
930 HeapFree(GetProcessHeap(), 0, devmodeW
);
935 /***********************************************************************
936 * GetDeviceCaps (GDI32.@)
938 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
943 if ((dc
= get_dc_ptr( hdc
)))
945 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
946 else switch(cap
) /* return meaningful values for some entries */
948 case HORZRES
: ret
= 640; break;
949 case VERTRES
: ret
= 480; break;
950 case BITSPIXEL
: ret
= 1; break;
951 case PLANES
: ret
= 1; break;
952 case NUMCOLORS
: ret
= 2; break;
953 case ASPECTX
: ret
= 36; break;
954 case ASPECTY
: ret
= 36; break;
955 case ASPECTXY
: ret
= 51; break;
956 case LOGPIXELSX
: ret
= 72; break;
957 case LOGPIXELSY
: ret
= 72; break;
958 case SIZEPALETTE
: ret
= 2; break;
960 release_dc_ptr( dc
);
966 /***********************************************************************
967 * GetBkColor (GDI32.@)
969 COLORREF WINAPI
GetBkColor( HDC hdc
)
972 DC
* dc
= get_dc_ptr( hdc
);
975 ret
= dc
->backgroundColor
;
976 release_dc_ptr( dc
);
982 /***********************************************************************
983 * SetBkColor (GDI32.@)
985 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
988 DC
* dc
= get_dc_ptr( hdc
);
990 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
992 if (!dc
) return CLR_INVALID
;
993 oldColor
= dc
->backgroundColor
;
994 if (dc
->funcs
->pSetBkColor
)
996 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
997 if (color
== CLR_INVALID
) /* don't change it */
1000 oldColor
= CLR_INVALID
;
1003 dc
->backgroundColor
= color
;
1004 release_dc_ptr( dc
);
1009 /***********************************************************************
1010 * GetTextColor (GDI32.@)
1012 COLORREF WINAPI
GetTextColor( HDC hdc
)
1015 DC
* dc
= get_dc_ptr( hdc
);
1018 ret
= dc
->textColor
;
1019 release_dc_ptr( dc
);
1025 /***********************************************************************
1026 * SetTextColor (GDI32.@)
1028 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
1031 DC
* dc
= get_dc_ptr( hdc
);
1033 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
1035 if (!dc
) return CLR_INVALID
;
1036 oldColor
= dc
->textColor
;
1037 if (dc
->funcs
->pSetTextColor
)
1039 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
1040 if (color
== CLR_INVALID
) /* don't change it */
1043 oldColor
= CLR_INVALID
;
1046 dc
->textColor
= color
;
1047 release_dc_ptr( dc
);
1052 /***********************************************************************
1053 * GetTextAlign (GDI32.@)
1055 UINT WINAPI
GetTextAlign( HDC hdc
)
1058 DC
* dc
= get_dc_ptr( hdc
);
1061 ret
= dc
->textAlign
;
1062 release_dc_ptr( dc
);
1068 /***********************************************************************
1069 * SetTextAlign (GDI32.@)
1071 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1074 DC
*dc
= get_dc_ptr( hdc
);
1076 TRACE("hdc=%p align=%d\n", hdc
, align
);
1078 if (!dc
) return 0x0;
1079 ret
= dc
->textAlign
;
1080 if (dc
->funcs
->pSetTextAlign
)
1081 if (!dc
->funcs
->pSetTextAlign(dc
->physDev
, align
))
1083 if (ret
!= GDI_ERROR
)
1084 dc
->textAlign
= align
;
1085 release_dc_ptr( dc
);
1089 /***********************************************************************
1090 * GetDCOrgEx (GDI32.@)
1092 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1096 if (!lpp
) return FALSE
;
1097 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1099 lpp
->x
= lpp
->y
= 0;
1100 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
1101 release_dc_ptr( dc
);
1106 /***********************************************************************
1107 * SetDCOrg (GDI.117)
1109 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
1112 HDC hdc
= HDC_32( hdc16
);
1113 DC
*dc
= get_dc_ptr( hdc
);
1115 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
1116 release_dc_ptr( dc
);
1121 /***********************************************************************
1122 * GetGraphicsMode (GDI32.@)
1124 INT WINAPI
GetGraphicsMode( HDC hdc
)
1127 DC
* dc
= get_dc_ptr( hdc
);
1130 ret
= dc
->GraphicsMode
;
1131 release_dc_ptr( dc
);
1137 /***********************************************************************
1138 * SetGraphicsMode (GDI32.@)
1140 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1143 DC
*dc
= get_dc_ptr( hdc
);
1145 /* One would think that setting the graphics mode to GM_COMPATIBLE
1146 * would also reset the world transformation matrix to the unity
1147 * matrix. However, in Windows, this is not the case. This doesn't
1148 * make a lot of sense to me, but that's the way it is.
1151 if ((mode
> 0) && (mode
<= GM_LAST
))
1153 ret
= dc
->GraphicsMode
;
1154 dc
->GraphicsMode
= mode
;
1156 release_dc_ptr( dc
);
1161 /***********************************************************************
1162 * GetArcDirection (GDI32.@)
1164 INT WINAPI
GetArcDirection( HDC hdc
)
1167 DC
* dc
= get_dc_ptr( hdc
);
1170 ret
= dc
->ArcDirection
;
1171 release_dc_ptr( dc
);
1177 /***********************************************************************
1178 * SetArcDirection (GDI32.@)
1180 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1183 INT nOldDirection
= 0;
1185 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1187 SetLastError(ERROR_INVALID_PARAMETER
);
1191 if ((dc
= get_dc_ptr( hdc
)))
1193 if (dc
->funcs
->pSetArcDirection
)
1195 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1197 nOldDirection
= dc
->ArcDirection
;
1198 dc
->ArcDirection
= nDirection
;
1199 release_dc_ptr( dc
);
1201 return nOldDirection
;
1205 /***********************************************************************
1206 * GetWorldTransform (GDI32.@)
1208 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1211 if (!xform
) return FALSE
;
1212 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1213 *xform
= dc
->xformWorld2Wnd
;
1214 release_dc_ptr( dc
);
1219 /***********************************************************************
1220 * GetTransform (GDI32.@)
1222 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1224 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1225 FIXME("stub: don't know what to do for code %x\n", unknown
);
1230 /***********************************************************************
1231 * SetWorldTransform (GDI32.@)
1233 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1236 DC
*dc
= get_dc_ptr( hdc
);
1238 if (!dc
) return FALSE
;
1239 if (!xform
) goto done
;
1241 /* Check that graphics mode is GM_ADVANCED */
1242 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1244 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1245 xform
->eM11
, xform
->eM12
, xform
->eM21
, xform
->eM22
, xform
->eDx
, xform
->eDy
);
1247 if (dc
->funcs
->pSetWorldTransform
)
1249 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1250 if (!ret
) goto done
;
1253 dc
->xformWorld2Wnd
= *xform
;
1254 DC_UpdateXforms( dc
);
1257 release_dc_ptr( dc
);
1262 /****************************************************************************
1263 * ModifyWorldTransform [GDI32.@]
1264 * Modifies the world transformation for a device context.
1267 * hdc [I] Handle to device context
1268 * xform [I] XFORM structure that will be used to modify the world
1270 * iMode [I] Specifies in what way to modify the world transformation
1273 * Resets the world transformation to the identity matrix.
1274 * The parameter xform is ignored.
1276 * Multiplies xform into the world transformation matrix from
1279 * Multiplies xform into the world transformation matrix from
1284 * Failure: FALSE. Use GetLastError() to determine the cause.
1286 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1290 DC
*dc
= get_dc_ptr( hdc
);
1292 /* Check for illegal parameters */
1293 if (!dc
) return FALSE
;
1294 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1296 /* Check that graphics mode is GM_ADVANCED */
1297 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1299 if (dc
->funcs
->pModifyWorldTransform
)
1301 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1302 if (!ret
) goto done
;
1308 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1309 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1310 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1311 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1312 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1313 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1315 case MWT_LEFTMULTIPLY
:
1316 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1317 &dc
->xformWorld2Wnd
);
1319 case MWT_RIGHTMULTIPLY
:
1320 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1327 DC_UpdateXforms( dc
);
1330 release_dc_ptr( dc
);
1335 /****************************************************************************
1336 * CombineTransform [GDI32.@]
1337 * Combines two transformation matrices.
1340 * xformResult [O] Stores the result of combining the two matrices
1341 * xform1 [I] Specifies the first matrix to apply
1342 * xform2 [I] Specifies the second matrix to apply
1345 * The same matrix can be passed in for more than one of the parameters.
1349 * Failure: FALSE. Use GetLastError() to determine the cause.
1351 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1352 const XFORM
*xform2
)
1356 /* Check for illegal parameters */
1357 if (!xformResult
|| !xform1
|| !xform2
)
1360 /* Create the result in a temporary XFORM, since xformResult may be
1361 * equal to xform1 or xform2 */
1362 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1363 xform1
->eM12
* xform2
->eM21
;
1364 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1365 xform1
->eM12
* xform2
->eM22
;
1366 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1367 xform1
->eM22
* xform2
->eM21
;
1368 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1369 xform1
->eM22
* xform2
->eM22
;
1370 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1371 xform1
->eDy
* xform2
->eM21
+
1373 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1374 xform1
->eDy
* xform2
->eM22
+
1377 /* Copy the result to xformResult */
1378 *xformResult
= xformTemp
;
1384 /***********************************************************************
1385 * SetDCHook (GDI32.@)
1387 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1389 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1391 DC
*dc
= get_dc_ptr( hdc
);
1393 if (!dc
) return FALSE
;
1395 if (!(dc
->flags
& DC_SAVED
))
1397 dc
->dwHookData
= dwHookData
;
1398 dc
->hookThunk
= hookProc
;
1400 release_dc_ptr( dc
);
1405 /***********************************************************************
1406 * GetDCHook (GDI32.@)
1408 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1410 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1412 DC
*dc
= get_dc_ptr( hdc
);
1416 if (proc
) *proc
= dc
->hookThunk
;
1417 ret
= dc
->dwHookData
;
1418 release_dc_ptr( dc
);
1423 /* relay function to call the 16-bit DC hook proc */
1424 static BOOL WINAPI
call_dc_hook16( HDC hdc
, WORD code
, DWORD_PTR data
, LPARAM lParam
)
1428 DC
*dc
= get_dc_ptr( hdc
);
1430 if (!dc
) return FALSE
;
1433 args
[5] = HDC_16(hdc
);
1435 args
[3] = HIWORD(data
);
1436 args
[2] = LOWORD(data
);
1437 args
[1] = HIWORD(lParam
);
1438 args
[0] = LOWORD(lParam
);
1439 WOWCallback16Ex( (DWORD
)dc
->hookProc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1441 release_dc_ptr( dc
);
1445 /***********************************************************************
1446 * SetDCHook (GDI.190)
1448 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1450 DC
*dc
= get_dc_ptr( HDC_32(hdc16
) );
1452 if (!dc
) return FALSE
;
1453 if (!(dc
->flags
& DC_SAVED
))
1455 dc
->dwHookData
= dwHookData
;
1456 dc
->hookThunk
= call_dc_hook16
;
1457 dc
->hookProc
= hookProc
;
1459 release_dc_ptr( dc
);
1464 /***********************************************************************
1465 * GetDCHook (GDI.191)
1467 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1469 HDC hdc
= HDC_32( hdc16
);
1470 DC
*dc
= get_dc_ptr( hdc
);
1474 *phookProc
= dc
->hookProc
;
1475 ret
= dc
->dwHookData
;
1476 release_dc_ptr( dc
);
1481 /***********************************************************************
1482 * SetHookFlags (GDI32.@)
1484 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1486 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1488 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1493 /* "Undocumented Windows" info is slightly confusing. */
1495 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1497 if (flags
& DCHF_INVALIDATEVISRGN
)
1498 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1499 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1500 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1502 GDI_ReleaseObj( dc
);
1506 /***********************************************************************
1507 * SetICMMode (GDI32.@)
1509 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1511 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1512 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1513 if (iEnableICM
== ICM_ON
) return 0;
1514 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1518 /***********************************************************************
1519 * GetDeviceGammaRamp (GDI32.@)
1521 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1524 DC
*dc
= get_dc_ptr( hDC
);
1528 if (dc
->funcs
->pGetDeviceGammaRamp
)
1529 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1530 release_dc_ptr( dc
);
1535 /***********************************************************************
1536 * SetDeviceGammaRamp (GDI32.@)
1538 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1541 DC
*dc
= get_dc_ptr( hDC
);
1545 if (dc
->funcs
->pSetDeviceGammaRamp
)
1546 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1547 release_dc_ptr( dc
);
1552 /***********************************************************************
1553 * GetColorSpace (GDI32.@)
1555 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1557 /*FIXME Need to to whatever GetColorSpace actually does */
1561 /***********************************************************************
1562 * CreateColorSpaceA (GDI32.@)
1564 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1570 /***********************************************************************
1571 * CreateColorSpaceW (GDI32.@)
1573 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1579 /***********************************************************************
1580 * DeleteColorSpace (GDI32.@)
1582 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1589 /***********************************************************************
1590 * SetColorSpace (GDI32.@)
1592 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1599 /***********************************************************************
1600 * GetBoundsRect (GDI32.@)
1602 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1605 DC
*dc
= get_dc_ptr( hdc
);
1607 if ( !dc
) return 0;
1609 if (rect
) *rect
= dc
->BoundsRect
;
1611 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1613 if (flags
& DCB_RESET
)
1615 dc
->BoundsRect
.left
= 0;
1616 dc
->BoundsRect
.top
= 0;
1617 dc
->BoundsRect
.right
= 0;
1618 dc
->BoundsRect
.bottom
= 0;
1619 dc
->flags
&= ~DC_BOUNDS_SET
;
1621 release_dc_ptr( dc
);
1626 /***********************************************************************
1627 * SetBoundsRect (GDI32.@)
1629 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1634 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1635 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1637 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1638 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1640 if (flags
& DCB_RESET
)
1642 dc
->BoundsRect
.left
= 0;
1643 dc
->BoundsRect
.top
= 0;
1644 dc
->BoundsRect
.right
= 0;
1645 dc
->BoundsRect
.bottom
= 0;
1646 dc
->flags
&= ~DC_BOUNDS_SET
;
1649 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1651 if (dc
->flags
& DC_BOUNDS_SET
)
1653 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1654 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1655 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1656 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1660 dc
->BoundsRect
= *rect
;
1661 dc
->flags
|= DC_BOUNDS_SET
;
1665 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1666 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1668 release_dc_ptr( dc
);
1673 /***********************************************************************
1674 * GetRelAbs (GDI32.@)
1676 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1679 DC
*dc
= get_dc_ptr( hdc
);
1682 ret
= dc
->relAbsMode
;
1683 release_dc_ptr( dc
);
1691 /***********************************************************************
1692 * GetBkMode (GDI32.@)
1694 INT WINAPI
GetBkMode( HDC hdc
)
1697 DC
* dc
= get_dc_ptr( hdc
);
1700 ret
= dc
->backgroundMode
;
1701 release_dc_ptr( dc
);
1707 /***********************************************************************
1708 * SetBkMode (GDI32.@)
1710 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1714 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1716 SetLastError(ERROR_INVALID_PARAMETER
);
1719 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1721 ret
= dc
->backgroundMode
;
1722 if (dc
->funcs
->pSetBkMode
)
1723 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1726 dc
->backgroundMode
= mode
;
1727 release_dc_ptr( dc
);
1732 /***********************************************************************
1735 INT WINAPI
GetROP2( HDC hdc
)
1738 DC
* dc
= get_dc_ptr( hdc
);
1742 release_dc_ptr( dc
);
1748 /***********************************************************************
1751 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1755 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1757 SetLastError(ERROR_INVALID_PARAMETER
);
1760 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1762 if (dc
->funcs
->pSetROP2
)
1763 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1767 release_dc_ptr( dc
);
1772 /***********************************************************************
1773 * SetRelAbs (GDI32.@)
1775 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1779 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1781 SetLastError(ERROR_INVALID_PARAMETER
);
1784 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1785 if (dc
->funcs
->pSetRelAbs
)
1786 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1789 ret
= dc
->relAbsMode
;
1790 dc
->relAbsMode
= mode
;
1792 release_dc_ptr( dc
);
1797 /***********************************************************************
1798 * GetPolyFillMode (GDI32.@)
1800 INT WINAPI
GetPolyFillMode( HDC hdc
)
1803 DC
* dc
= get_dc_ptr( hdc
);
1806 ret
= dc
->polyFillMode
;
1807 release_dc_ptr( dc
);
1813 /***********************************************************************
1814 * SetPolyFillMode (GDI32.@)
1816 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1820 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1822 SetLastError(ERROR_INVALID_PARAMETER
);
1825 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1826 ret
= dc
->polyFillMode
;
1827 if (dc
->funcs
->pSetPolyFillMode
)
1828 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1831 dc
->polyFillMode
= mode
;
1832 release_dc_ptr( dc
);
1837 /***********************************************************************
1838 * GetStretchBltMode (GDI32.@)
1840 INT WINAPI
GetStretchBltMode( HDC hdc
)
1843 DC
* dc
= get_dc_ptr( hdc
);
1846 ret
= dc
->stretchBltMode
;
1847 release_dc_ptr( dc
);
1853 /***********************************************************************
1854 * SetStretchBltMode (GDI32.@)
1856 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1860 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1862 SetLastError(ERROR_INVALID_PARAMETER
);
1865 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1866 ret
= dc
->stretchBltMode
;
1867 if (dc
->funcs
->pSetStretchBltMode
)
1868 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1871 dc
->stretchBltMode
= mode
;
1872 release_dc_ptr( dc
);
1877 /***********************************************************************
1878 * GetMapMode (GDI32.@)
1880 INT WINAPI
GetMapMode( HDC hdc
)
1883 DC
* dc
= get_dc_ptr( hdc
);
1887 release_dc_ptr( dc
);
1893 /***********************************************************************
1894 * GetBrushOrgEx (GDI32.@)
1896 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1898 DC
* dc
= get_dc_ptr( hdc
);
1899 if (!dc
) return FALSE
;
1900 pt
->x
= dc
->brushOrgX
;
1901 pt
->y
= dc
->brushOrgY
;
1902 release_dc_ptr( dc
);
1907 /***********************************************************************
1908 * GetCurrentPositionEx (GDI32.@)
1910 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1912 DC
* dc
= get_dc_ptr( hdc
);
1913 if (!dc
) return FALSE
;
1914 pt
->x
= dc
->CursPosX
;
1915 pt
->y
= dc
->CursPosY
;
1916 release_dc_ptr( dc
);
1921 /***********************************************************************
1922 * GetViewportExtEx (GDI32.@)
1924 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1926 DC
* dc
= get_dc_ptr( hdc
);
1927 if (!dc
) return FALSE
;
1928 size
->cx
= dc
->vportExtX
;
1929 size
->cy
= dc
->vportExtY
;
1930 release_dc_ptr( dc
);
1935 /***********************************************************************
1936 * GetViewportOrgEx (GDI32.@)
1938 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1940 DC
* dc
= get_dc_ptr( hdc
);
1941 if (!dc
) return FALSE
;
1942 pt
->x
= dc
->vportOrgX
;
1943 pt
->y
= dc
->vportOrgY
;
1944 release_dc_ptr( dc
);
1949 /***********************************************************************
1950 * GetWindowExtEx (GDI32.@)
1952 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1954 DC
* dc
= get_dc_ptr( hdc
);
1955 if (!dc
) return FALSE
;
1956 size
->cx
= dc
->wndExtX
;
1957 size
->cy
= dc
->wndExtY
;
1958 release_dc_ptr( dc
);
1963 /***********************************************************************
1964 * GetWindowOrgEx (GDI32.@)
1966 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1968 DC
* dc
= get_dc_ptr( hdc
);
1969 if (!dc
) return FALSE
;
1970 pt
->x
= dc
->wndOrgX
;
1971 pt
->y
= dc
->wndOrgY
;
1972 release_dc_ptr( dc
);
1977 /***********************************************************************
1978 * InquireVisRgn (GDI.131)
1980 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1983 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
1986 ret
= HRGN_16(dc
->hVisRgn
);
1987 release_dc_ptr( dc
);
1993 /***********************************************************************
1994 * GetClipRgn (GDI.173)
1996 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1999 DC
* dc
= get_dc_ptr( HDC_32(hdc
) );
2002 ret
= HRGN_16(dc
->hClipRgn
);
2003 release_dc_ptr( dc
);
2009 /***********************************************************************
2010 * GetLayout (GDI32.@)
2012 * Gets left->right or right->left text layout flags of a dc.
2015 DWORD WINAPI
GetLayout(HDC hdc
)
2017 DWORD layout
= GDI_ERROR
;
2019 DC
* dc
= get_dc_ptr( hdc
);
2022 layout
= dc
->layout
;
2023 release_dc_ptr( dc
);
2026 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
2031 /***********************************************************************
2032 * SetLayout (GDI32.@)
2034 * Sets left->right or right->left text layout flags of a dc.
2037 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
2039 DWORD oldlayout
= GDI_ERROR
;
2041 DC
* dc
= get_dc_ptr( hdc
);
2044 oldlayout
= dc
->layout
;
2045 dc
->layout
= layout
;
2046 release_dc_ptr( dc
);
2049 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
2054 /***********************************************************************
2055 * GetDCBrushColor (GDI32.@)
2057 * Retrieves the current brush color for the specified device
2061 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
2064 COLORREF dcBrushColor
= CLR_INVALID
;
2066 TRACE("hdc(%p)\n", hdc
);
2068 dc
= get_dc_ptr( hdc
);
2071 dcBrushColor
= dc
->dcBrushColor
;
2072 release_dc_ptr( dc
);
2075 return dcBrushColor
;
2078 /***********************************************************************
2079 * SetDCBrushColor (GDI32.@)
2081 * Sets the current device context (DC) brush color to the specified
2082 * color value. If the device cannot represent the specified color
2083 * value, the color is set to the nearest physical color.
2086 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2089 COLORREF oldClr
= CLR_INVALID
;
2091 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2093 dc
= get_dc_ptr( hdc
);
2096 if (dc
->funcs
->pSetDCBrushColor
)
2097 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2098 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2100 /* If DC_BRUSH is selected, update driver pen color */
2101 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2102 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2103 DeleteObject( hBrush
);
2106 if (crColor
!= CLR_INVALID
)
2108 oldClr
= dc
->dcBrushColor
;
2109 dc
->dcBrushColor
= crColor
;
2112 release_dc_ptr( dc
);
2118 /***********************************************************************
2119 * GetDCPenColor (GDI32.@)
2121 * Retrieves the current pen color for the specified device
2125 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2128 COLORREF dcPenColor
= CLR_INVALID
;
2130 TRACE("hdc(%p)\n", hdc
);
2132 dc
= get_dc_ptr( hdc
);
2135 dcPenColor
= dc
->dcPenColor
;
2136 release_dc_ptr( dc
);
2142 /***********************************************************************
2143 * SetDCPenColor (GDI32.@)
2145 * Sets the current device context (DC) pen color to the specified
2146 * color value. If the device cannot represent the specified color
2147 * value, the color is set to the nearest physical color.
2150 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2153 COLORREF oldClr
= CLR_INVALID
;
2155 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2157 dc
= get_dc_ptr( hdc
);
2160 if (dc
->funcs
->pSetDCPenColor
)
2161 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2162 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2164 /* If DC_PEN is selected, update the driver pen color */
2165 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2166 HPEN hPen
= CreatePenIndirect( &logpen
);
2167 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2168 DeleteObject( hPen
);
2171 if (crColor
!= CLR_INVALID
)
2173 oldClr
= dc
->dcPenColor
;
2174 dc
->dcPenColor
= crColor
;
2177 release_dc_ptr( dc
);
2183 /***********************************************************************
2184 * CancelDC (GDI32.@)
2186 BOOL WINAPI
CancelDC(HDC hdc
)
2192 /***********************************************************************
2193 * SetVirtualResolution (GDI32.@)
2195 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2197 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2199 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);
2203 /*******************************************************************
2204 * GetMiterLimit [GDI32.@]
2208 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2213 TRACE("(%p,%p)\n", hdc
, peLimit
);
2215 dc
= get_dc_ptr( hdc
);
2219 *peLimit
= dc
->miterLimit
;
2221 release_dc_ptr( dc
);
2227 /*******************************************************************
2228 * SetMiterLimit [GDI32.@]
2232 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2237 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2239 dc
= get_dc_ptr( hdc
);
2243 *peOldLimit
= dc
->miterLimit
;
2244 dc
->miterLimit
= eNewLimit
;
2245 release_dc_ptr( dc
);
2251 /*******************************************************************
2252 * GdiIsMetaPrintDC [GDI32.@]
2254 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2260 /*******************************************************************
2261 * GdiIsMetaFileDC [GDI32.@]
2263 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2267 switch( GetObjectType( hdc
) )
2276 /*******************************************************************
2277 * GdiIsPlayMetafileDC [GDI32.@]
2279 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)