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
->dibdrv
.dev
.funcs
= &dib_driver
;
83 dc
->dibdrv
.dev
.next
= NULL
;
84 dc
->physDev
= &dc
->nulldrv
;
85 dc
->thread
= GetCurrentThreadId();
100 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
105 dc
->hMetaClipRgn
= 0;
107 dc
->hPen
= GDI_inc_ref_count( GetStockObject( BLACK_PEN
));
108 dc
->hBrush
= GDI_inc_ref_count( GetStockObject( WHITE_BRUSH
));
109 dc
->hFont
= GDI_inc_ref_count( GetStockObject( SYSTEM_FONT
));
112 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
114 dc
->font_code_page
= CP_ACP
;
115 dc
->ROPmode
= R2_COPYPEN
;
116 dc
->polyFillMode
= ALTERNATE
;
117 dc
->stretchBltMode
= BLACKONWHITE
;
118 dc
->relAbsMode
= ABSOLUTE
;
119 dc
->backgroundMode
= OPAQUE
;
120 dc
->backgroundColor
= RGB( 255, 255, 255 );
121 dc
->dcBrushColor
= RGB( 255, 255, 255 );
122 dc
->dcPenColor
= RGB( 0, 0, 0 );
123 dc
->textColor
= RGB( 0, 0, 0 );
127 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
131 dc
->MapMode
= MM_TEXT
;
132 dc
->GraphicsMode
= GM_COMPATIBLE
;
133 dc
->pAbortProc
= NULL
;
136 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
137 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
138 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
139 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
140 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
141 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
142 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
143 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
144 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
145 dc
->vport2WorldValid
= TRUE
;
146 dc
->BoundsRect
.left
= 0;
147 dc
->BoundsRect
.top
= 0;
148 dc
->BoundsRect
.right
= 0;
149 dc
->BoundsRect
.bottom
= 0;
150 PATH_InitGdiPath(&dc
->path
);
152 if (!(dc
->hSelf
= alloc_gdi_handle( &dc
->header
, magic
, &dc_funcs
)))
154 HeapFree( GetProcessHeap(), 0, dc
);
157 dc
->nulldrv
.hdc
= dc
->hSelf
;
163 /***********************************************************************
166 static void free_dc_state( DC
*dc
)
168 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
169 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
170 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
171 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
172 PATH_DestroyGdiPath( &dc
->path
);
173 HeapFree( GetProcessHeap(), 0, dc
);
177 /***********************************************************************
180 void free_dc_ptr( DC
*dc
)
182 assert( dc
->refcount
== 1 );
184 while (dc
->physDev
!= &dc
->nulldrv
) pop_dc_driver( dc
, dc
->physDev
);
185 free_gdi_handle( dc
->hSelf
);
190 /***********************************************************************
193 * Retrieve a DC pointer but release the GDI lock.
195 DC
*get_dc_ptr( HDC hdc
)
197 DC
*dc
= get_dc_obj( hdc
);
198 if (!dc
) return NULL
;
200 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
202 dc
->thread
= GetCurrentThreadId();
204 else if (dc
->thread
!= GetCurrentThreadId())
206 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
207 GDI_ReleaseObj( hdc
);
210 else InterlockedIncrement( &dc
->refcount
);
212 GDI_ReleaseObj( hdc
);
217 /***********************************************************************
220 void release_dc_ptr( DC
*dc
)
225 ref
= InterlockedDecrement( &dc
->refcount
);
227 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
231 /***********************************************************************
234 * Make sure the DC vis region is up to date.
235 * This function may call up to USER so the GDI lock should _not_
236 * be held when calling it.
238 void update_dc( DC
*dc
)
240 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
241 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
245 /***********************************************************************
248 * Push a driver on top of the DC driver stack.
250 void push_dc_driver( DC
* dc
, PHYSDEV physdev
, const DC_FUNCTIONS
*funcs
)
252 physdev
->funcs
= funcs
;
253 physdev
->next
= dc
->physDev
;
254 physdev
->hdc
= dc
->hSelf
;
255 dc
->physDev
= physdev
;
259 /***********************************************************************
262 * Pop the top driver from the DC driver stack.
264 void pop_dc_driver( DC
* dc
, PHYSDEV physdev
)
266 assert( physdev
== dc
->physDev
);
267 assert( physdev
!= &dc
->nulldrv
);
268 dc
->physDev
= physdev
->next
;
269 physdev
->funcs
->pDeleteDC( physdev
);
273 /***********************************************************************
276 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
278 return DeleteDC( handle
);
282 /***********************************************************************
285 * Setup device-specific DC values for a newly created DC.
287 void DC_InitDC( DC
* dc
)
289 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRealizeDefaultPalette
);
290 physdev
->funcs
->pRealizeDefaultPalette( physdev
);
291 SetTextColor( dc
->hSelf
, dc
->textColor
);
292 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
293 SelectObject( dc
->hSelf
, dc
->hPen
);
294 SelectObject( dc
->hSelf
, dc
->hBrush
);
295 SelectObject( dc
->hSelf
, dc
->hFont
);
296 CLIPPING_UpdateGCRegion( dc
);
297 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
301 /***********************************************************************
304 * Computes the inverse of the transformation xformSrc and stores it to
305 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
308 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
312 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
313 xformSrc
->eM12
*xformSrc
->eM21
;
314 if (determinant
> -1e-12 && determinant
< 1e-12)
317 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
318 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
319 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
320 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
321 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
322 xformSrc
->eDy
* xformDest
->eM21
;
323 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
324 xformSrc
->eDy
* xformDest
->eM22
;
329 /* Construct a transformation to do the window-to-viewport conversion */
330 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
332 double scaleX
, scaleY
;
333 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
334 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
336 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
337 xform
->eM11
= scaleX
;
340 xform
->eM22
= scaleY
;
341 xform
->eDx
= (double)dc
->vportOrgX
- scaleX
* (double)dc
->wndOrgX
;
342 xform
->eDy
= (double)dc
->vportOrgY
- scaleY
* (double)dc
->wndOrgY
;
343 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
346 /***********************************************************************
349 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
350 * fields of the specified DC by creating a transformation that
351 * represents the current mapping mode and combining it with the DC's
352 * world transform. This function should be called whenever the
353 * parameters associated with the mapping mode (window and viewport
354 * extents and origins) or the world transform change.
356 void DC_UpdateXforms( DC
*dc
)
358 XFORM xformWnd2Vport
, oldworld2vport
;
360 construct_window_to_viewport(dc
, &xformWnd2Vport
);
362 oldworld2vport
= dc
->xformWorld2Vport
;
363 /* Combine with the world transformation */
364 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
367 /* Create inverse of world-to-viewport transformation */
368 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
369 &dc
->xformVport2World
);
371 /* Reselect the font and pen back into the dc so that the size
373 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
374 !GdiIsMetaFileDC(dc
->hSelf
))
376 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
377 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
382 /***********************************************************************
385 INT CDECL
nulldrv_SaveDC( PHYSDEV dev
)
387 DC
*newdc
, *dc
= get_nulldrv_dc( dev
);
389 if (!(newdc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc
)))) return 0;
390 newdc
->flags
= dc
->flags
;
391 newdc
->layout
= dc
->layout
;
392 newdc
->hPen
= dc
->hPen
;
393 newdc
->hBrush
= dc
->hBrush
;
394 newdc
->hFont
= dc
->hFont
;
395 newdc
->hBitmap
= dc
->hBitmap
;
396 newdc
->hDevice
= dc
->hDevice
;
397 newdc
->hPalette
= dc
->hPalette
;
398 newdc
->ROPmode
= dc
->ROPmode
;
399 newdc
->polyFillMode
= dc
->polyFillMode
;
400 newdc
->stretchBltMode
= dc
->stretchBltMode
;
401 newdc
->relAbsMode
= dc
->relAbsMode
;
402 newdc
->backgroundMode
= dc
->backgroundMode
;
403 newdc
->backgroundColor
= dc
->backgroundColor
;
404 newdc
->textColor
= dc
->textColor
;
405 newdc
->dcBrushColor
= dc
->dcBrushColor
;
406 newdc
->dcPenColor
= dc
->dcPenColor
;
407 newdc
->brushOrgX
= dc
->brushOrgX
;
408 newdc
->brushOrgY
= dc
->brushOrgY
;
409 newdc
->mapperFlags
= dc
->mapperFlags
;
410 newdc
->textAlign
= dc
->textAlign
;
411 newdc
->charExtra
= dc
->charExtra
;
412 newdc
->breakExtra
= dc
->breakExtra
;
413 newdc
->breakRem
= dc
->breakRem
;
414 newdc
->MapMode
= dc
->MapMode
;
415 newdc
->GraphicsMode
= dc
->GraphicsMode
;
416 newdc
->CursPosX
= dc
->CursPosX
;
417 newdc
->CursPosY
= dc
->CursPosY
;
418 newdc
->ArcDirection
= dc
->ArcDirection
;
419 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
420 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
421 newdc
->xformVport2World
= dc
->xformVport2World
;
422 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
423 newdc
->wndOrgX
= dc
->wndOrgX
;
424 newdc
->wndOrgY
= dc
->wndOrgY
;
425 newdc
->wndExtX
= dc
->wndExtX
;
426 newdc
->wndExtY
= dc
->wndExtY
;
427 newdc
->vportOrgX
= dc
->vportOrgX
;
428 newdc
->vportOrgY
= dc
->vportOrgY
;
429 newdc
->vportExtX
= dc
->vportExtX
;
430 newdc
->vportExtY
= dc
->vportExtY
;
431 newdc
->virtual_res
= dc
->virtual_res
;
432 newdc
->virtual_size
= dc
->virtual_size
;
433 newdc
->BoundsRect
= dc
->BoundsRect
;
434 newdc
->gdiFont
= dc
->gdiFont
;
436 PATH_InitGdiPath( &newdc
->path
);
438 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
443 newdc
->hMetaClipRgn
= 0;
446 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
447 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
451 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
452 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
455 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
457 if (!PATH_AssignGdiPath( &newdc
->path
, &dc
->path
))
459 release_dc_ptr( dc
);
460 free_dc_state( newdc
);
464 newdc
->saved_dc
= dc
->saved_dc
;
465 dc
->saved_dc
= newdc
;
466 return ++dc
->saveLevel
;
470 /***********************************************************************
473 BOOL CDECL
nulldrv_RestoreDC( PHYSDEV dev
, INT level
)
475 DC
*dcs
, *first_dcs
, *dc
= get_nulldrv_dc( dev
);
478 /* find the state level to restore */
480 if (abs(level
) > dc
->saveLevel
|| level
== 0) return FALSE
;
481 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
482 first_dcs
= dc
->saved_dc
;
483 for (dcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
486 /* restore the state */
488 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
)) return FALSE
;
490 dc
->flags
= dcs
->flags
;
491 dc
->layout
= dcs
->layout
;
492 dc
->hDevice
= dcs
->hDevice
;
493 dc
->ROPmode
= dcs
->ROPmode
;
494 dc
->polyFillMode
= dcs
->polyFillMode
;
495 dc
->stretchBltMode
= dcs
->stretchBltMode
;
496 dc
->relAbsMode
= dcs
->relAbsMode
;
497 dc
->backgroundMode
= dcs
->backgroundMode
;
498 dc
->backgroundColor
= dcs
->backgroundColor
;
499 dc
->textColor
= dcs
->textColor
;
500 dc
->dcBrushColor
= dcs
->dcBrushColor
;
501 dc
->dcPenColor
= dcs
->dcPenColor
;
502 dc
->brushOrgX
= dcs
->brushOrgX
;
503 dc
->brushOrgY
= dcs
->brushOrgY
;
504 dc
->mapperFlags
= dcs
->mapperFlags
;
505 dc
->textAlign
= dcs
->textAlign
;
506 dc
->charExtra
= dcs
->charExtra
;
507 dc
->breakExtra
= dcs
->breakExtra
;
508 dc
->breakRem
= dcs
->breakRem
;
509 dc
->MapMode
= dcs
->MapMode
;
510 dc
->GraphicsMode
= dcs
->GraphicsMode
;
511 dc
->CursPosX
= dcs
->CursPosX
;
512 dc
->CursPosY
= dcs
->CursPosY
;
513 dc
->ArcDirection
= dcs
->ArcDirection
;
514 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
515 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
516 dc
->xformVport2World
= dcs
->xformVport2World
;
517 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
518 dc
->BoundsRect
= dcs
->BoundsRect
;
520 dc
->wndOrgX
= dcs
->wndOrgX
;
521 dc
->wndOrgY
= dcs
->wndOrgY
;
522 dc
->wndExtX
= dcs
->wndExtX
;
523 dc
->wndExtY
= dcs
->wndExtY
;
524 dc
->vportOrgX
= dcs
->vportOrgX
;
525 dc
->vportOrgY
= dcs
->vportOrgY
;
526 dc
->vportExtX
= dcs
->vportExtX
;
527 dc
->vportExtY
= dcs
->vportExtY
;
528 dc
->virtual_res
= dcs
->virtual_res
;
529 dc
->virtual_size
= dcs
->virtual_size
;
533 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
534 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
538 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
543 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
544 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
548 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
551 DC_UpdateXforms( dc
);
552 CLIPPING_UpdateGCRegion( dc
);
554 SelectObject( dev
->hdc
, dcs
->hBitmap
);
555 SelectObject( dev
->hdc
, dcs
->hBrush
);
556 SelectObject( dev
->hdc
, dcs
->hFont
);
557 SelectObject( dev
->hdc
, dcs
->hPen
);
558 SetBkColor( dev
->hdc
, dcs
->backgroundColor
);
559 SetTextColor( dev
->hdc
, dcs
->textColor
);
560 GDISelectPalette( dev
->hdc
, dcs
->hPalette
, FALSE
);
562 dc
->saved_dc
= dcs
->saved_dc
;
564 dc
->saveLevel
= save_level
- 1;
566 /* now destroy all the saved DCs */
570 DC
*next
= first_dcs
->saved_dc
;
571 free_dc_state( first_dcs
);
578 /***********************************************************************
581 INT WINAPI
SaveDC( HDC hdc
)
586 if ((dc
= get_dc_ptr( hdc
)))
588 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSaveDC
);
589 ret
= physdev
->funcs
->pSaveDC( physdev
);
590 release_dc_ptr( dc
);
596 /***********************************************************************
597 * RestoreDC (GDI32.@)
599 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
602 BOOL success
= FALSE
;
604 TRACE("%p %d\n", hdc
, level
);
605 if ((dc
= get_dc_ptr( hdc
)))
607 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRestoreDC
);
609 success
= physdev
->funcs
->pRestoreDC( physdev
, level
);
610 release_dc_ptr( dc
);
616 /***********************************************************************
617 * CreateDCW (GDI32.@)
619 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
620 const DEVMODEW
*initData
)
624 const DC_FUNCTIONS
*funcs
;
629 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
633 ERR( "no device found for %s\n", debugstr_w(device
) );
636 strcpyW(buf
, driver
);
639 if (!(funcs
= DRIVER_load_driver( buf
)))
641 ERR( "no driver found for %s\n", debugstr_w(buf
) );
644 if (!(dc
= alloc_dc_ptr( OBJ_DC
))) goto error
;
647 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
648 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
650 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
651 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
653 if (funcs
->pCreateDC
)
656 if (!funcs
->pCreateDC( hdc
, &physdev
, buf
, device
, output
, initData
))
658 WARN("creation aborted by device\n" );
661 push_dc_driver( dc
, physdev
, funcs
);
664 dc
->vis_rect
.left
= 0;
665 dc
->vis_rect
.top
= 0;
666 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
667 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
668 SetRectRgn(dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
, dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
671 release_dc_ptr( dc
);
675 if (dc
) free_dc_ptr( dc
);
680 /***********************************************************************
681 * CreateDCA (GDI32.@)
683 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
684 const DEVMODEA
*initData
)
686 UNICODE_STRING driverW
, deviceW
, outputW
;
690 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
691 else driverW
.Buffer
= NULL
;
693 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
694 else deviceW
.Buffer
= NULL
;
696 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
697 else outputW
.Buffer
= NULL
;
702 /* don't convert initData for DISPLAY driver, it's not used */
703 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
704 initDataW
= GdiConvertToDevmodeW(initData
);
707 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
709 RtlFreeUnicodeString(&driverW
);
710 RtlFreeUnicodeString(&deviceW
);
711 RtlFreeUnicodeString(&outputW
);
712 HeapFree(GetProcessHeap(), 0, initDataW
);
717 /***********************************************************************
718 * CreateICA (GDI32.@)
720 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
721 const DEVMODEA
* initData
)
723 /* Nothing special yet for ICs */
724 return CreateDCA( driver
, device
, output
, initData
);
728 /***********************************************************************
729 * CreateICW (GDI32.@)
731 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
732 const DEVMODEW
* initData
)
734 /* Nothing special yet for ICs */
735 return CreateDCW( driver
, device
, output
, initData
);
739 /***********************************************************************
740 * CreateCompatibleDC (GDI32.@)
742 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
746 const DC_FUNCTIONS
*funcs
= NULL
;
747 PHYSDEV physDev
= NULL
;
753 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
754 physDev
= GET_DC_PHYSDEV( origDC
, pCreateDC
);
755 if (physDev
!= &origDC
->nulldrv
) funcs
= physDev
->funcs
;
757 release_dc_ptr( origDC
);
760 if (!funcs
&& !(funcs
= DRIVER_get_display_driver())) return 0;
762 if (!(dc
= alloc_dc_ptr( OBJ_MEMDC
))) goto error
;
764 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
766 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
767 dc
->vis_rect
.left
= 0;
768 dc
->vis_rect
.top
= 0;
769 dc
->vis_rect
.right
= 1;
770 dc
->vis_rect
.bottom
= 1;
771 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
775 /* Pass the driver-specific physical device info into
776 * the new DC. The driver may use this read-only info
777 * while creating the compatible DC. */
778 if (funcs
->pCreateDC
)
780 if (!funcs
->pCreateDC( dc
->hSelf
, &physDev
, NULL
, NULL
, NULL
, NULL
))
782 WARN("creation aborted by device\n");
785 push_dc_driver( dc
, physDev
, funcs
);
788 release_dc_ptr( dc
);
792 if (dc
) free_dc_ptr( dc
);
797 /***********************************************************************
800 BOOL WINAPI
DeleteDC( HDC hdc
)
808 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
809 if (dc
->refcount
!= 1)
811 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
812 release_dc_ptr( dc
);
816 /* Call hook procedure to check whether is it OK to delete this DC */
817 if (dc
->hookProc
&& !dc
->hookProc( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
819 release_dc_ptr( dc
);
823 while (dc
->saveLevel
)
825 DC
*dcs
= dc
->saved_dc
;
826 dc
->saved_dc
= dcs
->saved_dc
;
828 free_dc_state( dcs
);
831 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
832 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
833 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
834 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
841 /***********************************************************************
844 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
849 if ((dc
= get_dc_ptr( hdc
)))
851 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pResetDC
);
852 ret
= physdev
->funcs
->pResetDC( physdev
, devmode
);
853 if (ret
) /* reset the visible region */
856 dc
->vis_rect
.left
= 0;
857 dc
->vis_rect
.top
= 0;
858 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
859 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
860 SetRectRgn( dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
,
861 dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
862 CLIPPING_UpdateGCRegion( dc
);
864 release_dc_ptr( dc
);
870 /***********************************************************************
873 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
878 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
879 else devmodeW
= NULL
;
881 ret
= ResetDCW(hdc
, devmodeW
);
883 HeapFree(GetProcessHeap(), 0, devmodeW
);
888 /***********************************************************************
889 * GetDeviceCaps (GDI32.@)
891 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
896 if ((dc
= get_dc_ptr( hdc
)))
898 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceCaps
);
899 ret
= physdev
->funcs
->pGetDeviceCaps( physdev
, cap
);
900 release_dc_ptr( dc
);
906 /***********************************************************************
907 * GetBkColor (GDI32.@)
909 COLORREF WINAPI
GetBkColor( HDC hdc
)
912 DC
* dc
= get_dc_ptr( hdc
);
915 ret
= dc
->backgroundColor
;
916 release_dc_ptr( dc
);
922 /***********************************************************************
923 * SetBkColor (GDI32.@)
925 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
927 COLORREF ret
= CLR_INVALID
;
928 DC
* dc
= get_dc_ptr( hdc
);
930 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
934 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkColor
);
935 color
= physdev
->funcs
->pSetBkColor( physdev
, color
);
936 if (color
!= CLR_INVALID
)
938 ret
= dc
->backgroundColor
;
939 dc
->backgroundColor
= color
;
941 release_dc_ptr( dc
);
947 /***********************************************************************
948 * GetTextColor (GDI32.@)
950 COLORREF WINAPI
GetTextColor( HDC hdc
)
953 DC
* dc
= get_dc_ptr( hdc
);
957 release_dc_ptr( dc
);
963 /***********************************************************************
964 * SetTextColor (GDI32.@)
966 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
968 COLORREF ret
= CLR_INVALID
;
969 DC
* dc
= get_dc_ptr( hdc
);
971 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
975 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
976 color
= physdev
->funcs
->pSetTextColor( physdev
, color
);
977 if (color
!= CLR_INVALID
)
980 dc
->textColor
= color
;
982 release_dc_ptr( dc
);
988 /***********************************************************************
989 * GetTextAlign (GDI32.@)
991 UINT WINAPI
GetTextAlign( HDC hdc
)
994 DC
* dc
= get_dc_ptr( hdc
);
998 release_dc_ptr( dc
);
1004 /***********************************************************************
1005 * SetTextAlign (GDI32.@)
1007 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1009 UINT ret
= GDI_ERROR
;
1010 DC
*dc
= get_dc_ptr( hdc
);
1012 TRACE("hdc=%p align=%d\n", hdc
, align
);
1016 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
1017 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
1018 if (align
!= GDI_ERROR
)
1020 ret
= dc
->textAlign
;
1021 dc
->textAlign
= align
;
1023 release_dc_ptr( dc
);
1028 /***********************************************************************
1029 * GetDCOrgEx (GDI32.@)
1031 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1035 if (!lpp
) return FALSE
;
1036 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1037 lpp
->x
= dc
->vis_rect
.left
;
1038 lpp
->y
= dc
->vis_rect
.top
;
1039 release_dc_ptr( dc
);
1044 /***********************************************************************
1045 * GetGraphicsMode (GDI32.@)
1047 INT WINAPI
GetGraphicsMode( HDC hdc
)
1050 DC
* dc
= get_dc_ptr( hdc
);
1053 ret
= dc
->GraphicsMode
;
1054 release_dc_ptr( dc
);
1060 /***********************************************************************
1061 * SetGraphicsMode (GDI32.@)
1063 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1066 DC
*dc
= get_dc_ptr( hdc
);
1068 /* One would think that setting the graphics mode to GM_COMPATIBLE
1069 * would also reset the world transformation matrix to the unity
1070 * matrix. However, in Windows, this is not the case. This doesn't
1071 * make a lot of sense to me, but that's the way it is.
1074 if ((mode
> 0) && (mode
<= GM_LAST
))
1076 ret
= dc
->GraphicsMode
;
1077 dc
->GraphicsMode
= mode
;
1079 release_dc_ptr( dc
);
1084 /***********************************************************************
1085 * GetArcDirection (GDI32.@)
1087 INT WINAPI
GetArcDirection( HDC hdc
)
1090 DC
* dc
= get_dc_ptr( hdc
);
1093 ret
= dc
->ArcDirection
;
1094 release_dc_ptr( dc
);
1100 /***********************************************************************
1101 * SetArcDirection (GDI32.@)
1103 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1108 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1110 SetLastError(ERROR_INVALID_PARAMETER
);
1114 if ((dc
= get_dc_ptr( hdc
)))
1116 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1117 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1120 ret
= dc
->ArcDirection
;
1121 dc
->ArcDirection
= dir
;
1123 release_dc_ptr( dc
);
1129 /***********************************************************************
1130 * GetWorldTransform (GDI32.@)
1132 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1135 if (!xform
) return FALSE
;
1136 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1137 *xform
= dc
->xformWorld2Wnd
;
1138 release_dc_ptr( dc
);
1143 /***********************************************************************
1144 * GetTransform (GDI32.@)
1148 * Returns one of the co-ordinate space transforms
1151 * hdc [I] Device context.
1152 * which [I] Which xform to return:
1153 * 0x203 World -> Page transform (that set by SetWorldTransform).
1154 * 0x304 Page -> Device transform (the mapping mode transform).
1155 * 0x204 World -> Device transform (the combination of the above two).
1156 * 0x402 Device -> World transform (the inversion of the above).
1157 * xform [O] The xform.
1160 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1163 DC
*dc
= get_dc_ptr( hdc
);
1164 if (!dc
) return FALSE
;
1169 *xform
= dc
->xformWorld2Wnd
;
1173 construct_window_to_viewport(dc
, xform
);
1177 *xform
= dc
->xformWorld2Vport
;
1181 *xform
= dc
->xformVport2World
;
1185 FIXME("Unknown code %x\n", which
);
1189 release_dc_ptr( dc
);
1194 /****************************************************************************
1195 * CombineTransform [GDI32.@]
1196 * Combines two transformation matrices.
1199 * xformResult [O] Stores the result of combining the two matrices
1200 * xform1 [I] Specifies the first matrix to apply
1201 * xform2 [I] Specifies the second matrix to apply
1204 * The same matrix can be passed in for more than one of the parameters.
1208 * Failure: FALSE. Use GetLastError() to determine the cause.
1210 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1211 const XFORM
*xform2
)
1215 /* Check for illegal parameters */
1216 if (!xformResult
|| !xform1
|| !xform2
)
1219 /* Create the result in a temporary XFORM, since xformResult may be
1220 * equal to xform1 or xform2 */
1221 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1222 xform1
->eM12
* xform2
->eM21
;
1223 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1224 xform1
->eM12
* xform2
->eM22
;
1225 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1226 xform1
->eM22
* xform2
->eM21
;
1227 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1228 xform1
->eM22
* xform2
->eM22
;
1229 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1230 xform1
->eDy
* xform2
->eM21
+
1232 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1233 xform1
->eDy
* xform2
->eM22
+
1236 /* Copy the result to xformResult */
1237 *xformResult
= xformTemp
;
1243 /***********************************************************************
1244 * SetDCHook (GDI32.@)
1246 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1248 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1250 DC
*dc
= get_dc_ptr( hdc
);
1252 if (!dc
) return FALSE
;
1254 dc
->dwHookData
= dwHookData
;
1255 dc
->hookProc
= hookProc
;
1256 release_dc_ptr( dc
);
1261 /***********************************************************************
1262 * GetDCHook (GDI32.@)
1264 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1266 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1268 DC
*dc
= get_dc_ptr( hdc
);
1272 if (proc
) *proc
= dc
->hookProc
;
1273 ret
= dc
->dwHookData
;
1274 release_dc_ptr( dc
);
1279 /***********************************************************************
1280 * SetHookFlags (GDI32.@)
1282 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1284 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1286 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1291 /* "Undocumented Windows" info is slightly confusing. */
1293 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1295 if (flags
& DCHF_INVALIDATEVISRGN
)
1296 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1297 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1298 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1300 GDI_ReleaseObj( hdc
);
1304 /***********************************************************************
1305 * SetICMMode (GDI32.@)
1307 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1309 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1310 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1311 if (iEnableICM
== ICM_ON
) return 0;
1312 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1316 /***********************************************************************
1317 * GetDeviceGammaRamp (GDI32.@)
1319 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1322 DC
*dc
= get_dc_ptr( hDC
);
1326 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceGammaRamp
);
1327 ret
= physdev
->funcs
->pGetDeviceGammaRamp( physdev
, ptr
);
1328 release_dc_ptr( dc
);
1333 /***********************************************************************
1334 * SetDeviceGammaRamp (GDI32.@)
1336 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1339 DC
*dc
= get_dc_ptr( hDC
);
1343 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDeviceGammaRamp
);
1344 ret
= physdev
->funcs
->pSetDeviceGammaRamp( physdev
, ptr
);
1345 release_dc_ptr( dc
);
1350 /***********************************************************************
1351 * GetColorSpace (GDI32.@)
1353 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1355 /*FIXME Need to to whatever GetColorSpace actually does */
1359 /***********************************************************************
1360 * CreateColorSpaceA (GDI32.@)
1362 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1368 /***********************************************************************
1369 * CreateColorSpaceW (GDI32.@)
1371 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1377 /***********************************************************************
1378 * DeleteColorSpace (GDI32.@)
1380 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1387 /***********************************************************************
1388 * SetColorSpace (GDI32.@)
1390 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1397 /***********************************************************************
1398 * GetBoundsRect (GDI32.@)
1400 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1403 DC
*dc
= get_dc_ptr( hdc
);
1405 if ( !dc
) return 0;
1409 *rect
= dc
->BoundsRect
;
1410 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1415 if (flags
& DCB_RESET
)
1417 dc
->BoundsRect
.left
= 0;
1418 dc
->BoundsRect
.top
= 0;
1419 dc
->BoundsRect
.right
= 0;
1420 dc
->BoundsRect
.bottom
= 0;
1421 dc
->flags
&= ~DC_BOUNDS_SET
;
1423 release_dc_ptr( dc
);
1428 /***********************************************************************
1429 * SetBoundsRect (GDI32.@)
1431 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1436 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1437 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1439 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1440 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1442 if (flags
& DCB_RESET
)
1444 dc
->BoundsRect
.left
= 0;
1445 dc
->BoundsRect
.top
= 0;
1446 dc
->BoundsRect
.right
= 0;
1447 dc
->BoundsRect
.bottom
= 0;
1448 dc
->flags
&= ~DC_BOUNDS_SET
;
1451 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1453 if (dc
->flags
& DC_BOUNDS_SET
)
1455 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1456 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1457 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1458 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1462 dc
->BoundsRect
= *rect
;
1463 dc
->flags
|= DC_BOUNDS_SET
;
1467 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1468 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1470 release_dc_ptr( dc
);
1475 /***********************************************************************
1476 * GetRelAbs (GDI32.@)
1478 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1481 DC
*dc
= get_dc_ptr( hdc
);
1484 ret
= dc
->relAbsMode
;
1485 release_dc_ptr( dc
);
1493 /***********************************************************************
1494 * GetBkMode (GDI32.@)
1496 INT WINAPI
GetBkMode( HDC hdc
)
1499 DC
* dc
= get_dc_ptr( hdc
);
1502 ret
= dc
->backgroundMode
;
1503 release_dc_ptr( dc
);
1509 /***********************************************************************
1510 * SetBkMode (GDI32.@)
1512 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1517 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1519 SetLastError(ERROR_INVALID_PARAMETER
);
1522 if ((dc
= get_dc_ptr( hdc
)))
1524 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1525 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1528 ret
= dc
->backgroundMode
;
1529 dc
->backgroundMode
= mode
;
1531 release_dc_ptr( dc
);
1537 /***********************************************************************
1540 INT WINAPI
GetROP2( HDC hdc
)
1543 DC
* dc
= get_dc_ptr( hdc
);
1547 release_dc_ptr( dc
);
1553 /***********************************************************************
1556 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1561 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1563 SetLastError(ERROR_INVALID_PARAMETER
);
1566 if ((dc
= get_dc_ptr( hdc
)))
1568 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1569 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1575 release_dc_ptr( dc
);
1581 /***********************************************************************
1582 * SetRelAbs (GDI32.@)
1584 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1589 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1591 SetLastError(ERROR_INVALID_PARAMETER
);
1594 if ((dc
= get_dc_ptr( hdc
)))
1596 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1597 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1600 ret
= dc
->relAbsMode
;
1601 dc
->relAbsMode
= mode
;
1603 release_dc_ptr( dc
);
1609 /***********************************************************************
1610 * GetPolyFillMode (GDI32.@)
1612 INT WINAPI
GetPolyFillMode( HDC hdc
)
1615 DC
* dc
= get_dc_ptr( hdc
);
1618 ret
= dc
->polyFillMode
;
1619 release_dc_ptr( dc
);
1625 /***********************************************************************
1626 * SetPolyFillMode (GDI32.@)
1628 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1633 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1635 SetLastError(ERROR_INVALID_PARAMETER
);
1638 if ((dc
= get_dc_ptr( hdc
)))
1640 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1641 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1644 ret
= dc
->polyFillMode
;
1645 dc
->polyFillMode
= mode
;
1647 release_dc_ptr( dc
);
1653 /***********************************************************************
1654 * GetStretchBltMode (GDI32.@)
1656 INT WINAPI
GetStretchBltMode( HDC hdc
)
1659 DC
* dc
= get_dc_ptr( hdc
);
1662 ret
= dc
->stretchBltMode
;
1663 release_dc_ptr( dc
);
1669 /***********************************************************************
1670 * SetStretchBltMode (GDI32.@)
1672 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1677 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1679 SetLastError(ERROR_INVALID_PARAMETER
);
1682 if ((dc
= get_dc_ptr( hdc
)))
1684 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1685 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1688 ret
= dc
->stretchBltMode
;
1689 dc
->stretchBltMode
= mode
;
1691 release_dc_ptr( dc
);
1697 /***********************************************************************
1698 * GetMapMode (GDI32.@)
1700 INT WINAPI
GetMapMode( HDC hdc
)
1703 DC
* dc
= get_dc_ptr( hdc
);
1707 release_dc_ptr( dc
);
1713 /***********************************************************************
1714 * GetBrushOrgEx (GDI32.@)
1716 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1718 DC
* dc
= get_dc_ptr( hdc
);
1719 if (!dc
) return FALSE
;
1720 pt
->x
= dc
->brushOrgX
;
1721 pt
->y
= dc
->brushOrgY
;
1722 release_dc_ptr( dc
);
1727 /***********************************************************************
1728 * GetCurrentPositionEx (GDI32.@)
1730 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1732 DC
* dc
= get_dc_ptr( hdc
);
1733 if (!dc
) return FALSE
;
1734 pt
->x
= dc
->CursPosX
;
1735 pt
->y
= dc
->CursPosY
;
1736 release_dc_ptr( dc
);
1741 /***********************************************************************
1742 * GetViewportExtEx (GDI32.@)
1744 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1746 DC
* dc
= get_dc_ptr( hdc
);
1747 if (!dc
) return FALSE
;
1748 size
->cx
= dc
->vportExtX
;
1749 size
->cy
= dc
->vportExtY
;
1750 release_dc_ptr( dc
);
1755 /***********************************************************************
1756 * GetViewportOrgEx (GDI32.@)
1758 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1760 DC
* dc
= get_dc_ptr( hdc
);
1761 if (!dc
) return FALSE
;
1762 pt
->x
= dc
->vportOrgX
;
1763 pt
->y
= dc
->vportOrgY
;
1764 release_dc_ptr( dc
);
1769 /***********************************************************************
1770 * GetWindowExtEx (GDI32.@)
1772 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1774 DC
* dc
= get_dc_ptr( hdc
);
1775 if (!dc
) return FALSE
;
1776 size
->cx
= dc
->wndExtX
;
1777 size
->cy
= dc
->wndExtY
;
1778 release_dc_ptr( dc
);
1783 /***********************************************************************
1784 * GetWindowOrgEx (GDI32.@)
1786 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1788 DC
* dc
= get_dc_ptr( hdc
);
1789 if (!dc
) return FALSE
;
1790 pt
->x
= dc
->wndOrgX
;
1791 pt
->y
= dc
->wndOrgY
;
1792 release_dc_ptr( dc
);
1797 /***********************************************************************
1798 * GetLayout (GDI32.@)
1800 * Gets left->right or right->left text layout flags of a dc.
1803 DWORD WINAPI
GetLayout(HDC hdc
)
1805 DWORD layout
= GDI_ERROR
;
1807 DC
* dc
= get_dc_ptr( hdc
);
1810 layout
= dc
->layout
;
1811 release_dc_ptr( dc
);
1814 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1819 /***********************************************************************
1820 * SetLayout (GDI32.@)
1822 * Sets left->right or right->left text layout flags of a dc.
1825 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1827 DWORD oldlayout
= GDI_ERROR
;
1829 DC
* dc
= get_dc_ptr( hdc
);
1832 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetLayout
);
1833 layout
= physdev
->funcs
->pSetLayout( physdev
, layout
);
1834 if (layout
!= GDI_ERROR
)
1836 oldlayout
= dc
->layout
;
1837 dc
->layout
= layout
;
1838 if (layout
!= oldlayout
)
1840 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1841 DC_UpdateXforms( dc
);
1844 release_dc_ptr( dc
);
1847 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1852 /***********************************************************************
1853 * GetDCBrushColor (GDI32.@)
1855 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1858 COLORREF dcBrushColor
= CLR_INVALID
;
1860 TRACE("hdc(%p)\n", hdc
);
1862 dc
= get_dc_ptr( hdc
);
1865 dcBrushColor
= dc
->dcBrushColor
;
1866 release_dc_ptr( dc
);
1869 return dcBrushColor
;
1872 /***********************************************************************
1873 * SetDCBrushColor (GDI32.@)
1875 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1878 COLORREF oldClr
= CLR_INVALID
;
1880 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1882 dc
= get_dc_ptr( hdc
);
1885 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
1886 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
1887 if (crColor
!= CLR_INVALID
)
1889 oldClr
= dc
->dcBrushColor
;
1890 dc
->dcBrushColor
= crColor
;
1892 release_dc_ptr( dc
);
1898 /***********************************************************************
1899 * GetDCPenColor (GDI32.@)
1901 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1904 COLORREF dcPenColor
= CLR_INVALID
;
1906 TRACE("hdc(%p)\n", hdc
);
1908 dc
= get_dc_ptr( hdc
);
1911 dcPenColor
= dc
->dcPenColor
;
1912 release_dc_ptr( dc
);
1918 /***********************************************************************
1919 * SetDCPenColor (GDI32.@)
1921 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1924 COLORREF oldClr
= CLR_INVALID
;
1926 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1928 dc
= get_dc_ptr( hdc
);
1931 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
1932 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
1933 if (crColor
!= CLR_INVALID
)
1935 oldClr
= dc
->dcPenColor
;
1936 dc
->dcPenColor
= crColor
;
1938 release_dc_ptr( dc
);
1944 /***********************************************************************
1945 * CancelDC (GDI32.@)
1947 BOOL WINAPI
CancelDC(HDC hdc
)
1953 /*******************************************************************
1954 * GetMiterLimit [GDI32.@]
1958 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
1963 TRACE("(%p,%p)\n", hdc
, peLimit
);
1965 dc
= get_dc_ptr( hdc
);
1969 *peLimit
= dc
->miterLimit
;
1971 release_dc_ptr( dc
);
1977 /*******************************************************************
1978 * SetMiterLimit [GDI32.@]
1982 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
1987 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
1989 dc
= get_dc_ptr( hdc
);
1993 *peOldLimit
= dc
->miterLimit
;
1994 dc
->miterLimit
= eNewLimit
;
1995 release_dc_ptr( dc
);
2001 /*******************************************************************
2002 * GdiIsMetaPrintDC [GDI32.@]
2004 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2010 /*******************************************************************
2011 * GdiIsMetaFileDC [GDI32.@]
2013 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2017 switch( GetObjectType( hdc
) )
2026 /*******************************************************************
2027 * GdiIsPlayMetafileDC [GDI32.@]
2029 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)