2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/debug.h"
32 #include "wine/winuser16.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
36 /* ### start build ### */
37 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
38 /* ### stop build ### */
40 /***********************************************************************
43 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
48 if (!(dc
= GDI_AllocObject( sizeof(*dc
), DC_MAGIC
, &hdc
))) return NULL
;
69 dc
->hPen
= GetStockObject( BLACK_PEN
);
70 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
71 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
74 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
76 dc
->ROPmode
= R2_COPYPEN
;
77 dc
->polyFillMode
= ALTERNATE
;
78 dc
->stretchBltMode
= BLACKONWHITE
;
79 dc
->relAbsMode
= ABSOLUTE
;
80 dc
->backgroundMode
= OPAQUE
;
81 dc
->backgroundColor
= RGB( 255, 255, 255 );
82 dc
->textColor
= RGB( 0, 0, 0 );
85 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
87 dc
->breakTotalExtra
= 0;
91 dc
->totalExtent
.left
= 0;
92 dc
->totalExtent
.top
= 0;
93 dc
->totalExtent
.right
= 0;
94 dc
->totalExtent
.bottom
= 0;
96 dc
->MapMode
= MM_TEXT
;
97 dc
->GraphicsMode
= GM_COMPATIBLE
;
100 dc
->pAbortProc
= NULL
;
103 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
104 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
105 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
106 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
107 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
108 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
109 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
110 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
111 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
112 dc
->vport2WorldValid
= TRUE
;
113 PATH_InitGdiPath(&dc
->path
);
119 /***********************************************************************
122 DC
*DC_GetDCPtr( HDC hdc
)
124 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
125 if (!ptr
) return NULL
;
126 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
127 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
128 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
130 GDI_ReleaseObj( hdc
);
131 SetLastError( ERROR_INVALID_HANDLE
);
135 /***********************************************************************
138 * Retrieve a DC ptr while making sure the visRgn is updated.
139 * This function may call up to USER so the GDI lock should _not_
140 * be held when calling it.
142 DC
*DC_GetDCUpdate( HDC hdc
)
144 DC
*dc
= DC_GetDCPtr( hdc
);
145 if (!dc
) return NULL
;
146 while (dc
->flags
& DC_DIRTY
)
148 dc
->flags
&= ~DC_DIRTY
;
149 if (!(dc
->flags
& (DC_SAVED
| DC_MEMORY
)))
151 DCHOOKPROC proc
= dc
->hookThunk
;
154 DWORD data
= dc
->dwHookData
;
155 GDI_ReleaseObj( hdc
);
156 proc( hdc
, DCHC_INVALIDVISRGN
, data
, 0 );
157 if (!(dc
= DC_GetDCPtr( hdc
))) break;
158 /* otherwise restart the loop in case it became dirty again in the meantime */
165 /***********************************************************************
168 * Setup device-specific DC values for a newly created DC.
170 void DC_InitDC( DC
* dc
)
172 RealizeDefaultPalette16( dc
->hSelf
);
173 SetTextColor( dc
->hSelf
, dc
->textColor
);
174 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
175 SelectObject( dc
->hSelf
, dc
->hPen
);
176 SelectObject( dc
->hSelf
, dc
->hBrush
);
177 SelectObject( dc
->hSelf
, dc
->hFont
);
178 CLIPPING_UpdateGCRegion( dc
);
182 /***********************************************************************
185 * Computes the inverse of the transformation xformSrc and stores it to
186 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
189 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
193 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
194 xformSrc
->eM12
*xformSrc
->eM21
;
195 if (determinant
> -1e-12 && determinant
< 1e-12)
198 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
199 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
200 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
201 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
202 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
203 xformSrc
->eDy
* xformDest
->eM21
;
204 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
205 xformSrc
->eDy
* xformDest
->eM22
;
211 /***********************************************************************
214 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
215 * fields of the specified DC by creating a transformation that
216 * represents the current mapping mode and combining it with the DC's
217 * world transform. This function should be called whenever the
218 * parameters associated with the mapping mode (window and viewport
219 * extents and origins) or the world transform change.
221 void DC_UpdateXforms( DC
*dc
)
223 XFORM xformWnd2Vport
;
224 FLOAT scaleX
, scaleY
;
226 /* Construct a transformation to do the window-to-viewport conversion */
227 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
228 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
229 xformWnd2Vport
.eM11
= scaleX
;
230 xformWnd2Vport
.eM12
= 0.0;
231 xformWnd2Vport
.eM21
= 0.0;
232 xformWnd2Vport
.eM22
= scaleY
;
233 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
234 scaleX
* (FLOAT
)dc
->wndOrgX
;
235 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
236 scaleY
* (FLOAT
)dc
->wndOrgY
;
238 /* Combine with the world transformation */
239 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
242 /* Create inverse of world-to-viewport transformation */
243 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
244 &dc
->xformVport2World
);
248 /***********************************************************************
249 * GetDCState (GDI.179)
251 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
256 if (!(dc
= DC_GetDCUpdate( hdc
))) return 0;
257 if (!(newdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
, &handle
)))
259 GDI_ReleaseObj( hdc
);
262 TRACE("(%04x): returning %04x\n", hdc
, handle
);
264 newdc
->flags
= dc
->flags
| DC_SAVED
;
265 newdc
->hPen
= dc
->hPen
;
266 newdc
->hBrush
= dc
->hBrush
;
267 newdc
->hFont
= dc
->hFont
;
268 newdc
->hBitmap
= dc
->hBitmap
;
269 newdc
->hDevice
= dc
->hDevice
;
270 newdc
->hPalette
= dc
->hPalette
;
271 newdc
->totalExtent
= dc
->totalExtent
;
272 newdc
->bitsPerPixel
= dc
->bitsPerPixel
;
273 newdc
->ROPmode
= dc
->ROPmode
;
274 newdc
->polyFillMode
= dc
->polyFillMode
;
275 newdc
->stretchBltMode
= dc
->stretchBltMode
;
276 newdc
->relAbsMode
= dc
->relAbsMode
;
277 newdc
->backgroundMode
= dc
->backgroundMode
;
278 newdc
->backgroundColor
= dc
->backgroundColor
;
279 newdc
->textColor
= dc
->textColor
;
280 newdc
->brushOrgX
= dc
->brushOrgX
;
281 newdc
->brushOrgY
= dc
->brushOrgY
;
282 newdc
->textAlign
= dc
->textAlign
;
283 newdc
->charExtra
= dc
->charExtra
;
284 newdc
->breakTotalExtra
= dc
->breakTotalExtra
;
285 newdc
->breakCount
= dc
->breakCount
;
286 newdc
->breakExtra
= dc
->breakExtra
;
287 newdc
->breakRem
= dc
->breakRem
;
288 newdc
->MapMode
= dc
->MapMode
;
289 newdc
->GraphicsMode
= dc
->GraphicsMode
;
291 /* Apparently, the DC origin is not changed by [GS]etDCState */
292 newdc
->DCOrgX
= dc
->DCOrgX
;
293 newdc
->DCOrgY
= dc
->DCOrgY
;
295 newdc
->CursPosX
= dc
->CursPosX
;
296 newdc
->CursPosY
= dc
->CursPosY
;
297 newdc
->ArcDirection
= dc
->ArcDirection
;
298 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
299 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
300 newdc
->xformVport2World
= dc
->xformVport2World
;
301 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
302 newdc
->wndOrgX
= dc
->wndOrgX
;
303 newdc
->wndOrgY
= dc
->wndOrgY
;
304 newdc
->wndExtX
= dc
->wndExtX
;
305 newdc
->wndExtY
= dc
->wndExtY
;
306 newdc
->vportOrgX
= dc
->vportOrgX
;
307 newdc
->vportOrgY
= dc
->vportOrgY
;
308 newdc
->vportExtX
= dc
->vportExtX
;
309 newdc
->vportExtY
= dc
->vportExtY
;
311 newdc
->hSelf
= (HDC
)handle
;
312 newdc
->saveLevel
= 0;
314 PATH_InitGdiPath( &newdc
->path
);
316 newdc
->pAbortProc
= NULL
;
317 newdc
->hookThunk
= NULL
;
320 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
322 newdc
->hGCClipRgn
= newdc
->hVisRgn
= 0;
325 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
326 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
332 newdc
->gdiFont
= dc
->gdiFont
;
336 GDI_ReleaseObj( handle
);
337 GDI_ReleaseObj( hdc
);
342 /***********************************************************************
343 * SetDCState (GDI.180)
345 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
349 if (!(dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
350 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
352 GDI_ReleaseObj( hdc
);
355 if (!dcs
->flags
& DC_SAVED
)
357 GDI_ReleaseObj( hdc
);
358 GDI_ReleaseObj( hdcs
);
361 TRACE("%04x %04x\n", hdc
, hdcs
);
363 dc
->flags
= dcs
->flags
& ~DC_SAVED
;
364 dc
->hDevice
= dcs
->hDevice
;
365 dc
->totalExtent
= dcs
->totalExtent
;
366 dc
->ROPmode
= dcs
->ROPmode
;
367 dc
->polyFillMode
= dcs
->polyFillMode
;
368 dc
->stretchBltMode
= dcs
->stretchBltMode
;
369 dc
->relAbsMode
= dcs
->relAbsMode
;
370 dc
->backgroundMode
= dcs
->backgroundMode
;
371 dc
->backgroundColor
= dcs
->backgroundColor
;
372 dc
->textColor
= dcs
->textColor
;
373 dc
->brushOrgX
= dcs
->brushOrgX
;
374 dc
->brushOrgY
= dcs
->brushOrgY
;
375 dc
->textAlign
= dcs
->textAlign
;
376 dc
->charExtra
= dcs
->charExtra
;
377 dc
->breakTotalExtra
= dcs
->breakTotalExtra
;
378 dc
->breakCount
= dcs
->breakCount
;
379 dc
->breakExtra
= dcs
->breakExtra
;
380 dc
->breakRem
= dcs
->breakRem
;
381 dc
->MapMode
= dcs
->MapMode
;
382 dc
->GraphicsMode
= dcs
->GraphicsMode
;
384 /* Apparently, the DC origin is not changed by [GS]etDCState */
385 dc
->DCOrgX
= dcs
->DCOrgX
;
386 dc
->DCOrgY
= dcs
->DCOrgY
;
388 dc
->CursPosX
= dcs
->CursPosX
;
389 dc
->CursPosY
= dcs
->CursPosY
;
390 dc
->ArcDirection
= dcs
->ArcDirection
;
391 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
392 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
393 dc
->xformVport2World
= dcs
->xformVport2World
;
394 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
396 dc
->wndOrgX
= dcs
->wndOrgX
;
397 dc
->wndOrgY
= dcs
->wndOrgY
;
398 dc
->wndExtX
= dcs
->wndExtX
;
399 dc
->wndExtY
= dcs
->wndExtY
;
400 dc
->vportOrgX
= dcs
->vportOrgX
;
401 dc
->vportOrgY
= dcs
->vportOrgY
;
402 dc
->vportExtX
= dcs
->vportExtX
;
403 dc
->vportExtY
= dcs
->vportExtY
;
405 if (!(dc
->flags
& DC_MEMORY
)) dc
->bitsPerPixel
= dcs
->bitsPerPixel
;
409 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
410 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
414 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
417 CLIPPING_UpdateGCRegion( dc
);
419 SelectObject( hdc
, dcs
->hBitmap
);
420 SelectObject( hdc
, dcs
->hBrush
);
421 SelectObject( hdc
, dcs
->hFont
);
422 SelectObject( hdc
, dcs
->hPen
);
423 SetBkColor( hdc
, dcs
->backgroundColor
);
424 SetTextColor( hdc
, dcs
->textColor
);
425 GDISelectPalette16( hdc
, dcs
->hPalette
, FALSE
);
426 GDI_ReleaseObj( hdcs
);
427 GDI_ReleaseObj( hdc
);
431 /***********************************************************************
434 INT16 WINAPI
SaveDC16( HDC16 hdc
)
436 return (INT16
)SaveDC( hdc
);
440 /***********************************************************************
443 INT WINAPI
SaveDC( HDC hdc
)
449 dc
= DC_GetDCUpdate( hdc
);
452 if(dc
->funcs
->pSaveDC
)
454 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
455 GDI_ReleaseObj( hdc
);
459 if (!(hdcs
= GetDCState16( hdc
)))
461 GDI_ReleaseObj( hdc
);
464 dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
);
466 /* Copy path. The reason why path saving / restoring is in SaveDC/
467 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
468 * functions are only in Win16 (which doesn't have paths) and that
469 * SetDCState doesn't allow us to signal an error (which can happen
470 * when copying paths).
472 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
474 GDI_ReleaseObj( hdc
);
475 GDI_ReleaseObj( hdcs
);
480 dcs
->header
.hNext
= dc
->header
.hNext
;
481 dc
->header
.hNext
= hdcs
;
482 TRACE("(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
483 ret
= ++dc
->saveLevel
;
484 GDI_ReleaseObj( hdcs
);
485 GDI_ReleaseObj( hdc
);
490 /***********************************************************************
493 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
495 return RestoreDC( hdc
, level
);
499 /***********************************************************************
500 * RestoreDC (GDI32.@)
502 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
507 TRACE("%04x %d\n", hdc
, level
);
508 dc
= DC_GetDCPtr( hdc
);
509 if(!dc
) return FALSE
;
510 if(dc
->funcs
->pRestoreDC
)
512 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
513 GDI_ReleaseObj( hdc
);
517 if (level
== -1) level
= dc
->saveLevel
;
519 /* This pair of checks disagrees with MSDN "Platform SDK:
520 Windows GDI" July 2000 which says all negative values
521 for level will be interpreted as an instance relative
522 to the current state. Restricting it to just -1 does
524 || (level
> dc
->saveLevel
))
526 GDI_ReleaseObj( hdc
);
531 while (dc
->saveLevel
>= level
)
533 HDC16 hdcs
= dc
->header
.hNext
;
534 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
536 GDI_ReleaseObj( hdc
);
539 dc
->header
.hNext
= dcs
->header
.hNext
;
540 if (--dc
->saveLevel
< level
)
542 SetDCState16( hdc
, hdcs
);
543 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
544 /* FIXME: This might not be quite right, since we're
545 * returning FALSE but still destroying the saved DC state */
548 GDI_ReleaseObj( hdcs
);
549 GDI_ReleaseObj( hdc
);
551 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
553 GDI_ReleaseObj( hdc
);
558 /***********************************************************************
561 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
562 const DEVMODEA
*initData
)
564 return CreateDCA( driver
, device
, output
, initData
);
567 /***********************************************************************
568 * CreateDCA (GDI32.@)
570 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
571 const DEVMODEA
*initData
)
575 const DC_FUNCTIONS
*funcs
;
580 if (!device
|| !DRIVER_GetDriverName( device
, buf
, sizeof(buf
) ))
583 if (!(funcs
= DRIVER_load_driver( buf
)))
585 ERR( "no driver found for %s\n", buf
);
588 if (!(dc
= DC_AllocDC( funcs
)))
590 DRIVER_release_driver( funcs
);
596 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
597 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
599 if (dc
->funcs
->pCreateDC
&&
600 !dc
->funcs
->pCreateDC( dc
, buf
, device
, output
, initData
))
602 WARN("creation aborted by device\n" );
603 GDI_FreeObject( dc
->hSelf
, dc
);
604 DRIVER_release_driver( funcs
);
610 GDI_ReleaseObj( hdc
);
615 /***********************************************************************
616 * CreateDCW (GDI32.@)
618 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
619 const DEVMODEW
*initData
)
621 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
622 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
623 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
624 HDC res
= CreateDCA( driverA
, deviceA
, outputA
,
625 (const DEVMODEA
*)initData
/*FIXME*/ );
626 HeapFree( GetProcessHeap(), 0, driverA
);
627 HeapFree( GetProcessHeap(), 0, deviceA
);
628 HeapFree( GetProcessHeap(), 0, outputA
);
633 /***********************************************************************
636 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
637 const DEVMODEA
* initData
)
639 /* Nothing special yet for ICs */
640 return CreateDC16( driver
, device
, output
, initData
);
644 /***********************************************************************
645 * CreateICA (GDI32.@)
647 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
648 const DEVMODEA
* initData
)
650 /* Nothing special yet for ICs */
651 return CreateDCA( driver
, device
, output
, initData
);
655 /***********************************************************************
656 * CreateICW (GDI32.@)
658 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
659 const DEVMODEW
* initData
)
661 /* Nothing special yet for ICs */
662 return CreateDCW( driver
, device
, output
, initData
);
666 /***********************************************************************
667 * CreateCompatibleDC (GDI.52)
669 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
671 return (HDC16
)CreateCompatibleDC( hdc
);
675 /***********************************************************************
676 * CreateCompatibleDC (GDI32.@)
678 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
681 const DC_FUNCTIONS
*funcs
;
685 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
687 funcs
= origDC
->funcs
;
688 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
689 funcs
= DRIVER_get_driver( funcs
);
691 else funcs
= DRIVER_load_driver( "DISPLAY" );
693 if (!funcs
) return 0;
695 if (!(dc
= DC_AllocDC( funcs
)))
697 DRIVER_release_driver( funcs
);
701 TRACE("(%04x): returning %04x\n",
704 dc
->flags
= DC_MEMORY
;
705 dc
->bitsPerPixel
= 1;
706 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
708 /* Copy the driver-specific physical device info into
709 * the new DC. The driver may use this read-only info
710 * while creating the compatible DC below. */
711 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) dc
->physDev
= origDC
->physDev
;
713 if (dc
->funcs
->pCreateDC
&&
714 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
716 WARN("creation aborted by device\n");
717 GDI_FreeObject( dc
->hSelf
, dc
);
718 if (origDC
) GDI_ReleaseObj( hdc
);
719 DRIVER_release_driver( funcs
);
724 GDI_ReleaseObj( dc
->hSelf
);
725 if (origDC
) GDI_ReleaseObj( hdc
);
730 /***********************************************************************
733 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
735 return DeleteDC( hdc
);
739 /***********************************************************************
742 BOOL WINAPI
DeleteDC( HDC hdc
)
744 const DC_FUNCTIONS
*funcs
= NULL
;
747 TRACE("%04x\n", hdc
);
751 if (!(dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
))) return FALSE
;
753 /* Call hook procedure to check whether is it OK to delete this DC */
754 if (dc
->hookThunk
&& !(dc
->flags
& (DC_SAVED
| DC_MEMORY
)))
756 DCHOOKPROC proc
= dc
->hookThunk
;
759 DWORD data
= dc
->dwHookData
;
760 GDI_ReleaseObj( hdc
);
761 if (!proc( hdc
, DCHC_DELETEDC
, data
, 0 )) return FALSE
;
762 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
766 while (dc
->saveLevel
)
769 HDC16 hdcs
= dc
->header
.hNext
;
770 if (!(dcs
= GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
771 dc
->header
.hNext
= dcs
->header
.hNext
;
773 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
774 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
775 if (dcs
->hGCClipRgn
) DeleteObject( dcs
->hGCClipRgn
);
776 PATH_DestroyGdiPath(&dcs
->path
);
777 GDI_FreeObject( hdcs
, dcs
);
780 if (!(dc
->flags
& DC_SAVED
))
782 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
783 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
784 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
785 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
787 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
790 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
791 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
792 if (dc
->hGCClipRgn
) DeleteObject( dc
->hGCClipRgn
);
793 PATH_DestroyGdiPath(&dc
->path
);
795 GDI_FreeObject( hdc
, dc
);
796 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
801 /***********************************************************************
804 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODEA
*devmode
)
811 /***********************************************************************
814 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
821 /***********************************************************************
824 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
831 /***********************************************************************
832 * GetDeviceCaps (GDI.80)
834 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
836 INT16 ret
= GetDeviceCaps( hdc
, cap
);
837 /* some apps don't expect -1 and think it's a B&W screen */
838 if ((cap
== NUMCOLORS
) && (ret
== -1)) ret
= 2048;
843 /***********************************************************************
844 * GetDeviceCaps (GDI32.@)
846 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
851 if ((dc
= DC_GetDCPtr( hdc
)))
853 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
854 GDI_ReleaseObj( hdc
);
860 /***********************************************************************
863 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
865 return SetBkColor( hdc
, color
);
869 /***********************************************************************
870 * SetBkColor (GDI32.@)
872 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
875 DC
* dc
= DC_GetDCPtr( hdc
);
877 if (!dc
) return CLR_INVALID
;
878 oldColor
= dc
->backgroundColor
;
879 if (dc
->funcs
->pSetBkColor
)
881 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
882 if (color
== CLR_INVALID
) /* don't change it */
885 oldColor
= CLR_INVALID
;
888 dc
->backgroundColor
= color
;
889 GDI_ReleaseObj( hdc
);
894 /***********************************************************************
895 * SetTextColor (GDI.9)
897 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
899 return SetTextColor( hdc
, color
);
903 /***********************************************************************
904 * SetTextColor (GDI32.@)
906 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
909 DC
* dc
= DC_GetDCPtr( hdc
);
911 if (!dc
) return CLR_INVALID
;
912 oldColor
= dc
->textColor
;
913 if (dc
->funcs
->pSetTextColor
)
915 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
916 if (color
== CLR_INVALID
) /* don't change it */
919 oldColor
= CLR_INVALID
;
922 dc
->textColor
= color
;
923 GDI_ReleaseObj( hdc
);
927 /***********************************************************************
928 * SetTextAlign (GDI.346)
930 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 align
)
932 return SetTextAlign( hdc
, align
);
936 /***********************************************************************
937 * SetTextAlign (GDI32.@)
939 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
942 DC
*dc
= DC_GetDCPtr( hdc
);
944 if (dc
->funcs
->pSetTextAlign
)
945 prevAlign
= dc
->funcs
->pSetTextAlign(dc
->physDev
, align
);
947 prevAlign
= dc
->textAlign
;
948 dc
->textAlign
= align
;
950 GDI_ReleaseObj( hdc
);
954 /***********************************************************************
955 * GetDCOrgEx (GDI32.@)
957 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
961 if (!lpp
) return FALSE
;
962 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
965 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
966 lpp
->x
+= dc
->DCOrgX
;
967 lpp
->y
+= dc
->DCOrgY
;
968 GDI_ReleaseObj( hDC
);
973 /***********************************************************************
976 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
979 if( GetDCOrgEx( hdc
, &pt
) )
980 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
985 /***********************************************************************
988 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
991 DC
*dc
= DC_GetDCPtr( hdc
);
993 prevOrg
= dc
->DCOrgX
| (dc
->DCOrgY
<< 16);
996 GDI_ReleaseObj( hdc
);
1001 /***********************************************************************
1002 * SetGraphicsMode (GDI32.@)
1004 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1007 DC
*dc
= DC_GetDCPtr( hdc
);
1009 /* One would think that setting the graphics mode to GM_COMPATIBLE
1010 * would also reset the world transformation matrix to the unity
1011 * matrix. However, in Windows, this is not the case. This doesn't
1012 * make a lot of sense to me, but that's the way it is.
1015 if ((mode
> 0) || (mode
<= GM_LAST
))
1017 ret
= dc
->GraphicsMode
;
1018 dc
->GraphicsMode
= mode
;
1020 GDI_ReleaseObj( hdc
);
1025 /***********************************************************************
1026 * SetArcDirection (GDI.525)
1028 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
1030 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
1034 /***********************************************************************
1035 * SetArcDirection (GDI32.@)
1037 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1040 INT nOldDirection
= 0;
1042 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1044 SetLastError(ERROR_INVALID_PARAMETER
);
1048 if ((dc
= DC_GetDCPtr( hdc
)))
1050 nOldDirection
= dc
->ArcDirection
;
1051 dc
->ArcDirection
= nDirection
;
1052 GDI_ReleaseObj( hdc
);
1054 return nOldDirection
;
1058 /***********************************************************************
1059 * GetWorldTransform (GDI32.@)
1061 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1064 if (!xform
) return FALSE
;
1065 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1066 *xform
= dc
->xformWorld2Wnd
;
1067 GDI_ReleaseObj( hdc
);
1072 /***********************************************************************
1073 * SetWorldTransform (GDI32.@)
1075 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1078 DC
*dc
= DC_GetDCPtr( hdc
);
1080 if (!dc
) return FALSE
;
1081 if (!xform
) goto done
;
1083 /* Check that graphics mode is GM_ADVANCED */
1084 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1086 dc
->xformWorld2Wnd
= *xform
;
1087 DC_UpdateXforms( dc
);
1090 GDI_ReleaseObj( hdc
);
1095 /****************************************************************************
1096 * ModifyWorldTransform [GDI32.@]
1097 * Modifies the world transformation for a device context.
1100 * hdc [I] Handle to device context
1101 * xform [I] XFORM structure that will be used to modify the world
1103 * iMode [I] Specifies in what way to modify the world transformation
1106 * Resets the world transformation to the identity matrix.
1107 * The parameter xform is ignored.
1109 * Multiplies xform into the world transformation matrix from
1112 * Multiplies xform into the world transformation matrix from
1117 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1121 DC
*dc
= DC_GetDCPtr( hdc
);
1123 /* Check for illegal parameters */
1124 if (!dc
) return FALSE
;
1125 if (!xform
) goto done
;
1127 /* Check that graphics mode is GM_ADVANCED */
1128 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1133 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1134 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1135 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1136 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1137 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1138 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1140 case MWT_LEFTMULTIPLY
:
1141 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1142 &dc
->xformWorld2Wnd
);
1144 case MWT_RIGHTMULTIPLY
:
1145 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1152 DC_UpdateXforms( dc
);
1155 GDI_ReleaseObj( hdc
);
1160 /****************************************************************************
1161 * CombineTransform [GDI32.@]
1162 * Combines two transformation matrices.
1165 * xformResult [O] Stores the result of combining the two matrices
1166 * xform1 [I] Specifies the first matrix to apply
1167 * xform2 [I] Specifies the second matrix to apply
1170 * The same matrix can be passed in for more than one of the parameters.
1174 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1175 const XFORM
*xform2
)
1179 /* Check for illegal parameters */
1180 if (!xformResult
|| !xform1
|| !xform2
)
1183 /* Create the result in a temporary XFORM, since xformResult may be
1184 * equal to xform1 or xform2 */
1185 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1186 xform1
->eM12
* xform2
->eM21
;
1187 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1188 xform1
->eM12
* xform2
->eM22
;
1189 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1190 xform1
->eM22
* xform2
->eM21
;
1191 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1192 xform1
->eM22
* xform2
->eM22
;
1193 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1194 xform1
->eDy
* xform2
->eM21
+
1196 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1197 xform1
->eDy
* xform2
->eM22
+
1200 /* Copy the result to xformResult */
1201 *xformResult
= xformTemp
;
1207 /***********************************************************************
1208 * SetDCHook (GDI32.@)
1210 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1212 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1214 DC
*dc
= DC_GetDCPtr( hdc
);
1216 if (!dc
) return FALSE
;
1217 dc
->dwHookData
= dwHookData
;
1218 dc
->hookThunk
= hookProc
;
1219 GDI_ReleaseObj( hdc
);
1224 /* relay function to call the 16-bit DC hook proc */
1225 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc
, WORD code
, DWORD data
, LPARAM lParam
)
1227 FARPROC16 proc
= NULL
;
1228 DC
*dc
= DC_GetDCPtr( hdc
);
1229 if (!dc
) return FALSE
;
1230 proc
= dc
->hookProc
;
1231 GDI_ReleaseObj( hdc
);
1232 if (!proc
) return FALSE
;
1233 return GDI_CallTo16_word_wwll( proc
, hdc
, code
, data
, lParam
);
1236 /***********************************************************************
1237 * SetDCHook (GDI.190)
1239 BOOL16 WINAPI
SetDCHook16( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1241 DC
*dc
= DC_GetDCPtr( hdc
);
1242 if (!dc
) return FALSE
;
1244 dc
->hookProc
= hookProc
;
1245 GDI_ReleaseObj( hdc
);
1246 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1250 /***********************************************************************
1251 * GetDCHook (GDI.191)
1253 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1255 DC
*dc
= DC_GetDCPtr( hdc
);
1257 *phookProc
= dc
->hookProc
;
1258 GDI_ReleaseObj( hdc
);
1259 return dc
->dwHookData
;
1263 /***********************************************************************
1264 * SetHookFlags (GDI.192)
1266 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1268 DC
*dc
= DC_GetDCPtr( hDC
);
1272 WORD wRet
= dc
->flags
& DC_DIRTY
;
1274 /* "Undocumented Windows" info is slightly confusing.
1277 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1279 if( flags
& DCHF_INVALIDATEVISRGN
)
1280 dc
->flags
|= DC_DIRTY
;
1281 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1282 dc
->flags
&= ~DC_DIRTY
;
1283 GDI_ReleaseObj( hDC
);
1289 /***********************************************************************
1290 * SetICMMode (GDI32.@)
1292 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1294 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1295 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1296 if (iEnableICM
== ICM_ON
) return 0;
1297 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1301 /***********************************************************************
1302 * GetDeviceGammaRamp (GDI32.@)
1304 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1307 DC
*dc
= DC_GetDCPtr( hDC
);
1311 if (dc
->funcs
->pGetDeviceGammaRamp
)
1312 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1313 GDI_ReleaseObj( hDC
);
1318 /***********************************************************************
1319 * SetDeviceGammaRamp (GDI32.@)
1321 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1324 DC
*dc
= DC_GetDCPtr( hDC
);
1328 if (dc
->funcs
->pSetDeviceGammaRamp
)
1329 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1330 GDI_ReleaseObj( hDC
);
1335 /***********************************************************************
1336 * GetColorSpace (GDI32.@)
1338 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1340 /*FIXME Need to to whatever GetColorSpace actually does */
1344 /***********************************************************************
1345 * CreateColorSpaceA (GDI32.@)
1347 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1353 /***********************************************************************
1354 * CreateColorSpaceW (GDI32.@)
1356 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1362 /***********************************************************************
1363 * DeleteColorSpace (GDI32.@)
1365 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1372 /***********************************************************************
1373 * SetColorSpace (GDI32.@)
1375 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1382 /***********************************************************************
1383 * GetBoundsRect (GDI.194)
1385 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1387 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1390 /***********************************************************************
1391 * GetBoundsRect (GDI32.@)
1393 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1395 FIXME("(): stub\n");
1396 return DCB_RESET
; /* bounding rectangle always empty */
1399 /***********************************************************************
1400 * SetBoundsRect (GDI.193)
1402 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1404 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1405 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1407 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1410 /***********************************************************************
1411 * SetBoundsRect (GDI32.@)
1413 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1415 FIXME("(): stub\n");
1416 return DCB_DISABLE
; /* bounding rectangle always empty */
1420 /***********************************************************************
1421 * GetRelAbs (GDI32.@)
1423 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1426 DC
*dc
= DC_GetDCPtr( hdc
);
1427 if (dc
) ret
= dc
->relAbsMode
;
1428 GDI_ReleaseObj( hdc
);
1432 /***********************************************************************
1435 * Disables GDI, switches back to text mode.
1436 * We don't have to do anything here,
1437 * just let console support handle everything
1439 void WINAPI
Death16(HDC16 hDC
)
1441 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1444 /***********************************************************************
1445 * Resurrection (GDI.122)
1447 * Restores GDI functionality
1449 void WINAPI
Resurrection16(HDC16 hDC
,
1450 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1452 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1455 /***********************************************************************
1456 * GetLayout (GDI32.@)
1458 * Gets left->right or right->left text layout flags of a dc.
1459 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1462 DWORD WINAPI
GetLayout(HDC hdc
)
1464 FIXME("(%08x): stub\n", hdc
);
1465 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1469 /***********************************************************************
1470 * SetLayout (GDI32.@)
1472 * Sets left->right or right->left text layout flags of a dc.
1473 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1476 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1478 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1479 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);