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
;
207 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
209 dc
->thread
= GetCurrentThreadId();
211 else if (dc
->thread
!= GetCurrentThreadId())
213 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
214 GDI_ReleaseObj( hdc
);
217 else InterlockedIncrement( &dc
->refcount
);
219 GDI_ReleaseObj( hdc
);
224 /***********************************************************************
227 void release_dc_ptr( DC
*dc
)
232 ref
= InterlockedDecrement( &dc
->refcount
);
234 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
238 /***********************************************************************
241 * Make sure the DC vis region is up to date.
242 * This function may call up to USER so the GDI lock should _not_
243 * be held when calling it.
245 void update_dc( DC
*dc
)
247 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
248 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
252 /***********************************************************************
255 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
257 return DeleteDC( handle
);
261 /***********************************************************************
264 * Setup device-specific DC values for a newly created DC.
266 void DC_InitDC( DC
* dc
)
268 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRealizeDefaultPalette
);
269 physdev
->funcs
->pRealizeDefaultPalette( physdev
);
270 SetTextColor( dc
->hSelf
, dc
->textColor
);
271 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
272 SelectObject( dc
->hSelf
, dc
->hPen
);
273 SelectObject( dc
->hSelf
, dc
->hBrush
);
274 SelectObject( dc
->hSelf
, dc
->hFont
);
275 update_dc_clipping( dc
);
276 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
277 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
278 physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
);
282 /***********************************************************************
285 * Computes the inverse of the transformation xformSrc and stores it to
286 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
289 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
293 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
294 xformSrc
->eM12
*xformSrc
->eM21
;
295 if (determinant
> -1e-12 && determinant
< 1e-12)
298 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
299 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
300 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
301 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
302 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
303 xformSrc
->eDy
* xformDest
->eM21
;
304 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
305 xformSrc
->eDy
* xformDest
->eM22
;
310 /* Construct a transformation to do the window-to-viewport conversion */
311 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
313 double scaleX
, scaleY
;
314 scaleX
= (double)dc
->vport_ext
.cx
/ (double)dc
->wnd_ext
.cx
;
315 scaleY
= (double)dc
->vport_ext
.cy
/ (double)dc
->wnd_ext
.cy
;
317 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
318 xform
->eM11
= scaleX
;
321 xform
->eM22
= scaleY
;
322 xform
->eDx
= (double)dc
->vport_org
.x
- scaleX
* (double)dc
->wnd_org
.x
;
323 xform
->eDy
= (double)dc
->vport_org
.y
- scaleY
* (double)dc
->wnd_org
.y
;
324 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
327 /***********************************************************************
330 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
331 * fields of the specified DC by creating a transformation that
332 * represents the current mapping mode and combining it with the DC's
333 * world transform. This function should be called whenever the
334 * parameters associated with the mapping mode (window and viewport
335 * extents and origins) or the world transform change.
337 void DC_UpdateXforms( DC
*dc
)
339 XFORM xformWnd2Vport
, oldworld2vport
;
341 construct_window_to_viewport(dc
, &xformWnd2Vport
);
343 oldworld2vport
= dc
->xformWorld2Vport
;
344 /* Combine with the world transformation */
345 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
348 /* Create inverse of world-to-viewport transformation */
349 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
350 &dc
->xformVport2World
);
352 /* Reselect the font and pen back into the dc so that the size
354 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
355 !GdiIsMetaFileDC(dc
->hSelf
))
357 SelectObject(dc
->hSelf
, dc
->hFont
);
358 SelectObject(dc
->hSelf
, dc
->hPen
);
363 /***********************************************************************
366 INT
nulldrv_SaveDC( PHYSDEV dev
)
368 DC
*newdc
, *dc
= get_nulldrv_dc( dev
);
370 if (!(newdc
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*newdc
)))) return 0;
371 newdc
->layout
= dc
->layout
;
372 newdc
->hPen
= dc
->hPen
;
373 newdc
->hBrush
= dc
->hBrush
;
374 newdc
->hFont
= dc
->hFont
;
375 newdc
->hBitmap
= dc
->hBitmap
;
376 newdc
->hPalette
= dc
->hPalette
;
377 newdc
->ROPmode
= dc
->ROPmode
;
378 newdc
->polyFillMode
= dc
->polyFillMode
;
379 newdc
->stretchBltMode
= dc
->stretchBltMode
;
380 newdc
->relAbsMode
= dc
->relAbsMode
;
381 newdc
->backgroundMode
= dc
->backgroundMode
;
382 newdc
->backgroundColor
= dc
->backgroundColor
;
383 newdc
->textColor
= dc
->textColor
;
384 newdc
->dcBrushColor
= dc
->dcBrushColor
;
385 newdc
->dcPenColor
= dc
->dcPenColor
;
386 newdc
->brush_org
= dc
->brush_org
;
387 newdc
->mapperFlags
= dc
->mapperFlags
;
388 newdc
->textAlign
= dc
->textAlign
;
389 newdc
->charExtra
= dc
->charExtra
;
390 newdc
->breakExtra
= dc
->breakExtra
;
391 newdc
->breakRem
= dc
->breakRem
;
392 newdc
->MapMode
= dc
->MapMode
;
393 newdc
->GraphicsMode
= dc
->GraphicsMode
;
394 newdc
->cur_pos
= dc
->cur_pos
;
395 newdc
->ArcDirection
= dc
->ArcDirection
;
396 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
397 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
398 newdc
->xformVport2World
= dc
->xformVport2World
;
399 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
400 newdc
->wnd_org
= dc
->wnd_org
;
401 newdc
->wnd_ext
= dc
->wnd_ext
;
402 newdc
->vport_org
= dc
->vport_org
;
403 newdc
->vport_ext
= dc
->vport_ext
;
404 newdc
->virtual_res
= dc
->virtual_res
;
405 newdc
->virtual_size
= dc
->virtual_size
;
407 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
411 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
412 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
416 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
417 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
420 if (!PATH_SavePath( newdc
, dc
))
422 release_dc_ptr( dc
);
423 free_dc_state( newdc
);
427 newdc
->saved_dc
= dc
->saved_dc
;
428 dc
->saved_dc
= newdc
;
429 return ++dc
->saveLevel
;
433 /***********************************************************************
436 BOOL
nulldrv_RestoreDC( PHYSDEV dev
, INT level
)
438 DC
*dcs
, *first_dcs
, *dc
= get_nulldrv_dc( dev
);
441 /* find the state level to restore */
443 if (abs(level
) > dc
->saveLevel
|| level
== 0) return FALSE
;
444 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
445 first_dcs
= dc
->saved_dc
;
446 for (dcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
449 /* restore the state */
451 if (!PATH_RestorePath( dc
, dcs
)) return FALSE
;
453 dc
->layout
= dcs
->layout
;
454 dc
->ROPmode
= dcs
->ROPmode
;
455 dc
->polyFillMode
= dcs
->polyFillMode
;
456 dc
->stretchBltMode
= dcs
->stretchBltMode
;
457 dc
->relAbsMode
= dcs
->relAbsMode
;
458 dc
->backgroundMode
= dcs
->backgroundMode
;
459 dc
->backgroundColor
= dcs
->backgroundColor
;
460 dc
->textColor
= dcs
->textColor
;
461 dc
->dcBrushColor
= dcs
->dcBrushColor
;
462 dc
->dcPenColor
= dcs
->dcPenColor
;
463 dc
->brush_org
= dcs
->brush_org
;
464 dc
->mapperFlags
= dcs
->mapperFlags
;
465 dc
->textAlign
= dcs
->textAlign
;
466 dc
->charExtra
= dcs
->charExtra
;
467 dc
->breakExtra
= dcs
->breakExtra
;
468 dc
->breakRem
= dcs
->breakRem
;
469 dc
->MapMode
= dcs
->MapMode
;
470 dc
->GraphicsMode
= dcs
->GraphicsMode
;
471 dc
->cur_pos
= dcs
->cur_pos
;
472 dc
->ArcDirection
= dcs
->ArcDirection
;
473 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
474 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
475 dc
->xformVport2World
= dcs
->xformVport2World
;
476 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
477 dc
->wnd_org
= dcs
->wnd_org
;
478 dc
->wnd_ext
= dcs
->wnd_ext
;
479 dc
->vport_org
= dcs
->vport_org
;
480 dc
->vport_ext
= dcs
->vport_ext
;
481 dc
->virtual_res
= dcs
->virtual_res
;
482 dc
->virtual_size
= dcs
->virtual_size
;
486 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
487 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
491 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
496 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
497 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
501 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
504 DC_UpdateXforms( dc
);
505 update_dc_clipping( dc
);
507 SelectObject( dev
->hdc
, dcs
->hBitmap
);
508 SelectObject( dev
->hdc
, dcs
->hBrush
);
509 SelectObject( dev
->hdc
, dcs
->hFont
);
510 SelectObject( dev
->hdc
, dcs
->hPen
);
511 SetBkColor( dev
->hdc
, dcs
->backgroundColor
);
512 SetTextColor( dev
->hdc
, dcs
->textColor
);
513 GDISelectPalette( dev
->hdc
, dcs
->hPalette
, FALSE
);
515 dc
->saved_dc
= dcs
->saved_dc
;
517 dc
->saveLevel
= save_level
- 1;
519 /* now destroy all the saved DCs */
523 DC
*next
= first_dcs
->saved_dc
;
524 free_dc_state( first_dcs
);
531 /***********************************************************************
534 static BOOL
reset_dc_state( HDC hdc
)
538 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
540 set_initial_dc_state( dc
);
541 SetBkColor( hdc
, RGB( 255, 255, 255 ));
542 SetTextColor( hdc
, RGB( 0, 0, 0 ));
543 SelectObject( hdc
, GetStockObject( WHITE_BRUSH
));
544 SelectObject( hdc
, GetStockObject( SYSTEM_FONT
));
545 SelectObject( hdc
, GetStockObject( BLACK_PEN
));
546 SetVirtualResolution( hdc
, 0, 0, 0, 0 );
547 GDISelectPalette( hdc
, GetStockObject( DEFAULT_PALETTE
), FALSE
);
548 SetBoundsRect( hdc
, NULL
, DCB_DISABLE
);
551 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
552 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
555 update_dc_clipping( dc
);
557 for (dcs
= dc
->saved_dc
; dcs
; dcs
= next
)
559 next
= dcs
->saved_dc
;
560 free_dc_state( dcs
);
564 release_dc_ptr( dc
);
569 /***********************************************************************
572 INT WINAPI
SaveDC( HDC hdc
)
577 if ((dc
= get_dc_ptr( hdc
)))
579 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSaveDC
);
580 ret
= physdev
->funcs
->pSaveDC( physdev
);
581 release_dc_ptr( dc
);
587 /***********************************************************************
588 * RestoreDC (GDI32.@)
590 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
594 BOOL success
= FALSE
;
596 TRACE("%p %d\n", hdc
, level
);
597 if ((dc
= get_dc_ptr( hdc
)))
600 physdev
= GET_DC_PHYSDEV( dc
, pRestoreDC
);
601 success
= physdev
->funcs
->pRestoreDC( physdev
, level
);
602 release_dc_ptr( dc
);
608 /***********************************************************************
609 * CreateDCW (GDI32.@)
611 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
612 const DEVMODEW
*initData
)
616 const struct gdi_dc_funcs
*funcs
;
621 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
625 ERR( "no device found for %s\n", debugstr_w(device
) );
628 strcpyW(buf
, driver
);
631 if (!(funcs
= DRIVER_load_driver( buf
)))
633 ERR( "no driver found for %s\n", debugstr_w(buf
) );
636 if (!(dc
= alloc_dc_ptr( OBJ_DC
))) return 0;
639 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
641 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
642 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
644 if (funcs
->pCreateDC
)
646 if (!funcs
->pCreateDC( &dc
->physDev
, buf
, device
, output
, initData
))
648 WARN("creation aborted by device\n" );
654 dc
->vis_rect
.left
= 0;
655 dc
->vis_rect
.top
= 0;
656 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
657 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
660 release_dc_ptr( dc
);
665 /***********************************************************************
666 * CreateDCA (GDI32.@)
668 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
669 const DEVMODEA
*initData
)
671 UNICODE_STRING driverW
, deviceW
, outputW
;
675 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
676 else driverW
.Buffer
= NULL
;
678 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
679 else deviceW
.Buffer
= NULL
;
681 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
682 else outputW
.Buffer
= NULL
;
687 /* don't convert initData for DISPLAY driver, it's not used */
688 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
689 initDataW
= GdiConvertToDevmodeW(initData
);
692 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
694 RtlFreeUnicodeString(&driverW
);
695 RtlFreeUnicodeString(&deviceW
);
696 RtlFreeUnicodeString(&outputW
);
697 HeapFree(GetProcessHeap(), 0, initDataW
);
702 /***********************************************************************
703 * CreateICA (GDI32.@)
705 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
706 const DEVMODEA
* initData
)
708 /* Nothing special yet for ICs */
709 return CreateDCA( driver
, device
, output
, initData
);
713 /***********************************************************************
714 * CreateICW (GDI32.@)
716 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
717 const DEVMODEW
* initData
)
719 /* Nothing special yet for ICs */
720 return CreateDCW( driver
, device
, output
, initData
);
724 /***********************************************************************
725 * CreateCompatibleDC (GDI32.@)
727 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
731 const struct gdi_dc_funcs
*funcs
;
732 PHYSDEV physDev
= NULL
;
738 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
739 physDev
= GET_DC_PHYSDEV( origDC
, pCreateCompatibleDC
);
740 funcs
= physDev
->funcs
;
741 release_dc_ptr( origDC
);
743 else funcs
= DRIVER_load_driver( displayW
);
745 if (!(dc
= alloc_dc_ptr( OBJ_MEMDC
))) return 0;
747 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
749 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
750 dc
->vis_rect
.left
= 0;
751 dc
->vis_rect
.top
= 0;
752 dc
->vis_rect
.right
= 1;
753 dc
->vis_rect
.bottom
= 1;
754 dc
->device_rect
= dc
->vis_rect
;
758 if (funcs
->pCreateCompatibleDC
&& !funcs
->pCreateCompatibleDC( physDev
, &dc
->physDev
))
760 WARN("creation aborted by device\n");
765 if (!dib_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
770 physDev
= GET_DC_PHYSDEV( dc
, pSelectBitmap
);
771 physDev
->funcs
->pSelectBitmap( physDev
, dc
->hBitmap
);
774 release_dc_ptr( dc
);
779 /***********************************************************************
782 BOOL WINAPI
DeleteDC( HDC hdc
)
790 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
791 if (dc
->refcount
!= 1)
793 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
794 release_dc_ptr( dc
);
798 /* Call hook procedure to check whether is it OK to delete this DC */
799 if (dc
->hookProc
&& !dc
->hookProc( dc
->hSelf
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
801 release_dc_ptr( dc
);
804 reset_dc_state( hdc
);
810 /***********************************************************************
813 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
818 if ((dc
= get_dc_ptr( hdc
)))
820 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pResetDC
);
821 ret
= physdev
->funcs
->pResetDC( physdev
, devmode
);
822 if (ret
) /* reset the visible region */
825 dc
->vis_rect
.left
= 0;
826 dc
->vis_rect
.top
= 0;
827 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
828 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
829 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
831 update_dc_clipping( dc
);
833 release_dc_ptr( dc
);
839 /***********************************************************************
842 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
847 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
848 else devmodeW
= NULL
;
850 ret
= ResetDCW(hdc
, devmodeW
);
852 HeapFree(GetProcessHeap(), 0, devmodeW
);
857 /***********************************************************************
858 * GetDeviceCaps (GDI32.@)
860 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
865 if ((dc
= get_dc_ptr( hdc
)))
867 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceCaps
);
868 ret
= physdev
->funcs
->pGetDeviceCaps( physdev
, cap
);
869 release_dc_ptr( dc
);
875 /***********************************************************************
876 * GetBkColor (GDI32.@)
878 COLORREF WINAPI
GetBkColor( HDC hdc
)
881 DC
* dc
= get_dc_ptr( hdc
);
884 ret
= dc
->backgroundColor
;
885 release_dc_ptr( dc
);
891 /***********************************************************************
892 * SetBkColor (GDI32.@)
894 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
896 COLORREF ret
= CLR_INVALID
;
897 DC
* dc
= get_dc_ptr( hdc
);
899 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
903 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkColor
);
904 ret
= dc
->backgroundColor
;
905 dc
->backgroundColor
= physdev
->funcs
->pSetBkColor( physdev
, color
);
906 release_dc_ptr( dc
);
912 /***********************************************************************
913 * GetTextColor (GDI32.@)
915 COLORREF WINAPI
GetTextColor( HDC hdc
)
918 DC
* dc
= get_dc_ptr( hdc
);
922 release_dc_ptr( dc
);
928 /***********************************************************************
929 * SetTextColor (GDI32.@)
931 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
933 COLORREF ret
= CLR_INVALID
;
934 DC
* dc
= get_dc_ptr( hdc
);
936 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
940 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
942 dc
->textColor
= physdev
->funcs
->pSetTextColor( physdev
, color
);
943 release_dc_ptr( dc
);
949 /***********************************************************************
950 * GetTextAlign (GDI32.@)
952 UINT WINAPI
GetTextAlign( HDC hdc
)
955 DC
* dc
= get_dc_ptr( hdc
);
959 release_dc_ptr( dc
);
965 /***********************************************************************
966 * SetTextAlign (GDI32.@)
968 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
970 UINT ret
= GDI_ERROR
;
971 DC
*dc
= get_dc_ptr( hdc
);
973 TRACE("hdc=%p align=%d\n", hdc
, align
);
977 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
978 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
979 if (align
!= GDI_ERROR
)
982 dc
->textAlign
= align
;
984 release_dc_ptr( dc
);
989 /***********************************************************************
990 * GetDCOrgEx (GDI32.@)
992 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
996 if (!lpp
) return FALSE
;
997 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
998 lpp
->x
= dc
->vis_rect
.left
;
999 lpp
->y
= dc
->vis_rect
.top
;
1000 release_dc_ptr( dc
);
1005 /***********************************************************************
1006 * GetGraphicsMode (GDI32.@)
1008 INT WINAPI
GetGraphicsMode( HDC hdc
)
1011 DC
* dc
= get_dc_ptr( hdc
);
1014 ret
= dc
->GraphicsMode
;
1015 release_dc_ptr( dc
);
1021 /***********************************************************************
1022 * SetGraphicsMode (GDI32.@)
1024 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1027 DC
*dc
= get_dc_ptr( hdc
);
1029 /* One would think that setting the graphics mode to GM_COMPATIBLE
1030 * would also reset the world transformation matrix to the unity
1031 * matrix. However, in Windows, this is not the case. This doesn't
1032 * make a lot of sense to me, but that's the way it is.
1035 if ((mode
> 0) && (mode
<= GM_LAST
))
1037 ret
= dc
->GraphicsMode
;
1038 dc
->GraphicsMode
= mode
;
1040 /* font metrics depend on the graphics mode */
1041 if (ret
!= mode
) SelectObject(dc
->hSelf
, dc
->hFont
);
1042 release_dc_ptr( dc
);
1047 /***********************************************************************
1048 * GetArcDirection (GDI32.@)
1050 INT WINAPI
GetArcDirection( HDC hdc
)
1053 DC
* dc
= get_dc_ptr( hdc
);
1056 ret
= dc
->ArcDirection
;
1057 release_dc_ptr( dc
);
1063 /***********************************************************************
1064 * SetArcDirection (GDI32.@)
1066 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1071 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1073 SetLastError(ERROR_INVALID_PARAMETER
);
1077 if ((dc
= get_dc_ptr( hdc
)))
1079 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1080 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1083 ret
= dc
->ArcDirection
;
1084 dc
->ArcDirection
= dir
;
1086 release_dc_ptr( dc
);
1092 /***********************************************************************
1093 * GetWorldTransform (GDI32.@)
1095 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1098 if (!xform
) return FALSE
;
1099 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1100 *xform
= dc
->xformWorld2Wnd
;
1101 release_dc_ptr( dc
);
1106 /***********************************************************************
1107 * GetTransform (GDI32.@)
1111 * Returns one of the co-ordinate space transforms
1114 * hdc [I] Device context.
1115 * which [I] Which xform to return:
1116 * 0x203 World -> Page transform (that set by SetWorldTransform).
1117 * 0x304 Page -> Device transform (the mapping mode transform).
1118 * 0x204 World -> Device transform (the combination of the above two).
1119 * 0x402 Device -> World transform (the inversion of the above).
1120 * xform [O] The xform.
1123 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1126 DC
*dc
= get_dc_ptr( hdc
);
1127 if (!dc
) return FALSE
;
1132 *xform
= dc
->xformWorld2Wnd
;
1136 construct_window_to_viewport(dc
, xform
);
1140 *xform
= dc
->xformWorld2Vport
;
1144 *xform
= dc
->xformVport2World
;
1148 FIXME("Unknown code %x\n", which
);
1152 release_dc_ptr( dc
);
1157 /****************************************************************************
1158 * CombineTransform [GDI32.@]
1159 * Combines two transformation matrices.
1162 * xformResult [O] Stores the result of combining the two matrices
1163 * xform1 [I] Specifies the first matrix to apply
1164 * xform2 [I] Specifies the second matrix to apply
1167 * The same matrix can be passed in for more than one of the parameters.
1171 * Failure: FALSE. Use GetLastError() to determine the cause.
1173 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1174 const XFORM
*xform2
)
1178 /* Check for illegal parameters */
1179 if (!xformResult
|| !xform1
|| !xform2
)
1182 /* Create the result in a temporary XFORM, since xformResult may be
1183 * equal to xform1 or xform2 */
1184 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1185 xform1
->eM12
* xform2
->eM21
;
1186 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1187 xform1
->eM12
* xform2
->eM22
;
1188 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1189 xform1
->eM22
* xform2
->eM21
;
1190 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1191 xform1
->eM22
* xform2
->eM22
;
1192 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1193 xform1
->eDy
* xform2
->eM21
+
1195 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1196 xform1
->eDy
* xform2
->eM22
+
1199 /* Copy the result to xformResult */
1200 *xformResult
= xformTemp
;
1206 /***********************************************************************
1207 * SetDCHook (GDI32.@)
1209 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1211 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1213 DC
*dc
= get_dc_ptr( hdc
);
1215 if (!dc
) return FALSE
;
1217 dc
->dwHookData
= dwHookData
;
1218 dc
->hookProc
= hookProc
;
1219 release_dc_ptr( dc
);
1224 /***********************************************************************
1225 * GetDCHook (GDI32.@)
1227 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1229 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1231 DC
*dc
= get_dc_ptr( hdc
);
1235 if (proc
) *proc
= dc
->hookProc
;
1236 ret
= dc
->dwHookData
;
1237 release_dc_ptr( dc
);
1242 /***********************************************************************
1243 * SetHookFlags (GDI32.@)
1245 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1247 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1249 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1254 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1256 if (flags
& DCHF_INVALIDATEVISRGN
)
1257 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1258 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1259 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1261 GDI_ReleaseObj( hdc
);
1263 if (flags
& DCHF_RESETDC
) ret
= reset_dc_state( hdc
);
1267 /***********************************************************************
1268 * SetICMMode (GDI32.@)
1270 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1272 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1273 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1274 if (iEnableICM
== ICM_ON
) return 0;
1275 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1279 /***********************************************************************
1280 * GetDeviceGammaRamp (GDI32.@)
1282 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1285 DC
*dc
= get_dc_ptr( hDC
);
1287 TRACE("%p, %p\n", hDC
, ptr
);
1290 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1292 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceGammaRamp
);
1293 ret
= physdev
->funcs
->pGetDeviceGammaRamp( physdev
, ptr
);
1295 else SetLastError( ERROR_INVALID_PARAMETER
);
1296 release_dc_ptr( dc
);
1301 static BOOL
check_gamma_ramps(void *ptr
)
1305 while (ramp
< (WORD
*)ptr
+ 3 * 256)
1307 float r_x
, r_y
, r_lx
, r_ly
, r_d
, r_v
, r_e
, g_avg
, g_min
, g_max
;
1308 unsigned i
, f
, l
, g_n
, c
;
1314 TRACE("inverted or flat gamma ramp (%d->%d), rejected\n", f
, l
);
1318 g_min
= g_max
= g_avg
= 0.0;
1320 /* check gamma ramp entries to estimate the gamma */
1321 TRACE("analyzing gamma ramp (%d->%d)\n", f
, l
);
1322 for (i
=1, g_n
=0; i
<255; i
++)
1324 if (ramp
[i
] < f
|| ramp
[i
] > l
)
1326 TRACE("strange gamma ramp ([%d]=%d for %d->%d), rejected\n", i
, ramp
[i
], f
, l
);
1330 if (!c
) continue; /* avoid log(0) */
1332 /* normalize entry values into 0..1 range */
1333 r_x
= i
/255.0; r_y
= c
/ r_d
;
1334 /* compute logarithms of values */
1335 r_lx
= log(r_x
); r_ly
= log(r_y
);
1336 /* compute gamma for this entry */
1338 /* compute differential (error estimate) for this entry */
1339 /* some games use table-based logarithms that magnifies the error by 128 */
1340 r_e
= -r_lx
* 128 / (c
* r_lx
* r_lx
);
1342 /* compute min & max while compensating for estimated error */
1343 if (!g_n
|| g_min
> (r_v
+ r_e
)) g_min
= r_v
+ r_e
;
1344 if (!g_n
|| g_max
< (r_v
- r_e
)) g_max
= r_v
- r_e
;
1346 /* add to average */
1353 TRACE("no gamma data, shouldn't happen\n");
1357 TRACE("low bias is %d, high is %d, gamma is %5.3f\n", f
, 65535-l
, g_avg
);
1359 /* check that the gamma is reasonably uniform across the ramp */
1360 if (g_max
- g_min
> 12.8)
1362 TRACE("ramp not uniform (max=%f, min=%f, avg=%f), rejected\n", g_max
, g_min
, g_avg
);
1366 /* check that the gamma is not too bright */
1369 TRACE("too bright gamma ( %5.3f), rejected\n", g_avg
);
1379 /***********************************************************************
1380 * SetDeviceGammaRamp (GDI32.@)
1382 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1385 DC
*dc
= get_dc_ptr( hDC
);
1387 TRACE("%p, %p\n", hDC
, ptr
);
1390 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1392 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDeviceGammaRamp
);
1394 if (check_gamma_ramps(ptr
))
1395 ret
= physdev
->funcs
->pSetDeviceGammaRamp( physdev
, ptr
);
1397 else SetLastError( ERROR_INVALID_PARAMETER
);
1398 release_dc_ptr( dc
);
1403 /***********************************************************************
1404 * GetColorSpace (GDI32.@)
1406 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1408 /*FIXME Need to do whatever GetColorSpace actually does */
1412 /***********************************************************************
1413 * CreateColorSpaceA (GDI32.@)
1415 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1421 /***********************************************************************
1422 * CreateColorSpaceW (GDI32.@)
1424 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1430 /***********************************************************************
1431 * DeleteColorSpace (GDI32.@)
1433 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1440 /***********************************************************************
1441 * SetColorSpace (GDI32.@)
1443 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1450 /***********************************************************************
1451 * GetBoundsRect (GDI32.@)
1453 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1458 DC
*dc
= get_dc_ptr( hdc
);
1460 if ( !dc
) return 0;
1462 physdev
= GET_DC_PHYSDEV( dc
, pGetBoundsRect
);
1463 ret
= physdev
->funcs
->pGetBoundsRect( physdev
, &device_rect
, DCB_RESET
);
1466 release_dc_ptr( dc
);
1469 if (dc
->bounds_enabled
&& ret
== DCB_SET
) add_bounds_rect( &dc
->bounds
, &device_rect
);
1473 if (is_rect_empty( &dc
->bounds
))
1475 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
1481 rect
->left
= max( rect
->left
, 0 );
1482 rect
->top
= max( rect
->top
, 0 );
1483 rect
->right
= min( rect
->right
, dc
->vis_rect
.right
- dc
->vis_rect
.left
);
1484 rect
->bottom
= min( rect
->bottom
, dc
->vis_rect
.bottom
- dc
->vis_rect
.top
);
1487 dp_to_lp( dc
, (POINT
*)rect
, 2 );
1491 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1492 release_dc_ptr( dc
);
1497 /***********************************************************************
1498 * SetBoundsRect (GDI32.@)
1500 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1506 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1507 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1509 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
1510 ret
= physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, flags
);
1513 release_dc_ptr( dc
);
1517 ret
= (dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
) |
1518 (is_rect_empty( &dc
->bounds
) ? ret
& DCB_SET
: DCB_SET
);
1520 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1522 if ((flags
& DCB_ACCUMULATE
) && rect
)
1526 lp_to_dp( dc
, (POINT
*)&rc
, 2 );
1527 add_bounds_rect( &dc
->bounds
, &rc
);
1530 if (flags
& DCB_ENABLE
) dc
->bounds_enabled
= TRUE
;
1531 if (flags
& DCB_DISABLE
) dc
->bounds_enabled
= FALSE
;
1533 release_dc_ptr( dc
);
1538 /***********************************************************************
1539 * GetRelAbs (GDI32.@)
1541 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1544 DC
*dc
= get_dc_ptr( hdc
);
1547 ret
= dc
->relAbsMode
;
1548 release_dc_ptr( dc
);
1556 /***********************************************************************
1557 * GetBkMode (GDI32.@)
1559 INT WINAPI
GetBkMode( HDC hdc
)
1562 DC
* dc
= get_dc_ptr( hdc
);
1565 ret
= dc
->backgroundMode
;
1566 release_dc_ptr( dc
);
1572 /***********************************************************************
1573 * SetBkMode (GDI32.@)
1575 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1580 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1582 SetLastError(ERROR_INVALID_PARAMETER
);
1585 if ((dc
= get_dc_ptr( hdc
)))
1587 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1588 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1591 ret
= dc
->backgroundMode
;
1592 dc
->backgroundMode
= mode
;
1594 release_dc_ptr( dc
);
1600 /***********************************************************************
1603 INT WINAPI
GetROP2( HDC hdc
)
1606 DC
* dc
= get_dc_ptr( hdc
);
1610 release_dc_ptr( dc
);
1616 /***********************************************************************
1619 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1624 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1626 SetLastError(ERROR_INVALID_PARAMETER
);
1629 if ((dc
= get_dc_ptr( hdc
)))
1631 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1632 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1638 release_dc_ptr( dc
);
1644 /***********************************************************************
1645 * SetRelAbs (GDI32.@)
1647 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1652 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1654 SetLastError(ERROR_INVALID_PARAMETER
);
1657 if ((dc
= get_dc_ptr( hdc
)))
1659 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1660 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1663 ret
= dc
->relAbsMode
;
1664 dc
->relAbsMode
= mode
;
1666 release_dc_ptr( dc
);
1672 /***********************************************************************
1673 * GetPolyFillMode (GDI32.@)
1675 INT WINAPI
GetPolyFillMode( HDC hdc
)
1678 DC
* dc
= get_dc_ptr( hdc
);
1681 ret
= dc
->polyFillMode
;
1682 release_dc_ptr( dc
);
1688 /***********************************************************************
1689 * SetPolyFillMode (GDI32.@)
1691 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1696 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1698 SetLastError(ERROR_INVALID_PARAMETER
);
1701 if ((dc
= get_dc_ptr( hdc
)))
1703 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1704 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1707 ret
= dc
->polyFillMode
;
1708 dc
->polyFillMode
= mode
;
1710 release_dc_ptr( dc
);
1716 /***********************************************************************
1717 * GetStretchBltMode (GDI32.@)
1719 INT WINAPI
GetStretchBltMode( HDC hdc
)
1722 DC
* dc
= get_dc_ptr( hdc
);
1725 ret
= dc
->stretchBltMode
;
1726 release_dc_ptr( dc
);
1732 /***********************************************************************
1733 * SetStretchBltMode (GDI32.@)
1735 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1740 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1742 SetLastError(ERROR_INVALID_PARAMETER
);
1745 if ((dc
= get_dc_ptr( hdc
)))
1747 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1748 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1751 ret
= dc
->stretchBltMode
;
1752 dc
->stretchBltMode
= mode
;
1754 release_dc_ptr( dc
);
1760 /***********************************************************************
1761 * GetMapMode (GDI32.@)
1763 INT WINAPI
GetMapMode( HDC hdc
)
1766 DC
* dc
= get_dc_ptr( hdc
);
1770 release_dc_ptr( dc
);
1776 /***********************************************************************
1777 * GetBrushOrgEx (GDI32.@)
1779 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1781 DC
* dc
= get_dc_ptr( hdc
);
1782 if (!dc
) return FALSE
;
1783 *pt
= dc
->brush_org
;
1784 release_dc_ptr( dc
);
1789 /***********************************************************************
1790 * GetCurrentPositionEx (GDI32.@)
1792 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1794 DC
* dc
= get_dc_ptr( hdc
);
1795 if (!dc
) return FALSE
;
1797 release_dc_ptr( dc
);
1802 /***********************************************************************
1803 * GetViewportExtEx (GDI32.@)
1805 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1807 DC
* dc
= get_dc_ptr( hdc
);
1808 if (!dc
) return FALSE
;
1809 *size
= dc
->vport_ext
;
1810 release_dc_ptr( dc
);
1815 /***********************************************************************
1816 * GetViewportOrgEx (GDI32.@)
1818 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1820 DC
* dc
= get_dc_ptr( hdc
);
1821 if (!dc
) return FALSE
;
1822 *pt
= dc
->vport_org
;
1823 release_dc_ptr( dc
);
1828 /***********************************************************************
1829 * GetWindowExtEx (GDI32.@)
1831 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1833 DC
* dc
= get_dc_ptr( hdc
);
1834 if (!dc
) return FALSE
;
1835 *size
= dc
->wnd_ext
;
1836 release_dc_ptr( dc
);
1841 /***********************************************************************
1842 * GetWindowOrgEx (GDI32.@)
1844 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1846 DC
* dc
= get_dc_ptr( hdc
);
1847 if (!dc
) return FALSE
;
1849 release_dc_ptr( dc
);
1854 /***********************************************************************
1855 * GetLayout (GDI32.@)
1857 * Gets left->right or right->left text layout flags of a dc.
1860 DWORD WINAPI
GetLayout(HDC hdc
)
1862 DWORD layout
= GDI_ERROR
;
1864 DC
* dc
= get_dc_ptr( hdc
);
1867 layout
= dc
->layout
;
1868 release_dc_ptr( dc
);
1871 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1876 /***********************************************************************
1877 * SetLayout (GDI32.@)
1879 * Sets left->right or right->left text layout flags of a dc.
1882 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1884 DWORD oldlayout
= GDI_ERROR
;
1886 DC
* dc
= get_dc_ptr( hdc
);
1889 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetLayout
);
1890 layout
= physdev
->funcs
->pSetLayout( physdev
, layout
);
1891 if (layout
!= GDI_ERROR
)
1893 oldlayout
= dc
->layout
;
1894 dc
->layout
= layout
;
1895 if (layout
!= oldlayout
)
1897 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1898 DC_UpdateXforms( dc
);
1901 release_dc_ptr( dc
);
1904 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1909 /***********************************************************************
1910 * GetDCBrushColor (GDI32.@)
1912 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1915 COLORREF dcBrushColor
= CLR_INVALID
;
1917 TRACE("hdc(%p)\n", hdc
);
1919 dc
= get_dc_ptr( hdc
);
1922 dcBrushColor
= dc
->dcBrushColor
;
1923 release_dc_ptr( dc
);
1926 return dcBrushColor
;
1929 /***********************************************************************
1930 * SetDCBrushColor (GDI32.@)
1932 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1935 COLORREF oldClr
= CLR_INVALID
;
1937 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1939 dc
= get_dc_ptr( hdc
);
1942 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
1943 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
1944 if (crColor
!= CLR_INVALID
)
1946 oldClr
= dc
->dcBrushColor
;
1947 dc
->dcBrushColor
= crColor
;
1949 release_dc_ptr( dc
);
1955 /***********************************************************************
1956 * GetDCPenColor (GDI32.@)
1958 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1961 COLORREF dcPenColor
= CLR_INVALID
;
1963 TRACE("hdc(%p)\n", hdc
);
1965 dc
= get_dc_ptr( hdc
);
1968 dcPenColor
= dc
->dcPenColor
;
1969 release_dc_ptr( dc
);
1975 /***********************************************************************
1976 * SetDCPenColor (GDI32.@)
1978 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1981 COLORREF oldClr
= CLR_INVALID
;
1983 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1985 dc
= get_dc_ptr( hdc
);
1988 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
1989 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
1990 if (crColor
!= CLR_INVALID
)
1992 oldClr
= dc
->dcPenColor
;
1993 dc
->dcPenColor
= crColor
;
1995 release_dc_ptr( dc
);
2001 /***********************************************************************
2002 * CancelDC (GDI32.@)
2004 BOOL WINAPI
CancelDC(HDC hdc
)
2010 /*******************************************************************
2011 * GetMiterLimit [GDI32.@]
2015 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2020 TRACE("(%p,%p)\n", hdc
, peLimit
);
2022 dc
= get_dc_ptr( hdc
);
2026 *peLimit
= dc
->miterLimit
;
2028 release_dc_ptr( dc
);
2034 /*******************************************************************
2035 * SetMiterLimit [GDI32.@]
2039 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2044 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2046 dc
= get_dc_ptr( hdc
);
2050 *peOldLimit
= dc
->miterLimit
;
2051 dc
->miterLimit
= eNewLimit
;
2052 release_dc_ptr( dc
);
2058 /*******************************************************************
2059 * GdiIsMetaPrintDC [GDI32.@]
2061 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2067 /*******************************************************************
2068 * GdiIsMetaFileDC [GDI32.@]
2070 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2074 switch( GetObjectType( hdc
) )
2083 /*******************************************************************
2084 * GdiIsPlayMetafileDC [GDI32.@]
2086 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)