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
;
301 /***********************************************************************
304 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
305 * fields of the specified DC by creating a transformation that
306 * represents the current mapping mode and combining it with the DC's
307 * world transform. This function should be called whenever the
308 * parameters associated with the mapping mode (window and viewport
309 * extents and origins) or the world transform change.
311 void DC_UpdateXforms( DC
*dc
)
313 XFORM xformWnd2Vport
, oldworld2vport
;
315 construct_window_to_viewport(dc
, &xformWnd2Vport
);
317 oldworld2vport
= dc
->xformWorld2Vport
;
318 /* Combine with the world transformation */
319 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
322 /* Create inverse of world-to-viewport transformation */
323 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
324 &dc
->xformVport2World
);
326 /* Reselect the font and pen back into the dc so that the size
328 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
329 !GdiIsMetaFileDC(dc
->hSelf
))
331 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
332 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
337 /***********************************************************************
340 INT
save_dc_state( HDC hdc
)
345 if (!(dc
= get_dc_ptr( hdc
))) return 0;
346 if (!(newdc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc
))))
348 release_dc_ptr( dc
);
352 newdc
->flags
= dc
->flags
| DC_SAVED
;
353 newdc
->layout
= dc
->layout
;
354 newdc
->hPen
= dc
->hPen
;
355 newdc
->hBrush
= dc
->hBrush
;
356 newdc
->hFont
= dc
->hFont
;
357 newdc
->hBitmap
= dc
->hBitmap
;
358 newdc
->hDevice
= dc
->hDevice
;
359 newdc
->hPalette
= dc
->hPalette
;
360 newdc
->ROPmode
= dc
->ROPmode
;
361 newdc
->polyFillMode
= dc
->polyFillMode
;
362 newdc
->stretchBltMode
= dc
->stretchBltMode
;
363 newdc
->relAbsMode
= dc
->relAbsMode
;
364 newdc
->backgroundMode
= dc
->backgroundMode
;
365 newdc
->backgroundColor
= dc
->backgroundColor
;
366 newdc
->textColor
= dc
->textColor
;
367 newdc
->dcBrushColor
= dc
->dcBrushColor
;
368 newdc
->dcPenColor
= dc
->dcPenColor
;
369 newdc
->brushOrgX
= dc
->brushOrgX
;
370 newdc
->brushOrgY
= dc
->brushOrgY
;
371 newdc
->textAlign
= dc
->textAlign
;
372 newdc
->charExtra
= dc
->charExtra
;
373 newdc
->breakExtra
= dc
->breakExtra
;
374 newdc
->breakRem
= dc
->breakRem
;
375 newdc
->MapMode
= dc
->MapMode
;
376 newdc
->GraphicsMode
= dc
->GraphicsMode
;
377 newdc
->CursPosX
= dc
->CursPosX
;
378 newdc
->CursPosY
= dc
->CursPosY
;
379 newdc
->ArcDirection
= dc
->ArcDirection
;
380 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
381 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
382 newdc
->xformVport2World
= dc
->xformVport2World
;
383 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
384 newdc
->wndOrgX
= dc
->wndOrgX
;
385 newdc
->wndOrgY
= dc
->wndOrgY
;
386 newdc
->wndExtX
= dc
->wndExtX
;
387 newdc
->wndExtY
= dc
->wndExtY
;
388 newdc
->vportOrgX
= dc
->vportOrgX
;
389 newdc
->vportOrgY
= dc
->vportOrgY
;
390 newdc
->vportExtX
= dc
->vportExtX
;
391 newdc
->vportExtY
= dc
->vportExtY
;
392 newdc
->virtual_res
= dc
->virtual_res
;
393 newdc
->virtual_size
= dc
->virtual_size
;
394 newdc
->BoundsRect
= dc
->BoundsRect
;
395 newdc
->gdiFont
= dc
->gdiFont
;
397 newdc
->thread
= GetCurrentThreadId();
399 newdc
->saveLevel
= 0;
402 PATH_InitGdiPath( &newdc
->path
);
404 newdc
->pAbortProc
= NULL
;
405 newdc
->hookProc
= NULL
;
407 if (!(newdc
->hSelf
= alloc_gdi_handle( &newdc
->header
, dc
->header
.type
, &dc_funcs
)))
409 HeapFree( GetProcessHeap(), 0, newdc
);
410 release_dc_ptr( dc
);
414 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
419 newdc
->hMetaClipRgn
= 0;
422 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
423 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
427 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
430 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
432 if (!PATH_AssignGdiPath( &newdc
->path
, &dc
->path
))
434 release_dc_ptr( dc
);
435 free_dc_ptr( newdc
);
439 newdc
->saved_dc
= dc
->saved_dc
;
440 dc
->saved_dc
= newdc
->hSelf
;
441 ret
= ++dc
->saveLevel
;
442 release_dc_ptr( newdc
);
443 release_dc_ptr( dc
);
448 /***********************************************************************
451 BOOL
restore_dc_state( HDC hdc
, INT level
)
457 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
459 /* find the state level to restore */
461 if (abs(level
) > dc
->saveLevel
|| level
== 0)
463 release_dc_ptr( dc
);
466 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
467 first_dcs
= dc
->saved_dc
;
468 for (hdcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
470 if (!(dcs
= get_dc_ptr( hdcs
)))
472 release_dc_ptr( dc
);
475 hdcs
= dcs
->saved_dc
;
476 release_dc_ptr( dcs
);
479 /* restore the state */
481 if (!(dcs
= get_dc_ptr( hdcs
)))
483 release_dc_ptr( dc
);
486 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
488 release_dc_ptr( dcs
);
489 release_dc_ptr( dc
);
493 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
494 dc
->layout
= dcs
->layout
;
495 dc
->hDevice
= dcs
->hDevice
;
496 dc
->ROPmode
= dcs
->ROPmode
;
497 dc
->polyFillMode
= dcs
->polyFillMode
;
498 dc
->stretchBltMode
= dcs
->stretchBltMode
;
499 dc
->relAbsMode
= dcs
->relAbsMode
;
500 dc
->backgroundMode
= dcs
->backgroundMode
;
501 dc
->backgroundColor
= dcs
->backgroundColor
;
502 dc
->textColor
= dcs
->textColor
;
503 dc
->dcBrushColor
= dcs
->dcBrushColor
;
504 dc
->dcPenColor
= dcs
->dcPenColor
;
505 dc
->brushOrgX
= dcs
->brushOrgX
;
506 dc
->brushOrgY
= dcs
->brushOrgY
;
507 dc
->textAlign
= dcs
->textAlign
;
508 dc
->charExtra
= dcs
->charExtra
;
509 dc
->breakExtra
= dcs
->breakExtra
;
510 dc
->breakRem
= dcs
->breakRem
;
511 dc
->MapMode
= dcs
->MapMode
;
512 dc
->GraphicsMode
= dcs
->GraphicsMode
;
513 dc
->CursPosX
= dcs
->CursPosX
;
514 dc
->CursPosY
= dcs
->CursPosY
;
515 dc
->ArcDirection
= dcs
->ArcDirection
;
516 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
517 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
518 dc
->xformVport2World
= dcs
->xformVport2World
;
519 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
520 dc
->BoundsRect
= dcs
->BoundsRect
;
522 dc
->wndOrgX
= dcs
->wndOrgX
;
523 dc
->wndOrgY
= dcs
->wndOrgY
;
524 dc
->wndExtX
= dcs
->wndExtX
;
525 dc
->wndExtY
= dcs
->wndExtY
;
526 dc
->vportOrgX
= dcs
->vportOrgX
;
527 dc
->vportOrgY
= dcs
->vportOrgY
;
528 dc
->vportExtX
= dcs
->vportExtX
;
529 dc
->vportExtY
= dcs
->vportExtY
;
530 dc
->virtual_res
= dcs
->virtual_res
;
531 dc
->virtual_size
= dcs
->virtual_size
;
535 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
536 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
540 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
545 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
546 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
550 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
553 CLIPPING_UpdateGCRegion( dc
);
555 SelectObject( hdc
, dcs
->hBitmap
);
556 SelectObject( hdc
, dcs
->hBrush
);
557 SelectObject( hdc
, dcs
->hFont
);
558 SelectObject( hdc
, dcs
->hPen
);
559 SetBkColor( hdc
, dcs
->backgroundColor
);
560 SetTextColor( hdc
, dcs
->textColor
);
561 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
563 dc
->saved_dc
= dcs
->saved_dc
;
565 dc
->saveLevel
= save_level
- 1;
567 release_dc_ptr( dcs
);
569 /* now destroy all the saved DCs */
573 if (!(dcs
= get_dc_ptr( first_dcs
))) break;
574 hdcs
= dcs
->saved_dc
;
578 release_dc_ptr( dc
);
583 /***********************************************************************
586 INT WINAPI
SaveDC( HDC hdc
)
591 if (!(dc
= get_dc_ptr( hdc
))) return 0;
593 if(dc
->funcs
->pSaveDC
)
594 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
596 ret
= save_dc_state( hdc
);
598 release_dc_ptr( dc
);
603 /***********************************************************************
604 * RestoreDC (GDI32.@)
606 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
611 TRACE("%p %d\n", hdc
, level
);
612 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
615 if(dc
->funcs
->pRestoreDC
)
616 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
618 success
= restore_dc_state( hdc
, level
);
620 release_dc_ptr( dc
);
625 /***********************************************************************
626 * CreateDCW (GDI32.@)
628 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
629 const DEVMODEW
*initData
)
633 const DC_FUNCTIONS
*funcs
;
638 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
642 ERR( "no device found for %s\n", debugstr_w(device
) );
645 strcpyW(buf
, driver
);
648 if (!(funcs
= DRIVER_load_driver( buf
)))
650 ERR( "no driver found for %s\n", debugstr_w(buf
) );
653 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_DC
))) goto error
;
656 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
657 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
659 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
660 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
662 if (dc
->funcs
->pCreateDC
&&
663 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
665 WARN("creation aborted by device\n" );
669 dc
->vis_rect
.left
= 0;
670 dc
->vis_rect
.top
= 0;
671 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
672 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
673 SetRectRgn(dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
, dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
676 release_dc_ptr( dc
);
680 if (dc
) free_dc_ptr( dc
);
685 /***********************************************************************
686 * CreateDCA (GDI32.@)
688 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
689 const DEVMODEA
*initData
)
691 UNICODE_STRING driverW
, deviceW
, outputW
;
695 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
696 else driverW
.Buffer
= NULL
;
698 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
699 else deviceW
.Buffer
= NULL
;
701 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
702 else outputW
.Buffer
= NULL
;
707 /* don't convert initData for DISPLAY driver, it's not used */
708 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
709 initDataW
= GdiConvertToDevmodeW(initData
);
712 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
714 RtlFreeUnicodeString(&driverW
);
715 RtlFreeUnicodeString(&deviceW
);
716 RtlFreeUnicodeString(&outputW
);
717 HeapFree(GetProcessHeap(), 0, initDataW
);
722 /***********************************************************************
723 * CreateICA (GDI32.@)
725 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
726 const DEVMODEA
* initData
)
728 /* Nothing special yet for ICs */
729 return CreateDCA( driver
, device
, output
, initData
);
733 /***********************************************************************
734 * CreateICW (GDI32.@)
736 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
737 const DEVMODEW
* initData
)
739 /* Nothing special yet for ICs */
740 return CreateDCW( driver
, device
, output
, initData
);
744 /***********************************************************************
745 * CreateCompatibleDC (GDI32.@)
747 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
751 const DC_FUNCTIONS
*funcs
= NULL
;
752 PHYSDEV physDev
= NULL
;
758 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
759 if (GetObjectType( hdc
) == OBJ_DC
)
761 funcs
= origDC
->funcs
;
762 physDev
= origDC
->physDev
;
764 release_dc_ptr( origDC
);
767 if (!funcs
&& !(funcs
= DRIVER_get_display_driver())) return 0;
769 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_MEMDC
))) goto error
;
771 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
773 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
774 dc
->vis_rect
.left
= 0;
775 dc
->vis_rect
.top
= 0;
776 dc
->vis_rect
.right
= 1;
777 dc
->vis_rect
.bottom
= 1;
778 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
780 /* Copy the driver-specific physical device info into
781 * the new DC. The driver may use this read-only info
782 * while creating the compatible DC below. */
783 dc
->physDev
= physDev
;
786 if (dc
->funcs
->pCreateDC
&&
787 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
789 WARN("creation aborted by device\n");
794 release_dc_ptr( dc
);
798 if (dc
) free_dc_ptr( dc
);
803 /***********************************************************************
806 BOOL WINAPI
DeleteDC( HDC hdc
)
814 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
815 if (dc
->refcount
!= 1)
817 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
818 release_dc_ptr( dc
);
822 /* Call hook procedure to check whether is it OK to delete this DC */
823 if (dc
->hookProc
&& !dc
->hookProc( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
825 release_dc_ptr( dc
);
829 while (dc
->saveLevel
)
832 HDC hdcs
= dc
->saved_dc
;
833 if (!(dcs
= get_dc_ptr( hdcs
))) break;
834 dc
->saved_dc
= dcs
->saved_dc
;
839 if (!(dc
->flags
& DC_SAVED
))
841 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
842 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
843 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
844 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
845 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
854 /***********************************************************************
857 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
862 if ((dc
= get_dc_ptr( hdc
)))
864 if (dc
->funcs
->pResetDC
)
866 ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
867 if (ret
) /* reset the visible region */
870 dc
->vis_rect
.left
= 0;
871 dc
->vis_rect
.top
= 0;
872 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
873 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
874 SetRectRgn( dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
,
875 dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
876 CLIPPING_UpdateGCRegion( dc
);
879 release_dc_ptr( dc
);
885 /***********************************************************************
888 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
893 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
894 else devmodeW
= NULL
;
896 ret
= ResetDCW(hdc
, devmodeW
);
898 HeapFree(GetProcessHeap(), 0, devmodeW
);
903 /***********************************************************************
904 * GetDeviceCaps (GDI32.@)
906 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
911 if ((dc
= get_dc_ptr( hdc
)))
913 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
914 else switch(cap
) /* return meaningful values for some entries */
916 case HORZRES
: ret
= 640; break;
917 case VERTRES
: ret
= 480; break;
918 case BITSPIXEL
: ret
= 1; break;
919 case PLANES
: ret
= 1; break;
920 case NUMCOLORS
: ret
= 2; break;
921 case ASPECTX
: ret
= 36; break;
922 case ASPECTY
: ret
= 36; break;
923 case ASPECTXY
: ret
= 51; break;
924 case LOGPIXELSX
: ret
= 72; break;
925 case LOGPIXELSY
: ret
= 72; break;
926 case SIZEPALETTE
: ret
= 2; break;
928 ret
= (TC_OP_CHARACTER
| TC_OP_STROKE
| TC_CP_STROKE
|
929 TC_CR_ANY
| TC_SF_X_YINDEP
| TC_SA_DOUBLE
| TC_SA_INTEGER
|
930 TC_SA_CONTIN
| TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
| TC_VA_ABLE
);
933 release_dc_ptr( dc
);
939 /***********************************************************************
940 * GetBkColor (GDI32.@)
942 COLORREF WINAPI
GetBkColor( HDC hdc
)
945 DC
* dc
= get_dc_ptr( hdc
);
948 ret
= dc
->backgroundColor
;
949 release_dc_ptr( dc
);
955 /***********************************************************************
956 * SetBkColor (GDI32.@)
958 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
961 DC
* dc
= get_dc_ptr( hdc
);
963 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
965 if (!dc
) return CLR_INVALID
;
966 oldColor
= dc
->backgroundColor
;
967 if (dc
->funcs
->pSetBkColor
)
969 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
970 if (color
== CLR_INVALID
) /* don't change it */
973 oldColor
= CLR_INVALID
;
976 dc
->backgroundColor
= color
;
977 release_dc_ptr( dc
);
982 /***********************************************************************
983 * GetTextColor (GDI32.@)
985 COLORREF WINAPI
GetTextColor( HDC hdc
)
988 DC
* dc
= get_dc_ptr( hdc
);
992 release_dc_ptr( dc
);
998 /***********************************************************************
999 * SetTextColor (GDI32.@)
1001 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
1004 DC
* dc
= get_dc_ptr( hdc
);
1006 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
1008 if (!dc
) return CLR_INVALID
;
1009 oldColor
= dc
->textColor
;
1010 if (dc
->funcs
->pSetTextColor
)
1012 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
1013 if (color
== CLR_INVALID
) /* don't change it */
1016 oldColor
= CLR_INVALID
;
1019 dc
->textColor
= color
;
1020 release_dc_ptr( dc
);
1025 /***********************************************************************
1026 * GetTextAlign (GDI32.@)
1028 UINT WINAPI
GetTextAlign( HDC hdc
)
1031 DC
* dc
= get_dc_ptr( hdc
);
1034 ret
= dc
->textAlign
;
1035 release_dc_ptr( dc
);
1041 /***********************************************************************
1042 * SetTextAlign (GDI32.@)
1044 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1047 DC
*dc
= get_dc_ptr( hdc
);
1049 TRACE("hdc=%p align=%d\n", hdc
, align
);
1051 if (!dc
) return 0x0;
1052 ret
= dc
->textAlign
;
1053 if (dc
->funcs
->pSetTextAlign
)
1054 if (!dc
->funcs
->pSetTextAlign(dc
->physDev
, align
))
1056 if (ret
!= GDI_ERROR
)
1057 dc
->textAlign
= align
;
1058 release_dc_ptr( dc
);
1062 /***********************************************************************
1063 * GetDCOrgEx (GDI32.@)
1065 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1069 if (!lpp
) return FALSE
;
1070 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1072 lpp
->x
= lpp
->y
= 0;
1073 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
1074 release_dc_ptr( dc
);
1079 /***********************************************************************
1080 * GetGraphicsMode (GDI32.@)
1082 INT WINAPI
GetGraphicsMode( HDC hdc
)
1085 DC
* dc
= get_dc_ptr( hdc
);
1088 ret
= dc
->GraphicsMode
;
1089 release_dc_ptr( dc
);
1095 /***********************************************************************
1096 * SetGraphicsMode (GDI32.@)
1098 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1101 DC
*dc
= get_dc_ptr( hdc
);
1103 /* One would think that setting the graphics mode to GM_COMPATIBLE
1104 * would also reset the world transformation matrix to the unity
1105 * matrix. However, in Windows, this is not the case. This doesn't
1106 * make a lot of sense to me, but that's the way it is.
1109 if ((mode
> 0) && (mode
<= GM_LAST
))
1111 ret
= dc
->GraphicsMode
;
1112 dc
->GraphicsMode
= mode
;
1114 release_dc_ptr( dc
);
1119 /***********************************************************************
1120 * GetArcDirection (GDI32.@)
1122 INT WINAPI
GetArcDirection( HDC hdc
)
1125 DC
* dc
= get_dc_ptr( hdc
);
1128 ret
= dc
->ArcDirection
;
1129 release_dc_ptr( dc
);
1135 /***********************************************************************
1136 * SetArcDirection (GDI32.@)
1138 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1141 INT nOldDirection
= 0;
1143 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1145 SetLastError(ERROR_INVALID_PARAMETER
);
1149 if ((dc
= get_dc_ptr( hdc
)))
1151 if (dc
->funcs
->pSetArcDirection
)
1153 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1155 nOldDirection
= dc
->ArcDirection
;
1156 dc
->ArcDirection
= nDirection
;
1157 release_dc_ptr( dc
);
1159 return nOldDirection
;
1163 /***********************************************************************
1164 * GetWorldTransform (GDI32.@)
1166 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1169 if (!xform
) return FALSE
;
1170 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1171 *xform
= dc
->xformWorld2Wnd
;
1172 release_dc_ptr( dc
);
1177 /***********************************************************************
1178 * GetTransform (GDI32.@)
1182 * Returns one of the co-ordinate space transforms
1185 * hdc [I] Device context.
1186 * which [I] Which xform to return:
1187 * 0x203 World -> Page transform (that set by SetWorldTransform).
1188 * 0x304 Page -> Device transform (the mapping mode transform).
1189 * 0x204 World -> Device transform (the combination of the above two).
1190 * 0x402 Device -> World transform (the inversion of the above).
1191 * xform [O] The xform.
1194 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1197 DC
*dc
= get_dc_ptr( hdc
);
1198 if (!dc
) return FALSE
;
1203 *xform
= dc
->xformWorld2Wnd
;
1207 construct_window_to_viewport(dc
, xform
);
1211 *xform
= dc
->xformWorld2Vport
;
1215 *xform
= dc
->xformVport2World
;
1219 FIXME("Unknown code %x\n", which
);
1223 release_dc_ptr( dc
);
1228 /***********************************************************************
1229 * SetWorldTransform (GDI32.@)
1231 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1236 if (!xform
) return FALSE
;
1238 dc
= get_dc_ptr( hdc
);
1239 if (!dc
) return FALSE
;
1241 /* Check that graphics mode is GM_ADVANCED */
1242 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1244 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1245 xform
->eM11
, xform
->eM12
, xform
->eM21
, xform
->eM22
, xform
->eDx
, xform
->eDy
);
1247 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1248 if (xform
->eM11
* xform
->eM22
== xform
->eM12
* xform
->eM21
) goto done
;
1250 if (dc
->funcs
->pSetWorldTransform
)
1252 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1253 if (!ret
) goto done
;
1256 dc
->xformWorld2Wnd
= *xform
;
1257 DC_UpdateXforms( dc
);
1260 release_dc_ptr( dc
);
1265 /****************************************************************************
1266 * ModifyWorldTransform [GDI32.@]
1267 * Modifies the world transformation for a device context.
1270 * hdc [I] Handle to device context
1271 * xform [I] XFORM structure that will be used to modify the world
1273 * iMode [I] Specifies in what way to modify the world transformation
1276 * Resets the world transformation to the identity matrix.
1277 * The parameter xform is ignored.
1279 * Multiplies xform into the world transformation matrix from
1282 * Multiplies xform into the world transformation matrix from
1287 * Failure: FALSE. Use GetLastError() to determine the cause.
1289 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1293 DC
*dc
= get_dc_ptr( hdc
);
1295 /* Check for illegal parameters */
1296 if (!dc
) return FALSE
;
1297 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1299 /* Check that graphics mode is GM_ADVANCED */
1300 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1302 if (dc
->funcs
->pModifyWorldTransform
)
1304 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1305 if (!ret
) goto done
;
1311 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1312 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1313 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1314 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1315 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1316 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1318 case MWT_LEFTMULTIPLY
:
1319 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1320 &dc
->xformWorld2Wnd
);
1322 case MWT_RIGHTMULTIPLY
:
1323 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1330 DC_UpdateXforms( dc
);
1333 release_dc_ptr( dc
);
1338 /****************************************************************************
1339 * CombineTransform [GDI32.@]
1340 * Combines two transformation matrices.
1343 * xformResult [O] Stores the result of combining the two matrices
1344 * xform1 [I] Specifies the first matrix to apply
1345 * xform2 [I] Specifies the second matrix to apply
1348 * The same matrix can be passed in for more than one of the parameters.
1352 * Failure: FALSE. Use GetLastError() to determine the cause.
1354 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1355 const XFORM
*xform2
)
1359 /* Check for illegal parameters */
1360 if (!xformResult
|| !xform1
|| !xform2
)
1363 /* Create the result in a temporary XFORM, since xformResult may be
1364 * equal to xform1 or xform2 */
1365 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1366 xform1
->eM12
* xform2
->eM21
;
1367 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1368 xform1
->eM12
* xform2
->eM22
;
1369 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1370 xform1
->eM22
* xform2
->eM21
;
1371 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1372 xform1
->eM22
* xform2
->eM22
;
1373 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1374 xform1
->eDy
* xform2
->eM21
+
1376 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1377 xform1
->eDy
* xform2
->eM22
+
1380 /* Copy the result to xformResult */
1381 *xformResult
= xformTemp
;
1387 /***********************************************************************
1388 * SetDCHook (GDI32.@)
1390 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1392 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1394 DC
*dc
= get_dc_ptr( hdc
);
1396 if (!dc
) return FALSE
;
1398 if (!(dc
->flags
& DC_SAVED
))
1400 dc
->dwHookData
= dwHookData
;
1401 dc
->hookProc
= hookProc
;
1403 release_dc_ptr( dc
);
1408 /***********************************************************************
1409 * GetDCHook (GDI32.@)
1411 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1413 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1415 DC
*dc
= get_dc_ptr( hdc
);
1419 if (proc
) *proc
= dc
->hookProc
;
1420 ret
= dc
->dwHookData
;
1421 release_dc_ptr( dc
);
1426 /***********************************************************************
1427 * SetHookFlags (GDI32.@)
1429 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1431 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1433 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1438 /* "Undocumented Windows" info is slightly confusing. */
1440 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1442 if (flags
& DCHF_INVALIDATEVISRGN
)
1443 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1444 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1445 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1447 GDI_ReleaseObj( dc
);
1451 /***********************************************************************
1452 * SetICMMode (GDI32.@)
1454 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1456 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1457 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1458 if (iEnableICM
== ICM_ON
) return 0;
1459 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1463 /***********************************************************************
1464 * GetDeviceGammaRamp (GDI32.@)
1466 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1469 DC
*dc
= get_dc_ptr( hDC
);
1473 if (dc
->funcs
->pGetDeviceGammaRamp
)
1474 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1475 release_dc_ptr( dc
);
1480 /***********************************************************************
1481 * SetDeviceGammaRamp (GDI32.@)
1483 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1486 DC
*dc
= get_dc_ptr( hDC
);
1490 if (dc
->funcs
->pSetDeviceGammaRamp
)
1491 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1492 release_dc_ptr( dc
);
1497 /***********************************************************************
1498 * GetColorSpace (GDI32.@)
1500 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1502 /*FIXME Need to to whatever GetColorSpace actually does */
1506 /***********************************************************************
1507 * CreateColorSpaceA (GDI32.@)
1509 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1515 /***********************************************************************
1516 * CreateColorSpaceW (GDI32.@)
1518 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1524 /***********************************************************************
1525 * DeleteColorSpace (GDI32.@)
1527 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1534 /***********************************************************************
1535 * SetColorSpace (GDI32.@)
1537 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1544 /***********************************************************************
1545 * GetBoundsRect (GDI32.@)
1547 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1550 DC
*dc
= get_dc_ptr( hdc
);
1552 if ( !dc
) return 0;
1556 *rect
= dc
->BoundsRect
;
1557 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1562 if (flags
& DCB_RESET
)
1564 dc
->BoundsRect
.left
= 0;
1565 dc
->BoundsRect
.top
= 0;
1566 dc
->BoundsRect
.right
= 0;
1567 dc
->BoundsRect
.bottom
= 0;
1568 dc
->flags
&= ~DC_BOUNDS_SET
;
1570 release_dc_ptr( dc
);
1575 /***********************************************************************
1576 * SetBoundsRect (GDI32.@)
1578 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1583 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1584 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1586 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1587 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1589 if (flags
& DCB_RESET
)
1591 dc
->BoundsRect
.left
= 0;
1592 dc
->BoundsRect
.top
= 0;
1593 dc
->BoundsRect
.right
= 0;
1594 dc
->BoundsRect
.bottom
= 0;
1595 dc
->flags
&= ~DC_BOUNDS_SET
;
1598 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1600 if (dc
->flags
& DC_BOUNDS_SET
)
1602 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1603 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1604 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1605 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1609 dc
->BoundsRect
= *rect
;
1610 dc
->flags
|= DC_BOUNDS_SET
;
1614 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1615 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1617 release_dc_ptr( dc
);
1622 /***********************************************************************
1623 * GetRelAbs (GDI32.@)
1625 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1628 DC
*dc
= get_dc_ptr( hdc
);
1631 ret
= dc
->relAbsMode
;
1632 release_dc_ptr( dc
);
1640 /***********************************************************************
1641 * GetBkMode (GDI32.@)
1643 INT WINAPI
GetBkMode( HDC hdc
)
1646 DC
* dc
= get_dc_ptr( hdc
);
1649 ret
= dc
->backgroundMode
;
1650 release_dc_ptr( dc
);
1656 /***********************************************************************
1657 * SetBkMode (GDI32.@)
1659 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1663 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1665 SetLastError(ERROR_INVALID_PARAMETER
);
1668 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1670 ret
= dc
->backgroundMode
;
1671 if (dc
->funcs
->pSetBkMode
)
1672 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1675 dc
->backgroundMode
= mode
;
1676 release_dc_ptr( dc
);
1681 /***********************************************************************
1684 INT WINAPI
GetROP2( HDC hdc
)
1687 DC
* dc
= get_dc_ptr( hdc
);
1691 release_dc_ptr( dc
);
1697 /***********************************************************************
1700 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1704 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1706 SetLastError(ERROR_INVALID_PARAMETER
);
1709 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1711 if (dc
->funcs
->pSetROP2
)
1712 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1716 release_dc_ptr( dc
);
1721 /***********************************************************************
1722 * SetRelAbs (GDI32.@)
1724 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1728 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1730 SetLastError(ERROR_INVALID_PARAMETER
);
1733 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1734 if (dc
->funcs
->pSetRelAbs
)
1735 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1738 ret
= dc
->relAbsMode
;
1739 dc
->relAbsMode
= mode
;
1741 release_dc_ptr( dc
);
1746 /***********************************************************************
1747 * GetPolyFillMode (GDI32.@)
1749 INT WINAPI
GetPolyFillMode( HDC hdc
)
1752 DC
* dc
= get_dc_ptr( hdc
);
1755 ret
= dc
->polyFillMode
;
1756 release_dc_ptr( dc
);
1762 /***********************************************************************
1763 * SetPolyFillMode (GDI32.@)
1765 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1769 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1771 SetLastError(ERROR_INVALID_PARAMETER
);
1774 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1775 ret
= dc
->polyFillMode
;
1776 if (dc
->funcs
->pSetPolyFillMode
)
1777 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1780 dc
->polyFillMode
= mode
;
1781 release_dc_ptr( dc
);
1786 /***********************************************************************
1787 * GetStretchBltMode (GDI32.@)
1789 INT WINAPI
GetStretchBltMode( HDC hdc
)
1792 DC
* dc
= get_dc_ptr( hdc
);
1795 ret
= dc
->stretchBltMode
;
1796 release_dc_ptr( dc
);
1802 /***********************************************************************
1803 * SetStretchBltMode (GDI32.@)
1805 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1809 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1811 SetLastError(ERROR_INVALID_PARAMETER
);
1814 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1815 ret
= dc
->stretchBltMode
;
1816 if (dc
->funcs
->pSetStretchBltMode
)
1817 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1820 dc
->stretchBltMode
= mode
;
1821 release_dc_ptr( dc
);
1826 /***********************************************************************
1827 * GetMapMode (GDI32.@)
1829 INT WINAPI
GetMapMode( HDC hdc
)
1832 DC
* dc
= get_dc_ptr( hdc
);
1836 release_dc_ptr( dc
);
1842 /***********************************************************************
1843 * GetBrushOrgEx (GDI32.@)
1845 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1847 DC
* dc
= get_dc_ptr( hdc
);
1848 if (!dc
) return FALSE
;
1849 pt
->x
= dc
->brushOrgX
;
1850 pt
->y
= dc
->brushOrgY
;
1851 release_dc_ptr( dc
);
1856 /***********************************************************************
1857 * GetCurrentPositionEx (GDI32.@)
1859 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1861 DC
* dc
= get_dc_ptr( hdc
);
1862 if (!dc
) return FALSE
;
1863 pt
->x
= dc
->CursPosX
;
1864 pt
->y
= dc
->CursPosY
;
1865 release_dc_ptr( dc
);
1870 /***********************************************************************
1871 * GetViewportExtEx (GDI32.@)
1873 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1875 DC
* dc
= get_dc_ptr( hdc
);
1876 if (!dc
) return FALSE
;
1877 size
->cx
= dc
->vportExtX
;
1878 size
->cy
= dc
->vportExtY
;
1879 release_dc_ptr( dc
);
1884 /***********************************************************************
1885 * GetViewportOrgEx (GDI32.@)
1887 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1889 DC
* dc
= get_dc_ptr( hdc
);
1890 if (!dc
) return FALSE
;
1891 pt
->x
= dc
->vportOrgX
;
1892 pt
->y
= dc
->vportOrgY
;
1893 release_dc_ptr( dc
);
1898 /***********************************************************************
1899 * GetWindowExtEx (GDI32.@)
1901 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1903 DC
* dc
= get_dc_ptr( hdc
);
1904 if (!dc
) return FALSE
;
1905 size
->cx
= dc
->wndExtX
;
1906 size
->cy
= dc
->wndExtY
;
1907 release_dc_ptr( dc
);
1912 /***********************************************************************
1913 * GetWindowOrgEx (GDI32.@)
1915 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1917 DC
* dc
= get_dc_ptr( hdc
);
1918 if (!dc
) return FALSE
;
1919 pt
->x
= dc
->wndOrgX
;
1920 pt
->y
= dc
->wndOrgY
;
1921 release_dc_ptr( dc
);
1926 /***********************************************************************
1927 * GetLayout (GDI32.@)
1929 * Gets left->right or right->left text layout flags of a dc.
1932 DWORD WINAPI
GetLayout(HDC hdc
)
1934 DWORD layout
= GDI_ERROR
;
1936 DC
* dc
= get_dc_ptr( hdc
);
1939 layout
= dc
->layout
;
1940 release_dc_ptr( dc
);
1943 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1948 /***********************************************************************
1949 * SetLayout (GDI32.@)
1951 * Sets left->right or right->left text layout flags of a dc.
1954 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1956 DWORD oldlayout
= GDI_ERROR
;
1958 DC
* dc
= get_dc_ptr( hdc
);
1961 oldlayout
= dc
->layout
;
1962 dc
->layout
= layout
;
1963 if (layout
!= oldlayout
)
1965 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1966 DC_UpdateXforms( dc
);
1968 release_dc_ptr( dc
);
1971 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1976 /***********************************************************************
1977 * GetDCBrushColor (GDI32.@)
1979 * Retrieves the current brush color for the specified device
1983 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1986 COLORREF dcBrushColor
= CLR_INVALID
;
1988 TRACE("hdc(%p)\n", hdc
);
1990 dc
= get_dc_ptr( hdc
);
1993 dcBrushColor
= dc
->dcBrushColor
;
1994 release_dc_ptr( dc
);
1997 return dcBrushColor
;
2000 /***********************************************************************
2001 * SetDCBrushColor (GDI32.@)
2003 * Sets the current device context (DC) brush color to the specified
2004 * color value. If the device cannot represent the specified color
2005 * value, the color is set to the nearest physical color.
2008 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2011 COLORREF oldClr
= CLR_INVALID
;
2013 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2015 dc
= get_dc_ptr( hdc
);
2018 if (dc
->funcs
->pSetDCBrushColor
)
2019 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2020 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2022 /* If DC_BRUSH is selected, update driver pen color */
2023 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2024 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2025 DeleteObject( hBrush
);
2028 if (crColor
!= CLR_INVALID
)
2030 oldClr
= dc
->dcBrushColor
;
2031 dc
->dcBrushColor
= crColor
;
2034 release_dc_ptr( dc
);
2040 /***********************************************************************
2041 * GetDCPenColor (GDI32.@)
2043 * Retrieves the current pen color for the specified device
2047 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2050 COLORREF dcPenColor
= CLR_INVALID
;
2052 TRACE("hdc(%p)\n", hdc
);
2054 dc
= get_dc_ptr( hdc
);
2057 dcPenColor
= dc
->dcPenColor
;
2058 release_dc_ptr( dc
);
2064 /***********************************************************************
2065 * SetDCPenColor (GDI32.@)
2067 * Sets the current device context (DC) pen color to the specified
2068 * color value. If the device cannot represent the specified color
2069 * value, the color is set to the nearest physical color.
2072 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2075 COLORREF oldClr
= CLR_INVALID
;
2077 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2079 dc
= get_dc_ptr( hdc
);
2082 if (dc
->funcs
->pSetDCPenColor
)
2083 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2084 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2086 /* If DC_PEN is selected, update the driver pen color */
2087 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2088 HPEN hPen
= CreatePenIndirect( &logpen
);
2089 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2090 DeleteObject( hPen
);
2093 if (crColor
!= CLR_INVALID
)
2095 oldClr
= dc
->dcPenColor
;
2096 dc
->dcPenColor
= crColor
;
2099 release_dc_ptr( dc
);
2105 /***********************************************************************
2106 * CancelDC (GDI32.@)
2108 BOOL WINAPI
CancelDC(HDC hdc
)
2114 /*******************************************************************
2115 * GetMiterLimit [GDI32.@]
2119 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2124 TRACE("(%p,%p)\n", hdc
, peLimit
);
2126 dc
= get_dc_ptr( hdc
);
2130 *peLimit
= dc
->miterLimit
;
2132 release_dc_ptr( dc
);
2138 /*******************************************************************
2139 * SetMiterLimit [GDI32.@]
2143 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2148 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2150 dc
= get_dc_ptr( hdc
);
2154 *peOldLimit
= dc
->miterLimit
;
2155 dc
->miterLimit
= eNewLimit
;
2156 release_dc_ptr( dc
);
2162 /*******************************************************************
2163 * GdiIsMetaPrintDC [GDI32.@]
2165 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2171 /*******************************************************************
2172 * GdiIsMetaFileDC [GDI32.@]
2174 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2178 switch( GetObjectType( hdc
) )
2187 /*******************************************************************
2188 * GdiIsPlayMetafileDC [GDI32.@]
2190 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)