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
)
56 DC
*dc
= get_any_obj_ptr( hdc
, &type
);
67 GDI_ReleaseObj( hdc
);
68 SetLastError( ERROR_INVALID_HANDLE
);
74 /***********************************************************************
75 * set_initial_dc_state
77 static void set_initial_dc_state( DC
*dc
)
87 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
89 dc
->font_code_page
= CP_ACP
;
90 dc
->ROPmode
= R2_COPYPEN
;
91 dc
->polyFillMode
= ALTERNATE
;
92 dc
->stretchBltMode
= BLACKONWHITE
;
93 dc
->relAbsMode
= ABSOLUTE
;
94 dc
->backgroundMode
= OPAQUE
;
95 dc
->backgroundColor
= RGB( 255, 255, 255 );
96 dc
->dcBrushColor
= RGB( 255, 255, 255 );
97 dc
->dcPenColor
= RGB( 0, 0, 0 );
98 dc
->textColor
= RGB( 0, 0, 0 );
102 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
106 dc
->MapMode
= MM_TEXT
;
107 dc
->GraphicsMode
= GM_COMPATIBLE
;
110 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
111 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
112 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
113 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
114 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
115 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
116 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
117 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
118 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
119 dc
->vport2WorldValid
= TRUE
;
121 reset_bounds( &dc
->bounds
);
124 /***********************************************************************
127 DC
*alloc_dc_ptr( WORD magic
)
131 if (!(dc
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dc
) ))) return NULL
;
133 dc
->nulldrv
.funcs
= &null_driver
;
134 dc
->physDev
= &dc
->nulldrv
;
135 dc
->thread
= GetCurrentThreadId();
137 dc
->hPen
= GDI_inc_ref_count( GetStockObject( BLACK_PEN
));
138 dc
->hBrush
= GDI_inc_ref_count( GetStockObject( WHITE_BRUSH
));
139 dc
->hFont
= GDI_inc_ref_count( GetStockObject( SYSTEM_FONT
));
140 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
142 set_initial_dc_state( dc
);
144 if (!(dc
->hSelf
= alloc_gdi_handle( dc
, magic
, &dc_funcs
)))
146 HeapFree( GetProcessHeap(), 0, dc
);
149 dc
->nulldrv
.hdc
= dc
->hSelf
;
151 if (font_driver
&& !font_driver
->pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
161 /***********************************************************************
164 static void free_dc_state( DC
*dc
)
166 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
167 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
168 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
169 if (dc
->region
) DeleteObject( dc
->region
);
170 if (dc
->path
) free_gdi_path( dc
->path
);
171 HeapFree( GetProcessHeap(), 0, dc
);
175 /***********************************************************************
178 void free_dc_ptr( DC
*dc
)
180 assert( dc
->refcount
== 1 );
182 while (dc
->physDev
!= &dc
->nulldrv
)
184 PHYSDEV physdev
= dc
->physDev
;
185 dc
->physDev
= physdev
->next
;
186 physdev
->funcs
->pDeleteDC( physdev
);
188 GDI_dec_ref_count( dc
->hPen
);
189 GDI_dec_ref_count( dc
->hBrush
);
190 GDI_dec_ref_count( dc
->hFont
);
191 if (dc
->hBitmap
) GDI_dec_ref_count( dc
->hBitmap
);
192 free_gdi_handle( dc
->hSelf
);
197 /***********************************************************************
200 * Retrieve a DC pointer but release the GDI lock.
202 DC
*get_dc_ptr( HDC hdc
)
204 DC
*dc
= get_dc_obj( hdc
);
205 if (!dc
) return NULL
;
208 GDI_ReleaseObj( hdc
);
212 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
214 dc
->thread
= GetCurrentThreadId();
216 else if (dc
->thread
!= GetCurrentThreadId())
218 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
219 GDI_ReleaseObj( hdc
);
222 else InterlockedIncrement( &dc
->refcount
);
224 GDI_ReleaseObj( hdc
);
229 /***********************************************************************
232 void release_dc_ptr( DC
*dc
)
237 ref
= InterlockedDecrement( &dc
->refcount
);
239 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
243 /***********************************************************************
246 * Make sure the DC vis region is up to date.
247 * This function may call up to USER so the GDI lock should _not_
248 * be held when calling it.
250 void update_dc( DC
*dc
)
252 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
253 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
257 /***********************************************************************
260 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
262 return DeleteDC( handle
);
266 /***********************************************************************
269 * Setup device-specific DC values for a newly created DC.
271 void DC_InitDC( DC
* dc
)
273 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRealizeDefaultPalette
);
274 physdev
->funcs
->pRealizeDefaultPalette( physdev
);
275 SetTextColor( dc
->hSelf
, dc
->textColor
);
276 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
277 SelectObject( dc
->hSelf
, dc
->hPen
);
278 SelectObject( dc
->hSelf
, dc
->hBrush
);
279 SelectObject( dc
->hSelf
, dc
->hFont
);
280 update_dc_clipping( dc
);
281 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
282 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
283 physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
);
287 /***********************************************************************
290 * Computes the inverse of the transformation xformSrc and stores it to
291 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
294 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
298 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
299 xformSrc
->eM12
*xformSrc
->eM21
;
300 if (determinant
> -1e-12 && determinant
< 1e-12)
303 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
304 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
305 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
306 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
307 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
308 xformSrc
->eDy
* xformDest
->eM21
;
309 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
310 xformSrc
->eDy
* xformDest
->eM22
;
315 /* Construct a transformation to do the window-to-viewport conversion */
316 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
318 double scaleX
, scaleY
;
319 scaleX
= (double)dc
->vport_ext
.cx
/ (double)dc
->wnd_ext
.cx
;
320 scaleY
= (double)dc
->vport_ext
.cy
/ (double)dc
->wnd_ext
.cy
;
322 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
323 xform
->eM11
= scaleX
;
326 xform
->eM22
= scaleY
;
327 xform
->eDx
= (double)dc
->vport_org
.x
- scaleX
* (double)dc
->wnd_org
.x
;
328 xform
->eDy
= (double)dc
->vport_org
.y
- scaleY
* (double)dc
->wnd_org
.y
;
329 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
332 /***********************************************************************
335 * Compares the linear transform portion of two XFORMs (i.e. the 2x2 submatrix).
336 * Returns 0 if they match.
338 static inline int linear_xform_cmp( const XFORM
*a
, const XFORM
*b
)
340 return memcmp( a
, b
, FIELD_OFFSET( XFORM
, eDx
) );
343 /***********************************************************************
346 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
347 * fields of the specified DC by creating a transformation that
348 * represents the current mapping mode and combining it with the DC's
349 * world transform. This function should be called whenever the
350 * parameters associated with the mapping mode (window and viewport
351 * extents and origins) or the world transform change.
353 void DC_UpdateXforms( DC
*dc
)
355 XFORM xformWnd2Vport
, oldworld2vport
;
357 construct_window_to_viewport(dc
, &xformWnd2Vport
);
359 oldworld2vport
= dc
->xformWorld2Vport
;
360 /* Combine with the world transformation */
361 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
364 /* Create inverse of world-to-viewport transformation */
365 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
366 &dc
->xformVport2World
);
368 /* Reselect the font and pen back into the dc so that the size
370 if (linear_xform_cmp( &oldworld2vport
, &dc
->xformWorld2Vport
) &&
371 !GdiIsMetaFileDC(dc
->hSelf
))
373 SelectObject(dc
->hSelf
, dc
->hFont
);
374 SelectObject(dc
->hSelf
, dc
->hPen
);
379 /***********************************************************************
382 INT
nulldrv_SaveDC( PHYSDEV dev
)
384 DC
*newdc
, *dc
= get_nulldrv_dc( dev
);
386 if (!(newdc
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*newdc
)))) return 0;
387 newdc
->layout
= dc
->layout
;
388 newdc
->hPen
= dc
->hPen
;
389 newdc
->hBrush
= dc
->hBrush
;
390 newdc
->hFont
= dc
->hFont
;
391 newdc
->hBitmap
= dc
->hBitmap
;
392 newdc
->hPalette
= dc
->hPalette
;
393 newdc
->ROPmode
= dc
->ROPmode
;
394 newdc
->polyFillMode
= dc
->polyFillMode
;
395 newdc
->stretchBltMode
= dc
->stretchBltMode
;
396 newdc
->relAbsMode
= dc
->relAbsMode
;
397 newdc
->backgroundMode
= dc
->backgroundMode
;
398 newdc
->backgroundColor
= dc
->backgroundColor
;
399 newdc
->textColor
= dc
->textColor
;
400 newdc
->dcBrushColor
= dc
->dcBrushColor
;
401 newdc
->dcPenColor
= dc
->dcPenColor
;
402 newdc
->brush_org
= dc
->brush_org
;
403 newdc
->mapperFlags
= dc
->mapperFlags
;
404 newdc
->textAlign
= dc
->textAlign
;
405 newdc
->charExtra
= dc
->charExtra
;
406 newdc
->breakExtra
= dc
->breakExtra
;
407 newdc
->breakRem
= dc
->breakRem
;
408 newdc
->MapMode
= dc
->MapMode
;
409 newdc
->GraphicsMode
= dc
->GraphicsMode
;
410 newdc
->cur_pos
= dc
->cur_pos
;
411 newdc
->ArcDirection
= dc
->ArcDirection
;
412 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
413 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
414 newdc
->xformVport2World
= dc
->xformVport2World
;
415 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
416 newdc
->wnd_org
= dc
->wnd_org
;
417 newdc
->wnd_ext
= dc
->wnd_ext
;
418 newdc
->vport_org
= dc
->vport_org
;
419 newdc
->vport_ext
= dc
->vport_ext
;
420 newdc
->virtual_res
= dc
->virtual_res
;
421 newdc
->virtual_size
= dc
->virtual_size
;
423 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
427 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
432 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
433 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
436 if (!PATH_SavePath( newdc
, dc
))
438 release_dc_ptr( dc
);
439 free_dc_state( newdc
);
443 newdc
->saved_dc
= dc
->saved_dc
;
444 dc
->saved_dc
= newdc
;
445 return ++dc
->saveLevel
;
449 /***********************************************************************
452 BOOL
nulldrv_RestoreDC( PHYSDEV dev
, INT level
)
454 DC
*dcs
, *first_dcs
, *dc
= get_nulldrv_dc( dev
);
457 /* find the state level to restore */
459 if (abs(level
) > dc
->saveLevel
|| level
== 0) return FALSE
;
460 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
461 first_dcs
= dc
->saved_dc
;
462 for (dcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
465 /* restore the state */
467 if (!PATH_RestorePath( dc
, dcs
)) return FALSE
;
469 dc
->layout
= dcs
->layout
;
470 dc
->ROPmode
= dcs
->ROPmode
;
471 dc
->polyFillMode
= dcs
->polyFillMode
;
472 dc
->stretchBltMode
= dcs
->stretchBltMode
;
473 dc
->relAbsMode
= dcs
->relAbsMode
;
474 dc
->backgroundMode
= dcs
->backgroundMode
;
475 dc
->backgroundColor
= dcs
->backgroundColor
;
476 dc
->textColor
= dcs
->textColor
;
477 dc
->dcBrushColor
= dcs
->dcBrushColor
;
478 dc
->dcPenColor
= dcs
->dcPenColor
;
479 dc
->brush_org
= dcs
->brush_org
;
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
->cur_pos
= dcs
->cur_pos
;
488 dc
->ArcDirection
= dcs
->ArcDirection
;
489 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
490 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
491 dc
->xformVport2World
= dcs
->xformVport2World
;
492 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
493 dc
->wnd_org
= dcs
->wnd_org
;
494 dc
->wnd_ext
= dcs
->wnd_ext
;
495 dc
->vport_org
= dcs
->vport_org
;
496 dc
->vport_ext
= dcs
->vport_ext
;
497 dc
->virtual_res
= dcs
->virtual_res
;
498 dc
->virtual_size
= dcs
->virtual_size
;
502 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
503 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
507 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
512 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
513 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
517 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
520 DC_UpdateXforms( dc
);
521 update_dc_clipping( dc
);
523 SelectObject( dev
->hdc
, dcs
->hBitmap
);
524 SelectObject( dev
->hdc
, dcs
->hBrush
);
525 SelectObject( dev
->hdc
, dcs
->hFont
);
526 SelectObject( dev
->hdc
, dcs
->hPen
);
527 SetBkColor( dev
->hdc
, dcs
->backgroundColor
);
528 SetTextColor( dev
->hdc
, dcs
->textColor
);
529 GDISelectPalette( dev
->hdc
, dcs
->hPalette
, FALSE
);
531 dc
->saved_dc
= dcs
->saved_dc
;
533 dc
->saveLevel
= save_level
- 1;
535 /* now destroy all the saved DCs */
539 DC
*next
= first_dcs
->saved_dc
;
540 free_dc_state( first_dcs
);
547 /***********************************************************************
550 static BOOL
reset_dc_state( HDC hdc
)
554 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
556 set_initial_dc_state( dc
);
557 SetBkColor( hdc
, RGB( 255, 255, 255 ));
558 SetTextColor( hdc
, RGB( 0, 0, 0 ));
559 SelectObject( hdc
, GetStockObject( WHITE_BRUSH
));
560 SelectObject( hdc
, GetStockObject( SYSTEM_FONT
));
561 SelectObject( hdc
, GetStockObject( BLACK_PEN
));
562 SetVirtualResolution( hdc
, 0, 0, 0, 0 );
563 GDISelectPalette( hdc
, GetStockObject( DEFAULT_PALETTE
), FALSE
);
564 SetBoundsRect( hdc
, NULL
, DCB_DISABLE
);
567 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
568 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
571 update_dc_clipping( dc
);
573 for (dcs
= dc
->saved_dc
; dcs
; dcs
= next
)
575 next
= dcs
->saved_dc
;
576 free_dc_state( dcs
);
580 release_dc_ptr( dc
);
585 /***********************************************************************
588 INT WINAPI
SaveDC( HDC hdc
)
593 if ((dc
= get_dc_ptr( hdc
)))
595 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSaveDC
);
596 ret
= physdev
->funcs
->pSaveDC( physdev
);
597 release_dc_ptr( dc
);
603 /***********************************************************************
604 * RestoreDC (GDI32.@)
606 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
610 BOOL success
= FALSE
;
612 TRACE("%p %d\n", hdc
, level
);
613 if ((dc
= get_dc_ptr( hdc
)))
616 physdev
= GET_DC_PHYSDEV( dc
, pRestoreDC
);
617 success
= physdev
->funcs
->pRestoreDC( physdev
, level
);
618 release_dc_ptr( dc
);
624 /***********************************************************************
625 * CreateDCW (GDI32.@)
627 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
628 const DEVMODEW
*initData
)
632 const struct gdi_dc_funcs
*funcs
;
637 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
641 ERR( "no device found for %s\n", debugstr_w(device
) );
644 strcpyW(buf
, driver
);
647 if (!(funcs
= DRIVER_load_driver( buf
)))
649 ERR( "no driver found for %s\n", debugstr_w(buf
) );
652 if (!(dc
= alloc_dc_ptr( OBJ_DC
))) return 0;
655 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
657 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
658 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
660 if (funcs
->pCreateDC
)
662 if (!funcs
->pCreateDC( &dc
->physDev
, buf
, device
, output
, initData
))
664 WARN("creation aborted by device\n" );
670 dc
->vis_rect
.left
= 0;
671 dc
->vis_rect
.top
= 0;
672 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
673 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
676 release_dc_ptr( dc
);
681 /***********************************************************************
682 * CreateDCA (GDI32.@)
684 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
685 const DEVMODEA
*initData
)
687 UNICODE_STRING driverW
, deviceW
, outputW
;
691 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
692 else driverW
.Buffer
= NULL
;
694 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
695 else deviceW
.Buffer
= NULL
;
697 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
698 else outputW
.Buffer
= NULL
;
703 /* don't convert initData for DISPLAY driver, it's not used */
704 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
705 initDataW
= GdiConvertToDevmodeW(initData
);
708 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
710 RtlFreeUnicodeString(&driverW
);
711 RtlFreeUnicodeString(&deviceW
);
712 RtlFreeUnicodeString(&outputW
);
713 HeapFree(GetProcessHeap(), 0, initDataW
);
718 /***********************************************************************
719 * CreateICA (GDI32.@)
721 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
722 const DEVMODEA
* initData
)
724 /* Nothing special yet for ICs */
725 return CreateDCA( driver
, device
, output
, initData
);
729 /***********************************************************************
730 * CreateICW (GDI32.@)
732 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
733 const DEVMODEW
* initData
)
735 /* Nothing special yet for ICs */
736 return CreateDCW( driver
, device
, output
, initData
);
740 /***********************************************************************
741 * CreateCompatibleDC (GDI32.@)
743 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
747 const struct gdi_dc_funcs
*funcs
;
748 PHYSDEV physDev
= NULL
;
754 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
755 physDev
= GET_DC_PHYSDEV( origDC
, pCreateCompatibleDC
);
756 funcs
= physDev
->funcs
;
757 release_dc_ptr( origDC
);
759 else funcs
= DRIVER_load_driver( displayW
);
761 if (!(dc
= alloc_dc_ptr( OBJ_MEMDC
))) return 0;
763 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
765 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
766 dc
->vis_rect
.left
= 0;
767 dc
->vis_rect
.top
= 0;
768 dc
->vis_rect
.right
= 1;
769 dc
->vis_rect
.bottom
= 1;
770 dc
->device_rect
= dc
->vis_rect
;
774 if (funcs
->pCreateCompatibleDC
&& !funcs
->pCreateCompatibleDC( physDev
, &dc
->physDev
))
776 WARN("creation aborted by device\n");
781 if (!dib_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
786 physDev
= GET_DC_PHYSDEV( dc
, pSelectBitmap
);
787 physDev
->funcs
->pSelectBitmap( physDev
, dc
->hBitmap
);
790 release_dc_ptr( dc
);
795 /***********************************************************************
798 BOOL WINAPI
DeleteDC( HDC hdc
)
806 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
807 if (dc
->refcount
!= 1)
809 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
810 release_dc_ptr( dc
);
814 /* Call hook procedure to check whether is it OK to delete this DC */
815 if (dc
->hookProc
&& !dc
->hookProc( dc
->hSelf
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
817 release_dc_ptr( dc
);
820 reset_dc_state( hdc
);
826 /***********************************************************************
829 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
834 if ((dc
= get_dc_ptr( hdc
)))
836 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pResetDC
);
837 ret
= physdev
->funcs
->pResetDC( physdev
, devmode
);
838 if (ret
) /* reset the visible region */
841 dc
->vis_rect
.left
= 0;
842 dc
->vis_rect
.top
= 0;
843 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
844 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
845 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
847 update_dc_clipping( dc
);
849 release_dc_ptr( dc
);
855 /***********************************************************************
858 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
863 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
864 else devmodeW
= NULL
;
866 ret
= ResetDCW(hdc
, devmodeW
);
868 HeapFree(GetProcessHeap(), 0, devmodeW
);
873 /***********************************************************************
874 * GetDeviceCaps (GDI32.@)
876 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
881 if ((dc
= get_dc_ptr( hdc
)))
883 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceCaps
);
884 ret
= physdev
->funcs
->pGetDeviceCaps( physdev
, cap
);
885 release_dc_ptr( dc
);
891 /***********************************************************************
892 * GetBkColor (GDI32.@)
894 COLORREF WINAPI
GetBkColor( HDC hdc
)
897 DC
* dc
= get_dc_ptr( hdc
);
900 ret
= dc
->backgroundColor
;
901 release_dc_ptr( dc
);
907 /***********************************************************************
908 * SetBkColor (GDI32.@)
910 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
912 COLORREF ret
= CLR_INVALID
;
913 DC
* dc
= get_dc_ptr( hdc
);
915 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
919 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkColor
);
920 ret
= dc
->backgroundColor
;
921 dc
->backgroundColor
= physdev
->funcs
->pSetBkColor( physdev
, color
);
922 release_dc_ptr( dc
);
928 /***********************************************************************
929 * GetTextColor (GDI32.@)
931 COLORREF WINAPI
GetTextColor( HDC hdc
)
934 DC
* dc
= get_dc_ptr( hdc
);
938 release_dc_ptr( dc
);
944 /***********************************************************************
945 * SetTextColor (GDI32.@)
947 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
949 COLORREF ret
= CLR_INVALID
;
950 DC
* dc
= get_dc_ptr( hdc
);
952 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
956 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
958 dc
->textColor
= physdev
->funcs
->pSetTextColor( physdev
, color
);
959 release_dc_ptr( dc
);
965 /***********************************************************************
966 * GetTextAlign (GDI32.@)
968 UINT WINAPI
GetTextAlign( HDC hdc
)
971 DC
* dc
= get_dc_ptr( hdc
);
975 release_dc_ptr( dc
);
981 /***********************************************************************
982 * SetTextAlign (GDI32.@)
984 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
986 UINT ret
= GDI_ERROR
;
987 DC
*dc
= get_dc_ptr( hdc
);
989 TRACE("hdc=%p align=%d\n", hdc
, align
);
993 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
994 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
995 if (align
!= GDI_ERROR
)
998 dc
->textAlign
= align
;
1000 release_dc_ptr( dc
);
1005 /***********************************************************************
1006 * GetDCOrgEx (GDI32.@)
1008 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1012 if (!lpp
) return FALSE
;
1013 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1014 lpp
->x
= dc
->vis_rect
.left
;
1015 lpp
->y
= dc
->vis_rect
.top
;
1016 release_dc_ptr( dc
);
1021 /***********************************************************************
1022 * GetGraphicsMode (GDI32.@)
1024 INT WINAPI
GetGraphicsMode( HDC hdc
)
1027 DC
* dc
= get_dc_ptr( hdc
);
1030 ret
= dc
->GraphicsMode
;
1031 release_dc_ptr( dc
);
1037 /***********************************************************************
1038 * SetGraphicsMode (GDI32.@)
1040 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1043 DC
*dc
= get_dc_ptr( hdc
);
1045 /* One would think that setting the graphics mode to GM_COMPATIBLE
1046 * would also reset the world transformation matrix to the unity
1047 * matrix. However, in Windows, this is not the case. This doesn't
1048 * make a lot of sense to me, but that's the way it is.
1051 if ((mode
> 0) && (mode
<= GM_LAST
))
1053 ret
= dc
->GraphicsMode
;
1054 dc
->GraphicsMode
= mode
;
1056 /* font metrics depend on the graphics mode */
1057 if (ret
!= mode
) SelectObject(dc
->hSelf
, dc
->hFont
);
1058 release_dc_ptr( dc
);
1063 /***********************************************************************
1064 * GetArcDirection (GDI32.@)
1066 INT WINAPI
GetArcDirection( HDC hdc
)
1069 DC
* dc
= get_dc_ptr( hdc
);
1072 ret
= dc
->ArcDirection
;
1073 release_dc_ptr( dc
);
1079 /***********************************************************************
1080 * SetArcDirection (GDI32.@)
1082 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1087 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1089 SetLastError(ERROR_INVALID_PARAMETER
);
1093 if ((dc
= get_dc_ptr( hdc
)))
1095 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1096 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1099 ret
= dc
->ArcDirection
;
1100 dc
->ArcDirection
= dir
;
1102 release_dc_ptr( dc
);
1108 /***********************************************************************
1109 * GetWorldTransform (GDI32.@)
1111 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1114 if (!xform
) return FALSE
;
1115 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1116 *xform
= dc
->xformWorld2Wnd
;
1117 release_dc_ptr( dc
);
1122 /***********************************************************************
1123 * GetTransform (GDI32.@)
1127 * Returns one of the co-ordinate space transforms
1130 * hdc [I] Device context.
1131 * which [I] Which xform to return:
1132 * 0x203 World -> Page transform (that set by SetWorldTransform).
1133 * 0x304 Page -> Device transform (the mapping mode transform).
1134 * 0x204 World -> Device transform (the combination of the above two).
1135 * 0x402 Device -> World transform (the inversion of the above).
1136 * xform [O] The xform.
1139 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1142 DC
*dc
= get_dc_ptr( hdc
);
1143 if (!dc
) return FALSE
;
1148 *xform
= dc
->xformWorld2Wnd
;
1152 construct_window_to_viewport(dc
, xform
);
1156 *xform
= dc
->xformWorld2Vport
;
1160 *xform
= dc
->xformVport2World
;
1164 FIXME("Unknown code %x\n", which
);
1168 release_dc_ptr( dc
);
1173 /****************************************************************************
1174 * CombineTransform [GDI32.@]
1175 * Combines two transformation matrices.
1178 * xformResult [O] Stores the result of combining the two matrices
1179 * xform1 [I] Specifies the first matrix to apply
1180 * xform2 [I] Specifies the second matrix to apply
1183 * The same matrix can be passed in for more than one of the parameters.
1187 * Failure: FALSE. Use GetLastError() to determine the cause.
1189 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1190 const XFORM
*xform2
)
1194 /* Check for illegal parameters */
1195 if (!xformResult
|| !xform1
|| !xform2
)
1198 /* Create the result in a temporary XFORM, since xformResult may be
1199 * equal to xform1 or xform2 */
1200 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1201 xform1
->eM12
* xform2
->eM21
;
1202 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1203 xform1
->eM12
* xform2
->eM22
;
1204 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1205 xform1
->eM22
* xform2
->eM21
;
1206 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1207 xform1
->eM22
* xform2
->eM22
;
1208 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1209 xform1
->eDy
* xform2
->eM21
+
1211 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1212 xform1
->eDy
* xform2
->eM22
+
1215 /* Copy the result to xformResult */
1216 *xformResult
= xformTemp
;
1222 /***********************************************************************
1223 * SetDCHook (GDI32.@)
1225 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1227 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1229 DC
*dc
= get_dc_ptr( hdc
);
1231 if (!dc
) return FALSE
;
1233 dc
->dwHookData
= dwHookData
;
1234 dc
->hookProc
= hookProc
;
1235 release_dc_ptr( dc
);
1240 /***********************************************************************
1241 * GetDCHook (GDI32.@)
1243 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1245 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1247 DC
*dc
= get_dc_ptr( hdc
);
1251 if (proc
) *proc
= dc
->hookProc
;
1252 ret
= dc
->dwHookData
;
1253 release_dc_ptr( dc
);
1258 /***********************************************************************
1259 * SetHookFlags (GDI32.@)
1261 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1263 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1265 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1270 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1272 if (flags
& DCHF_INVALIDATEVISRGN
)
1273 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1274 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1275 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1277 if (flags
& DCHF_DISABLEDC
)
1278 ret
= InterlockedExchange( &dc
->disabled
, 1 );
1279 else if (flags
& DCHF_ENABLEDC
)
1280 ret
= InterlockedExchange( &dc
->disabled
, 0 );
1282 GDI_ReleaseObj( hdc
);
1284 if (flags
& DCHF_RESETDC
) ret
= reset_dc_state( hdc
);
1288 /***********************************************************************
1289 * SetICMMode (GDI32.@)
1291 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1293 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1294 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1295 if (iEnableICM
== ICM_ON
) return 0;
1296 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1300 /***********************************************************************
1301 * GetDeviceGammaRamp (GDI32.@)
1303 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1306 DC
*dc
= get_dc_ptr( hDC
);
1308 TRACE("%p, %p\n", hDC
, ptr
);
1311 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1313 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceGammaRamp
);
1314 ret
= physdev
->funcs
->pGetDeviceGammaRamp( physdev
, ptr
);
1316 else SetLastError( ERROR_INVALID_PARAMETER
);
1317 release_dc_ptr( dc
);
1322 static BOOL
check_gamma_ramps(void *ptr
)
1326 while (ramp
< (WORD
*)ptr
+ 3 * 256)
1328 float r_x
, r_y
, r_lx
, r_ly
, r_d
, r_v
, r_e
, g_avg
, g_min
, g_max
;
1329 unsigned i
, f
, l
, g_n
, c
;
1335 TRACE("inverted or flat gamma ramp (%d->%d), rejected\n", f
, l
);
1339 g_min
= g_max
= g_avg
= 0.0;
1341 /* check gamma ramp entries to estimate the gamma */
1342 TRACE("analyzing gamma ramp (%d->%d)\n", f
, l
);
1343 for (i
=1, g_n
=0; i
<255; i
++)
1345 if (ramp
[i
] < f
|| ramp
[i
] > l
)
1347 TRACE("strange gamma ramp ([%d]=%d for %d->%d), rejected\n", i
, ramp
[i
], f
, l
);
1351 if (!c
) continue; /* avoid log(0) */
1353 /* normalize entry values into 0..1 range */
1354 r_x
= i
/255.0; r_y
= c
/ r_d
;
1355 /* compute logarithms of values */
1356 r_lx
= log(r_x
); r_ly
= log(r_y
);
1357 /* compute gamma for this entry */
1359 /* compute differential (error estimate) for this entry */
1360 /* some games use table-based logarithms that magnifies the error by 128 */
1361 r_e
= -r_lx
* 128 / (c
* r_lx
* r_lx
);
1363 /* compute min & max while compensating for estimated error */
1364 if (!g_n
|| g_min
> (r_v
+ r_e
)) g_min
= r_v
+ r_e
;
1365 if (!g_n
|| g_max
< (r_v
- r_e
)) g_max
= r_v
- r_e
;
1367 /* add to average */
1374 TRACE("no gamma data, shouldn't happen\n");
1378 TRACE("low bias is %d, high is %d, gamma is %5.3f\n", f
, 65535-l
, g_avg
);
1380 /* check that the gamma is reasonably uniform across the ramp */
1381 if (g_max
- g_min
> 12.8)
1383 TRACE("ramp not uniform (max=%f, min=%f, avg=%f), rejected\n", g_max
, g_min
, g_avg
);
1387 /* check that the gamma is not too bright */
1390 TRACE("too bright gamma ( %5.3f), rejected\n", g_avg
);
1400 /***********************************************************************
1401 * SetDeviceGammaRamp (GDI32.@)
1403 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1406 DC
*dc
= get_dc_ptr( hDC
);
1408 TRACE("%p, %p\n", hDC
, ptr
);
1411 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1413 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDeviceGammaRamp
);
1415 if (check_gamma_ramps(ptr
))
1416 ret
= physdev
->funcs
->pSetDeviceGammaRamp( physdev
, ptr
);
1418 else SetLastError( ERROR_INVALID_PARAMETER
);
1419 release_dc_ptr( dc
);
1424 /***********************************************************************
1425 * GetColorSpace (GDI32.@)
1427 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1429 /*FIXME Need to do whatever GetColorSpace actually does */
1433 /***********************************************************************
1434 * CreateColorSpaceA (GDI32.@)
1436 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1442 /***********************************************************************
1443 * CreateColorSpaceW (GDI32.@)
1445 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1451 /***********************************************************************
1452 * DeleteColorSpace (GDI32.@)
1454 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1461 /***********************************************************************
1462 * SetColorSpace (GDI32.@)
1464 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1471 /***********************************************************************
1472 * GetBoundsRect (GDI32.@)
1474 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1479 DC
*dc
= get_dc_ptr( hdc
);
1481 if ( !dc
) return 0;
1483 physdev
= GET_DC_PHYSDEV( dc
, pGetBoundsRect
);
1484 ret
= physdev
->funcs
->pGetBoundsRect( physdev
, &device_rect
, DCB_RESET
);
1487 release_dc_ptr( dc
);
1490 if (dc
->bounds_enabled
&& ret
== DCB_SET
) add_bounds_rect( &dc
->bounds
, &device_rect
);
1494 if (is_rect_empty( &dc
->bounds
))
1496 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
1502 rect
->left
= max( rect
->left
, 0 );
1503 rect
->top
= max( rect
->top
, 0 );
1504 rect
->right
= min( rect
->right
, dc
->vis_rect
.right
- dc
->vis_rect
.left
);
1505 rect
->bottom
= min( rect
->bottom
, dc
->vis_rect
.bottom
- dc
->vis_rect
.top
);
1508 dp_to_lp( dc
, (POINT
*)rect
, 2 );
1512 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1513 release_dc_ptr( dc
);
1518 /***********************************************************************
1519 * SetBoundsRect (GDI32.@)
1521 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1527 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1528 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1530 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
1531 ret
= physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, flags
);
1534 release_dc_ptr( dc
);
1538 ret
= (dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
) |
1539 (is_rect_empty( &dc
->bounds
) ? ret
& DCB_SET
: DCB_SET
);
1541 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1543 if ((flags
& DCB_ACCUMULATE
) && rect
)
1547 lp_to_dp( dc
, (POINT
*)&rc
, 2 );
1548 add_bounds_rect( &dc
->bounds
, &rc
);
1551 if (flags
& DCB_ENABLE
) dc
->bounds_enabled
= TRUE
;
1552 if (flags
& DCB_DISABLE
) dc
->bounds_enabled
= FALSE
;
1554 release_dc_ptr( dc
);
1559 /***********************************************************************
1560 * GetRelAbs (GDI32.@)
1562 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1565 DC
*dc
= get_dc_ptr( hdc
);
1568 ret
= dc
->relAbsMode
;
1569 release_dc_ptr( dc
);
1577 /***********************************************************************
1578 * GetBkMode (GDI32.@)
1580 INT WINAPI
GetBkMode( HDC hdc
)
1583 DC
* dc
= get_dc_ptr( hdc
);
1586 ret
= dc
->backgroundMode
;
1587 release_dc_ptr( dc
);
1593 /***********************************************************************
1594 * SetBkMode (GDI32.@)
1596 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1601 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1603 SetLastError(ERROR_INVALID_PARAMETER
);
1606 if ((dc
= get_dc_ptr( hdc
)))
1608 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1609 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1612 ret
= dc
->backgroundMode
;
1613 dc
->backgroundMode
= mode
;
1615 release_dc_ptr( dc
);
1621 /***********************************************************************
1624 INT WINAPI
GetROP2( HDC hdc
)
1627 DC
* dc
= get_dc_ptr( hdc
);
1631 release_dc_ptr( dc
);
1637 /***********************************************************************
1640 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1645 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1647 SetLastError(ERROR_INVALID_PARAMETER
);
1650 if ((dc
= get_dc_ptr( hdc
)))
1652 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1653 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1659 release_dc_ptr( dc
);
1665 /***********************************************************************
1666 * SetRelAbs (GDI32.@)
1668 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1673 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1675 SetLastError(ERROR_INVALID_PARAMETER
);
1678 if ((dc
= get_dc_ptr( hdc
)))
1680 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1681 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1684 ret
= dc
->relAbsMode
;
1685 dc
->relAbsMode
= mode
;
1687 release_dc_ptr( dc
);
1693 /***********************************************************************
1694 * GetPolyFillMode (GDI32.@)
1696 INT WINAPI
GetPolyFillMode( HDC hdc
)
1699 DC
* dc
= get_dc_ptr( hdc
);
1702 ret
= dc
->polyFillMode
;
1703 release_dc_ptr( dc
);
1709 /***********************************************************************
1710 * SetPolyFillMode (GDI32.@)
1712 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1717 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1719 SetLastError(ERROR_INVALID_PARAMETER
);
1722 if ((dc
= get_dc_ptr( hdc
)))
1724 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1725 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1728 ret
= dc
->polyFillMode
;
1729 dc
->polyFillMode
= mode
;
1731 release_dc_ptr( dc
);
1737 /***********************************************************************
1738 * GetStretchBltMode (GDI32.@)
1740 INT WINAPI
GetStretchBltMode( HDC hdc
)
1743 DC
* dc
= get_dc_ptr( hdc
);
1746 ret
= dc
->stretchBltMode
;
1747 release_dc_ptr( dc
);
1753 /***********************************************************************
1754 * SetStretchBltMode (GDI32.@)
1756 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1761 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1763 SetLastError(ERROR_INVALID_PARAMETER
);
1766 if ((dc
= get_dc_ptr( hdc
)))
1768 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1769 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1772 ret
= dc
->stretchBltMode
;
1773 dc
->stretchBltMode
= mode
;
1775 release_dc_ptr( dc
);
1781 /***********************************************************************
1782 * GetMapMode (GDI32.@)
1784 INT WINAPI
GetMapMode( HDC hdc
)
1787 DC
* dc
= get_dc_ptr( hdc
);
1791 release_dc_ptr( dc
);
1797 /***********************************************************************
1798 * GetBrushOrgEx (GDI32.@)
1800 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1802 DC
* dc
= get_dc_ptr( hdc
);
1803 if (!dc
) return FALSE
;
1804 *pt
= dc
->brush_org
;
1805 release_dc_ptr( dc
);
1810 /***********************************************************************
1811 * GetCurrentPositionEx (GDI32.@)
1813 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1815 DC
* dc
= get_dc_ptr( hdc
);
1816 if (!dc
) return FALSE
;
1818 release_dc_ptr( dc
);
1823 /***********************************************************************
1824 * GetViewportExtEx (GDI32.@)
1826 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1828 DC
* dc
= get_dc_ptr( hdc
);
1829 if (!dc
) return FALSE
;
1830 *size
= dc
->vport_ext
;
1831 release_dc_ptr( dc
);
1836 /***********************************************************************
1837 * GetViewportOrgEx (GDI32.@)
1839 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1841 DC
* dc
= get_dc_ptr( hdc
);
1842 if (!dc
) return FALSE
;
1843 *pt
= dc
->vport_org
;
1844 release_dc_ptr( dc
);
1849 /***********************************************************************
1850 * GetWindowExtEx (GDI32.@)
1852 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1854 DC
* dc
= get_dc_ptr( hdc
);
1855 if (!dc
) return FALSE
;
1856 *size
= dc
->wnd_ext
;
1857 release_dc_ptr( dc
);
1862 /***********************************************************************
1863 * GetWindowOrgEx (GDI32.@)
1865 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1867 DC
* dc
= get_dc_ptr( hdc
);
1868 if (!dc
) return FALSE
;
1870 release_dc_ptr( dc
);
1875 /***********************************************************************
1876 * GetLayout (GDI32.@)
1878 * Gets left->right or right->left text layout flags of a dc.
1881 DWORD WINAPI
GetLayout(HDC hdc
)
1883 DWORD layout
= GDI_ERROR
;
1885 DC
* dc
= get_dc_ptr( hdc
);
1888 layout
= dc
->layout
;
1889 release_dc_ptr( dc
);
1892 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1897 /***********************************************************************
1898 * SetLayout (GDI32.@)
1900 * Sets left->right or right->left text layout flags of a dc.
1903 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1905 DWORD oldlayout
= GDI_ERROR
;
1907 DC
* dc
= get_dc_ptr( hdc
);
1910 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetLayout
);
1911 layout
= physdev
->funcs
->pSetLayout( physdev
, layout
);
1912 if (layout
!= GDI_ERROR
)
1914 oldlayout
= dc
->layout
;
1915 dc
->layout
= layout
;
1916 if (layout
!= oldlayout
)
1918 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1919 DC_UpdateXforms( dc
);
1922 release_dc_ptr( dc
);
1925 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1930 /***********************************************************************
1931 * GetDCBrushColor (GDI32.@)
1933 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1936 COLORREF dcBrushColor
= CLR_INVALID
;
1938 TRACE("hdc(%p)\n", hdc
);
1940 dc
= get_dc_ptr( hdc
);
1943 dcBrushColor
= dc
->dcBrushColor
;
1944 release_dc_ptr( dc
);
1947 return dcBrushColor
;
1950 /***********************************************************************
1951 * SetDCBrushColor (GDI32.@)
1953 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1956 COLORREF oldClr
= CLR_INVALID
;
1958 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1960 dc
= get_dc_ptr( hdc
);
1963 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
1964 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
1965 if (crColor
!= CLR_INVALID
)
1967 oldClr
= dc
->dcBrushColor
;
1968 dc
->dcBrushColor
= crColor
;
1970 release_dc_ptr( dc
);
1976 /***********************************************************************
1977 * GetDCPenColor (GDI32.@)
1979 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1982 COLORREF dcPenColor
= CLR_INVALID
;
1984 TRACE("hdc(%p)\n", hdc
);
1986 dc
= get_dc_ptr( hdc
);
1989 dcPenColor
= dc
->dcPenColor
;
1990 release_dc_ptr( dc
);
1996 /***********************************************************************
1997 * SetDCPenColor (GDI32.@)
1999 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2002 COLORREF oldClr
= CLR_INVALID
;
2004 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2006 dc
= get_dc_ptr( hdc
);
2009 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
2010 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
2011 if (crColor
!= CLR_INVALID
)
2013 oldClr
= dc
->dcPenColor
;
2014 dc
->dcPenColor
= crColor
;
2016 release_dc_ptr( dc
);
2022 /***********************************************************************
2023 * CancelDC (GDI32.@)
2025 BOOL WINAPI
CancelDC(HDC hdc
)
2031 /*******************************************************************
2032 * GetMiterLimit [GDI32.@]
2036 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2041 TRACE("(%p,%p)\n", hdc
, peLimit
);
2043 dc
= get_dc_ptr( hdc
);
2047 *peLimit
= dc
->miterLimit
;
2049 release_dc_ptr( dc
);
2055 /*******************************************************************
2056 * SetMiterLimit [GDI32.@]
2060 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2065 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2067 dc
= get_dc_ptr( hdc
);
2071 *peOldLimit
= dc
->miterLimit
;
2072 dc
->miterLimit
= eNewLimit
;
2073 release_dc_ptr( dc
);
2079 /*******************************************************************
2080 * GdiIsMetaPrintDC [GDI32.@]
2082 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2088 /*******************************************************************
2089 * GdiIsMetaFileDC [GDI32.@]
2091 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2095 switch( GetObjectType( hdc
) )
2104 /*******************************************************************
2105 * GdiIsPlayMetafileDC [GDI32.@]
2107 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)