2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
19 /***********************************************************************
22 * Fill the WIN_DC_INFO structure.
24 static void DC_Init_DC_INFO( WIN_DC_INFO
*win_dc_info
)
26 win_dc_info
->flags
= 0;
27 win_dc_info
->devCaps
= NULL
;
28 win_dc_info
->hClipRgn
= 0;
29 win_dc_info
->hVisRgn
= 0;
30 win_dc_info
->hGCClipRgn
= 0;
31 win_dc_info
->hPen
= STOCK_BLACK_PEN
;
32 win_dc_info
->hBrush
= STOCK_WHITE_BRUSH
;
33 win_dc_info
->hFont
= STOCK_SYSTEM_FONT
;
34 win_dc_info
->hBitmap
= 0;
35 win_dc_info
->hFirstBitmap
= 0;
36 win_dc_info
->hDevice
= 0;
37 win_dc_info
->hPalette
= STOCK_DEFAULT_PALETTE
;
38 win_dc_info
->ROPmode
= R2_COPYPEN
;
39 win_dc_info
->polyFillMode
= ALTERNATE
;
40 win_dc_info
->stretchBltMode
= BLACKONWHITE
;
41 win_dc_info
->relAbsMode
= ABSOLUTE
;
42 win_dc_info
->backgroundMode
= OPAQUE
;
43 win_dc_info
->backgroundColor
= RGB( 255, 255, 255 );
44 win_dc_info
->textColor
= RGB( 0, 0, 0 );
45 win_dc_info
->brushOrgX
= 0;
46 win_dc_info
->brushOrgY
= 0;
47 win_dc_info
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
48 win_dc_info
->charExtra
= 0;
49 win_dc_info
->breakTotalExtra
= 0;
50 win_dc_info
->breakCount
= 0;
51 win_dc_info
->breakExtra
= 0;
52 win_dc_info
->breakRem
= 0;
53 win_dc_info
->bitsPerPixel
= 1;
54 win_dc_info
->MapMode
= MM_TEXT
;
55 win_dc_info
->GraphicsMode
= GM_COMPATIBLE
;
56 win_dc_info
->DCOrgX
= 0;
57 win_dc_info
->DCOrgY
= 0;
58 win_dc_info
->lpfnPrint
= NULL
;
59 win_dc_info
->CursPosX
= 0;
60 win_dc_info
->CursPosY
= 0;
61 win_dc_info
->ArcDirection
= AD_COUNTERCLOCKWISE
;
62 win_dc_info
->xformWorld2Wnd
.eM11
= 1.0f
;
63 win_dc_info
->xformWorld2Wnd
.eM12
= 0.0f
;
64 win_dc_info
->xformWorld2Wnd
.eM21
= 0.0f
;
65 win_dc_info
->xformWorld2Wnd
.eM22
= 1.0f
;
66 win_dc_info
->xformWorld2Wnd
.eDx
= 0.0f
;
67 win_dc_info
->xformWorld2Wnd
.eDy
= 0.0f
;
68 win_dc_info
->xformWorld2Vport
= win_dc_info
->xformWorld2Wnd
;
69 win_dc_info
->xformVport2World
= win_dc_info
->xformWorld2Wnd
;
70 win_dc_info
->vport2WorldValid
= TRUE
;
72 PATH_InitGdiPath(&win_dc_info
->path
);
76 /***********************************************************************
79 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
84 if (!(hdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
))) return NULL
;
85 dc
= (DC
*) GDI_HEAP_LOCK( hdc
);
102 DC_Init_DC_INFO( &dc
->w
);
109 /***********************************************************************
112 DC
*DC_GetDCPtr( HDC32 hdc
)
114 GDIOBJHDR
*ptr
= (GDIOBJHDR
*)GDI_HEAP_LOCK( hdc
);
115 if (!ptr
) return NULL
;
116 if ((ptr
->wMagic
== DC_MAGIC
) || (ptr
->wMagic
== METAFILE_DC_MAGIC
))
118 GDI_HEAP_UNLOCK( hdc
);
123 /***********************************************************************
126 * Setup device-specific DC values for a newly created DC.
128 void DC_InitDC( DC
* dc
)
130 RealizeDefaultPalette( dc
->hSelf
);
131 SetTextColor32( dc
->hSelf
, dc
->w
.textColor
);
132 SetBkColor32( dc
->hSelf
, dc
->w
.backgroundColor
);
133 SelectObject32( dc
->hSelf
, dc
->w
.hPen
);
134 SelectObject32( dc
->hSelf
, dc
->w
.hBrush
);
135 SelectObject32( dc
->hSelf
, dc
->w
.hFont
);
136 CLIPPING_UpdateGCRegion( dc
);
140 /***********************************************************************
143 * Computes the inverse of the transformation xformSrc and stores it to
144 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
147 static BOOL32
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
151 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
152 xformSrc
->eM12
*xformSrc
->eM21
;
153 if (determinant
> -1e-12 && determinant
< 1e-12)
156 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
157 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
158 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
159 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
160 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
161 xformSrc
->eDy
* xformDest
->eM21
;
162 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
163 xformSrc
->eDy
* xformDest
->eM22
;
169 /***********************************************************************
172 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
173 * fields of the specified DC by creating a transformation that
174 * represents the current mapping mode and combining it with the DC's
175 * world transform. This function should be called whenever the
176 * parameters associated with the mapping mode (window and viewport
177 * extents and origins) or the world transform change.
179 void DC_UpdateXforms( DC
*dc
)
181 XFORM xformWnd2Vport
;
182 FLOAT scaleX
, scaleY
;
184 /* Construct a transformation to do the window-to-viewport conversion */
185 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
186 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
187 xformWnd2Vport
.eM11
= scaleX
;
188 xformWnd2Vport
.eM12
= 0.0;
189 xformWnd2Vport
.eM21
= 0.0;
190 xformWnd2Vport
.eM22
= scaleY
;
191 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
192 scaleX
* (FLOAT
)dc
->wndOrgX
;
193 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
194 scaleY
* (FLOAT
)dc
->wndOrgY
;
196 /* Combine with the world transformation */
197 CombineTransform( &dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
,
200 /* Create inverse of world-to-viewport transformation */
201 dc
->w
.vport2WorldValid
= DC_InvertXform( &dc
->w
.xformWorld2Vport
,
202 &dc
->w
.xformVport2World
);
206 /***********************************************************************
207 * GetDCState (GDI.179)
209 HDC16 WINAPI
GetDCState( HDC16 hdc
)
214 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
215 if (!(handle
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
)))
217 GDI_HEAP_UNLOCK( hdc
);
220 newdc
= (DC
*) GDI_HEAP_LOCK( handle
);
222 TRACE(dc
, "(%04x): returning %04x\n", hdc
, handle
);
224 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
225 newdc
->w
.devCaps
= dc
->w
.devCaps
;
226 newdc
->w
.hPen
= dc
->w
.hPen
;
227 newdc
->w
.hBrush
= dc
->w
.hBrush
;
228 newdc
->w
.hFont
= dc
->w
.hFont
;
229 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
230 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
231 newdc
->w
.hDevice
= dc
->w
.hDevice
;
232 newdc
->w
.hPalette
= dc
->w
.hPalette
;
233 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
234 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
235 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
236 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
237 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
238 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
239 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
240 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
241 newdc
->w
.textColor
= dc
->w
.textColor
;
242 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
243 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
244 newdc
->w
.textAlign
= dc
->w
.textAlign
;
245 newdc
->w
.charExtra
= dc
->w
.charExtra
;
246 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
247 newdc
->w
.breakCount
= dc
->w
.breakCount
;
248 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
249 newdc
->w
.breakRem
= dc
->w
.breakRem
;
250 newdc
->w
.MapMode
= dc
->w
.MapMode
;
251 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
253 /* Apparently, the DC origin is not changed by [GS]etDCState */
254 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
255 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
257 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
258 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
259 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
260 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
261 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
262 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
263 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
264 newdc
->wndOrgX
= dc
->wndOrgX
;
265 newdc
->wndOrgY
= dc
->wndOrgY
;
266 newdc
->wndExtX
= dc
->wndExtX
;
267 newdc
->wndExtY
= dc
->wndExtY
;
268 newdc
->vportOrgX
= dc
->vportOrgX
;
269 newdc
->vportOrgY
= dc
->vportOrgY
;
270 newdc
->vportExtX
= dc
->vportExtX
;
271 newdc
->vportExtY
= dc
->vportExtY
;
273 newdc
->hSelf
= (HDC32
)handle
;
274 newdc
->saveLevel
= 0;
276 PATH_InitGdiPath( &newdc
->w
.path
);
278 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
280 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
283 newdc
->w
.hClipRgn
= CreateRectRgn32( 0, 0, 0, 0 );
284 CombineRgn32( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
287 newdc
->w
.hClipRgn
= 0;
288 GDI_HEAP_UNLOCK( handle
);
289 GDI_HEAP_UNLOCK( hdc
);
294 /***********************************************************************
295 * SetDCState (GDI.180)
297 void WINAPI
SetDCState( HDC16 hdc
, HDC16 hdcs
)
301 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
302 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
304 GDI_HEAP_UNLOCK( hdc
);
307 if (!dcs
->w
.flags
& DC_SAVED
)
309 GDI_HEAP_UNLOCK( hdc
);
310 GDI_HEAP_UNLOCK( hdcs
);
313 TRACE(dc
, "%04x %04x\n", hdc
, hdcs
);
315 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
316 dc
->w
.devCaps
= dcs
->w
.devCaps
;
317 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
318 dc
->w
.hDevice
= dcs
->w
.hDevice
;
319 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
320 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
321 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
322 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
323 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
324 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
325 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
326 dc
->w
.textColor
= dcs
->w
.textColor
;
327 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
328 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
329 dc
->w
.textAlign
= dcs
->w
.textAlign
;
330 dc
->w
.charExtra
= dcs
->w
.charExtra
;
331 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
332 dc
->w
.breakCount
= dcs
->w
.breakCount
;
333 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
334 dc
->w
.breakRem
= dcs
->w
.breakRem
;
335 dc
->w
.MapMode
= dcs
->w
.MapMode
;
336 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
338 /* Apparently, the DC origin is not changed by [GS]etDCState */
339 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
340 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
342 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
343 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
344 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
345 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
346 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
347 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
348 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
350 dc
->wndOrgX
= dcs
->wndOrgX
;
351 dc
->wndOrgY
= dcs
->wndOrgY
;
352 dc
->wndExtX
= dcs
->wndExtX
;
353 dc
->wndExtY
= dcs
->wndExtY
;
354 dc
->vportOrgX
= dcs
->vportOrgX
;
355 dc
->vportOrgY
= dcs
->vportOrgY
;
356 dc
->vportExtX
= dcs
->vportExtX
;
357 dc
->vportExtY
= dcs
->vportExtY
;
359 if (!(dc
->w
.flags
& DC_MEMORY
)) dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
363 if (!dc
->w
.hClipRgn
) dc
->w
.hClipRgn
= CreateRectRgn32( 0, 0, 0, 0 );
364 CombineRgn32( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
368 if (dc
->w
.hClipRgn
) DeleteObject16( dc
->w
.hClipRgn
);
371 CLIPPING_UpdateGCRegion( dc
);
373 SelectObject32( hdc
, dcs
->w
.hBitmap
);
374 SelectObject32( hdc
, dcs
->w
.hBrush
);
375 SelectObject32( hdc
, dcs
->w
.hFont
);
376 SelectObject32( hdc
, dcs
->w
.hPen
);
377 SetBkColor32( hdc
, dcs
->w
.backgroundColor
);
378 SetTextColor32( hdc
, dcs
->w
.textColor
);
379 GDISelectPalette( hdc
, dcs
->w
.hPalette
, FALSE
);
380 GDI_HEAP_UNLOCK( hdc
);
381 GDI_HEAP_UNLOCK( hdcs
);
385 /***********************************************************************
388 INT16 WINAPI
SaveDC16( HDC16 hdc
)
390 return (INT16
)SaveDC32( hdc
);
394 /***********************************************************************
395 * SaveDC32 (GDI32.292)
397 INT32 WINAPI
SaveDC32( HDC32 hdc
)
403 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
406 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
408 MF_MetaParam0(dc
, META_SAVEDC
);
409 GDI_HEAP_UNLOCK( hdc
);
412 if (!(hdcs
= GetDCState( hdc
)))
414 GDI_HEAP_UNLOCK( hdc
);
417 dcs
= (DC
*) GDI_HEAP_LOCK( hdcs
);
419 /* Copy path. The reason why path saving / restoring is in SaveDC/
420 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
421 * functions are only in Win16 (which doesn't have paths) and that
422 * SetDCState doesn't allow us to signal an error (which can happen
423 * when copying paths).
425 if (!PATH_AssignGdiPath( &dcs
->w
.path
, &dc
->w
.path
))
427 GDI_HEAP_UNLOCK( hdc
);
428 GDI_HEAP_UNLOCK( hdcs
);
433 dcs
->header
.hNext
= dc
->header
.hNext
;
434 dc
->header
.hNext
= hdcs
;
435 TRACE(dc
, "(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
436 ret
= ++dc
->saveLevel
;
437 GDI_HEAP_UNLOCK( hdcs
);
438 GDI_HEAP_UNLOCK( hdc
);
443 /***********************************************************************
444 * RestoreDC16 (GDI.39)
446 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
448 return RestoreDC32( hdc
, level
);
452 /***********************************************************************
453 * RestoreDC32 (GDI32.290)
455 BOOL32 WINAPI
RestoreDC32( HDC32 hdc
, INT32 level
)
460 TRACE(dc
, "%04x %d\n", hdc
, level
);
461 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
464 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
465 if (!dc
) return FALSE
;
468 GDI_HEAP_UNLOCK( hdc
);
471 MF_MetaParam1(dc
, META_RESTOREDC
, level
);
472 GDI_HEAP_UNLOCK( hdc
);
475 if (level
== -1) level
= dc
->saveLevel
;
476 if ((level
< 1) || (level
> dc
->saveLevel
))
478 GDI_HEAP_UNLOCK( hdc
);
483 while (dc
->saveLevel
>= level
)
485 HDC16 hdcs
= dc
->header
.hNext
;
486 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
488 GDI_HEAP_UNLOCK( hdc
);
491 dc
->header
.hNext
= dcs
->header
.hNext
;
492 if (--dc
->saveLevel
< level
)
494 SetDCState( hdc
, hdcs
);
495 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
496 /* FIXME: This might not be quite right, since we're
497 * returning FALSE but still destroying the saved DC state */
502 GDI_HEAP_UNLOCK( hdc
);
507 /***********************************************************************
508 * CreateDC16 (GDI.53)
510 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
511 const DEVMODE16
*initData
)
514 const DC_FUNCTIONS
*funcs
;
516 if (!(funcs
= DRIVER_FindDriver( driver
))) return 0;
517 if (!(dc
= DC_AllocDC( funcs
))) return 0;
520 TRACE(dc
, "(driver=%s, device=%s, output=%s): returning %04x\n",
521 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
523 if (dc
->funcs
->pCreateDC
&&
524 !dc
->funcs
->pCreateDC( dc
, driver
, device
, output
, initData
))
526 WARN(dc
, "creation aborted by device\n" );
527 GDI_HEAP_FREE( dc
->hSelf
);
532 GDI_HEAP_UNLOCK( dc
->hSelf
);
537 /***********************************************************************
538 * CreateDC32A (GDI32.)
540 HDC32 WINAPI
CreateDC32A( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
541 const DEVMODE32A
*initData
)
543 return CreateDC16( driver
, device
, output
, (const DEVMODE16
*)initData
);
547 /***********************************************************************
548 * CreateDC32W (GDI32.)
550 HDC32 WINAPI
CreateDC32W( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
551 const DEVMODE32W
*initData
)
553 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
554 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
555 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
556 HDC32 res
= CreateDC16( driverA
, deviceA
, outputA
,
557 (const DEVMODE16
*)initData
/*FIXME*/ );
558 HeapFree( GetProcessHeap(), 0, driverA
);
559 HeapFree( GetProcessHeap(), 0, deviceA
);
560 HeapFree( GetProcessHeap(), 0, outputA
);
565 /***********************************************************************
566 * CreateIC16 (GDI.153)
568 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
569 const DEVMODE16
* initData
)
571 /* Nothing special yet for ICs */
572 return CreateDC16( driver
, device
, output
, initData
);
576 /***********************************************************************
577 * CreateIC32A (GDI32.49)
579 HDC32 WINAPI
CreateIC32A( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
580 const DEVMODE32A
* initData
)
582 /* Nothing special yet for ICs */
583 return CreateDC32A( driver
, device
, output
, initData
);
587 /***********************************************************************
588 * CreateIC32W (GDI32.50)
590 HDC32 WINAPI
CreateIC32W( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
591 const DEVMODE32W
* initData
)
593 /* Nothing special yet for ICs */
594 return CreateDC32W( driver
, device
, output
, initData
);
598 /***********************************************************************
599 * CreateCompatibleDC16 (GDI.52)
601 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
603 return (HDC16
)CreateCompatibleDC32( hdc
);
607 /***********************************************************************
608 * CreateCompatibleDC32 (GDI32.31)
610 HDC32 WINAPI
CreateCompatibleDC32( HDC32 hdc
)
614 const DC_FUNCTIONS
*funcs
;
616 if ((origDC
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
))) funcs
= origDC
->funcs
;
617 else funcs
= DRIVER_FindDriver( "DISPLAY" );
618 if (!funcs
) return 0;
620 if (!(dc
= DC_AllocDC( funcs
))) return 0;
622 TRACE(dc
, "(%04x): returning %04x\n",
625 /* Create default bitmap */
626 if (!(hbitmap
= CreateBitmap32( 1, 1, 1, 1, NULL
)))
628 GDI_HEAP_FREE( dc
->hSelf
);
631 dc
->w
.flags
= DC_MEMORY
;
632 dc
->w
.bitsPerPixel
= 1;
633 dc
->w
.hBitmap
= hbitmap
;
634 dc
->w
.hFirstBitmap
= hbitmap
;
636 if (dc
->funcs
->pCreateDC
&&
637 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
639 WARN(dc
, "creation aborted by device\n");
640 DeleteObject32( hbitmap
);
641 GDI_HEAP_FREE( dc
->hSelf
);
646 GDI_HEAP_UNLOCK( dc
->hSelf
);
651 /***********************************************************************
652 * DeleteDC16 (GDI.68)
654 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
656 return DeleteDC32( hdc
);
660 /***********************************************************************
661 * DeleteDC32 (GDI32.67)
663 BOOL32 WINAPI
DeleteDC32( HDC32 hdc
)
665 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
666 if (!dc
) return FALSE
;
668 TRACE(dc
, "%04x\n", hdc
);
670 while (dc
->saveLevel
)
673 HDC16 hdcs
= dc
->header
.hNext
;
674 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
675 dc
->header
.hNext
= dcs
->header
.hNext
;
680 if (!(dc
->w
.flags
& DC_SAVED
))
682 SelectObject32( hdc
, STOCK_BLACK_PEN
);
683 SelectObject32( hdc
, STOCK_WHITE_BRUSH
);
684 SelectObject32( hdc
, STOCK_SYSTEM_FONT
);
685 if (dc
->w
.flags
& DC_MEMORY
) DeleteObject32( dc
->w
.hFirstBitmap
);
686 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
689 if (dc
->w
.hClipRgn
) DeleteObject32( dc
->w
.hClipRgn
);
690 if (dc
->w
.hVisRgn
) DeleteObject32( dc
->w
.hVisRgn
);
691 if (dc
->w
.hGCClipRgn
) DeleteObject32( dc
->w
.hGCClipRgn
);
693 PATH_DestroyGdiPath(&dc
->w
.path
);
695 return GDI_FreeObject( hdc
);
699 /***********************************************************************
700 * ResetDC16 (GDI.376)
702 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODE16
*devmode
)
704 FIXME(dc
, "stub\n" );
709 /***********************************************************************
710 * ResetDC32A (GDI32.287)
712 HDC32 WINAPI
ResetDC32A( HDC32 hdc
, const DEVMODE32A
*devmode
)
714 FIXME(dc
, "stub\n" );
719 /***********************************************************************
720 * ResetDC32W (GDI32.288)
722 HDC32 WINAPI
ResetDC32W( HDC32 hdc
, const DEVMODE32W
*devmode
)
724 FIXME(dc
, "stub\n" );
729 /***********************************************************************
730 * GetDeviceCaps16 (GDI.80)
732 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
734 return GetDeviceCaps32( hdc
, cap
);
738 /***********************************************************************
739 * GetDeviceCaps32 (GDI32.171)
741 INT32 WINAPI
GetDeviceCaps32( HDC32 hdc
, INT32 cap
)
743 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
748 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
)))
750 GDI_HEAP_UNLOCK( hdc
);
754 TRACE(dc
, "(%04x,%d): returning %d\n",
755 hdc
, cap
, *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
) );
756 ret
= *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
);
757 GDI_HEAP_UNLOCK( hdc
);
762 /***********************************************************************
763 * SetBkColor16 (GDI.1)
765 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
767 return SetBkColor32( hdc
, color
);
771 /***********************************************************************
772 * SetBkColor32 (GDI32.305)
774 COLORREF WINAPI
SetBkColor32( HDC32 hdc
, COLORREF color
)
777 DC
* dc
= DC_GetDCPtr( hdc
);
779 if (!dc
) return 0x80000000;
780 if (dc
->funcs
->pSetBkColor
)
781 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
783 oldColor
= dc
->w
.backgroundColor
;
784 dc
->w
.backgroundColor
= color
;
786 GDI_HEAP_UNLOCK( hdc
);
791 /***********************************************************************
792 * SetTextColor16 (GDI.9)
794 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
796 return SetTextColor32( hdc
, color
);
800 /***********************************************************************
801 * SetTextColor32 (GDI32.338)
803 COLORREF WINAPI
SetTextColor32( HDC32 hdc
, COLORREF color
)
806 DC
* dc
= DC_GetDCPtr( hdc
);
808 if (!dc
) return 0x80000000;
809 if (dc
->funcs
->pSetTextColor
)
810 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
812 oldColor
= dc
->w
.textColor
;
813 dc
->w
.textColor
= color
;
815 GDI_HEAP_UNLOCK( hdc
);
820 /***********************************************************************
821 * SetTextAlign16 (GDI.346)
823 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 textAlign
)
825 return SetTextAlign32( hdc
, textAlign
);
829 /***********************************************************************
830 * SetTextAlign32 (GDI32.336)
832 UINT32 WINAPI
SetTextAlign32( HDC32 hdc
, UINT32 textAlign
)
835 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
838 if (!(dc
= (DC
*)GDI_GetObjPtr( hdc
, METAFILE_DC_MAGIC
))) return 0;
839 MF_MetaParam1( dc
, META_SETTEXTALIGN
, textAlign
);
840 GDI_HEAP_UNLOCK( hdc
);
843 prevAlign
= dc
->w
.textAlign
;
844 dc
->w
.textAlign
= textAlign
;
845 GDI_HEAP_UNLOCK( hdc
);
850 /***********************************************************************
851 * GetDCOrgEx (GDI32.168)
853 BOOL32 WINAPI
GetDCOrgEx( HDC32 hDC
, LPPOINT32 lpp
)
856 X11DRV_PDEVICE
*physDev
;
858 if (!lpp
) return FALSE
;
859 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return FALSE
;
860 physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
862 if (!(dc
->w
.flags
& DC_MEMORY
))
865 int w
, h
, border
, depth
;
866 /* FIXME: this is not correct for managed windows */
867 TSXGetGeometry( display
, physDev
->drawable
, &root
,
868 &lpp
->x
, &lpp
->y
, &w
, &h
, &border
, &depth
);
870 else lpp
->x
= lpp
->y
= 0;
871 lpp
->x
+= dc
->w
.DCOrgX
; lpp
->y
+= dc
->w
.DCOrgY
;
872 GDI_HEAP_UNLOCK( hDC
);
877 /***********************************************************************
880 DWORD WINAPI
GetDCOrg( HDC16 hdc
)
883 if( GetDCOrgEx( hdc
, &pt
) )
884 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
889 /***********************************************************************
892 DWORD WINAPI
SetDCOrg( HDC16 hdc
, INT16 x
, INT16 y
)
895 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
897 prevOrg
= dc
->w
.DCOrgX
| (dc
->w
.DCOrgY
<< 16);
900 GDI_HEAP_UNLOCK( hdc
);
905 /***********************************************************************
906 * GetGraphicsMode (GDI32.188)
908 INT32 WINAPI
GetGraphicsMode( HDC32 hdc
)
910 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
912 return dc
->w
.GraphicsMode
;
916 /***********************************************************************
917 * SetGraphicsMode (GDI32.317)
919 INT32 WINAPI
SetGraphicsMode( HDC32 hdc
, INT32 mode
)
922 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
924 /* One would think that setting the graphics mode to GM_COMPATIBLE
925 * would also reset the world transformation matrix to the unity
926 * matrix. However, in Windows, this is not the case. This doesn't
927 * make a lot of sense to me, but that's the way it is.
931 if ((mode
<= 0) || (mode
> GM_LAST
)) return 0;
932 ret
= dc
->w
.GraphicsMode
;
933 dc
->w
.GraphicsMode
= mode
;
938 /***********************************************************************
939 * GetArcDirection16 (GDI.524)
941 INT16 WINAPI
GetArcDirection16( HDC16 hdc
)
943 return GetArcDirection32( (HDC32
)hdc
);
947 /***********************************************************************
948 * GetArcDirection32 (GDI32.141)
950 INT32 WINAPI
GetArcDirection32( HDC32 hdc
)
952 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
957 return dc
->w
.ArcDirection
;
961 /***********************************************************************
962 * SetArcDirection16 (GDI.525)
964 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
966 return SetArcDirection32( (HDC32
)hdc
, (INT32
)nDirection
);
970 /***********************************************************************
971 * SetArcDirection32 (GDI32.302)
973 INT32 WINAPI
SetArcDirection32( HDC32 hdc
, INT32 nDirection
)
975 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
981 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
983 SetLastError(ERROR_INVALID_PARAMETER
);
987 nOldDirection
= dc
->w
.ArcDirection
;
988 dc
->w
.ArcDirection
= nDirection
;
990 return nOldDirection
;
994 /***********************************************************************
995 * GetWorldTransform (GDI32.244)
997 BOOL32 WINAPI
GetWorldTransform( HDC32 hdc
, LPXFORM xform
)
999 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1006 *xform
= dc
->w
.xformWorld2Wnd
;
1012 /***********************************************************************
1013 * SetWorldTransform (GDI32.346)
1015 BOOL32 WINAPI
SetWorldTransform( HDC32 hdc
, const XFORM
*xform
)
1017 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1021 SetLastError( ERROR_INVALID_HANDLE
);
1028 /* Check that graphics mode is GM_ADVANCED */
1029 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1032 dc
->w
.xformWorld2Wnd
= *xform
;
1034 DC_UpdateXforms( dc
);
1040 /****************************************************************************
1041 * ModifyWorldTransform [GDI32.253]
1042 * Modifies the world transformation for a device context.
1045 * hdc [I] Handle to device context
1046 * xform [I] XFORM structure that will be used to modify the world
1048 * iMode [I] Specifies in what way to modify the world transformation
1051 * Resets the world transformation to the identity matrix.
1052 * The parameter xform is ignored.
1054 * Multiplies xform into the world transformation matrix from
1057 * Multiplies xform into the world transformation matrix from
1062 BOOL32 WINAPI
ModifyWorldTransform( HDC32 hdc
, const XFORM
*xform
,
1065 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1067 /* Check for illegal parameters */
1070 SetLastError( ERROR_INVALID_HANDLE
);
1076 /* Check that graphics mode is GM_ADVANCED */
1077 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1083 dc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1084 dc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1085 dc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1086 dc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1087 dc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1088 dc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1090 case MWT_LEFTMULTIPLY
:
1091 CombineTransform( &dc
->w
.xformWorld2Wnd
, xform
,
1092 &dc
->w
.xformWorld2Wnd
);
1094 case MWT_RIGHTMULTIPLY
:
1095 CombineTransform( &dc
->w
.xformWorld2Wnd
, &dc
->w
.xformWorld2Wnd
,
1102 DC_UpdateXforms( dc
);
1108 /****************************************************************************
1109 * CombineTransform [GDI32.20]
1110 * Combines two transformation matrices.
1113 * xformResult [O] Stores the result of combining the two matrices
1114 * xform1 [I] Specifies the first matrix to apply
1115 * xform2 [I] Specifies the second matrix to apply
1118 * The same matrix can be passed in for more than one of the parameters.
1122 BOOL32 WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1123 const XFORM
*xform2
)
1127 /* Check for illegal parameters */
1128 if (!xformResult
|| !xform1
|| !xform2
)
1131 /* Create the result in a temporary XFORM, since xformResult may be
1132 * equal to xform1 or xform2 */
1133 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1134 xform1
->eM12
* xform2
->eM21
;
1135 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1136 xform1
->eM12
* xform2
->eM22
;
1137 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1138 xform1
->eM22
* xform2
->eM21
;
1139 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1140 xform1
->eM22
* xform2
->eM22
;
1141 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1142 xform1
->eDy
* xform2
->eM21
+
1144 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1145 xform1
->eDy
* xform2
->eM22
+
1148 /* Copy the result to xformResult */
1149 *xformResult
= xformTemp
;
1155 /***********************************************************************
1156 * SetDCHook (GDI.190)
1158 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1160 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1162 TRACE(dc
, "hookProc %08x, default is %08x\n",
1163 (UINT32
)hookProc
, (UINT32
)DCHook
);
1165 if (!dc
) return FALSE
;
1166 dc
->hookProc
= hookProc
;
1167 dc
->dwHookData
= dwHookData
;
1168 GDI_HEAP_UNLOCK( hdc
);
1173 /***********************************************************************
1174 * GetDCHook (GDI.191)
1176 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1178 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1180 *phookProc
= dc
->hookProc
;
1181 GDI_HEAP_UNLOCK( hdc
);
1182 return dc
->dwHookData
;
1186 /***********************************************************************
1187 * SetHookFlags (GDI.192)
1189 WORD WINAPI
SetHookFlags(HDC16 hDC
, WORD flags
)
1191 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
1195 WORD wRet
= dc
->w
.flags
& DC_DIRTY
;
1197 /* "Undocumented Windows" info is slightly confusing.
1200 TRACE(dc
,"hDC %04x, flags %04x\n",hDC
,flags
);
1202 if( flags
& DCHF_INVALIDATEVISRGN
)
1203 dc
->w
.flags
|= DC_DIRTY
;
1204 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1205 dc
->w
.flags
&= ~DC_DIRTY
;
1206 GDI_HEAP_UNLOCK( hDC
);
1212 /***********************************************************************
1213 * SetICMMode (GDI32.318)
1215 INT32 WINAPI
SetICMMode(HDC32 hdc
, INT32 iEnableICM
)
1217 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1218 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1219 if (iEnableICM
== ICM_ON
) return 0;
1220 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1225 /***********************************************************************
1226 * GetColorSpace (GDI32.165)
1228 HCOLORSPACE32 WINAPI
GetColorSpace(HDC32 hdc
)
1230 /*FIXME Need to to whatever GetColorSpace actually does */
1234 /***********************************************************************
1235 * GetBoundsRect16 (GDI.194)
1237 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1239 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1242 /***********************************************************************
1243 * GetBoundsRect32 (GDI32.147)
1245 UINT32 WINAPI
GetBoundsRect32(HDC32 hdc
, LPRECT32 rect
, UINT32 flags
)
1247 FIXME(dc
, "(): stub\n");
1248 return DCB_RESET
; /* bounding rectangle always empty */
1251 /***********************************************************************
1252 * SetBoundsRect16 (GDI.193)
1254 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1256 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1257 FIXME( dc
, "(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1259 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1262 /***********************************************************************
1263 * SetBoundsRect32 (GDI32.307)
1265 UINT32 WINAPI
SetBoundsRect32(HDC32 hdc
, const RECT32
* rect
, UINT32 flags
)
1267 FIXME(dc
, "(): stub\n");
1268 return DCB_DISABLE
; /* bounding rectangle always empty */