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 "wine/winuser16.h"
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
, void *obj
);
44 static const struct gdi_obj_funcs dc_funcs
=
46 NULL
, /* pSelectObject */
47 NULL
, /* pGetObject16 */
48 NULL
, /* pGetObjectA */
49 NULL
, /* pGetObjectW */
50 NULL
, /* pUnrealizeObject */
51 DC_DeleteObject
/* pDeleteObject */
54 /***********************************************************************
57 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
, WORD magic
)
62 if (!(dc
= GDI_AllocObject( sizeof(*dc
), magic
, (HGDIOBJ
*)&hdc
, &dc_funcs
))) return NULL
;
80 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
87 dc
->hPen
= GetStockObject( BLACK_PEN
);
88 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
89 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
92 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
94 dc
->ROPmode
= R2_COPYPEN
;
95 dc
->polyFillMode
= ALTERNATE
;
96 dc
->stretchBltMode
= BLACKONWHITE
;
97 dc
->relAbsMode
= ABSOLUTE
;
98 dc
->backgroundMode
= OPAQUE
;
99 dc
->backgroundColor
= RGB( 255, 255, 255 );
100 dc
->dcBrushColor
= RGB( 255, 255, 255 );
101 dc
->dcPenColor
= RGB( 0, 0, 0 );
102 dc
->textColor
= RGB( 0, 0, 0 );
105 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
109 dc
->MapMode
= MM_TEXT
;
110 dc
->GraphicsMode
= GM_COMPATIBLE
;
111 dc
->pAbortProc
= NULL
;
114 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
115 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
116 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
117 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
118 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
119 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
120 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
121 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
122 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
123 dc
->vport2WorldValid
= TRUE
;
124 dc
->BoundsRect
.left
= 0;
125 dc
->BoundsRect
.top
= 0;
126 dc
->BoundsRect
.right
= 0;
127 dc
->BoundsRect
.bottom
= 0;
128 dc
->saved_visrgn
= NULL
;
129 PATH_InitGdiPath(&dc
->path
);
135 /***********************************************************************
138 DC
*DC_GetDCPtr( HDC hdc
)
140 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
141 if (!ptr
) return NULL
;
142 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
143 (GDIMAGIC(ptr
->wMagic
) == MEMORY_DC_MAGIC
) ||
144 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
145 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
147 GDI_ReleaseObj( hdc
);
148 SetLastError( ERROR_INVALID_HANDLE
);
152 /***********************************************************************
155 * Retrieve a DC ptr while making sure the visRgn is updated.
156 * This function may call up to USER so the GDI lock should _not_
157 * be held when calling it.
159 DC
*DC_GetDCUpdate( HDC hdc
)
161 DC
*dc
= DC_GetDCPtr( hdc
);
162 if (!dc
) return NULL
;
163 while (dc
->flags
& DC_DIRTY
)
165 DCHOOKPROC proc
= dc
->hookThunk
;
166 dc
->flags
&= ~DC_DIRTY
;
169 DWORD_PTR data
= dc
->dwHookData
;
170 DC_ReleaseDCPtr( dc
);
171 proc( hdc
, DCHC_INVALIDVISRGN
, data
, 0 );
172 if (!(dc
= DC_GetDCPtr( hdc
))) break;
173 /* otherwise restart the loop in case it became dirty again in the meantime */
180 /***********************************************************************
183 void DC_ReleaseDCPtr( DC
*dc
)
185 GDI_ReleaseObj( dc
->hSelf
);
189 /***********************************************************************
192 BOOL
DC_FreeDCPtr( DC
*dc
)
194 return GDI_FreeObject( dc
->hSelf
, dc
);
198 /***********************************************************************
201 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
203 GDI_ReleaseObj( handle
);
204 return DeleteDC( handle
);
208 /***********************************************************************
211 * Setup device-specific DC values for a newly created DC.
213 void DC_InitDC( DC
* dc
)
215 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
216 SetTextColor( dc
->hSelf
, dc
->textColor
);
217 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
218 SelectObject( dc
->hSelf
, dc
->hPen
);
219 SelectObject( dc
->hSelf
, dc
->hBrush
);
220 SelectObject( dc
->hSelf
, dc
->hFont
);
221 CLIPPING_UpdateGCRegion( dc
);
225 /***********************************************************************
228 * Computes the inverse of the transformation xformSrc and stores it to
229 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
232 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
236 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
237 xformSrc
->eM12
*xformSrc
->eM21
;
238 if (determinant
> -1e-12 && determinant
< 1e-12)
241 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
242 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
243 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
244 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
245 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
246 xformSrc
->eDy
* xformDest
->eM21
;
247 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
248 xformSrc
->eDy
* xformDest
->eM22
;
254 /***********************************************************************
257 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
258 * fields of the specified DC by creating a transformation that
259 * represents the current mapping mode and combining it with the DC's
260 * world transform. This function should be called whenever the
261 * parameters associated with the mapping mode (window and viewport
262 * extents and origins) or the world transform change.
264 void DC_UpdateXforms( DC
*dc
)
266 XFORM xformWnd2Vport
, oldworld2vport
;
267 FLOAT scaleX
, scaleY
;
269 /* Construct a transformation to do the window-to-viewport conversion */
270 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
271 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
272 xformWnd2Vport
.eM11
= scaleX
;
273 xformWnd2Vport
.eM12
= 0.0;
274 xformWnd2Vport
.eM21
= 0.0;
275 xformWnd2Vport
.eM22
= scaleY
;
276 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
277 scaleX
* (FLOAT
)dc
->wndOrgX
;
278 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
279 scaleY
* (FLOAT
)dc
->wndOrgY
;
281 oldworld2vport
= dc
->xformWorld2Vport
;
282 /* Combine with the world transformation */
283 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
286 /* Create inverse of world-to-viewport transformation */
287 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
288 &dc
->xformVport2World
);
290 /* Reselect the font and pen back into the dc so that the size
292 if(memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)))
294 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
295 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
300 /***********************************************************************
301 * GetDCState (Not a Windows API)
303 HDC WINAPI
GetDCState( HDC hdc
)
308 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
309 if (!(newdc
= GDI_AllocObject( sizeof(DC
), GDIMAGIC(dc
->header
.wMagic
), &handle
, &dc_funcs
)))
311 DC_ReleaseDCPtr( dc
);
314 TRACE("(%p): returning %p\n", hdc
, handle
);
316 newdc
->flags
= dc
->flags
| DC_SAVED
;
317 newdc
->layout
= dc
->layout
;
318 newdc
->hPen
= dc
->hPen
;
319 newdc
->hBrush
= dc
->hBrush
;
320 newdc
->hFont
= dc
->hFont
;
321 newdc
->hBitmap
= dc
->hBitmap
;
322 newdc
->hDevice
= dc
->hDevice
;
323 newdc
->hPalette
= dc
->hPalette
;
324 newdc
->ROPmode
= dc
->ROPmode
;
325 newdc
->polyFillMode
= dc
->polyFillMode
;
326 newdc
->stretchBltMode
= dc
->stretchBltMode
;
327 newdc
->relAbsMode
= dc
->relAbsMode
;
328 newdc
->backgroundMode
= dc
->backgroundMode
;
329 newdc
->backgroundColor
= dc
->backgroundColor
;
330 newdc
->textColor
= dc
->textColor
;
331 newdc
->dcBrushColor
= dc
->dcBrushColor
;
332 newdc
->dcPenColor
= dc
->dcPenColor
;
333 newdc
->brushOrgX
= dc
->brushOrgX
;
334 newdc
->brushOrgY
= dc
->brushOrgY
;
335 newdc
->textAlign
= dc
->textAlign
;
336 newdc
->charExtra
= dc
->charExtra
;
337 newdc
->breakExtra
= dc
->breakExtra
;
338 newdc
->breakRem
= dc
->breakRem
;
339 newdc
->MapMode
= dc
->MapMode
;
340 newdc
->GraphicsMode
= dc
->GraphicsMode
;
341 newdc
->CursPosX
= dc
->CursPosX
;
342 newdc
->CursPosY
= dc
->CursPosY
;
343 newdc
->ArcDirection
= dc
->ArcDirection
;
344 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
345 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
346 newdc
->xformVport2World
= dc
->xformVport2World
;
347 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
348 newdc
->wndOrgX
= dc
->wndOrgX
;
349 newdc
->wndOrgY
= dc
->wndOrgY
;
350 newdc
->wndExtX
= dc
->wndExtX
;
351 newdc
->wndExtY
= dc
->wndExtY
;
352 newdc
->vportOrgX
= dc
->vportOrgX
;
353 newdc
->vportOrgY
= dc
->vportOrgY
;
354 newdc
->vportExtX
= dc
->vportExtX
;
355 newdc
->vportExtY
= dc
->vportExtY
;
356 newdc
->BoundsRect
= dc
->BoundsRect
;
358 newdc
->hSelf
= (HDC
)handle
;
359 newdc
->saveLevel
= 0;
362 PATH_InitGdiPath( &newdc
->path
);
364 newdc
->pAbortProc
= NULL
;
365 newdc
->hookThunk
= NULL
;
367 newdc
->saved_visrgn
= NULL
;
369 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
374 newdc
->hMetaClipRgn
= 0;
377 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
378 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
382 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
383 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
385 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
388 newdc
->gdiFont
= dc
->gdiFont
;
392 DC_ReleaseDCPtr( newdc
);
393 DC_ReleaseDCPtr( dc
);
398 /***********************************************************************
399 * SetDCState (Not a Windows API)
401 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
405 if (!(dc
= DC_GetDCUpdate( hdc
))) return;
406 if (!(dcs
= DC_GetDCPtr( hdcs
)))
408 DC_ReleaseDCPtr( dc
);
411 if (!dcs
->flags
& DC_SAVED
)
413 DC_ReleaseDCPtr( dc
);
414 DC_ReleaseDCPtr( dcs
);
417 TRACE("%p %p\n", hdc
, hdcs
);
419 dc
->flags
= dcs
->flags
& ~(DC_SAVED
| DC_DIRTY
);
420 dc
->layout
= dcs
->layout
;
421 dc
->hDevice
= dcs
->hDevice
;
422 dc
->ROPmode
= dcs
->ROPmode
;
423 dc
->polyFillMode
= dcs
->polyFillMode
;
424 dc
->stretchBltMode
= dcs
->stretchBltMode
;
425 dc
->relAbsMode
= dcs
->relAbsMode
;
426 dc
->backgroundMode
= dcs
->backgroundMode
;
427 dc
->backgroundColor
= dcs
->backgroundColor
;
428 dc
->textColor
= dcs
->textColor
;
429 dc
->dcBrushColor
= dcs
->dcBrushColor
;
430 dc
->dcPenColor
= dcs
->dcPenColor
;
431 dc
->brushOrgX
= dcs
->brushOrgX
;
432 dc
->brushOrgY
= dcs
->brushOrgY
;
433 dc
->textAlign
= dcs
->textAlign
;
434 dc
->charExtra
= dcs
->charExtra
;
435 dc
->breakExtra
= dcs
->breakExtra
;
436 dc
->breakRem
= dcs
->breakRem
;
437 dc
->MapMode
= dcs
->MapMode
;
438 dc
->GraphicsMode
= dcs
->GraphicsMode
;
439 dc
->CursPosX
= dcs
->CursPosX
;
440 dc
->CursPosY
= dcs
->CursPosY
;
441 dc
->ArcDirection
= dcs
->ArcDirection
;
442 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
443 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
444 dc
->xformVport2World
= dcs
->xformVport2World
;
445 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
446 dc
->BoundsRect
= dcs
->BoundsRect
;
448 dc
->wndOrgX
= dcs
->wndOrgX
;
449 dc
->wndOrgY
= dcs
->wndOrgY
;
450 dc
->wndExtX
= dcs
->wndExtX
;
451 dc
->wndExtY
= dcs
->wndExtY
;
452 dc
->vportOrgX
= dcs
->vportOrgX
;
453 dc
->vportOrgY
= dcs
->vportOrgY
;
454 dc
->vportExtX
= dcs
->vportExtX
;
455 dc
->vportExtY
= dcs
->vportExtY
;
459 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
460 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
464 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
469 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
470 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
474 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
477 CLIPPING_UpdateGCRegion( dc
);
479 SelectObject( hdc
, dcs
->hBitmap
);
480 SelectObject( hdc
, dcs
->hBrush
);
481 SelectObject( hdc
, dcs
->hFont
);
482 SelectObject( hdc
, dcs
->hPen
);
483 SetBkColor( hdc
, dcs
->backgroundColor
);
484 SetTextColor( hdc
, dcs
->textColor
);
485 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
486 DC_ReleaseDCPtr( dcs
);
487 DC_ReleaseDCPtr( dc
);
491 /***********************************************************************
492 * GetDCState (GDI.179)
494 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
496 return HDC_16( GetDCState( HDC_32(hdc
) ));
500 /***********************************************************************
501 * SetDCState (GDI.180)
503 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
505 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
509 /***********************************************************************
512 INT WINAPI
SaveDC( HDC hdc
)
518 dc
= DC_GetDCPtr( hdc
);
521 if(dc
->funcs
->pSaveDC
)
523 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
525 ret
= ++dc
->saveLevel
;
526 DC_ReleaseDCPtr( dc
);
530 if (!(hdcs
= GetDCState( hdc
)))
532 DC_ReleaseDCPtr( dc
);
535 dcs
= DC_GetDCPtr( hdcs
);
537 /* Copy path. The reason why path saving / restoring is in SaveDC/
538 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
539 * functions are only in Win16 (which doesn't have paths) and that
540 * SetDCState doesn't allow us to signal an error (which can happen
541 * when copying paths).
543 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
545 DC_ReleaseDCPtr( dc
);
546 DC_ReleaseDCPtr( dcs
);
551 dcs
->saved_dc
= dc
->saved_dc
;
553 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
554 ret
= ++dc
->saveLevel
;
555 DC_ReleaseDCPtr( dcs
);
556 DC_ReleaseDCPtr( dc
);
561 /***********************************************************************
562 * RestoreDC (GDI32.@)
564 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
569 TRACE("%p %d\n", hdc
, level
);
570 dc
= DC_GetDCUpdate( hdc
);
571 if(!dc
) return FALSE
;
573 if(abs(level
) > dc
->saveLevel
|| level
== 0)
575 DC_ReleaseDCPtr( dc
);
579 if(dc
->funcs
->pRestoreDC
)
581 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
582 if(level
< 0) level
= dc
->saveLevel
+ level
+ 1;
584 dc
->saveLevel
= level
- 1;
585 DC_ReleaseDCPtr( dc
);
589 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
591 while (dc
->saveLevel
>= level
)
593 HDC hdcs
= dc
->saved_dc
;
594 if (!(dcs
= DC_GetDCPtr( hdcs
)))
596 DC_ReleaseDCPtr( dc
);
599 dc
->saved_dc
= dcs
->saved_dc
;
601 if (--dc
->saveLevel
< level
)
603 SetDCState( hdc
, hdcs
);
604 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
605 /* FIXME: This might not be quite right, since we're
606 * returning FALSE but still destroying the saved DC state */
609 DC_ReleaseDCPtr( dcs
);
610 DC_ReleaseDCPtr( dc
);
612 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
614 DC_ReleaseDCPtr( dc
);
619 /***********************************************************************
620 * CreateDCW (GDI32.@)
622 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
623 const DEVMODEW
*initData
)
627 const DC_FUNCTIONS
*funcs
;
632 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
636 ERR( "no device found for %s\n", debugstr_w(device
) );
639 strcpyW(buf
, driver
);
642 if (!(funcs
= DRIVER_load_driver( buf
)))
644 ERR( "no driver found for %s\n", debugstr_w(buf
) );
647 if (!(dc
= DC_AllocDC( funcs
, DC_MAGIC
))) goto error
;
650 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
651 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
;
653 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
654 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
656 if (dc
->funcs
->pCreateDC
&&
657 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
659 WARN("creation aborted by device\n" );
663 SetRectRgn( dc
->hVisRgn
, 0, 0,
664 GetDeviceCaps( hdc
, DESKTOPHORZRES
), GetDeviceCaps( hdc
, DESKTOPVERTRES
) );
667 DC_ReleaseDCPtr( dc
);
671 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
672 if (dc
) DC_FreeDCPtr( dc
);
673 DRIVER_release_driver( funcs
);
678 /***********************************************************************
679 * CreateDCA (GDI32.@)
681 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
682 const DEVMODEA
*initData
)
684 UNICODE_STRING driverW
, deviceW
, outputW
;
688 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
689 else driverW
.Buffer
= NULL
;
691 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
692 else deviceW
.Buffer
= NULL
;
694 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
695 else outputW
.Buffer
= NULL
;
700 /* don't convert initData for DISPLAY driver, it's not used */
701 if (!driverW
.Buffer
|| strcmpiW( driverW
.Buffer
, displayW
))
702 initDataW
= GdiConvertToDevmodeW(initData
);
705 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
707 RtlFreeUnicodeString(&driverW
);
708 RtlFreeUnicodeString(&deviceW
);
709 RtlFreeUnicodeString(&outputW
);
710 HeapFree(GetProcessHeap(), 0, initDataW
);
715 /***********************************************************************
716 * CreateICA (GDI32.@)
718 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
719 const DEVMODEA
* initData
)
721 /* Nothing special yet for ICs */
722 return CreateDCA( driver
, device
, output
, initData
);
726 /***********************************************************************
727 * CreateICW (GDI32.@)
729 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
730 const DEVMODEW
* initData
)
732 /* Nothing special yet for ICs */
733 return CreateDCW( driver
, device
, output
, initData
);
737 /***********************************************************************
738 * CreateCompatibleDC (GDI32.@)
740 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
743 const DC_FUNCTIONS
*funcs
= NULL
;
744 PHYSDEV physDev
= NULL
;
748 if ((origDC
= DC_GetDCPtr( hdc
)))
750 if (GetObjectType( hdc
) == OBJ_DC
)
752 funcs
= origDC
->funcs
;
753 physDev
= origDC
->physDev
;
755 DC_ReleaseDCPtr( origDC
); /* can't hold the lock while loading the driver */
756 if (funcs
) funcs
= DRIVER_get_driver( funcs
);
759 if (!funcs
&& !(funcs
= DRIVER_load_driver( displayW
))) return 0;
761 if (!(dc
= DC_AllocDC( funcs
, MEMORY_DC_MAGIC
))) goto error
;
763 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
765 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
766 if (!(dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ))) goto error
; /* default bitmap is 1x1 */
768 /* Copy the driver-specific physical device info into
769 * the new DC. The driver may use this read-only info
770 * while creating the compatible DC below. */
771 dc
->physDev
= physDev
;
773 if (dc
->funcs
->pCreateDC
&&
774 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
776 WARN("creation aborted by device\n");
781 DC_ReleaseDCPtr( dc
);
785 if (dc
&& dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
786 if (dc
) DC_FreeDCPtr( dc
);
787 DRIVER_release_driver( funcs
);
792 /***********************************************************************
795 BOOL WINAPI
DeleteDC( HDC hdc
)
797 const DC_FUNCTIONS
*funcs
= NULL
;
804 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
806 /* Call hook procedure to check whether is it OK to delete this DC */
809 DCHOOKPROC proc
= dc
->hookThunk
;
810 DWORD_PTR data
= dc
->dwHookData
;
811 DC_ReleaseDCPtr( dc
);
812 if (!proc( hdc
, DCHC_DELETEDC
, data
, 0 )) return FALSE
;
813 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
816 while (dc
->saveLevel
)
819 HDC hdcs
= dc
->saved_dc
;
820 if (!(dcs
= DC_GetDCPtr( hdcs
))) break;
821 dc
->saved_dc
= dcs
->saved_dc
;
823 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
824 if (dcs
->hMetaRgn
) DeleteObject( dcs
->hMetaRgn
);
825 if (dcs
->hMetaClipRgn
) DeleteObject( dcs
->hMetaClipRgn
);
826 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
827 PATH_DestroyGdiPath(&dcs
->path
);
831 if (!(dc
->flags
& DC_SAVED
))
833 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
834 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
835 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
836 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
838 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
842 while (dc
->saved_visrgn
)
844 struct saved_visrgn
*next
= dc
->saved_visrgn
->next
;
845 DeleteObject( dc
->saved_visrgn
->hrgn
);
846 HeapFree( GetProcessHeap(), 0, dc
->saved_visrgn
);
847 dc
->saved_visrgn
= next
;
849 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
850 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
851 if (dc
->hMetaClipRgn
) DeleteObject( dc
->hMetaClipRgn
);
852 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
853 PATH_DestroyGdiPath(&dc
->path
);
856 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
861 /***********************************************************************
864 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
869 if ((dc
= DC_GetDCPtr( hdc
)))
871 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
872 DC_ReleaseDCPtr( dc
);
878 /***********************************************************************
881 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
886 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
887 else devmodeW
= NULL
;
889 ret
= ResetDCW(hdc
, devmodeW
);
891 HeapFree(GetProcessHeap(), 0, devmodeW
);
896 /***********************************************************************
897 * GetDeviceCaps (GDI32.@)
899 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
904 if ((dc
= DC_GetDCPtr( hdc
)))
906 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
907 else switch(cap
) /* return meaningful values for some entries */
909 case HORZRES
: ret
= 640; break;
910 case VERTRES
: ret
= 480; break;
911 case BITSPIXEL
: ret
= 1; break;
912 case PLANES
: ret
= 1; break;
913 case NUMCOLORS
: ret
= 2; break;
914 case ASPECTX
: ret
= 36; break;
915 case ASPECTY
: ret
= 36; break;
916 case ASPECTXY
: ret
= 51; break;
917 case LOGPIXELSX
: ret
= 72; break;
918 case LOGPIXELSY
: ret
= 72; break;
919 case SIZEPALETTE
: ret
= 2; break;
921 DC_ReleaseDCPtr( dc
);
927 /***********************************************************************
928 * GetBkColor (GDI32.@)
930 COLORREF WINAPI
GetBkColor( HDC hdc
)
933 DC
* dc
= DC_GetDCPtr( hdc
);
936 ret
= dc
->backgroundColor
;
937 DC_ReleaseDCPtr( dc
);
943 /***********************************************************************
944 * SetBkColor (GDI32.@)
946 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
949 DC
* dc
= DC_GetDCPtr( hdc
);
951 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
953 if (!dc
) return CLR_INVALID
;
954 oldColor
= dc
->backgroundColor
;
955 if (dc
->funcs
->pSetBkColor
)
957 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
958 if (color
== CLR_INVALID
) /* don't change it */
961 oldColor
= CLR_INVALID
;
964 dc
->backgroundColor
= color
;
965 DC_ReleaseDCPtr( dc
);
970 /***********************************************************************
971 * GetTextColor (GDI32.@)
973 COLORREF WINAPI
GetTextColor( HDC hdc
)
976 DC
* dc
= DC_GetDCPtr( hdc
);
980 DC_ReleaseDCPtr( dc
);
986 /***********************************************************************
987 * SetTextColor (GDI32.@)
989 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
992 DC
* dc
= DC_GetDCPtr( hdc
);
994 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
996 if (!dc
) return CLR_INVALID
;
997 oldColor
= dc
->textColor
;
998 if (dc
->funcs
->pSetTextColor
)
1000 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
1001 if (color
== CLR_INVALID
) /* don't change it */
1004 oldColor
= CLR_INVALID
;
1007 dc
->textColor
= color
;
1008 DC_ReleaseDCPtr( dc
);
1013 /***********************************************************************
1014 * GetTextAlign (GDI32.@)
1016 UINT WINAPI
GetTextAlign( HDC hdc
)
1019 DC
* dc
= DC_GetDCPtr( hdc
);
1022 ret
= dc
->textAlign
;
1023 DC_ReleaseDCPtr( dc
);
1029 /***********************************************************************
1030 * SetTextAlign (GDI32.@)
1032 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1035 DC
*dc
= DC_GetDCPtr( hdc
);
1037 TRACE("hdc=%p align=%d\n", hdc
, align
);
1039 if (!dc
) return 0x0;
1040 ret
= dc
->textAlign
;
1041 if (dc
->funcs
->pSetTextAlign
)
1042 if (!dc
->funcs
->pSetTextAlign(dc
->physDev
, align
))
1044 if (ret
!= GDI_ERROR
)
1045 dc
->textAlign
= align
;
1046 DC_ReleaseDCPtr( dc
);
1050 /***********************************************************************
1051 * GetDCOrgEx (GDI32.@)
1053 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1057 if (!lpp
) return FALSE
;
1058 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
1060 lpp
->x
= lpp
->y
= 0;
1061 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
1062 DC_ReleaseDCPtr( dc
);
1067 /***********************************************************************
1068 * SetDCOrg (GDI.117)
1070 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
1073 HDC hdc
= HDC_32( hdc16
);
1074 DC
*dc
= DC_GetDCPtr( hdc
);
1076 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
1077 DC_ReleaseDCPtr( dc
);
1082 /***********************************************************************
1083 * GetGraphicsMode (GDI32.@)
1085 INT WINAPI
GetGraphicsMode( HDC hdc
)
1088 DC
* dc
= DC_GetDCPtr( hdc
);
1091 ret
= dc
->GraphicsMode
;
1092 DC_ReleaseDCPtr( dc
);
1098 /***********************************************************************
1099 * SetGraphicsMode (GDI32.@)
1101 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1104 DC
*dc
= DC_GetDCPtr( hdc
);
1106 /* One would think that setting the graphics mode to GM_COMPATIBLE
1107 * would also reset the world transformation matrix to the unity
1108 * matrix. However, in Windows, this is not the case. This doesn't
1109 * make a lot of sense to me, but that's the way it is.
1112 if ((mode
> 0) && (mode
<= GM_LAST
))
1114 ret
= dc
->GraphicsMode
;
1115 dc
->GraphicsMode
= mode
;
1117 DC_ReleaseDCPtr( dc
);
1122 /***********************************************************************
1123 * GetArcDirection (GDI32.@)
1125 INT WINAPI
GetArcDirection( HDC hdc
)
1128 DC
* dc
= DC_GetDCPtr( hdc
);
1131 ret
= dc
->ArcDirection
;
1132 DC_ReleaseDCPtr( dc
);
1138 /***********************************************************************
1139 * SetArcDirection (GDI32.@)
1141 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1144 INT nOldDirection
= 0;
1146 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1148 SetLastError(ERROR_INVALID_PARAMETER
);
1152 if ((dc
= DC_GetDCPtr( hdc
)))
1154 if (dc
->funcs
->pSetArcDirection
)
1156 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1158 nOldDirection
= dc
->ArcDirection
;
1159 dc
->ArcDirection
= nDirection
;
1160 DC_ReleaseDCPtr( dc
);
1162 return nOldDirection
;
1166 /***********************************************************************
1167 * GetWorldTransform (GDI32.@)
1169 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1172 if (!xform
) return FALSE
;
1173 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1174 *xform
= dc
->xformWorld2Wnd
;
1175 DC_ReleaseDCPtr( dc
);
1180 /***********************************************************************
1181 * GetTransform (GDI32.@)
1183 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1185 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1186 FIXME("stub: don't know what to do for code %x\n", unknown
);
1191 /***********************************************************************
1192 * SetWorldTransform (GDI32.@)
1194 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1197 DC
*dc
= DC_GetDCPtr( hdc
);
1199 if (!dc
) return FALSE
;
1200 if (!xform
) goto done
;
1202 /* Check that graphics mode is GM_ADVANCED */
1203 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1205 if (dc
->funcs
->pSetWorldTransform
)
1207 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1208 if (!ret
) goto done
;
1211 dc
->xformWorld2Wnd
= *xform
;
1212 DC_UpdateXforms( dc
);
1215 DC_ReleaseDCPtr( dc
);
1220 /****************************************************************************
1221 * ModifyWorldTransform [GDI32.@]
1222 * Modifies the world transformation for a device context.
1225 * hdc [I] Handle to device context
1226 * xform [I] XFORM structure that will be used to modify the world
1228 * iMode [I] Specifies in what way to modify the world transformation
1231 * Resets the world transformation to the identity matrix.
1232 * The parameter xform is ignored.
1234 * Multiplies xform into the world transformation matrix from
1237 * Multiplies xform into the world transformation matrix from
1242 * Failure: FALSE. Use GetLastError() to determine the cause.
1244 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1248 DC
*dc
= DC_GetDCPtr( hdc
);
1250 /* Check for illegal parameters */
1251 if (!dc
) return FALSE
;
1252 if (!xform
&& iMode
!= MWT_IDENTITY
) goto done
;
1254 /* Check that graphics mode is GM_ADVANCED */
1255 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1257 if (dc
->funcs
->pModifyWorldTransform
)
1259 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1260 if (!ret
) goto done
;
1266 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1267 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1268 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1269 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1270 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1271 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1273 case MWT_LEFTMULTIPLY
:
1274 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1275 &dc
->xformWorld2Wnd
);
1277 case MWT_RIGHTMULTIPLY
:
1278 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1285 DC_UpdateXforms( dc
);
1288 DC_ReleaseDCPtr( dc
);
1293 /****************************************************************************
1294 * CombineTransform [GDI32.@]
1295 * Combines two transformation matrices.
1298 * xformResult [O] Stores the result of combining the two matrices
1299 * xform1 [I] Specifies the first matrix to apply
1300 * xform2 [I] Specifies the second matrix to apply
1303 * The same matrix can be passed in for more than one of the parameters.
1307 * Failure: FALSE. Use GetLastError() to determine the cause.
1309 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1310 const XFORM
*xform2
)
1314 /* Check for illegal parameters */
1315 if (!xformResult
|| !xform1
|| !xform2
)
1318 /* Create the result in a temporary XFORM, since xformResult may be
1319 * equal to xform1 or xform2 */
1320 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1321 xform1
->eM12
* xform2
->eM21
;
1322 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1323 xform1
->eM12
* xform2
->eM22
;
1324 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1325 xform1
->eM22
* xform2
->eM21
;
1326 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1327 xform1
->eM22
* xform2
->eM22
;
1328 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1329 xform1
->eDy
* xform2
->eM21
+
1331 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1332 xform1
->eDy
* xform2
->eM22
+
1335 /* Copy the result to xformResult */
1336 *xformResult
= xformTemp
;
1342 /***********************************************************************
1343 * SetDCHook (GDI32.@)
1345 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1347 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1349 DC
*dc
= DC_GetDCPtr( hdc
);
1351 if (!dc
) return FALSE
;
1353 if (!(dc
->flags
& DC_SAVED
))
1355 dc
->dwHookData
= dwHookData
;
1356 dc
->hookThunk
= hookProc
;
1358 DC_ReleaseDCPtr( dc
);
1363 /* relay function to call the 16-bit DC hook proc */
1364 static BOOL WINAPI
call_dc_hook16( HDC hdc
, WORD code
, DWORD_PTR data
, LPARAM lParam
)
1368 FARPROC16 proc
= NULL
;
1369 DC
*dc
= DC_GetDCPtr( hdc
);
1371 if (!dc
) return FALSE
;
1372 proc
= dc
->hookProc
;
1373 DC_ReleaseDCPtr( dc
);
1374 if (!proc
) return FALSE
;
1375 args
[5] = HDC_16(hdc
);
1377 args
[3] = HIWORD(data
);
1378 args
[2] = LOWORD(data
);
1379 args
[1] = HIWORD(lParam
);
1380 args
[0] = LOWORD(lParam
);
1381 WOWCallback16Ex( (DWORD
)proc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1385 /***********************************************************************
1386 * SetDCHook (GDI.190)
1388 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1390 HDC hdc
= HDC_32( hdc16
);
1391 DC
*dc
= DC_GetDCPtr( hdc
);
1392 if (!dc
) return FALSE
;
1394 dc
->hookProc
= hookProc
;
1395 DC_ReleaseDCPtr( dc
);
1396 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1400 /***********************************************************************
1401 * GetDCHook (GDI.191)
1403 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1405 HDC hdc
= HDC_32( hdc16
);
1406 DC
*dc
= DC_GetDCPtr( hdc
);
1410 *phookProc
= dc
->hookProc
;
1411 ret
= dc
->dwHookData
;
1412 DC_ReleaseDCPtr( dc
);
1417 /***********************************************************************
1418 * SetHookFlags (GDI.192)
1420 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1422 HDC hdc
= HDC_32( hdc16
);
1423 DC
*dc
= DC_GetDCPtr( hdc
);
1427 WORD wRet
= dc
->flags
& DC_DIRTY
;
1429 /* "Undocumented Windows" info is slightly confusing.
1432 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1434 if( flags
& DCHF_INVALIDATEVISRGN
)
1435 dc
->flags
|= DC_DIRTY
;
1436 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1437 dc
->flags
&= ~DC_DIRTY
;
1438 DC_ReleaseDCPtr( dc
);
1444 /***********************************************************************
1445 * SetICMMode (GDI32.@)
1447 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1449 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1450 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1451 if (iEnableICM
== ICM_ON
) return 0;
1452 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1456 /***********************************************************************
1457 * GetDeviceGammaRamp (GDI32.@)
1459 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1462 DC
*dc
= DC_GetDCPtr( hDC
);
1466 if (dc
->funcs
->pGetDeviceGammaRamp
)
1467 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1468 DC_ReleaseDCPtr( dc
);
1473 /***********************************************************************
1474 * SetDeviceGammaRamp (GDI32.@)
1476 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1479 DC
*dc
= DC_GetDCPtr( hDC
);
1483 if (dc
->funcs
->pSetDeviceGammaRamp
)
1484 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1485 DC_ReleaseDCPtr( dc
);
1490 /***********************************************************************
1491 * GetColorSpace (GDI32.@)
1493 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1495 /*FIXME Need to to whatever GetColorSpace actually does */
1499 /***********************************************************************
1500 * CreateColorSpaceA (GDI32.@)
1502 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1508 /***********************************************************************
1509 * CreateColorSpaceW (GDI32.@)
1511 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1517 /***********************************************************************
1518 * DeleteColorSpace (GDI32.@)
1520 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1527 /***********************************************************************
1528 * SetColorSpace (GDI32.@)
1530 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1537 /***********************************************************************
1538 * GetBoundsRect (GDI32.@)
1540 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1543 DC
*dc
= DC_GetDCPtr( hdc
);
1545 if ( !dc
) return 0;
1547 if (rect
) *rect
= dc
->BoundsRect
;
1549 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1551 if (flags
& DCB_RESET
)
1553 dc
->BoundsRect
.left
= 0;
1554 dc
->BoundsRect
.top
= 0;
1555 dc
->BoundsRect
.right
= 0;
1556 dc
->BoundsRect
.bottom
= 0;
1557 dc
->flags
&= ~DC_BOUNDS_SET
;
1559 DC_ReleaseDCPtr( dc
);
1564 /***********************************************************************
1565 * SetBoundsRect (GDI32.@)
1567 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1572 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1573 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1575 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1576 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1578 if (flags
& DCB_RESET
)
1580 dc
->BoundsRect
.left
= 0;
1581 dc
->BoundsRect
.top
= 0;
1582 dc
->BoundsRect
.right
= 0;
1583 dc
->BoundsRect
.bottom
= 0;
1584 dc
->flags
&= ~DC_BOUNDS_SET
;
1587 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1589 if (dc
->flags
& DC_BOUNDS_SET
)
1591 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1592 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1593 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1594 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1598 dc
->BoundsRect
= *rect
;
1599 dc
->flags
|= DC_BOUNDS_SET
;
1603 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1604 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1606 DC_ReleaseDCPtr( dc
);
1611 /***********************************************************************
1612 * GetRelAbs (GDI32.@)
1614 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1617 DC
*dc
= DC_GetDCPtr( hdc
);
1620 ret
= dc
->relAbsMode
;
1621 DC_ReleaseDCPtr( dc
);
1629 /***********************************************************************
1630 * GetBkMode (GDI32.@)
1632 INT WINAPI
GetBkMode( HDC hdc
)
1635 DC
* dc
= DC_GetDCPtr( hdc
);
1638 ret
= dc
->backgroundMode
;
1639 DC_ReleaseDCPtr( dc
);
1645 /***********************************************************************
1646 * SetBkMode (GDI32.@)
1648 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1652 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1654 SetLastError(ERROR_INVALID_PARAMETER
);
1657 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1659 ret
= dc
->backgroundMode
;
1660 if (dc
->funcs
->pSetBkMode
)
1661 if (!dc
->funcs
->pSetBkMode( dc
->physDev
, mode
))
1664 dc
->backgroundMode
= mode
;
1665 DC_ReleaseDCPtr( dc
);
1670 /***********************************************************************
1673 INT WINAPI
GetROP2( HDC hdc
)
1676 DC
* dc
= DC_GetDCPtr( hdc
);
1680 DC_ReleaseDCPtr( dc
);
1686 /***********************************************************************
1689 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1693 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1695 SetLastError(ERROR_INVALID_PARAMETER
);
1698 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1700 if (dc
->funcs
->pSetROP2
)
1701 if (!dc
->funcs
->pSetROP2( dc
->physDev
, mode
))
1705 DC_ReleaseDCPtr( dc
);
1710 /***********************************************************************
1711 * SetRelAbs (GDI32.@)
1713 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1717 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1719 SetLastError(ERROR_INVALID_PARAMETER
);
1722 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1723 if (dc
->funcs
->pSetRelAbs
)
1724 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1727 ret
= dc
->relAbsMode
;
1728 dc
->relAbsMode
= mode
;
1730 DC_ReleaseDCPtr( dc
);
1735 /***********************************************************************
1736 * GetPolyFillMode (GDI32.@)
1738 INT WINAPI
GetPolyFillMode( HDC hdc
)
1741 DC
* dc
= DC_GetDCPtr( hdc
);
1744 ret
= dc
->polyFillMode
;
1745 DC_ReleaseDCPtr( dc
);
1751 /***********************************************************************
1752 * SetPolyFillMode (GDI32.@)
1754 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1758 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1760 SetLastError(ERROR_INVALID_PARAMETER
);
1763 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1764 ret
= dc
->polyFillMode
;
1765 if (dc
->funcs
->pSetPolyFillMode
)
1766 if (!dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
))
1769 dc
->polyFillMode
= mode
;
1770 DC_ReleaseDCPtr( dc
);
1775 /***********************************************************************
1776 * GetStretchBltMode (GDI32.@)
1778 INT WINAPI
GetStretchBltMode( HDC hdc
)
1781 DC
* dc
= DC_GetDCPtr( hdc
);
1784 ret
= dc
->stretchBltMode
;
1785 DC_ReleaseDCPtr( dc
);
1791 /***********************************************************************
1792 * SetStretchBltMode (GDI32.@)
1794 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1798 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1800 SetLastError(ERROR_INVALID_PARAMETER
);
1803 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1804 ret
= dc
->stretchBltMode
;
1805 if (dc
->funcs
->pSetStretchBltMode
)
1806 if (!dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
))
1809 dc
->stretchBltMode
= mode
;
1810 DC_ReleaseDCPtr( dc
);
1815 /***********************************************************************
1816 * GetMapMode (GDI32.@)
1818 INT WINAPI
GetMapMode( HDC hdc
)
1821 DC
* dc
= DC_GetDCPtr( hdc
);
1825 DC_ReleaseDCPtr( dc
);
1831 /***********************************************************************
1832 * GetBrushOrgEx (GDI32.@)
1834 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1836 DC
* dc
= DC_GetDCPtr( hdc
);
1837 if (!dc
) return FALSE
;
1838 pt
->x
= dc
->brushOrgX
;
1839 pt
->y
= dc
->brushOrgY
;
1840 DC_ReleaseDCPtr( dc
);
1845 /***********************************************************************
1846 * GetCurrentPositionEx (GDI32.@)
1848 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1850 DC
* dc
= DC_GetDCPtr( hdc
);
1851 if (!dc
) return FALSE
;
1852 pt
->x
= dc
->CursPosX
;
1853 pt
->y
= dc
->CursPosY
;
1854 DC_ReleaseDCPtr( dc
);
1859 /***********************************************************************
1860 * GetViewportExtEx (GDI32.@)
1862 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1864 DC
* dc
= DC_GetDCPtr( hdc
);
1865 if (!dc
) return FALSE
;
1866 size
->cx
= dc
->vportExtX
;
1867 size
->cy
= dc
->vportExtY
;
1868 DC_ReleaseDCPtr( dc
);
1873 /***********************************************************************
1874 * GetViewportOrgEx (GDI32.@)
1876 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1878 DC
* dc
= DC_GetDCPtr( hdc
);
1879 if (!dc
) return FALSE
;
1880 pt
->x
= dc
->vportOrgX
;
1881 pt
->y
= dc
->vportOrgY
;
1882 DC_ReleaseDCPtr( dc
);
1887 /***********************************************************************
1888 * GetWindowExtEx (GDI32.@)
1890 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1892 DC
* dc
= DC_GetDCPtr( hdc
);
1893 if (!dc
) return FALSE
;
1894 size
->cx
= dc
->wndExtX
;
1895 size
->cy
= dc
->wndExtY
;
1896 DC_ReleaseDCPtr( dc
);
1901 /***********************************************************************
1902 * GetWindowOrgEx (GDI32.@)
1904 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1906 DC
* dc
= DC_GetDCPtr( hdc
);
1907 if (!dc
) return FALSE
;
1908 pt
->x
= dc
->wndOrgX
;
1909 pt
->y
= dc
->wndOrgY
;
1910 DC_ReleaseDCPtr( dc
);
1915 /***********************************************************************
1916 * InquireVisRgn (GDI.131)
1918 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1921 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1924 ret
= HRGN_16(dc
->hVisRgn
);
1925 DC_ReleaseDCPtr( dc
);
1931 /***********************************************************************
1932 * GetClipRgn (GDI.173)
1934 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1937 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1940 ret
= HRGN_16(dc
->hClipRgn
);
1941 DC_ReleaseDCPtr( dc
);
1947 /***********************************************************************
1948 * GetLayout (GDI32.@)
1950 * Gets left->right or right->left text layout flags of a dc.
1953 DWORD WINAPI
GetLayout(HDC hdc
)
1955 DWORD layout
= GDI_ERROR
;
1957 DC
* dc
= DC_GetDCPtr( hdc
);
1960 layout
= dc
->layout
;
1961 DC_ReleaseDCPtr( dc
);
1964 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1969 /***********************************************************************
1970 * SetLayout (GDI32.@)
1972 * Sets left->right or right->left text layout flags of a dc.
1975 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1977 DWORD oldlayout
= GDI_ERROR
;
1979 DC
* dc
= DC_GetDCPtr( hdc
);
1982 oldlayout
= dc
->layout
;
1983 dc
->layout
= layout
;
1984 DC_ReleaseDCPtr( dc
);
1987 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1992 /***********************************************************************
1993 * GetDCBrushColor (GDI32.@)
1995 * Retrieves the current brush color for the specified device
1999 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
2002 COLORREF dcBrushColor
= CLR_INVALID
;
2004 TRACE("hdc(%p)\n", hdc
);
2006 dc
= DC_GetDCPtr( hdc
);
2009 dcBrushColor
= dc
->dcBrushColor
;
2010 DC_ReleaseDCPtr( dc
);
2013 return dcBrushColor
;
2016 /***********************************************************************
2017 * SetDCBrushColor (GDI32.@)
2019 * Sets the current device context (DC) brush color to the specified
2020 * color value. If the device cannot represent the specified color
2021 * value, the color is set to the nearest physical color.
2024 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
2027 COLORREF oldClr
= CLR_INVALID
;
2029 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2031 dc
= DC_GetDCPtr( hdc
);
2034 if (dc
->funcs
->pSetDCBrushColor
)
2035 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
2036 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
2038 /* If DC_BRUSH is selected, update driver pen color */
2039 HBRUSH hBrush
= CreateSolidBrush( crColor
);
2040 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
2041 DeleteObject( hBrush
);
2044 if (crColor
!= CLR_INVALID
)
2046 oldClr
= dc
->dcBrushColor
;
2047 dc
->dcBrushColor
= crColor
;
2050 DC_ReleaseDCPtr( dc
);
2056 /***********************************************************************
2057 * GetDCPenColor (GDI32.@)
2059 * Retrieves the current pen color for the specified device
2063 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
2066 COLORREF dcPenColor
= CLR_INVALID
;
2068 TRACE("hdc(%p)\n", hdc
);
2070 dc
= DC_GetDCPtr( hdc
);
2073 dcPenColor
= dc
->dcPenColor
;
2074 DC_ReleaseDCPtr( dc
);
2080 /***********************************************************************
2081 * SetDCPenColor (GDI32.@)
2083 * Sets the current device context (DC) pen color to the specified
2084 * color value. If the device cannot represent the specified color
2085 * value, the color is set to the nearest physical color.
2088 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2091 COLORREF oldClr
= CLR_INVALID
;
2093 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2095 dc
= DC_GetDCPtr( hdc
);
2098 if (dc
->funcs
->pSetDCPenColor
)
2099 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2100 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2102 /* If DC_PEN is selected, update the driver pen color */
2103 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2104 HPEN hPen
= CreatePenIndirect( &logpen
);
2105 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2106 DeleteObject( hPen
);
2109 if (crColor
!= CLR_INVALID
)
2111 oldClr
= dc
->dcPenColor
;
2112 dc
->dcPenColor
= crColor
;
2115 DC_ReleaseDCPtr( dc
);
2121 /***********************************************************************
2122 * CancelDC (GDI32.@)
2124 BOOL WINAPI
CancelDC(HDC hdc
)
2130 /***********************************************************************
2131 * SetVirtualResolution (GDI32.@)
2133 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2135 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2137 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);
2141 /*******************************************************************
2142 * GetMiterLimit [GDI32.@]
2146 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2151 TRACE("(%p,%p)\n", hdc
, peLimit
);
2153 dc
= DC_GetDCPtr( hdc
);
2157 *peLimit
= dc
->miterLimit
;
2159 DC_ReleaseDCPtr( dc
);
2165 /*******************************************************************
2166 * SetMiterLimit [GDI32.@]
2170 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2175 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2177 dc
= DC_GetDCPtr( hdc
);
2181 *peOldLimit
= dc
->miterLimit
;
2182 dc
->miterLimit
= eNewLimit
;
2183 DC_ReleaseDCPtr( dc
);
2189 /*******************************************************************
2190 * GdiIsMetaPrintDC [GDI32.@]
2192 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2198 /*******************************************************************
2199 * GdiIsMetaFileDC [GDI32.@]
2201 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2205 switch( GetObjectType( hdc
) )
2214 /*******************************************************************
2215 * GdiIsPlayMetafileDC [GDI32.@]
2217 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)