2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
20 #include "wine/winuser16.h"
22 /***********************************************************************
25 * Fill the WIN_DC_INFO structure.
27 static void DC_Init_DC_INFO( WIN_DC_INFO
*win_dc_info
)
29 win_dc_info
->flags
= 0;
30 win_dc_info
->devCaps
= NULL
;
31 win_dc_info
->hClipRgn
= 0;
32 win_dc_info
->hVisRgn
= 0;
33 win_dc_info
->hGCClipRgn
= 0;
34 win_dc_info
->hPen
= STOCK_BLACK_PEN
;
35 win_dc_info
->hBrush
= STOCK_WHITE_BRUSH
;
36 win_dc_info
->hFont
= STOCK_SYSTEM_FONT
;
37 win_dc_info
->hBitmap
= 0;
38 win_dc_info
->hFirstBitmap
= 0;
39 win_dc_info
->hDevice
= 0;
40 win_dc_info
->hPalette
= STOCK_DEFAULT_PALETTE
;
41 win_dc_info
->ROPmode
= R2_COPYPEN
;
42 win_dc_info
->polyFillMode
= ALTERNATE
;
43 win_dc_info
->stretchBltMode
= BLACKONWHITE
;
44 win_dc_info
->relAbsMode
= ABSOLUTE
;
45 win_dc_info
->backgroundMode
= OPAQUE
;
46 win_dc_info
->backgroundColor
= RGB( 255, 255, 255 );
47 win_dc_info
->textColor
= RGB( 0, 0, 0 );
48 win_dc_info
->brushOrgX
= 0;
49 win_dc_info
->brushOrgY
= 0;
50 win_dc_info
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
51 win_dc_info
->charExtra
= 0;
52 win_dc_info
->breakTotalExtra
= 0;
53 win_dc_info
->breakCount
= 0;
54 win_dc_info
->breakExtra
= 0;
55 win_dc_info
->breakRem
= 0;
56 win_dc_info
->bitsPerPixel
= 1;
57 win_dc_info
->MapMode
= MM_TEXT
;
58 win_dc_info
->GraphicsMode
= GM_COMPATIBLE
;
59 win_dc_info
->DCOrgX
= 0;
60 win_dc_info
->DCOrgY
= 0;
61 win_dc_info
->lpfnPrint
= NULL
;
62 win_dc_info
->CursPosX
= 0;
63 win_dc_info
->CursPosY
= 0;
64 win_dc_info
->ArcDirection
= AD_COUNTERCLOCKWISE
;
65 win_dc_info
->xformWorld2Wnd
.eM11
= 1.0f
;
66 win_dc_info
->xformWorld2Wnd
.eM12
= 0.0f
;
67 win_dc_info
->xformWorld2Wnd
.eM21
= 0.0f
;
68 win_dc_info
->xformWorld2Wnd
.eM22
= 1.0f
;
69 win_dc_info
->xformWorld2Wnd
.eDx
= 0.0f
;
70 win_dc_info
->xformWorld2Wnd
.eDy
= 0.0f
;
71 win_dc_info
->xformWorld2Vport
= win_dc_info
->xformWorld2Wnd
;
72 win_dc_info
->xformVport2World
= win_dc_info
->xformWorld2Wnd
;
73 win_dc_info
->vport2WorldValid
= TRUE
;
75 PATH_InitGdiPath(&win_dc_info
->path
);
79 /***********************************************************************
82 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
87 if (!(hdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
))) return NULL
;
88 dc
= (DC
*) GDI_HEAP_LOCK( hdc
);
105 DC_Init_DC_INFO( &dc
->w
);
112 /***********************************************************************
115 DC
*DC_GetDCPtr( HDC hdc
)
117 GDIOBJHDR
*ptr
= (GDIOBJHDR
*)GDI_HEAP_LOCK( hdc
);
118 if (!ptr
) return NULL
;
119 if ((ptr
->wMagic
== DC_MAGIC
) || (ptr
->wMagic
== METAFILE_DC_MAGIC
))
121 GDI_HEAP_UNLOCK( hdc
);
126 /***********************************************************************
129 * Setup device-specific DC values for a newly created DC.
131 void DC_InitDC( DC
* dc
)
133 RealizeDefaultPalette16( dc
->hSelf
);
134 SetTextColor( dc
->hSelf
, dc
->w
.textColor
);
135 SetBkColor( dc
->hSelf
, dc
->w
.backgroundColor
);
136 SelectObject( dc
->hSelf
, dc
->w
.hPen
);
137 SelectObject( dc
->hSelf
, dc
->w
.hBrush
);
138 SelectObject( dc
->hSelf
, dc
->w
.hFont
);
139 CLIPPING_UpdateGCRegion( dc
);
143 /***********************************************************************
146 * Computes the inverse of the transformation xformSrc and stores it to
147 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
150 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
154 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
155 xformSrc
->eM12
*xformSrc
->eM21
;
156 if (determinant
> -1e-12 && determinant
< 1e-12)
159 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
160 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
161 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
162 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
163 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
164 xformSrc
->eDy
* xformDest
->eM21
;
165 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
166 xformSrc
->eDy
* xformDest
->eM22
;
172 /***********************************************************************
175 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
176 * fields of the specified DC by creating a transformation that
177 * represents the current mapping mode and combining it with the DC's
178 * world transform. This function should be called whenever the
179 * parameters associated with the mapping mode (window and viewport
180 * extents and origins) or the world transform change.
182 void DC_UpdateXforms( DC
*dc
)
184 XFORM xformWnd2Vport
;
185 FLOAT scaleX
, scaleY
;
187 /* Construct a transformation to do the window-to-viewport conversion */
188 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
189 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
190 xformWnd2Vport
.eM11
= scaleX
;
191 xformWnd2Vport
.eM12
= 0.0;
192 xformWnd2Vport
.eM21
= 0.0;
193 xformWnd2Vport
.eM22
= scaleY
;
194 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
195 scaleX
* (FLOAT
)dc
->wndOrgX
;
196 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
197 scaleY
* (FLOAT
)dc
->wndOrgY
;
199 /* Combine with the world transformation */
200 CombineTransform( &dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
,
203 /* Create inverse of world-to-viewport transformation */
204 dc
->w
.vport2WorldValid
= DC_InvertXform( &dc
->w
.xformWorld2Vport
,
205 &dc
->w
.xformVport2World
);
209 /***********************************************************************
210 * GetDCState (GDI.179)
212 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
217 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
218 if (!(handle
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
)))
220 GDI_HEAP_UNLOCK( hdc
);
223 newdc
= (DC
*) GDI_HEAP_LOCK( handle
);
225 TRACE(dc
, "(%04x): returning %04x\n", hdc
, handle
);
227 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
228 newdc
->w
.devCaps
= dc
->w
.devCaps
;
229 newdc
->w
.hPen
= dc
->w
.hPen
;
230 newdc
->w
.hBrush
= dc
->w
.hBrush
;
231 newdc
->w
.hFont
= dc
->w
.hFont
;
232 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
233 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
234 newdc
->w
.hDevice
= dc
->w
.hDevice
;
235 newdc
->w
.hPalette
= dc
->w
.hPalette
;
236 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
237 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
238 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
239 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
240 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
241 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
242 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
243 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
244 newdc
->w
.textColor
= dc
->w
.textColor
;
245 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
246 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
247 newdc
->w
.textAlign
= dc
->w
.textAlign
;
248 newdc
->w
.charExtra
= dc
->w
.charExtra
;
249 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
250 newdc
->w
.breakCount
= dc
->w
.breakCount
;
251 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
252 newdc
->w
.breakRem
= dc
->w
.breakRem
;
253 newdc
->w
.MapMode
= dc
->w
.MapMode
;
254 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
256 /* Apparently, the DC origin is not changed by [GS]etDCState */
257 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
258 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
260 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
261 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
262 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
263 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
264 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
265 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
266 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
267 newdc
->wndOrgX
= dc
->wndOrgX
;
268 newdc
->wndOrgY
= dc
->wndOrgY
;
269 newdc
->wndExtX
= dc
->wndExtX
;
270 newdc
->wndExtY
= dc
->wndExtY
;
271 newdc
->vportOrgX
= dc
->vportOrgX
;
272 newdc
->vportOrgY
= dc
->vportOrgY
;
273 newdc
->vportExtX
= dc
->vportExtX
;
274 newdc
->vportExtY
= dc
->vportExtY
;
276 newdc
->hSelf
= (HDC
)handle
;
277 newdc
->saveLevel
= 0;
279 PATH_InitGdiPath( &newdc
->w
.path
);
281 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
283 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
286 newdc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
287 CombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
290 newdc
->w
.hClipRgn
= 0;
291 GDI_HEAP_UNLOCK( handle
);
292 GDI_HEAP_UNLOCK( hdc
);
297 /***********************************************************************
298 * SetDCState (GDI.180)
300 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
304 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
305 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
307 GDI_HEAP_UNLOCK( hdc
);
310 if (!dcs
->w
.flags
& DC_SAVED
)
312 GDI_HEAP_UNLOCK( hdc
);
313 GDI_HEAP_UNLOCK( hdcs
);
316 TRACE(dc
, "%04x %04x\n", hdc
, hdcs
);
318 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
319 dc
->w
.devCaps
= dcs
->w
.devCaps
;
320 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
321 dc
->w
.hDevice
= dcs
->w
.hDevice
;
322 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
323 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
324 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
325 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
326 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
327 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
328 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
329 dc
->w
.textColor
= dcs
->w
.textColor
;
330 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
331 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
332 dc
->w
.textAlign
= dcs
->w
.textAlign
;
333 dc
->w
.charExtra
= dcs
->w
.charExtra
;
334 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
335 dc
->w
.breakCount
= dcs
->w
.breakCount
;
336 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
337 dc
->w
.breakRem
= dcs
->w
.breakRem
;
338 dc
->w
.MapMode
= dcs
->w
.MapMode
;
339 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
341 /* Apparently, the DC origin is not changed by [GS]etDCState */
342 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
343 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
345 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
346 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
347 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
348 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
349 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
350 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
351 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
353 dc
->wndOrgX
= dcs
->wndOrgX
;
354 dc
->wndOrgY
= dcs
->wndOrgY
;
355 dc
->wndExtX
= dcs
->wndExtX
;
356 dc
->wndExtY
= dcs
->wndExtY
;
357 dc
->vportOrgX
= dcs
->vportOrgX
;
358 dc
->vportOrgY
= dcs
->vportOrgY
;
359 dc
->vportExtX
= dcs
->vportExtX
;
360 dc
->vportExtY
= dcs
->vportExtY
;
362 if (!(dc
->w
.flags
& DC_MEMORY
)) dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
366 if (!dc
->w
.hClipRgn
) dc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
367 CombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
371 if (dc
->w
.hClipRgn
) DeleteObject16( dc
->w
.hClipRgn
);
374 CLIPPING_UpdateGCRegion( dc
);
376 SelectObject( hdc
, dcs
->w
.hBitmap
);
377 SelectObject( hdc
, dcs
->w
.hBrush
);
378 SelectObject( hdc
, dcs
->w
.hFont
);
379 SelectObject( hdc
, dcs
->w
.hPen
);
380 SetBkColor( hdc
, dcs
->w
.backgroundColor
);
381 SetTextColor( hdc
, dcs
->w
.textColor
);
382 GDISelectPalette16( hdc
, dcs
->w
.hPalette
, FALSE
);
383 GDI_HEAP_UNLOCK( hdc
);
384 GDI_HEAP_UNLOCK( hdcs
);
388 /***********************************************************************
391 INT16 WINAPI
SaveDC16( HDC16 hdc
)
393 return (INT16
)SaveDC( hdc
);
397 /***********************************************************************
398 * SaveDC32 (GDI32.292)
400 INT WINAPI
SaveDC( HDC hdc
)
406 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
409 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
411 MF_MetaParam0(dc
, META_SAVEDC
);
412 GDI_HEAP_UNLOCK( hdc
);
415 if (!(hdcs
= GetDCState16( hdc
)))
417 GDI_HEAP_UNLOCK( hdc
);
420 dcs
= (DC
*) GDI_HEAP_LOCK( hdcs
);
422 /* Copy path. The reason why path saving / restoring is in SaveDC/
423 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
424 * functions are only in Win16 (which doesn't have paths) and that
425 * SetDCState doesn't allow us to signal an error (which can happen
426 * when copying paths).
428 if (!PATH_AssignGdiPath( &dcs
->w
.path
, &dc
->w
.path
))
430 GDI_HEAP_UNLOCK( hdc
);
431 GDI_HEAP_UNLOCK( hdcs
);
436 dcs
->header
.hNext
= dc
->header
.hNext
;
437 dc
->header
.hNext
= hdcs
;
438 TRACE(dc
, "(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
439 ret
= ++dc
->saveLevel
;
440 GDI_HEAP_UNLOCK( hdcs
);
441 GDI_HEAP_UNLOCK( hdc
);
446 /***********************************************************************
447 * RestoreDC16 (GDI.39)
449 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
451 return RestoreDC( hdc
, level
);
455 /***********************************************************************
456 * RestoreDC32 (GDI32.290)
458 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
463 TRACE(dc
, "%04x %d\n", hdc
, level
);
464 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
467 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
468 if (!dc
) return FALSE
;
471 GDI_HEAP_UNLOCK( hdc
);
474 MF_MetaParam1(dc
, META_RESTOREDC
, level
);
475 GDI_HEAP_UNLOCK( hdc
);
478 if (level
== -1) level
= dc
->saveLevel
;
479 if ((level
< 1) || (level
> dc
->saveLevel
))
481 GDI_HEAP_UNLOCK( hdc
);
486 while (dc
->saveLevel
>= level
)
488 HDC16 hdcs
= dc
->header
.hNext
;
489 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
491 GDI_HEAP_UNLOCK( hdc
);
494 dc
->header
.hNext
= dcs
->header
.hNext
;
495 if (--dc
->saveLevel
< level
)
497 SetDCState16( hdc
, hdcs
);
498 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
499 /* FIXME: This might not be quite right, since we're
500 * returning FALSE but still destroying the saved DC state */
505 GDI_HEAP_UNLOCK( hdc
);
510 /***********************************************************************
511 * CreateDC16 (GDI.53)
513 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
514 const DEVMODE16
*initData
)
517 const DC_FUNCTIONS
*funcs
;
519 if (!(funcs
= DRIVER_FindDriver( driver
))) return 0;
520 if (!(dc
= DC_AllocDC( funcs
))) return 0;
523 TRACE(dc
, "(driver=%s, device=%s, output=%s): returning %04x\n",
524 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
526 if (dc
->funcs
->pCreateDC
&&
527 !dc
->funcs
->pCreateDC( dc
, driver
, device
, output
, initData
))
529 WARN(dc
, "creation aborted by device\n" );
530 GDI_HEAP_FREE( dc
->hSelf
);
535 GDI_HEAP_UNLOCK( dc
->hSelf
);
540 /***********************************************************************
541 * CreateDC32A (GDI32.)
543 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
544 const DEVMODEA
*initData
)
546 return CreateDC16( driver
, device
, output
, (const DEVMODE16
*)initData
);
550 /***********************************************************************
551 * CreateDC32W (GDI32.)
553 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
554 const DEVMODEW
*initData
)
556 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
557 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
558 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
559 HDC res
= CreateDC16( driverA
, deviceA
, outputA
,
560 (const DEVMODE16
*)initData
/*FIXME*/ );
561 HeapFree( GetProcessHeap(), 0, driverA
);
562 HeapFree( GetProcessHeap(), 0, deviceA
);
563 HeapFree( GetProcessHeap(), 0, outputA
);
568 /***********************************************************************
569 * CreateIC16 (GDI.153)
571 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
572 const DEVMODE16
* initData
)
574 /* Nothing special yet for ICs */
575 return CreateDC16( driver
, device
, output
, initData
);
579 /***********************************************************************
580 * CreateIC32A (GDI32.49)
582 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
583 const DEVMODEA
* initData
)
585 /* Nothing special yet for ICs */
586 return CreateDCA( driver
, device
, output
, initData
);
590 /***********************************************************************
591 * CreateIC32W (GDI32.50)
593 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
594 const DEVMODEW
* initData
)
596 /* Nothing special yet for ICs */
597 return CreateDCW( driver
, device
, output
, initData
);
601 /***********************************************************************
602 * CreateCompatibleDC16 (GDI.52)
604 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
606 return (HDC16
)CreateCompatibleDC( hdc
);
610 /***********************************************************************
611 * CreateCompatibleDC32 (GDI32.31)
613 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
617 const DC_FUNCTIONS
*funcs
;
619 if ((origDC
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
))) funcs
= origDC
->funcs
;
620 else funcs
= DRIVER_FindDriver( "DISPLAY" );
621 if (!funcs
) return 0;
623 if (!(dc
= DC_AllocDC( funcs
))) return 0;
625 TRACE(dc
, "(%04x): returning %04x\n",
628 /* Create default bitmap */
629 if (!(hbitmap
= CreateBitmap( 1, 1, 1, 1, NULL
)))
631 GDI_HEAP_FREE( dc
->hSelf
);
634 dc
->w
.flags
= DC_MEMORY
;
635 dc
->w
.bitsPerPixel
= 1;
636 dc
->w
.hBitmap
= hbitmap
;
637 dc
->w
.hFirstBitmap
= hbitmap
;
639 if (dc
->funcs
->pCreateDC
&&
640 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
642 WARN(dc
, "creation aborted by device\n");
643 DeleteObject( hbitmap
);
644 GDI_HEAP_FREE( dc
->hSelf
);
649 GDI_HEAP_UNLOCK( dc
->hSelf
);
654 /***********************************************************************
655 * DeleteDC16 (GDI.68)
657 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
659 return DeleteDC( hdc
);
663 /***********************************************************************
664 * DeleteDC32 (GDI32.67)
666 BOOL WINAPI
DeleteDC( HDC hdc
)
668 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
669 if (!dc
) return FALSE
;
671 TRACE(dc
, "%04x\n", hdc
);
673 while (dc
->saveLevel
)
676 HDC16 hdcs
= dc
->header
.hNext
;
677 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
678 dc
->header
.hNext
= dcs
->header
.hNext
;
683 if (!(dc
->w
.flags
& DC_SAVED
))
685 SelectObject( hdc
, STOCK_BLACK_PEN
);
686 SelectObject( hdc
, STOCK_WHITE_BRUSH
);
687 SelectObject( hdc
, STOCK_SYSTEM_FONT
);
688 if (dc
->w
.flags
& DC_MEMORY
) DeleteObject( dc
->w
.hFirstBitmap
);
689 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
692 if (dc
->w
.hClipRgn
) DeleteObject( dc
->w
.hClipRgn
);
693 if (dc
->w
.hVisRgn
) DeleteObject( dc
->w
.hVisRgn
);
694 if (dc
->w
.hGCClipRgn
) DeleteObject( dc
->w
.hGCClipRgn
);
696 PATH_DestroyGdiPath(&dc
->w
.path
);
698 return GDI_FreeObject( hdc
);
702 /***********************************************************************
703 * ResetDC16 (GDI.376)
705 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODE16
*devmode
)
707 FIXME(dc
, "stub\n" );
712 /***********************************************************************
713 * ResetDC32A (GDI32.287)
715 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
717 FIXME(dc
, "stub\n" );
722 /***********************************************************************
723 * ResetDC32W (GDI32.288)
725 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
727 FIXME(dc
, "stub\n" );
732 /***********************************************************************
733 * GetDeviceCaps16 (GDI.80)
735 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
737 return GetDeviceCaps( hdc
, cap
);
741 /***********************************************************************
742 * GetDeviceCaps32 (GDI32.171)
744 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
746 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
751 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
)))
753 GDI_HEAP_UNLOCK( hdc
);
757 TRACE(dc
, "(%04x,%d): returning %d\n",
758 hdc
, cap
, *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
) );
759 ret
= *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
);
760 GDI_HEAP_UNLOCK( hdc
);
765 /***********************************************************************
766 * SetBkColor16 (GDI.1)
768 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
770 return SetBkColor( hdc
, color
);
774 /***********************************************************************
775 * SetBkColor32 (GDI32.305)
777 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
780 DC
* dc
= DC_GetDCPtr( hdc
);
782 if (!dc
) return 0x80000000;
783 if (dc
->funcs
->pSetBkColor
)
784 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
786 oldColor
= dc
->w
.backgroundColor
;
787 dc
->w
.backgroundColor
= color
;
789 GDI_HEAP_UNLOCK( hdc
);
794 /***********************************************************************
795 * SetTextColor16 (GDI.9)
797 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
799 return SetTextColor( hdc
, color
);
803 /***********************************************************************
804 * SetTextColor32 (GDI32.338)
806 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
809 DC
* dc
= DC_GetDCPtr( hdc
);
811 if (!dc
) return 0x80000000;
812 if (dc
->funcs
->pSetTextColor
)
813 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
815 oldColor
= dc
->w
.textColor
;
816 dc
->w
.textColor
= color
;
818 GDI_HEAP_UNLOCK( hdc
);
823 /***********************************************************************
824 * SetTextAlign16 (GDI.346)
826 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 textAlign
)
828 return SetTextAlign( hdc
, textAlign
);
832 /***********************************************************************
833 * SetTextAlign32 (GDI32.336)
835 UINT WINAPI
SetTextAlign( HDC hdc
, UINT textAlign
)
838 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
841 if (!(dc
= (DC
*)GDI_GetObjPtr( hdc
, METAFILE_DC_MAGIC
))) return 0;
842 MF_MetaParam1( dc
, META_SETTEXTALIGN
, textAlign
);
843 GDI_HEAP_UNLOCK( hdc
);
846 prevAlign
= dc
->w
.textAlign
;
847 dc
->w
.textAlign
= textAlign
;
848 GDI_HEAP_UNLOCK( hdc
);
853 /***********************************************************************
854 * GetDCOrgEx (GDI32.168)
856 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
859 X11DRV_PDEVICE
*physDev
;
861 if (!lpp
) return FALSE
;
862 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return FALSE
;
863 physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
865 if (!(dc
->w
.flags
& DC_MEMORY
))
868 int w
, h
, border
, depth
;
869 /* FIXME: this is not correct for managed windows */
870 TSXGetGeometry( display
, physDev
->drawable
, &root
,
871 (int*)&lpp
->x
, (int*)&lpp
->y
, &w
, &h
, &border
, &depth
);
873 else lpp
->x
= lpp
->y
= 0;
874 lpp
->x
+= dc
->w
.DCOrgX
; lpp
->y
+= dc
->w
.DCOrgY
;
875 GDI_HEAP_UNLOCK( hDC
);
880 /***********************************************************************
883 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
886 if( GetDCOrgEx( hdc
, &pt
) )
887 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
892 /***********************************************************************
895 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
898 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
900 prevOrg
= dc
->w
.DCOrgX
| (dc
->w
.DCOrgY
<< 16);
903 GDI_HEAP_UNLOCK( hdc
);
908 /***********************************************************************
909 * GetGraphicsMode (GDI32.188)
911 INT WINAPI
GetGraphicsMode( HDC hdc
)
913 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
915 return dc
->w
.GraphicsMode
;
919 /***********************************************************************
920 * SetGraphicsMode (GDI32.317)
922 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
925 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
927 /* One would think that setting the graphics mode to GM_COMPATIBLE
928 * would also reset the world transformation matrix to the unity
929 * matrix. However, in Windows, this is not the case. This doesn't
930 * make a lot of sense to me, but that's the way it is.
934 if ((mode
<= 0) || (mode
> GM_LAST
)) return 0;
935 ret
= dc
->w
.GraphicsMode
;
936 dc
->w
.GraphicsMode
= mode
;
941 /***********************************************************************
942 * GetArcDirection16 (GDI.524)
944 INT16 WINAPI
GetArcDirection16( HDC16 hdc
)
946 return GetArcDirection( (HDC
)hdc
);
950 /***********************************************************************
951 * GetArcDirection32 (GDI32.141)
953 INT WINAPI
GetArcDirection( HDC hdc
)
955 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
960 return dc
->w
.ArcDirection
;
964 /***********************************************************************
965 * SetArcDirection16 (GDI.525)
967 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
969 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
973 /***********************************************************************
974 * SetArcDirection32 (GDI32.302)
976 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
978 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
984 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
986 SetLastError(ERROR_INVALID_PARAMETER
);
990 nOldDirection
= dc
->w
.ArcDirection
;
991 dc
->w
.ArcDirection
= nDirection
;
993 return nOldDirection
;
997 /***********************************************************************
998 * GetWorldTransform (GDI32.244)
1000 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1002 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1009 *xform
= dc
->w
.xformWorld2Wnd
;
1015 /***********************************************************************
1016 * SetWorldTransform (GDI32.346)
1018 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1020 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1024 SetLastError( ERROR_INVALID_HANDLE
);
1031 /* Check that graphics mode is GM_ADVANCED */
1032 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1035 dc
->w
.xformWorld2Wnd
= *xform
;
1037 DC_UpdateXforms( dc
);
1043 /****************************************************************************
1044 * ModifyWorldTransform [GDI32.253]
1045 * Modifies the world transformation for a device context.
1048 * hdc [I] Handle to device context
1049 * xform [I] XFORM structure that will be used to modify the world
1051 * iMode [I] Specifies in what way to modify the world transformation
1054 * Resets the world transformation to the identity matrix.
1055 * The parameter xform is ignored.
1057 * Multiplies xform into the world transformation matrix from
1060 * Multiplies xform into the world transformation matrix from
1065 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1068 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1070 /* Check for illegal parameters */
1073 SetLastError( ERROR_INVALID_HANDLE
);
1079 /* Check that graphics mode is GM_ADVANCED */
1080 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1086 dc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1087 dc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1088 dc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1089 dc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1090 dc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1091 dc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1093 case MWT_LEFTMULTIPLY
:
1094 CombineTransform( &dc
->w
.xformWorld2Wnd
, xform
,
1095 &dc
->w
.xformWorld2Wnd
);
1097 case MWT_RIGHTMULTIPLY
:
1098 CombineTransform( &dc
->w
.xformWorld2Wnd
, &dc
->w
.xformWorld2Wnd
,
1105 DC_UpdateXforms( dc
);
1111 /****************************************************************************
1112 * CombineTransform [GDI32.20]
1113 * Combines two transformation matrices.
1116 * xformResult [O] Stores the result of combining the two matrices
1117 * xform1 [I] Specifies the first matrix to apply
1118 * xform2 [I] Specifies the second matrix to apply
1121 * The same matrix can be passed in for more than one of the parameters.
1125 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1126 const XFORM
*xform2
)
1130 /* Check for illegal parameters */
1131 if (!xformResult
|| !xform1
|| !xform2
)
1134 /* Create the result in a temporary XFORM, since xformResult may be
1135 * equal to xform1 or xform2 */
1136 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1137 xform1
->eM12
* xform2
->eM21
;
1138 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1139 xform1
->eM12
* xform2
->eM22
;
1140 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1141 xform1
->eM22
* xform2
->eM21
;
1142 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1143 xform1
->eM22
* xform2
->eM22
;
1144 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1145 xform1
->eDy
* xform2
->eM21
+
1147 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1148 xform1
->eDy
* xform2
->eM22
+
1151 /* Copy the result to xformResult */
1152 *xformResult
= xformTemp
;
1158 /***********************************************************************
1159 * SetDCHook (GDI.190)
1161 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1163 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1165 TRACE(dc
, "hookProc %08x, default is %08x\n",
1166 (UINT
)hookProc
, (UINT
)DCHook16
);
1168 if (!dc
) return FALSE
;
1169 dc
->hookProc
= hookProc
;
1170 dc
->dwHookData
= dwHookData
;
1171 GDI_HEAP_UNLOCK( hdc
);
1176 /***********************************************************************
1177 * GetDCHook (GDI.191)
1179 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1181 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1183 *phookProc
= dc
->hookProc
;
1184 GDI_HEAP_UNLOCK( hdc
);
1185 return dc
->dwHookData
;
1189 /***********************************************************************
1190 * SetHookFlags (GDI.192)
1192 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1194 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
1198 WORD wRet
= dc
->w
.flags
& DC_DIRTY
;
1200 /* "Undocumented Windows" info is slightly confusing.
1203 TRACE(dc
,"hDC %04x, flags %04x\n",hDC
,flags
);
1205 if( flags
& DCHF_INVALIDATEVISRGN
)
1206 dc
->w
.flags
|= DC_DIRTY
;
1207 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1208 dc
->w
.flags
&= ~DC_DIRTY
;
1209 GDI_HEAP_UNLOCK( hDC
);
1215 /***********************************************************************
1216 * SetICMMode (GDI32.318)
1218 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1220 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1221 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1222 if (iEnableICM
== ICM_ON
) return 0;
1223 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1228 /***********************************************************************
1229 * GetColorSpace (GDI32.165)
1231 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1233 /*FIXME Need to to whatever GetColorSpace actually does */
1237 /***********************************************************************
1238 * GetBoundsRect16 (GDI.194)
1240 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1242 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1245 /***********************************************************************
1246 * GetBoundsRect32 (GDI32.147)
1248 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1250 FIXME(dc
, "(): stub\n");
1251 return DCB_RESET
; /* bounding rectangle always empty */
1254 /***********************************************************************
1255 * SetBoundsRect16 (GDI.193)
1257 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1259 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1260 FIXME( dc
, "(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1262 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1265 /***********************************************************************
1266 * SetBoundsRect32 (GDI32.307)
1268 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1270 FIXME(dc
, "(): stub\n");
1271 return DCB_DISABLE
; /* bounding rectangle always empty */
1274 /***********************************************************************
1277 * Disables GDI, switches back to text mode.
1278 * We don't have to do anything here,
1279 * just let console support handle everything
1281 void WINAPI
Death16(HDC16 hDC
)
1283 MSG("Death(%04x) called. Application enters text mode...\n", hDC
);
1286 /***********************************************************************
1287 * Resurrection (GDI.122)
1289 * Restores GDI functionality
1291 void WINAPI
Resurrection16(HDC16 hDC
,
1292 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1294 MSG("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);