2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "gdi_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
39 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
41 static BOOL
DC_DeleteObject( HGDIOBJ handle
);
43 static const struct gdi_obj_funcs dc_funcs
=
45 NULL
, /* pSelectObject */
46 NULL
, /* pGetObjectA */
47 NULL
, /* pGetObjectW */
48 NULL
, /* pUnrealizeObject */
49 DC_DeleteObject
/* pDeleteObject */
53 static inline DC
*get_dc_obj( HDC hdc
)
55 DC
*dc
= GDI_GetObjPtr( hdc
, 0 );
58 if ((dc
->header
.type
!= OBJ_DC
) &&
59 (dc
->header
.type
!= OBJ_MEMDC
) &&
60 (dc
->header
.type
!= OBJ_METADC
) &&
61 (dc
->header
.type
!= OBJ_ENHMETADC
))
63 GDI_ReleaseObj( hdc
);
64 SetLastError( ERROR_INVALID_HANDLE
);
71 /***********************************************************************
74 DC
*alloc_dc_ptr( const DC_FUNCTIONS
*funcs
, WORD magic
)
78 if (!(dc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dc
) ))) return NULL
;
81 dc
->nulldrv
.funcs
= &null_driver
;
82 dc
->nulldrv
.next
= NULL
;
83 dc
->physDev
= &dc
->nulldrv
;
84 dc
->thread
= GetCurrentThreadId();
99 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
104 dc
->hMetaClipRgn
= 0;
106 dc
->hPen
= GDI_inc_ref_count( GetStockObject( BLACK_PEN
));
107 dc
->hBrush
= GDI_inc_ref_count( GetStockObject( WHITE_BRUSH
));
108 dc
->hFont
= GDI_inc_ref_count( GetStockObject( SYSTEM_FONT
));
111 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
113 dc
->font_code_page
= CP_ACP
;
114 dc
->ROPmode
= R2_COPYPEN
;
115 dc
->polyFillMode
= ALTERNATE
;
116 dc
->stretchBltMode
= BLACKONWHITE
;
117 dc
->relAbsMode
= ABSOLUTE
;
118 dc
->backgroundMode
= OPAQUE
;
119 dc
->backgroundColor
= RGB( 255, 255, 255 );
120 dc
->dcBrushColor
= RGB( 255, 255, 255 );
121 dc
->dcPenColor
= RGB( 0, 0, 0 );
122 dc
->textColor
= RGB( 0, 0, 0 );
126 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
130 dc
->MapMode
= MM_TEXT
;
131 dc
->GraphicsMode
= GM_COMPATIBLE
;
132 dc
->pAbortProc
= NULL
;
135 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
136 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
137 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
138 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
139 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
140 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
141 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
142 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
143 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
144 dc
->vport2WorldValid
= TRUE
;
145 dc
->BoundsRect
.left
= 0;
146 dc
->BoundsRect
.top
= 0;
147 dc
->BoundsRect
.right
= 0;
148 dc
->BoundsRect
.bottom
= 0;
149 PATH_InitGdiPath(&dc
->path
);
151 if (!(dc
->hSelf
= alloc_gdi_handle( &dc
->header
, magic
, &dc_funcs
)))
153 HeapFree( GetProcessHeap(), 0, dc
);
156 dc
->nulldrv
.hdc
= dc
->hSelf
;
162 /***********************************************************************
165 BOOL
free_dc_ptr( DC
*dc
)
167 assert( dc
->refcount
== 1 );
168 if (free_gdi_handle( dc
->hSelf
) != dc
) return FALSE
; /* shouldn't happen */
169 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
170 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
171 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
172 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
173 PATH_DestroyGdiPath( &dc
->path
);
174 return HeapFree( GetProcessHeap(), 0, dc
);
178 /***********************************************************************
181 * Retrieve a DC pointer but release the GDI lock.
183 DC
*get_dc_ptr( HDC hdc
)
185 DC
*dc
= get_dc_obj( hdc
);
186 if (!dc
) return NULL
;
188 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
190 dc
->thread
= GetCurrentThreadId();
192 else if (dc
->thread
!= GetCurrentThreadId())
194 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
195 GDI_ReleaseObj( hdc
);
198 else InterlockedIncrement( &dc
->refcount
);
200 GDI_ReleaseObj( hdc
);
205 /***********************************************************************
208 void release_dc_ptr( DC
*dc
)
213 ref
= InterlockedDecrement( &dc
->refcount
);
215 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
219 /***********************************************************************
222 * Make sure the DC vis region is up to date.
223 * This function may call up to USER so the GDI lock should _not_
224 * be held when calling it.
226 void update_dc( DC
*dc
)
228 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
229 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
233 /***********************************************************************
236 * Push a driver on top of the DC driver stack.
238 void push_dc_driver( DC
* dc
, PHYSDEV physdev
)
240 physdev
->next
= dc
->physDev
;
241 physdev
->hdc
= dc
->hSelf
;
242 dc
->physDev
= physdev
;
243 dc
->funcs
= physdev
->funcs
;
247 /***********************************************************************
250 * Pop the top driver from the DC driver stack.
252 void pop_dc_driver( DC
* dc
, PHYSDEV physdev
)
254 assert( physdev
== dc
->physDev
);
255 assert( physdev
!= &dc
->nulldrv
);
256 dc
->physDev
= physdev
->next
;
257 dc
->funcs
= dc
->physDev
->funcs
;
261 /***********************************************************************
264 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
266 return DeleteDC( handle
);
270 /***********************************************************************
273 * Setup device-specific DC values for a newly created DC.
275 void DC_InitDC( DC
* dc
)
277 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
278 SetTextColor( dc
->hSelf
, dc
->textColor
);
279 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
280 SelectObject( dc
->hSelf
, dc
->hPen
);
281 SelectObject( dc
->hSelf
, dc
->hBrush
);
282 SelectObject( dc
->hSelf
, dc
->hFont
);
283 CLIPPING_UpdateGCRegion( dc
);
284 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
288 /***********************************************************************
291 * Computes the inverse of the transformation xformSrc and stores it to
292 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
295 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
299 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
300 xformSrc
->eM12
*xformSrc
->eM21
;
301 if (determinant
> -1e-12 && determinant
< 1e-12)
304 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
305 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
306 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
307 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
308 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
309 xformSrc
->eDy
* xformDest
->eM21
;
310 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
311 xformSrc
->eDy
* xformDest
->eM22
;
316 /* Construct a transformation to do the window-to-viewport conversion */
317 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
319 double scaleX
, scaleY
;
320 scaleX
= (double)dc
->vportExtX
/ (double)dc
->wndExtX
;
321 scaleY
= (double)dc
->vportExtY
/ (double)dc
->wndExtY
;
323 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
324 xform
->eM11
= scaleX
;
327 xform
->eM22
= scaleY
;
328 xform
->eDx
= (double)dc
->vportOrgX
- scaleX
* (double)dc
->wndOrgX
;
329 xform
->eDy
= (double)dc
->vportOrgY
- scaleY
* (double)dc
->wndOrgY
;
330 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
333 /***********************************************************************
336 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
337 * fields of the specified DC by creating a transformation that
338 * represents the current mapping mode and combining it with the DC's
339 * world transform. This function should be called whenever the
340 * parameters associated with the mapping mode (window and viewport
341 * extents and origins) or the world transform change.
343 void DC_UpdateXforms( DC
*dc
)
345 XFORM xformWnd2Vport
, oldworld2vport
;
347 construct_window_to_viewport(dc
, &xformWnd2Vport
);
349 oldworld2vport
= dc
->xformWorld2Vport
;
350 /* Combine with the world transformation */
351 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
354 /* Create inverse of world-to-viewport transformation */
355 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
356 &dc
->xformVport2World
);
358 /* Reselect the font and pen back into the dc so that the size
360 if (memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)) &&
361 !GdiIsMetaFileDC(dc
->hSelf
))
363 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
364 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
369 /***********************************************************************
372 INT
save_dc_state( HDC hdc
)
377 if (!(dc
= get_dc_ptr( hdc
))) return 0;
378 if (!(newdc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc
))))
380 release_dc_ptr( dc
);
384 newdc
->flags
= dc
->flags
| DC_SAVED
;
385 newdc
->layout
= dc
->layout
;
386 newdc
->hPen
= dc
->hPen
;
387 newdc
->hBrush
= dc
->hBrush
;
388 newdc
->hFont
= dc
->hFont
;
389 newdc
->hBitmap
= dc
->hBitmap
;
390 newdc
->hDevice
= dc
->hDevice
;
391 newdc
->hPalette
= dc
->hPalette
;
392 newdc
->ROPmode
= dc
->ROPmode
;
393 newdc
->polyFillMode
= dc
->polyFillMode
;
394 newdc
->stretchBltMode
= dc
->stretchBltMode
;
395 newdc
->relAbsMode
= dc
->relAbsMode
;
396 newdc
->backgroundMode
= dc
->backgroundMode
;
397 newdc
->backgroundColor
= dc
->backgroundColor
;
398 newdc
->textColor
= dc
->textColor
;
399 newdc
->dcBrushColor
= dc
->dcBrushColor
;
400 newdc
->dcPenColor
= dc
->dcPenColor
;
401 newdc
->brushOrgX
= dc
->brushOrgX
;
402 newdc
->brushOrgY
= dc
->brushOrgY
;
403 newdc
->mapperFlags
= dc
->mapperFlags
;
404 newdc
->textAlign
= dc
->textAlign
;
405 newdc
->charExtra
= dc
->charExtra
;
406 newdc
->breakExtra
= dc
->breakExtra
;
407 newdc
->breakRem
= dc
->breakRem
;
408 newdc
->MapMode
= dc
->MapMode
;
409 newdc
->GraphicsMode
= dc
->GraphicsMode
;
410 newdc
->CursPosX
= dc
->CursPosX
;
411 newdc
->CursPosY
= dc
->CursPosY
;
412 newdc
->ArcDirection
= dc
->ArcDirection
;
413 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
414 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
415 newdc
->xformVport2World
= dc
->xformVport2World
;
416 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
417 newdc
->wndOrgX
= dc
->wndOrgX
;
418 newdc
->wndOrgY
= dc
->wndOrgY
;
419 newdc
->wndExtX
= dc
->wndExtX
;
420 newdc
->wndExtY
= dc
->wndExtY
;
421 newdc
->vportOrgX
= dc
->vportOrgX
;
422 newdc
->vportOrgY
= dc
->vportOrgY
;
423 newdc
->vportExtX
= dc
->vportExtX
;
424 newdc
->vportExtY
= dc
->vportExtY
;
425 newdc
->virtual_res
= dc
->virtual_res
;
426 newdc
->virtual_size
= dc
->virtual_size
;
427 newdc
->BoundsRect
= dc
->BoundsRect
;
428 newdc
->gdiFont
= dc
->gdiFont
;
430 newdc
->thread
= GetCurrentThreadId();
432 newdc
->saveLevel
= 0;
435 PATH_InitGdiPath( &newdc
->path
);
437 newdc
->pAbortProc
= NULL
;
438 newdc
->hookProc
= NULL
;
440 if (!(newdc
->hSelf
= alloc_gdi_handle( &newdc
->header
, dc
->header
.type
, &dc_funcs
)))
442 HeapFree( GetProcessHeap(), 0, newdc
);
443 release_dc_ptr( dc
);
447 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
452 newdc
->hMetaClipRgn
= 0;
455 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
456 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
460 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
461 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
463 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
465 if (!PATH_AssignGdiPath( &newdc
->path
, &dc
->path
))
467 release_dc_ptr( dc
);
468 free_dc_ptr( newdc
);
472 newdc
->saved_dc
= dc
->saved_dc
;
473 dc
->saved_dc
= newdc
->hSelf
;
474 ret
= ++dc
->saveLevel
;
475 release_dc_ptr( newdc
);
476 release_dc_ptr( dc
);
481 /***********************************************************************
484 BOOL
restore_dc_state( HDC hdc
, INT level
)
490 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
492 /* find the state level to restore */
494 if (abs(level
) > dc
->saveLevel
|| level
== 0)
496 release_dc_ptr( dc
);
499 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
500 first_dcs
= dc
->saved_dc
;
501 for (hdcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
503 if (!(dcs
= get_dc_ptr( hdcs
)))
505 release_dc_ptr( dc
);
508 hdcs
= dcs
->saved_dc
;
509 release_dc_ptr( dcs
);
512 /* restore the state */
514 if (!(dcs
= get_dc_ptr( hdcs
)))
516 release_dc_ptr( dc
);
519 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
521 release_dc_ptr( dcs
);
522 release_dc_ptr( dc
);
526 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
527 dc
->layout
= dcs
->layout
;
528 dc
->hDevice
= dcs
->hDevice
;
529 dc
->ROPmode
= dcs
->ROPmode
;
530 dc
->polyFillMode
= dcs
->polyFillMode
;
531 dc
->stretchBltMode
= dcs
->stretchBltMode
;
532 dc
->relAbsMode
= dcs
->relAbsMode
;
533 dc
->backgroundMode
= dcs
->backgroundMode
;
534 dc
->backgroundColor
= dcs
->backgroundColor
;
535 dc
->textColor
= dcs
->textColor
;
536 dc
->dcBrushColor
= dcs
->dcBrushColor
;
537 dc
->dcPenColor
= dcs
->dcPenColor
;
538 dc
->brushOrgX
= dcs
->brushOrgX
;
539 dc
->brushOrgY
= dcs
->brushOrgY
;
540 dc
->mapperFlags
= dcs
->mapperFlags
;
541 dc
->textAlign
= dcs
->textAlign
;
542 dc
->charExtra
= dcs
->charExtra
;
543 dc
->breakExtra
= dcs
->breakExtra
;
544 dc
->breakRem
= dcs
->breakRem
;
545 dc
->MapMode
= dcs
->MapMode
;
546 dc
->GraphicsMode
= dcs
->GraphicsMode
;
547 dc
->CursPosX
= dcs
->CursPosX
;
548 dc
->CursPosY
= dcs
->CursPosY
;
549 dc
->ArcDirection
= dcs
->ArcDirection
;
550 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
551 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
552 dc
->xformVport2World
= dcs
->xformVport2World
;
553 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
554 dc
->BoundsRect
= dcs
->BoundsRect
;
556 dc
->wndOrgX
= dcs
->wndOrgX
;
557 dc
->wndOrgY
= dcs
->wndOrgY
;
558 dc
->wndExtX
= dcs
->wndExtX
;
559 dc
->wndExtY
= dcs
->wndExtY
;
560 dc
->vportOrgX
= dcs
->vportOrgX
;
561 dc
->vportOrgY
= dcs
->vportOrgY
;
562 dc
->vportExtX
= dcs
->vportExtX
;
563 dc
->vportExtY
= dcs
->vportExtY
;
564 dc
->virtual_res
= dcs
->virtual_res
;
565 dc
->virtual_size
= dcs
->virtual_size
;
569 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
570 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
574 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
579 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
580 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
584 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
587 DC_UpdateXforms( dc
);
588 CLIPPING_UpdateGCRegion( dc
);
590 SelectObject( hdc
, dcs
->hBitmap
);
591 SelectObject( hdc
, dcs
->hBrush
);
592 SelectObject( hdc
, dcs
->hFont
);
593 SelectObject( hdc
, dcs
->hPen
);
594 SetBkColor( hdc
, dcs
->backgroundColor
);
595 SetTextColor( hdc
, dcs
->textColor
);
596 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
598 dc
->saved_dc
= dcs
->saved_dc
;
600 dc
->saveLevel
= save_level
- 1;
602 release_dc_ptr( dcs
);
604 /* now destroy all the saved DCs */
608 if (!(dcs
= get_dc_ptr( first_dcs
))) break;
609 hdcs
= dcs
->saved_dc
;
613 release_dc_ptr( dc
);
618 /***********************************************************************
621 INT WINAPI
SaveDC( HDC hdc
)
626 if (!(dc
= get_dc_ptr( hdc
))) return 0;
628 if(dc
->funcs
->pSaveDC
)
629 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
631 ret
= save_dc_state( hdc
);
633 release_dc_ptr( dc
);
638 /***********************************************************************
639 * RestoreDC (GDI32.@)
641 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
646 TRACE("%p %d\n", hdc
, level
);
647 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
650 if(dc
->funcs
->pRestoreDC
)
651 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
653 success
= restore_dc_state( hdc
, level
);
655 release_dc_ptr( dc
);
660 /***********************************************************************
661 * CreateDCW (GDI32.@)
663 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
664 const DEVMODEW
*initData
)
669 const DC_FUNCTIONS
*funcs
;
674 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
678 ERR( "no device found for %s\n", debugstr_w(device
) );
681 strcpyW(buf
, driver
);
684 if (!(funcs
= DRIVER_load_driver( buf
)))
686 ERR( "no driver found for %s\n", debugstr_w(buf
) );
689 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_DC
))) goto error
;
692 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
693 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
695 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
696 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
698 if (dc
->funcs
->pCreateDC
&&
699 !dc
->funcs
->pCreateDC( hdc
, &physdev
, buf
, device
, output
, initData
))
701 WARN("creation aborted by device\n" );
705 physdev
->funcs
= funcs
;
706 push_dc_driver( dc
, physdev
);
708 dc
->vis_rect
.left
= 0;
709 dc
->vis_rect
.top
= 0;
710 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
711 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
712 SetRectRgn(dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
, dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
715 release_dc_ptr( dc
);
719 if (dc
) free_dc_ptr( dc
);
724 /***********************************************************************
725 * CreateDCA (GDI32.@)
727 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
728 const DEVMODEA
*initData
)
730 UNICODE_STRING driverW
, deviceW
, outputW
;
734 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
735 else driverW
.Buffer
= NULL
;
737 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
738 else deviceW
.Buffer
= NULL
;
740 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
741 else outputW
.Buffer
= NULL
;
746 /* don't convert initData for DISPLAY driver, it's not used */
747 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
748 initDataW
= GdiConvertToDevmodeW(initData
);
751 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
753 RtlFreeUnicodeString(&driverW
);
754 RtlFreeUnicodeString(&deviceW
);
755 RtlFreeUnicodeString(&outputW
);
756 HeapFree(GetProcessHeap(), 0, initDataW
);
761 /***********************************************************************
762 * CreateICA (GDI32.@)
764 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
765 const DEVMODEA
* initData
)
767 /* Nothing special yet for ICs */
768 return CreateDCA( driver
, device
, output
, initData
);
772 /***********************************************************************
773 * CreateICW (GDI32.@)
775 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
776 const DEVMODEW
* initData
)
778 /* Nothing special yet for ICs */
779 return CreateDCW( driver
, device
, output
, initData
);
783 /***********************************************************************
784 * CreateCompatibleDC (GDI32.@)
786 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
790 const DC_FUNCTIONS
*funcs
= NULL
;
791 PHYSDEV physDev
= NULL
;
797 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
798 if (GetObjectType( hdc
) == OBJ_DC
)
800 funcs
= origDC
->funcs
;
801 physDev
= origDC
->physDev
;
803 release_dc_ptr( origDC
);
806 if (!funcs
&& !(funcs
= DRIVER_get_display_driver())) return 0;
808 if (!(dc
= alloc_dc_ptr( funcs
, OBJ_MEMDC
))) goto error
;
810 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
812 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
813 dc
->vis_rect
.left
= 0;
814 dc
->vis_rect
.top
= 0;
815 dc
->vis_rect
.right
= 1;
816 dc
->vis_rect
.bottom
= 1;
817 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
821 /* Pass the driver-specific physical device info into
822 * the new DC. The driver may use this read-only info
823 * while creating the compatible DC. */
824 if (dc
->funcs
->pCreateDC
&&
825 !dc
->funcs
->pCreateDC( dc
->hSelf
, &physDev
, NULL
, NULL
, NULL
, NULL
))
827 WARN("creation aborted by device\n");
831 physDev
->funcs
= funcs
;
832 push_dc_driver( dc
, physDev
);
834 release_dc_ptr( dc
);
838 if (dc
) free_dc_ptr( dc
);
843 /***********************************************************************
846 BOOL WINAPI
DeleteDC( HDC hdc
)
854 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
855 if (dc
->refcount
!= 1)
857 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
858 release_dc_ptr( dc
);
862 /* Call hook procedure to check whether is it OK to delete this DC */
863 if (dc
->hookProc
&& !dc
->hookProc( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
865 release_dc_ptr( dc
);
869 while (dc
->saveLevel
)
872 HDC hdcs
= dc
->saved_dc
;
873 if (!(dcs
= get_dc_ptr( hdcs
))) break;
874 dc
->saved_dc
= dcs
->saved_dc
;
879 if (!(dc
->flags
& DC_SAVED
))
881 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
882 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
883 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
884 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
885 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
894 /***********************************************************************
897 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
902 if ((dc
= get_dc_ptr( hdc
)))
904 if (dc
->funcs
->pResetDC
)
906 ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
907 if (ret
) /* reset the visible region */
910 dc
->vis_rect
.left
= 0;
911 dc
->vis_rect
.top
= 0;
912 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
913 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
914 SetRectRgn( dc
->hVisRgn
, dc
->vis_rect
.left
, dc
->vis_rect
.top
,
915 dc
->vis_rect
.right
, dc
->vis_rect
.bottom
);
916 CLIPPING_UpdateGCRegion( dc
);
919 release_dc_ptr( dc
);
925 /***********************************************************************
928 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
933 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
934 else devmodeW
= NULL
;
936 ret
= ResetDCW(hdc
, devmodeW
);
938 HeapFree(GetProcessHeap(), 0, devmodeW
);
943 /***********************************************************************
944 * GetDeviceCaps (GDI32.@)
946 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
951 if ((dc
= get_dc_ptr( hdc
)))
953 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
954 else switch(cap
) /* return meaningful values for some entries */
956 case HORZRES
: ret
= 640; break;
957 case VERTRES
: ret
= 480; break;
958 case BITSPIXEL
: ret
= 1; break;
959 case PLANES
: ret
= 1; break;
960 case NUMCOLORS
: ret
= 2; break;
961 case ASPECTX
: ret
= 36; break;
962 case ASPECTY
: ret
= 36; break;
963 case ASPECTXY
: ret
= 51; break;
964 case LOGPIXELSX
: ret
= 72; break;
965 case LOGPIXELSY
: ret
= 72; break;
966 case SIZEPALETTE
: ret
= 2; break;
968 ret
= (TC_OP_CHARACTER
| TC_OP_STROKE
| TC_CP_STROKE
|
969 TC_CR_ANY
| TC_SF_X_YINDEP
| TC_SA_DOUBLE
| TC_SA_INTEGER
|
970 TC_SA_CONTIN
| TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
| TC_VA_ABLE
);
973 release_dc_ptr( dc
);
979 /***********************************************************************
980 * GetBkColor (GDI32.@)
982 COLORREF WINAPI
GetBkColor( HDC hdc
)
985 DC
* dc
= get_dc_ptr( hdc
);
988 ret
= dc
->backgroundColor
;
989 release_dc_ptr( dc
);
995 /***********************************************************************
996 * SetBkColor (GDI32.@)
998 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
1000 COLORREF ret
= CLR_INVALID
;
1001 DC
* dc
= get_dc_ptr( hdc
);
1003 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
1007 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkColor
);
1008 color
= physdev
->funcs
->pSetBkColor( physdev
, color
);
1009 if (color
!= CLR_INVALID
)
1011 ret
= dc
->backgroundColor
;
1012 dc
->backgroundColor
= color
;
1014 release_dc_ptr( dc
);
1020 /***********************************************************************
1021 * GetTextColor (GDI32.@)
1023 COLORREF WINAPI
GetTextColor( HDC hdc
)
1026 DC
* dc
= get_dc_ptr( hdc
);
1029 ret
= dc
->textColor
;
1030 release_dc_ptr( dc
);
1036 /***********************************************************************
1037 * SetTextColor (GDI32.@)
1039 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
1041 COLORREF ret
= CLR_INVALID
;
1042 DC
* dc
= get_dc_ptr( hdc
);
1044 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
1048 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
1049 color
= physdev
->funcs
->pSetTextColor( physdev
, color
);
1050 if (color
!= CLR_INVALID
)
1052 ret
= dc
->textColor
;
1053 dc
->textColor
= color
;
1055 release_dc_ptr( dc
);
1061 /***********************************************************************
1062 * GetTextAlign (GDI32.@)
1064 UINT WINAPI
GetTextAlign( HDC hdc
)
1067 DC
* dc
= get_dc_ptr( hdc
);
1070 ret
= dc
->textAlign
;
1071 release_dc_ptr( dc
);
1077 /***********************************************************************
1078 * SetTextAlign (GDI32.@)
1080 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1082 UINT ret
= GDI_ERROR
;
1083 DC
*dc
= get_dc_ptr( hdc
);
1085 TRACE("hdc=%p align=%d\n", hdc
, align
);
1089 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
1090 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
1091 if (align
!= GDI_ERROR
)
1093 ret
= dc
->textAlign
;
1094 dc
->textAlign
= align
;
1096 release_dc_ptr( dc
);
1101 /***********************************************************************
1102 * GetDCOrgEx (GDI32.@)
1104 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1108 if (!lpp
) return FALSE
;
1109 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1110 lpp
->x
= dc
->vis_rect
.left
;
1111 lpp
->y
= dc
->vis_rect
.top
;
1112 release_dc_ptr( dc
);
1117 /***********************************************************************
1118 * GetGraphicsMode (GDI32.@)
1120 INT WINAPI
GetGraphicsMode( HDC hdc
)
1123 DC
* dc
= get_dc_ptr( hdc
);
1126 ret
= dc
->GraphicsMode
;
1127 release_dc_ptr( dc
);
1133 /***********************************************************************
1134 * SetGraphicsMode (GDI32.@)
1136 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1139 DC
*dc
= get_dc_ptr( hdc
);
1141 /* One would think that setting the graphics mode to GM_COMPATIBLE
1142 * would also reset the world transformation matrix to the unity
1143 * matrix. However, in Windows, this is not the case. This doesn't
1144 * make a lot of sense to me, but that's the way it is.
1147 if ((mode
> 0) && (mode
<= GM_LAST
))
1149 ret
= dc
->GraphicsMode
;
1150 dc
->GraphicsMode
= mode
;
1152 release_dc_ptr( dc
);
1157 /***********************************************************************
1158 * GetArcDirection (GDI32.@)
1160 INT WINAPI
GetArcDirection( HDC hdc
)
1163 DC
* dc
= get_dc_ptr( hdc
);
1166 ret
= dc
->ArcDirection
;
1167 release_dc_ptr( dc
);
1173 /***********************************************************************
1174 * SetArcDirection (GDI32.@)
1176 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1181 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1183 SetLastError(ERROR_INVALID_PARAMETER
);
1187 if ((dc
= get_dc_ptr( hdc
)))
1189 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1190 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1193 ret
= dc
->ArcDirection
;
1194 dc
->ArcDirection
= dir
;
1196 release_dc_ptr( dc
);
1202 /***********************************************************************
1203 * GetWorldTransform (GDI32.@)
1205 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1208 if (!xform
) return FALSE
;
1209 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1210 *xform
= dc
->xformWorld2Wnd
;
1211 release_dc_ptr( dc
);
1216 /***********************************************************************
1217 * GetTransform (GDI32.@)
1221 * Returns one of the co-ordinate space transforms
1224 * hdc [I] Device context.
1225 * which [I] Which xform to return:
1226 * 0x203 World -> Page transform (that set by SetWorldTransform).
1227 * 0x304 Page -> Device transform (the mapping mode transform).
1228 * 0x204 World -> Device transform (the combination of the above two).
1229 * 0x402 Device -> World transform (the inversion of the above).
1230 * xform [O] The xform.
1233 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1236 DC
*dc
= get_dc_ptr( hdc
);
1237 if (!dc
) return FALSE
;
1242 *xform
= dc
->xformWorld2Wnd
;
1246 construct_window_to_viewport(dc
, xform
);
1250 *xform
= dc
->xformWorld2Vport
;
1254 *xform
= dc
->xformVport2World
;
1258 FIXME("Unknown code %x\n", which
);
1262 release_dc_ptr( dc
);
1267 /***********************************************************************
1268 * SetWorldTransform (GDI32.@)
1270 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1275 if (!xform
) return FALSE
;
1277 dc
= get_dc_ptr( hdc
);
1278 if (!dc
) return FALSE
;
1280 /* Check that graphics mode is GM_ADVANCED */
1281 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1283 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1284 xform
->eM11
, xform
->eM12
, xform
->eM21
, xform
->eM22
, xform
->eDx
, xform
->eDy
);
1286 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1287 if (xform
->eM11
* xform
->eM22
== xform
->eM12
* xform
->eM21
) goto done
;
1289 if (dc
->funcs
->pSetWorldTransform
)
1291 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1292 if (!ret
) goto done
;
1295 dc
->xformWorld2Wnd
= *xform
;
1296 DC_UpdateXforms( dc
);
1299 release_dc_ptr( dc
);
1304 /****************************************************************************
1305 * ModifyWorldTransform [GDI32.@]
1306 * Modifies the world transformation for a device context.
1309 * hdc [I] Handle to device context
1310 * xform [I] XFORM structure that will be used to modify the world
1312 * iMode [I] Specifies in what way to modify the world transformation
1315 * Resets the world transformation to the identity matrix.
1316 * The parameter xform is ignored.
1318 * Multiplies xform into the world transformation matrix from
1321 * Multiplies xform into the world transformation matrix from
1326 * Failure: FALSE. Use GetLastError() to determine the cause.
1328 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1332 DC
*dc
= get_dc_ptr( hdc
);
1334 /* Check for illegal parameters */
1335 if (!dc
) return FALSE
;
1336 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1338 /* Check that graphics mode is GM_ADVANCED */
1339 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1341 if (dc
->funcs
->pModifyWorldTransform
)
1343 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1344 if (!ret
) goto done
;
1350 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1351 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1352 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1353 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1354 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1355 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1357 case MWT_LEFTMULTIPLY
:
1358 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1359 &dc
->xformWorld2Wnd
);
1361 case MWT_RIGHTMULTIPLY
:
1362 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1369 DC_UpdateXforms( dc
);
1372 release_dc_ptr( dc
);
1377 /****************************************************************************
1378 * CombineTransform [GDI32.@]
1379 * Combines two transformation matrices.
1382 * xformResult [O] Stores the result of combining the two matrices
1383 * xform1 [I] Specifies the first matrix to apply
1384 * xform2 [I] Specifies the second matrix to apply
1387 * The same matrix can be passed in for more than one of the parameters.
1391 * Failure: FALSE. Use GetLastError() to determine the cause.
1393 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1394 const XFORM
*xform2
)
1398 /* Check for illegal parameters */
1399 if (!xformResult
|| !xform1
|| !xform2
)
1402 /* Create the result in a temporary XFORM, since xformResult may be
1403 * equal to xform1 or xform2 */
1404 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1405 xform1
->eM12
* xform2
->eM21
;
1406 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1407 xform1
->eM12
* xform2
->eM22
;
1408 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1409 xform1
->eM22
* xform2
->eM21
;
1410 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1411 xform1
->eM22
* xform2
->eM22
;
1412 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1413 xform1
->eDy
* xform2
->eM21
+
1415 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1416 xform1
->eDy
* xform2
->eM22
+
1419 /* Copy the result to xformResult */
1420 *xformResult
= xformTemp
;
1426 /***********************************************************************
1427 * SetDCHook (GDI32.@)
1429 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1431 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1433 DC
*dc
= get_dc_ptr( hdc
);
1435 if (!dc
) return FALSE
;
1437 if (!(dc
->flags
& DC_SAVED
))
1439 dc
->dwHookData
= dwHookData
;
1440 dc
->hookProc
= hookProc
;
1442 release_dc_ptr( dc
);
1447 /***********************************************************************
1448 * GetDCHook (GDI32.@)
1450 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1452 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1454 DC
*dc
= get_dc_ptr( hdc
);
1458 if (proc
) *proc
= dc
->hookProc
;
1459 ret
= dc
->dwHookData
;
1460 release_dc_ptr( dc
);
1465 /***********************************************************************
1466 * SetHookFlags (GDI32.@)
1468 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1470 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1472 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1477 /* "Undocumented Windows" info is slightly confusing. */
1479 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1481 if (flags
& DCHF_INVALIDATEVISRGN
)
1482 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1483 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1484 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1486 GDI_ReleaseObj( hdc
);
1490 /***********************************************************************
1491 * SetICMMode (GDI32.@)
1493 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1495 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1496 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1497 if (iEnableICM
== ICM_ON
) return 0;
1498 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1502 /***********************************************************************
1503 * GetDeviceGammaRamp (GDI32.@)
1505 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1508 DC
*dc
= get_dc_ptr( hDC
);
1512 if (dc
->funcs
->pGetDeviceGammaRamp
)
1513 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1514 release_dc_ptr( dc
);
1519 /***********************************************************************
1520 * SetDeviceGammaRamp (GDI32.@)
1522 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1525 DC
*dc
= get_dc_ptr( hDC
);
1529 if (dc
->funcs
->pSetDeviceGammaRamp
)
1530 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1531 release_dc_ptr( dc
);
1536 /***********************************************************************
1537 * GetColorSpace (GDI32.@)
1539 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1541 /*FIXME Need to to whatever GetColorSpace actually does */
1545 /***********************************************************************
1546 * CreateColorSpaceA (GDI32.@)
1548 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1554 /***********************************************************************
1555 * CreateColorSpaceW (GDI32.@)
1557 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1563 /***********************************************************************
1564 * DeleteColorSpace (GDI32.@)
1566 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1573 /***********************************************************************
1574 * SetColorSpace (GDI32.@)
1576 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1583 /***********************************************************************
1584 * GetBoundsRect (GDI32.@)
1586 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1589 DC
*dc
= get_dc_ptr( hdc
);
1591 if ( !dc
) return 0;
1595 *rect
= dc
->BoundsRect
;
1596 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1601 if (flags
& DCB_RESET
)
1603 dc
->BoundsRect
.left
= 0;
1604 dc
->BoundsRect
.top
= 0;
1605 dc
->BoundsRect
.right
= 0;
1606 dc
->BoundsRect
.bottom
= 0;
1607 dc
->flags
&= ~DC_BOUNDS_SET
;
1609 release_dc_ptr( dc
);
1614 /***********************************************************************
1615 * SetBoundsRect (GDI32.@)
1617 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1622 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1623 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1625 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1626 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1628 if (flags
& DCB_RESET
)
1630 dc
->BoundsRect
.left
= 0;
1631 dc
->BoundsRect
.top
= 0;
1632 dc
->BoundsRect
.right
= 0;
1633 dc
->BoundsRect
.bottom
= 0;
1634 dc
->flags
&= ~DC_BOUNDS_SET
;
1637 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1639 if (dc
->flags
& DC_BOUNDS_SET
)
1641 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1642 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1643 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1644 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1648 dc
->BoundsRect
= *rect
;
1649 dc
->flags
|= DC_BOUNDS_SET
;
1653 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1654 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1656 release_dc_ptr( dc
);
1661 /***********************************************************************
1662 * GetRelAbs (GDI32.@)
1664 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1667 DC
*dc
= get_dc_ptr( hdc
);
1670 ret
= dc
->relAbsMode
;
1671 release_dc_ptr( dc
);
1679 /***********************************************************************
1680 * GetBkMode (GDI32.@)
1682 INT WINAPI
GetBkMode( HDC hdc
)
1685 DC
* dc
= get_dc_ptr( hdc
);
1688 ret
= dc
->backgroundMode
;
1689 release_dc_ptr( dc
);
1695 /***********************************************************************
1696 * SetBkMode (GDI32.@)
1698 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1703 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1705 SetLastError(ERROR_INVALID_PARAMETER
);
1708 if ((dc
= get_dc_ptr( hdc
)))
1710 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1711 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1714 ret
= dc
->backgroundMode
;
1715 dc
->backgroundMode
= mode
;
1717 release_dc_ptr( dc
);
1723 /***********************************************************************
1726 INT WINAPI
GetROP2( HDC hdc
)
1729 DC
* dc
= get_dc_ptr( hdc
);
1733 release_dc_ptr( dc
);
1739 /***********************************************************************
1742 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1747 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1749 SetLastError(ERROR_INVALID_PARAMETER
);
1752 if ((dc
= get_dc_ptr( hdc
)))
1754 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1755 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1761 release_dc_ptr( dc
);
1767 /***********************************************************************
1768 * SetRelAbs (GDI32.@)
1770 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1775 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1777 SetLastError(ERROR_INVALID_PARAMETER
);
1780 if ((dc
= get_dc_ptr( hdc
)))
1782 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1783 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1786 ret
= dc
->relAbsMode
;
1787 dc
->relAbsMode
= mode
;
1789 release_dc_ptr( dc
);
1795 /***********************************************************************
1796 * GetPolyFillMode (GDI32.@)
1798 INT WINAPI
GetPolyFillMode( HDC hdc
)
1801 DC
* dc
= get_dc_ptr( hdc
);
1804 ret
= dc
->polyFillMode
;
1805 release_dc_ptr( dc
);
1811 /***********************************************************************
1812 * SetPolyFillMode (GDI32.@)
1814 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1819 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1821 SetLastError(ERROR_INVALID_PARAMETER
);
1824 if ((dc
= get_dc_ptr( hdc
)))
1826 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1827 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1830 ret
= dc
->polyFillMode
;
1831 dc
->polyFillMode
= mode
;
1833 release_dc_ptr( dc
);
1839 /***********************************************************************
1840 * GetStretchBltMode (GDI32.@)
1842 INT WINAPI
GetStretchBltMode( HDC hdc
)
1845 DC
* dc
= get_dc_ptr( hdc
);
1848 ret
= dc
->stretchBltMode
;
1849 release_dc_ptr( dc
);
1855 /***********************************************************************
1856 * SetStretchBltMode (GDI32.@)
1858 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1863 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1865 SetLastError(ERROR_INVALID_PARAMETER
);
1868 if ((dc
= get_dc_ptr( hdc
)))
1870 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1871 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1874 ret
= dc
->stretchBltMode
;
1875 dc
->stretchBltMode
= mode
;
1877 release_dc_ptr( dc
);
1883 /***********************************************************************
1884 * GetMapMode (GDI32.@)
1886 INT WINAPI
GetMapMode( HDC hdc
)
1889 DC
* dc
= get_dc_ptr( hdc
);
1893 release_dc_ptr( dc
);
1899 /***********************************************************************
1900 * GetBrushOrgEx (GDI32.@)
1902 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1904 DC
* dc
= get_dc_ptr( hdc
);
1905 if (!dc
) return FALSE
;
1906 pt
->x
= dc
->brushOrgX
;
1907 pt
->y
= dc
->brushOrgY
;
1908 release_dc_ptr( dc
);
1913 /***********************************************************************
1914 * GetCurrentPositionEx (GDI32.@)
1916 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1918 DC
* dc
= get_dc_ptr( hdc
);
1919 if (!dc
) return FALSE
;
1920 pt
->x
= dc
->CursPosX
;
1921 pt
->y
= dc
->CursPosY
;
1922 release_dc_ptr( dc
);
1927 /***********************************************************************
1928 * GetViewportExtEx (GDI32.@)
1930 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1932 DC
* dc
= get_dc_ptr( hdc
);
1933 if (!dc
) return FALSE
;
1934 size
->cx
= dc
->vportExtX
;
1935 size
->cy
= dc
->vportExtY
;
1936 release_dc_ptr( dc
);
1941 /***********************************************************************
1942 * GetViewportOrgEx (GDI32.@)
1944 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1946 DC
* dc
= get_dc_ptr( hdc
);
1947 if (!dc
) return FALSE
;
1948 pt
->x
= dc
->vportOrgX
;
1949 pt
->y
= dc
->vportOrgY
;
1950 release_dc_ptr( dc
);
1955 /***********************************************************************
1956 * GetWindowExtEx (GDI32.@)
1958 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1960 DC
* dc
= get_dc_ptr( hdc
);
1961 if (!dc
) return FALSE
;
1962 size
->cx
= dc
->wndExtX
;
1963 size
->cy
= dc
->wndExtY
;
1964 release_dc_ptr( dc
);
1969 /***********************************************************************
1970 * GetWindowOrgEx (GDI32.@)
1972 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1974 DC
* dc
= get_dc_ptr( hdc
);
1975 if (!dc
) return FALSE
;
1976 pt
->x
= dc
->wndOrgX
;
1977 pt
->y
= dc
->wndOrgY
;
1978 release_dc_ptr( dc
);
1983 /***********************************************************************
1984 * GetLayout (GDI32.@)
1986 * Gets left->right or right->left text layout flags of a dc.
1989 DWORD WINAPI
GetLayout(HDC hdc
)
1991 DWORD layout
= GDI_ERROR
;
1993 DC
* dc
= get_dc_ptr( hdc
);
1996 layout
= dc
->layout
;
1997 release_dc_ptr( dc
);
2000 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
2005 /***********************************************************************
2006 * SetLayout (GDI32.@)
2008 * Sets left->right or right->left text layout flags of a dc.
2011 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
2013 DWORD oldlayout
= GDI_ERROR
;
2015 DC
* dc
= get_dc_ptr( hdc
);
2018 oldlayout
= dc
->layout
;
2019 dc
->layout
= layout
;
2020 if (layout
!= oldlayout
)
2022 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
2023 DC_UpdateXforms( dc
);
2025 release_dc_ptr( dc
);
2028 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
2033 /***********************************************************************
2034 * GetDCBrushColor (GDI32.@)
2036 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
2039 COLORREF dcBrushColor
= CLR_INVALID
;
2041 TRACE("hdc(%p)\n", hdc
);
2043 dc
= get_dc_ptr( hdc
);
2046 dcBrushColor
= dc
->dcBrushColor
;
2047 release_dc_ptr( dc
);
2050 return dcBrushColor
;
2053 /***********************************************************************
2054 * SetDCBrushColor (GDI32.@)
2056 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2059 COLORREF oldClr
= CLR_INVALID
;
2061 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2063 dc
= get_dc_ptr( hdc
);
2066 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
2067 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
2068 if (crColor
!= CLR_INVALID
)
2070 oldClr
= dc
->dcBrushColor
;
2071 dc
->dcBrushColor
= crColor
;
2073 release_dc_ptr( dc
);
2079 /***********************************************************************
2080 * GetDCPenColor (GDI32.@)
2082 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2085 COLORREF dcPenColor
= CLR_INVALID
;
2087 TRACE("hdc(%p)\n", hdc
);
2089 dc
= get_dc_ptr( hdc
);
2092 dcPenColor
= dc
->dcPenColor
;
2093 release_dc_ptr( dc
);
2099 /***********************************************************************
2100 * SetDCPenColor (GDI32.@)
2102 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2105 COLORREF oldClr
= CLR_INVALID
;
2107 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2109 dc
= get_dc_ptr( hdc
);
2112 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
2113 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
2114 if (crColor
!= CLR_INVALID
)
2116 oldClr
= dc
->dcPenColor
;
2117 dc
->dcPenColor
= crColor
;
2119 release_dc_ptr( dc
);
2125 /***********************************************************************
2126 * CancelDC (GDI32.@)
2128 BOOL WINAPI
CancelDC(HDC hdc
)
2134 /*******************************************************************
2135 * GetMiterLimit [GDI32.@]
2139 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2144 TRACE("(%p,%p)\n", hdc
, peLimit
);
2146 dc
= get_dc_ptr( hdc
);
2150 *peLimit
= dc
->miterLimit
;
2152 release_dc_ptr( dc
);
2158 /*******************************************************************
2159 * SetMiterLimit [GDI32.@]
2163 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2168 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2170 dc
= get_dc_ptr( hdc
);
2174 *peOldLimit
= dc
->miterLimit
;
2175 dc
->miterLimit
= eNewLimit
;
2176 release_dc_ptr( dc
);
2182 /*******************************************************************
2183 * GdiIsMetaPrintDC [GDI32.@]
2185 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2191 /*******************************************************************
2192 * GdiIsMetaFileDC [GDI32.@]
2194 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2198 switch( GetObjectType( hdc
) )
2207 /*******************************************************************
2208 * GdiIsPlayMetafileDC [GDI32.@]
2210 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)