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
);
130 /***********************************************************************
133 * Setup device-specific DC values for a newly created DC.
135 void DC_InitDC( DC
* dc
)
137 RealizeDefaultPalette16( dc
->hSelf
);
138 SetTextColor( dc
->hSelf
, dc
->w
.textColor
);
139 SetBkColor( dc
->hSelf
, dc
->w
.backgroundColor
);
140 SelectObject( dc
->hSelf
, dc
->w
.hPen
);
141 SelectObject( dc
->hSelf
, dc
->w
.hBrush
);
142 SelectObject( dc
->hSelf
, dc
->w
.hFont
);
143 CLIPPING_UpdateGCRegion( dc
);
147 /***********************************************************************
150 * Computes the inverse of the transformation xformSrc and stores it to
151 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
154 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
158 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
159 xformSrc
->eM12
*xformSrc
->eM21
;
160 if (determinant
> -1e-12 && determinant
< 1e-12)
163 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
164 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
165 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
166 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
167 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
168 xformSrc
->eDy
* xformDest
->eM21
;
169 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
170 xformSrc
->eDy
* xformDest
->eM22
;
176 /***********************************************************************
179 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
180 * fields of the specified DC by creating a transformation that
181 * represents the current mapping mode and combining it with the DC's
182 * world transform. This function should be called whenever the
183 * parameters associated with the mapping mode (window and viewport
184 * extents and origins) or the world transform change.
186 void DC_UpdateXforms( DC
*dc
)
188 XFORM xformWnd2Vport
;
189 FLOAT scaleX
, scaleY
;
191 /* Construct a transformation to do the window-to-viewport conversion */
192 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
193 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
194 xformWnd2Vport
.eM11
= scaleX
;
195 xformWnd2Vport
.eM12
= 0.0;
196 xformWnd2Vport
.eM21
= 0.0;
197 xformWnd2Vport
.eM22
= scaleY
;
198 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
199 scaleX
* (FLOAT
)dc
->wndOrgX
;
200 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
201 scaleY
* (FLOAT
)dc
->wndOrgY
;
203 /* Combine with the world transformation */
204 CombineTransform( &dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
,
207 /* Create inverse of world-to-viewport transformation */
208 dc
->w
.vport2WorldValid
= DC_InvertXform( &dc
->w
.xformWorld2Vport
,
209 &dc
->w
.xformVport2World
);
213 /***********************************************************************
214 * GetDCState (GDI.179)
216 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
221 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
222 if (!(handle
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
)))
224 GDI_HEAP_UNLOCK( hdc
);
227 newdc
= (DC
*) GDI_HEAP_LOCK( handle
);
229 TRACE("(%04x): returning %04x\n", hdc
, handle
);
231 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
232 newdc
->w
.devCaps
= dc
->w
.devCaps
;
233 newdc
->w
.hPen
= dc
->w
.hPen
;
234 newdc
->w
.hBrush
= dc
->w
.hBrush
;
235 newdc
->w
.hFont
= dc
->w
.hFont
;
236 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
237 newdc
->w
.hDevice
= dc
->w
.hDevice
;
238 newdc
->w
.hPalette
= dc
->w
.hPalette
;
239 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
240 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
241 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
242 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
243 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
244 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
245 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
246 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
247 newdc
->w
.textColor
= dc
->w
.textColor
;
248 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
249 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
250 newdc
->w
.textAlign
= dc
->w
.textAlign
;
251 newdc
->w
.charExtra
= dc
->w
.charExtra
;
252 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
253 newdc
->w
.breakCount
= dc
->w
.breakCount
;
254 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
255 newdc
->w
.breakRem
= dc
->w
.breakRem
;
256 newdc
->w
.MapMode
= dc
->w
.MapMode
;
257 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
259 /* Apparently, the DC origin is not changed by [GS]etDCState */
260 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
261 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
263 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
264 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
265 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
266 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
267 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
268 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
269 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
270 newdc
->wndOrgX
= dc
->wndOrgX
;
271 newdc
->wndOrgY
= dc
->wndOrgY
;
272 newdc
->wndExtX
= dc
->wndExtX
;
273 newdc
->wndExtY
= dc
->wndExtY
;
274 newdc
->vportOrgX
= dc
->vportOrgX
;
275 newdc
->vportOrgY
= dc
->vportOrgY
;
276 newdc
->vportExtX
= dc
->vportExtX
;
277 newdc
->vportExtY
= dc
->vportExtY
;
279 newdc
->hSelf
= (HDC
)handle
;
280 newdc
->saveLevel
= 0;
282 PATH_InitGdiPath( &newdc
->w
.path
);
284 newdc
->w
.pAbortProc
= NULL
;
286 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
288 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
291 newdc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
292 CombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
295 newdc
->w
.hClipRgn
= 0;
296 GDI_HEAP_UNLOCK( handle
);
297 GDI_HEAP_UNLOCK( hdc
);
302 /***********************************************************************
303 * SetDCState (GDI.180)
305 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
309 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
310 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
312 GDI_HEAP_UNLOCK( hdc
);
315 if (!dcs
->w
.flags
& DC_SAVED
)
317 GDI_HEAP_UNLOCK( hdc
);
318 GDI_HEAP_UNLOCK( hdcs
);
321 TRACE("%04x %04x\n", hdc
, hdcs
);
323 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
324 dc
->w
.devCaps
= dcs
->w
.devCaps
;
325 dc
->w
.hDevice
= dcs
->w
.hDevice
;
326 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
327 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
328 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
329 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
330 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
331 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
332 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
333 dc
->w
.textColor
= dcs
->w
.textColor
;
334 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
335 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
336 dc
->w
.textAlign
= dcs
->w
.textAlign
;
337 dc
->w
.charExtra
= dcs
->w
.charExtra
;
338 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
339 dc
->w
.breakCount
= dcs
->w
.breakCount
;
340 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
341 dc
->w
.breakRem
= dcs
->w
.breakRem
;
342 dc
->w
.MapMode
= dcs
->w
.MapMode
;
343 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
345 /* Apparently, the DC origin is not changed by [GS]etDCState */
346 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
347 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
349 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
350 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
351 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
352 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
353 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
354 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
355 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
357 dc
->wndOrgX
= dcs
->wndOrgX
;
358 dc
->wndOrgY
= dcs
->wndOrgY
;
359 dc
->wndExtX
= dcs
->wndExtX
;
360 dc
->wndExtY
= dcs
->wndExtY
;
361 dc
->vportOrgX
= dcs
->vportOrgX
;
362 dc
->vportOrgY
= dcs
->vportOrgY
;
363 dc
->vportExtX
= dcs
->vportExtX
;
364 dc
->vportExtY
= dcs
->vportExtY
;
366 if (!(dc
->w
.flags
& DC_MEMORY
)) dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
370 if (!dc
->w
.hClipRgn
) dc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
371 CombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
375 if (dc
->w
.hClipRgn
) DeleteObject16( dc
->w
.hClipRgn
);
378 CLIPPING_UpdateGCRegion( dc
);
380 SelectObject( hdc
, dcs
->w
.hBitmap
);
381 SelectObject( hdc
, dcs
->w
.hBrush
);
382 SelectObject( hdc
, dcs
->w
.hFont
);
383 SelectObject( hdc
, dcs
->w
.hPen
);
384 SetBkColor( hdc
, dcs
->w
.backgroundColor
);
385 SetTextColor( hdc
, dcs
->w
.textColor
);
386 GDISelectPalette16( hdc
, dcs
->w
.hPalette
, FALSE
);
387 GDI_HEAP_UNLOCK( hdc
);
388 GDI_HEAP_UNLOCK( hdcs
);
392 /***********************************************************************
395 INT16 WINAPI
SaveDC16( HDC16 hdc
)
397 return (INT16
)SaveDC( hdc
);
401 /***********************************************************************
404 INT WINAPI
SaveDC( HDC hdc
)
410 dc
= DC_GetDCPtr( hdc
);
413 if(dc
->funcs
->pSaveDC
)
414 return dc
->funcs
->pSaveDC( dc
);
416 if (!(hdcs
= GetDCState16( hdc
)))
418 GDI_HEAP_UNLOCK( hdc
);
421 dcs
= (DC
*) GDI_HEAP_LOCK( hdcs
);
423 /* Copy path. The reason why path saving / restoring is in SaveDC/
424 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
425 * functions are only in Win16 (which doesn't have paths) and that
426 * SetDCState doesn't allow us to signal an error (which can happen
427 * when copying paths).
429 if (!PATH_AssignGdiPath( &dcs
->w
.path
, &dc
->w
.path
))
431 GDI_HEAP_UNLOCK( hdc
);
432 GDI_HEAP_UNLOCK( hdcs
);
437 dcs
->header
.hNext
= dc
->header
.hNext
;
438 dc
->header
.hNext
= hdcs
;
439 TRACE("(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
440 ret
= ++dc
->saveLevel
;
441 GDI_HEAP_UNLOCK( hdcs
);
442 GDI_HEAP_UNLOCK( hdc
);
447 /***********************************************************************
448 * RestoreDC16 (GDI.39)
450 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
452 return RestoreDC( hdc
, level
);
456 /***********************************************************************
457 * RestoreDC (GDI32.290)
459 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
464 TRACE("%04x %d\n", hdc
, level
);
465 dc
= DC_GetDCPtr( hdc
);
466 if(!dc
) return FALSE
;
467 if(dc
->funcs
->pRestoreDC
)
468 return dc
->funcs
->pRestoreDC( dc
, level
);
470 if (level
== -1) level
= dc
->saveLevel
;
471 if ((level
< 1) || (level
> dc
->saveLevel
))
473 GDI_HEAP_UNLOCK( hdc
);
478 while (dc
->saveLevel
>= level
)
480 HDC16 hdcs
= dc
->header
.hNext
;
481 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
483 GDI_HEAP_UNLOCK( hdc
);
486 dc
->header
.hNext
= dcs
->header
.hNext
;
487 if (--dc
->saveLevel
< level
)
489 SetDCState16( hdc
, hdcs
);
490 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
491 /* FIXME: This might not be quite right, since we're
492 * returning FALSE but still destroying the saved DC state */
497 GDI_HEAP_UNLOCK( hdc
);
502 /***********************************************************************
503 * CreateDC16 (GDI.53)
505 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
506 const DEVMODEA
*initData
)
509 const DC_FUNCTIONS
*funcs
;
513 if(!DRIVER_GetDriverName( device
, buf
, sizeof(buf
) )) return 0;
517 if (!(funcs
= DRIVER_FindDriver( buf
))) return 0;
518 if (!(dc
= DC_AllocDC( funcs
))) return 0;
521 TRACE("(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
, buf
, device
, output
, initData
))
527 WARN("creation aborted by device\n" );
528 GDI_HEAP_FREE( dc
->hSelf
);
533 GDI_HEAP_UNLOCK( dc
->hSelf
);
538 /***********************************************************************
541 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
542 const DEVMODEA
*initData
)
544 return CreateDC16( driver
, device
, output
, (const DEVMODEA
*)initData
);
548 /***********************************************************************
551 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
552 const DEVMODEW
*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 HDC res
= CreateDC16( driverA
, deviceA
, outputA
,
558 (const DEVMODEA
*)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 DEVMODEA
* initData
)
572 /* Nothing special yet for ICs */
573 return CreateDC16( driver
, device
, output
, initData
);
577 /***********************************************************************
578 * CreateICA (GDI32.49)
580 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
581 const DEVMODEA
* initData
)
583 /* Nothing special yet for ICs */
584 return CreateDCA( driver
, device
, output
, initData
);
588 /***********************************************************************
589 * CreateICW (GDI32.50)
591 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
592 const DEVMODEW
* initData
)
594 /* Nothing special yet for ICs */
595 return CreateDCW( driver
, device
, output
, initData
);
599 /***********************************************************************
600 * CreateCompatibleDC16 (GDI.52)
602 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
604 return (HDC16
)CreateCompatibleDC( hdc
);
608 /***********************************************************************
609 * CreateCompatibleDC (GDI32.31)
611 HDC WINAPI
CreateCompatibleDC( HDC 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("(%04x): returning %04x\n",
625 dc
->w
.flags
= DC_MEMORY
;
626 dc
->w
.bitsPerPixel
= 1;
627 dc
->w
.hBitmap
= hPseudoStockBitmap
;
629 /* Copy the driver-specific physical device info into
630 * the new DC. The driver may use this read-only info
631 * while creating the compatible DC below. */
633 dc
->physDev
= origDC
->physDev
;
635 if (dc
->funcs
->pCreateDC
&&
636 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
638 WARN("creation aborted by device\n");
639 GDI_HEAP_FREE( dc
->hSelf
);
644 GDI_HEAP_UNLOCK( dc
->hSelf
);
649 /***********************************************************************
650 * DeleteDC16 (GDI.68)
652 BOOL16 WINAPI
DeleteDC16( HDC16 hdc
)
654 return DeleteDC( hdc
);
658 /***********************************************************************
659 * DeleteDC (GDI32.67)
661 BOOL WINAPI
DeleteDC( HDC hdc
)
663 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
664 if (!dc
) return FALSE
;
666 TRACE("%04x\n", hdc
);
668 /* Call hook procedure to check whether is it OK to delete this DC */
669 if ( dc
->hookThunk
&& !(dc
->w
.flags
& (DC_SAVED
| DC_MEMORY
))
670 && dc
->hookThunk( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ) == FALSE
)
672 GDI_HEAP_UNLOCK( hdc
);
676 while (dc
->saveLevel
)
679 HDC16 hdcs
= dc
->header
.hNext
;
680 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
681 dc
->header
.hNext
= dcs
->header
.hNext
;
686 if (!(dc
->w
.flags
& DC_SAVED
))
688 SelectObject( hdc
, STOCK_BLACK_PEN
);
689 SelectObject( hdc
, STOCK_WHITE_BRUSH
);
690 SelectObject( hdc
, STOCK_SYSTEM_FONT
);
691 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
694 if (dc
->w
.hClipRgn
) DeleteObject( dc
->w
.hClipRgn
);
695 if (dc
->w
.hVisRgn
) DeleteObject( dc
->w
.hVisRgn
);
696 if (dc
->w
.hGCClipRgn
) DeleteObject( dc
->w
.hGCClipRgn
);
697 if (dc
->w
.pAbortProc
) THUNK_Free( (FARPROC
)dc
->w
.pAbortProc
);
698 if (dc
->hookThunk
) THUNK_Free( (FARPROC
)dc
->hookThunk
);
699 PATH_DestroyGdiPath(&dc
->w
.path
);
701 return GDI_FreeObject( hdc
);
705 /***********************************************************************
706 * ResetDC16 (GDI.376)
708 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODEA
*devmode
)
715 /***********************************************************************
716 * ResetDCA (GDI32.287)
718 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
725 /***********************************************************************
726 * ResetDCW (GDI32.288)
728 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
735 /***********************************************************************
736 * GetDeviceCaps16 (GDI.80)
738 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
740 return GetDeviceCaps( hdc
, cap
);
744 /***********************************************************************
745 * GetDeviceCaps (GDI32.171)
747 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
749 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
755 /* Device capabilities for the printer */
759 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
762 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
764 case PHYSICALOFFSETX
:
765 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
767 case PHYSICALOFFSETY
:
768 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
771 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
774 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
778 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
)))
780 GDI_HEAP_UNLOCK( hdc
);
784 if (((cap
>=46) && (cap
<88)) || ((cap
>=92) && (cap
<104)))
785 FIXME("(%04x,%d): unsupported DeviceCaps capability, will yield 0!\n",
788 TRACE("(%04x,%d): returning %d\n",
789 hdc
, cap
, *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
) );
790 ret
= *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
);
791 GDI_HEAP_UNLOCK( hdc
);
796 /***********************************************************************
797 * SetBkColor16 (GDI.1)
799 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
801 return SetBkColor( hdc
, color
);
805 /***********************************************************************
806 * SetBkColor (GDI32.305)
808 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
811 DC
* dc
= DC_GetDCPtr( hdc
);
813 if (!dc
) return 0x80000000;
814 if (dc
->funcs
->pSetBkColor
)
815 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
817 oldColor
= dc
->w
.backgroundColor
;
818 dc
->w
.backgroundColor
= color
;
820 GDI_HEAP_UNLOCK( hdc
);
825 /***********************************************************************
826 * SetTextColor16 (GDI.9)
828 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
830 return SetTextColor( hdc
, color
);
834 /***********************************************************************
835 * SetTextColor (GDI32.338)
837 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
840 DC
* dc
= DC_GetDCPtr( hdc
);
842 if (!dc
) return 0x80000000;
843 if (dc
->funcs
->pSetTextColor
)
844 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
846 oldColor
= dc
->w
.textColor
;
847 dc
->w
.textColor
= color
;
849 GDI_HEAP_UNLOCK( hdc
);
853 /***********************************************************************
854 * SetTextAlign16 (GDI.346)
856 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 align
)
858 return SetTextAlign( hdc
, align
);
862 /***********************************************************************
863 * SetTextAlign (GDI32.336)
865 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
868 DC
*dc
= DC_GetDCPtr( hdc
);
870 if (dc
->funcs
->pSetTextAlign
)
871 prevAlign
= dc
->funcs
->pSetTextAlign(dc
, align
);
873 prevAlign
= dc
->w
.textAlign
;
874 dc
->w
.textAlign
= align
;
876 GDI_HEAP_UNLOCK( hdc
);
880 /***********************************************************************
881 * GetDCOrgEx (GDI32.168)
883 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
887 if (!lpp
) return FALSE
;
888 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return FALSE
;
891 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
, lpp
);
892 lpp
->x
+= dc
->w
.DCOrgX
;
893 lpp
->y
+= dc
->w
.DCOrgY
;
894 GDI_HEAP_UNLOCK( hDC
);
899 /***********************************************************************
902 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
905 if( GetDCOrgEx( hdc
, &pt
) )
906 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
911 /***********************************************************************
914 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
917 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
919 prevOrg
= dc
->w
.DCOrgX
| (dc
->w
.DCOrgY
<< 16);
922 GDI_HEAP_UNLOCK( hdc
);
927 /***********************************************************************
928 * GetGraphicsMode (GDI32.188)
930 INT WINAPI
GetGraphicsMode( HDC hdc
)
932 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
934 return dc
->w
.GraphicsMode
;
938 /***********************************************************************
939 * SetGraphicsMode (GDI32.317)
941 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
944 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
946 /* One would think that setting the graphics mode to GM_COMPATIBLE
947 * would also reset the world transformation matrix to the unity
948 * matrix. However, in Windows, this is not the case. This doesn't
949 * make a lot of sense to me, but that's the way it is.
953 if ((mode
<= 0) || (mode
> GM_LAST
)) return 0;
954 ret
= dc
->w
.GraphicsMode
;
955 dc
->w
.GraphicsMode
= mode
;
960 /***********************************************************************
961 * GetArcDirection16 (GDI.524)
963 INT16 WINAPI
GetArcDirection16( HDC16 hdc
)
965 return GetArcDirection( (HDC
)hdc
);
969 /***********************************************************************
970 * GetArcDirection (GDI32.141)
972 INT WINAPI
GetArcDirection( HDC hdc
)
974 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
979 return dc
->w
.ArcDirection
;
983 /***********************************************************************
984 * SetArcDirection16 (GDI.525)
986 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
988 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
992 /***********************************************************************
993 * SetArcDirection (GDI32.302)
995 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
997 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1003 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1005 SetLastError(ERROR_INVALID_PARAMETER
);
1009 nOldDirection
= dc
->w
.ArcDirection
;
1010 dc
->w
.ArcDirection
= nDirection
;
1012 return nOldDirection
;
1016 /***********************************************************************
1017 * GetWorldTransform (GDI32.244)
1019 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1021 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1028 *xform
= dc
->w
.xformWorld2Wnd
;
1034 /***********************************************************************
1035 * SetWorldTransform (GDI32.346)
1037 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1039 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1043 SetLastError( ERROR_INVALID_HANDLE
);
1050 /* Check that graphics mode is GM_ADVANCED */
1051 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1054 dc
->w
.xformWorld2Wnd
= *xform
;
1056 DC_UpdateXforms( dc
);
1062 /****************************************************************************
1063 * ModifyWorldTransform [GDI32.253]
1064 * Modifies the world transformation for a device context.
1067 * hdc [I] Handle to device context
1068 * xform [I] XFORM structure that will be used to modify the world
1070 * iMode [I] Specifies in what way to modify the world transformation
1073 * Resets the world transformation to the identity matrix.
1074 * The parameter xform is ignored.
1076 * Multiplies xform into the world transformation matrix from
1079 * Multiplies xform into the world transformation matrix from
1084 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1087 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1089 /* Check for illegal parameters */
1092 SetLastError( ERROR_INVALID_HANDLE
);
1098 /* Check that graphics mode is GM_ADVANCED */
1099 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1105 dc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1106 dc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1107 dc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1108 dc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1109 dc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1110 dc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1112 case MWT_LEFTMULTIPLY
:
1113 CombineTransform( &dc
->w
.xformWorld2Wnd
, xform
,
1114 &dc
->w
.xformWorld2Wnd
);
1116 case MWT_RIGHTMULTIPLY
:
1117 CombineTransform( &dc
->w
.xformWorld2Wnd
, &dc
->w
.xformWorld2Wnd
,
1124 DC_UpdateXforms( dc
);
1130 /****************************************************************************
1131 * CombineTransform [GDI32.20]
1132 * Combines two transformation matrices.
1135 * xformResult [O] Stores the result of combining the two matrices
1136 * xform1 [I] Specifies the first matrix to apply
1137 * xform2 [I] Specifies the second matrix to apply
1140 * The same matrix can be passed in for more than one of the parameters.
1144 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1145 const XFORM
*xform2
)
1149 /* Check for illegal parameters */
1150 if (!xformResult
|| !xform1
|| !xform2
)
1153 /* Create the result in a temporary XFORM, since xformResult may be
1154 * equal to xform1 or xform2 */
1155 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1156 xform1
->eM12
* xform2
->eM21
;
1157 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1158 xform1
->eM12
* xform2
->eM22
;
1159 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1160 xform1
->eM22
* xform2
->eM21
;
1161 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1162 xform1
->eM22
* xform2
->eM22
;
1163 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1164 xform1
->eDy
* xform2
->eM21
+
1166 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1167 xform1
->eDy
* xform2
->eM22
+
1170 /* Copy the result to xformResult */
1171 *xformResult
= xformTemp
;
1177 /***********************************************************************
1178 * SetDCHook (GDI.190)
1180 /* ### start build ### */
1181 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
1182 /* ### stop build ### */
1183 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1185 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1186 if (!dc
) return FALSE
;
1189 * Note: We store the original SEGPTR 'hookProc' as we need to be
1190 * able to return it verbatim in GetDCHook,
1192 * On the other hand, we still call THUNK_Alloc and store the
1193 * 32-bit thunk into another DC member, because THUNK_Alloc
1194 * recognizes the (typical) case that the 'hookProc' is indeed
1195 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1197 * We could perform that test every time the hook is about to
1198 * be called (or else we could live with the 32->16->32 detour),
1199 * but this way is the most efficient ...
1202 dc
->hookProc
= hookProc
;
1203 dc
->dwHookData
= dwHookData
;
1205 THUNK_Free( (FARPROC
)dc
->hookThunk
);
1206 dc
->hookThunk
= (DCHOOKPROC
)
1207 THUNK_Alloc( hookProc
, (RELAY
)GDI_CallTo16_word_wwll
);
1209 GDI_HEAP_UNLOCK( hdc
);
1214 /***********************************************************************
1215 * GetDCHook (GDI.191)
1217 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1219 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1221 *phookProc
= dc
->hookProc
;
1222 GDI_HEAP_UNLOCK( hdc
);
1223 return dc
->dwHookData
;
1227 /***********************************************************************
1228 * SetHookFlags (GDI.192)
1230 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1232 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
1236 WORD wRet
= dc
->w
.flags
& DC_DIRTY
;
1238 /* "Undocumented Windows" info is slightly confusing.
1241 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1243 if( flags
& DCHF_INVALIDATEVISRGN
)
1244 dc
->w
.flags
|= DC_DIRTY
;
1245 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1246 dc
->w
.flags
&= ~DC_DIRTY
;
1247 GDI_HEAP_UNLOCK( hDC
);
1253 /***********************************************************************
1254 * SetICMMode (GDI32.318)
1256 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1258 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1259 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1260 if (iEnableICM
== ICM_ON
) return 0;
1261 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1266 /***********************************************************************
1267 * GetColorSpace (GDI32.165)
1269 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1271 /*FIXME Need to to whatever GetColorSpace actually does */
1275 /***********************************************************************
1276 * CreateColorSpaceA (GDI32.???)
1278 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1284 /***********************************************************************
1285 * CreateColorSpaceW (GDI32.???)
1287 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1293 /***********************************************************************
1294 * DeleteColorSpace (GDI32.???)
1296 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1303 /***********************************************************************
1304 * SetColorSpace (GDI32.???)
1306 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1313 /***********************************************************************
1314 * GetBoundsRect16 (GDI.194)
1316 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1318 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1321 /***********************************************************************
1322 * GetBoundsRect (GDI32.147)
1324 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1326 FIXME("(): stub\n");
1327 return DCB_RESET
; /* bounding rectangle always empty */
1330 /***********************************************************************
1331 * SetBoundsRect16 (GDI.193)
1333 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1335 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1336 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1338 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1341 /***********************************************************************
1342 * SetBoundsRect (GDI32.307)
1344 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1346 FIXME("(): stub\n");
1347 return DCB_DISABLE
; /* bounding rectangle always empty */
1350 /***********************************************************************
1353 * Disables GDI, switches back to text mode.
1354 * We don't have to do anything here,
1355 * just let console support handle everything
1357 void WINAPI
Death16(HDC16 hDC
)
1359 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1362 /***********************************************************************
1363 * Resurrection (GDI.122)
1365 * Restores GDI functionality
1367 void WINAPI
Resurrection16(HDC16 hDC
,
1368 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1370 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1373 /***********************************************************************
1374 * GetLayout (GDI32.321)
1376 * Gets left->right or right->left text layout flags of a dc.
1377 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1380 DWORD WINAPI
GetLayout(HDC hdc
)
1382 FIXME("(%08x): stub\n", hdc
);
1383 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1387 /***********************************************************************
1388 * SetLayout (GDI32.450)
1390 * Sets left->right or right->left text layout flags of a dc.
1391 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1394 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1396 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1397 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);