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.@)
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 /***********************************************************************
574 * CreateDCA (GDI32.@)
576 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
577 const DEVMODEA
*initData
)
579 return CreateDC16( driver
, device
, output
, (const DEVMODEA
*)initData
);
583 /***********************************************************************
584 * CreateDCW (GDI32.@)
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.@)
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.@)
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.@)
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 /***********************************************************************
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 /***********************************************************************
764 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
771 /***********************************************************************
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.@)
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
)))
846 ret
= *(WORD
*)(((char *)dc
->devCaps
) + cap
);
847 if ((cap
== NUMCOLORS
) && (ret
== 0xffff)) ret
= -1;
849 GDI_ReleaseObj( hdc
);
854 TRACE("(%04x,%d): returning %d\n", hdc
, cap
, ret
);
859 /***********************************************************************
860 * SetBkColor16 (GDI.1)
862 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
864 return SetBkColor( hdc
, color
);
868 /***********************************************************************
869 * SetBkColor (GDI32.@)
871 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
874 DC
* dc
= DC_GetDCPtr( hdc
);
876 if (!dc
) return 0x80000000;
877 if (dc
->funcs
->pSetBkColor
)
878 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
880 oldColor
= dc
->backgroundColor
;
881 dc
->backgroundColor
= color
;
883 GDI_ReleaseObj( hdc
);
888 /***********************************************************************
889 * SetTextColor16 (GDI.9)
891 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
893 return SetTextColor( hdc
, color
);
897 /***********************************************************************
898 * SetTextColor (GDI32.@)
900 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
903 DC
* dc
= DC_GetDCPtr( hdc
);
905 if (!dc
) return 0x80000000;
906 if (dc
->funcs
->pSetTextColor
)
907 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
909 oldColor
= dc
->textColor
;
910 dc
->textColor
= color
;
912 GDI_ReleaseObj( hdc
);
916 /***********************************************************************
917 * SetTextAlign16 (GDI.346)
919 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 align
)
921 return SetTextAlign( hdc
, align
);
925 /***********************************************************************
926 * SetTextAlign (GDI32.@)
928 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
931 DC
*dc
= DC_GetDCPtr( hdc
);
933 if (dc
->funcs
->pSetTextAlign
)
934 prevAlign
= dc
->funcs
->pSetTextAlign(dc
, align
);
936 prevAlign
= dc
->textAlign
;
937 dc
->textAlign
= align
;
939 GDI_ReleaseObj( hdc
);
943 /***********************************************************************
944 * GetDCOrgEx (GDI32.@)
946 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
950 if (!lpp
) return FALSE
;
951 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
954 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
, lpp
);
955 lpp
->x
+= dc
->DCOrgX
;
956 lpp
->y
+= dc
->DCOrgY
;
957 GDI_ReleaseObj( hDC
);
962 /***********************************************************************
965 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
968 if( GetDCOrgEx( hdc
, &pt
) )
969 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
974 /***********************************************************************
977 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
980 DC
*dc
= DC_GetDCPtr( hdc
);
982 prevOrg
= dc
->DCOrgX
| (dc
->DCOrgY
<< 16);
985 GDI_ReleaseObj( hdc
);
990 /***********************************************************************
991 * SetGraphicsMode (GDI32.@)
993 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
996 DC
*dc
= DC_GetDCPtr( hdc
);
998 /* One would think that setting the graphics mode to GM_COMPATIBLE
999 * would also reset the world transformation matrix to the unity
1000 * matrix. However, in Windows, this is not the case. This doesn't
1001 * make a lot of sense to me, but that's the way it is.
1004 if ((mode
> 0) || (mode
<= GM_LAST
))
1006 ret
= dc
->GraphicsMode
;
1007 dc
->GraphicsMode
= mode
;
1009 GDI_ReleaseObj( hdc
);
1014 /***********************************************************************
1015 * SetArcDirection16 (GDI.525)
1017 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
1019 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
1023 /***********************************************************************
1024 * SetArcDirection (GDI32.@)
1026 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1029 INT nOldDirection
= 0;
1031 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1033 SetLastError(ERROR_INVALID_PARAMETER
);
1037 if ((dc
= DC_GetDCPtr( hdc
)))
1039 nOldDirection
= dc
->ArcDirection
;
1040 dc
->ArcDirection
= nDirection
;
1041 GDI_ReleaseObj( hdc
);
1043 return nOldDirection
;
1047 /***********************************************************************
1048 * GetWorldTransform (GDI32.@)
1050 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1053 if (!xform
) return FALSE
;
1054 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1055 *xform
= dc
->xformWorld2Wnd
;
1056 GDI_ReleaseObj( hdc
);
1061 /***********************************************************************
1062 * SetWorldTransform (GDI32.@)
1064 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1067 DC
*dc
= DC_GetDCPtr( hdc
);
1069 if (!dc
) return FALSE
;
1070 if (!xform
) goto done
;
1072 /* Check that graphics mode is GM_ADVANCED */
1073 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1075 dc
->xformWorld2Wnd
= *xform
;
1076 DC_UpdateXforms( dc
);
1079 GDI_ReleaseObj( hdc
);
1084 /****************************************************************************
1085 * ModifyWorldTransform [GDI32.@]
1086 * Modifies the world transformation for a device context.
1089 * hdc [I] Handle to device context
1090 * xform [I] XFORM structure that will be used to modify the world
1092 * iMode [I] Specifies in what way to modify the world transformation
1095 * Resets the world transformation to the identity matrix.
1096 * The parameter xform is ignored.
1098 * Multiplies xform into the world transformation matrix from
1101 * Multiplies xform into the world transformation matrix from
1106 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1110 DC
*dc
= DC_GetDCPtr( hdc
);
1112 /* Check for illegal parameters */
1113 if (!dc
) return FALSE
;
1114 if (!xform
) goto done
;
1116 /* Check that graphics mode is GM_ADVANCED */
1117 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1122 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1123 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1124 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1125 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1126 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1127 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1129 case MWT_LEFTMULTIPLY
:
1130 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1131 &dc
->xformWorld2Wnd
);
1133 case MWT_RIGHTMULTIPLY
:
1134 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1141 DC_UpdateXforms( dc
);
1144 GDI_ReleaseObj( hdc
);
1149 /****************************************************************************
1150 * CombineTransform [GDI32.@]
1151 * Combines two transformation matrices.
1154 * xformResult [O] Stores the result of combining the two matrices
1155 * xform1 [I] Specifies the first matrix to apply
1156 * xform2 [I] Specifies the second matrix to apply
1159 * The same matrix can be passed in for more than one of the parameters.
1163 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1164 const XFORM
*xform2
)
1168 /* Check for illegal parameters */
1169 if (!xformResult
|| !xform1
|| !xform2
)
1172 /* Create the result in a temporary XFORM, since xformResult may be
1173 * equal to xform1 or xform2 */
1174 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1175 xform1
->eM12
* xform2
->eM21
;
1176 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1177 xform1
->eM12
* xform2
->eM22
;
1178 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1179 xform1
->eM22
* xform2
->eM21
;
1180 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1181 xform1
->eM22
* xform2
->eM22
;
1182 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1183 xform1
->eDy
* xform2
->eM21
+
1185 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1186 xform1
->eDy
* xform2
->eM22
+
1189 /* Copy the result to xformResult */
1190 *xformResult
= xformTemp
;
1196 /***********************************************************************
1197 * SetDCHook (GDI.190)
1200 /* ### start build ### */
1201 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
1202 /* ### stop build ### */
1204 /**********************************************************************/
1206 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1208 DC
*dc
= DC_GetDCPtr( hdc
);
1209 if (!dc
) return FALSE
;
1212 * Note: We store the original SEGPTR 'hookProc' as we need to be
1213 * able to return it verbatim in GetDCHook,
1215 * On the other hand, we still call THUNK_Alloc and store the
1216 * 32-bit thunk into another DC member, because THUNK_Alloc
1217 * recognizes the (typical) case that the 'hookProc' is indeed
1218 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1220 * We could perform that test every time the hook is about to
1221 * be called (or else we could live with the 32->16->32 detour),
1222 * but this way is the most efficient ...
1225 dc
->hookProc
= hookProc
;
1226 dc
->dwHookData
= dwHookData
;
1228 THUNK_Free( (FARPROC
)dc
->hookThunk
);
1229 dc
->hookThunk
= (DCHOOKPROC
)
1230 THUNK_Alloc( hookProc
, (RELAY
)GDI_CallTo16_word_wwll
);
1232 GDI_ReleaseObj( hdc
);
1237 /***********************************************************************
1238 * GetDCHook (GDI.191)
1240 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1242 DC
*dc
= DC_GetDCPtr( hdc
);
1244 *phookProc
= dc
->hookProc
;
1245 GDI_ReleaseObj( hdc
);
1246 return dc
->dwHookData
;
1250 /***********************************************************************
1251 * SetHookFlags (GDI.192)
1253 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1255 DC
*dc
= DC_GetDCPtr( hDC
);
1259 WORD wRet
= dc
->flags
& DC_DIRTY
;
1261 /* "Undocumented Windows" info is slightly confusing.
1264 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1266 if( flags
& DCHF_INVALIDATEVISRGN
)
1267 dc
->flags
|= DC_DIRTY
;
1268 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1269 dc
->flags
&= ~DC_DIRTY
;
1270 GDI_ReleaseObj( hDC
);
1276 /***********************************************************************
1277 * SetICMMode (GDI32.@)
1279 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1281 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1282 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1283 if (iEnableICM
== ICM_ON
) return 0;
1284 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1288 /***********************************************************************
1289 * GetDeviceGammaRamp (GDI32.@)
1291 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1294 DC
*dc
= DC_GetDCPtr( hDC
);
1298 if (dc
->funcs
->pGetDeviceGammaRamp
)
1299 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
, ptr
);
1300 GDI_ReleaseObj( hDC
);
1305 /***********************************************************************
1306 * SetDeviceGammaRamp (GDI32.@)
1308 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1311 DC
*dc
= DC_GetDCPtr( hDC
);
1315 if (dc
->funcs
->pSetDeviceGammaRamp
)
1316 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
, ptr
);
1317 GDI_ReleaseObj( hDC
);
1322 /***********************************************************************
1323 * GetColorSpace (GDI32.@)
1325 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1327 /*FIXME Need to to whatever GetColorSpace actually does */
1331 /***********************************************************************
1332 * CreateColorSpaceA (GDI32.@)
1334 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1340 /***********************************************************************
1341 * CreateColorSpaceW (GDI32.@)
1343 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1349 /***********************************************************************
1350 * DeleteColorSpace (GDI32.@)
1352 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1359 /***********************************************************************
1360 * SetColorSpace (GDI32.@)
1362 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1369 /***********************************************************************
1370 * GetBoundsRect16 (GDI.194)
1372 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1374 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1377 /***********************************************************************
1378 * GetBoundsRect (GDI32.@)
1380 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1382 FIXME("(): stub\n");
1383 return DCB_RESET
; /* bounding rectangle always empty */
1386 /***********************************************************************
1387 * SetBoundsRect16 (GDI.193)
1389 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1391 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1392 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1394 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1397 /***********************************************************************
1398 * SetBoundsRect (GDI32.@)
1400 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1402 FIXME("(): stub\n");
1403 return DCB_DISABLE
; /* bounding rectangle always empty */
1407 /***********************************************************************
1408 * GetRelAbs (GDI32.@)
1410 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1413 DC
*dc
= DC_GetDCPtr( hdc
);
1414 if (dc
) ret
= dc
->relAbsMode
;
1415 GDI_ReleaseObj( hdc
);
1419 /***********************************************************************
1422 * Disables GDI, switches back to text mode.
1423 * We don't have to do anything here,
1424 * just let console support handle everything
1426 void WINAPI
Death16(HDC16 hDC
)
1428 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1431 /***********************************************************************
1432 * Resurrection (GDI.122)
1434 * Restores GDI functionality
1436 void WINAPI
Resurrection16(HDC16 hDC
,
1437 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1439 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1442 /***********************************************************************
1443 * GetLayout (GDI32.@)
1445 * Gets left->right or right->left text layout flags of a dc.
1446 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1449 DWORD WINAPI
GetLayout(HDC hdc
)
1451 FIXME("(%08x): stub\n", hdc
);
1452 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1456 /***********************************************************************
1457 * SetLayout (GDI32.@)
1459 * Sets left->right or right->left text layout flags of a dc.
1460 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1463 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1465 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1466 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);