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(), HEAP_ZERO_MEMORY
, sizeof(*dc
) ))) return NULL
;
80 dc
->nulldrv
.funcs
= &null_driver
;
81 dc
->physDev
= &dc
->nulldrv
;
82 dc
->thread
= GetCurrentThreadId();
88 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
89 dc
->hPen
= GDI_inc_ref_count( GetStockObject( BLACK_PEN
));
90 dc
->hBrush
= GDI_inc_ref_count( GetStockObject( WHITE_BRUSH
));
91 dc
->hFont
= GDI_inc_ref_count( GetStockObject( SYSTEM_FONT
));
92 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
93 dc
->font_code_page
= CP_ACP
;
94 dc
->ROPmode
= R2_COPYPEN
;
95 dc
->polyFillMode
= ALTERNATE
;
96 dc
->stretchBltMode
= BLACKONWHITE
;
97 dc
->relAbsMode
= ABSOLUTE
;
98 dc
->backgroundMode
= OPAQUE
;
99 dc
->backgroundColor
= RGB( 255, 255, 255 );
100 dc
->dcBrushColor
= RGB( 255, 255, 255 );
101 dc
->dcPenColor
= RGB( 0, 0, 0 );
102 dc
->textColor
= RGB( 0, 0, 0 );
103 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
104 dc
->MapMode
= MM_TEXT
;
105 dc
->GraphicsMode
= GM_COMPATIBLE
;
106 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
107 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
108 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
109 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
110 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
111 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
112 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
113 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
114 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
115 dc
->vport2WorldValid
= TRUE
;
117 reset_bounds( &dc
->bounds
);
119 if (!(dc
->hSelf
= alloc_gdi_handle( &dc
->header
, magic
, &dc_funcs
)))
121 HeapFree( GetProcessHeap(), 0, dc
);
124 dc
->nulldrv
.hdc
= dc
->hSelf
;
126 if (font_driver
&& !font_driver
->pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
136 /***********************************************************************
139 static void free_dc_state( DC
*dc
)
141 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
142 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
143 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
144 if (dc
->region
) DeleteObject( dc
->region
);
145 if (dc
->path
) free_gdi_path( dc
->path
);
146 HeapFree( GetProcessHeap(), 0, dc
);
150 /***********************************************************************
153 void free_dc_ptr( DC
*dc
)
155 assert( dc
->refcount
== 1 );
157 while (dc
->physDev
!= &dc
->nulldrv
)
159 PHYSDEV physdev
= dc
->physDev
;
160 dc
->physDev
= physdev
->next
;
161 physdev
->funcs
->pDeleteDC( physdev
);
163 free_gdi_handle( dc
->hSelf
);
168 /***********************************************************************
171 * Retrieve a DC pointer but release the GDI lock.
173 DC
*get_dc_ptr( HDC hdc
)
175 DC
*dc
= get_dc_obj( hdc
);
176 if (!dc
) return NULL
;
178 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
180 dc
->thread
= GetCurrentThreadId();
182 else if (dc
->thread
!= GetCurrentThreadId())
184 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
185 GDI_ReleaseObj( hdc
);
188 else InterlockedIncrement( &dc
->refcount
);
190 GDI_ReleaseObj( hdc
);
195 /***********************************************************************
198 void release_dc_ptr( DC
*dc
)
203 ref
= InterlockedDecrement( &dc
->refcount
);
205 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
209 /***********************************************************************
212 * Make sure the DC vis region is up to date.
213 * This function may call up to USER so the GDI lock should _not_
214 * be held when calling it.
216 void update_dc( DC
*dc
)
218 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
219 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
223 /***********************************************************************
226 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
228 return DeleteDC( handle
);
232 /***********************************************************************
235 * Setup device-specific DC values for a newly created DC.
237 void DC_InitDC( DC
* dc
)
239 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRealizeDefaultPalette
);
240 physdev
->funcs
->pRealizeDefaultPalette( physdev
);
241 SetTextColor( dc
->hSelf
, dc
->textColor
);
242 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
243 SelectObject( dc
->hSelf
, dc
->hPen
);
244 SelectObject( dc
->hSelf
, dc
->hBrush
);
245 SelectObject( dc
->hSelf
, dc
->hFont
);
246 update_dc_clipping( dc
);
247 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
248 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
249 physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
);
253 /***********************************************************************
256 * Computes the inverse of the transformation xformSrc and stores it to
257 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
260 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
264 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
265 xformSrc
->eM12
*xformSrc
->eM21
;
266 if (determinant
> -1e-12 && determinant
< 1e-12)
269 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
270 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
271 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
272 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
273 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
274 xformSrc
->eDy
* xformDest
->eM21
;
275 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
276 xformSrc
->eDy
* xformDest
->eM22
;
281 /* Construct a transformation to do the window-to-viewport conversion */
282 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
284 double scaleX
, scaleY
;
285 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
286 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
288 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
289 xform
->eM11
= scaleX
;
292 xform
->eM22
= scaleY
;
293 xform
->eDx
= (double)dc
->vportOrgX
- scaleX
* (double)dc
->wndOrgX
;
294 xform
->eDy
= (double)dc
->vportOrgY
- scaleY
* (double)dc
->wndOrgY
;
295 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
298 /***********************************************************************
301 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
302 * fields of the specified DC by creating a transformation that
303 * represents the current mapping mode and combining it with the DC's
304 * world transform. This function should be called whenever the
305 * parameters associated with the mapping mode (window and viewport
306 * extents and origins) or the world transform change.
308 void DC_UpdateXforms( DC
*dc
)
310 XFORM xformWnd2Vport
, oldworld2vport
;
312 construct_window_to_viewport(dc
, &xformWnd2Vport
);
314 oldworld2vport
= dc
->xformWorld2Vport
;
315 /* Combine with the world transformation */
316 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
319 /* Create inverse of world-to-viewport transformation */
320 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
321 &dc
->xformVport2World
);
323 /* Reselect the font and pen back into the dc so that the size
325 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
326 !GdiIsMetaFileDC(dc
->hSelf
))
328 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
329 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
334 /***********************************************************************
337 INT
nulldrv_SaveDC( PHYSDEV dev
)
339 DC
*newdc
, *dc
= get_nulldrv_dc( dev
);
341 if (!(newdc
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*newdc
)))) return 0;
342 newdc
->layout
= dc
->layout
;
343 newdc
->hPen
= dc
->hPen
;
344 newdc
->hBrush
= dc
->hBrush
;
345 newdc
->hFont
= dc
->hFont
;
346 newdc
->hBitmap
= dc
->hBitmap
;
347 newdc
->hDevice
= dc
->hDevice
;
348 newdc
->hPalette
= dc
->hPalette
;
349 newdc
->ROPmode
= dc
->ROPmode
;
350 newdc
->polyFillMode
= dc
->polyFillMode
;
351 newdc
->stretchBltMode
= dc
->stretchBltMode
;
352 newdc
->relAbsMode
= dc
->relAbsMode
;
353 newdc
->backgroundMode
= dc
->backgroundMode
;
354 newdc
->backgroundColor
= dc
->backgroundColor
;
355 newdc
->textColor
= dc
->textColor
;
356 newdc
->dcBrushColor
= dc
->dcBrushColor
;
357 newdc
->dcPenColor
= dc
->dcPenColor
;
358 newdc
->brushOrgX
= dc
->brushOrgX
;
359 newdc
->brushOrgY
= dc
->brushOrgY
;
360 newdc
->mapperFlags
= dc
->mapperFlags
;
361 newdc
->textAlign
= dc
->textAlign
;
362 newdc
->charExtra
= dc
->charExtra
;
363 newdc
->breakExtra
= dc
->breakExtra
;
364 newdc
->breakRem
= dc
->breakRem
;
365 newdc
->MapMode
= dc
->MapMode
;
366 newdc
->GraphicsMode
= dc
->GraphicsMode
;
367 newdc
->CursPosX
= dc
->CursPosX
;
368 newdc
->CursPosY
= dc
->CursPosY
;
369 newdc
->ArcDirection
= dc
->ArcDirection
;
370 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
371 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
372 newdc
->xformVport2World
= dc
->xformVport2World
;
373 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
374 newdc
->wndOrgX
= dc
->wndOrgX
;
375 newdc
->wndOrgY
= dc
->wndOrgY
;
376 newdc
->wndExtX
= dc
->wndExtX
;
377 newdc
->wndExtY
= dc
->wndExtY
;
378 newdc
->vportOrgX
= dc
->vportOrgX
;
379 newdc
->vportOrgY
= dc
->vportOrgY
;
380 newdc
->vportExtX
= dc
->vportExtX
;
381 newdc
->vportExtY
= dc
->vportExtY
;
382 newdc
->virtual_res
= dc
->virtual_res
;
383 newdc
->virtual_size
= dc
->virtual_size
;
384 newdc
->gdiFont
= dc
->gdiFont
;
386 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
390 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
391 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
395 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
396 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
399 if (!PATH_SavePath( newdc
, dc
))
401 release_dc_ptr( dc
);
402 free_dc_state( newdc
);
406 newdc
->saved_dc
= dc
->saved_dc
;
407 dc
->saved_dc
= newdc
;
408 return ++dc
->saveLevel
;
412 /***********************************************************************
415 BOOL
nulldrv_RestoreDC( PHYSDEV dev
, INT level
)
417 DC
*dcs
, *first_dcs
, *dc
= get_nulldrv_dc( dev
);
420 /* find the state level to restore */
422 if (abs(level
) > dc
->saveLevel
|| level
== 0) return FALSE
;
423 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
424 first_dcs
= dc
->saved_dc
;
425 for (dcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
428 /* restore the state */
430 if (!PATH_RestorePath( dc
, dcs
)) return FALSE
;
432 dc
->layout
= dcs
->layout
;
433 dc
->hDevice
= dcs
->hDevice
;
434 dc
->ROPmode
= dcs
->ROPmode
;
435 dc
->polyFillMode
= dcs
->polyFillMode
;
436 dc
->stretchBltMode
= dcs
->stretchBltMode
;
437 dc
->relAbsMode
= dcs
->relAbsMode
;
438 dc
->backgroundMode
= dcs
->backgroundMode
;
439 dc
->backgroundColor
= dcs
->backgroundColor
;
440 dc
->textColor
= dcs
->textColor
;
441 dc
->dcBrushColor
= dcs
->dcBrushColor
;
442 dc
->dcPenColor
= dcs
->dcPenColor
;
443 dc
->brushOrgX
= dcs
->brushOrgX
;
444 dc
->brushOrgY
= dcs
->brushOrgY
;
445 dc
->mapperFlags
= dcs
->mapperFlags
;
446 dc
->textAlign
= dcs
->textAlign
;
447 dc
->charExtra
= dcs
->charExtra
;
448 dc
->breakExtra
= dcs
->breakExtra
;
449 dc
->breakRem
= dcs
->breakRem
;
450 dc
->MapMode
= dcs
->MapMode
;
451 dc
->GraphicsMode
= dcs
->GraphicsMode
;
452 dc
->CursPosX
= dcs
->CursPosX
;
453 dc
->CursPosY
= dcs
->CursPosY
;
454 dc
->ArcDirection
= dcs
->ArcDirection
;
455 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
456 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
457 dc
->xformVport2World
= dcs
->xformVport2World
;
458 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
459 dc
->wndOrgX
= dcs
->wndOrgX
;
460 dc
->wndOrgY
= dcs
->wndOrgY
;
461 dc
->wndExtX
= dcs
->wndExtX
;
462 dc
->wndExtY
= dcs
->wndExtY
;
463 dc
->vportOrgX
= dcs
->vportOrgX
;
464 dc
->vportOrgY
= dcs
->vportOrgY
;
465 dc
->vportExtX
= dcs
->vportExtX
;
466 dc
->vportExtY
= dcs
->vportExtY
;
467 dc
->virtual_res
= dcs
->virtual_res
;
468 dc
->virtual_size
= dcs
->virtual_size
;
472 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
473 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
477 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
482 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
483 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
487 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
490 DC_UpdateXforms( dc
);
491 update_dc_clipping( dc
);
493 SelectObject( dev
->hdc
, dcs
->hBitmap
);
494 SelectObject( dev
->hdc
, dcs
->hBrush
);
495 SelectObject( dev
->hdc
, dcs
->hFont
);
496 SelectObject( dev
->hdc
, dcs
->hPen
);
497 SetBkColor( dev
->hdc
, dcs
->backgroundColor
);
498 SetTextColor( dev
->hdc
, dcs
->textColor
);
499 GDISelectPalette( dev
->hdc
, dcs
->hPalette
, FALSE
);
501 dc
->saved_dc
= dcs
->saved_dc
;
503 dc
->saveLevel
= save_level
- 1;
505 /* now destroy all the saved DCs */
509 DC
*next
= first_dcs
->saved_dc
;
510 free_dc_state( first_dcs
);
517 /***********************************************************************
520 INT WINAPI
SaveDC( HDC hdc
)
525 if ((dc
= get_dc_ptr( hdc
)))
527 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSaveDC
);
528 ret
= physdev
->funcs
->pSaveDC( physdev
);
529 release_dc_ptr( dc
);
535 /***********************************************************************
536 * RestoreDC (GDI32.@)
538 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
541 BOOL success
= FALSE
;
543 TRACE("%p %d\n", hdc
, level
);
544 if ((dc
= get_dc_ptr( hdc
)))
546 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRestoreDC
);
548 success
= physdev
->funcs
->pRestoreDC( physdev
, level
);
549 release_dc_ptr( dc
);
555 /***********************************************************************
556 * CreateDCW (GDI32.@)
558 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
559 const DEVMODEW
*initData
)
563 const struct gdi_dc_funcs
*funcs
;
568 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
572 ERR( "no device found for %s\n", debugstr_w(device
) );
575 strcpyW(buf
, driver
);
578 if (!(funcs
= DRIVER_load_driver( buf
)))
580 ERR( "no driver found for %s\n", debugstr_w(buf
) );
583 if (!(dc
= alloc_dc_ptr( OBJ_DC
))) return 0;
586 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
588 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
589 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
591 if (funcs
->pCreateDC
)
593 if (!funcs
->pCreateDC( &dc
->physDev
, buf
, device
, output
, initData
))
595 WARN("creation aborted by device\n" );
601 dc
->vis_rect
.left
= 0;
602 dc
->vis_rect
.top
= 0;
603 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
604 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
607 release_dc_ptr( dc
);
612 /***********************************************************************
613 * CreateDCA (GDI32.@)
615 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
616 const DEVMODEA
*initData
)
618 UNICODE_STRING driverW
, deviceW
, outputW
;
622 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
623 else driverW
.Buffer
= NULL
;
625 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
626 else deviceW
.Buffer
= NULL
;
628 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
629 else outputW
.Buffer
= NULL
;
634 /* don't convert initData for DISPLAY driver, it's not used */
635 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
636 initDataW
= GdiConvertToDevmodeW(initData
);
639 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
641 RtlFreeUnicodeString(&driverW
);
642 RtlFreeUnicodeString(&deviceW
);
643 RtlFreeUnicodeString(&outputW
);
644 HeapFree(GetProcessHeap(), 0, initDataW
);
649 /***********************************************************************
650 * CreateICA (GDI32.@)
652 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
653 const DEVMODEA
* initData
)
655 /* Nothing special yet for ICs */
656 return CreateDCA( driver
, device
, output
, initData
);
660 /***********************************************************************
661 * CreateICW (GDI32.@)
663 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
664 const DEVMODEW
* initData
)
666 /* Nothing special yet for ICs */
667 return CreateDCW( driver
, device
, output
, initData
);
671 /***********************************************************************
672 * CreateCompatibleDC (GDI32.@)
674 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
678 const struct gdi_dc_funcs
*funcs
= &null_driver
;
679 PHYSDEV physDev
= NULL
;
685 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
686 physDev
= GET_DC_PHYSDEV( origDC
, pCreateCompatibleDC
);
687 funcs
= physDev
->funcs
;
688 release_dc_ptr( origDC
);
691 if (!(dc
= alloc_dc_ptr( OBJ_MEMDC
))) return 0;
693 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
695 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
696 dc
->vis_rect
.left
= 0;
697 dc
->vis_rect
.top
= 0;
698 dc
->vis_rect
.right
= 1;
699 dc
->vis_rect
.bottom
= 1;
700 dc
->device_rect
= dc
->vis_rect
;
704 if (!funcs
->pCreateCompatibleDC( physDev
, &dc
->physDev
))
706 WARN("creation aborted by device\n");
711 if (!dib_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
716 physDev
= GET_DC_PHYSDEV( dc
, pSelectBitmap
);
717 physDev
->funcs
->pSelectBitmap( physDev
, dc
->hBitmap
);
720 release_dc_ptr( dc
);
725 /***********************************************************************
728 BOOL WINAPI
DeleteDC( HDC hdc
)
736 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
737 if (dc
->refcount
!= 1)
739 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
740 release_dc_ptr( dc
);
744 /* Call hook procedure to check whether is it OK to delete this DC */
745 if (dc
->hookProc
&& !dc
->hookProc( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
747 release_dc_ptr( dc
);
751 while (dc
->saveLevel
)
753 DC
*dcs
= dc
->saved_dc
;
754 dc
->saved_dc
= dcs
->saved_dc
;
756 free_dc_state( dcs
);
760 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
761 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
762 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
763 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
770 /***********************************************************************
773 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
778 if ((dc
= get_dc_ptr( hdc
)))
780 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pResetDC
);
781 ret
= physdev
->funcs
->pResetDC( physdev
, devmode
);
782 if (ret
) /* reset the visible region */
785 dc
->vis_rect
.left
= 0;
786 dc
->vis_rect
.top
= 0;
787 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
788 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
789 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
791 update_dc_clipping( dc
);
793 release_dc_ptr( dc
);
799 /***********************************************************************
802 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
807 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
808 else devmodeW
= NULL
;
810 ret
= ResetDCW(hdc
, devmodeW
);
812 HeapFree(GetProcessHeap(), 0, devmodeW
);
817 /***********************************************************************
818 * GetDeviceCaps (GDI32.@)
820 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
825 if ((dc
= get_dc_ptr( hdc
)))
827 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceCaps
);
828 ret
= physdev
->funcs
->pGetDeviceCaps( physdev
, cap
);
829 release_dc_ptr( dc
);
835 /***********************************************************************
836 * GetBkColor (GDI32.@)
838 COLORREF WINAPI
GetBkColor( HDC hdc
)
841 DC
* dc
= get_dc_ptr( hdc
);
844 ret
= dc
->backgroundColor
;
845 release_dc_ptr( dc
);
851 /***********************************************************************
852 * SetBkColor (GDI32.@)
854 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
856 COLORREF ret
= CLR_INVALID
;
857 DC
* dc
= get_dc_ptr( hdc
);
859 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
863 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkColor
);
864 ret
= dc
->backgroundColor
;
865 dc
->backgroundColor
= physdev
->funcs
->pSetBkColor( physdev
, color
);
866 release_dc_ptr( dc
);
872 /***********************************************************************
873 * GetTextColor (GDI32.@)
875 COLORREF WINAPI
GetTextColor( HDC hdc
)
878 DC
* dc
= get_dc_ptr( hdc
);
882 release_dc_ptr( dc
);
888 /***********************************************************************
889 * SetTextColor (GDI32.@)
891 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
893 COLORREF ret
= CLR_INVALID
;
894 DC
* dc
= get_dc_ptr( hdc
);
896 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
900 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
902 dc
->textColor
= physdev
->funcs
->pSetTextColor( physdev
, color
);
903 release_dc_ptr( dc
);
909 /***********************************************************************
910 * GetTextAlign (GDI32.@)
912 UINT WINAPI
GetTextAlign( HDC hdc
)
915 DC
* dc
= get_dc_ptr( hdc
);
919 release_dc_ptr( dc
);
925 /***********************************************************************
926 * SetTextAlign (GDI32.@)
928 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
930 UINT ret
= GDI_ERROR
;
931 DC
*dc
= get_dc_ptr( hdc
);
933 TRACE("hdc=%p align=%d\n", hdc
, align
);
937 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
938 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
939 if (align
!= GDI_ERROR
)
942 dc
->textAlign
= align
;
944 release_dc_ptr( dc
);
949 /***********************************************************************
950 * GetDCOrgEx (GDI32.@)
952 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
956 if (!lpp
) return FALSE
;
957 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
958 lpp
->x
= dc
->vis_rect
.left
;
959 lpp
->y
= dc
->vis_rect
.top
;
960 release_dc_ptr( dc
);
965 /***********************************************************************
966 * GetGraphicsMode (GDI32.@)
968 INT WINAPI
GetGraphicsMode( HDC hdc
)
971 DC
* dc
= get_dc_ptr( hdc
);
974 ret
= dc
->GraphicsMode
;
975 release_dc_ptr( dc
);
981 /***********************************************************************
982 * SetGraphicsMode (GDI32.@)
984 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
987 DC
*dc
= get_dc_ptr( hdc
);
989 /* One would think that setting the graphics mode to GM_COMPATIBLE
990 * would also reset the world transformation matrix to the unity
991 * matrix. However, in Windows, this is not the case. This doesn't
992 * make a lot of sense to me, but that's the way it is.
995 if ((mode
> 0) && (mode
<= GM_LAST
))
997 ret
= dc
->GraphicsMode
;
998 dc
->GraphicsMode
= mode
;
1000 release_dc_ptr( dc
);
1005 /***********************************************************************
1006 * GetArcDirection (GDI32.@)
1008 INT WINAPI
GetArcDirection( HDC hdc
)
1011 DC
* dc
= get_dc_ptr( hdc
);
1014 ret
= dc
->ArcDirection
;
1015 release_dc_ptr( dc
);
1021 /***********************************************************************
1022 * SetArcDirection (GDI32.@)
1024 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1029 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1031 SetLastError(ERROR_INVALID_PARAMETER
);
1035 if ((dc
= get_dc_ptr( hdc
)))
1037 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1038 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1041 ret
= dc
->ArcDirection
;
1042 dc
->ArcDirection
= dir
;
1044 release_dc_ptr( dc
);
1050 /***********************************************************************
1051 * GetWorldTransform (GDI32.@)
1053 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1056 if (!xform
) return FALSE
;
1057 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1058 *xform
= dc
->xformWorld2Wnd
;
1059 release_dc_ptr( dc
);
1064 /***********************************************************************
1065 * GetTransform (GDI32.@)
1069 * Returns one of the co-ordinate space transforms
1072 * hdc [I] Device context.
1073 * which [I] Which xform to return:
1074 * 0x203 World -> Page transform (that set by SetWorldTransform).
1075 * 0x304 Page -> Device transform (the mapping mode transform).
1076 * 0x204 World -> Device transform (the combination of the above two).
1077 * 0x402 Device -> World transform (the inversion of the above).
1078 * xform [O] The xform.
1081 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1084 DC
*dc
= get_dc_ptr( hdc
);
1085 if (!dc
) return FALSE
;
1090 *xform
= dc
->xformWorld2Wnd
;
1094 construct_window_to_viewport(dc
, xform
);
1098 *xform
= dc
->xformWorld2Vport
;
1102 *xform
= dc
->xformVport2World
;
1106 FIXME("Unknown code %x\n", which
);
1110 release_dc_ptr( dc
);
1115 /****************************************************************************
1116 * CombineTransform [GDI32.@]
1117 * Combines two transformation matrices.
1120 * xformResult [O] Stores the result of combining the two matrices
1121 * xform1 [I] Specifies the first matrix to apply
1122 * xform2 [I] Specifies the second matrix to apply
1125 * The same matrix can be passed in for more than one of the parameters.
1129 * Failure: FALSE. Use GetLastError() to determine the cause.
1131 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1132 const XFORM
*xform2
)
1136 /* Check for illegal parameters */
1137 if (!xformResult
|| !xform1
|| !xform2
)
1140 /* Create the result in a temporary XFORM, since xformResult may be
1141 * equal to xform1 or xform2 */
1142 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1143 xform1
->eM12
* xform2
->eM21
;
1144 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1145 xform1
->eM12
* xform2
->eM22
;
1146 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1147 xform1
->eM22
* xform2
->eM21
;
1148 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1149 xform1
->eM22
* xform2
->eM22
;
1150 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1151 xform1
->eDy
* xform2
->eM21
+
1153 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1154 xform1
->eDy
* xform2
->eM22
+
1157 /* Copy the result to xformResult */
1158 *xformResult
= xformTemp
;
1164 /***********************************************************************
1165 * SetDCHook (GDI32.@)
1167 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1169 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1171 DC
*dc
= get_dc_ptr( hdc
);
1173 if (!dc
) return FALSE
;
1175 dc
->dwHookData
= dwHookData
;
1176 dc
->hookProc
= hookProc
;
1177 release_dc_ptr( dc
);
1182 /***********************************************************************
1183 * GetDCHook (GDI32.@)
1185 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1187 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1189 DC
*dc
= get_dc_ptr( hdc
);
1193 if (proc
) *proc
= dc
->hookProc
;
1194 ret
= dc
->dwHookData
;
1195 release_dc_ptr( dc
);
1200 /***********************************************************************
1201 * SetHookFlags (GDI32.@)
1203 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1205 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1207 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1212 /* "Undocumented Windows" info is slightly confusing. */
1214 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1216 if (flags
& DCHF_INVALIDATEVISRGN
)
1217 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1218 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1219 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1221 GDI_ReleaseObj( hdc
);
1225 /***********************************************************************
1226 * SetICMMode (GDI32.@)
1228 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1230 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1231 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1232 if (iEnableICM
== ICM_ON
) return 0;
1233 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1237 /***********************************************************************
1238 * GetDeviceGammaRamp (GDI32.@)
1240 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1243 DC
*dc
= get_dc_ptr( hDC
);
1245 TRACE("%p, %p\n", hDC
, ptr
);
1248 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1250 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceGammaRamp
);
1251 ret
= physdev
->funcs
->pGetDeviceGammaRamp( physdev
, ptr
);
1253 else SetLastError( ERROR_INVALID_PARAMETER
);
1254 release_dc_ptr( dc
);
1259 /***********************************************************************
1260 * SetDeviceGammaRamp (GDI32.@)
1262 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1265 DC
*dc
= get_dc_ptr( hDC
);
1267 TRACE("%p, %p\n", hDC
, ptr
);
1270 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1272 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDeviceGammaRamp
);
1273 ret
= physdev
->funcs
->pSetDeviceGammaRamp( physdev
, ptr
);
1275 else SetLastError( ERROR_INVALID_PARAMETER
);
1276 release_dc_ptr( dc
);
1281 /***********************************************************************
1282 * GetColorSpace (GDI32.@)
1284 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1286 /*FIXME Need to do whatever GetColorSpace actually does */
1290 /***********************************************************************
1291 * CreateColorSpaceA (GDI32.@)
1293 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1299 /***********************************************************************
1300 * CreateColorSpaceW (GDI32.@)
1302 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1308 /***********************************************************************
1309 * DeleteColorSpace (GDI32.@)
1311 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1318 /***********************************************************************
1319 * SetColorSpace (GDI32.@)
1321 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1328 /***********************************************************************
1329 * GetBoundsRect (GDI32.@)
1331 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1336 DC
*dc
= get_dc_ptr( hdc
);
1338 if ( !dc
) return 0;
1340 physdev
= GET_DC_PHYSDEV( dc
, pGetBoundsRect
);
1341 ret
= physdev
->funcs
->pGetBoundsRect( physdev
, &device_rect
, DCB_RESET
);
1344 release_dc_ptr( dc
);
1347 if (dc
->bounds_enabled
&& ret
== DCB_SET
) add_bounds_rect( &dc
->bounds
, &device_rect
);
1351 if (is_rect_empty( &dc
->bounds
))
1353 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
1359 rect
->left
= max( rect
->left
, 0 );
1360 rect
->top
= max( rect
->top
, 0 );
1361 rect
->right
= min( rect
->right
, dc
->vis_rect
.right
- dc
->vis_rect
.left
);
1362 rect
->bottom
= min( rect
->bottom
, dc
->vis_rect
.bottom
- dc
->vis_rect
.top
);
1365 DPtoLP( hdc
, (POINT
*)rect
, 2 );
1369 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1370 release_dc_ptr( dc
);
1375 /***********************************************************************
1376 * SetBoundsRect (GDI32.@)
1378 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1384 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1385 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1387 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
1388 ret
= physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, flags
);
1391 release_dc_ptr( dc
);
1395 ret
= (dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
) |
1396 (is_rect_empty( &dc
->bounds
) ? ret
& DCB_SET
: DCB_SET
);
1398 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1400 if ((flags
& DCB_ACCUMULATE
) && rect
)
1404 LPtoDP( hdc
, (POINT
*)&rc
, 2 );
1405 add_bounds_rect( &dc
->bounds
, &rc
);
1408 if (flags
& DCB_ENABLE
) dc
->bounds_enabled
= TRUE
;
1409 if (flags
& DCB_DISABLE
) dc
->bounds_enabled
= FALSE
;
1411 release_dc_ptr( dc
);
1416 /***********************************************************************
1417 * GetRelAbs (GDI32.@)
1419 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1422 DC
*dc
= get_dc_ptr( hdc
);
1425 ret
= dc
->relAbsMode
;
1426 release_dc_ptr( dc
);
1434 /***********************************************************************
1435 * GetBkMode (GDI32.@)
1437 INT WINAPI
GetBkMode( HDC hdc
)
1440 DC
* dc
= get_dc_ptr( hdc
);
1443 ret
= dc
->backgroundMode
;
1444 release_dc_ptr( dc
);
1450 /***********************************************************************
1451 * SetBkMode (GDI32.@)
1453 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1458 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1460 SetLastError(ERROR_INVALID_PARAMETER
);
1463 if ((dc
= get_dc_ptr( hdc
)))
1465 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1466 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1469 ret
= dc
->backgroundMode
;
1470 dc
->backgroundMode
= mode
;
1472 release_dc_ptr( dc
);
1478 /***********************************************************************
1481 INT WINAPI
GetROP2( HDC hdc
)
1484 DC
* dc
= get_dc_ptr( hdc
);
1488 release_dc_ptr( dc
);
1494 /***********************************************************************
1497 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1502 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1504 SetLastError(ERROR_INVALID_PARAMETER
);
1507 if ((dc
= get_dc_ptr( hdc
)))
1509 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1510 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1516 release_dc_ptr( dc
);
1522 /***********************************************************************
1523 * SetRelAbs (GDI32.@)
1525 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1530 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1532 SetLastError(ERROR_INVALID_PARAMETER
);
1535 if ((dc
= get_dc_ptr( hdc
)))
1537 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1538 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1541 ret
= dc
->relAbsMode
;
1542 dc
->relAbsMode
= mode
;
1544 release_dc_ptr( dc
);
1550 /***********************************************************************
1551 * GetPolyFillMode (GDI32.@)
1553 INT WINAPI
GetPolyFillMode( HDC hdc
)
1556 DC
* dc
= get_dc_ptr( hdc
);
1559 ret
= dc
->polyFillMode
;
1560 release_dc_ptr( dc
);
1566 /***********************************************************************
1567 * SetPolyFillMode (GDI32.@)
1569 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1574 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1576 SetLastError(ERROR_INVALID_PARAMETER
);
1579 if ((dc
= get_dc_ptr( hdc
)))
1581 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1582 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1585 ret
= dc
->polyFillMode
;
1586 dc
->polyFillMode
= mode
;
1588 release_dc_ptr( dc
);
1594 /***********************************************************************
1595 * GetStretchBltMode (GDI32.@)
1597 INT WINAPI
GetStretchBltMode( HDC hdc
)
1600 DC
* dc
= get_dc_ptr( hdc
);
1603 ret
= dc
->stretchBltMode
;
1604 release_dc_ptr( dc
);
1610 /***********************************************************************
1611 * SetStretchBltMode (GDI32.@)
1613 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1618 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1620 SetLastError(ERROR_INVALID_PARAMETER
);
1623 if ((dc
= get_dc_ptr( hdc
)))
1625 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1626 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1629 ret
= dc
->stretchBltMode
;
1630 dc
->stretchBltMode
= mode
;
1632 release_dc_ptr( dc
);
1638 /***********************************************************************
1639 * GetMapMode (GDI32.@)
1641 INT WINAPI
GetMapMode( HDC hdc
)
1644 DC
* dc
= get_dc_ptr( hdc
);
1648 release_dc_ptr( dc
);
1654 /***********************************************************************
1655 * GetBrushOrgEx (GDI32.@)
1657 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1659 DC
* dc
= get_dc_ptr( hdc
);
1660 if (!dc
) return FALSE
;
1661 pt
->x
= dc
->brushOrgX
;
1662 pt
->y
= dc
->brushOrgY
;
1663 release_dc_ptr( dc
);
1668 /***********************************************************************
1669 * GetCurrentPositionEx (GDI32.@)
1671 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1673 DC
* dc
= get_dc_ptr( hdc
);
1674 if (!dc
) return FALSE
;
1675 pt
->x
= dc
->CursPosX
;
1676 pt
->y
= dc
->CursPosY
;
1677 release_dc_ptr( dc
);
1682 /***********************************************************************
1683 * GetViewportExtEx (GDI32.@)
1685 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1687 DC
* dc
= get_dc_ptr( hdc
);
1688 if (!dc
) return FALSE
;
1689 size
->cx
= dc
->vportExtX
;
1690 size
->cy
= dc
->vportExtY
;
1691 release_dc_ptr( dc
);
1696 /***********************************************************************
1697 * GetViewportOrgEx (GDI32.@)
1699 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1701 DC
* dc
= get_dc_ptr( hdc
);
1702 if (!dc
) return FALSE
;
1703 pt
->x
= dc
->vportOrgX
;
1704 pt
->y
= dc
->vportOrgY
;
1705 release_dc_ptr( dc
);
1710 /***********************************************************************
1711 * GetWindowExtEx (GDI32.@)
1713 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1715 DC
* dc
= get_dc_ptr( hdc
);
1716 if (!dc
) return FALSE
;
1717 size
->cx
= dc
->wndExtX
;
1718 size
->cy
= dc
->wndExtY
;
1719 release_dc_ptr( dc
);
1724 /***********************************************************************
1725 * GetWindowOrgEx (GDI32.@)
1727 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1729 DC
* dc
= get_dc_ptr( hdc
);
1730 if (!dc
) return FALSE
;
1731 pt
->x
= dc
->wndOrgX
;
1732 pt
->y
= dc
->wndOrgY
;
1733 release_dc_ptr( dc
);
1738 /***********************************************************************
1739 * GetLayout (GDI32.@)
1741 * Gets left->right or right->left text layout flags of a dc.
1744 DWORD WINAPI
GetLayout(HDC hdc
)
1746 DWORD layout
= GDI_ERROR
;
1748 DC
* dc
= get_dc_ptr( hdc
);
1751 layout
= dc
->layout
;
1752 release_dc_ptr( dc
);
1755 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1760 /***********************************************************************
1761 * SetLayout (GDI32.@)
1763 * Sets left->right or right->left text layout flags of a dc.
1766 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1768 DWORD oldlayout
= GDI_ERROR
;
1770 DC
* dc
= get_dc_ptr( hdc
);
1773 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetLayout
);
1774 layout
= physdev
->funcs
->pSetLayout( physdev
, layout
);
1775 if (layout
!= GDI_ERROR
)
1777 oldlayout
= dc
->layout
;
1778 dc
->layout
= layout
;
1779 if (layout
!= oldlayout
)
1781 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1782 DC_UpdateXforms( dc
);
1785 release_dc_ptr( dc
);
1788 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1793 /***********************************************************************
1794 * GetDCBrushColor (GDI32.@)
1796 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1799 COLORREF dcBrushColor
= CLR_INVALID
;
1801 TRACE("hdc(%p)\n", hdc
);
1803 dc
= get_dc_ptr( hdc
);
1806 dcBrushColor
= dc
->dcBrushColor
;
1807 release_dc_ptr( dc
);
1810 return dcBrushColor
;
1813 /***********************************************************************
1814 * SetDCBrushColor (GDI32.@)
1816 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1819 COLORREF oldClr
= CLR_INVALID
;
1821 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1823 dc
= get_dc_ptr( hdc
);
1826 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
1827 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
1828 if (crColor
!= CLR_INVALID
)
1830 oldClr
= dc
->dcBrushColor
;
1831 dc
->dcBrushColor
= crColor
;
1833 release_dc_ptr( dc
);
1839 /***********************************************************************
1840 * GetDCPenColor (GDI32.@)
1842 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1845 COLORREF dcPenColor
= CLR_INVALID
;
1847 TRACE("hdc(%p)\n", hdc
);
1849 dc
= get_dc_ptr( hdc
);
1852 dcPenColor
= dc
->dcPenColor
;
1853 release_dc_ptr( dc
);
1859 /***********************************************************************
1860 * SetDCPenColor (GDI32.@)
1862 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1865 COLORREF oldClr
= CLR_INVALID
;
1867 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1869 dc
= get_dc_ptr( hdc
);
1872 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
1873 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
1874 if (crColor
!= CLR_INVALID
)
1876 oldClr
= dc
->dcPenColor
;
1877 dc
->dcPenColor
= crColor
;
1879 release_dc_ptr( dc
);
1885 /***********************************************************************
1886 * CancelDC (GDI32.@)
1888 BOOL WINAPI
CancelDC(HDC hdc
)
1894 /*******************************************************************
1895 * GetMiterLimit [GDI32.@]
1899 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
1904 TRACE("(%p,%p)\n", hdc
, peLimit
);
1906 dc
= get_dc_ptr( hdc
);
1910 *peLimit
= dc
->miterLimit
;
1912 release_dc_ptr( dc
);
1918 /*******************************************************************
1919 * SetMiterLimit [GDI32.@]
1923 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
1928 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
1930 dc
= get_dc_ptr( hdc
);
1934 *peOldLimit
= dc
->miterLimit
;
1935 dc
->miterLimit
= eNewLimit
;
1936 release_dc_ptr( dc
);
1942 /*******************************************************************
1943 * GdiIsMetaPrintDC [GDI32.@]
1945 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
1951 /*******************************************************************
1952 * GdiIsMetaFileDC [GDI32.@]
1954 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
1958 switch( GetObjectType( hdc
) )
1967 /*******************************************************************
1968 * GdiIsPlayMetafileDC [GDI32.@]
1970 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)