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
;
54 dc
->hPen
= GetStockObject( BLACK_PEN
);
55 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
56 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
59 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
->hPen
= dc
->hPen
;
251 newdc
->hBrush
= dc
->hBrush
;
252 newdc
->hFont
= dc
->hFont
;
253 newdc
->hBitmap
= dc
->hBitmap
;
254 newdc
->hDevice
= dc
->hDevice
;
255 newdc
->hPalette
= dc
->hPalette
;
256 newdc
->totalExtent
= dc
->totalExtent
;
257 newdc
->bitsPerPixel
= dc
->bitsPerPixel
;
258 newdc
->ROPmode
= dc
->ROPmode
;
259 newdc
->polyFillMode
= dc
->polyFillMode
;
260 newdc
->stretchBltMode
= dc
->stretchBltMode
;
261 newdc
->relAbsMode
= dc
->relAbsMode
;
262 newdc
->backgroundMode
= dc
->backgroundMode
;
263 newdc
->backgroundColor
= dc
->backgroundColor
;
264 newdc
->textColor
= dc
->textColor
;
265 newdc
->brushOrgX
= dc
->brushOrgX
;
266 newdc
->brushOrgY
= dc
->brushOrgY
;
267 newdc
->textAlign
= dc
->textAlign
;
268 newdc
->charExtra
= dc
->charExtra
;
269 newdc
->breakTotalExtra
= dc
->breakTotalExtra
;
270 newdc
->breakCount
= dc
->breakCount
;
271 newdc
->breakExtra
= dc
->breakExtra
;
272 newdc
->breakRem
= dc
->breakRem
;
273 newdc
->MapMode
= dc
->MapMode
;
274 newdc
->GraphicsMode
= dc
->GraphicsMode
;
276 /* Apparently, the DC origin is not changed by [GS]etDCState */
277 newdc
->DCOrgX
= dc
->DCOrgX
;
278 newdc
->DCOrgY
= dc
->DCOrgY
;
280 newdc
->CursPosX
= dc
->CursPosX
;
281 newdc
->CursPosY
= dc
->CursPosY
;
282 newdc
->ArcDirection
= dc
->ArcDirection
;
283 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
284 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
285 newdc
->xformVport2World
= dc
->xformVport2World
;
286 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
287 newdc
->wndOrgX
= dc
->wndOrgX
;
288 newdc
->wndOrgY
= dc
->wndOrgY
;
289 newdc
->wndExtX
= dc
->wndExtX
;
290 newdc
->wndExtY
= dc
->wndExtY
;
291 newdc
->vportOrgX
= dc
->vportOrgX
;
292 newdc
->vportOrgY
= dc
->vportOrgY
;
293 newdc
->vportExtX
= dc
->vportExtX
;
294 newdc
->vportExtY
= dc
->vportExtY
;
296 newdc
->hSelf
= (HDC
)handle
;
297 newdc
->saveLevel
= 0;
299 PATH_InitGdiPath( &newdc
->path
);
301 newdc
->pAbortProc
= NULL
;
302 newdc
->hookThunk
= NULL
;
305 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
307 newdc
->hGCClipRgn
= newdc
->hVisRgn
= 0;
310 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
311 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
317 WineEngAddRefFont(dc
->gdiFont
);
318 newdc
->gdiFont
= dc
->gdiFont
;
322 GDI_ReleaseObj( handle
);
323 GDI_ReleaseObj( hdc
);
328 /***********************************************************************
329 * SetDCState (GDI.180)
331 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
335 if (!(dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
336 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
338 GDI_ReleaseObj( hdc
);
341 if (!dcs
->flags
& DC_SAVED
)
343 GDI_ReleaseObj( hdc
);
344 GDI_ReleaseObj( hdcs
);
347 TRACE("%04x %04x\n", hdc
, hdcs
);
349 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
350 dc
->hDevice
= dcs
->hDevice
;
351 dc
->totalExtent
= dcs
->totalExtent
;
352 dc
->ROPmode
= dcs
->ROPmode
;
353 dc
->polyFillMode
= dcs
->polyFillMode
;
354 dc
->stretchBltMode
= dcs
->stretchBltMode
;
355 dc
->relAbsMode
= dcs
->relAbsMode
;
356 dc
->backgroundMode
= dcs
->backgroundMode
;
357 dc
->backgroundColor
= dcs
->backgroundColor
;
358 dc
->textColor
= dcs
->textColor
;
359 dc
->brushOrgX
= dcs
->brushOrgX
;
360 dc
->brushOrgY
= dcs
->brushOrgY
;
361 dc
->textAlign
= dcs
->textAlign
;
362 dc
->charExtra
= dcs
->charExtra
;
363 dc
->breakTotalExtra
= dcs
->breakTotalExtra
;
364 dc
->breakCount
= dcs
->breakCount
;
365 dc
->breakExtra
= dcs
->breakExtra
;
366 dc
->breakRem
= dcs
->breakRem
;
367 dc
->MapMode
= dcs
->MapMode
;
368 dc
->GraphicsMode
= dcs
->GraphicsMode
;
370 /* Apparently, the DC origin is not changed by [GS]etDCState */
371 dc
->DCOrgX
= dcs
->DCOrgX
;
372 dc
->DCOrgY
= dcs
->DCOrgY
;
374 dc
->CursPosX
= dcs
->CursPosX
;
375 dc
->CursPosY
= dcs
->CursPosY
;
376 dc
->ArcDirection
= dcs
->ArcDirection
;
377 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
378 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
379 dc
->xformVport2World
= dcs
->xformVport2World
;
380 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
382 dc
->wndOrgX
= dcs
->wndOrgX
;
383 dc
->wndOrgY
= dcs
->wndOrgY
;
384 dc
->wndExtX
= dcs
->wndExtX
;
385 dc
->wndExtY
= dcs
->wndExtY
;
386 dc
->vportOrgX
= dcs
->vportOrgX
;
387 dc
->vportOrgY
= dcs
->vportOrgY
;
388 dc
->vportExtX
= dcs
->vportExtX
;
389 dc
->vportExtY
= dcs
->vportExtY
;
391 if (!(dc
->flags
& DC_MEMORY
)) dc
->bitsPerPixel
= dcs
->bitsPerPixel
;
395 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
396 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
400 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
403 CLIPPING_UpdateGCRegion( dc
);
405 SelectObject( hdc
, dcs
->hBitmap
);
406 SelectObject( hdc
, dcs
->hBrush
);
407 SelectObject( hdc
, dcs
->hFont
);
408 SelectObject( hdc
, dcs
->hPen
);
409 SetBkColor( hdc
, dcs
->backgroundColor
);
410 SetTextColor( hdc
, dcs
->textColor
);
411 GDISelectPalette16( hdc
, dcs
->hPalette
, FALSE
);
412 GDI_ReleaseObj( hdcs
);
413 GDI_ReleaseObj( hdc
);
417 /***********************************************************************
420 INT16 WINAPI
SaveDC16( HDC16 hdc
)
422 return (INT16
)SaveDC( hdc
);
426 /***********************************************************************
429 INT WINAPI
SaveDC( HDC hdc
)
435 dc
= DC_GetDCUpdate( hdc
);
438 if(dc
->funcs
->pSaveDC
)
440 ret
= dc
->funcs
->pSaveDC( dc
);
441 GDI_ReleaseObj( hdc
);
445 if (!(hdcs
= GetDCState16( hdc
)))
447 GDI_ReleaseObj( hdc
);
450 dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
);
452 /* Copy path. The reason why path saving / restoring is in SaveDC/
453 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
454 * functions are only in Win16 (which doesn't have paths) and that
455 * SetDCState doesn't allow us to signal an error (which can happen
456 * when copying paths).
458 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
460 GDI_ReleaseObj( hdc
);
461 GDI_ReleaseObj( hdcs
);
466 dcs
->header
.hNext
= dc
->header
.hNext
;
467 dc
->header
.hNext
= hdcs
;
468 TRACE("(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
469 ret
= ++dc
->saveLevel
;
470 GDI_ReleaseObj( hdcs
);
471 GDI_ReleaseObj( hdc
);
476 /***********************************************************************
479 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
481 return RestoreDC( hdc
, level
);
485 /***********************************************************************
486 * RestoreDC (GDI32.@)
488 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
493 TRACE("%04x %d\n", hdc
, level
);
494 dc
= DC_GetDCPtr( hdc
);
495 if(!dc
) return FALSE
;
496 if(dc
->funcs
->pRestoreDC
)
498 success
= dc
->funcs
->pRestoreDC( dc
, level
);
499 GDI_ReleaseObj( hdc
);
503 if (level
== -1) level
= dc
->saveLevel
;
505 /* This pair of checks disagrees with MSDN "Platform SDK:
506 Windows GDI" July 2000 which says all negative values
507 for level will be interpreted as an instance relative
508 to the current state. Restricting it to just -1 does
510 || (level
> dc
->saveLevel
))
512 GDI_ReleaseObj( hdc
);
517 while (dc
->saveLevel
>= level
)
519 HDC16 hdcs
= dc
->header
.hNext
;
520 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
522 GDI_ReleaseObj( hdc
);
525 dc
->header
.hNext
= dcs
->header
.hNext
;
526 if (--dc
->saveLevel
< level
)
528 SetDCState16( hdc
, hdcs
);
529 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
530 /* FIXME: This might not be quite right, since we're
531 * returning FALSE but still destroying the saved DC state */
534 GDI_ReleaseObj( hdcs
);
535 GDI_ReleaseObj( hdc
);
537 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
539 GDI_ReleaseObj( hdc
);
544 /***********************************************************************
547 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
548 const DEVMODEA
*initData
)
550 return CreateDCA( driver
, device
, output
, initData
);
553 /***********************************************************************
554 * CreateDCA (GDI32.@)
556 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
557 const DEVMODEA
*initData
)
561 const DC_FUNCTIONS
*funcs
;
566 if (!device
|| !DRIVER_GetDriverName( device
, buf
, sizeof(buf
) ))
569 if (!(funcs
= DRIVER_load_driver( buf
)))
571 ERR( "no driver found for %s\n", buf
);
574 if (!(dc
= DC_AllocDC( funcs
)))
576 DRIVER_release_driver( funcs
);
582 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
583 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
585 if (dc
->funcs
->pCreateDC
&&
586 !dc
->funcs
->pCreateDC( dc
, buf
, device
, output
, initData
))
588 WARN("creation aborted by device\n" );
589 GDI_FreeObject( dc
->hSelf
, dc
);
590 DRIVER_release_driver( funcs
);
596 GDI_ReleaseObj( hdc
);
601 /***********************************************************************
602 * CreateDCW (GDI32.@)
604 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
605 const DEVMODEW
*initData
)
607 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
608 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
609 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
610 HDC res
= CreateDCA( driverA
, deviceA
, outputA
,
611 (const DEVMODEA
*)initData
/*FIXME*/ );
612 HeapFree( GetProcessHeap(), 0, driverA
);
613 HeapFree( GetProcessHeap(), 0, deviceA
);
614 HeapFree( GetProcessHeap(), 0, outputA
);
619 /***********************************************************************
622 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
623 const DEVMODEA
* initData
)
625 /* Nothing special yet for ICs */
626 return CreateDC16( driver
, device
, output
, initData
);
630 /***********************************************************************
631 * CreateICA (GDI32.@)
633 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
634 const DEVMODEA
* initData
)
636 /* Nothing special yet for ICs */
637 return CreateDCA( driver
, device
, output
, initData
);
641 /***********************************************************************
642 * CreateICW (GDI32.@)
644 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
645 const DEVMODEW
* initData
)
647 /* Nothing special yet for ICs */
648 return CreateDCW( driver
, device
, output
, initData
);
652 /***********************************************************************
653 * CreateCompatibleDC (GDI.52)
655 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
657 return (HDC16
)CreateCompatibleDC( hdc
);
661 /***********************************************************************
662 * CreateCompatibleDC (GDI32.@)
664 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
667 const DC_FUNCTIONS
*funcs
;
671 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
673 funcs
= origDC
->funcs
;
674 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
675 funcs
= DRIVER_get_driver( funcs
);
677 else funcs
= DRIVER_load_driver( "DISPLAY" );
679 if (!funcs
) return 0;
681 if (!(dc
= DC_AllocDC( funcs
)))
683 DRIVER_release_driver( funcs
);
687 TRACE("(%04x): returning %04x\n",
690 dc
->flags
= DC_MEMORY
;
691 dc
->bitsPerPixel
= 1;
692 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
694 /* Copy the driver-specific physical device info into
695 * the new DC. The driver may use this read-only info
696 * while creating the compatible DC below. */
697 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) dc
->physDev
= origDC
->physDev
;
699 if (dc
->funcs
->pCreateDC
&&
700 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
702 WARN("creation aborted by device\n");
703 GDI_FreeObject( dc
->hSelf
, dc
);
704 if (origDC
) GDI_ReleaseObj( hdc
);
705 DRIVER_release_driver( funcs
);
710 GDI_ReleaseObj( dc
->hSelf
);
711 if (origDC
) GDI_ReleaseObj( hdc
);
716 /***********************************************************************
719 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
721 return DeleteDC( hdc
);
725 /***********************************************************************
728 BOOL WINAPI
DeleteDC( HDC hdc
)
730 const DC_FUNCTIONS
*funcs
= NULL
;
733 TRACE("%04x\n", hdc
);
737 if (!(dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) return FALSE
;
739 /* Call hook procedure to check whether is it OK to delete this DC */
740 if (dc
->hookThunk
&& !(dc
->flags
& (DC_SAVED
| DC_MEMORY
)))
742 DCHOOKPROC proc
= dc
->hookThunk
;
745 DWORD data
= dc
->dwHookData
;
746 GDI_ReleaseObj( hdc
);
747 if (!proc( hdc
, DCHC_DELETEDC
, data
, 0 )) return FALSE
;
748 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
752 while (dc
->saveLevel
)
755 HDC16 hdcs
= dc
->header
.hNext
;
756 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
757 dc
->header
.hNext
= dcs
->header
.hNext
;
759 GDI_ReleaseObj( hdcs
);
763 if (!(dc
->flags
& DC_SAVED
))
765 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
766 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
767 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
768 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
770 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
773 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
774 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
775 if (dc
->hGCClipRgn
) DeleteObject( dc
->hGCClipRgn
);
776 if (dc
->pAbortProc
) THUNK_Free( (FARPROC
)dc
->pAbortProc
);
777 if (dc
->hookThunk
) THUNK_Free( (FARPROC
)dc
->hookThunk
);
778 if (dc
->gdiFont
) WineEngDecRefFont( dc
->gdiFont
);
779 PATH_DestroyGdiPath(&dc
->path
);
781 GDI_FreeObject( hdc
, dc
);
782 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
787 /***********************************************************************
790 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODEA
*devmode
)
797 /***********************************************************************
800 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
807 /***********************************************************************
810 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
817 /***********************************************************************
818 * GetDeviceCaps (GDI.80)
820 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
822 INT16 ret
= GetDeviceCaps( hdc
, cap
);
823 /* some apps don't expect -1 and think it's a B&W screen */
824 if ((cap
== NUMCOLORS
) && (ret
== -1)) ret
= 2048;
829 /***********************************************************************
830 * GetDeviceCaps (GDI32.@)
832 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
837 if ((dc
= DC_GetDCPtr( hdc
)))
839 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
, cap
);
840 GDI_ReleaseObj( hdc
);
846 /***********************************************************************
849 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
851 return SetBkColor( hdc
, color
);
855 /***********************************************************************
856 * SetBkColor (GDI32.@)
858 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
861 DC
* dc
= DC_GetDCPtr( hdc
);
863 if (!dc
) return 0x80000000;
864 if (dc
->funcs
->pSetBkColor
)
865 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
867 oldColor
= dc
->backgroundColor
;
868 dc
->backgroundColor
= color
;
870 GDI_ReleaseObj( hdc
);
875 /***********************************************************************
876 * SetTextColor (GDI.9)
878 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
880 return SetTextColor( hdc
, color
);
884 /***********************************************************************
885 * SetTextColor (GDI32.@)
887 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
890 DC
* dc
= DC_GetDCPtr( hdc
);
892 if (!dc
) return 0x80000000;
893 if (dc
->funcs
->pSetTextColor
)
894 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
896 oldColor
= dc
->textColor
;
897 dc
->textColor
= color
;
899 GDI_ReleaseObj( hdc
);
903 /***********************************************************************
904 * SetTextAlign (GDI.346)
906 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 align
)
908 return SetTextAlign( hdc
, align
);
912 /***********************************************************************
913 * SetTextAlign (GDI32.@)
915 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
918 DC
*dc
= DC_GetDCPtr( hdc
);
920 if (dc
->funcs
->pSetTextAlign
)
921 prevAlign
= dc
->funcs
->pSetTextAlign(dc
, align
);
923 prevAlign
= dc
->textAlign
;
924 dc
->textAlign
= align
;
926 GDI_ReleaseObj( hdc
);
930 /***********************************************************************
931 * GetDCOrgEx (GDI32.@)
933 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
937 if (!lpp
) return FALSE
;
938 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
941 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
, lpp
);
942 lpp
->x
+= dc
->DCOrgX
;
943 lpp
->y
+= dc
->DCOrgY
;
944 GDI_ReleaseObj( hDC
);
949 /***********************************************************************
952 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
955 if( GetDCOrgEx( hdc
, &pt
) )
956 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
961 /***********************************************************************
964 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
967 DC
*dc
= DC_GetDCPtr( hdc
);
969 prevOrg
= dc
->DCOrgX
| (dc
->DCOrgY
<< 16);
972 GDI_ReleaseObj( hdc
);
977 /***********************************************************************
978 * SetGraphicsMode (GDI32.@)
980 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
983 DC
*dc
= DC_GetDCPtr( hdc
);
985 /* One would think that setting the graphics mode to GM_COMPATIBLE
986 * would also reset the world transformation matrix to the unity
987 * matrix. However, in Windows, this is not the case. This doesn't
988 * make a lot of sense to me, but that's the way it is.
991 if ((mode
> 0) || (mode
<= GM_LAST
))
993 ret
= dc
->GraphicsMode
;
994 dc
->GraphicsMode
= mode
;
996 GDI_ReleaseObj( hdc
);
1001 /***********************************************************************
1002 * SetArcDirection (GDI.525)
1004 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
1006 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
1010 /***********************************************************************
1011 * SetArcDirection (GDI32.@)
1013 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1016 INT nOldDirection
= 0;
1018 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1020 SetLastError(ERROR_INVALID_PARAMETER
);
1024 if ((dc
= DC_GetDCPtr( hdc
)))
1026 nOldDirection
= dc
->ArcDirection
;
1027 dc
->ArcDirection
= nDirection
;
1028 GDI_ReleaseObj( hdc
);
1030 return nOldDirection
;
1034 /***********************************************************************
1035 * GetWorldTransform (GDI32.@)
1037 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1040 if (!xform
) return FALSE
;
1041 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1042 *xform
= dc
->xformWorld2Wnd
;
1043 GDI_ReleaseObj( hdc
);
1048 /***********************************************************************
1049 * SetWorldTransform (GDI32.@)
1051 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1054 DC
*dc
= DC_GetDCPtr( hdc
);
1056 if (!dc
) return FALSE
;
1057 if (!xform
) goto done
;
1059 /* Check that graphics mode is GM_ADVANCED */
1060 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1062 dc
->xformWorld2Wnd
= *xform
;
1063 DC_UpdateXforms( dc
);
1066 GDI_ReleaseObj( hdc
);
1071 /****************************************************************************
1072 * ModifyWorldTransform [GDI32.@]
1073 * Modifies the world transformation for a device context.
1076 * hdc [I] Handle to device context
1077 * xform [I] XFORM structure that will be used to modify the world
1079 * iMode [I] Specifies in what way to modify the world transformation
1082 * Resets the world transformation to the identity matrix.
1083 * The parameter xform is ignored.
1085 * Multiplies xform into the world transformation matrix from
1088 * Multiplies xform into the world transformation matrix from
1093 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1097 DC
*dc
= DC_GetDCPtr( hdc
);
1099 /* Check for illegal parameters */
1100 if (!dc
) return FALSE
;
1101 if (!xform
) goto done
;
1103 /* Check that graphics mode is GM_ADVANCED */
1104 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1109 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1110 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1111 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1112 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1113 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1114 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1116 case MWT_LEFTMULTIPLY
:
1117 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1118 &dc
->xformWorld2Wnd
);
1120 case MWT_RIGHTMULTIPLY
:
1121 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1128 DC_UpdateXforms( dc
);
1131 GDI_ReleaseObj( hdc
);
1136 /****************************************************************************
1137 * CombineTransform [GDI32.@]
1138 * Combines two transformation matrices.
1141 * xformResult [O] Stores the result of combining the two matrices
1142 * xform1 [I] Specifies the first matrix to apply
1143 * xform2 [I] Specifies the second matrix to apply
1146 * The same matrix can be passed in for more than one of the parameters.
1150 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1151 const XFORM
*xform2
)
1155 /* Check for illegal parameters */
1156 if (!xformResult
|| !xform1
|| !xform2
)
1159 /* Create the result in a temporary XFORM, since xformResult may be
1160 * equal to xform1 or xform2 */
1161 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1162 xform1
->eM12
* xform2
->eM21
;
1163 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1164 xform1
->eM12
* xform2
->eM22
;
1165 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1166 xform1
->eM22
* xform2
->eM21
;
1167 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1168 xform1
->eM22
* xform2
->eM22
;
1169 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1170 xform1
->eDy
* xform2
->eM21
+
1172 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1173 xform1
->eDy
* xform2
->eM22
+
1176 /* Copy the result to xformResult */
1177 *xformResult
= xformTemp
;
1183 /***********************************************************************
1184 * SetDCHook (GDI.190)
1187 /* ### start build ### */
1188 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
1189 /* ### stop build ### */
1191 /**********************************************************************/
1193 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1195 DC
*dc
= DC_GetDCPtr( hdc
);
1196 if (!dc
) return FALSE
;
1199 * Note: We store the original SEGPTR 'hookProc' as we need to be
1200 * able to return it verbatim in GetDCHook,
1202 * On the other hand, we still call THUNK_Alloc and store the
1203 * 32-bit thunk into another DC member, because THUNK_Alloc
1204 * recognizes the (typical) case that the 'hookProc' is indeed
1205 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1207 * We could perform that test every time the hook is about to
1208 * be called (or else we could live with the 32->16->32 detour),
1209 * but this way is the most efficient ...
1212 dc
->hookProc
= hookProc
;
1213 dc
->dwHookData
= dwHookData
;
1215 THUNK_Free( (FARPROC
)dc
->hookThunk
);
1216 dc
->hookThunk
= (DCHOOKPROC
)
1217 THUNK_Alloc( hookProc
, (RELAY
)GDI_CallTo16_word_wwll
);
1219 GDI_ReleaseObj( hdc
);
1224 /***********************************************************************
1225 * GetDCHook (GDI.191)
1227 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1229 DC
*dc
= DC_GetDCPtr( hdc
);
1231 *phookProc
= dc
->hookProc
;
1232 GDI_ReleaseObj( hdc
);
1233 return dc
->dwHookData
;
1237 /***********************************************************************
1238 * SetHookFlags (GDI.192)
1240 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1242 DC
*dc
= DC_GetDCPtr( hDC
);
1246 WORD wRet
= dc
->flags
& DC_DIRTY
;
1248 /* "Undocumented Windows" info is slightly confusing.
1251 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1253 if( flags
& DCHF_INVALIDATEVISRGN
)
1254 dc
->flags
|= DC_DIRTY
;
1255 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1256 dc
->flags
&= ~DC_DIRTY
;
1257 GDI_ReleaseObj( hDC
);
1263 /***********************************************************************
1264 * SetICMMode (GDI32.@)
1266 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1268 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1269 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1270 if (iEnableICM
== ICM_ON
) return 0;
1271 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1275 /***********************************************************************
1276 * GetDeviceGammaRamp (GDI32.@)
1278 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1281 DC
*dc
= DC_GetDCPtr( hDC
);
1285 if (dc
->funcs
->pGetDeviceGammaRamp
)
1286 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
, ptr
);
1287 GDI_ReleaseObj( hDC
);
1292 /***********************************************************************
1293 * SetDeviceGammaRamp (GDI32.@)
1295 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1298 DC
*dc
= DC_GetDCPtr( hDC
);
1302 if (dc
->funcs
->pSetDeviceGammaRamp
)
1303 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
, ptr
);
1304 GDI_ReleaseObj( hDC
);
1309 /***********************************************************************
1310 * GetColorSpace (GDI32.@)
1312 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1314 /*FIXME Need to to whatever GetColorSpace actually does */
1318 /***********************************************************************
1319 * CreateColorSpaceA (GDI32.@)
1321 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1327 /***********************************************************************
1328 * CreateColorSpaceW (GDI32.@)
1330 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1336 /***********************************************************************
1337 * DeleteColorSpace (GDI32.@)
1339 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1346 /***********************************************************************
1347 * SetColorSpace (GDI32.@)
1349 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1356 /***********************************************************************
1357 * GetBoundsRect (GDI.194)
1359 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1361 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1364 /***********************************************************************
1365 * GetBoundsRect (GDI32.@)
1367 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1369 FIXME("(): stub\n");
1370 return DCB_RESET
; /* bounding rectangle always empty */
1373 /***********************************************************************
1374 * SetBoundsRect (GDI.193)
1376 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1378 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1379 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1381 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1384 /***********************************************************************
1385 * SetBoundsRect (GDI32.@)
1387 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1389 FIXME("(): stub\n");
1390 return DCB_DISABLE
; /* bounding rectangle always empty */
1394 /***********************************************************************
1395 * GetRelAbs (GDI32.@)
1397 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1400 DC
*dc
= DC_GetDCPtr( hdc
);
1401 if (dc
) ret
= dc
->relAbsMode
;
1402 GDI_ReleaseObj( hdc
);
1406 /***********************************************************************
1409 * Disables GDI, switches back to text mode.
1410 * We don't have to do anything here,
1411 * just let console support handle everything
1413 void WINAPI
Death16(HDC16 hDC
)
1415 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1418 /***********************************************************************
1419 * Resurrection (GDI.122)
1421 * Restores GDI functionality
1423 void WINAPI
Resurrection16(HDC16 hDC
,
1424 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1426 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1429 /***********************************************************************
1430 * GetLayout (GDI32.@)
1432 * Gets left->right or right->left text layout flags of a dc.
1433 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1436 DWORD WINAPI
GetLayout(HDC hdc
)
1438 FIXME("(%08x): stub\n", hdc
);
1439 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1443 /***********************************************************************
1444 * SetLayout (GDI32.@)
1446 * Sets left->right or right->left text layout flags of a dc.
1447 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1450 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1452 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1453 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);