2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
14 #include "debugtools.h"
19 #include "wine/winuser16.h"
21 DEFAULT_DEBUG_CHANNEL(dc
);
23 /* ### start build ### */
24 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
25 /* ### stop build ### */
27 /***********************************************************************
30 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
35 if (!(dc
= GDI_AllocObject( sizeof(*dc
), DC_MAGIC
, &hdc
))) return NULL
;
56 dc
->hPen
= GetStockObject( BLACK_PEN
);
57 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
58 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
61 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
63 dc
->ROPmode
= R2_COPYPEN
;
64 dc
->polyFillMode
= ALTERNATE
;
65 dc
->stretchBltMode
= BLACKONWHITE
;
66 dc
->relAbsMode
= ABSOLUTE
;
67 dc
->backgroundMode
= OPAQUE
;
68 dc
->backgroundColor
= RGB( 255, 255, 255 );
69 dc
->textColor
= RGB( 0, 0, 0 );
72 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
74 dc
->breakTotalExtra
= 0;
78 dc
->totalExtent
.left
= 0;
79 dc
->totalExtent
.top
= 0;
80 dc
->totalExtent
.right
= 0;
81 dc
->totalExtent
.bottom
= 0;
83 dc
->MapMode
= MM_TEXT
;
84 dc
->GraphicsMode
= GM_COMPATIBLE
;
87 dc
->pAbortProc
= NULL
;
90 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
91 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
92 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
93 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
94 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
95 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
96 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
97 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
98 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
99 dc
->vport2WorldValid
= TRUE
;
100 PATH_InitGdiPath(&dc
->path
);
106 /***********************************************************************
109 DC
*DC_GetDCPtr( HDC hdc
)
111 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
112 if (!ptr
) return NULL
;
113 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
114 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
115 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
117 GDI_ReleaseObj( hdc
);
118 SetLastError( ERROR_INVALID_HANDLE
);
122 /***********************************************************************
125 * Retrieve a DC ptr while making sure the visRgn is updated.
126 * This function may call up to USER so the GDI lock should _not_
127 * be held when calling it.
129 DC
*DC_GetDCUpdate( HDC hdc
)
131 DC
*dc
= DC_GetDCPtr( hdc
);
132 if (!dc
) return NULL
;
133 while (dc
->flags
& DC_DIRTY
)
135 dc
->flags
&= ~DC_DIRTY
;
136 if (!(dc
->flags
& (DC_SAVED
| DC_MEMORY
)))
138 DCHOOKPROC proc
= dc
->hookThunk
;
141 DWORD data
= dc
->dwHookData
;
142 GDI_ReleaseObj( hdc
);
143 proc( hdc
, DCHC_INVALIDVISRGN
, data
, 0 );
144 if (!(dc
= DC_GetDCPtr( hdc
))) break;
145 /* otherwise restart the loop in case it became dirty again in the meantime */
152 /***********************************************************************
155 * Setup device-specific DC values for a newly created DC.
157 void DC_InitDC( DC
* dc
)
159 RealizeDefaultPalette16( dc
->hSelf
);
160 SetTextColor( dc
->hSelf
, dc
->textColor
);
161 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
162 SelectObject( dc
->hSelf
, dc
->hPen
);
163 SelectObject( dc
->hSelf
, dc
->hBrush
);
164 SelectObject( dc
->hSelf
, dc
->hFont
);
165 CLIPPING_UpdateGCRegion( dc
);
169 /***********************************************************************
172 * Computes the inverse of the transformation xformSrc and stores it to
173 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
176 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
180 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
181 xformSrc
->eM12
*xformSrc
->eM21
;
182 if (determinant
> -1e-12 && determinant
< 1e-12)
185 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
186 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
187 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
188 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
189 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
190 xformSrc
->eDy
* xformDest
->eM21
;
191 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
192 xformSrc
->eDy
* xformDest
->eM22
;
198 /***********************************************************************
201 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
202 * fields of the specified DC by creating a transformation that
203 * represents the current mapping mode and combining it with the DC's
204 * world transform. This function should be called whenever the
205 * parameters associated with the mapping mode (window and viewport
206 * extents and origins) or the world transform change.
208 void DC_UpdateXforms( DC
*dc
)
210 XFORM xformWnd2Vport
;
211 FLOAT scaleX
, scaleY
;
213 /* Construct a transformation to do the window-to-viewport conversion */
214 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
215 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
216 xformWnd2Vport
.eM11
= scaleX
;
217 xformWnd2Vport
.eM12
= 0.0;
218 xformWnd2Vport
.eM21
= 0.0;
219 xformWnd2Vport
.eM22
= scaleY
;
220 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
221 scaleX
* (FLOAT
)dc
->wndOrgX
;
222 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
223 scaleY
* (FLOAT
)dc
->wndOrgY
;
225 /* Combine with the world transformation */
226 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
229 /* Create inverse of world-to-viewport transformation */
230 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
231 &dc
->xformVport2World
);
235 /***********************************************************************
236 * GetDCState (GDI.179)
238 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
243 if (!(dc
= DC_GetDCUpdate( hdc
))) return 0;
244 if (!(newdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
, &handle
)))
246 GDI_ReleaseObj( hdc
);
249 TRACE("(%04x): returning %04x\n", hdc
, handle
);
251 newdc
->flags
= dc
->flags
| DC_SAVED
;
252 newdc
->hPen
= dc
->hPen
;
253 newdc
->hBrush
= dc
->hBrush
;
254 newdc
->hFont
= dc
->hFont
;
255 newdc
->hBitmap
= dc
->hBitmap
;
256 newdc
->hDevice
= dc
->hDevice
;
257 newdc
->hPalette
= dc
->hPalette
;
258 newdc
->totalExtent
= dc
->totalExtent
;
259 newdc
->bitsPerPixel
= dc
->bitsPerPixel
;
260 newdc
->ROPmode
= dc
->ROPmode
;
261 newdc
->polyFillMode
= dc
->polyFillMode
;
262 newdc
->stretchBltMode
= dc
->stretchBltMode
;
263 newdc
->relAbsMode
= dc
->relAbsMode
;
264 newdc
->backgroundMode
= dc
->backgroundMode
;
265 newdc
->backgroundColor
= dc
->backgroundColor
;
266 newdc
->textColor
= dc
->textColor
;
267 newdc
->brushOrgX
= dc
->brushOrgX
;
268 newdc
->brushOrgY
= dc
->brushOrgY
;
269 newdc
->textAlign
= dc
->textAlign
;
270 newdc
->charExtra
= dc
->charExtra
;
271 newdc
->breakTotalExtra
= dc
->breakTotalExtra
;
272 newdc
->breakCount
= dc
->breakCount
;
273 newdc
->breakExtra
= dc
->breakExtra
;
274 newdc
->breakRem
= dc
->breakRem
;
275 newdc
->MapMode
= dc
->MapMode
;
276 newdc
->GraphicsMode
= dc
->GraphicsMode
;
278 /* Apparently, the DC origin is not changed by [GS]etDCState */
279 newdc
->DCOrgX
= dc
->DCOrgX
;
280 newdc
->DCOrgY
= dc
->DCOrgY
;
282 newdc
->CursPosX
= dc
->CursPosX
;
283 newdc
->CursPosY
= dc
->CursPosY
;
284 newdc
->ArcDirection
= dc
->ArcDirection
;
285 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
286 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
287 newdc
->xformVport2World
= dc
->xformVport2World
;
288 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
289 newdc
->wndOrgX
= dc
->wndOrgX
;
290 newdc
->wndOrgY
= dc
->wndOrgY
;
291 newdc
->wndExtX
= dc
->wndExtX
;
292 newdc
->wndExtY
= dc
->wndExtY
;
293 newdc
->vportOrgX
= dc
->vportOrgX
;
294 newdc
->vportOrgY
= dc
->vportOrgY
;
295 newdc
->vportExtX
= dc
->vportExtX
;
296 newdc
->vportExtY
= dc
->vportExtY
;
298 newdc
->hSelf
= (HDC
)handle
;
299 newdc
->saveLevel
= 0;
301 PATH_InitGdiPath( &newdc
->path
);
303 newdc
->pAbortProc
= NULL
;
304 newdc
->hookThunk
= NULL
;
307 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
309 newdc
->hGCClipRgn
= newdc
->hVisRgn
= 0;
312 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
313 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
319 WineEngAddRefFont(dc
->gdiFont
);
320 newdc
->gdiFont
= dc
->gdiFont
;
324 GDI_ReleaseObj( handle
);
325 GDI_ReleaseObj( hdc
);
330 /***********************************************************************
331 * SetDCState (GDI.180)
333 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
337 if (!(dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
338 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
340 GDI_ReleaseObj( hdc
);
343 if (!dcs
->flags
& DC_SAVED
)
345 GDI_ReleaseObj( hdc
);
346 GDI_ReleaseObj( hdcs
);
349 TRACE("%04x %04x\n", hdc
, hdcs
);
351 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
352 dc
->hDevice
= dcs
->hDevice
;
353 dc
->totalExtent
= dcs
->totalExtent
;
354 dc
->ROPmode
= dcs
->ROPmode
;
355 dc
->polyFillMode
= dcs
->polyFillMode
;
356 dc
->stretchBltMode
= dcs
->stretchBltMode
;
357 dc
->relAbsMode
= dcs
->relAbsMode
;
358 dc
->backgroundMode
= dcs
->backgroundMode
;
359 dc
->backgroundColor
= dcs
->backgroundColor
;
360 dc
->textColor
= dcs
->textColor
;
361 dc
->brushOrgX
= dcs
->brushOrgX
;
362 dc
->brushOrgY
= dcs
->brushOrgY
;
363 dc
->textAlign
= dcs
->textAlign
;
364 dc
->charExtra
= dcs
->charExtra
;
365 dc
->breakTotalExtra
= dcs
->breakTotalExtra
;
366 dc
->breakCount
= dcs
->breakCount
;
367 dc
->breakExtra
= dcs
->breakExtra
;
368 dc
->breakRem
= dcs
->breakRem
;
369 dc
->MapMode
= dcs
->MapMode
;
370 dc
->GraphicsMode
= dcs
->GraphicsMode
;
372 /* Apparently, the DC origin is not changed by [GS]etDCState */
373 dc
->DCOrgX
= dcs
->DCOrgX
;
374 dc
->DCOrgY
= dcs
->DCOrgY
;
376 dc
->CursPosX
= dcs
->CursPosX
;
377 dc
->CursPosY
= dcs
->CursPosY
;
378 dc
->ArcDirection
= dcs
->ArcDirection
;
379 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
380 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
381 dc
->xformVport2World
= dcs
->xformVport2World
;
382 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
384 dc
->wndOrgX
= dcs
->wndOrgX
;
385 dc
->wndOrgY
= dcs
->wndOrgY
;
386 dc
->wndExtX
= dcs
->wndExtX
;
387 dc
->wndExtY
= dcs
->wndExtY
;
388 dc
->vportOrgX
= dcs
->vportOrgX
;
389 dc
->vportOrgY
= dcs
->vportOrgY
;
390 dc
->vportExtX
= dcs
->vportExtX
;
391 dc
->vportExtY
= dcs
->vportExtY
;
393 if (!(dc
->flags
& DC_MEMORY
)) dc
->bitsPerPixel
= dcs
->bitsPerPixel
;
397 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
398 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
402 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
405 CLIPPING_UpdateGCRegion( dc
);
407 SelectObject( hdc
, dcs
->hBitmap
);
408 SelectObject( hdc
, dcs
->hBrush
);
409 SelectObject( hdc
, dcs
->hFont
);
410 SelectObject( hdc
, dcs
->hPen
);
411 SetBkColor( hdc
, dcs
->backgroundColor
);
412 SetTextColor( hdc
, dcs
->textColor
);
413 GDISelectPalette16( hdc
, dcs
->hPalette
, FALSE
);
414 GDI_ReleaseObj( hdcs
);
415 GDI_ReleaseObj( hdc
);
419 /***********************************************************************
422 INT16 WINAPI
SaveDC16( HDC16 hdc
)
424 return (INT16
)SaveDC( hdc
);
428 /***********************************************************************
431 INT WINAPI
SaveDC( HDC hdc
)
437 dc
= DC_GetDCUpdate( hdc
);
440 if(dc
->funcs
->pSaveDC
)
442 ret
= dc
->funcs
->pSaveDC( dc
);
443 GDI_ReleaseObj( hdc
);
447 if (!(hdcs
= GetDCState16( hdc
)))
449 GDI_ReleaseObj( hdc
);
452 dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
);
454 /* Copy path. The reason why path saving / restoring is in SaveDC/
455 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
456 * functions are only in Win16 (which doesn't have paths) and that
457 * SetDCState doesn't allow us to signal an error (which can happen
458 * when copying paths).
460 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
462 GDI_ReleaseObj( hdc
);
463 GDI_ReleaseObj( hdcs
);
468 dcs
->header
.hNext
= dc
->header
.hNext
;
469 dc
->header
.hNext
= hdcs
;
470 TRACE("(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
471 ret
= ++dc
->saveLevel
;
472 GDI_ReleaseObj( hdcs
);
473 GDI_ReleaseObj( hdc
);
478 /***********************************************************************
481 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
483 return RestoreDC( hdc
, level
);
487 /***********************************************************************
488 * RestoreDC (GDI32.@)
490 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
495 TRACE("%04x %d\n", hdc
, level
);
496 dc
= DC_GetDCPtr( hdc
);
497 if(!dc
) return FALSE
;
498 if(dc
->funcs
->pRestoreDC
)
500 success
= dc
->funcs
->pRestoreDC( dc
, level
);
501 GDI_ReleaseObj( hdc
);
505 if (level
== -1) level
= dc
->saveLevel
;
507 /* This pair of checks disagrees with MSDN "Platform SDK:
508 Windows GDI" July 2000 which says all negative values
509 for level will be interpreted as an instance relative
510 to the current state. Restricting it to just -1 does
512 || (level
> dc
->saveLevel
))
514 GDI_ReleaseObj( hdc
);
519 while (dc
->saveLevel
>= level
)
521 HDC16 hdcs
= dc
->header
.hNext
;
522 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
524 GDI_ReleaseObj( hdc
);
527 dc
->header
.hNext
= dcs
->header
.hNext
;
528 if (--dc
->saveLevel
< level
)
530 SetDCState16( hdc
, hdcs
);
531 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
532 /* FIXME: This might not be quite right, since we're
533 * returning FALSE but still destroying the saved DC state */
536 GDI_ReleaseObj( hdcs
);
537 GDI_ReleaseObj( hdc
);
539 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
541 GDI_ReleaseObj( hdc
);
546 /***********************************************************************
549 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
550 const DEVMODEA
*initData
)
552 return CreateDCA( driver
, device
, output
, initData
);
555 /***********************************************************************
556 * CreateDCA (GDI32.@)
558 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
559 const DEVMODEA
*initData
)
563 const DC_FUNCTIONS
*funcs
;
568 if (!device
|| !DRIVER_GetDriverName( device
, buf
, sizeof(buf
) ))
571 if (!(funcs
= DRIVER_load_driver( buf
)))
573 ERR( "no driver found for %s\n", buf
);
576 if (!(dc
= DC_AllocDC( funcs
)))
578 DRIVER_release_driver( funcs
);
584 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
585 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
587 if (dc
->funcs
->pCreateDC
&&
588 !dc
->funcs
->pCreateDC( dc
, buf
, device
, output
, initData
))
590 WARN("creation aborted by device\n" );
591 GDI_FreeObject( dc
->hSelf
, dc
);
592 DRIVER_release_driver( funcs
);
598 GDI_ReleaseObj( hdc
);
603 /***********************************************************************
604 * CreateDCW (GDI32.@)
606 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
607 const DEVMODEW
*initData
)
609 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
610 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
611 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
612 HDC res
= CreateDCA( driverA
, deviceA
, outputA
,
613 (const DEVMODEA
*)initData
/*FIXME*/ );
614 HeapFree( GetProcessHeap(), 0, driverA
);
615 HeapFree( GetProcessHeap(), 0, deviceA
);
616 HeapFree( GetProcessHeap(), 0, outputA
);
621 /***********************************************************************
624 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
625 const DEVMODEA
* initData
)
627 /* Nothing special yet for ICs */
628 return CreateDC16( driver
, device
, output
, initData
);
632 /***********************************************************************
633 * CreateICA (GDI32.@)
635 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
636 const DEVMODEA
* initData
)
638 /* Nothing special yet for ICs */
639 return CreateDCA( driver
, device
, output
, initData
);
643 /***********************************************************************
644 * CreateICW (GDI32.@)
646 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
647 const DEVMODEW
* initData
)
649 /* Nothing special yet for ICs */
650 return CreateDCW( driver
, device
, output
, initData
);
654 /***********************************************************************
655 * CreateCompatibleDC (GDI.52)
657 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
659 return (HDC16
)CreateCompatibleDC( hdc
);
663 /***********************************************************************
664 * CreateCompatibleDC (GDI32.@)
666 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
669 const DC_FUNCTIONS
*funcs
;
673 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
675 funcs
= origDC
->funcs
;
676 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
677 funcs
= DRIVER_get_driver( funcs
);
679 else funcs
= DRIVER_load_driver( "DISPLAY" );
681 if (!funcs
) return 0;
683 if (!(dc
= DC_AllocDC( funcs
)))
685 DRIVER_release_driver( funcs
);
689 TRACE("(%04x): returning %04x\n",
692 dc
->flags
= DC_MEMORY
;
693 dc
->bitsPerPixel
= 1;
694 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
696 /* Copy the driver-specific physical device info into
697 * the new DC. The driver may use this read-only info
698 * while creating the compatible DC below. */
699 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) dc
->physDev
= origDC
->physDev
;
701 if (dc
->funcs
->pCreateDC
&&
702 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
704 WARN("creation aborted by device\n");
705 GDI_FreeObject( dc
->hSelf
, dc
);
706 if (origDC
) GDI_ReleaseObj( hdc
);
707 DRIVER_release_driver( funcs
);
712 GDI_ReleaseObj( dc
->hSelf
);
713 if (origDC
) GDI_ReleaseObj( hdc
);
718 /***********************************************************************
721 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
723 return DeleteDC( hdc
);
727 /***********************************************************************
730 BOOL WINAPI
DeleteDC( HDC hdc
)
732 const DC_FUNCTIONS
*funcs
= NULL
;
735 TRACE("%04x\n", hdc
);
739 if (!(dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) return FALSE
;
741 /* Call hook procedure to check whether is it OK to delete this DC */
742 if (dc
->hookThunk
&& !(dc
->flags
& (DC_SAVED
| DC_MEMORY
)))
744 DCHOOKPROC proc
= dc
->hookThunk
;
747 DWORD data
= dc
->dwHookData
;
748 GDI_ReleaseObj( hdc
);
749 if (!proc( hdc
, DCHC_DELETEDC
, data
, 0 )) return FALSE
;
750 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
754 while (dc
->saveLevel
)
757 HDC16 hdcs
= dc
->header
.hNext
;
758 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
759 dc
->header
.hNext
= dcs
->header
.hNext
;
761 GDI_ReleaseObj( hdcs
);
765 if (!(dc
->flags
& DC_SAVED
))
767 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
768 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
769 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
770 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
772 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
775 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
776 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
777 if (dc
->hGCClipRgn
) DeleteObject( dc
->hGCClipRgn
);
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 (GDI32.@)
1186 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1188 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1190 DC
*dc
= DC_GetDCPtr( hdc
);
1192 if (!dc
) return FALSE
;
1193 dc
->dwHookData
= dwHookData
;
1194 dc
->hookThunk
= hookProc
;
1195 GDI_ReleaseObj( hdc
);
1200 /* relay function to call the 16-bit DC hook proc */
1201 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc
, WORD code
, DWORD data
, LPARAM lParam
)
1203 FARPROC16 proc
= NULL
;
1204 DC
*dc
= DC_GetDCPtr( hdc
);
1205 if (!dc
) return FALSE
;
1206 proc
= dc
->hookProc
;
1207 GDI_ReleaseObj( hdc
);
1208 if (!proc
) return FALSE
;
1209 return GDI_CallTo16_word_wwll( proc
, hdc
, code
, data
, lParam
);
1212 /***********************************************************************
1213 * SetDCHook (GDI.190)
1215 BOOL16 WINAPI
SetDCHook16( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1217 DC
*dc
= DC_GetDCPtr( hdc
);
1218 if (!dc
) return FALSE
;
1220 dc
->hookProc
= hookProc
;
1221 GDI_ReleaseObj( hdc
);
1222 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1226 /***********************************************************************
1227 * GetDCHook (GDI.191)
1229 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1231 DC
*dc
= DC_GetDCPtr( hdc
);
1233 *phookProc
= dc
->hookProc
;
1234 GDI_ReleaseObj( hdc
);
1235 return dc
->dwHookData
;
1239 /***********************************************************************
1240 * SetHookFlags (GDI.192)
1242 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1244 DC
*dc
= DC_GetDCPtr( hDC
);
1248 WORD wRet
= dc
->flags
& DC_DIRTY
;
1250 /* "Undocumented Windows" info is slightly confusing.
1253 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1255 if( flags
& DCHF_INVALIDATEVISRGN
)
1256 dc
->flags
|= DC_DIRTY
;
1257 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1258 dc
->flags
&= ~DC_DIRTY
;
1259 GDI_ReleaseObj( hDC
);
1265 /***********************************************************************
1266 * SetICMMode (GDI32.@)
1268 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1270 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1271 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1272 if (iEnableICM
== ICM_ON
) return 0;
1273 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1277 /***********************************************************************
1278 * GetDeviceGammaRamp (GDI32.@)
1280 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1283 DC
*dc
= DC_GetDCPtr( hDC
);
1287 if (dc
->funcs
->pGetDeviceGammaRamp
)
1288 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
, ptr
);
1289 GDI_ReleaseObj( hDC
);
1294 /***********************************************************************
1295 * SetDeviceGammaRamp (GDI32.@)
1297 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1300 DC
*dc
= DC_GetDCPtr( hDC
);
1304 if (dc
->funcs
->pSetDeviceGammaRamp
)
1305 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
, ptr
);
1306 GDI_ReleaseObj( hDC
);
1311 /***********************************************************************
1312 * GetColorSpace (GDI32.@)
1314 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1316 /*FIXME Need to to whatever GetColorSpace actually does */
1320 /***********************************************************************
1321 * CreateColorSpaceA (GDI32.@)
1323 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1329 /***********************************************************************
1330 * CreateColorSpaceW (GDI32.@)
1332 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1338 /***********************************************************************
1339 * DeleteColorSpace (GDI32.@)
1341 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1348 /***********************************************************************
1349 * SetColorSpace (GDI32.@)
1351 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1358 /***********************************************************************
1359 * GetBoundsRect (GDI.194)
1361 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1363 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1366 /***********************************************************************
1367 * GetBoundsRect (GDI32.@)
1369 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1371 FIXME("(): stub\n");
1372 return DCB_RESET
; /* bounding rectangle always empty */
1375 /***********************************************************************
1376 * SetBoundsRect (GDI.193)
1378 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1380 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1381 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1383 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1386 /***********************************************************************
1387 * SetBoundsRect (GDI32.@)
1389 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1391 FIXME("(): stub\n");
1392 return DCB_DISABLE
; /* bounding rectangle always empty */
1396 /***********************************************************************
1397 * GetRelAbs (GDI32.@)
1399 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1402 DC
*dc
= DC_GetDCPtr( hdc
);
1403 if (dc
) ret
= dc
->relAbsMode
;
1404 GDI_ReleaseObj( hdc
);
1408 /***********************************************************************
1411 * Disables GDI, switches back to text mode.
1412 * We don't have to do anything here,
1413 * just let console support handle everything
1415 void WINAPI
Death16(HDC16 hDC
)
1417 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1420 /***********************************************************************
1421 * Resurrection (GDI.122)
1423 * Restores GDI functionality
1425 void WINAPI
Resurrection16(HDC16 hDC
,
1426 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1428 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1431 /***********************************************************************
1432 * GetLayout (GDI32.@)
1434 * Gets left->right or right->left text layout flags of a dc.
1435 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1438 DWORD WINAPI
GetLayout(HDC hdc
)
1440 FIXME("(%08x): stub\n", hdc
);
1441 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1445 /***********************************************************************
1446 * SetLayout (GDI32.@)
1448 * Sets left->right or right->left text layout flags of a dc.
1449 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1452 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1454 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1455 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);