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
)
186 PHYSDEV physdev
= pop_dc_driver( &dc
->physDev
);
187 physdev
->funcs
->pDeleteDC( physdev
);
189 free_gdi_handle( dc
->hSelf
);
194 /***********************************************************************
197 * Retrieve a DC pointer but release the GDI lock.
199 DC
*get_dc_ptr( HDC hdc
)
201 DC
*dc
= get_dc_obj( hdc
);
202 if (!dc
) return NULL
;
204 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
206 dc
->thread
= GetCurrentThreadId();
208 else if (dc
->thread
!= GetCurrentThreadId())
210 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
211 GDI_ReleaseObj( hdc
);
214 else InterlockedIncrement( &dc
->refcount
);
216 GDI_ReleaseObj( hdc
);
221 /***********************************************************************
224 void release_dc_ptr( DC
*dc
)
229 ref
= InterlockedDecrement( &dc
->refcount
);
231 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
235 /***********************************************************************
238 * Make sure the DC vis region is up to date.
239 * This function may call up to USER so the GDI lock should _not_
240 * be held when calling it.
242 void update_dc( DC
*dc
)
244 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
245 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
249 /***********************************************************************
252 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
254 return DeleteDC( handle
);
258 /***********************************************************************
261 * Setup device-specific DC values for a newly created DC.
263 void DC_InitDC( DC
* dc
)
265 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRealizeDefaultPalette
);
266 physdev
->funcs
->pRealizeDefaultPalette( physdev
);
267 SetTextColor( dc
->hSelf
, dc
->textColor
);
268 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
269 SelectObject( dc
->hSelf
, dc
->hPen
);
270 SelectObject( dc
->hSelf
, dc
->hBrush
);
271 SelectObject( dc
->hSelf
, dc
->hFont
);
272 CLIPPING_UpdateGCRegion( dc
);
273 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
277 /***********************************************************************
280 * Computes the inverse of the transformation xformSrc and stores it to
281 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
284 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
288 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
289 xformSrc
->eM12
*xformSrc
->eM21
;
290 if (determinant
> -1e-12 && determinant
< 1e-12)
293 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
294 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
295 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
296 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
297 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
298 xformSrc
->eDy
* xformDest
->eM21
;
299 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
300 xformSrc
->eDy
* xformDest
->eM22
;
305 /* Construct a transformation to do the window-to-viewport conversion */
306 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
308 double scaleX
, scaleY
;
309 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
310 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
312 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
313 xform
->eM11
= scaleX
;
316 xform
->eM22
= scaleY
;
317 xform
->eDx
= (double)dc
->vportOrgX
- scaleX
* (double)dc
->wndOrgX
;
318 xform
->eDy
= (double)dc
->vportOrgY
- scaleY
* (double)dc
->wndOrgY
;
319 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
322 /***********************************************************************
325 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
326 * fields of the specified DC by creating a transformation that
327 * represents the current mapping mode and combining it with the DC's
328 * world transform. This function should be called whenever the
329 * parameters associated with the mapping mode (window and viewport
330 * extents and origins) or the world transform change.
332 void DC_UpdateXforms( DC
*dc
)
334 XFORM xformWnd2Vport
, oldworld2vport
;
336 construct_window_to_viewport(dc
, &xformWnd2Vport
);
338 oldworld2vport
= dc
->xformWorld2Vport
;
339 /* Combine with the world transformation */
340 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
343 /* Create inverse of world-to-viewport transformation */
344 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
345 &dc
->xformVport2World
);
347 /* Reselect the font and pen back into the dc so that the size
349 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
350 !GdiIsMetaFileDC(dc
->hSelf
))
352 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
353 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
358 /***********************************************************************
361 INT
nulldrv_SaveDC( PHYSDEV dev
)
363 DC
*newdc
, *dc
= get_nulldrv_dc( dev
);
365 if (!(newdc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc
)))) return 0;
366 newdc
->flags
= dc
->flags
;
367 newdc
->layout
= dc
->layout
;
368 newdc
->hPen
= dc
->hPen
;
369 newdc
->hBrush
= dc
->hBrush
;
370 newdc
->hFont
= dc
->hFont
;
371 newdc
->hBitmap
= dc
->hBitmap
;
372 newdc
->hDevice
= dc
->hDevice
;
373 newdc
->hPalette
= dc
->hPalette
;
374 newdc
->ROPmode
= dc
->ROPmode
;
375 newdc
->polyFillMode
= dc
->polyFillMode
;
376 newdc
->stretchBltMode
= dc
->stretchBltMode
;
377 newdc
->relAbsMode
= dc
->relAbsMode
;
378 newdc
->backgroundMode
= dc
->backgroundMode
;
379 newdc
->backgroundColor
= dc
->backgroundColor
;
380 newdc
->textColor
= dc
->textColor
;
381 newdc
->dcBrushColor
= dc
->dcBrushColor
;
382 newdc
->dcPenColor
= dc
->dcPenColor
;
383 newdc
->brushOrgX
= dc
->brushOrgX
;
384 newdc
->brushOrgY
= dc
->brushOrgY
;
385 newdc
->mapperFlags
= dc
->mapperFlags
;
386 newdc
->textAlign
= dc
->textAlign
;
387 newdc
->charExtra
= dc
->charExtra
;
388 newdc
->breakExtra
= dc
->breakExtra
;
389 newdc
->breakRem
= dc
->breakRem
;
390 newdc
->MapMode
= dc
->MapMode
;
391 newdc
->GraphicsMode
= dc
->GraphicsMode
;
392 newdc
->CursPosX
= dc
->CursPosX
;
393 newdc
->CursPosY
= dc
->CursPosY
;
394 newdc
->ArcDirection
= dc
->ArcDirection
;
395 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
396 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
397 newdc
->xformVport2World
= dc
->xformVport2World
;
398 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
399 newdc
->wndOrgX
= dc
->wndOrgX
;
400 newdc
->wndOrgY
= dc
->wndOrgY
;
401 newdc
->wndExtX
= dc
->wndExtX
;
402 newdc
->wndExtY
= dc
->wndExtY
;
403 newdc
->vportOrgX
= dc
->vportOrgX
;
404 newdc
->vportOrgY
= dc
->vportOrgY
;
405 newdc
->vportExtX
= dc
->vportExtX
;
406 newdc
->vportExtY
= dc
->vportExtY
;
407 newdc
->virtual_res
= dc
->virtual_res
;
408 newdc
->virtual_size
= dc
->virtual_size
;
409 newdc
->BoundsRect
= dc
->BoundsRect
;
410 newdc
->gdiFont
= dc
->gdiFont
;
412 PATH_InitGdiPath( &newdc
->path
);
414 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
419 newdc
->hMetaClipRgn
= 0;
422 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
423 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
427 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
431 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
433 if (!PATH_AssignGdiPath( &newdc
->path
, &dc
->path
))
435 release_dc_ptr( dc
);
436 free_dc_state( newdc
);
440 newdc
->saved_dc
= dc
->saved_dc
;
441 dc
->saved_dc
= newdc
;
442 return ++dc
->saveLevel
;
446 /***********************************************************************
449 BOOL
nulldrv_RestoreDC( PHYSDEV dev
, INT level
)
451 DC
*dcs
, *first_dcs
, *dc
= get_nulldrv_dc( dev
);
454 /* find the state level to restore */
456 if (abs(level
) > dc
->saveLevel
|| level
== 0) return FALSE
;
457 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
458 first_dcs
= dc
->saved_dc
;
459 for (dcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
462 /* restore the state */
464 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
)) return FALSE
;
466 dc
->flags
= dcs
->flags
;
467 dc
->layout
= dcs
->layout
;
468 dc
->hDevice
= dcs
->hDevice
;
469 dc
->ROPmode
= dcs
->ROPmode
;
470 dc
->polyFillMode
= dcs
->polyFillMode
;
471 dc
->stretchBltMode
= dcs
->stretchBltMode
;
472 dc
->relAbsMode
= dcs
->relAbsMode
;
473 dc
->backgroundMode
= dcs
->backgroundMode
;
474 dc
->backgroundColor
= dcs
->backgroundColor
;
475 dc
->textColor
= dcs
->textColor
;
476 dc
->dcBrushColor
= dcs
->dcBrushColor
;
477 dc
->dcPenColor
= dcs
->dcPenColor
;
478 dc
->brushOrgX
= dcs
->brushOrgX
;
479 dc
->brushOrgY
= dcs
->brushOrgY
;
480 dc
->mapperFlags
= dcs
->mapperFlags
;
481 dc
->textAlign
= dcs
->textAlign
;
482 dc
->charExtra
= dcs
->charExtra
;
483 dc
->breakExtra
= dcs
->breakExtra
;
484 dc
->breakRem
= dcs
->breakRem
;
485 dc
->MapMode
= dcs
->MapMode
;
486 dc
->GraphicsMode
= dcs
->GraphicsMode
;
487 dc
->CursPosX
= dcs
->CursPosX
;
488 dc
->CursPosY
= dcs
->CursPosY
;
489 dc
->ArcDirection
= dcs
->ArcDirection
;
490 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
491 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
492 dc
->xformVport2World
= dcs
->xformVport2World
;
493 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
494 dc
->BoundsRect
= dcs
->BoundsRect
;
496 dc
->wndOrgX
= dcs
->wndOrgX
;
497 dc
->wndOrgY
= dcs
->wndOrgY
;
498 dc
->wndExtX
= dcs
->wndExtX
;
499 dc
->wndExtY
= dcs
->wndExtY
;
500 dc
->vportOrgX
= dcs
->vportOrgX
;
501 dc
->vportOrgY
= dcs
->vportOrgY
;
502 dc
->vportExtX
= dcs
->vportExtX
;
503 dc
->vportExtY
= dcs
->vportExtY
;
504 dc
->virtual_res
= dcs
->virtual_res
;
505 dc
->virtual_size
= dcs
->virtual_size
;
509 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
510 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
514 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
519 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
520 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
524 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
527 DC_UpdateXforms( dc
);
528 CLIPPING_UpdateGCRegion( dc
);
530 SelectObject( dev
->hdc
, dcs
->hBitmap
);
531 SelectObject( dev
->hdc
, dcs
->hBrush
);
532 SelectObject( dev
->hdc
, dcs
->hFont
);
533 SelectObject( dev
->hdc
, dcs
->hPen
);
534 SetBkColor( dev
->hdc
, dcs
->backgroundColor
);
535 SetTextColor( dev
->hdc
, dcs
->textColor
);
536 GDISelectPalette( dev
->hdc
, dcs
->hPalette
, FALSE
);
538 dc
->saved_dc
= dcs
->saved_dc
;
540 dc
->saveLevel
= save_level
- 1;
542 /* now destroy all the saved DCs */
546 DC
*next
= first_dcs
->saved_dc
;
547 free_dc_state( first_dcs
);
554 /***********************************************************************
557 INT WINAPI
SaveDC( HDC hdc
)
562 if ((dc
= get_dc_ptr( hdc
)))
564 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSaveDC
);
565 ret
= physdev
->funcs
->pSaveDC( physdev
);
566 release_dc_ptr( dc
);
572 /***********************************************************************
573 * RestoreDC (GDI32.@)
575 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
578 BOOL success
= FALSE
;
580 TRACE("%p %d\n", hdc
, level
);
581 if ((dc
= get_dc_ptr( hdc
)))
583 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRestoreDC
);
585 success
= physdev
->funcs
->pRestoreDC( physdev
, level
);
586 release_dc_ptr( dc
);
592 /***********************************************************************
593 * CreateDCW (GDI32.@)
595 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
596 const DEVMODEW
*initData
)
600 const DC_FUNCTIONS
*funcs
;
605 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
609 ERR( "no device found for %s\n", debugstr_w(device
) );
612 strcpyW(buf
, driver
);
615 if (!(funcs
= DRIVER_load_driver( buf
)))
617 ERR( "no driver found for %s\n", debugstr_w(buf
) );
620 if (!(dc
= alloc_dc_ptr( OBJ_DC
))) goto error
;
623 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
624 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
626 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
627 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
629 if (funcs
->pCreateDC
)
632 if (!funcs
->pCreateDC( hdc
, &physdev
, buf
, device
, output
, initData
))
634 WARN("creation aborted by device\n" );
637 push_dc_driver( &dc
->physDev
, physdev
, funcs
);
640 dc
->vis_rect
.left
= 0;
641 dc
->vis_rect
.top
= 0;
642 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
643 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
644 SetRectRgn(dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
, dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
647 release_dc_ptr( dc
);
651 if (dc
) free_dc_ptr( dc
);
656 /***********************************************************************
657 * CreateDCA (GDI32.@)
659 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
660 const DEVMODEA
*initData
)
662 UNICODE_STRING driverW
, deviceW
, outputW
;
666 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
667 else driverW
.Buffer
= NULL
;
669 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
670 else deviceW
.Buffer
= NULL
;
672 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
673 else outputW
.Buffer
= NULL
;
678 /* don't convert initData for DISPLAY driver, it's not used */
679 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
680 initDataW
= GdiConvertToDevmodeW(initData
);
683 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
685 RtlFreeUnicodeString(&driverW
);
686 RtlFreeUnicodeString(&deviceW
);
687 RtlFreeUnicodeString(&outputW
);
688 HeapFree(GetProcessHeap(), 0, initDataW
);
693 /***********************************************************************
694 * CreateICA (GDI32.@)
696 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
697 const DEVMODEA
* initData
)
699 /* Nothing special yet for ICs */
700 return CreateDCA( driver
, device
, output
, initData
);
704 /***********************************************************************
705 * CreateICW (GDI32.@)
707 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
708 const DEVMODEW
* initData
)
710 /* Nothing special yet for ICs */
711 return CreateDCW( driver
, device
, output
, initData
);
715 /***********************************************************************
716 * CreateCompatibleDC (GDI32.@)
718 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
722 const struct gdi_dc_funcs
*funcs
= &null_driver
;
723 PHYSDEV physDev
= NULL
;
729 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
730 physDev
= GET_DC_PHYSDEV( origDC
, pCreateCompatibleDC
);
731 funcs
= physDev
->funcs
;
732 release_dc_ptr( origDC
);
735 if (!(dc
= alloc_dc_ptr( OBJ_MEMDC
))) goto error
;
737 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
739 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
740 dc
->vis_rect
.left
= 0;
741 dc
->vis_rect
.top
= 0;
742 dc
->vis_rect
.right
= 1;
743 dc
->vis_rect
.bottom
= 1;
744 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
748 if (!funcs
->pCreateCompatibleDC( physDev
, &dc
->physDev
))
750 WARN("creation aborted by device\n");
754 release_dc_ptr( dc
);
758 if (dc
) free_dc_ptr( dc
);
763 /***********************************************************************
766 BOOL WINAPI
DeleteDC( HDC hdc
)
774 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
775 if (dc
->refcount
!= 1)
777 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
778 release_dc_ptr( dc
);
782 /* Call hook procedure to check whether is it OK to delete this DC */
783 if (dc
->hookProc
&& !dc
->hookProc( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
785 release_dc_ptr( dc
);
789 while (dc
->saveLevel
)
791 DC
*dcs
= dc
->saved_dc
;
792 dc
->saved_dc
= dcs
->saved_dc
;
794 free_dc_state( dcs
);
797 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
798 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
799 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
800 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
807 /***********************************************************************
810 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
815 if ((dc
= get_dc_ptr( hdc
)))
817 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pResetDC
);
818 ret
= physdev
->funcs
->pResetDC( physdev
, devmode
);
819 if (ret
) /* reset the visible region */
822 dc
->vis_rect
.left
= 0;
823 dc
->vis_rect
.top
= 0;
824 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
825 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
826 SetRectRgn( dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
,
827 dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
828 CLIPPING_UpdateGCRegion( dc
);
830 release_dc_ptr( dc
);
836 /***********************************************************************
839 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
844 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
845 else devmodeW
= NULL
;
847 ret
= ResetDCW(hdc
, devmodeW
);
849 HeapFree(GetProcessHeap(), 0, devmodeW
);
854 /***********************************************************************
855 * GetDeviceCaps (GDI32.@)
857 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
862 if ((dc
= get_dc_ptr( hdc
)))
864 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceCaps
);
865 ret
= physdev
->funcs
->pGetDeviceCaps( physdev
, cap
);
866 release_dc_ptr( dc
);
872 /***********************************************************************
873 * GetBkColor (GDI32.@)
875 COLORREF WINAPI
GetBkColor( HDC hdc
)
878 DC
* dc
= get_dc_ptr( hdc
);
881 ret
= dc
->backgroundColor
;
882 release_dc_ptr( dc
);
888 /***********************************************************************
889 * SetBkColor (GDI32.@)
891 COLORREF WINAPI
SetBkColor( 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
, pSetBkColor
);
901 color
= physdev
->funcs
->pSetBkColor( physdev
, color
);
902 if (color
!= CLR_INVALID
)
904 ret
= dc
->backgroundColor
;
905 dc
->backgroundColor
= color
;
907 release_dc_ptr( dc
);
913 /***********************************************************************
914 * GetTextColor (GDI32.@)
916 COLORREF WINAPI
GetTextColor( HDC hdc
)
919 DC
* dc
= get_dc_ptr( hdc
);
923 release_dc_ptr( dc
);
929 /***********************************************************************
930 * SetTextColor (GDI32.@)
932 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
934 COLORREF ret
= CLR_INVALID
;
935 DC
* dc
= get_dc_ptr( hdc
);
937 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
941 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
942 color
= physdev
->funcs
->pSetTextColor( physdev
, color
);
943 if (color
!= CLR_INVALID
)
946 dc
->textColor
= color
;
948 release_dc_ptr( dc
);
954 /***********************************************************************
955 * GetTextAlign (GDI32.@)
957 UINT WINAPI
GetTextAlign( HDC hdc
)
960 DC
* dc
= get_dc_ptr( hdc
);
964 release_dc_ptr( dc
);
970 /***********************************************************************
971 * SetTextAlign (GDI32.@)
973 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
975 UINT ret
= GDI_ERROR
;
976 DC
*dc
= get_dc_ptr( hdc
);
978 TRACE("hdc=%p align=%d\n", hdc
, align
);
982 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
983 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
984 if (align
!= GDI_ERROR
)
987 dc
->textAlign
= align
;
989 release_dc_ptr( dc
);
994 /***********************************************************************
995 * GetDCOrgEx (GDI32.@)
997 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1001 if (!lpp
) return FALSE
;
1002 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1003 lpp
->x
= dc
->vis_rect
.left
;
1004 lpp
->y
= dc
->vis_rect
.top
;
1005 release_dc_ptr( dc
);
1010 /***********************************************************************
1011 * GetGraphicsMode (GDI32.@)
1013 INT WINAPI
GetGraphicsMode( HDC hdc
)
1016 DC
* dc
= get_dc_ptr( hdc
);
1019 ret
= dc
->GraphicsMode
;
1020 release_dc_ptr( dc
);
1026 /***********************************************************************
1027 * SetGraphicsMode (GDI32.@)
1029 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1032 DC
*dc
= get_dc_ptr( hdc
);
1034 /* One would think that setting the graphics mode to GM_COMPATIBLE
1035 * would also reset the world transformation matrix to the unity
1036 * matrix. However, in Windows, this is not the case. This doesn't
1037 * make a lot of sense to me, but that's the way it is.
1040 if ((mode
> 0) && (mode
<= GM_LAST
))
1042 ret
= dc
->GraphicsMode
;
1043 dc
->GraphicsMode
= mode
;
1045 release_dc_ptr( dc
);
1050 /***********************************************************************
1051 * GetArcDirection (GDI32.@)
1053 INT WINAPI
GetArcDirection( HDC hdc
)
1056 DC
* dc
= get_dc_ptr( hdc
);
1059 ret
= dc
->ArcDirection
;
1060 release_dc_ptr( dc
);
1066 /***********************************************************************
1067 * SetArcDirection (GDI32.@)
1069 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1074 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1076 SetLastError(ERROR_INVALID_PARAMETER
);
1080 if ((dc
= get_dc_ptr( hdc
)))
1082 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1083 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1086 ret
= dc
->ArcDirection
;
1087 dc
->ArcDirection
= dir
;
1089 release_dc_ptr( dc
);
1095 /***********************************************************************
1096 * GetWorldTransform (GDI32.@)
1098 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1101 if (!xform
) return FALSE
;
1102 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1103 *xform
= dc
->xformWorld2Wnd
;
1104 release_dc_ptr( dc
);
1109 /***********************************************************************
1110 * GetTransform (GDI32.@)
1114 * Returns one of the co-ordinate space transforms
1117 * hdc [I] Device context.
1118 * which [I] Which xform to return:
1119 * 0x203 World -> Page transform (that set by SetWorldTransform).
1120 * 0x304 Page -> Device transform (the mapping mode transform).
1121 * 0x204 World -> Device transform (the combination of the above two).
1122 * 0x402 Device -> World transform (the inversion of the above).
1123 * xform [O] The xform.
1126 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1129 DC
*dc
= get_dc_ptr( hdc
);
1130 if (!dc
) return FALSE
;
1135 *xform
= dc
->xformWorld2Wnd
;
1139 construct_window_to_viewport(dc
, xform
);
1143 *xform
= dc
->xformWorld2Vport
;
1147 *xform
= dc
->xformVport2World
;
1151 FIXME("Unknown code %x\n", which
);
1155 release_dc_ptr( dc
);
1160 /****************************************************************************
1161 * CombineTransform [GDI32.@]
1162 * Combines two transformation matrices.
1165 * xformResult [O] Stores the result of combining the two matrices
1166 * xform1 [I] Specifies the first matrix to apply
1167 * xform2 [I] Specifies the second matrix to apply
1170 * The same matrix can be passed in for more than one of the parameters.
1174 * Failure: FALSE. Use GetLastError() to determine the cause.
1176 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1177 const XFORM
*xform2
)
1181 /* Check for illegal parameters */
1182 if (!xformResult
|| !xform1
|| !xform2
)
1185 /* Create the result in a temporary XFORM, since xformResult may be
1186 * equal to xform1 or xform2 */
1187 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1188 xform1
->eM12
* xform2
->eM21
;
1189 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1190 xform1
->eM12
* xform2
->eM22
;
1191 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1192 xform1
->eM22
* xform2
->eM21
;
1193 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1194 xform1
->eM22
* xform2
->eM22
;
1195 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1196 xform1
->eDy
* xform2
->eM21
+
1198 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1199 xform1
->eDy
* xform2
->eM22
+
1202 /* Copy the result to xformResult */
1203 *xformResult
= xformTemp
;
1209 /***********************************************************************
1210 * SetDCHook (GDI32.@)
1212 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1214 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1216 DC
*dc
= get_dc_ptr( hdc
);
1218 if (!dc
) return FALSE
;
1220 dc
->dwHookData
= dwHookData
;
1221 dc
->hookProc
= hookProc
;
1222 release_dc_ptr( dc
);
1227 /***********************************************************************
1228 * GetDCHook (GDI32.@)
1230 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1232 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1234 DC
*dc
= get_dc_ptr( hdc
);
1238 if (proc
) *proc
= dc
->hookProc
;
1239 ret
= dc
->dwHookData
;
1240 release_dc_ptr( dc
);
1245 /***********************************************************************
1246 * SetHookFlags (GDI32.@)
1248 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1250 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1252 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1257 /* "Undocumented Windows" info is slightly confusing. */
1259 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1261 if (flags
& DCHF_INVALIDATEVISRGN
)
1262 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1263 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1264 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1266 GDI_ReleaseObj( hdc
);
1270 /***********************************************************************
1271 * SetICMMode (GDI32.@)
1273 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1275 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1276 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1277 if (iEnableICM
== ICM_ON
) return 0;
1278 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1282 /***********************************************************************
1283 * GetDeviceGammaRamp (GDI32.@)
1285 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1288 DC
*dc
= get_dc_ptr( hDC
);
1292 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceGammaRamp
);
1293 ret
= physdev
->funcs
->pGetDeviceGammaRamp( physdev
, ptr
);
1294 release_dc_ptr( dc
);
1299 /***********************************************************************
1300 * SetDeviceGammaRamp (GDI32.@)
1302 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1305 DC
*dc
= get_dc_ptr( hDC
);
1309 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDeviceGammaRamp
);
1310 ret
= physdev
->funcs
->pSetDeviceGammaRamp( physdev
, ptr
);
1311 release_dc_ptr( dc
);
1316 /***********************************************************************
1317 * GetColorSpace (GDI32.@)
1319 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1321 /*FIXME Need to to whatever GetColorSpace actually does */
1325 /***********************************************************************
1326 * CreateColorSpaceA (GDI32.@)
1328 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1334 /***********************************************************************
1335 * CreateColorSpaceW (GDI32.@)
1337 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1343 /***********************************************************************
1344 * DeleteColorSpace (GDI32.@)
1346 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1353 /***********************************************************************
1354 * SetColorSpace (GDI32.@)
1356 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1363 /***********************************************************************
1364 * GetBoundsRect (GDI32.@)
1366 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1369 DC
*dc
= get_dc_ptr( hdc
);
1371 if ( !dc
) return 0;
1375 *rect
= dc
->BoundsRect
;
1376 ret
= is_rect_empty( rect
) ? DCB_RESET
: DCB_SET
;
1377 DPtoLP( hdc
, (POINT
*)rect
, 2 );
1379 if (flags
& DCB_RESET
)
1381 dc
->BoundsRect
.left
= 0;
1382 dc
->BoundsRect
.top
= 0;
1383 dc
->BoundsRect
.right
= 0;
1384 dc
->BoundsRect
.bottom
= 0;
1386 release_dc_ptr( dc
);
1391 /***********************************************************************
1392 * SetBoundsRect (GDI32.@)
1394 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1399 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1400 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1402 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1403 (is_rect_empty( &dc
->BoundsRect
) ? DCB_RESET
: DCB_SET
);
1405 if (flags
& DCB_RESET
)
1407 dc
->BoundsRect
.left
= 0;
1408 dc
->BoundsRect
.top
= 0;
1409 dc
->BoundsRect
.right
= 0;
1410 dc
->BoundsRect
.bottom
= 0;
1413 if ((flags
& DCB_ACCUMULATE
) && rect
)
1417 LPtoDP( hdc
, (POINT
*)&rc
, 2 );
1418 if (!is_rect_empty( &rc
))
1420 if (!is_rect_empty( &dc
->BoundsRect
))
1422 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rc
.left
);
1423 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rc
.top
);
1424 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rc
.right
);
1425 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rc
.bottom
);
1427 else dc
->BoundsRect
= rc
;
1431 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1432 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1434 release_dc_ptr( dc
);
1439 /***********************************************************************
1440 * GetRelAbs (GDI32.@)
1442 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1445 DC
*dc
= get_dc_ptr( hdc
);
1448 ret
= dc
->relAbsMode
;
1449 release_dc_ptr( dc
);
1457 /***********************************************************************
1458 * GetBkMode (GDI32.@)
1460 INT WINAPI
GetBkMode( HDC hdc
)
1463 DC
* dc
= get_dc_ptr( hdc
);
1466 ret
= dc
->backgroundMode
;
1467 release_dc_ptr( dc
);
1473 /***********************************************************************
1474 * SetBkMode (GDI32.@)
1476 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1481 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1483 SetLastError(ERROR_INVALID_PARAMETER
);
1486 if ((dc
= get_dc_ptr( hdc
)))
1488 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1489 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1492 ret
= dc
->backgroundMode
;
1493 dc
->backgroundMode
= mode
;
1495 release_dc_ptr( dc
);
1501 /***********************************************************************
1504 INT WINAPI
GetROP2( HDC hdc
)
1507 DC
* dc
= get_dc_ptr( hdc
);
1511 release_dc_ptr( dc
);
1517 /***********************************************************************
1520 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1525 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1527 SetLastError(ERROR_INVALID_PARAMETER
);
1530 if ((dc
= get_dc_ptr( hdc
)))
1532 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1533 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1539 release_dc_ptr( dc
);
1545 /***********************************************************************
1546 * SetRelAbs (GDI32.@)
1548 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1553 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1555 SetLastError(ERROR_INVALID_PARAMETER
);
1558 if ((dc
= get_dc_ptr( hdc
)))
1560 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1561 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1564 ret
= dc
->relAbsMode
;
1565 dc
->relAbsMode
= mode
;
1567 release_dc_ptr( dc
);
1573 /***********************************************************************
1574 * GetPolyFillMode (GDI32.@)
1576 INT WINAPI
GetPolyFillMode( HDC hdc
)
1579 DC
* dc
= get_dc_ptr( hdc
);
1582 ret
= dc
->polyFillMode
;
1583 release_dc_ptr( dc
);
1589 /***********************************************************************
1590 * SetPolyFillMode (GDI32.@)
1592 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1597 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1599 SetLastError(ERROR_INVALID_PARAMETER
);
1602 if ((dc
= get_dc_ptr( hdc
)))
1604 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1605 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1608 ret
= dc
->polyFillMode
;
1609 dc
->polyFillMode
= mode
;
1611 release_dc_ptr( dc
);
1617 /***********************************************************************
1618 * GetStretchBltMode (GDI32.@)
1620 INT WINAPI
GetStretchBltMode( HDC hdc
)
1623 DC
* dc
= get_dc_ptr( hdc
);
1626 ret
= dc
->stretchBltMode
;
1627 release_dc_ptr( dc
);
1633 /***********************************************************************
1634 * SetStretchBltMode (GDI32.@)
1636 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1641 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1643 SetLastError(ERROR_INVALID_PARAMETER
);
1646 if ((dc
= get_dc_ptr( hdc
)))
1648 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1649 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1652 ret
= dc
->stretchBltMode
;
1653 dc
->stretchBltMode
= mode
;
1655 release_dc_ptr( dc
);
1661 /***********************************************************************
1662 * GetMapMode (GDI32.@)
1664 INT WINAPI
GetMapMode( HDC hdc
)
1667 DC
* dc
= get_dc_ptr( hdc
);
1671 release_dc_ptr( dc
);
1677 /***********************************************************************
1678 * GetBrushOrgEx (GDI32.@)
1680 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1682 DC
* dc
= get_dc_ptr( hdc
);
1683 if (!dc
) return FALSE
;
1684 pt
->x
= dc
->brushOrgX
;
1685 pt
->y
= dc
->brushOrgY
;
1686 release_dc_ptr( dc
);
1691 /***********************************************************************
1692 * GetCurrentPositionEx (GDI32.@)
1694 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1696 DC
* dc
= get_dc_ptr( hdc
);
1697 if (!dc
) return FALSE
;
1698 pt
->x
= dc
->CursPosX
;
1699 pt
->y
= dc
->CursPosY
;
1700 release_dc_ptr( dc
);
1705 /***********************************************************************
1706 * GetViewportExtEx (GDI32.@)
1708 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1710 DC
* dc
= get_dc_ptr( hdc
);
1711 if (!dc
) return FALSE
;
1712 size
->cx
= dc
->vportExtX
;
1713 size
->cy
= dc
->vportExtY
;
1714 release_dc_ptr( dc
);
1719 /***********************************************************************
1720 * GetViewportOrgEx (GDI32.@)
1722 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1724 DC
* dc
= get_dc_ptr( hdc
);
1725 if (!dc
) return FALSE
;
1726 pt
->x
= dc
->vportOrgX
;
1727 pt
->y
= dc
->vportOrgY
;
1728 release_dc_ptr( dc
);
1733 /***********************************************************************
1734 * GetWindowExtEx (GDI32.@)
1736 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1738 DC
* dc
= get_dc_ptr( hdc
);
1739 if (!dc
) return FALSE
;
1740 size
->cx
= dc
->wndExtX
;
1741 size
->cy
= dc
->wndExtY
;
1742 release_dc_ptr( dc
);
1747 /***********************************************************************
1748 * GetWindowOrgEx (GDI32.@)
1750 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1752 DC
* dc
= get_dc_ptr( hdc
);
1753 if (!dc
) return FALSE
;
1754 pt
->x
= dc
->wndOrgX
;
1755 pt
->y
= dc
->wndOrgY
;
1756 release_dc_ptr( dc
);
1761 /***********************************************************************
1762 * GetLayout (GDI32.@)
1764 * Gets left->right or right->left text layout flags of a dc.
1767 DWORD WINAPI
GetLayout(HDC hdc
)
1769 DWORD layout
= GDI_ERROR
;
1771 DC
* dc
= get_dc_ptr( hdc
);
1774 layout
= dc
->layout
;
1775 release_dc_ptr( dc
);
1778 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1783 /***********************************************************************
1784 * SetLayout (GDI32.@)
1786 * Sets left->right or right->left text layout flags of a dc.
1789 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1791 DWORD oldlayout
= GDI_ERROR
;
1793 DC
* dc
= get_dc_ptr( hdc
);
1796 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetLayout
);
1797 layout
= physdev
->funcs
->pSetLayout( physdev
, layout
);
1798 if (layout
!= GDI_ERROR
)
1800 oldlayout
= dc
->layout
;
1801 dc
->layout
= layout
;
1802 if (layout
!= oldlayout
)
1804 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1805 DC_UpdateXforms( dc
);
1808 release_dc_ptr( dc
);
1811 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1816 /***********************************************************************
1817 * GetDCBrushColor (GDI32.@)
1819 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1822 COLORREF dcBrushColor
= CLR_INVALID
;
1824 TRACE("hdc(%p)\n", hdc
);
1826 dc
= get_dc_ptr( hdc
);
1829 dcBrushColor
= dc
->dcBrushColor
;
1830 release_dc_ptr( dc
);
1833 return dcBrushColor
;
1836 /***********************************************************************
1837 * SetDCBrushColor (GDI32.@)
1839 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1842 COLORREF oldClr
= CLR_INVALID
;
1844 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1846 dc
= get_dc_ptr( hdc
);
1849 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
1850 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
1851 if (crColor
!= CLR_INVALID
)
1853 oldClr
= dc
->dcBrushColor
;
1854 dc
->dcBrushColor
= crColor
;
1856 release_dc_ptr( dc
);
1862 /***********************************************************************
1863 * GetDCPenColor (GDI32.@)
1865 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1868 COLORREF dcPenColor
= CLR_INVALID
;
1870 TRACE("hdc(%p)\n", hdc
);
1872 dc
= get_dc_ptr( hdc
);
1875 dcPenColor
= dc
->dcPenColor
;
1876 release_dc_ptr( dc
);
1882 /***********************************************************************
1883 * SetDCPenColor (GDI32.@)
1885 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1888 COLORREF oldClr
= CLR_INVALID
;
1890 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1892 dc
= get_dc_ptr( hdc
);
1895 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
1896 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
1897 if (crColor
!= CLR_INVALID
)
1899 oldClr
= dc
->dcPenColor
;
1900 dc
->dcPenColor
= crColor
;
1902 release_dc_ptr( dc
);
1908 /***********************************************************************
1909 * CancelDC (GDI32.@)
1911 BOOL WINAPI
CancelDC(HDC hdc
)
1917 /*******************************************************************
1918 * GetMiterLimit [GDI32.@]
1922 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
1927 TRACE("(%p,%p)\n", hdc
, peLimit
);
1929 dc
= get_dc_ptr( hdc
);
1933 *peLimit
= dc
->miterLimit
;
1935 release_dc_ptr( dc
);
1941 /*******************************************************************
1942 * SetMiterLimit [GDI32.@]
1946 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
1951 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
1953 dc
= get_dc_ptr( hdc
);
1957 *peOldLimit
= dc
->miterLimit
;
1958 dc
->miterLimit
= eNewLimit
;
1959 release_dc_ptr( dc
);
1965 /*******************************************************************
1966 * GdiIsMetaPrintDC [GDI32.@]
1968 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
1974 /*******************************************************************
1975 * GdiIsMetaFileDC [GDI32.@]
1977 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
1981 switch( GetObjectType( hdc
) )
1990 /*******************************************************************
1991 * GdiIsPlayMetafileDC [GDI32.@]
1993 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)