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
33 #include "gdi_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
39 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
41 static BOOL
DC_DeleteObject( HGDIOBJ handle
);
43 static const struct gdi_obj_funcs dc_funcs
=
45 NULL
, /* pSelectObject */
46 NULL
, /* pGetObjectA */
47 NULL
, /* pGetObjectW */
48 NULL
, /* pUnrealizeObject */
49 DC_DeleteObject
/* pDeleteObject */
53 static inline DC
*get_dc_obj( HDC hdc
)
55 DC
*dc
= GDI_GetObjPtr( hdc
, 0 );
58 if ((dc
->header
.type
!= OBJ_DC
) &&
59 (dc
->header
.type
!= OBJ_MEMDC
) &&
60 (dc
->header
.type
!= OBJ_METADC
) &&
61 (dc
->header
.type
!= OBJ_ENHMETADC
))
63 GDI_ReleaseObj( hdc
);
64 SetLastError( ERROR_INVALID_HANDLE
);
71 /***********************************************************************
74 DC
*alloc_dc_ptr( WORD magic
)
78 if (!(dc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dc
) ))) return NULL
;
80 dc
->nulldrv
.funcs
= &null_driver
;
81 dc
->nulldrv
.next
= NULL
;
82 dc
->physDev
= &dc
->nulldrv
;
83 dc
->thread
= GetCurrentThreadId();
98 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
103 dc
->hMetaClipRgn
= 0;
105 dc
->hPen
= GDI_inc_ref_count( GetStockObject( BLACK_PEN
));
106 dc
->hBrush
= GDI_inc_ref_count( GetStockObject( WHITE_BRUSH
));
107 dc
->hFont
= GDI_inc_ref_count( GetStockObject( SYSTEM_FONT
));
110 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
112 dc
->font_code_page
= CP_ACP
;
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 );
125 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
129 dc
->MapMode
= MM_TEXT
;
130 dc
->GraphicsMode
= GM_COMPATIBLE
;
131 dc
->pAbortProc
= NULL
;
134 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
135 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
136 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
137 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
138 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
139 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
140 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
141 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
142 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
143 dc
->vport2WorldValid
= TRUE
;
144 dc
->BoundsRect
.left
= 0;
145 dc
->BoundsRect
.top
= 0;
146 dc
->BoundsRect
.right
= 0;
147 dc
->BoundsRect
.bottom
= 0;
148 PATH_InitGdiPath(&dc
->path
);
150 if (!(dc
->hSelf
= alloc_gdi_handle( &dc
->header
, magic
, &dc_funcs
)))
152 HeapFree( GetProcessHeap(), 0, dc
);
155 dc
->nulldrv
.hdc
= dc
->hSelf
;
161 /***********************************************************************
164 static void free_dc_state( DC
*dc
)
166 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
167 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
168 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
169 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
170 PATH_DestroyGdiPath( &dc
->path
);
171 HeapFree( GetProcessHeap(), 0, dc
);
175 /***********************************************************************
178 void free_dc_ptr( DC
*dc
)
180 assert( dc
->refcount
== 1 );
182 while (dc
->physDev
!= &dc
->nulldrv
) pop_dc_driver( dc
, dc
->physDev
);
183 free_gdi_handle( dc
->hSelf
);
188 /***********************************************************************
191 * Retrieve a DC pointer but release the GDI lock.
193 DC
*get_dc_ptr( HDC hdc
)
195 DC
*dc
= get_dc_obj( hdc
);
196 if (!dc
) return NULL
;
198 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
200 dc
->thread
= GetCurrentThreadId();
202 else if (dc
->thread
!= GetCurrentThreadId())
204 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
205 GDI_ReleaseObj( hdc
);
208 else InterlockedIncrement( &dc
->refcount
);
210 GDI_ReleaseObj( hdc
);
215 /***********************************************************************
218 void release_dc_ptr( DC
*dc
)
223 ref
= InterlockedDecrement( &dc
->refcount
);
225 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
229 /***********************************************************************
232 * Make sure the DC vis region is up to date.
233 * This function may call up to USER so the GDI lock should _not_
234 * be held when calling it.
236 void update_dc( DC
*dc
)
238 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
239 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
243 /***********************************************************************
246 * Push a driver on top of the DC driver stack.
248 void push_dc_driver( DC
* dc
, PHYSDEV physdev
, const DC_FUNCTIONS
*funcs
)
250 physdev
->funcs
= funcs
;
251 physdev
->next
= dc
->physDev
;
252 physdev
->hdc
= dc
->hSelf
;
253 dc
->physDev
= physdev
;
257 /***********************************************************************
260 * Pop the top driver from the DC driver stack.
262 void pop_dc_driver( DC
* dc
, PHYSDEV physdev
)
264 assert( physdev
== dc
->physDev
);
265 assert( physdev
!= &dc
->nulldrv
);
266 dc
->physDev
= physdev
->next
;
267 physdev
->funcs
->pDeleteDC( physdev
);
271 /***********************************************************************
274 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
276 return DeleteDC( handle
);
280 /***********************************************************************
283 * Setup device-specific DC values for a newly created DC.
285 void DC_InitDC( DC
* dc
)
287 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRealizeDefaultPalette
);
288 physdev
->funcs
->pRealizeDefaultPalette( physdev
);
289 SetTextColor( dc
->hSelf
, dc
->textColor
);
290 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
291 SelectObject( dc
->hSelf
, dc
->hPen
);
292 SelectObject( dc
->hSelf
, dc
->hBrush
);
293 SelectObject( dc
->hSelf
, dc
->hFont
);
294 CLIPPING_UpdateGCRegion( dc
);
295 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
299 /***********************************************************************
302 * Computes the inverse of the transformation xformSrc and stores it to
303 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
306 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
310 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
311 xformSrc
->eM12
*xformSrc
->eM21
;
312 if (determinant
> -1e-12 && determinant
< 1e-12)
315 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
316 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
317 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
318 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
319 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
320 xformSrc
->eDy
* xformDest
->eM21
;
321 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
322 xformSrc
->eDy
* xformDest
->eM22
;
327 /* Construct a transformation to do the window-to-viewport conversion */
328 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
330 double scaleX
, scaleY
;
331 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
332 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
334 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
335 xform
->eM11
= scaleX
;
338 xform
->eM22
= scaleY
;
339 xform
->eDx
= (double)dc
->vportOrgX
- scaleX
* (double)dc
->wndOrgX
;
340 xform
->eDy
= (double)dc
->vportOrgY
- scaleY
* (double)dc
->wndOrgY
;
341 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
344 /***********************************************************************
347 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
348 * fields of the specified DC by creating a transformation that
349 * represents the current mapping mode and combining it with the DC's
350 * world transform. This function should be called whenever the
351 * parameters associated with the mapping mode (window and viewport
352 * extents and origins) or the world transform change.
354 void DC_UpdateXforms( DC
*dc
)
356 XFORM xformWnd2Vport
, oldworld2vport
;
358 construct_window_to_viewport(dc
, &xformWnd2Vport
);
360 oldworld2vport
= dc
->xformWorld2Vport
;
361 /* Combine with the world transformation */
362 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
365 /* Create inverse of world-to-viewport transformation */
366 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
367 &dc
->xformVport2World
);
369 /* Reselect the font and pen back into the dc so that the size
371 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
372 !GdiIsMetaFileDC(dc
->hSelf
))
374 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
375 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
380 /***********************************************************************
383 INT CDECL
nulldrv_SaveDC( PHYSDEV dev
)
385 DC
*newdc
, *dc
= get_nulldrv_dc( dev
);
387 if (!(newdc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc
)))) return 0;
388 newdc
->flags
= dc
->flags
;
389 newdc
->layout
= dc
->layout
;
390 newdc
->hPen
= dc
->hPen
;
391 newdc
->hBrush
= dc
->hBrush
;
392 newdc
->hFont
= dc
->hFont
;
393 newdc
->hBitmap
= dc
->hBitmap
;
394 newdc
->hDevice
= dc
->hDevice
;
395 newdc
->hPalette
= dc
->hPalette
;
396 newdc
->ROPmode
= dc
->ROPmode
;
397 newdc
->polyFillMode
= dc
->polyFillMode
;
398 newdc
->stretchBltMode
= dc
->stretchBltMode
;
399 newdc
->relAbsMode
= dc
->relAbsMode
;
400 newdc
->backgroundMode
= dc
->backgroundMode
;
401 newdc
->backgroundColor
= dc
->backgroundColor
;
402 newdc
->textColor
= dc
->textColor
;
403 newdc
->dcBrushColor
= dc
->dcBrushColor
;
404 newdc
->dcPenColor
= dc
->dcPenColor
;
405 newdc
->brushOrgX
= dc
->brushOrgX
;
406 newdc
->brushOrgY
= dc
->brushOrgY
;
407 newdc
->mapperFlags
= dc
->mapperFlags
;
408 newdc
->textAlign
= dc
->textAlign
;
409 newdc
->charExtra
= dc
->charExtra
;
410 newdc
->breakExtra
= dc
->breakExtra
;
411 newdc
->breakRem
= dc
->breakRem
;
412 newdc
->MapMode
= dc
->MapMode
;
413 newdc
->GraphicsMode
= dc
->GraphicsMode
;
414 newdc
->CursPosX
= dc
->CursPosX
;
415 newdc
->CursPosY
= dc
->CursPosY
;
416 newdc
->ArcDirection
= dc
->ArcDirection
;
417 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
418 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
419 newdc
->xformVport2World
= dc
->xformVport2World
;
420 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
421 newdc
->wndOrgX
= dc
->wndOrgX
;
422 newdc
->wndOrgY
= dc
->wndOrgY
;
423 newdc
->wndExtX
= dc
->wndExtX
;
424 newdc
->wndExtY
= dc
->wndExtY
;
425 newdc
->vportOrgX
= dc
->vportOrgX
;
426 newdc
->vportOrgY
= dc
->vportOrgY
;
427 newdc
->vportExtX
= dc
->vportExtX
;
428 newdc
->vportExtY
= dc
->vportExtY
;
429 newdc
->virtual_res
= dc
->virtual_res
;
430 newdc
->virtual_size
= dc
->virtual_size
;
431 newdc
->BoundsRect
= dc
->BoundsRect
;
432 newdc
->gdiFont
= dc
->gdiFont
;
434 PATH_InitGdiPath( &newdc
->path
);
436 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
441 newdc
->hMetaClipRgn
= 0;
444 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
445 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
449 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
450 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
453 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
455 if (!PATH_AssignGdiPath( &newdc
->path
, &dc
->path
))
457 release_dc_ptr( dc
);
458 free_dc_state( newdc
);
462 newdc
->saved_dc
= dc
->saved_dc
;
463 dc
->saved_dc
= newdc
;
464 return ++dc
->saveLevel
;
468 /***********************************************************************
471 BOOL CDECL
nulldrv_RestoreDC( PHYSDEV dev
, INT level
)
473 DC
*dcs
, *first_dcs
, *dc
= get_nulldrv_dc( dev
);
476 /* find the state level to restore */
478 if (abs(level
) > dc
->saveLevel
|| level
== 0) return FALSE
;
479 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
480 first_dcs
= dc
->saved_dc
;
481 for (dcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
484 /* restore the state */
486 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
)) return FALSE
;
488 dc
->flags
= dcs
->flags
;
489 dc
->layout
= dcs
->layout
;
490 dc
->hDevice
= dcs
->hDevice
;
491 dc
->ROPmode
= dcs
->ROPmode
;
492 dc
->polyFillMode
= dcs
->polyFillMode
;
493 dc
->stretchBltMode
= dcs
->stretchBltMode
;
494 dc
->relAbsMode
= dcs
->relAbsMode
;
495 dc
->backgroundMode
= dcs
->backgroundMode
;
496 dc
->backgroundColor
= dcs
->backgroundColor
;
497 dc
->textColor
= dcs
->textColor
;
498 dc
->dcBrushColor
= dcs
->dcBrushColor
;
499 dc
->dcPenColor
= dcs
->dcPenColor
;
500 dc
->brushOrgX
= dcs
->brushOrgX
;
501 dc
->brushOrgY
= dcs
->brushOrgY
;
502 dc
->mapperFlags
= dcs
->mapperFlags
;
503 dc
->textAlign
= dcs
->textAlign
;
504 dc
->charExtra
= dcs
->charExtra
;
505 dc
->breakExtra
= dcs
->breakExtra
;
506 dc
->breakRem
= dcs
->breakRem
;
507 dc
->MapMode
= dcs
->MapMode
;
508 dc
->GraphicsMode
= dcs
->GraphicsMode
;
509 dc
->CursPosX
= dcs
->CursPosX
;
510 dc
->CursPosY
= dcs
->CursPosY
;
511 dc
->ArcDirection
= dcs
->ArcDirection
;
512 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
513 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
514 dc
->xformVport2World
= dcs
->xformVport2World
;
515 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
516 dc
->BoundsRect
= dcs
->BoundsRect
;
518 dc
->wndOrgX
= dcs
->wndOrgX
;
519 dc
->wndOrgY
= dcs
->wndOrgY
;
520 dc
->wndExtX
= dcs
->wndExtX
;
521 dc
->wndExtY
= dcs
->wndExtY
;
522 dc
->vportOrgX
= dcs
->vportOrgX
;
523 dc
->vportOrgY
= dcs
->vportOrgY
;
524 dc
->vportExtX
= dcs
->vportExtX
;
525 dc
->vportExtY
= dcs
->vportExtY
;
526 dc
->virtual_res
= dcs
->virtual_res
;
527 dc
->virtual_size
= dcs
->virtual_size
;
531 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
532 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
536 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
541 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
542 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
546 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
549 DC_UpdateXforms( dc
);
550 CLIPPING_UpdateGCRegion( dc
);
552 SelectObject( dev
->hdc
, dcs
->hBitmap
);
553 SelectObject( dev
->hdc
, dcs
->hBrush
);
554 SelectObject( dev
->hdc
, dcs
->hFont
);
555 SelectObject( dev
->hdc
, dcs
->hPen
);
556 SetBkColor( dev
->hdc
, dcs
->backgroundColor
);
557 SetTextColor( dev
->hdc
, dcs
->textColor
);
558 GDISelectPalette( dev
->hdc
, dcs
->hPalette
, FALSE
);
560 dc
->saved_dc
= dcs
->saved_dc
;
562 dc
->saveLevel
= save_level
- 1;
564 /* now destroy all the saved DCs */
568 DC
*next
= first_dcs
->saved_dc
;
569 free_dc_state( first_dcs
);
576 /***********************************************************************
579 INT WINAPI
SaveDC( HDC hdc
)
584 if ((dc
= get_dc_ptr( hdc
)))
586 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSaveDC
);
587 ret
= physdev
->funcs
->pSaveDC( physdev
);
588 release_dc_ptr( dc
);
594 /***********************************************************************
595 * RestoreDC (GDI32.@)
597 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
600 BOOL success
= FALSE
;
602 TRACE("%p %d\n", hdc
, level
);
603 if ((dc
= get_dc_ptr( hdc
)))
605 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRestoreDC
);
607 success
= physdev
->funcs
->pRestoreDC( physdev
, level
);
608 release_dc_ptr( dc
);
614 /***********************************************************************
615 * CreateDCW (GDI32.@)
617 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
618 const DEVMODEW
*initData
)
622 const DC_FUNCTIONS
*funcs
;
627 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
631 ERR( "no device found for %s\n", debugstr_w(device
) );
634 strcpyW(buf
, driver
);
637 if (!(funcs
= DRIVER_load_driver( buf
)))
639 ERR( "no driver found for %s\n", debugstr_w(buf
) );
642 if (!(dc
= alloc_dc_ptr( OBJ_DC
))) goto error
;
645 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
646 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
648 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
649 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
651 if (funcs
->pCreateDC
)
654 if (!funcs
->pCreateDC( hdc
, &physdev
, buf
, device
, output
, initData
))
656 WARN("creation aborted by device\n" );
659 push_dc_driver( dc
, physdev
, funcs
);
662 dc
->vis_rect
.left
= 0;
663 dc
->vis_rect
.top
= 0;
664 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
665 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
666 SetRectRgn(dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
, dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
669 release_dc_ptr( dc
);
673 if (dc
) free_dc_ptr( dc
);
678 /***********************************************************************
679 * CreateDCA (GDI32.@)
681 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
682 const DEVMODEA
*initData
)
684 UNICODE_STRING driverW
, deviceW
, outputW
;
688 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
689 else driverW
.Buffer
= NULL
;
691 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
692 else deviceW
.Buffer
= NULL
;
694 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
695 else outputW
.Buffer
= NULL
;
700 /* don't convert initData for DISPLAY driver, it's not used */
701 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
702 initDataW
= GdiConvertToDevmodeW(initData
);
705 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
707 RtlFreeUnicodeString(&driverW
);
708 RtlFreeUnicodeString(&deviceW
);
709 RtlFreeUnicodeString(&outputW
);
710 HeapFree(GetProcessHeap(), 0, initDataW
);
715 /***********************************************************************
716 * CreateICA (GDI32.@)
718 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
719 const DEVMODEA
* initData
)
721 /* Nothing special yet for ICs */
722 return CreateDCA( driver
, device
, output
, initData
);
726 /***********************************************************************
727 * CreateICW (GDI32.@)
729 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
730 const DEVMODEW
* initData
)
732 /* Nothing special yet for ICs */
733 return CreateDCW( driver
, device
, output
, initData
);
737 /***********************************************************************
738 * CreateCompatibleDC (GDI32.@)
740 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
744 const DC_FUNCTIONS
*funcs
= NULL
;
745 PHYSDEV physDev
= NULL
;
751 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
752 physDev
= GET_DC_PHYSDEV( origDC
, pCreateDC
);
753 if (physDev
!= &origDC
->nulldrv
) funcs
= physDev
->funcs
;
755 release_dc_ptr( origDC
);
758 if (!funcs
&& !(funcs
= DRIVER_get_display_driver())) return 0;
760 if (!(dc
= alloc_dc_ptr( OBJ_MEMDC
))) goto error
;
762 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
764 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
765 dc
->vis_rect
.left
= 0;
766 dc
->vis_rect
.top
= 0;
767 dc
->vis_rect
.right
= 1;
768 dc
->vis_rect
.bottom
= 1;
769 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
773 /* Pass the driver-specific physical device info into
774 * the new DC. The driver may use this read-only info
775 * while creating the compatible DC. */
776 if (funcs
->pCreateDC
)
778 if (!funcs
->pCreateDC( dc
->hSelf
, &physDev
, NULL
, NULL
, NULL
, NULL
))
780 WARN("creation aborted by device\n");
783 push_dc_driver( dc
, physDev
, funcs
);
786 release_dc_ptr( dc
);
790 if (dc
) free_dc_ptr( dc
);
795 /***********************************************************************
798 BOOL WINAPI
DeleteDC( HDC hdc
)
806 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
807 if (dc
->refcount
!= 1)
809 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
810 release_dc_ptr( dc
);
814 /* Call hook procedure to check whether is it OK to delete this DC */
815 if (dc
->hookProc
&& !dc
->hookProc( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
817 release_dc_ptr( dc
);
821 while (dc
->saveLevel
)
823 DC
*dcs
= dc
->saved_dc
;
824 dc
->saved_dc
= dcs
->saved_dc
;
826 free_dc_state( dcs
);
829 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
830 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
831 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
832 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
839 /***********************************************************************
842 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
847 if ((dc
= get_dc_ptr( hdc
)))
849 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pResetDC
);
850 ret
= physdev
->funcs
->pResetDC( physdev
, devmode
);
851 if (ret
) /* reset the visible region */
854 dc
->vis_rect
.left
= 0;
855 dc
->vis_rect
.top
= 0;
856 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
857 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
858 SetRectRgn( dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
,
859 dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
860 CLIPPING_UpdateGCRegion( dc
);
862 release_dc_ptr( dc
);
868 /***********************************************************************
871 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
876 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
877 else devmodeW
= NULL
;
879 ret
= ResetDCW(hdc
, devmodeW
);
881 HeapFree(GetProcessHeap(), 0, devmodeW
);
886 /***********************************************************************
887 * GetDeviceCaps (GDI32.@)
889 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
894 if ((dc
= get_dc_ptr( hdc
)))
896 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceCaps
);
897 ret
= physdev
->funcs
->pGetDeviceCaps( physdev
, cap
);
898 release_dc_ptr( dc
);
904 /***********************************************************************
905 * GetBkColor (GDI32.@)
907 COLORREF WINAPI
GetBkColor( HDC hdc
)
910 DC
* dc
= get_dc_ptr( hdc
);
913 ret
= dc
->backgroundColor
;
914 release_dc_ptr( dc
);
920 /***********************************************************************
921 * SetBkColor (GDI32.@)
923 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
925 COLORREF ret
= CLR_INVALID
;
926 DC
* dc
= get_dc_ptr( hdc
);
928 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
932 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkColor
);
933 color
= physdev
->funcs
->pSetBkColor( physdev
, color
);
934 if (color
!= CLR_INVALID
)
936 ret
= dc
->backgroundColor
;
937 dc
->backgroundColor
= color
;
939 release_dc_ptr( dc
);
945 /***********************************************************************
946 * GetTextColor (GDI32.@)
948 COLORREF WINAPI
GetTextColor( HDC hdc
)
951 DC
* dc
= get_dc_ptr( hdc
);
955 release_dc_ptr( dc
);
961 /***********************************************************************
962 * SetTextColor (GDI32.@)
964 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
966 COLORREF ret
= CLR_INVALID
;
967 DC
* dc
= get_dc_ptr( hdc
);
969 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
973 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
974 color
= physdev
->funcs
->pSetTextColor( physdev
, color
);
975 if (color
!= CLR_INVALID
)
978 dc
->textColor
= color
;
980 release_dc_ptr( dc
);
986 /***********************************************************************
987 * GetTextAlign (GDI32.@)
989 UINT WINAPI
GetTextAlign( HDC hdc
)
992 DC
* dc
= get_dc_ptr( hdc
);
996 release_dc_ptr( dc
);
1002 /***********************************************************************
1003 * SetTextAlign (GDI32.@)
1005 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1007 UINT ret
= GDI_ERROR
;
1008 DC
*dc
= get_dc_ptr( hdc
);
1010 TRACE("hdc=%p align=%d\n", hdc
, align
);
1014 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
1015 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
1016 if (align
!= GDI_ERROR
)
1018 ret
= dc
->textAlign
;
1019 dc
->textAlign
= align
;
1021 release_dc_ptr( dc
);
1026 /***********************************************************************
1027 * GetDCOrgEx (GDI32.@)
1029 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1033 if (!lpp
) return FALSE
;
1034 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1035 lpp
->x
= dc
->vis_rect
.left
;
1036 lpp
->y
= dc
->vis_rect
.top
;
1037 release_dc_ptr( dc
);
1042 /***********************************************************************
1043 * GetGraphicsMode (GDI32.@)
1045 INT WINAPI
GetGraphicsMode( HDC hdc
)
1048 DC
* dc
= get_dc_ptr( hdc
);
1051 ret
= dc
->GraphicsMode
;
1052 release_dc_ptr( dc
);
1058 /***********************************************************************
1059 * SetGraphicsMode (GDI32.@)
1061 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1064 DC
*dc
= get_dc_ptr( hdc
);
1066 /* One would think that setting the graphics mode to GM_COMPATIBLE
1067 * would also reset the world transformation matrix to the unity
1068 * matrix. However, in Windows, this is not the case. This doesn't
1069 * make a lot of sense to me, but that's the way it is.
1072 if ((mode
> 0) && (mode
<= GM_LAST
))
1074 ret
= dc
->GraphicsMode
;
1075 dc
->GraphicsMode
= mode
;
1077 release_dc_ptr( dc
);
1082 /***********************************************************************
1083 * GetArcDirection (GDI32.@)
1085 INT WINAPI
GetArcDirection( HDC hdc
)
1088 DC
* dc
= get_dc_ptr( hdc
);
1091 ret
= dc
->ArcDirection
;
1092 release_dc_ptr( dc
);
1098 /***********************************************************************
1099 * SetArcDirection (GDI32.@)
1101 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1106 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1108 SetLastError(ERROR_INVALID_PARAMETER
);
1112 if ((dc
= get_dc_ptr( hdc
)))
1114 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1115 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1118 ret
= dc
->ArcDirection
;
1119 dc
->ArcDirection
= dir
;
1121 release_dc_ptr( dc
);
1127 /***********************************************************************
1128 * GetWorldTransform (GDI32.@)
1130 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1133 if (!xform
) return FALSE
;
1134 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1135 *xform
= dc
->xformWorld2Wnd
;
1136 release_dc_ptr( dc
);
1141 /***********************************************************************
1142 * GetTransform (GDI32.@)
1146 * Returns one of the co-ordinate space transforms
1149 * hdc [I] Device context.
1150 * which [I] Which xform to return:
1151 * 0x203 World -> Page transform (that set by SetWorldTransform).
1152 * 0x304 Page -> Device transform (the mapping mode transform).
1153 * 0x204 World -> Device transform (the combination of the above two).
1154 * 0x402 Device -> World transform (the inversion of the above).
1155 * xform [O] The xform.
1158 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1161 DC
*dc
= get_dc_ptr( hdc
);
1162 if (!dc
) return FALSE
;
1167 *xform
= dc
->xformWorld2Wnd
;
1171 construct_window_to_viewport(dc
, xform
);
1175 *xform
= dc
->xformWorld2Vport
;
1179 *xform
= dc
->xformVport2World
;
1183 FIXME("Unknown code %x\n", which
);
1187 release_dc_ptr( dc
);
1192 /****************************************************************************
1193 * CombineTransform [GDI32.@]
1194 * Combines two transformation matrices.
1197 * xformResult [O] Stores the result of combining the two matrices
1198 * xform1 [I] Specifies the first matrix to apply
1199 * xform2 [I] Specifies the second matrix to apply
1202 * The same matrix can be passed in for more than one of the parameters.
1206 * Failure: FALSE. Use GetLastError() to determine the cause.
1208 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1209 const XFORM
*xform2
)
1213 /* Check for illegal parameters */
1214 if (!xformResult
|| !xform1
|| !xform2
)
1217 /* Create the result in a temporary XFORM, since xformResult may be
1218 * equal to xform1 or xform2 */
1219 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1220 xform1
->eM12
* xform2
->eM21
;
1221 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1222 xform1
->eM12
* xform2
->eM22
;
1223 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1224 xform1
->eM22
* xform2
->eM21
;
1225 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1226 xform1
->eM22
* xform2
->eM22
;
1227 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1228 xform1
->eDy
* xform2
->eM21
+
1230 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1231 xform1
->eDy
* xform2
->eM22
+
1234 /* Copy the result to xformResult */
1235 *xformResult
= xformTemp
;
1241 /***********************************************************************
1242 * SetDCHook (GDI32.@)
1244 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1246 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1248 DC
*dc
= get_dc_ptr( hdc
);
1250 if (!dc
) return FALSE
;
1252 dc
->dwHookData
= dwHookData
;
1253 dc
->hookProc
= hookProc
;
1254 release_dc_ptr( dc
);
1259 /***********************************************************************
1260 * GetDCHook (GDI32.@)
1262 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1264 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1266 DC
*dc
= get_dc_ptr( hdc
);
1270 if (proc
) *proc
= dc
->hookProc
;
1271 ret
= dc
->dwHookData
;
1272 release_dc_ptr( dc
);
1277 /***********************************************************************
1278 * SetHookFlags (GDI32.@)
1280 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1282 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1284 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1289 /* "Undocumented Windows" info is slightly confusing. */
1291 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1293 if (flags
& DCHF_INVALIDATEVISRGN
)
1294 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1295 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1296 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1298 GDI_ReleaseObj( hdc
);
1302 /***********************************************************************
1303 * SetICMMode (GDI32.@)
1305 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1307 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1308 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1309 if (iEnableICM
== ICM_ON
) return 0;
1310 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1314 /***********************************************************************
1315 * GetDeviceGammaRamp (GDI32.@)
1317 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1320 DC
*dc
= get_dc_ptr( hDC
);
1324 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceGammaRamp
);
1325 ret
= physdev
->funcs
->pGetDeviceGammaRamp( physdev
, ptr
);
1326 release_dc_ptr( dc
);
1331 /***********************************************************************
1332 * SetDeviceGammaRamp (GDI32.@)
1334 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1337 DC
*dc
= get_dc_ptr( hDC
);
1341 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDeviceGammaRamp
);
1342 ret
= physdev
->funcs
->pSetDeviceGammaRamp( physdev
, ptr
);
1343 release_dc_ptr( dc
);
1348 /***********************************************************************
1349 * GetColorSpace (GDI32.@)
1351 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1353 /*FIXME Need to to whatever GetColorSpace actually does */
1357 /***********************************************************************
1358 * CreateColorSpaceA (GDI32.@)
1360 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1366 /***********************************************************************
1367 * CreateColorSpaceW (GDI32.@)
1369 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1375 /***********************************************************************
1376 * DeleteColorSpace (GDI32.@)
1378 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1385 /***********************************************************************
1386 * SetColorSpace (GDI32.@)
1388 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1395 /***********************************************************************
1396 * GetBoundsRect (GDI32.@)
1398 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1401 DC
*dc
= get_dc_ptr( hdc
);
1403 if ( !dc
) return 0;
1407 *rect
= dc
->BoundsRect
;
1408 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1413 if (flags
& DCB_RESET
)
1415 dc
->BoundsRect
.left
= 0;
1416 dc
->BoundsRect
.top
= 0;
1417 dc
->BoundsRect
.right
= 0;
1418 dc
->BoundsRect
.bottom
= 0;
1419 dc
->flags
&= ~DC_BOUNDS_SET
;
1421 release_dc_ptr( dc
);
1426 /***********************************************************************
1427 * SetBoundsRect (GDI32.@)
1429 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1434 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1435 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1437 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1438 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1440 if (flags
& DCB_RESET
)
1442 dc
->BoundsRect
.left
= 0;
1443 dc
->BoundsRect
.top
= 0;
1444 dc
->BoundsRect
.right
= 0;
1445 dc
->BoundsRect
.bottom
= 0;
1446 dc
->flags
&= ~DC_BOUNDS_SET
;
1449 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1451 if (dc
->flags
& DC_BOUNDS_SET
)
1453 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1454 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1455 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1456 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1460 dc
->BoundsRect
= *rect
;
1461 dc
->flags
|= DC_BOUNDS_SET
;
1465 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1466 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1468 release_dc_ptr( dc
);
1473 /***********************************************************************
1474 * GetRelAbs (GDI32.@)
1476 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1479 DC
*dc
= get_dc_ptr( hdc
);
1482 ret
= dc
->relAbsMode
;
1483 release_dc_ptr( dc
);
1491 /***********************************************************************
1492 * GetBkMode (GDI32.@)
1494 INT WINAPI
GetBkMode( HDC hdc
)
1497 DC
* dc
= get_dc_ptr( hdc
);
1500 ret
= dc
->backgroundMode
;
1501 release_dc_ptr( dc
);
1507 /***********************************************************************
1508 * SetBkMode (GDI32.@)
1510 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1515 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1517 SetLastError(ERROR_INVALID_PARAMETER
);
1520 if ((dc
= get_dc_ptr( hdc
)))
1522 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1523 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1526 ret
= dc
->backgroundMode
;
1527 dc
->backgroundMode
= mode
;
1529 release_dc_ptr( dc
);
1535 /***********************************************************************
1538 INT WINAPI
GetROP2( HDC hdc
)
1541 DC
* dc
= get_dc_ptr( hdc
);
1545 release_dc_ptr( dc
);
1551 /***********************************************************************
1554 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1559 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1561 SetLastError(ERROR_INVALID_PARAMETER
);
1564 if ((dc
= get_dc_ptr( hdc
)))
1566 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1567 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1573 release_dc_ptr( dc
);
1579 /***********************************************************************
1580 * SetRelAbs (GDI32.@)
1582 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1587 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1589 SetLastError(ERROR_INVALID_PARAMETER
);
1592 if ((dc
= get_dc_ptr( hdc
)))
1594 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1595 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1598 ret
= dc
->relAbsMode
;
1599 dc
->relAbsMode
= mode
;
1601 release_dc_ptr( dc
);
1607 /***********************************************************************
1608 * GetPolyFillMode (GDI32.@)
1610 INT WINAPI
GetPolyFillMode( HDC hdc
)
1613 DC
* dc
= get_dc_ptr( hdc
);
1616 ret
= dc
->polyFillMode
;
1617 release_dc_ptr( dc
);
1623 /***********************************************************************
1624 * SetPolyFillMode (GDI32.@)
1626 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1631 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1633 SetLastError(ERROR_INVALID_PARAMETER
);
1636 if ((dc
= get_dc_ptr( hdc
)))
1638 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1639 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1642 ret
= dc
->polyFillMode
;
1643 dc
->polyFillMode
= mode
;
1645 release_dc_ptr( dc
);
1651 /***********************************************************************
1652 * GetStretchBltMode (GDI32.@)
1654 INT WINAPI
GetStretchBltMode( HDC hdc
)
1657 DC
* dc
= get_dc_ptr( hdc
);
1660 ret
= dc
->stretchBltMode
;
1661 release_dc_ptr( dc
);
1667 /***********************************************************************
1668 * SetStretchBltMode (GDI32.@)
1670 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1675 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1677 SetLastError(ERROR_INVALID_PARAMETER
);
1680 if ((dc
= get_dc_ptr( hdc
)))
1682 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1683 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1686 ret
= dc
->stretchBltMode
;
1687 dc
->stretchBltMode
= mode
;
1689 release_dc_ptr( dc
);
1695 /***********************************************************************
1696 * GetMapMode (GDI32.@)
1698 INT WINAPI
GetMapMode( HDC hdc
)
1701 DC
* dc
= get_dc_ptr( hdc
);
1705 release_dc_ptr( dc
);
1711 /***********************************************************************
1712 * GetBrushOrgEx (GDI32.@)
1714 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1716 DC
* dc
= get_dc_ptr( hdc
);
1717 if (!dc
) return FALSE
;
1718 pt
->x
= dc
->brushOrgX
;
1719 pt
->y
= dc
->brushOrgY
;
1720 release_dc_ptr( dc
);
1725 /***********************************************************************
1726 * GetCurrentPositionEx (GDI32.@)
1728 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1730 DC
* dc
= get_dc_ptr( hdc
);
1731 if (!dc
) return FALSE
;
1732 pt
->x
= dc
->CursPosX
;
1733 pt
->y
= dc
->CursPosY
;
1734 release_dc_ptr( dc
);
1739 /***********************************************************************
1740 * GetViewportExtEx (GDI32.@)
1742 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1744 DC
* dc
= get_dc_ptr( hdc
);
1745 if (!dc
) return FALSE
;
1746 size
->cx
= dc
->vportExtX
;
1747 size
->cy
= dc
->vportExtY
;
1748 release_dc_ptr( dc
);
1753 /***********************************************************************
1754 * GetViewportOrgEx (GDI32.@)
1756 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1758 DC
* dc
= get_dc_ptr( hdc
);
1759 if (!dc
) return FALSE
;
1760 pt
->x
= dc
->vportOrgX
;
1761 pt
->y
= dc
->vportOrgY
;
1762 release_dc_ptr( dc
);
1767 /***********************************************************************
1768 * GetWindowExtEx (GDI32.@)
1770 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1772 DC
* dc
= get_dc_ptr( hdc
);
1773 if (!dc
) return FALSE
;
1774 size
->cx
= dc
->wndExtX
;
1775 size
->cy
= dc
->wndExtY
;
1776 release_dc_ptr( dc
);
1781 /***********************************************************************
1782 * GetWindowOrgEx (GDI32.@)
1784 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1786 DC
* dc
= get_dc_ptr( hdc
);
1787 if (!dc
) return FALSE
;
1788 pt
->x
= dc
->wndOrgX
;
1789 pt
->y
= dc
->wndOrgY
;
1790 release_dc_ptr( dc
);
1795 /***********************************************************************
1796 * GetLayout (GDI32.@)
1798 * Gets left->right or right->left text layout flags of a dc.
1801 DWORD WINAPI
GetLayout(HDC hdc
)
1803 DWORD layout
= GDI_ERROR
;
1805 DC
* dc
= get_dc_ptr( hdc
);
1808 layout
= dc
->layout
;
1809 release_dc_ptr( dc
);
1812 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1817 /***********************************************************************
1818 * SetLayout (GDI32.@)
1820 * Sets left->right or right->left text layout flags of a dc.
1823 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1825 DWORD oldlayout
= GDI_ERROR
;
1827 DC
* dc
= get_dc_ptr( hdc
);
1830 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetLayout
);
1831 layout
= physdev
->funcs
->pSetLayout( physdev
, layout
);
1832 if (layout
!= GDI_ERROR
)
1834 oldlayout
= dc
->layout
;
1835 dc
->layout
= layout
;
1836 if (layout
!= oldlayout
)
1838 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1839 DC_UpdateXforms( dc
);
1842 release_dc_ptr( dc
);
1845 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1850 /***********************************************************************
1851 * GetDCBrushColor (GDI32.@)
1853 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1856 COLORREF dcBrushColor
= CLR_INVALID
;
1858 TRACE("hdc(%p)\n", hdc
);
1860 dc
= get_dc_ptr( hdc
);
1863 dcBrushColor
= dc
->dcBrushColor
;
1864 release_dc_ptr( dc
);
1867 return dcBrushColor
;
1870 /***********************************************************************
1871 * SetDCBrushColor (GDI32.@)
1873 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1876 COLORREF oldClr
= CLR_INVALID
;
1878 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1880 dc
= get_dc_ptr( hdc
);
1883 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
1884 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
1885 if (crColor
!= CLR_INVALID
)
1887 oldClr
= dc
->dcBrushColor
;
1888 dc
->dcBrushColor
= crColor
;
1890 release_dc_ptr( dc
);
1896 /***********************************************************************
1897 * GetDCPenColor (GDI32.@)
1899 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1902 COLORREF dcPenColor
= CLR_INVALID
;
1904 TRACE("hdc(%p)\n", hdc
);
1906 dc
= get_dc_ptr( hdc
);
1909 dcPenColor
= dc
->dcPenColor
;
1910 release_dc_ptr( dc
);
1916 /***********************************************************************
1917 * SetDCPenColor (GDI32.@)
1919 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1922 COLORREF oldClr
= CLR_INVALID
;
1924 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1926 dc
= get_dc_ptr( hdc
);
1929 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
1930 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
1931 if (crColor
!= CLR_INVALID
)
1933 oldClr
= dc
->dcPenColor
;
1934 dc
->dcPenColor
= crColor
;
1936 release_dc_ptr( dc
);
1942 /***********************************************************************
1943 * CancelDC (GDI32.@)
1945 BOOL WINAPI
CancelDC(HDC hdc
)
1951 /*******************************************************************
1952 * GetMiterLimit [GDI32.@]
1956 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
1961 TRACE("(%p,%p)\n", hdc
, peLimit
);
1963 dc
= get_dc_ptr( hdc
);
1967 *peLimit
= dc
->miterLimit
;
1969 release_dc_ptr( dc
);
1975 /*******************************************************************
1976 * SetMiterLimit [GDI32.@]
1980 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
1985 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
1987 dc
= get_dc_ptr( hdc
);
1991 *peOldLimit
= dc
->miterLimit
;
1992 dc
->miterLimit
= eNewLimit
;
1993 release_dc_ptr( dc
);
1999 /*******************************************************************
2000 * GdiIsMetaPrintDC [GDI32.@]
2002 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2008 /*******************************************************************
2009 * GdiIsMetaFileDC [GDI32.@]
2011 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2015 switch( GetObjectType( hdc
) )
2024 /*******************************************************************
2025 * GdiIsPlayMetafileDC [GDI32.@]
2027 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)