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 memset( &newdc
->u
.x
, 0, sizeof(newdc
->u
.x
) );
225 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
226 newdc
->w
.devCaps
= dc
->w
.devCaps
;
227 newdc
->w
.hPen
= dc
->w
.hPen
;
228 newdc
->w
.hBrush
= dc
->w
.hBrush
;
229 newdc
->w
.hFont
= dc
->w
.hFont
;
230 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
231 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
232 newdc
->w
.hDevice
= dc
->w
.hDevice
;
233 newdc
->w
.hPalette
= dc
->w
.hPalette
;
234 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
235 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
236 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
237 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
238 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
239 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
240 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
241 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
242 newdc
->w
.textColor
= dc
->w
.textColor
;
243 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
244 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
245 newdc
->w
.textAlign
= dc
->w
.textAlign
;
246 newdc
->w
.charExtra
= dc
->w
.charExtra
;
247 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
248 newdc
->w
.breakCount
= dc
->w
.breakCount
;
249 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
250 newdc
->w
.breakRem
= dc
->w
.breakRem
;
251 newdc
->w
.MapMode
= dc
->w
.MapMode
;
252 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
254 /* Apparently, the DC origin is not changed by [GS]etDCState */
255 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
256 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
258 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
259 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
260 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
261 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
262 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
263 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
264 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
265 newdc
->wndOrgX
= dc
->wndOrgX
;
266 newdc
->wndOrgY
= dc
->wndOrgY
;
267 newdc
->wndExtX
= dc
->wndExtX
;
268 newdc
->wndExtY
= dc
->wndExtY
;
269 newdc
->vportOrgX
= dc
->vportOrgX
;
270 newdc
->vportOrgY
= dc
->vportOrgY
;
271 newdc
->vportExtX
= dc
->vportExtX
;
272 newdc
->vportExtY
= dc
->vportExtY
;
274 newdc
->hSelf
= (HDC32
)handle
;
275 newdc
->saveLevel
= 0;
277 PATH_InitGdiPath( &newdc
->w
.path
);
279 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
281 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
284 newdc
->w
.hClipRgn
= CreateRectRgn32( 0, 0, 0, 0 );
285 CombineRgn32( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
288 newdc
->w
.hClipRgn
= 0;
289 GDI_HEAP_UNLOCK( handle
);
290 GDI_HEAP_UNLOCK( hdc
);
295 /***********************************************************************
296 * SetDCState (GDI.180)
298 void WINAPI
SetDCState( HDC16 hdc
, HDC16 hdcs
)
302 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
303 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
305 GDI_HEAP_UNLOCK( hdc
);
308 if (!dcs
->w
.flags
& DC_SAVED
)
310 GDI_HEAP_UNLOCK( hdc
);
311 GDI_HEAP_UNLOCK( hdcs
);
314 TRACE(dc
, "%04x %04x\n", hdc
, hdcs
);
316 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
317 dc
->w
.devCaps
= dcs
->w
.devCaps
;
318 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
319 dc
->w
.hDevice
= dcs
->w
.hDevice
;
320 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
321 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
322 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
323 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
324 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
325 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
326 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
327 dc
->w
.textColor
= dcs
->w
.textColor
;
328 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
329 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
330 dc
->w
.textAlign
= dcs
->w
.textAlign
;
331 dc
->w
.charExtra
= dcs
->w
.charExtra
;
332 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
333 dc
->w
.breakCount
= dcs
->w
.breakCount
;
334 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
335 dc
->w
.breakRem
= dcs
->w
.breakRem
;
336 dc
->w
.MapMode
= dcs
->w
.MapMode
;
337 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
339 /* Apparently, the DC origin is not changed by [GS]etDCState */
340 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
341 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
343 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
344 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
345 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
346 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
347 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
348 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
349 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
351 dc
->wndOrgX
= dcs
->wndOrgX
;
352 dc
->wndOrgY
= dcs
->wndOrgY
;
353 dc
->wndExtX
= dcs
->wndExtX
;
354 dc
->wndExtY
= dcs
->wndExtY
;
355 dc
->vportOrgX
= dcs
->vportOrgX
;
356 dc
->vportOrgY
= dcs
->vportOrgY
;
357 dc
->vportExtX
= dcs
->vportExtX
;
358 dc
->vportExtY
= dcs
->vportExtY
;
360 if (!(dc
->w
.flags
& DC_MEMORY
)) dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
364 if (!dc
->w
.hClipRgn
) dc
->w
.hClipRgn
= CreateRectRgn32( 0, 0, 0, 0 );
365 CombineRgn32( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
369 if (dc
->w
.hClipRgn
) DeleteObject16( dc
->w
.hClipRgn
);
372 CLIPPING_UpdateGCRegion( dc
);
374 SelectObject32( hdc
, dcs
->w
.hBitmap
);
375 SelectObject32( hdc
, dcs
->w
.hBrush
);
376 SelectObject32( hdc
, dcs
->w
.hFont
);
377 SelectObject32( hdc
, dcs
->w
.hPen
);
378 SetBkColor32( hdc
, dcs
->w
.backgroundColor
);
379 SetTextColor32( hdc
, dcs
->w
.textColor
);
380 GDISelectPalette( hdc
, dcs
->w
.hPalette
, FALSE
);
381 GDI_HEAP_UNLOCK( hdc
);
382 GDI_HEAP_UNLOCK( hdcs
);
386 /***********************************************************************
389 INT16 WINAPI
SaveDC16( HDC16 hdc
)
391 return (INT16
)SaveDC32( hdc
);
395 /***********************************************************************
396 * SaveDC32 (GDI32.292)
398 INT32 WINAPI
SaveDC32( HDC32 hdc
)
404 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
407 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
409 MF_MetaParam0(dc
, META_SAVEDC
);
410 GDI_HEAP_UNLOCK( hdc
);
413 if (!(hdcs
= GetDCState( hdc
)))
415 GDI_HEAP_UNLOCK( hdc
);
418 dcs
= (DC
*) GDI_HEAP_LOCK( hdcs
);
420 /* Copy path. The reason why path saving / restoring is in SaveDC/
421 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
422 * functions are only in Win16 (which doesn't have paths) and that
423 * SetDCState doesn't allow us to signal an error (which can happen
424 * when copying paths).
426 if (!PATH_AssignGdiPath( &dcs
->w
.path
, &dc
->w
.path
))
428 GDI_HEAP_UNLOCK( hdc
);
429 GDI_HEAP_UNLOCK( hdcs
);
434 dcs
->header
.hNext
= dc
->header
.hNext
;
435 dc
->header
.hNext
= hdcs
;
436 TRACE(dc
, "(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
437 ret
= ++dc
->saveLevel
;
438 GDI_HEAP_UNLOCK( hdcs
);
439 GDI_HEAP_UNLOCK( hdc
);
444 /***********************************************************************
445 * RestoreDC16 (GDI.39)
447 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
449 return RestoreDC32( hdc
, level
);
453 /***********************************************************************
454 * RestoreDC32 (GDI32.290)
456 BOOL32 WINAPI
RestoreDC32( HDC32 hdc
, INT32 level
)
461 TRACE(dc
, "%04x %d\n", hdc
, level
);
462 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
465 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
466 if (!dc
) return FALSE
;
469 GDI_HEAP_UNLOCK( hdc
);
472 MF_MetaParam1(dc
, META_RESTOREDC
, level
);
473 GDI_HEAP_UNLOCK( hdc
);
476 if (level
== -1) level
= dc
->saveLevel
;
477 if ((level
< 1) || (level
> dc
->saveLevel
))
479 GDI_HEAP_UNLOCK( hdc
);
484 while (dc
->saveLevel
>= level
)
486 HDC16 hdcs
= dc
->header
.hNext
;
487 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
489 GDI_HEAP_UNLOCK( hdc
);
492 dc
->header
.hNext
= dcs
->header
.hNext
;
493 if (--dc
->saveLevel
< level
)
495 SetDCState( hdc
, hdcs
);
496 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
497 /* FIXME: This might not be quite right, since we're
498 * returning FALSE but still destroying the saved DC state */
503 GDI_HEAP_UNLOCK( hdc
);
508 /***********************************************************************
509 * CreateDC16 (GDI.53)
511 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
512 const DEVMODE16
*initData
)
515 const DC_FUNCTIONS
*funcs
;
517 if (!(funcs
= DRIVER_FindDriver( driver
))) return 0;
518 if (!(dc
= DC_AllocDC( funcs
))) return 0;
521 TRACE(dc
, "(driver=%s, device=%s, output=%s): returning %04x\n",
522 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
524 if (dc
->funcs
->pCreateDC
&&
525 !dc
->funcs
->pCreateDC( dc
, driver
, device
, output
, initData
))
527 WARN(dc
, "creation aborted by device\n" );
528 GDI_HEAP_FREE( dc
->hSelf
);
533 GDI_HEAP_UNLOCK( dc
->hSelf
);
538 /***********************************************************************
539 * CreateDC32A (GDI32.)
541 HDC32 WINAPI
CreateDC32A( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
542 const DEVMODE32A
*initData
)
544 return CreateDC16( driver
, device
, output
, (const DEVMODE16
*)initData
);
548 /***********************************************************************
549 * CreateDC32W (GDI32.)
551 HDC32 WINAPI
CreateDC32W( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
552 const DEVMODE32W
*initData
)
554 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
555 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
556 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
557 HDC32 res
= CreateDC16( driverA
, deviceA
, outputA
,
558 (const DEVMODE16
*)initData
/*FIXME*/ );
559 HeapFree( GetProcessHeap(), 0, driverA
);
560 HeapFree( GetProcessHeap(), 0, deviceA
);
561 HeapFree( GetProcessHeap(), 0, outputA
);
566 /***********************************************************************
567 * CreateIC16 (GDI.153)
569 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
570 const DEVMODE16
* initData
)
572 /* Nothing special yet for ICs */
573 return CreateDC16( driver
, device
, output
, initData
);
577 /***********************************************************************
578 * CreateIC32A (GDI32.49)
580 HDC32 WINAPI
CreateIC32A( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
581 const DEVMODE32A
* initData
)
583 /* Nothing special yet for ICs */
584 return CreateDC32A( driver
, device
, output
, initData
);
588 /***********************************************************************
589 * CreateIC32W (GDI32.50)
591 HDC32 WINAPI
CreateIC32W( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
592 const DEVMODE32W
* initData
)
594 /* Nothing special yet for ICs */
595 return CreateDC32W( driver
, device
, output
, initData
);
599 /***********************************************************************
600 * CreateCompatibleDC16 (GDI.52)
602 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
604 return (HDC16
)CreateCompatibleDC32( hdc
);
608 /***********************************************************************
609 * CreateCompatibleDC32 (GDI32.31)
611 HDC32 WINAPI
CreateCompatibleDC32( HDC32 hdc
)
615 const DC_FUNCTIONS
*funcs
;
617 if ((origDC
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
))) funcs
= origDC
->funcs
;
618 else funcs
= DRIVER_FindDriver( "DISPLAY" );
619 if (!funcs
) return 0;
621 if (!(dc
= DC_AllocDC( funcs
))) return 0;
623 TRACE(dc
, "(%04x): returning %04x\n",
626 /* Create default bitmap */
627 if (!(hbitmap
= CreateBitmap32( 1, 1, 1, 1, NULL
)))
629 GDI_HEAP_FREE( dc
->hSelf
);
632 dc
->w
.flags
= DC_MEMORY
;
633 dc
->w
.bitsPerPixel
= 1;
634 dc
->w
.hBitmap
= hbitmap
;
635 dc
->w
.hFirstBitmap
= hbitmap
;
637 if (dc
->funcs
->pCreateDC
&&
638 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
640 WARN(dc
, "creation aborted by device\n");
641 DeleteObject32( hbitmap
);
642 GDI_HEAP_FREE( dc
->hSelf
);
647 GDI_HEAP_UNLOCK( dc
->hSelf
);
652 /***********************************************************************
653 * DeleteDC16 (GDI.68)
655 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
657 return DeleteDC32( hdc
);
661 /***********************************************************************
662 * DeleteDC32 (GDI32.67)
664 BOOL32 WINAPI
DeleteDC32( HDC32 hdc
)
666 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
667 if (!dc
) return FALSE
;
669 TRACE(dc
, "%04x\n", hdc
);
671 while (dc
->saveLevel
)
674 HDC16 hdcs
= dc
->header
.hNext
;
675 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
676 dc
->header
.hNext
= dcs
->header
.hNext
;
681 if (!(dc
->w
.flags
& DC_SAVED
))
683 SelectObject32( hdc
, STOCK_BLACK_PEN
);
684 SelectObject32( hdc
, STOCK_WHITE_BRUSH
);
685 SelectObject32( hdc
, STOCK_SYSTEM_FONT
);
686 if (dc
->w
.flags
& DC_MEMORY
) DeleteObject32( dc
->w
.hFirstBitmap
);
687 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
690 if (dc
->w
.hClipRgn
) DeleteObject32( dc
->w
.hClipRgn
);
691 if (dc
->w
.hVisRgn
) DeleteObject32( dc
->w
.hVisRgn
);
692 if (dc
->w
.hGCClipRgn
) DeleteObject32( dc
->w
.hGCClipRgn
);
694 PATH_DestroyGdiPath(&dc
->w
.path
);
696 return GDI_FreeObject( hdc
);
700 /***********************************************************************
701 * ResetDC16 (GDI.376)
703 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODE16
*devmode
)
705 FIXME(dc
, "stub\n" );
710 /***********************************************************************
711 * ResetDC32A (GDI32.287)
713 HDC32 WINAPI
ResetDC32A( HDC32 hdc
, const DEVMODE32A
*devmode
)
715 FIXME(dc
, "stub\n" );
720 /***********************************************************************
721 * ResetDC32W (GDI32.288)
723 HDC32 WINAPI
ResetDC32W( HDC32 hdc
, const DEVMODE32W
*devmode
)
725 FIXME(dc
, "stub\n" );
730 /***********************************************************************
731 * GetDeviceCaps16 (GDI.80)
733 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
735 return GetDeviceCaps32( hdc
, cap
);
739 /***********************************************************************
740 * GetDeviceCaps32 (GDI32.171)
742 INT32 WINAPI
GetDeviceCaps32( HDC32 hdc
, INT32 cap
)
744 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
749 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
)))
751 GDI_HEAP_UNLOCK( hdc
);
755 TRACE(dc
, "(%04x,%d): returning %d\n",
756 hdc
, cap
, *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
) );
757 ret
= *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
);
758 GDI_HEAP_UNLOCK( hdc
);
763 /***********************************************************************
764 * SetBkColor16 (GDI.1)
766 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
768 return SetBkColor32( hdc
, color
);
772 /***********************************************************************
773 * SetBkColor32 (GDI32.305)
775 COLORREF WINAPI
SetBkColor32( HDC32 hdc
, COLORREF color
)
778 DC
* dc
= DC_GetDCPtr( hdc
);
780 if (!dc
) return 0x80000000;
781 if (dc
->funcs
->pSetBkColor
)
782 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
784 oldColor
= dc
->w
.backgroundColor
;
785 dc
->w
.backgroundColor
= color
;
787 GDI_HEAP_UNLOCK( hdc
);
792 /***********************************************************************
793 * SetTextColor16 (GDI.9)
795 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
797 return SetTextColor32( hdc
, color
);
801 /***********************************************************************
802 * SetTextColor32 (GDI32.338)
804 COLORREF WINAPI
SetTextColor32( HDC32 hdc
, COLORREF color
)
807 DC
* dc
= DC_GetDCPtr( hdc
);
809 if (!dc
) return 0x80000000;
810 if (dc
->funcs
->pSetTextColor
)
811 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
813 oldColor
= dc
->w
.textColor
;
814 dc
->w
.textColor
= color
;
816 GDI_HEAP_UNLOCK( hdc
);
821 /***********************************************************************
822 * SetTextAlign16 (GDI.346)
824 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 textAlign
)
826 return SetTextAlign32( hdc
, textAlign
);
830 /***********************************************************************
831 * SetTextAlign32 (GDI32.336)
833 UINT32 WINAPI
SetTextAlign32( HDC32 hdc
, UINT32 textAlign
)
836 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
839 if (!(dc
= (DC
*)GDI_GetObjPtr( hdc
, METAFILE_DC_MAGIC
))) return 0;
840 MF_MetaParam1( dc
, META_SETTEXTALIGN
, textAlign
);
841 GDI_HEAP_UNLOCK( hdc
);
844 prevAlign
= dc
->w
.textAlign
;
845 dc
->w
.textAlign
= textAlign
;
846 GDI_HEAP_UNLOCK( hdc
);
851 /***********************************************************************
852 * GetDCOrgEx (GDI32.168)
854 BOOL32 WINAPI
GetDCOrgEx( HDC32 hDC
, LPPOINT32 lpp
)
857 if (!lpp
) return FALSE
;
858 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return FALSE
;
860 if (!(dc
->w
.flags
& DC_MEMORY
))
863 int w
, h
, border
, depth
;
864 /* FIXME: this is not correct for managed windows */
865 TSXGetGeometry( display
, dc
->u
.x
.drawable
, &root
,
866 &lpp
->x
, &lpp
->y
, &w
, &h
, &border
, &depth
);
868 else lpp
->x
= lpp
->y
= 0;
869 lpp
->x
+= dc
->w
.DCOrgX
; lpp
->y
+= dc
->w
.DCOrgY
;
870 GDI_HEAP_UNLOCK( hDC
);
875 /***********************************************************************
878 DWORD WINAPI
GetDCOrg( HDC16 hdc
)
881 if( GetDCOrgEx( hdc
, &pt
) )
882 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
887 /***********************************************************************
890 DWORD WINAPI
SetDCOrg( HDC16 hdc
, INT16 x
, INT16 y
)
893 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
895 prevOrg
= dc
->w
.DCOrgX
| (dc
->w
.DCOrgY
<< 16);
898 GDI_HEAP_UNLOCK( hdc
);
903 /***********************************************************************
904 * GetGraphicsMode (GDI32.188)
906 INT32 WINAPI
GetGraphicsMode( HDC32 hdc
)
908 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
910 return dc
->w
.GraphicsMode
;
914 /***********************************************************************
915 * SetGraphicsMode (GDI32.317)
917 INT32 WINAPI
SetGraphicsMode( HDC32 hdc
, INT32 mode
)
920 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
922 /* One would think that setting the graphics mode to GM_COMPATIBLE
923 * would also reset the world transformation matrix to the unity
924 * matrix. However, in Windows, this is not the case. This doesn't
925 * make a lot of sense to me, but that's the way it is.
929 if ((mode
<= 0) || (mode
> GM_LAST
)) return 0;
930 ret
= dc
->w
.GraphicsMode
;
931 dc
->w
.GraphicsMode
= mode
;
936 /***********************************************************************
937 * GetArcDirection16 (GDI.524)
939 INT16 WINAPI
GetArcDirection16( HDC16 hdc
)
941 return GetArcDirection32( (HDC32
)hdc
);
945 /***********************************************************************
946 * GetArcDirection32 (GDI32.141)
948 INT32 WINAPI
GetArcDirection32( HDC32 hdc
)
950 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
955 return dc
->w
.ArcDirection
;
959 /***********************************************************************
960 * SetArcDirection16 (GDI.525)
962 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
964 return SetArcDirection32( (HDC32
)hdc
, (INT32
)nDirection
);
968 /***********************************************************************
969 * SetArcDirection32 (GDI32.302)
971 INT32 WINAPI
SetArcDirection32( HDC32 hdc
, INT32 nDirection
)
973 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
979 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
981 SetLastError(ERROR_INVALID_PARAMETER
);
985 nOldDirection
= dc
->w
.ArcDirection
;
986 dc
->w
.ArcDirection
= nDirection
;
988 return nOldDirection
;
992 /***********************************************************************
993 * GetWorldTransform (GDI32.244)
995 BOOL32 WINAPI
GetWorldTransform( HDC32 hdc
, LPXFORM xform
)
997 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1004 *xform
= dc
->w
.xformWorld2Wnd
;
1010 /***********************************************************************
1011 * SetWorldTransform (GDI32.346)
1013 BOOL32 WINAPI
SetWorldTransform( HDC32 hdc
, const XFORM
*xform
)
1015 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1019 SetLastError( ERROR_INVALID_HANDLE
);
1026 /* Check that graphics mode is GM_ADVANCED */
1027 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1030 dc
->w
.xformWorld2Wnd
= *xform
;
1032 DC_UpdateXforms( dc
);
1038 /****************************************************************************
1039 * ModifyWorldTransform [GDI32.253]
1040 * Modifies the world transformation for a device context.
1043 * hdc [I] Handle to device context
1044 * xform [I] XFORM structure that will be used to modify the world
1046 * iMode [I] Specifies in what way to modify the world transformation
1049 * Resets the world transformation to the identity matrix.
1050 * The parameter xform is ignored.
1052 * Multiplies xform into the world transformation matrix from
1055 * Multiplies xform into the world transformation matrix from
1060 BOOL32 WINAPI
ModifyWorldTransform( HDC32 hdc
, const XFORM
*xform
,
1063 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1065 /* Check for illegal parameters */
1068 SetLastError( ERROR_INVALID_HANDLE
);
1074 /* Check that graphics mode is GM_ADVANCED */
1075 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1081 dc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1082 dc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1083 dc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1084 dc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1085 dc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1086 dc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1088 case MWT_LEFTMULTIPLY
:
1089 CombineTransform( &dc
->w
.xformWorld2Wnd
, xform
,
1090 &dc
->w
.xformWorld2Wnd
);
1092 case MWT_RIGHTMULTIPLY
:
1093 CombineTransform( &dc
->w
.xformWorld2Wnd
, &dc
->w
.xformWorld2Wnd
,
1100 DC_UpdateXforms( dc
);
1106 /****************************************************************************
1107 * CombineTransform [GDI32.20]
1108 * Combines two transformation matrices.
1111 * xformResult [O] Stores the result of combining the two matrices
1112 * xform1 [I] Specifies the first matrix to apply
1113 * xform2 [I] Specifies the second matrix to apply
1116 * The same matrix can be passed in for more than one of the parameters.
1120 BOOL32 WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1121 const XFORM
*xform2
)
1125 /* Check for illegal parameters */
1126 if (!xformResult
|| !xform1
|| !xform2
)
1129 /* Create the result in a temporary XFORM, since xformResult may be
1130 * equal to xform1 or xform2 */
1131 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1132 xform1
->eM12
* xform2
->eM21
;
1133 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1134 xform1
->eM12
* xform2
->eM22
;
1135 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1136 xform1
->eM22
* xform2
->eM21
;
1137 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1138 xform1
->eM22
* xform2
->eM22
;
1139 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1140 xform1
->eDy
* xform2
->eM21
+
1142 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1143 xform1
->eDy
* xform2
->eM22
+
1146 /* Copy the result to xformResult */
1147 *xformResult
= xformTemp
;
1153 /***********************************************************************
1154 * SetDCHook (GDI.190)
1156 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1158 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1160 TRACE(dc
, "hookProc %08x, default is %08x\n",
1161 (UINT32
)hookProc
, (UINT32
)DCHook
);
1163 if (!dc
) return FALSE
;
1164 dc
->hookProc
= hookProc
;
1165 dc
->dwHookData
= dwHookData
;
1166 GDI_HEAP_UNLOCK( hdc
);
1171 /***********************************************************************
1172 * GetDCHook (GDI.191)
1174 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1176 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1178 *phookProc
= dc
->hookProc
;
1179 GDI_HEAP_UNLOCK( hdc
);
1180 return dc
->dwHookData
;
1184 /***********************************************************************
1185 * SetHookFlags (GDI.192)
1187 WORD WINAPI
SetHookFlags(HDC16 hDC
, WORD flags
)
1189 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
1193 WORD wRet
= dc
->w
.flags
& DC_DIRTY
;
1195 /* "Undocumented Windows" info is slightly confusing.
1198 TRACE(dc
,"hDC %04x, flags %04x\n",hDC
,flags
);
1200 if( flags
& DCHF_INVALIDATEVISRGN
)
1201 dc
->w
.flags
|= DC_DIRTY
;
1202 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1203 dc
->w
.flags
&= ~DC_DIRTY
;
1204 GDI_HEAP_UNLOCK( hDC
);
1210 /***********************************************************************
1211 * SetICMMode (GDI32.318)
1213 INT32 WINAPI
SetICMMode(HDC32 hdc
, INT32 iEnableICM
)
1215 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1216 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1217 if (iEnableICM
== ICM_ON
) return 0;
1218 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1223 /***********************************************************************
1224 * GetColorSpace (GDI32.165)
1226 HCOLORSPACE32 WINAPI
GetColorSpace(HDC32 hdc
)
1228 /*FIXME Need to to whatever GetColorSpace actually does */
1232 /***********************************************************************
1233 * GetBoundsRect16 (GDI.194)
1235 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1237 FIXME(dc
, "(): stub\n");
1238 return DCB_RESET
; /* bounding rectangle always empty */
1241 /***********************************************************************
1242 * SetBoundsRect16 (GDI.193)
1244 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1246 FIXME(dc
, "(): stub\n");
1247 return DCB_DISABLE
; /* bounding rectangle always empty */