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
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
40 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
42 static BOOL
DC_DeleteObject( HGDIOBJ handle
);
44 static const struct gdi_obj_funcs dc_funcs
=
46 NULL
, /* pSelectObject */
47 NULL
, /* pGetObjectA */
48 NULL
, /* pGetObjectW */
49 NULL
, /* pUnrealizeObject */
50 DC_DeleteObject
/* pDeleteObject */
54 static inline DC
*get_dc_obj( HDC hdc
)
56 DC
*dc
= GDI_GetObjPtr( hdc
, 0 );
59 if ((dc
->header
.type
!= OBJ_DC
) &&
60 (dc
->header
.type
!= OBJ_MEMDC
) &&
61 (dc
->header
.type
!= OBJ_METADC
) &&
62 (dc
->header
.type
!= OBJ_ENHMETADC
))
64 GDI_ReleaseObj( hdc
);
65 SetLastError( ERROR_INVALID_HANDLE
);
72 /***********************************************************************
75 DC
*alloc_dc_ptr( const DC_FUNCTIONS
*funcs
, WORD magic
)
79 if (!(dc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dc
) ))) return NULL
;
83 dc
->thread
= GetCurrentThreadId();
98 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
103 dc
->hMetaClipRgn
= 0;
105 dc
->hPen
= GDI_inc_ref_count( GetStockObject( BLACK_PEN
));
106 dc
->hBrush
= GDI_inc_ref_count( GetStockObject( WHITE_BRUSH
));
107 dc
->hFont
= GDI_inc_ref_count( GetStockObject( SYSTEM_FONT
));
110 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
112 dc
->font_code_page
= CP_ACP
;
113 dc
->ROPmode
= R2_COPYPEN
;
114 dc
->polyFillMode
= ALTERNATE
;
115 dc
->stretchBltMode
= BLACKONWHITE
;
116 dc
->relAbsMode
= ABSOLUTE
;
117 dc
->backgroundMode
= OPAQUE
;
118 dc
->backgroundColor
= RGB( 255, 255, 255 );
119 dc
->dcBrushColor
= RGB( 255, 255, 255 );
120 dc
->dcPenColor
= RGB( 0, 0, 0 );
121 dc
->textColor
= RGB( 0, 0, 0 );
124 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
128 dc
->MapMode
= MM_TEXT
;
129 dc
->GraphicsMode
= GM_COMPATIBLE
;
130 dc
->pAbortProc
= NULL
;
133 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
134 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
135 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
136 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
137 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
138 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
139 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
140 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
141 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
142 dc
->vport2WorldValid
= TRUE
;
143 dc
->BoundsRect
.left
= 0;
144 dc
->BoundsRect
.top
= 0;
145 dc
->BoundsRect
.right
= 0;
146 dc
->BoundsRect
.bottom
= 0;
147 PATH_InitGdiPath(&dc
->path
);
149 if (!(dc
->hSelf
= alloc_gdi_handle( &dc
->header
, magic
, &dc_funcs
)))
151 HeapFree( GetProcessHeap(), 0, dc
);
159 /***********************************************************************
162 BOOL
free_dc_ptr( DC
*dc
)
164 assert( dc
->refcount
== 1 );
165 if (free_gdi_handle( dc
->hSelf
) != dc
) return FALSE
; /* shouldn't happen */
166 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
167 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
168 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
169 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
170 PATH_DestroyGdiPath( &dc
->path
);
171 return HeapFree( GetProcessHeap(), 0, dc
);
175 /***********************************************************************
178 * Retrieve a DC pointer but release the GDI lock.
180 DC
*get_dc_ptr( HDC hdc
)
182 DC
*dc
= get_dc_obj( hdc
);
183 if (!dc
) return NULL
;
185 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
187 dc
->thread
= GetCurrentThreadId();
189 else if (dc
->thread
!= GetCurrentThreadId())
191 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
192 GDI_ReleaseObj( hdc
);
195 else InterlockedIncrement( &dc
->refcount
);
197 GDI_ReleaseObj( hdc
);
202 /***********************************************************************
205 void release_dc_ptr( DC
*dc
)
210 ref
= InterlockedDecrement( &dc
->refcount
);
212 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
216 /***********************************************************************
219 * Make sure the DC vis region is up to date.
220 * This function may call up to USER so the GDI lock should _not_
221 * be held when calling it.
223 void update_dc( DC
*dc
)
225 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
226 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
230 /***********************************************************************
233 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
235 return DeleteDC( handle
);
239 /***********************************************************************
242 * Setup device-specific DC values for a newly created DC.
244 void DC_InitDC( DC
* dc
)
246 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
247 SetTextColor( dc
->hSelf
, dc
->textColor
);
248 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
249 SelectObject( dc
->hSelf
, dc
->hPen
);
250 SelectObject( dc
->hSelf
, dc
->hBrush
);
251 SelectObject( dc
->hSelf
, dc
->hFont
);
252 CLIPPING_UpdateGCRegion( dc
);
253 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
257 /***********************************************************************
260 * Computes the inverse of the transformation xformSrc and stores it to
261 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
264 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
268 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
269 xformSrc
->eM12
*xformSrc
->eM21
;
270 if (determinant
> -1e-12 && determinant
< 1e-12)
273 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
274 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
275 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
276 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
277 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
278 xformSrc
->eDy
* xformDest
->eM21
;
279 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
280 xformSrc
->eDy
* xformDest
->eM22
;
285 /* Construct a transformation to do the window-to-viewport conversion */
286 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
288 double scaleX
, scaleY
;
289 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
290 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
292 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
293 xform
->eM11
= scaleX
;
296 xform
->eM22
= scaleY
;
297 xform
->eDx
= (double)dc
->vportOrgX
- scaleX
* (double)dc
->wndOrgX
;
298 xform
->eDy
= (double)dc
->vportOrgY
- scaleY
* (double)dc
->wndOrgY
;
299 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
302 /***********************************************************************
305 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
306 * fields of the specified DC by creating a transformation that
307 * represents the current mapping mode and combining it with the DC's
308 * world transform. This function should be called whenever the
309 * parameters associated with the mapping mode (window and viewport
310 * extents and origins) or the world transform change.
312 void DC_UpdateXforms( DC
*dc
)
314 XFORM xformWnd2Vport
, oldworld2vport
;
316 construct_window_to_viewport(dc
, &xformWnd2Vport
);
318 oldworld2vport
= dc
->xformWorld2Vport
;
319 /* Combine with the world transformation */
320 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
323 /* Create inverse of world-to-viewport transformation */
324 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
325 &dc
->xformVport2World
);
327 /* Reselect the font and pen back into the dc so that the size
329 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
330 !GdiIsMetaFileDC(dc
->hSelf
))
332 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
333 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
338 /***********************************************************************
341 INT
save_dc_state( HDC hdc
)
346 if (!(dc
= get_dc_ptr( hdc
))) return 0;
347 if (!(newdc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc
))))
349 release_dc_ptr( dc
);
353 newdc
->flags
= dc
->flags
| DC_SAVED
;
354 newdc
->layout
= dc
->layout
;
355 newdc
->hPen
= dc
->hPen
;
356 newdc
->hBrush
= dc
->hBrush
;
357 newdc
->hFont
= dc
->hFont
;
358 newdc
->hBitmap
= dc
->hBitmap
;
359 newdc
->hDevice
= dc
->hDevice
;
360 newdc
->hPalette
= dc
->hPalette
;
361 newdc
->ROPmode
= dc
->ROPmode
;
362 newdc
->polyFillMode
= dc
->polyFillMode
;
363 newdc
->stretchBltMode
= dc
->stretchBltMode
;
364 newdc
->relAbsMode
= dc
->relAbsMode
;
365 newdc
->backgroundMode
= dc
->backgroundMode
;
366 newdc
->backgroundColor
= dc
->backgroundColor
;
367 newdc
->textColor
= dc
->textColor
;
368 newdc
->dcBrushColor
= dc
->dcBrushColor
;
369 newdc
->dcPenColor
= dc
->dcPenColor
;
370 newdc
->brushOrgX
= dc
->brushOrgX
;
371 newdc
->brushOrgY
= dc
->brushOrgY
;
372 newdc
->textAlign
= dc
->textAlign
;
373 newdc
->charExtra
= dc
->charExtra
;
374 newdc
->breakExtra
= dc
->breakExtra
;
375 newdc
->breakRem
= dc
->breakRem
;
376 newdc
->MapMode
= dc
->MapMode
;
377 newdc
->GraphicsMode
= dc
->GraphicsMode
;
378 newdc
->CursPosX
= dc
->CursPosX
;
379 newdc
->CursPosY
= dc
->CursPosY
;
380 newdc
->ArcDirection
= dc
->ArcDirection
;
381 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
382 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
383 newdc
->xformVport2World
= dc
->xformVport2World
;
384 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
385 newdc
->wndOrgX
= dc
->wndOrgX
;
386 newdc
->wndOrgY
= dc
->wndOrgY
;
387 newdc
->wndExtX
= dc
->wndExtX
;
388 newdc
->wndExtY
= dc
->wndExtY
;
389 newdc
->vportOrgX
= dc
->vportOrgX
;
390 newdc
->vportOrgY
= dc
->vportOrgY
;
391 newdc
->vportExtX
= dc
->vportExtX
;
392 newdc
->vportExtY
= dc
->vportExtY
;
393 newdc
->virtual_res
= dc
->virtual_res
;
394 newdc
->virtual_size
= dc
->virtual_size
;
395 newdc
->BoundsRect
= dc
->BoundsRect
;
396 newdc
->gdiFont
= dc
->gdiFont
;
398 newdc
->thread
= GetCurrentThreadId();
400 newdc
->saveLevel
= 0;
403 PATH_InitGdiPath( &newdc
->path
);
405 newdc
->pAbortProc
= NULL
;
406 newdc
->hookProc
= NULL
;
408 if (!(newdc
->hSelf
= alloc_gdi_handle( &newdc
->header
, dc
->header
.type
, &dc_funcs
)))
410 HeapFree( GetProcessHeap(), 0, newdc
);
411 release_dc_ptr( dc
);
415 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
420 newdc
->hMetaClipRgn
= 0;
423 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
424 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
428 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
429 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_ptr( newdc
);
440 newdc
->saved_dc
= dc
->saved_dc
;
441 dc
->saved_dc
= newdc
->hSelf
;
442 ret
= ++dc
->saveLevel
;
443 release_dc_ptr( newdc
);
444 release_dc_ptr( dc
);
449 /***********************************************************************
452 BOOL
restore_dc_state( HDC hdc
, INT level
)
458 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
460 /* find the state level to restore */
462 if (abs(level
) > dc
->saveLevel
|| level
== 0)
464 release_dc_ptr( dc
);
467 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
468 first_dcs
= dc
->saved_dc
;
469 for (hdcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
471 if (!(dcs
= get_dc_ptr( hdcs
)))
473 release_dc_ptr( dc
);
476 hdcs
= dcs
->saved_dc
;
477 release_dc_ptr( dcs
);
480 /* restore the state */
482 if (!(dcs
= get_dc_ptr( hdcs
)))
484 release_dc_ptr( dc
);
487 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
489 release_dc_ptr( dcs
);
490 release_dc_ptr( dc
);
494 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
495 dc
->layout
= dcs
->layout
;
496 dc
->hDevice
= dcs
->hDevice
;
497 dc
->ROPmode
= dcs
->ROPmode
;
498 dc
->polyFillMode
= dcs
->polyFillMode
;
499 dc
->stretchBltMode
= dcs
->stretchBltMode
;
500 dc
->relAbsMode
= dcs
->relAbsMode
;
501 dc
->backgroundMode
= dcs
->backgroundMode
;
502 dc
->backgroundColor
= dcs
->backgroundColor
;
503 dc
->textColor
= dcs
->textColor
;
504 dc
->dcBrushColor
= dcs
->dcBrushColor
;
505 dc
->dcPenColor
= dcs
->dcPenColor
;
506 dc
->brushOrgX
= dcs
->brushOrgX
;
507 dc
->brushOrgY
= dcs
->brushOrgY
;
508 dc
->textAlign
= dcs
->textAlign
;
509 dc
->charExtra
= dcs
->charExtra
;
510 dc
->breakExtra
= dcs
->breakExtra
;
511 dc
->breakRem
= dcs
->breakRem
;
512 dc
->MapMode
= dcs
->MapMode
;
513 dc
->GraphicsMode
= dcs
->GraphicsMode
;
514 dc
->CursPosX
= dcs
->CursPosX
;
515 dc
->CursPosY
= dcs
->CursPosY
;
516 dc
->ArcDirection
= dcs
->ArcDirection
;
517 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
518 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
519 dc
->xformVport2World
= dcs
->xformVport2World
;
520 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
521 dc
->BoundsRect
= dcs
->BoundsRect
;
523 dc
->wndOrgX
= dcs
->wndOrgX
;
524 dc
->wndOrgY
= dcs
->wndOrgY
;
525 dc
->wndExtX
= dcs
->wndExtX
;
526 dc
->wndExtY
= dcs
->wndExtY
;
527 dc
->vportOrgX
= dcs
->vportOrgX
;
528 dc
->vportOrgY
= dcs
->vportOrgY
;
529 dc
->vportExtX
= dcs
->vportExtX
;
530 dc
->vportExtY
= dcs
->vportExtY
;
531 dc
->virtual_res
= dcs
->virtual_res
;
532 dc
->virtual_size
= dcs
->virtual_size
;
536 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
537 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
541 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
546 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
547 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
551 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
554 DC_UpdateXforms( dc
);
555 CLIPPING_UpdateGCRegion( dc
);
557 SelectObject( hdc
, dcs
->hBitmap
);
558 SelectObject( hdc
, dcs
->hBrush
);
559 SelectObject( hdc
, dcs
->hFont
);
560 SelectObject( hdc
, dcs
->hPen
);
561 SetBkColor( hdc
, dcs
->backgroundColor
);
562 SetTextColor( hdc
, dcs
->textColor
);
563 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
565 dc
->saved_dc
= dcs
->saved_dc
;
567 dc
->saveLevel
= save_level
- 1;
569 release_dc_ptr( dcs
);
571 /* now destroy all the saved DCs */
575 if (!(dcs
= get_dc_ptr( first_dcs
))) break;
576 hdcs
= dcs
->saved_dc
;
580 release_dc_ptr( dc
);
585 /***********************************************************************
588 INT WINAPI
SaveDC( HDC hdc
)
593 if (!(dc
= get_dc_ptr( hdc
))) return 0;
595 if(dc
->funcs
->pSaveDC
)
596 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
598 ret
= save_dc_state( hdc
);
600 release_dc_ptr( dc
);
605 /***********************************************************************
606 * RestoreDC (GDI32.@)
608 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
613 TRACE("%p %d\n", hdc
, level
);
614 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
617 if(dc
->funcs
->pRestoreDC
)
618 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
620 success
= restore_dc_state( hdc
, level
);
622 release_dc_ptr( dc
);
627 /***********************************************************************
628 * CreateDCW (GDI32.@)
630 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
631 const DEVMODEW
*initData
)
635 const DC_FUNCTIONS
*funcs
;
640 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
644 ERR( "no device found for %s\n", debugstr_w(device
) );
647 strcpyW(buf
, driver
);
650 if (!(funcs
= DRIVER_load_driver( buf
)))
652 ERR( "no driver found for %s\n", debugstr_w(buf
) );
655 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_DC
))) goto error
;
658 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
659 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
661 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
662 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
664 if (dc
->funcs
->pCreateDC
&&
665 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
667 WARN("creation aborted by device\n" );
671 dc
->vis_rect
.left
= 0;
672 dc
->vis_rect
.top
= 0;
673 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
674 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
675 SetRectRgn(dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
, dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
678 release_dc_ptr( dc
);
682 if (dc
) free_dc_ptr( dc
);
687 /***********************************************************************
688 * CreateDCA (GDI32.@)
690 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
691 const DEVMODEA
*initData
)
693 UNICODE_STRING driverW
, deviceW
, outputW
;
697 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
698 else driverW
.Buffer
= NULL
;
700 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
701 else deviceW
.Buffer
= NULL
;
703 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
704 else outputW
.Buffer
= NULL
;
709 /* don't convert initData for DISPLAY driver, it's not used */
710 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
711 initDataW
= GdiConvertToDevmodeW(initData
);
714 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
716 RtlFreeUnicodeString(&driverW
);
717 RtlFreeUnicodeString(&deviceW
);
718 RtlFreeUnicodeString(&outputW
);
719 HeapFree(GetProcessHeap(), 0, initDataW
);
724 /***********************************************************************
725 * CreateICA (GDI32.@)
727 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
728 const DEVMODEA
* initData
)
730 /* Nothing special yet for ICs */
731 return CreateDCA( driver
, device
, output
, initData
);
735 /***********************************************************************
736 * CreateICW (GDI32.@)
738 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
739 const DEVMODEW
* initData
)
741 /* Nothing special yet for ICs */
742 return CreateDCW( driver
, device
, output
, initData
);
746 /***********************************************************************
747 * CreateCompatibleDC (GDI32.@)
749 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
753 const DC_FUNCTIONS
*funcs
= NULL
;
754 PHYSDEV physDev
= NULL
;
760 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
761 if (GetObjectType( hdc
) == OBJ_DC
)
763 funcs
= origDC
->funcs
;
764 physDev
= origDC
->physDev
;
766 release_dc_ptr( origDC
);
769 if (!funcs
&& !(funcs
= DRIVER_get_display_driver())) return 0;
771 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_MEMDC
))) goto error
;
773 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
775 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
776 dc
->vis_rect
.left
= 0;
777 dc
->vis_rect
.top
= 0;
778 dc
->vis_rect
.right
= 1;
779 dc
->vis_rect
.bottom
= 1;
780 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
782 /* Copy the driver-specific physical device info into
783 * the new DC. The driver may use this read-only info
784 * while creating the compatible DC below. */
785 dc
->physDev
= physDev
;
788 if (dc
->funcs
->pCreateDC
&&
789 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
791 WARN("creation aborted by device\n");
796 release_dc_ptr( dc
);
800 if (dc
) free_dc_ptr( dc
);
805 /***********************************************************************
808 BOOL WINAPI
DeleteDC( HDC hdc
)
816 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
817 if (dc
->refcount
!= 1)
819 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
820 release_dc_ptr( dc
);
824 /* Call hook procedure to check whether is it OK to delete this DC */
825 if (dc
->hookProc
&& !dc
->hookProc( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
827 release_dc_ptr( dc
);
831 while (dc
->saveLevel
)
834 HDC hdcs
= dc
->saved_dc
;
835 if (!(dcs
= get_dc_ptr( hdcs
))) break;
836 dc
->saved_dc
= dcs
->saved_dc
;
841 if (!(dc
->flags
& DC_SAVED
))
843 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
844 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
845 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
846 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
847 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
856 /***********************************************************************
859 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
864 if ((dc
= get_dc_ptr( hdc
)))
866 if (dc
->funcs
->pResetDC
)
868 ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
869 if (ret
) /* reset the visible region */
872 dc
->vis_rect
.left
= 0;
873 dc
->vis_rect
.top
= 0;
874 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
875 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
876 SetRectRgn( dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
,
877 dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
878 CLIPPING_UpdateGCRegion( dc
);
881 release_dc_ptr( dc
);
887 /***********************************************************************
890 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
895 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
896 else devmodeW
= NULL
;
898 ret
= ResetDCW(hdc
, devmodeW
);
900 HeapFree(GetProcessHeap(), 0, devmodeW
);
905 /***********************************************************************
906 * GetDeviceCaps (GDI32.@)
908 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
913 if ((dc
= get_dc_ptr( hdc
)))
915 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
916 else switch(cap
) /* return meaningful values for some entries */
918 case HORZRES
: ret
= 640; break;
919 case VERTRES
: ret
= 480; break;
920 case BITSPIXEL
: ret
= 1; break;
921 case PLANES
: ret
= 1; break;
922 case NUMCOLORS
: ret
= 2; break;
923 case ASPECTX
: ret
= 36; break;
924 case ASPECTY
: ret
= 36; break;
925 case ASPECTXY
: ret
= 51; break;
926 case LOGPIXELSX
: ret
= 72; break;
927 case LOGPIXELSY
: ret
= 72; break;
928 case SIZEPALETTE
: ret
= 2; break;
930 ret
= (TC_OP_CHARACTER
| TC_OP_STROKE
| TC_CP_STROKE
|
931 TC_CR_ANY
| TC_SF_X_YINDEP
| TC_SA_DOUBLE
| TC_SA_INTEGER
|
932 TC_SA_CONTIN
| TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
| TC_VA_ABLE
);
935 release_dc_ptr( dc
);
941 /***********************************************************************
942 * GetBkColor (GDI32.@)
944 COLORREF WINAPI
GetBkColor( HDC hdc
)
947 DC
* dc
= get_dc_ptr( hdc
);
950 ret
= dc
->backgroundColor
;
951 release_dc_ptr( dc
);
957 /***********************************************************************
958 * SetBkColor (GDI32.@)
960 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
963 DC
* dc
= get_dc_ptr( hdc
);
965 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
967 if (!dc
) return CLR_INVALID
;
968 oldColor
= dc
->backgroundColor
;
969 if (dc
->funcs
->pSetBkColor
)
971 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
972 if (color
== CLR_INVALID
) /* don't change it */
975 oldColor
= CLR_INVALID
;
978 dc
->backgroundColor
= color
;
979 release_dc_ptr( dc
);
984 /***********************************************************************
985 * GetTextColor (GDI32.@)
987 COLORREF WINAPI
GetTextColor( HDC hdc
)
990 DC
* dc
= get_dc_ptr( hdc
);
994 release_dc_ptr( dc
);
1000 /***********************************************************************
1001 * SetTextColor (GDI32.@)
1003 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
1006 DC
* dc
= get_dc_ptr( hdc
);
1008 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
1010 if (!dc
) return CLR_INVALID
;
1011 oldColor
= dc
->textColor
;
1012 if (dc
->funcs
->pSetTextColor
)
1014 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
1015 if (color
== CLR_INVALID
) /* don't change it */
1018 oldColor
= CLR_INVALID
;
1021 dc
->textColor
= color
;
1022 release_dc_ptr( dc
);
1027 /***********************************************************************
1028 * GetTextAlign (GDI32.@)
1030 UINT WINAPI
GetTextAlign( HDC hdc
)
1033 DC
* dc
= get_dc_ptr( hdc
);
1036 ret
= dc
->textAlign
;
1037 release_dc_ptr( dc
);
1043 /***********************************************************************
1044 * SetTextAlign (GDI32.@)
1046 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1049 DC
*dc
= get_dc_ptr( hdc
);
1051 TRACE("hdc=%p align=%d\n", hdc
, align
);
1053 if (!dc
) return 0x0;
1054 ret
= dc
->textAlign
;
1055 if (dc
->funcs
->pSetTextAlign
)
1056 if (!dc
->funcs
->pSetTextAlign(dc
->physDev
, align
))
1058 if (ret
!= GDI_ERROR
)
1059 dc
->textAlign
= align
;
1060 release_dc_ptr( dc
);
1064 /***********************************************************************
1065 * GetDCOrgEx (GDI32.@)
1067 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1071 if (!lpp
) return FALSE
;
1072 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1073 lpp
->x
= dc
->vis_rect
.left
;
1074 lpp
->y
= dc
->vis_rect
.top
;
1075 release_dc_ptr( dc
);
1080 /***********************************************************************
1081 * GetGraphicsMode (GDI32.@)
1083 INT WINAPI
GetGraphicsMode( HDC hdc
)
1086 DC
* dc
= get_dc_ptr( hdc
);
1089 ret
= dc
->GraphicsMode
;
1090 release_dc_ptr( dc
);
1096 /***********************************************************************
1097 * SetGraphicsMode (GDI32.@)
1099 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1102 DC
*dc
= get_dc_ptr( hdc
);
1104 /* One would think that setting the graphics mode to GM_COMPATIBLE
1105 * would also reset the world transformation matrix to the unity
1106 * matrix. However, in Windows, this is not the case. This doesn't
1107 * make a lot of sense to me, but that's the way it is.
1110 if ((mode
> 0) && (mode
<= GM_LAST
))
1112 ret
= dc
->GraphicsMode
;
1113 dc
->GraphicsMode
= mode
;
1115 release_dc_ptr( dc
);
1120 /***********************************************************************
1121 * GetArcDirection (GDI32.@)
1123 INT WINAPI
GetArcDirection( HDC hdc
)
1126 DC
* dc
= get_dc_ptr( hdc
);
1129 ret
= dc
->ArcDirection
;
1130 release_dc_ptr( dc
);
1136 /***********************************************************************
1137 * SetArcDirection (GDI32.@)
1139 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1142 INT nOldDirection
= 0;
1144 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1146 SetLastError(ERROR_INVALID_PARAMETER
);
1150 if ((dc
= get_dc_ptr( hdc
)))
1152 if (dc
->funcs
->pSetArcDirection
)
1154 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1156 nOldDirection
= dc
->ArcDirection
;
1157 dc
->ArcDirection
= nDirection
;
1158 release_dc_ptr( dc
);
1160 return nOldDirection
;
1164 /***********************************************************************
1165 * GetWorldTransform (GDI32.@)
1167 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1170 if (!xform
) return FALSE
;
1171 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1172 *xform
= dc
->xformWorld2Wnd
;
1173 release_dc_ptr( dc
);
1178 /***********************************************************************
1179 * GetTransform (GDI32.@)
1183 * Returns one of the co-ordinate space transforms
1186 * hdc [I] Device context.
1187 * which [I] Which xform to return:
1188 * 0x203 World -> Page transform (that set by SetWorldTransform).
1189 * 0x304 Page -> Device transform (the mapping mode transform).
1190 * 0x204 World -> Device transform (the combination of the above two).
1191 * 0x402 Device -> World transform (the inversion of the above).
1192 * xform [O] The xform.
1195 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1198 DC
*dc
= get_dc_ptr( hdc
);
1199 if (!dc
) return FALSE
;
1204 *xform
= dc
->xformWorld2Wnd
;
1208 construct_window_to_viewport(dc
, xform
);
1212 *xform
= dc
->xformWorld2Vport
;
1216 *xform
= dc
->xformVport2World
;
1220 FIXME("Unknown code %x\n", which
);
1224 release_dc_ptr( dc
);
1229 /***********************************************************************
1230 * SetWorldTransform (GDI32.@)
1232 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1237 if (!xform
) return FALSE
;
1239 dc
= get_dc_ptr( hdc
);
1240 if (!dc
) return FALSE
;
1242 /* Check that graphics mode is GM_ADVANCED */
1243 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1245 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1246 xform
->eM11
, xform
->eM12
, xform
->eM21
, xform
->eM22
, xform
->eDx
, xform
->eDy
);
1248 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1249 if (xform
->eM11
* xform
->eM22
== xform
->eM12
* xform
->eM21
) goto done
;
1251 if (dc
->funcs
->pSetWorldTransform
)
1253 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1254 if (!ret
) goto done
;
1257 dc
->xformWorld2Wnd
= *xform
;
1258 DC_UpdateXforms( dc
);
1261 release_dc_ptr( dc
);
1266 /****************************************************************************
1267 * ModifyWorldTransform [GDI32.@]
1268 * Modifies the world transformation for a device context.
1271 * hdc [I] Handle to device context
1272 * xform [I] XFORM structure that will be used to modify the world
1274 * iMode [I] Specifies in what way to modify the world transformation
1277 * Resets the world transformation to the identity matrix.
1278 * The parameter xform is ignored.
1280 * Multiplies xform into the world transformation matrix from
1283 * Multiplies xform into the world transformation matrix from
1288 * Failure: FALSE. Use GetLastError() to determine the cause.
1290 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1294 DC
*dc
= get_dc_ptr( hdc
);
1296 /* Check for illegal parameters */
1297 if (!dc
) return FALSE
;
1298 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1300 /* Check that graphics mode is GM_ADVANCED */
1301 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1303 if (dc
->funcs
->pModifyWorldTransform
)
1305 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1306 if (!ret
) goto done
;
1312 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1313 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1314 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1315 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1316 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1317 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1319 case MWT_LEFTMULTIPLY
:
1320 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1321 &dc
->xformWorld2Wnd
);
1323 case MWT_RIGHTMULTIPLY
:
1324 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1331 DC_UpdateXforms( dc
);
1334 release_dc_ptr( dc
);
1339 /****************************************************************************
1340 * CombineTransform [GDI32.@]
1341 * Combines two transformation matrices.
1344 * xformResult [O] Stores the result of combining the two matrices
1345 * xform1 [I] Specifies the first matrix to apply
1346 * xform2 [I] Specifies the second matrix to apply
1349 * The same matrix can be passed in for more than one of the parameters.
1353 * Failure: FALSE. Use GetLastError() to determine the cause.
1355 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1356 const XFORM
*xform2
)
1360 /* Check for illegal parameters */
1361 if (!xformResult
|| !xform1
|| !xform2
)
1364 /* Create the result in a temporary XFORM, since xformResult may be
1365 * equal to xform1 or xform2 */
1366 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1367 xform1
->eM12
* xform2
->eM21
;
1368 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1369 xform1
->eM12
* xform2
->eM22
;
1370 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1371 xform1
->eM22
* xform2
->eM21
;
1372 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1373 xform1
->eM22
* xform2
->eM22
;
1374 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1375 xform1
->eDy
* xform2
->eM21
+
1377 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1378 xform1
->eDy
* xform2
->eM22
+
1381 /* Copy the result to xformResult */
1382 *xformResult
= xformTemp
;
1388 /***********************************************************************
1389 * SetDCHook (GDI32.@)
1391 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1393 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1395 DC
*dc
= get_dc_ptr( hdc
);
1397 if (!dc
) return FALSE
;
1399 if (!(dc
->flags
& DC_SAVED
))
1401 dc
->dwHookData
= dwHookData
;
1402 dc
->hookProc
= hookProc
;
1404 release_dc_ptr( dc
);
1409 /***********************************************************************
1410 * GetDCHook (GDI32.@)
1412 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1414 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1416 DC
*dc
= get_dc_ptr( hdc
);
1420 if (proc
) *proc
= dc
->hookProc
;
1421 ret
= dc
->dwHookData
;
1422 release_dc_ptr( dc
);
1427 /***********************************************************************
1428 * SetHookFlags (GDI32.@)
1430 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1432 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1434 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1439 /* "Undocumented Windows" info is slightly confusing. */
1441 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1443 if (flags
& DCHF_INVALIDATEVISRGN
)
1444 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1445 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1446 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1448 GDI_ReleaseObj( hdc
);
1452 /***********************************************************************
1453 * SetICMMode (GDI32.@)
1455 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1457 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1458 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1459 if (iEnableICM
== ICM_ON
) return 0;
1460 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1464 /***********************************************************************
1465 * GetDeviceGammaRamp (GDI32.@)
1467 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1470 DC
*dc
= get_dc_ptr( hDC
);
1474 if (dc
->funcs
->pGetDeviceGammaRamp
)
1475 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1476 release_dc_ptr( dc
);
1481 /***********************************************************************
1482 * SetDeviceGammaRamp (GDI32.@)
1484 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1487 DC
*dc
= get_dc_ptr( hDC
);
1491 if (dc
->funcs
->pSetDeviceGammaRamp
)
1492 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1493 release_dc_ptr( dc
);
1498 /***********************************************************************
1499 * GetColorSpace (GDI32.@)
1501 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1503 /*FIXME Need to to whatever GetColorSpace actually does */
1507 /***********************************************************************
1508 * CreateColorSpaceA (GDI32.@)
1510 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1516 /***********************************************************************
1517 * CreateColorSpaceW (GDI32.@)
1519 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1525 /***********************************************************************
1526 * DeleteColorSpace (GDI32.@)
1528 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1535 /***********************************************************************
1536 * SetColorSpace (GDI32.@)
1538 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1545 /***********************************************************************
1546 * GetBoundsRect (GDI32.@)
1548 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1551 DC
*dc
= get_dc_ptr( hdc
);
1553 if ( !dc
) return 0;
1557 *rect
= dc
->BoundsRect
;
1558 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1563 if (flags
& DCB_RESET
)
1565 dc
->BoundsRect
.left
= 0;
1566 dc
->BoundsRect
.top
= 0;
1567 dc
->BoundsRect
.right
= 0;
1568 dc
->BoundsRect
.bottom
= 0;
1569 dc
->flags
&= ~DC_BOUNDS_SET
;
1571 release_dc_ptr( dc
);
1576 /***********************************************************************
1577 * SetBoundsRect (GDI32.@)
1579 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1584 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1585 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1587 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1588 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1590 if (flags
& DCB_RESET
)
1592 dc
->BoundsRect
.left
= 0;
1593 dc
->BoundsRect
.top
= 0;
1594 dc
->BoundsRect
.right
= 0;
1595 dc
->BoundsRect
.bottom
= 0;
1596 dc
->flags
&= ~DC_BOUNDS_SET
;
1599 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1601 if (dc
->flags
& DC_BOUNDS_SET
)
1603 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1604 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1605 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1606 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1610 dc
->BoundsRect
= *rect
;
1611 dc
->flags
|= DC_BOUNDS_SET
;
1615 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1616 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1618 release_dc_ptr( dc
);
1623 /***********************************************************************
1624 * GetRelAbs (GDI32.@)
1626 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1629 DC
*dc
= get_dc_ptr( hdc
);
1632 ret
= dc
->relAbsMode
;
1633 release_dc_ptr( dc
);
1641 /***********************************************************************
1642 * GetBkMode (GDI32.@)
1644 INT WINAPI
GetBkMode( HDC hdc
)
1647 DC
* dc
= get_dc_ptr( hdc
);
1650 ret
= dc
->backgroundMode
;
1651 release_dc_ptr( dc
);
1657 /***********************************************************************
1658 * SetBkMode (GDI32.@)
1660 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1664 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1666 SetLastError(ERROR_INVALID_PARAMETER
);
1669 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1671 ret
= dc
->backgroundMode
;
1672 if (dc
->funcs
->pSetBkMode
)
1673 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1676 dc
->backgroundMode
= mode
;
1677 release_dc_ptr( dc
);
1682 /***********************************************************************
1685 INT WINAPI
GetROP2( HDC hdc
)
1688 DC
* dc
= get_dc_ptr( hdc
);
1692 release_dc_ptr( dc
);
1698 /***********************************************************************
1701 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1705 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1707 SetLastError(ERROR_INVALID_PARAMETER
);
1710 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1712 if (dc
->funcs
->pSetROP2
)
1713 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1717 release_dc_ptr( dc
);
1722 /***********************************************************************
1723 * SetRelAbs (GDI32.@)
1725 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1729 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1731 SetLastError(ERROR_INVALID_PARAMETER
);
1734 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1735 if (dc
->funcs
->pSetRelAbs
)
1736 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1739 ret
= dc
->relAbsMode
;
1740 dc
->relAbsMode
= mode
;
1742 release_dc_ptr( dc
);
1747 /***********************************************************************
1748 * GetPolyFillMode (GDI32.@)
1750 INT WINAPI
GetPolyFillMode( HDC hdc
)
1753 DC
* dc
= get_dc_ptr( hdc
);
1756 ret
= dc
->polyFillMode
;
1757 release_dc_ptr( dc
);
1763 /***********************************************************************
1764 * SetPolyFillMode (GDI32.@)
1766 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1770 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1772 SetLastError(ERROR_INVALID_PARAMETER
);
1775 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1776 ret
= dc
->polyFillMode
;
1777 if (dc
->funcs
->pSetPolyFillMode
)
1778 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1781 dc
->polyFillMode
= mode
;
1782 release_dc_ptr( dc
);
1787 /***********************************************************************
1788 * GetStretchBltMode (GDI32.@)
1790 INT WINAPI
GetStretchBltMode( HDC hdc
)
1793 DC
* dc
= get_dc_ptr( hdc
);
1796 ret
= dc
->stretchBltMode
;
1797 release_dc_ptr( dc
);
1803 /***********************************************************************
1804 * SetStretchBltMode (GDI32.@)
1806 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1810 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1812 SetLastError(ERROR_INVALID_PARAMETER
);
1815 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1816 ret
= dc
->stretchBltMode
;
1817 if (dc
->funcs
->pSetStretchBltMode
)
1818 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1821 dc
->stretchBltMode
= mode
;
1822 release_dc_ptr( dc
);
1827 /***********************************************************************
1828 * GetMapMode (GDI32.@)
1830 INT WINAPI
GetMapMode( HDC hdc
)
1833 DC
* dc
= get_dc_ptr( hdc
);
1837 release_dc_ptr( dc
);
1843 /***********************************************************************
1844 * GetBrushOrgEx (GDI32.@)
1846 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1848 DC
* dc
= get_dc_ptr( hdc
);
1849 if (!dc
) return FALSE
;
1850 pt
->x
= dc
->brushOrgX
;
1851 pt
->y
= dc
->brushOrgY
;
1852 release_dc_ptr( dc
);
1857 /***********************************************************************
1858 * GetCurrentPositionEx (GDI32.@)
1860 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1862 DC
* dc
= get_dc_ptr( hdc
);
1863 if (!dc
) return FALSE
;
1864 pt
->x
= dc
->CursPosX
;
1865 pt
->y
= dc
->CursPosY
;
1866 release_dc_ptr( dc
);
1871 /***********************************************************************
1872 * GetViewportExtEx (GDI32.@)
1874 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1876 DC
* dc
= get_dc_ptr( hdc
);
1877 if (!dc
) return FALSE
;
1878 size
->cx
= dc
->vportExtX
;
1879 size
->cy
= dc
->vportExtY
;
1880 release_dc_ptr( dc
);
1885 /***********************************************************************
1886 * GetViewportOrgEx (GDI32.@)
1888 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1890 DC
* dc
= get_dc_ptr( hdc
);
1891 if (!dc
) return FALSE
;
1892 pt
->x
= dc
->vportOrgX
;
1893 pt
->y
= dc
->vportOrgY
;
1894 release_dc_ptr( dc
);
1899 /***********************************************************************
1900 * GetWindowExtEx (GDI32.@)
1902 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1904 DC
* dc
= get_dc_ptr( hdc
);
1905 if (!dc
) return FALSE
;
1906 size
->cx
= dc
->wndExtX
;
1907 size
->cy
= dc
->wndExtY
;
1908 release_dc_ptr( dc
);
1913 /***********************************************************************
1914 * GetWindowOrgEx (GDI32.@)
1916 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1918 DC
* dc
= get_dc_ptr( hdc
);
1919 if (!dc
) return FALSE
;
1920 pt
->x
= dc
->wndOrgX
;
1921 pt
->y
= dc
->wndOrgY
;
1922 release_dc_ptr( dc
);
1927 /***********************************************************************
1928 * GetLayout (GDI32.@)
1930 * Gets left->right or right->left text layout flags of a dc.
1933 DWORD WINAPI
GetLayout(HDC hdc
)
1935 DWORD layout
= GDI_ERROR
;
1937 DC
* dc
= get_dc_ptr( hdc
);
1940 layout
= dc
->layout
;
1941 release_dc_ptr( dc
);
1944 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1949 /***********************************************************************
1950 * SetLayout (GDI32.@)
1952 * Sets left->right or right->left text layout flags of a dc.
1955 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1957 DWORD oldlayout
= GDI_ERROR
;
1959 DC
* dc
= get_dc_ptr( hdc
);
1962 oldlayout
= dc
->layout
;
1963 dc
->layout
= layout
;
1964 if (layout
!= oldlayout
)
1966 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1967 DC_UpdateXforms( dc
);
1969 release_dc_ptr( dc
);
1972 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1977 /***********************************************************************
1978 * GetDCBrushColor (GDI32.@)
1980 * Retrieves the current brush color for the specified device
1984 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1987 COLORREF dcBrushColor
= CLR_INVALID
;
1989 TRACE("hdc(%p)\n", hdc
);
1991 dc
= get_dc_ptr( hdc
);
1994 dcBrushColor
= dc
->dcBrushColor
;
1995 release_dc_ptr( dc
);
1998 return dcBrushColor
;
2001 /***********************************************************************
2002 * SetDCBrushColor (GDI32.@)
2004 * Sets the current device context (DC) brush color to the specified
2005 * color value. If the device cannot represent the specified color
2006 * value, the color is set to the nearest physical color.
2009 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2012 COLORREF oldClr
= CLR_INVALID
;
2014 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2016 dc
= get_dc_ptr( hdc
);
2019 if (dc
->funcs
->pSetDCBrushColor
)
2020 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2021 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2023 /* If DC_BRUSH is selected, update driver pen color */
2024 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2025 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2026 DeleteObject( hBrush
);
2029 if (crColor
!= CLR_INVALID
)
2031 oldClr
= dc
->dcBrushColor
;
2032 dc
->dcBrushColor
= crColor
;
2035 release_dc_ptr( dc
);
2041 /***********************************************************************
2042 * GetDCPenColor (GDI32.@)
2044 * Retrieves the current pen color for the specified device
2048 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2051 COLORREF dcPenColor
= CLR_INVALID
;
2053 TRACE("hdc(%p)\n", hdc
);
2055 dc
= get_dc_ptr( hdc
);
2058 dcPenColor
= dc
->dcPenColor
;
2059 release_dc_ptr( dc
);
2065 /***********************************************************************
2066 * SetDCPenColor (GDI32.@)
2068 * Sets the current device context (DC) pen color to the specified
2069 * color value. If the device cannot represent the specified color
2070 * value, the color is set to the nearest physical color.
2073 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2076 COLORREF oldClr
= CLR_INVALID
;
2078 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2080 dc
= get_dc_ptr( hdc
);
2083 if (dc
->funcs
->pSetDCPenColor
)
2084 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2085 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2087 /* If DC_PEN is selected, update the driver pen color */
2088 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2089 HPEN hPen
= CreatePenIndirect( &logpen
);
2090 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2091 DeleteObject( hPen
);
2094 if (crColor
!= CLR_INVALID
)
2096 oldClr
= dc
->dcPenColor
;
2097 dc
->dcPenColor
= crColor
;
2100 release_dc_ptr( dc
);
2106 /***********************************************************************
2107 * CancelDC (GDI32.@)
2109 BOOL WINAPI
CancelDC(HDC hdc
)
2115 /*******************************************************************
2116 * GetMiterLimit [GDI32.@]
2120 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2125 TRACE("(%p,%p)\n", hdc
, peLimit
);
2127 dc
= get_dc_ptr( hdc
);
2131 *peLimit
= dc
->miterLimit
;
2133 release_dc_ptr( dc
);
2139 /*******************************************************************
2140 * SetMiterLimit [GDI32.@]
2144 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2149 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2151 dc
= get_dc_ptr( hdc
);
2155 *peOldLimit
= dc
->miterLimit
;
2156 dc
->miterLimit
= eNewLimit
;
2157 release_dc_ptr( dc
);
2163 /*******************************************************************
2164 * GdiIsMetaPrintDC [GDI32.@]
2166 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2172 /*******************************************************************
2173 * GdiIsMetaFileDC [GDI32.@]
2175 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2179 switch( GetObjectType( hdc
) )
2188 /*******************************************************************
2189 * GdiIsPlayMetafileDC [GDI32.@]
2191 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)