2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
15 #include "debugtools.h"
21 #include "wine/winuser16.h"
23 DEFAULT_DEBUG_CHANNEL(dc
);
25 /***********************************************************************
28 * Fill the WIN_DC_INFO structure.
30 static void DC_Init_DC_INFO( WIN_DC_INFO
*win_dc_info
)
32 win_dc_info
->flags
= 0;
33 win_dc_info
->devCaps
= NULL
;
34 win_dc_info
->hClipRgn
= 0;
35 win_dc_info
->hVisRgn
= 0;
36 win_dc_info
->hGCClipRgn
= 0;
37 win_dc_info
->hPen
= STOCK_BLACK_PEN
;
38 win_dc_info
->hBrush
= STOCK_WHITE_BRUSH
;
39 win_dc_info
->hFont
= STOCK_SYSTEM_FONT
;
40 win_dc_info
->hBitmap
= 0;
41 win_dc_info
->hDevice
= 0;
42 win_dc_info
->hPalette
= STOCK_DEFAULT_PALETTE
;
43 win_dc_info
->ROPmode
= R2_COPYPEN
;
44 win_dc_info
->polyFillMode
= ALTERNATE
;
45 win_dc_info
->stretchBltMode
= BLACKONWHITE
;
46 win_dc_info
->relAbsMode
= ABSOLUTE
;
47 win_dc_info
->backgroundMode
= OPAQUE
;
48 win_dc_info
->backgroundColor
= RGB( 255, 255, 255 );
49 win_dc_info
->textColor
= RGB( 0, 0, 0 );
50 win_dc_info
->brushOrgX
= 0;
51 win_dc_info
->brushOrgY
= 0;
52 win_dc_info
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
53 win_dc_info
->charExtra
= 0;
54 win_dc_info
->breakTotalExtra
= 0;
55 win_dc_info
->breakCount
= 0;
56 win_dc_info
->breakExtra
= 0;
57 win_dc_info
->breakRem
= 0;
58 win_dc_info
->bitsPerPixel
= 1;
59 win_dc_info
->MapMode
= MM_TEXT
;
60 win_dc_info
->GraphicsMode
= GM_COMPATIBLE
;
61 win_dc_info
->DCOrgX
= 0;
62 win_dc_info
->DCOrgY
= 0;
63 win_dc_info
->pAbortProc
= NULL
;
64 win_dc_info
->CursPosX
= 0;
65 win_dc_info
->CursPosY
= 0;
66 win_dc_info
->ArcDirection
= AD_COUNTERCLOCKWISE
;
67 win_dc_info
->xformWorld2Wnd
.eM11
= 1.0f
;
68 win_dc_info
->xformWorld2Wnd
.eM12
= 0.0f
;
69 win_dc_info
->xformWorld2Wnd
.eM21
= 0.0f
;
70 win_dc_info
->xformWorld2Wnd
.eM22
= 1.0f
;
71 win_dc_info
->xformWorld2Wnd
.eDx
= 0.0f
;
72 win_dc_info
->xformWorld2Wnd
.eDy
= 0.0f
;
73 win_dc_info
->xformWorld2Vport
= win_dc_info
->xformWorld2Wnd
;
74 win_dc_info
->xformVport2World
= win_dc_info
->xformWorld2Wnd
;
75 win_dc_info
->vport2WorldValid
= TRUE
;
77 PATH_InitGdiPath(&win_dc_info
->path
);
81 /***********************************************************************
84 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
89 if (!(hdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
))) return NULL
;
90 dc
= (DC
*) GDI_HEAP_LOCK( hdc
);
108 DC_Init_DC_INFO( &dc
->w
);
115 /***********************************************************************
118 DC
*DC_GetDCPtr( HDC hdc
)
120 GDIOBJHDR
*ptr
= (GDIOBJHDR
*)GDI_HEAP_LOCK( hdc
);
121 if (!ptr
) return NULL
;
122 if ((ptr
->wMagic
== DC_MAGIC
) || (ptr
->wMagic
== METAFILE_DC_MAGIC
) ||
123 (ptr
->wMagic
== ENHMETAFILE_DC_MAGIC
))
125 GDI_HEAP_UNLOCK( hdc
);
126 SetLastError( ERROR_INVALID_HANDLE
);
131 /***********************************************************************
134 * Setup device-specific DC values for a newly created DC.
136 void DC_InitDC( DC
* dc
)
138 RealizeDefaultPalette16( dc
->hSelf
);
139 SetTextColor( dc
->hSelf
, dc
->w
.textColor
);
140 SetBkColor( dc
->hSelf
, dc
->w
.backgroundColor
);
141 SelectObject( dc
->hSelf
, dc
->w
.hPen
);
142 SelectObject( dc
->hSelf
, dc
->w
.hBrush
);
143 SelectObject( dc
->hSelf
, dc
->w
.hFont
);
144 CLIPPING_UpdateGCRegion( dc
);
148 /***********************************************************************
151 * Computes the inverse of the transformation xformSrc and stores it to
152 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
155 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
159 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
160 xformSrc
->eM12
*xformSrc
->eM21
;
161 if (determinant
> -1e-12 && determinant
< 1e-12)
164 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
165 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
166 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
167 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
168 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
169 xformSrc
->eDy
* xformDest
->eM21
;
170 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
171 xformSrc
->eDy
* xformDest
->eM22
;
177 /***********************************************************************
180 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
181 * fields of the specified DC by creating a transformation that
182 * represents the current mapping mode and combining it with the DC's
183 * world transform. This function should be called whenever the
184 * parameters associated with the mapping mode (window and viewport
185 * extents and origins) or the world transform change.
187 void DC_UpdateXforms( DC
*dc
)
189 XFORM xformWnd2Vport
;
190 FLOAT scaleX
, scaleY
;
192 /* Construct a transformation to do the window-to-viewport conversion */
193 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
194 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
195 xformWnd2Vport
.eM11
= scaleX
;
196 xformWnd2Vport
.eM12
= 0.0;
197 xformWnd2Vport
.eM21
= 0.0;
198 xformWnd2Vport
.eM22
= scaleY
;
199 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
200 scaleX
* (FLOAT
)dc
->wndOrgX
;
201 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
202 scaleY
* (FLOAT
)dc
->wndOrgY
;
204 /* Combine with the world transformation */
205 CombineTransform( &dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
,
208 /* Create inverse of world-to-viewport transformation */
209 dc
->w
.vport2WorldValid
= DC_InvertXform( &dc
->w
.xformWorld2Vport
,
210 &dc
->w
.xformVport2World
);
214 /***********************************************************************
215 * GetDCState (GDI.179)
217 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
222 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
223 if (!(handle
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
)))
225 GDI_HEAP_UNLOCK( hdc
);
228 newdc
= (DC
*) GDI_HEAP_LOCK( handle
);
230 TRACE("(%04x): returning %04x\n", hdc
, handle
);
232 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
233 newdc
->w
.devCaps
= dc
->w
.devCaps
;
234 newdc
->w
.hPen
= dc
->w
.hPen
;
235 newdc
->w
.hBrush
= dc
->w
.hBrush
;
236 newdc
->w
.hFont
= dc
->w
.hFont
;
237 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
238 newdc
->w
.hDevice
= dc
->w
.hDevice
;
239 newdc
->w
.hPalette
= dc
->w
.hPalette
;
240 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
241 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
242 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
243 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
244 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
245 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
246 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
247 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
248 newdc
->w
.textColor
= dc
->w
.textColor
;
249 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
250 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
251 newdc
->w
.textAlign
= dc
->w
.textAlign
;
252 newdc
->w
.charExtra
= dc
->w
.charExtra
;
253 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
254 newdc
->w
.breakCount
= dc
->w
.breakCount
;
255 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
256 newdc
->w
.breakRem
= dc
->w
.breakRem
;
257 newdc
->w
.MapMode
= dc
->w
.MapMode
;
258 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
260 /* Apparently, the DC origin is not changed by [GS]etDCState */
261 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
262 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
264 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
265 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
266 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
267 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
268 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
269 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
270 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
271 newdc
->wndOrgX
= dc
->wndOrgX
;
272 newdc
->wndOrgY
= dc
->wndOrgY
;
273 newdc
->wndExtX
= dc
->wndExtX
;
274 newdc
->wndExtY
= dc
->wndExtY
;
275 newdc
->vportOrgX
= dc
->vportOrgX
;
276 newdc
->vportOrgY
= dc
->vportOrgY
;
277 newdc
->vportExtX
= dc
->vportExtX
;
278 newdc
->vportExtY
= dc
->vportExtY
;
280 newdc
->hSelf
= (HDC
)handle
;
281 newdc
->saveLevel
= 0;
283 PATH_InitGdiPath( &newdc
->w
.path
);
285 newdc
->w
.pAbortProc
= NULL
;
287 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
289 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
292 newdc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
293 CombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
296 newdc
->w
.hClipRgn
= 0;
297 GDI_HEAP_UNLOCK( handle
);
298 GDI_HEAP_UNLOCK( hdc
);
303 /***********************************************************************
304 * SetDCState (GDI.180)
306 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
310 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
311 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
313 GDI_HEAP_UNLOCK( hdc
);
316 if (!dcs
->w
.flags
& DC_SAVED
)
318 GDI_HEAP_UNLOCK( hdc
);
319 GDI_HEAP_UNLOCK( hdcs
);
322 TRACE("%04x %04x\n", hdc
, hdcs
);
324 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
325 dc
->w
.devCaps
= dcs
->w
.devCaps
;
326 dc
->w
.hDevice
= dcs
->w
.hDevice
;
327 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
328 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
329 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
330 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
331 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
332 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
333 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
334 dc
->w
.textColor
= dcs
->w
.textColor
;
335 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
336 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
337 dc
->w
.textAlign
= dcs
->w
.textAlign
;
338 dc
->w
.charExtra
= dcs
->w
.charExtra
;
339 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
340 dc
->w
.breakCount
= dcs
->w
.breakCount
;
341 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
342 dc
->w
.breakRem
= dcs
->w
.breakRem
;
343 dc
->w
.MapMode
= dcs
->w
.MapMode
;
344 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
346 /* Apparently, the DC origin is not changed by [GS]etDCState */
347 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
348 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
350 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
351 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
352 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
353 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
354 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
355 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
356 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
358 dc
->wndOrgX
= dcs
->wndOrgX
;
359 dc
->wndOrgY
= dcs
->wndOrgY
;
360 dc
->wndExtX
= dcs
->wndExtX
;
361 dc
->wndExtY
= dcs
->wndExtY
;
362 dc
->vportOrgX
= dcs
->vportOrgX
;
363 dc
->vportOrgY
= dcs
->vportOrgY
;
364 dc
->vportExtX
= dcs
->vportExtX
;
365 dc
->vportExtY
= dcs
->vportExtY
;
367 if (!(dc
->w
.flags
& DC_MEMORY
)) dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
371 if (!dc
->w
.hClipRgn
) dc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
372 CombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
376 if (dc
->w
.hClipRgn
) DeleteObject16( dc
->w
.hClipRgn
);
379 CLIPPING_UpdateGCRegion( dc
);
381 SelectObject( hdc
, dcs
->w
.hBitmap
);
382 SelectObject( hdc
, dcs
->w
.hBrush
);
383 SelectObject( hdc
, dcs
->w
.hFont
);
384 SelectObject( hdc
, dcs
->w
.hPen
);
385 SetBkColor( hdc
, dcs
->w
.backgroundColor
);
386 SetTextColor( hdc
, dcs
->w
.textColor
);
387 GDISelectPalette16( hdc
, dcs
->w
.hPalette
, FALSE
);
388 GDI_HEAP_UNLOCK( hdc
);
389 GDI_HEAP_UNLOCK( hdcs
);
393 /***********************************************************************
396 INT16 WINAPI
SaveDC16( HDC16 hdc
)
398 return (INT16
)SaveDC( hdc
);
402 /***********************************************************************
405 INT WINAPI
SaveDC( HDC hdc
)
411 dc
= DC_GetDCPtr( hdc
);
414 if(dc
->funcs
->pSaveDC
)
415 return dc
->funcs
->pSaveDC( dc
);
417 if (!(hdcs
= GetDCState16( hdc
)))
419 GDI_HEAP_UNLOCK( hdc
);
422 dcs
= (DC
*) GDI_HEAP_LOCK( hdcs
);
424 /* Copy path. The reason why path saving / restoring is in SaveDC/
425 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
426 * functions are only in Win16 (which doesn't have paths) and that
427 * SetDCState doesn't allow us to signal an error (which can happen
428 * when copying paths).
430 if (!PATH_AssignGdiPath( &dcs
->w
.path
, &dc
->w
.path
))
432 GDI_HEAP_UNLOCK( hdc
);
433 GDI_HEAP_UNLOCK( hdcs
);
438 dcs
->header
.hNext
= dc
->header
.hNext
;
439 dc
->header
.hNext
= hdcs
;
440 TRACE("(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
441 ret
= ++dc
->saveLevel
;
442 GDI_HEAP_UNLOCK( hdcs
);
443 GDI_HEAP_UNLOCK( hdc
);
448 /***********************************************************************
449 * RestoreDC16 (GDI.39)
451 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
453 return RestoreDC( hdc
, level
);
457 /***********************************************************************
458 * RestoreDC (GDI32.290)
460 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
465 TRACE("%04x %d\n", hdc
, level
);
466 dc
= DC_GetDCPtr( hdc
);
467 if(!dc
) return FALSE
;
468 if(dc
->funcs
->pRestoreDC
)
469 return dc
->funcs
->pRestoreDC( dc
, level
);
471 if (level
== -1) level
= dc
->saveLevel
;
472 if ((level
< 1) || (level
> dc
->saveLevel
))
474 GDI_HEAP_UNLOCK( hdc
);
479 while (dc
->saveLevel
>= level
)
481 HDC16 hdcs
= dc
->header
.hNext
;
482 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
484 GDI_HEAP_UNLOCK( hdc
);
487 dc
->header
.hNext
= dcs
->header
.hNext
;
488 if (--dc
->saveLevel
< level
)
490 SetDCState16( hdc
, hdcs
);
491 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
492 /* FIXME: This might not be quite right, since we're
493 * returning FALSE but still destroying the saved DC state */
498 GDI_HEAP_UNLOCK( hdc
);
503 /***********************************************************************
504 * CreateDC16 (GDI.53)
506 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
507 const DEVMODEA
*initData
)
510 const DC_FUNCTIONS
*funcs
;
514 if(!DRIVER_GetDriverName( device
, buf
, sizeof(buf
) )) return 0;
518 if (!(funcs
= DRIVER_FindDriver( buf
))) return 0;
519 if (!(dc
= DC_AllocDC( funcs
))) return 0;
522 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
523 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
525 if (dc
->funcs
->pCreateDC
&&
526 !dc
->funcs
->pCreateDC( dc
, buf
, device
, output
, initData
))
528 WARN("creation aborted by device\n" );
529 GDI_HEAP_FREE( dc
->hSelf
);
534 GDI_HEAP_UNLOCK( dc
->hSelf
);
539 /***********************************************************************
542 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
543 const DEVMODEA
*initData
)
545 return CreateDC16( driver
, device
, output
, (const DEVMODEA
*)initData
);
549 /***********************************************************************
552 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
553 const DEVMODEW
*initData
)
555 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
556 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
557 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
558 HDC res
= CreateDC16( driverA
, deviceA
, outputA
,
559 (const DEVMODEA
*)initData
/*FIXME*/ );
560 HeapFree( GetProcessHeap(), 0, driverA
);
561 HeapFree( GetProcessHeap(), 0, deviceA
);
562 HeapFree( GetProcessHeap(), 0, outputA
);
567 /***********************************************************************
568 * CreateIC16 (GDI.153)
570 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
571 const DEVMODEA
* initData
)
573 /* Nothing special yet for ICs */
574 return CreateDC16( driver
, device
, output
, initData
);
578 /***********************************************************************
579 * CreateICA (GDI32.49)
581 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
582 const DEVMODEA
* initData
)
584 /* Nothing special yet for ICs */
585 return CreateDCA( driver
, device
, output
, initData
);
589 /***********************************************************************
590 * CreateICW (GDI32.50)
592 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
593 const DEVMODEW
* initData
)
595 /* Nothing special yet for ICs */
596 return CreateDCW( driver
, device
, output
, initData
);
600 /***********************************************************************
601 * CreateCompatibleDC16 (GDI.52)
603 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
605 return (HDC16
)CreateCompatibleDC( hdc
);
609 /***********************************************************************
610 * CreateCompatibleDC (GDI32.31)
612 HDC WINAPI
CreateCompatibleDC( HDC 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("(%04x): returning %04x\n",
626 dc
->w
.flags
= DC_MEMORY
;
627 dc
->w
.bitsPerPixel
= 1;
628 dc
->w
.hBitmap
= hPseudoStockBitmap
;
630 /* Copy the driver-specific physical device info into
631 * the new DC. The driver may use this read-only info
632 * while creating the compatible DC below. */
634 dc
->physDev
= origDC
->physDev
;
636 if (dc
->funcs
->pCreateDC
&&
637 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
639 WARN("creation aborted by device\n");
640 GDI_HEAP_FREE( dc
->hSelf
);
645 GDI_HEAP_UNLOCK( dc
->hSelf
);
650 /***********************************************************************
651 * DeleteDC16 (GDI.68)
653 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
655 return DeleteDC( hdc
);
659 /***********************************************************************
660 * DeleteDC (GDI32.67)
662 BOOL WINAPI
DeleteDC( HDC hdc
)
664 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
665 if (!dc
) return FALSE
;
667 TRACE("%04x\n", hdc
);
669 /* Call hook procedure to check whether is it OK to delete this DC */
670 if ( dc
->hookThunk
&& !(dc
->w
.flags
& (DC_SAVED
| DC_MEMORY
))
671 && dc
->hookThunk( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ) == FALSE
)
673 GDI_HEAP_UNLOCK( hdc
);
677 while (dc
->saveLevel
)
680 HDC16 hdcs
= dc
->header
.hNext
;
681 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
682 dc
->header
.hNext
= dcs
->header
.hNext
;
687 if (!(dc
->w
.flags
& DC_SAVED
))
689 SelectObject( hdc
, STOCK_BLACK_PEN
);
690 SelectObject( hdc
, STOCK_WHITE_BRUSH
);
691 SelectObject( hdc
, STOCK_SYSTEM_FONT
);
692 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
695 if (dc
->w
.hClipRgn
) DeleteObject( dc
->w
.hClipRgn
);
696 if (dc
->w
.hVisRgn
) DeleteObject( dc
->w
.hVisRgn
);
697 if (dc
->w
.hGCClipRgn
) DeleteObject( dc
->w
.hGCClipRgn
);
698 if (dc
->w
.pAbortProc
) THUNK_Free( (FARPROC
)dc
->w
.pAbortProc
);
699 if (dc
->hookThunk
) THUNK_Free( (FARPROC
)dc
->hookThunk
);
700 PATH_DestroyGdiPath(&dc
->w
.path
);
702 return GDI_FreeObject( hdc
);
706 /***********************************************************************
707 * ResetDC16 (GDI.376)
709 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODEA
*devmode
)
716 /***********************************************************************
717 * ResetDCA (GDI32.287)
719 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
726 /***********************************************************************
727 * ResetDCW (GDI32.288)
729 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
736 /***********************************************************************
737 * GetDeviceCaps16 (GDI.80)
739 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
741 return GetDeviceCaps( hdc
, cap
);
745 /***********************************************************************
746 * GetDeviceCaps (GDI32.171)
748 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
750 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
756 /* Device capabilities for the printer */
760 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
763 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
765 case PHYSICALOFFSETX
:
766 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
768 case PHYSICALOFFSETY
:
769 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
772 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
775 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
779 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
)))
781 GDI_HEAP_UNLOCK( hdc
);
785 if (((cap
>=46) && (cap
<88)) || ((cap
>=92) && (cap
<104)))
786 FIXME("(%04x,%d): unsupported DeviceCaps capability, will yield 0!\n",
789 TRACE("(%04x,%d): returning %d\n",
790 hdc
, cap
, *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
) );
791 ret
= *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
);
792 GDI_HEAP_UNLOCK( hdc
);
797 /***********************************************************************
798 * SetBkColor16 (GDI.1)
800 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
802 return SetBkColor( hdc
, color
);
806 /***********************************************************************
807 * SetBkColor (GDI32.305)
809 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
812 DC
* dc
= DC_GetDCPtr( hdc
);
814 if (!dc
) return 0x80000000;
815 if (dc
->funcs
->pSetBkColor
)
816 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
818 oldColor
= dc
->w
.backgroundColor
;
819 dc
->w
.backgroundColor
= color
;
821 GDI_HEAP_UNLOCK( hdc
);
826 /***********************************************************************
827 * SetTextColor16 (GDI.9)
829 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
831 return SetTextColor( hdc
, color
);
835 /***********************************************************************
836 * SetTextColor (GDI32.338)
838 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
841 DC
* dc
= DC_GetDCPtr( hdc
);
843 if (!dc
) return 0x80000000;
844 if (dc
->funcs
->pSetTextColor
)
845 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
847 oldColor
= dc
->w
.textColor
;
848 dc
->w
.textColor
= color
;
850 GDI_HEAP_UNLOCK( hdc
);
854 /***********************************************************************
855 * SetTextAlign16 (GDI.346)
857 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 align
)
859 return SetTextAlign( hdc
, align
);
863 /***********************************************************************
864 * SetTextAlign (GDI32.336)
866 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
869 DC
*dc
= DC_GetDCPtr( hdc
);
871 if (dc
->funcs
->pSetTextAlign
)
872 prevAlign
= dc
->funcs
->pSetTextAlign(dc
, align
);
874 prevAlign
= dc
->w
.textAlign
;
875 dc
->w
.textAlign
= align
;
877 GDI_HEAP_UNLOCK( hdc
);
881 /***********************************************************************
882 * GetDCOrgEx (GDI32.168)
884 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
888 if (!lpp
) return FALSE
;
889 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return FALSE
;
892 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
, lpp
);
893 lpp
->x
+= dc
->w
.DCOrgX
;
894 lpp
->y
+= dc
->w
.DCOrgY
;
895 GDI_HEAP_UNLOCK( hDC
);
900 /***********************************************************************
903 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
906 if( GetDCOrgEx( hdc
, &pt
) )
907 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
912 /***********************************************************************
915 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
918 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
920 prevOrg
= dc
->w
.DCOrgX
| (dc
->w
.DCOrgY
<< 16);
923 GDI_HEAP_UNLOCK( hdc
);
928 /***********************************************************************
929 * GetGraphicsMode (GDI32.188)
931 INT WINAPI
GetGraphicsMode( HDC hdc
)
933 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
935 return dc
->w
.GraphicsMode
;
939 /***********************************************************************
940 * SetGraphicsMode (GDI32.317)
942 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
945 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
947 /* One would think that setting the graphics mode to GM_COMPATIBLE
948 * would also reset the world transformation matrix to the unity
949 * matrix. However, in Windows, this is not the case. This doesn't
950 * make a lot of sense to me, but that's the way it is.
954 if ((mode
<= 0) || (mode
> GM_LAST
)) return 0;
955 ret
= dc
->w
.GraphicsMode
;
956 dc
->w
.GraphicsMode
= mode
;
961 /***********************************************************************
962 * GetArcDirection16 (GDI.524)
964 INT16 WINAPI
GetArcDirection16( HDC16 hdc
)
966 return GetArcDirection( (HDC
)hdc
);
970 /***********************************************************************
971 * GetArcDirection (GDI32.141)
973 INT WINAPI
GetArcDirection( HDC hdc
)
975 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
980 return dc
->w
.ArcDirection
;
984 /***********************************************************************
985 * SetArcDirection16 (GDI.525)
987 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
989 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
993 /***********************************************************************
994 * SetArcDirection (GDI32.302)
996 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
998 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1004 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1006 SetLastError(ERROR_INVALID_PARAMETER
);
1010 nOldDirection
= dc
->w
.ArcDirection
;
1011 dc
->w
.ArcDirection
= nDirection
;
1013 return nOldDirection
;
1017 /***********************************************************************
1018 * GetWorldTransform (GDI32.244)
1020 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1022 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1029 *xform
= dc
->w
.xformWorld2Wnd
;
1035 /***********************************************************************
1036 * SetWorldTransform (GDI32.346)
1038 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1040 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1044 SetLastError( ERROR_INVALID_HANDLE
);
1051 /* Check that graphics mode is GM_ADVANCED */
1052 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1055 dc
->w
.xformWorld2Wnd
= *xform
;
1057 DC_UpdateXforms( dc
);
1063 /****************************************************************************
1064 * ModifyWorldTransform [GDI32.253]
1065 * Modifies the world transformation for a device context.
1068 * hdc [I] Handle to device context
1069 * xform [I] XFORM structure that will be used to modify the world
1071 * iMode [I] Specifies in what way to modify the world transformation
1074 * Resets the world transformation to the identity matrix.
1075 * The parameter xform is ignored.
1077 * Multiplies xform into the world transformation matrix from
1080 * Multiplies xform into the world transformation matrix from
1085 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1088 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1090 /* Check for illegal parameters */
1093 SetLastError( ERROR_INVALID_HANDLE
);
1099 /* Check that graphics mode is GM_ADVANCED */
1100 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1106 dc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1107 dc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1108 dc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1109 dc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1110 dc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1111 dc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1113 case MWT_LEFTMULTIPLY
:
1114 CombineTransform( &dc
->w
.xformWorld2Wnd
, xform
,
1115 &dc
->w
.xformWorld2Wnd
);
1117 case MWT_RIGHTMULTIPLY
:
1118 CombineTransform( &dc
->w
.xformWorld2Wnd
, &dc
->w
.xformWorld2Wnd
,
1125 DC_UpdateXforms( dc
);
1131 /****************************************************************************
1132 * CombineTransform [GDI32.20]
1133 * Combines two transformation matrices.
1136 * xformResult [O] Stores the result of combining the two matrices
1137 * xform1 [I] Specifies the first matrix to apply
1138 * xform2 [I] Specifies the second matrix to apply
1141 * The same matrix can be passed in for more than one of the parameters.
1145 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1146 const XFORM
*xform2
)
1150 /* Check for illegal parameters */
1151 if (!xformResult
|| !xform1
|| !xform2
)
1154 /* Create the result in a temporary XFORM, since xformResult may be
1155 * equal to xform1 or xform2 */
1156 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1157 xform1
->eM12
* xform2
->eM21
;
1158 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1159 xform1
->eM12
* xform2
->eM22
;
1160 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1161 xform1
->eM22
* xform2
->eM21
;
1162 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1163 xform1
->eM22
* xform2
->eM22
;
1164 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1165 xform1
->eDy
* xform2
->eM21
+
1167 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1168 xform1
->eDy
* xform2
->eM22
+
1171 /* Copy the result to xformResult */
1172 *xformResult
= xformTemp
;
1178 /***********************************************************************
1179 * SetDCHook (GDI.190)
1181 /* ### start build ### */
1182 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
1183 /* ### stop build ### */
1184 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1186 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1187 if (!dc
) return FALSE
;
1190 * Note: We store the original SEGPTR 'hookProc' as we need to be
1191 * able to return it verbatim in GetDCHook,
1193 * On the other hand, we still call THUNK_Alloc and store the
1194 * 32-bit thunk into another DC member, because THUNK_Alloc
1195 * recognizes the (typical) case that the 'hookProc' is indeed
1196 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1198 * We could perform that test every time the hook is about to
1199 * be called (or else we could live with the 32->16->32 detour),
1200 * but this way is the most efficient ...
1203 dc
->hookProc
= hookProc
;
1204 dc
->dwHookData
= dwHookData
;
1206 THUNK_Free( (FARPROC
)dc
->hookThunk
);
1207 dc
->hookThunk
= (DCHOOKPROC
)
1208 THUNK_Alloc( hookProc
, (RELAY
)GDI_CallTo16_word_wwll
);
1210 GDI_HEAP_UNLOCK( hdc
);
1215 /***********************************************************************
1216 * GetDCHook (GDI.191)
1218 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1220 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1222 *phookProc
= dc
->hookProc
;
1223 GDI_HEAP_UNLOCK( hdc
);
1224 return dc
->dwHookData
;
1228 /***********************************************************************
1229 * SetHookFlags (GDI.192)
1231 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1233 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
1237 WORD wRet
= dc
->w
.flags
& DC_DIRTY
;
1239 /* "Undocumented Windows" info is slightly confusing.
1242 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1244 if( flags
& DCHF_INVALIDATEVISRGN
)
1245 dc
->w
.flags
|= DC_DIRTY
;
1246 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1247 dc
->w
.flags
&= ~DC_DIRTY
;
1248 GDI_HEAP_UNLOCK( hDC
);
1254 /***********************************************************************
1255 * SetICMMode (GDI32.318)
1257 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1259 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1260 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1261 if (iEnableICM
== ICM_ON
) return 0;
1262 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1267 /***********************************************************************
1268 * GetColorSpace (GDI32.165)
1270 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1272 /*FIXME Need to to whatever GetColorSpace actually does */
1276 /***********************************************************************
1277 * CreateColorSpaceA (GDI32.???)
1279 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1285 /***********************************************************************
1286 * CreateColorSpaceW (GDI32.???)
1288 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1294 /***********************************************************************
1295 * DeleteColorSpace (GDI32.???)
1297 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1304 /***********************************************************************
1305 * SetColorSpace (GDI32.???)
1307 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1314 /***********************************************************************
1315 * GetBoundsRect16 (GDI.194)
1317 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1319 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1322 /***********************************************************************
1323 * GetBoundsRect (GDI32.147)
1325 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1327 FIXME("(): stub\n");
1328 return DCB_RESET
; /* bounding rectangle always empty */
1331 /***********************************************************************
1332 * SetBoundsRect16 (GDI.193)
1334 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1336 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1337 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1339 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1342 /***********************************************************************
1343 * SetBoundsRect (GDI32.307)
1345 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1347 FIXME("(): stub\n");
1348 return DCB_DISABLE
; /* bounding rectangle always empty */
1352 /***********************************************************************
1353 * GetRelAbs (GDI32.218)
1355 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1357 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1359 return dc
->w
.relAbsMode
;
1362 /***********************************************************************
1365 * Disables GDI, switches back to text mode.
1366 * We don't have to do anything here,
1367 * just let console support handle everything
1369 void WINAPI
Death16(HDC16 hDC
)
1371 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1374 /***********************************************************************
1375 * Resurrection (GDI.122)
1377 * Restores GDI functionality
1379 void WINAPI
Resurrection16(HDC16 hDC
,
1380 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1382 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1385 /***********************************************************************
1386 * GetLayout (GDI32.321)
1388 * Gets left->right or right->left text layout flags of a dc.
1389 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1392 DWORD WINAPI
GetLayout(HDC hdc
)
1394 FIXME("(%08x): stub\n", hdc
);
1395 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1399 /***********************************************************************
1400 * SetLayout (GDI32.450)
1402 * Sets left->right or right->left text layout flags of a dc.
1403 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1406 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1408 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1409 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);