2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
14 #include "debugtools.h"
20 #include "wine/winuser16.h"
22 DEFAULT_DEBUG_CHANNEL(dc
);
25 /***********************************************************************
28 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
33 if (!(dc
= GDI_AllocObject( sizeof(*dc
), DC_MAGIC
, &hdc
))) return NULL
;
55 dc
->hPen
= GetStockObject( BLACK_PEN
);
56 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
57 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
60 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
61 dc
->ROPmode
= R2_COPYPEN
;
62 dc
->polyFillMode
= ALTERNATE
;
63 dc
->stretchBltMode
= BLACKONWHITE
;
64 dc
->relAbsMode
= ABSOLUTE
;
65 dc
->backgroundMode
= OPAQUE
;
66 dc
->backgroundColor
= RGB( 255, 255, 255 );
67 dc
->textColor
= RGB( 0, 0, 0 );
70 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
72 dc
->breakTotalExtra
= 0;
76 dc
->totalExtent
.left
= 0;
77 dc
->totalExtent
.top
= 0;
78 dc
->totalExtent
.right
= 0;
79 dc
->totalExtent
.bottom
= 0;
81 dc
->MapMode
= MM_TEXT
;
82 dc
->GraphicsMode
= GM_COMPATIBLE
;
85 dc
->pAbortProc
= NULL
;
88 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
89 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
90 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
91 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
92 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
93 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
94 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
95 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
96 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
97 dc
->vport2WorldValid
= TRUE
;
98 PATH_InitGdiPath(&dc
->path
);
104 /***********************************************************************
107 DC
*DC_GetDCPtr( HDC hdc
)
109 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
110 if (!ptr
) return NULL
;
111 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
112 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
113 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
115 GDI_ReleaseObj( hdc
);
116 SetLastError( ERROR_INVALID_HANDLE
);
120 /***********************************************************************
123 * Retrieve a DC ptr while making sure the visRgn is updated.
124 * This function may call up to USER so the GDI lock should _not_
125 * be held when calling it.
127 DC
*DC_GetDCUpdate( HDC hdc
)
129 DC
*dc
= DC_GetDCPtr( hdc
);
130 if (!dc
) return NULL
;
131 while (dc
->flags
& DC_DIRTY
)
133 dc
->flags
&= ~DC_DIRTY
;
134 if (!(dc
->flags
& (DC_SAVED
| DC_MEMORY
)))
136 DCHOOKPROC proc
= dc
->hookThunk
;
139 DWORD data
= dc
->dwHookData
;
140 GDI_ReleaseObj( hdc
);
141 proc( hdc
, DCHC_INVALIDVISRGN
, data
, 0 );
142 if (!(dc
= DC_GetDCPtr( hdc
))) break;
143 /* otherwise restart the loop in case it became dirty again in the meantime */
150 /***********************************************************************
153 * Setup device-specific DC values for a newly created DC.
155 void DC_InitDC( DC
* dc
)
157 RealizeDefaultPalette16( dc
->hSelf
);
158 SetTextColor( dc
->hSelf
, dc
->textColor
);
159 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
160 SelectObject( dc
->hSelf
, dc
->hPen
);
161 SelectObject( dc
->hSelf
, dc
->hBrush
);
162 SelectObject( dc
->hSelf
, dc
->hFont
);
163 CLIPPING_UpdateGCRegion( dc
);
167 /***********************************************************************
170 * Computes the inverse of the transformation xformSrc and stores it to
171 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
174 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
178 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
179 xformSrc
->eM12
*xformSrc
->eM21
;
180 if (determinant
> -1e-12 && determinant
< 1e-12)
183 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
184 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
185 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
186 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
187 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
188 xformSrc
->eDy
* xformDest
->eM21
;
189 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
190 xformSrc
->eDy
* xformDest
->eM22
;
196 /***********************************************************************
199 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
200 * fields of the specified DC by creating a transformation that
201 * represents the current mapping mode and combining it with the DC's
202 * world transform. This function should be called whenever the
203 * parameters associated with the mapping mode (window and viewport
204 * extents and origins) or the world transform change.
206 void DC_UpdateXforms( DC
*dc
)
208 XFORM xformWnd2Vport
;
209 FLOAT scaleX
, scaleY
;
211 /* Construct a transformation to do the window-to-viewport conversion */
212 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
213 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
214 xformWnd2Vport
.eM11
= scaleX
;
215 xformWnd2Vport
.eM12
= 0.0;
216 xformWnd2Vport
.eM21
= 0.0;
217 xformWnd2Vport
.eM22
= scaleY
;
218 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
219 scaleX
* (FLOAT
)dc
->wndOrgX
;
220 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
221 scaleY
* (FLOAT
)dc
->wndOrgY
;
223 /* Combine with the world transformation */
224 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
227 /* Create inverse of world-to-viewport transformation */
228 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
229 &dc
->xformVport2World
);
233 /***********************************************************************
234 * GetDCState (GDI.179)
236 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
241 if (!(dc
= DC_GetDCUpdate( hdc
))) return 0;
242 if (!(newdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
, &handle
)))
244 GDI_ReleaseObj( hdc
);
247 TRACE("(%04x): returning %04x\n", hdc
, handle
);
249 newdc
->flags
= dc
->flags
| DC_SAVED
;
250 newdc
->devCaps
= dc
->devCaps
;
251 newdc
->hPen
= dc
->hPen
;
252 newdc
->hBrush
= dc
->hBrush
;
253 newdc
->hFont
= dc
->hFont
;
254 newdc
->hBitmap
= dc
->hBitmap
;
255 newdc
->hDevice
= dc
->hDevice
;
256 newdc
->hPalette
= dc
->hPalette
;
257 newdc
->totalExtent
= dc
->totalExtent
;
258 newdc
->bitsPerPixel
= dc
->bitsPerPixel
;
259 newdc
->ROPmode
= dc
->ROPmode
;
260 newdc
->polyFillMode
= dc
->polyFillMode
;
261 newdc
->stretchBltMode
= dc
->stretchBltMode
;
262 newdc
->relAbsMode
= dc
->relAbsMode
;
263 newdc
->backgroundMode
= dc
->backgroundMode
;
264 newdc
->backgroundColor
= dc
->backgroundColor
;
265 newdc
->textColor
= dc
->textColor
;
266 newdc
->brushOrgX
= dc
->brushOrgX
;
267 newdc
->brushOrgY
= dc
->brushOrgY
;
268 newdc
->textAlign
= dc
->textAlign
;
269 newdc
->charExtra
= dc
->charExtra
;
270 newdc
->breakTotalExtra
= dc
->breakTotalExtra
;
271 newdc
->breakCount
= dc
->breakCount
;
272 newdc
->breakExtra
= dc
->breakExtra
;
273 newdc
->breakRem
= dc
->breakRem
;
274 newdc
->MapMode
= dc
->MapMode
;
275 newdc
->GraphicsMode
= dc
->GraphicsMode
;
277 /* Apparently, the DC origin is not changed by [GS]etDCState */
278 newdc
->DCOrgX
= dc
->DCOrgX
;
279 newdc
->DCOrgY
= dc
->DCOrgY
;
281 newdc
->CursPosX
= dc
->CursPosX
;
282 newdc
->CursPosY
= dc
->CursPosY
;
283 newdc
->ArcDirection
= dc
->ArcDirection
;
284 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
285 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
286 newdc
->xformVport2World
= dc
->xformVport2World
;
287 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
288 newdc
->wndOrgX
= dc
->wndOrgX
;
289 newdc
->wndOrgY
= dc
->wndOrgY
;
290 newdc
->wndExtX
= dc
->wndExtX
;
291 newdc
->wndExtY
= dc
->wndExtY
;
292 newdc
->vportOrgX
= dc
->vportOrgX
;
293 newdc
->vportOrgY
= dc
->vportOrgY
;
294 newdc
->vportExtX
= dc
->vportExtX
;
295 newdc
->vportExtY
= dc
->vportExtY
;
297 newdc
->hSelf
= (HDC
)handle
;
298 newdc
->saveLevel
= 0;
300 PATH_InitGdiPath( &newdc
->path
);
302 newdc
->pAbortProc
= NULL
;
303 newdc
->hookThunk
= NULL
;
306 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
308 newdc
->hGCClipRgn
= newdc
->hVisRgn
= 0;
311 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
312 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
316 GDI_ReleaseObj( handle
);
317 GDI_ReleaseObj( hdc
);
322 /***********************************************************************
323 * SetDCState (GDI.180)
325 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
329 if (!(dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
330 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
332 GDI_ReleaseObj( hdc
);
335 if (!dcs
->flags
& DC_SAVED
)
337 GDI_ReleaseObj( hdc
);
338 GDI_ReleaseObj( hdcs
);
341 TRACE("%04x %04x\n", hdc
, hdcs
);
343 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
344 dc
->devCaps
= dcs
->devCaps
;
345 dc
->hDevice
= dcs
->hDevice
;
346 dc
->totalExtent
= dcs
->totalExtent
;
347 dc
->ROPmode
= dcs
->ROPmode
;
348 dc
->polyFillMode
= dcs
->polyFillMode
;
349 dc
->stretchBltMode
= dcs
->stretchBltMode
;
350 dc
->relAbsMode
= dcs
->relAbsMode
;
351 dc
->backgroundMode
= dcs
->backgroundMode
;
352 dc
->backgroundColor
= dcs
->backgroundColor
;
353 dc
->textColor
= dcs
->textColor
;
354 dc
->brushOrgX
= dcs
->brushOrgX
;
355 dc
->brushOrgY
= dcs
->brushOrgY
;
356 dc
->textAlign
= dcs
->textAlign
;
357 dc
->charExtra
= dcs
->charExtra
;
358 dc
->breakTotalExtra
= dcs
->breakTotalExtra
;
359 dc
->breakCount
= dcs
->breakCount
;
360 dc
->breakExtra
= dcs
->breakExtra
;
361 dc
->breakRem
= dcs
->breakRem
;
362 dc
->MapMode
= dcs
->MapMode
;
363 dc
->GraphicsMode
= dcs
->GraphicsMode
;
365 /* Apparently, the DC origin is not changed by [GS]etDCState */
366 dc
->DCOrgX
= dcs
->DCOrgX
;
367 dc
->DCOrgY
= dcs
->DCOrgY
;
369 dc
->CursPosX
= dcs
->CursPosX
;
370 dc
->CursPosY
= dcs
->CursPosY
;
371 dc
->ArcDirection
= dcs
->ArcDirection
;
372 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
373 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
374 dc
->xformVport2World
= dcs
->xformVport2World
;
375 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
377 dc
->wndOrgX
= dcs
->wndOrgX
;
378 dc
->wndOrgY
= dcs
->wndOrgY
;
379 dc
->wndExtX
= dcs
->wndExtX
;
380 dc
->wndExtY
= dcs
->wndExtY
;
381 dc
->vportOrgX
= dcs
->vportOrgX
;
382 dc
->vportOrgY
= dcs
->vportOrgY
;
383 dc
->vportExtX
= dcs
->vportExtX
;
384 dc
->vportExtY
= dcs
->vportExtY
;
386 if (!(dc
->flags
& DC_MEMORY
)) dc
->bitsPerPixel
= dcs
->bitsPerPixel
;
390 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
391 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
395 if (dc
->hClipRgn
) DeleteObject16( dc
->hClipRgn
);
398 CLIPPING_UpdateGCRegion( dc
);
400 SelectObject( hdc
, dcs
->hBitmap
);
401 SelectObject( hdc
, dcs
->hBrush
);
402 SelectObject( hdc
, dcs
->hFont
);
403 SelectObject( hdc
, dcs
->hPen
);
404 SetBkColor( hdc
, dcs
->backgroundColor
);
405 SetTextColor( hdc
, dcs
->textColor
);
406 GDISelectPalette16( hdc
, dcs
->hPalette
, FALSE
);
407 GDI_ReleaseObj( hdcs
);
408 GDI_ReleaseObj( hdc
);
412 /***********************************************************************
415 INT16 WINAPI
SaveDC16( HDC16 hdc
)
417 return (INT16
)SaveDC( hdc
);
421 /***********************************************************************
424 INT WINAPI
SaveDC( HDC hdc
)
430 dc
= DC_GetDCUpdate( hdc
);
433 if(dc
->funcs
->pSaveDC
)
435 ret
= dc
->funcs
->pSaveDC( dc
);
436 GDI_ReleaseObj( hdc
);
440 if (!(hdcs
= GetDCState16( hdc
)))
442 GDI_ReleaseObj( hdc
);
445 dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
);
447 /* Copy path. The reason why path saving / restoring is in SaveDC/
448 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
449 * functions are only in Win16 (which doesn't have paths) and that
450 * SetDCState doesn't allow us to signal an error (which can happen
451 * when copying paths).
453 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
455 GDI_ReleaseObj( hdc
);
456 GDI_ReleaseObj( hdcs
);
461 dcs
->header
.hNext
= dc
->header
.hNext
;
462 dc
->header
.hNext
= hdcs
;
463 TRACE("(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
464 ret
= ++dc
->saveLevel
;
465 GDI_ReleaseObj( hdcs
);
466 GDI_ReleaseObj( hdc
);
471 /***********************************************************************
472 * RestoreDC16 (GDI.39)
474 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
476 return RestoreDC( hdc
, level
);
480 /***********************************************************************
481 * RestoreDC (GDI32.290)
483 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
488 TRACE("%04x %d\n", hdc
, level
);
489 dc
= DC_GetDCPtr( hdc
);
490 if(!dc
) return FALSE
;
491 if(dc
->funcs
->pRestoreDC
)
493 success
= dc
->funcs
->pRestoreDC( dc
, level
);
494 GDI_ReleaseObj( hdc
);
498 if (level
== -1) level
= dc
->saveLevel
;
500 /* This pair of checks disagrees with MSDN "Platform SDK:
501 Windows GDI" July 2000 which says all negative values
502 for level will be interpreted as an instance relative
503 to the current state. Restricting it to just -1 does
505 || (level
> dc
->saveLevel
))
507 GDI_ReleaseObj( hdc
);
512 while (dc
->saveLevel
>= level
)
514 HDC16 hdcs
= dc
->header
.hNext
;
515 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
517 GDI_ReleaseObj( hdc
);
520 dc
->header
.hNext
= dcs
->header
.hNext
;
521 if (--dc
->saveLevel
< level
)
523 SetDCState16( hdc
, hdcs
);
524 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
525 /* FIXME: This might not be quite right, since we're
526 * returning FALSE but still destroying the saved DC state */
529 GDI_ReleaseObj( hdcs
);
532 GDI_ReleaseObj( hdc
);
537 /***********************************************************************
538 * CreateDC16 (GDI.53)
540 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
541 const DEVMODEA
*initData
)
545 const DC_FUNCTIONS
*funcs
;
548 if (!device
|| !DRIVER_GetDriverName( device
, buf
, sizeof(buf
) ))
551 if (!(funcs
= DRIVER_FindDriver( buf
))) return 0;
552 if (!(dc
= DC_AllocDC( funcs
))) return 0;
555 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
556 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
558 if (dc
->funcs
->pCreateDC
&&
559 !dc
->funcs
->pCreateDC( dc
, buf
, device
, output
, initData
))
561 WARN("creation aborted by device\n" );
562 GDI_FreeObject( dc
->hSelf
, dc
);
568 GDI_ReleaseObj( hdc
);
573 /***********************************************************************
576 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
577 const DEVMODEA
*initData
)
579 return CreateDC16( driver
, device
, output
, (const DEVMODEA
*)initData
);
583 /***********************************************************************
586 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
587 const DEVMODEW
*initData
)
589 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
590 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
591 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
592 HDC res
= CreateDC16( driverA
, deviceA
, outputA
,
593 (const DEVMODEA
*)initData
/*FIXME*/ );
594 HeapFree( GetProcessHeap(), 0, driverA
);
595 HeapFree( GetProcessHeap(), 0, deviceA
);
596 HeapFree( GetProcessHeap(), 0, outputA
);
601 /***********************************************************************
602 * CreateIC16 (GDI.153)
604 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
605 const DEVMODEA
* initData
)
607 /* Nothing special yet for ICs */
608 return CreateDC16( driver
, device
, output
, initData
);
612 /***********************************************************************
613 * CreateICA (GDI32.49)
615 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
616 const DEVMODEA
* initData
)
618 /* Nothing special yet for ICs */
619 return CreateDCA( driver
, device
, output
, initData
);
623 /***********************************************************************
624 * CreateICW (GDI32.50)
626 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
627 const DEVMODEW
* initData
)
629 /* Nothing special yet for ICs */
630 return CreateDCW( driver
, device
, output
, initData
);
634 /***********************************************************************
635 * CreateCompatibleDC16 (GDI.52)
637 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
639 return (HDC16
)CreateCompatibleDC( hdc
);
643 /***********************************************************************
644 * CreateCompatibleDC (GDI32.31)
646 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
649 const DC_FUNCTIONS
*funcs
;
651 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) funcs
= origDC
->funcs
;
652 else funcs
= DRIVER_FindDriver( "DISPLAY" );
654 if (!funcs
|| !(dc
= DC_AllocDC( funcs
)))
656 if (origDC
) GDI_ReleaseObj( hdc
);
660 TRACE("(%04x): returning %04x\n",
663 dc
->flags
= DC_MEMORY
;
664 dc
->bitsPerPixel
= 1;
665 dc
->hBitmap
= hPseudoStockBitmap
;
667 /* Copy the driver-specific physical device info into
668 * the new DC. The driver may use this read-only info
669 * while creating the compatible DC below. */
671 dc
->physDev
= origDC
->physDev
;
673 if (dc
->funcs
->pCreateDC
&&
674 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
676 WARN("creation aborted by device\n");
677 GDI_FreeObject( dc
->hSelf
, dc
);
678 if (origDC
) GDI_ReleaseObj( hdc
);
683 GDI_ReleaseObj( dc
->hSelf
);
684 if (origDC
) GDI_ReleaseObj( hdc
);
689 /***********************************************************************
690 * DeleteDC16 (GDI.68)
692 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
694 return DeleteDC( hdc
);
698 /***********************************************************************
699 * DeleteDC (GDI32.67)
701 BOOL WINAPI
DeleteDC( HDC hdc
)
703 DC
* dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
);
704 if (!dc
) return FALSE
;
706 TRACE("%04x\n", hdc
);
708 /* Call hook procedure to check whether is it OK to delete this DC */
709 if (dc
->hookThunk
&& !(dc
->flags
& (DC_SAVED
| DC_MEMORY
)))
711 DCHOOKPROC proc
= dc
->hookThunk
;
714 DWORD data
= dc
->dwHookData
;
715 GDI_ReleaseObj( hdc
);
716 if (!proc( hdc
, DCHC_DELETEDC
, data
, 0 )) return FALSE
;
717 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
721 while (dc
->saveLevel
)
724 HDC16 hdcs
= dc
->header
.hNext
;
725 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
726 dc
->header
.hNext
= dcs
->header
.hNext
;
728 GDI_ReleaseObj( hdcs
);
732 if (!(dc
->flags
& DC_SAVED
))
734 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
735 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
736 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
737 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
740 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
741 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
742 if (dc
->hGCClipRgn
) DeleteObject( dc
->hGCClipRgn
);
743 if (dc
->pAbortProc
) THUNK_Free( (FARPROC
)dc
->pAbortProc
);
744 if (dc
->hookThunk
) THUNK_Free( (FARPROC
)dc
->hookThunk
);
745 PATH_DestroyGdiPath(&dc
->path
);
747 return GDI_FreeObject( hdc
, dc
);
751 /***********************************************************************
752 * ResetDC16 (GDI.376)
754 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODEA
*devmode
)
761 /***********************************************************************
762 * ResetDCA (GDI32.287)
764 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
771 /***********************************************************************
772 * ResetDCW (GDI32.288)
774 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
781 /***********************************************************************
782 * GetDeviceCaps16 (GDI.80)
784 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
786 INT16 ret
= GetDeviceCaps( hdc
, cap
);
787 /* some apps don't expect -1 and think it's a B&W screen */
788 if ((cap
== NUMCOLORS
) && (ret
== -1)) ret
= 2048;
793 /***********************************************************************
794 * GetDeviceCaps (GDI32.171)
796 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
802 /* Device capabilities for the printer */
806 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0) ret
= pt
.x
;
809 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0) ret
= pt
.y
;
811 case PHYSICALOFFSETX
:
812 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0) ret
= pt
.x
;
814 case PHYSICALOFFSETY
:
815 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0) ret
= pt
.y
;
818 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0) ret
= pt
.x
;
821 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0) ret
= pt
.y
;
824 FIXME("(%04x,%d): DeviceCaps param CAPS1 is UNIMPLEMENTED, will yield 0!\n",
827 /* please see wingdi.h for the possible bit-flag values that need
831 http://msdn.microsoft.com/library/ddkdoc/win95ddk/graphcnt_1m0p.htm
833 the fall-through to 'default' is on purpose */
837 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
))) break;
839 if (((cap
>=46) && (cap
<88)) || ((cap
>=92) && (cap
<104)))
840 FIXME("(%04x,%d): unsupported DeviceCaps capability, will yield 0!\n",
842 if ((dc
= DC_GetDCPtr( hdc
)))
844 ret
= *(WORD
*)(((char *)dc
->devCaps
) + cap
);
845 GDI_ReleaseObj( hdc
);
846 if ((cap
== NUMCOLORS
) && (ret
== 0xffff)) ret
= -1;
851 TRACE("(%04x,%d): returning %d\n", hdc
, cap
, ret
);
856 /***********************************************************************
857 * SetBkColor16 (GDI.1)
859 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
861 return SetBkColor( hdc
, color
);
865 /***********************************************************************
866 * SetBkColor (GDI32.305)
868 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
871 DC
* dc
= DC_GetDCPtr( hdc
);
873 if (!dc
) return 0x80000000;
874 if (dc
->funcs
->pSetBkColor
)
875 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
877 oldColor
= dc
->backgroundColor
;
878 dc
->backgroundColor
= color
;
880 GDI_ReleaseObj( hdc
);
885 /***********************************************************************
886 * SetTextColor16 (GDI.9)
888 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
890 return SetTextColor( hdc
, color
);
894 /***********************************************************************
895 * SetTextColor (GDI32.338)
897 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
900 DC
* dc
= DC_GetDCPtr( hdc
);
902 if (!dc
) return 0x80000000;
903 if (dc
->funcs
->pSetTextColor
)
904 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
906 oldColor
= dc
->textColor
;
907 dc
->textColor
= color
;
909 GDI_ReleaseObj( hdc
);
913 /***********************************************************************
914 * SetTextAlign16 (GDI.346)
916 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 align
)
918 return SetTextAlign( hdc
, align
);
922 /***********************************************************************
923 * SetTextAlign (GDI32.336)
925 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
928 DC
*dc
= DC_GetDCPtr( hdc
);
930 if (dc
->funcs
->pSetTextAlign
)
931 prevAlign
= dc
->funcs
->pSetTextAlign(dc
, align
);
933 prevAlign
= dc
->textAlign
;
934 dc
->textAlign
= align
;
936 GDI_ReleaseObj( hdc
);
940 /***********************************************************************
941 * GetDCOrgEx (GDI32.168)
943 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
947 if (!lpp
) return FALSE
;
948 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
951 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
, lpp
);
952 lpp
->x
+= dc
->DCOrgX
;
953 lpp
->y
+= dc
->DCOrgY
;
954 GDI_ReleaseObj( hDC
);
959 /***********************************************************************
962 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
965 if( GetDCOrgEx( hdc
, &pt
) )
966 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
971 /***********************************************************************
974 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
977 DC
*dc
= DC_GetDCPtr( hdc
);
979 prevOrg
= dc
->DCOrgX
| (dc
->DCOrgY
<< 16);
982 GDI_ReleaseObj( hdc
);
987 /***********************************************************************
988 * SetGraphicsMode (GDI32.317)
990 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
993 DC
*dc
= DC_GetDCPtr( hdc
);
995 /* One would think that setting the graphics mode to GM_COMPATIBLE
996 * would also reset the world transformation matrix to the unity
997 * matrix. However, in Windows, this is not the case. This doesn't
998 * make a lot of sense to me, but that's the way it is.
1001 if ((mode
> 0) || (mode
<= GM_LAST
))
1003 ret
= dc
->GraphicsMode
;
1004 dc
->GraphicsMode
= mode
;
1006 GDI_ReleaseObj( hdc
);
1011 /***********************************************************************
1012 * SetArcDirection16 (GDI.525)
1014 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
1016 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
1020 /***********************************************************************
1021 * SetArcDirection (GDI32.302)
1023 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1026 INT nOldDirection
= 0;
1028 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1030 SetLastError(ERROR_INVALID_PARAMETER
);
1034 if ((dc
= DC_GetDCPtr( hdc
)))
1036 nOldDirection
= dc
->ArcDirection
;
1037 dc
->ArcDirection
= nDirection
;
1038 GDI_ReleaseObj( hdc
);
1040 return nOldDirection
;
1044 /***********************************************************************
1045 * GetWorldTransform (GDI32.244)
1047 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1050 if (!xform
) return FALSE
;
1051 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1052 *xform
= dc
->xformWorld2Wnd
;
1053 GDI_ReleaseObj( hdc
);
1058 /***********************************************************************
1059 * SetWorldTransform (GDI32.346)
1061 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1064 DC
*dc
= DC_GetDCPtr( hdc
);
1066 if (!dc
) return FALSE
;
1067 if (!xform
) goto done
;
1069 /* Check that graphics mode is GM_ADVANCED */
1070 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1072 dc
->xformWorld2Wnd
= *xform
;
1073 DC_UpdateXforms( dc
);
1076 GDI_ReleaseObj( hdc
);
1081 /****************************************************************************
1082 * ModifyWorldTransform [GDI32.253]
1083 * Modifies the world transformation for a device context.
1086 * hdc [I] Handle to device context
1087 * xform [I] XFORM structure that will be used to modify the world
1089 * iMode [I] Specifies in what way to modify the world transformation
1092 * Resets the world transformation to the identity matrix.
1093 * The parameter xform is ignored.
1095 * Multiplies xform into the world transformation matrix from
1098 * Multiplies xform into the world transformation matrix from
1103 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1107 DC
*dc
= DC_GetDCPtr( hdc
);
1109 /* Check for illegal parameters */
1110 if (!dc
) return FALSE
;
1111 if (!xform
) goto done
;
1113 /* Check that graphics mode is GM_ADVANCED */
1114 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1119 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1120 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1121 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1122 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1123 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1124 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1126 case MWT_LEFTMULTIPLY
:
1127 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1128 &dc
->xformWorld2Wnd
);
1130 case MWT_RIGHTMULTIPLY
:
1131 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1138 DC_UpdateXforms( dc
);
1141 GDI_ReleaseObj( hdc
);
1146 /****************************************************************************
1147 * CombineTransform [GDI32.20]
1148 * Combines two transformation matrices.
1151 * xformResult [O] Stores the result of combining the two matrices
1152 * xform1 [I] Specifies the first matrix to apply
1153 * xform2 [I] Specifies the second matrix to apply
1156 * The same matrix can be passed in for more than one of the parameters.
1160 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1161 const XFORM
*xform2
)
1165 /* Check for illegal parameters */
1166 if (!xformResult
|| !xform1
|| !xform2
)
1169 /* Create the result in a temporary XFORM, since xformResult may be
1170 * equal to xform1 or xform2 */
1171 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1172 xform1
->eM12
* xform2
->eM21
;
1173 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1174 xform1
->eM12
* xform2
->eM22
;
1175 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1176 xform1
->eM22
* xform2
->eM21
;
1177 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1178 xform1
->eM22
* xform2
->eM22
;
1179 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1180 xform1
->eDy
* xform2
->eM21
+
1182 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1183 xform1
->eDy
* xform2
->eM22
+
1186 /* Copy the result to xformResult */
1187 *xformResult
= xformTemp
;
1193 /***********************************************************************
1194 * SetDCHook (GDI.190)
1197 /* ### start build ### */
1198 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
1199 /* ### stop build ### */
1201 /**********************************************************************/
1203 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1205 DC
*dc
= DC_GetDCPtr( hdc
);
1206 if (!dc
) return FALSE
;
1209 * Note: We store the original SEGPTR 'hookProc' as we need to be
1210 * able to return it verbatim in GetDCHook,
1212 * On the other hand, we still call THUNK_Alloc and store the
1213 * 32-bit thunk into another DC member, because THUNK_Alloc
1214 * recognizes the (typical) case that the 'hookProc' is indeed
1215 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1217 * We could perform that test every time the hook is about to
1218 * be called (or else we could live with the 32->16->32 detour),
1219 * but this way is the most efficient ...
1222 dc
->hookProc
= hookProc
;
1223 dc
->dwHookData
= dwHookData
;
1225 THUNK_Free( (FARPROC
)dc
->hookThunk
);
1226 dc
->hookThunk
= (DCHOOKPROC
)
1227 THUNK_Alloc( hookProc
, (RELAY
)GDI_CallTo16_word_wwll
);
1229 GDI_ReleaseObj( hdc
);
1234 /***********************************************************************
1235 * GetDCHook (GDI.191)
1237 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1239 DC
*dc
= DC_GetDCPtr( hdc
);
1241 *phookProc
= dc
->hookProc
;
1242 GDI_ReleaseObj( hdc
);
1243 return dc
->dwHookData
;
1247 /***********************************************************************
1248 * SetHookFlags (GDI.192)
1250 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1252 DC
*dc
= DC_GetDCPtr( hDC
);
1256 WORD wRet
= dc
->flags
& DC_DIRTY
;
1258 /* "Undocumented Windows" info is slightly confusing.
1261 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1263 if( flags
& DCHF_INVALIDATEVISRGN
)
1264 dc
->flags
|= DC_DIRTY
;
1265 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1266 dc
->flags
&= ~DC_DIRTY
;
1267 GDI_ReleaseObj( hDC
);
1273 /***********************************************************************
1274 * SetICMMode (GDI32.318)
1276 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1278 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1279 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1280 if (iEnableICM
== ICM_ON
) return 0;
1281 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1285 /***********************************************************************
1286 * GetDeviceGammaRamp (GDI32.*)
1288 BOOL WINAPI
GetDeviceGammaRamp(HDC hdc
,LPVOID ptr
) {
1289 FIXME("(%x,%p), empty stub!\n",hdc
,ptr
);
1293 /***********************************************************************
1294 * GetColorSpace (GDI32.165)
1296 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1298 /*FIXME Need to to whatever GetColorSpace actually does */
1302 /***********************************************************************
1303 * CreateColorSpaceA (GDI32.???)
1305 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1311 /***********************************************************************
1312 * CreateColorSpaceW (GDI32.???)
1314 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1320 /***********************************************************************
1321 * DeleteColorSpace (GDI32.???)
1323 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1330 /***********************************************************************
1331 * SetColorSpace (GDI32.???)
1333 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1340 /***********************************************************************
1341 * GetBoundsRect16 (GDI.194)
1343 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1345 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1348 /***********************************************************************
1349 * GetBoundsRect (GDI32.147)
1351 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1353 FIXME("(): stub\n");
1354 return DCB_RESET
; /* bounding rectangle always empty */
1357 /***********************************************************************
1358 * SetBoundsRect16 (GDI.193)
1360 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1362 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1363 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1365 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1368 /***********************************************************************
1369 * SetBoundsRect (GDI32.307)
1371 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1373 FIXME("(): stub\n");
1374 return DCB_DISABLE
; /* bounding rectangle always empty */
1378 /***********************************************************************
1379 * GetRelAbs (GDI32.218)
1381 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1384 DC
*dc
= DC_GetDCPtr( hdc
);
1385 if (dc
) ret
= dc
->relAbsMode
;
1386 GDI_ReleaseObj( hdc
);
1390 /***********************************************************************
1393 * Disables GDI, switches back to text mode.
1394 * We don't have to do anything here,
1395 * just let console support handle everything
1397 void WINAPI
Death16(HDC16 hDC
)
1399 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1402 /***********************************************************************
1403 * Resurrection (GDI.122)
1405 * Restores GDI functionality
1407 void WINAPI
Resurrection16(HDC16 hDC
,
1408 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1410 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1413 /***********************************************************************
1414 * GetLayout (GDI32.321)
1416 * Gets left->right or right->left text layout flags of a dc.
1417 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1420 DWORD WINAPI
GetLayout(HDC hdc
)
1422 FIXME("(%08x): stub\n", hdc
);
1423 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1427 /***********************************************************************
1428 * SetLayout (GDI32.450)
1430 * Sets left->right or right->left text layout flags of a dc.
1431 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1434 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1436 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1437 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);