2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
10 #ifndef X_DISPLAY_MISSING
13 #endif /* !defined(X_DISPLAY_MISSING) */
20 #include "debugtools.h"
24 #include "wine/winuser16.h"
26 DEFAULT_DEBUG_CHANNEL(dc
)
28 /***********************************************************************
31 * Fill the WIN_DC_INFO structure.
33 static void DC_Init_DC_INFO( WIN_DC_INFO
*win_dc_info
)
35 win_dc_info
->flags
= 0;
36 win_dc_info
->devCaps
= NULL
;
37 win_dc_info
->hClipRgn
= 0;
38 win_dc_info
->hVisRgn
= 0;
39 win_dc_info
->hGCClipRgn
= 0;
40 win_dc_info
->hPen
= STOCK_BLACK_PEN
;
41 win_dc_info
->hBrush
= STOCK_WHITE_BRUSH
;
42 win_dc_info
->hFont
= STOCK_SYSTEM_FONT
;
43 win_dc_info
->hBitmap
= 0;
44 win_dc_info
->hDevice
= 0;
45 win_dc_info
->hPalette
= STOCK_DEFAULT_PALETTE
;
46 win_dc_info
->ROPmode
= R2_COPYPEN
;
47 win_dc_info
->polyFillMode
= ALTERNATE
;
48 win_dc_info
->stretchBltMode
= BLACKONWHITE
;
49 win_dc_info
->relAbsMode
= ABSOLUTE
;
50 win_dc_info
->backgroundMode
= OPAQUE
;
51 win_dc_info
->backgroundColor
= RGB( 255, 255, 255 );
52 win_dc_info
->textColor
= RGB( 0, 0, 0 );
53 win_dc_info
->brushOrgX
= 0;
54 win_dc_info
->brushOrgY
= 0;
55 win_dc_info
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
56 win_dc_info
->charExtra
= 0;
57 win_dc_info
->breakTotalExtra
= 0;
58 win_dc_info
->breakCount
= 0;
59 win_dc_info
->breakExtra
= 0;
60 win_dc_info
->breakRem
= 0;
61 win_dc_info
->bitsPerPixel
= 1;
62 win_dc_info
->MapMode
= MM_TEXT
;
63 win_dc_info
->GraphicsMode
= GM_COMPATIBLE
;
64 win_dc_info
->DCOrgX
= 0;
65 win_dc_info
->DCOrgY
= 0;
66 win_dc_info
->pAbortProc
= NULL
;
67 win_dc_info
->CursPosX
= 0;
68 win_dc_info
->CursPosY
= 0;
69 win_dc_info
->ArcDirection
= AD_COUNTERCLOCKWISE
;
70 win_dc_info
->xformWorld2Wnd
.eM11
= 1.0f
;
71 win_dc_info
->xformWorld2Wnd
.eM12
= 0.0f
;
72 win_dc_info
->xformWorld2Wnd
.eM21
= 0.0f
;
73 win_dc_info
->xformWorld2Wnd
.eM22
= 1.0f
;
74 win_dc_info
->xformWorld2Wnd
.eDx
= 0.0f
;
75 win_dc_info
->xformWorld2Wnd
.eDy
= 0.0f
;
76 win_dc_info
->xformWorld2Vport
= win_dc_info
->xformWorld2Wnd
;
77 win_dc_info
->xformVport2World
= win_dc_info
->xformWorld2Wnd
;
78 win_dc_info
->vport2WorldValid
= TRUE
;
80 PATH_InitGdiPath(&win_dc_info
->path
);
84 /***********************************************************************
87 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
92 if (!(hdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
))) return NULL
;
93 dc
= (DC
*) GDI_HEAP_LOCK( hdc
);
101 dc
->hookThunk
= NULL
;
111 DC_Init_DC_INFO( &dc
->w
);
118 /***********************************************************************
121 DC
*DC_GetDCPtr( HDC hdc
)
123 GDIOBJHDR
*ptr
= (GDIOBJHDR
*)GDI_HEAP_LOCK( hdc
);
124 if (!ptr
) return NULL
;
125 if ((ptr
->wMagic
== DC_MAGIC
) || (ptr
->wMagic
== METAFILE_DC_MAGIC
) ||
126 (ptr
->wMagic
== ENHMETAFILE_DC_MAGIC
))
128 GDI_HEAP_UNLOCK( hdc
);
133 /***********************************************************************
136 * Setup device-specific DC values for a newly created DC.
138 void DC_InitDC( DC
* dc
)
140 RealizeDefaultPalette16( dc
->hSelf
);
141 SetTextColor( dc
->hSelf
, dc
->w
.textColor
);
142 SetBkColor( dc
->hSelf
, dc
->w
.backgroundColor
);
143 SelectObject( dc
->hSelf
, dc
->w
.hPen
);
144 SelectObject( dc
->hSelf
, dc
->w
.hBrush
);
145 SelectObject( dc
->hSelf
, dc
->w
.hFont
);
146 CLIPPING_UpdateGCRegion( dc
);
150 /***********************************************************************
153 * Computes the inverse of the transformation xformSrc and stores it to
154 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
157 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
161 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
162 xformSrc
->eM12
*xformSrc
->eM21
;
163 if (determinant
> -1e-12 && determinant
< 1e-12)
166 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
167 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
168 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
169 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
170 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
171 xformSrc
->eDy
* xformDest
->eM21
;
172 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
173 xformSrc
->eDy
* xformDest
->eM22
;
179 /***********************************************************************
182 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
183 * fields of the specified DC by creating a transformation that
184 * represents the current mapping mode and combining it with the DC's
185 * world transform. This function should be called whenever the
186 * parameters associated with the mapping mode (window and viewport
187 * extents and origins) or the world transform change.
189 void DC_UpdateXforms( DC
*dc
)
191 XFORM xformWnd2Vport
;
192 FLOAT scaleX
, scaleY
;
194 /* Construct a transformation to do the window-to-viewport conversion */
195 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
196 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
197 xformWnd2Vport
.eM11
= scaleX
;
198 xformWnd2Vport
.eM12
= 0.0;
199 xformWnd2Vport
.eM21
= 0.0;
200 xformWnd2Vport
.eM22
= scaleY
;
201 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
202 scaleX
* (FLOAT
)dc
->wndOrgX
;
203 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
204 scaleY
* (FLOAT
)dc
->wndOrgY
;
206 /* Combine with the world transformation */
207 CombineTransform( &dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
,
210 /* Create inverse of world-to-viewport transformation */
211 dc
->w
.vport2WorldValid
= DC_InvertXform( &dc
->w
.xformWorld2Vport
,
212 &dc
->w
.xformVport2World
);
216 /***********************************************************************
217 * GetDCState (GDI.179)
219 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
224 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
225 if (!(handle
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
)))
227 GDI_HEAP_UNLOCK( hdc
);
230 newdc
= (DC
*) GDI_HEAP_LOCK( handle
);
232 TRACE("(%04x): returning %04x\n", hdc
, handle
);
234 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
235 newdc
->w
.devCaps
= dc
->w
.devCaps
;
236 newdc
->w
.hPen
= dc
->w
.hPen
;
237 newdc
->w
.hBrush
= dc
->w
.hBrush
;
238 newdc
->w
.hFont
= dc
->w
.hFont
;
239 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
240 newdc
->w
.hDevice
= dc
->w
.hDevice
;
241 newdc
->w
.hPalette
= dc
->w
.hPalette
;
242 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
243 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
244 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
245 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
246 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
247 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
248 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
249 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
250 newdc
->w
.textColor
= dc
->w
.textColor
;
251 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
252 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
253 newdc
->w
.textAlign
= dc
->w
.textAlign
;
254 newdc
->w
.charExtra
= dc
->w
.charExtra
;
255 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
256 newdc
->w
.breakCount
= dc
->w
.breakCount
;
257 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
258 newdc
->w
.breakRem
= dc
->w
.breakRem
;
259 newdc
->w
.MapMode
= dc
->w
.MapMode
;
260 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
262 /* Apparently, the DC origin is not changed by [GS]etDCState */
263 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
264 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
266 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
267 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
268 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
269 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
270 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
271 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
272 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
273 newdc
->wndOrgX
= dc
->wndOrgX
;
274 newdc
->wndOrgY
= dc
->wndOrgY
;
275 newdc
->wndExtX
= dc
->wndExtX
;
276 newdc
->wndExtY
= dc
->wndExtY
;
277 newdc
->vportOrgX
= dc
->vportOrgX
;
278 newdc
->vportOrgY
= dc
->vportOrgY
;
279 newdc
->vportExtX
= dc
->vportExtX
;
280 newdc
->vportExtY
= dc
->vportExtY
;
282 newdc
->hSelf
= (HDC
)handle
;
283 newdc
->saveLevel
= 0;
285 PATH_InitGdiPath( &newdc
->w
.path
);
287 newdc
->w
.pAbortProc
= NULL
;
289 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
291 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
294 newdc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
295 CombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
298 newdc
->w
.hClipRgn
= 0;
299 GDI_HEAP_UNLOCK( handle
);
300 GDI_HEAP_UNLOCK( hdc
);
305 /***********************************************************************
306 * SetDCState (GDI.180)
308 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
312 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
313 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
315 GDI_HEAP_UNLOCK( hdc
);
318 if (!dcs
->w
.flags
& DC_SAVED
)
320 GDI_HEAP_UNLOCK( hdc
);
321 GDI_HEAP_UNLOCK( hdcs
);
324 TRACE("%04x %04x\n", hdc
, hdcs
);
326 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
327 dc
->w
.devCaps
= dcs
->w
.devCaps
;
328 dc
->w
.hDevice
= dcs
->w
.hDevice
;
329 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
330 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
331 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
332 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
333 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
334 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
335 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
336 dc
->w
.textColor
= dcs
->w
.textColor
;
337 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
338 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
339 dc
->w
.textAlign
= dcs
->w
.textAlign
;
340 dc
->w
.charExtra
= dcs
->w
.charExtra
;
341 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
342 dc
->w
.breakCount
= dcs
->w
.breakCount
;
343 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
344 dc
->w
.breakRem
= dcs
->w
.breakRem
;
345 dc
->w
.MapMode
= dcs
->w
.MapMode
;
346 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
348 /* Apparently, the DC origin is not changed by [GS]etDCState */
349 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
350 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
352 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
353 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
354 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
355 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
356 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
357 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
358 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
360 dc
->wndOrgX
= dcs
->wndOrgX
;
361 dc
->wndOrgY
= dcs
->wndOrgY
;
362 dc
->wndExtX
= dcs
->wndExtX
;
363 dc
->wndExtY
= dcs
->wndExtY
;
364 dc
->vportOrgX
= dcs
->vportOrgX
;
365 dc
->vportOrgY
= dcs
->vportOrgY
;
366 dc
->vportExtX
= dcs
->vportExtX
;
367 dc
->vportExtY
= dcs
->vportExtY
;
369 if (!(dc
->w
.flags
& DC_MEMORY
)) dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
373 if (!dc
->w
.hClipRgn
) dc
->w
.hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
374 CombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
378 if (dc
->w
.hClipRgn
) DeleteObject16( dc
->w
.hClipRgn
);
381 CLIPPING_UpdateGCRegion( dc
);
383 SelectObject( hdc
, dcs
->w
.hBitmap
);
384 SelectObject( hdc
, dcs
->w
.hBrush
);
385 SelectObject( hdc
, dcs
->w
.hFont
);
386 SelectObject( hdc
, dcs
->w
.hPen
);
387 SetBkColor( hdc
, dcs
->w
.backgroundColor
);
388 SetTextColor( hdc
, dcs
->w
.textColor
);
389 GDISelectPalette16( hdc
, dcs
->w
.hPalette
, FALSE
);
390 GDI_HEAP_UNLOCK( hdc
);
391 GDI_HEAP_UNLOCK( hdcs
);
395 /***********************************************************************
398 INT16 WINAPI
SaveDC16( HDC16 hdc
)
400 return (INT16
)SaveDC( hdc
);
404 /***********************************************************************
405 * SaveDC32 (GDI32.292)
407 INT WINAPI
SaveDC( HDC hdc
)
413 dc
= DC_GetDCPtr( hdc
);
416 if(dc
->funcs
->pSaveDC
)
417 return dc
->funcs
->pSaveDC( dc
);
419 if (!(hdcs
= GetDCState16( hdc
)))
421 GDI_HEAP_UNLOCK( hdc
);
424 dcs
= (DC
*) GDI_HEAP_LOCK( hdcs
);
426 /* Copy path. The reason why path saving / restoring is in SaveDC/
427 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
428 * functions are only in Win16 (which doesn't have paths) and that
429 * SetDCState doesn't allow us to signal an error (which can happen
430 * when copying paths).
432 if (!PATH_AssignGdiPath( &dcs
->w
.path
, &dc
->w
.path
))
434 GDI_HEAP_UNLOCK( hdc
);
435 GDI_HEAP_UNLOCK( hdcs
);
440 dcs
->header
.hNext
= dc
->header
.hNext
;
441 dc
->header
.hNext
= hdcs
;
442 TRACE("(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
443 ret
= ++dc
->saveLevel
;
444 GDI_HEAP_UNLOCK( hdcs
);
445 GDI_HEAP_UNLOCK( hdc
);
450 /***********************************************************************
451 * RestoreDC16 (GDI.39)
453 BOOL16 WINAPI
RestoreDC16( HDC16 hdc
, INT16 level
)
455 return RestoreDC( hdc
, level
);
459 /***********************************************************************
460 * RestoreDC32 (GDI32.290)
462 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
467 TRACE("%04x %d\n", hdc
, level
);
468 dc
= DC_GetDCPtr( hdc
);
469 if(!dc
) return FALSE
;
470 if(dc
->funcs
->pRestoreDC
)
471 return dc
->funcs
->pRestoreDC( dc
, level
);
473 if (level
== -1) level
= dc
->saveLevel
;
474 if ((level
< 1) || (level
> dc
->saveLevel
))
476 GDI_HEAP_UNLOCK( hdc
);
481 while (dc
->saveLevel
>= level
)
483 HDC16 hdcs
= dc
->header
.hNext
;
484 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
)))
486 GDI_HEAP_UNLOCK( hdc
);
489 dc
->header
.hNext
= dcs
->header
.hNext
;
490 if (--dc
->saveLevel
< level
)
492 SetDCState16( hdc
, hdcs
);
493 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
494 /* FIXME: This might not be quite right, since we're
495 * returning FALSE but still destroying the saved DC state */
500 GDI_HEAP_UNLOCK( hdc
);
505 /***********************************************************************
506 * CreateDC16 (GDI.53)
508 HDC16 WINAPI
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
509 const DEVMODEA
*initData
)
512 const DC_FUNCTIONS
*funcs
;
516 if(!DRIVER_GetDriverName( device
, buf
, sizeof(buf
) )) return 0;
520 if (!(funcs
= DRIVER_FindDriver( buf
))) return 0;
521 if (!(dc
= DC_AllocDC( funcs
))) return 0;
524 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
525 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
527 if (dc
->funcs
->pCreateDC
&&
528 !dc
->funcs
->pCreateDC( dc
, buf
, device
, output
, initData
))
530 WARN("creation aborted by device\n" );
531 GDI_HEAP_FREE( dc
->hSelf
);
536 GDI_HEAP_UNLOCK( dc
->hSelf
);
541 /***********************************************************************
542 * CreateDC32A (GDI32.)
544 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
545 const DEVMODEA
*initData
)
547 return CreateDC16( driver
, device
, output
, (const DEVMODEA
*)initData
);
551 /***********************************************************************
552 * CreateDC32W (GDI32.)
554 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
555 const DEVMODEW
*initData
)
557 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
558 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
559 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
560 HDC res
= CreateDC16( driverA
, deviceA
, outputA
,
561 (const DEVMODEA
*)initData
/*FIXME*/ );
562 HeapFree( GetProcessHeap(), 0, driverA
);
563 HeapFree( GetProcessHeap(), 0, deviceA
);
564 HeapFree( GetProcessHeap(), 0, outputA
);
569 /***********************************************************************
570 * CreateIC16 (GDI.153)
572 HDC16 WINAPI
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
573 const DEVMODEA
* initData
)
575 /* Nothing special yet for ICs */
576 return CreateDC16( driver
, device
, output
, initData
);
580 /***********************************************************************
581 * CreateIC32A (GDI32.49)
583 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
584 const DEVMODEA
* initData
)
586 /* Nothing special yet for ICs */
587 return CreateDCA( driver
, device
, output
, initData
);
591 /***********************************************************************
592 * CreateIC32W (GDI32.50)
594 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
595 const DEVMODEW
* initData
)
597 /* Nothing special yet for ICs */
598 return CreateDCW( driver
, device
, output
, initData
);
602 /***********************************************************************
603 * CreateCompatibleDC16 (GDI.52)
605 HDC16 WINAPI
CreateCompatibleDC16( HDC16 hdc
)
607 return (HDC16
)CreateCompatibleDC( hdc
);
611 /***********************************************************************
612 * CreateCompatibleDC32 (GDI32.31)
614 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
617 const DC_FUNCTIONS
*funcs
;
619 if ((origDC
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
))) funcs
= origDC
->funcs
;
620 else funcs
= DRIVER_FindDriver( "DISPLAY" );
621 if (!funcs
) return 0;
623 if (!(dc
= DC_AllocDC( funcs
))) return 0;
625 TRACE("(%04x): returning %04x\n",
628 dc
->w
.flags
= DC_MEMORY
;
629 dc
->w
.bitsPerPixel
= 1;
630 dc
->w
.hBitmap
= hPseudoStockBitmap
;
632 /* Copy the driver-specific physical device info into
633 * the new DC. The driver may use this read-only info
634 * while creating the compatible DC below. */
636 dc
->physDev
= origDC
->physDev
;
638 if (dc
->funcs
->pCreateDC
&&
639 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
641 WARN("creation aborted by device\n");
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 DeleteDC( hdc
);
661 /***********************************************************************
662 * DeleteDC32 (GDI32.67)
664 BOOL WINAPI
DeleteDC( HDC hdc
)
666 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
667 if (!dc
) return FALSE
;
669 TRACE("%04x\n", hdc
);
671 /* Call hook procedure to check whether is it OK to delete this DC */
672 if ( dc
->hookThunk
&& !(dc
->w
.flags
& (DC_SAVED
| DC_MEMORY
))
673 && dc
->hookThunk( hdc
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ) == FALSE
)
675 GDI_HEAP_UNLOCK( hdc
);
679 while (dc
->saveLevel
)
682 HDC16 hdcs
= dc
->header
.hNext
;
683 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
684 dc
->header
.hNext
= dcs
->header
.hNext
;
689 if (!(dc
->w
.flags
& DC_SAVED
))
691 SelectObject( hdc
, STOCK_BLACK_PEN
);
692 SelectObject( hdc
, STOCK_WHITE_BRUSH
);
693 SelectObject( hdc
, STOCK_SYSTEM_FONT
);
694 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
697 if (dc
->w
.hClipRgn
) DeleteObject( dc
->w
.hClipRgn
);
698 if (dc
->w
.hVisRgn
) DeleteObject( dc
->w
.hVisRgn
);
699 if (dc
->w
.hGCClipRgn
) DeleteObject( dc
->w
.hGCClipRgn
);
700 if (dc
->w
.pAbortProc
) THUNK_Free( (FARPROC
)dc
->w
.pAbortProc
);
701 if (dc
->hookThunk
) THUNK_Free( (FARPROC
)dc
->hookThunk
);
702 PATH_DestroyGdiPath(&dc
->w
.path
);
704 return GDI_FreeObject( hdc
);
708 /***********************************************************************
709 * ResetDC16 (GDI.376)
711 HDC16 WINAPI
ResetDC16( HDC16 hdc
, const DEVMODEA
*devmode
)
718 /***********************************************************************
719 * ResetDC32A (GDI32.287)
721 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
728 /***********************************************************************
729 * ResetDC32W (GDI32.288)
731 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
738 /***********************************************************************
739 * GetDeviceCaps16 (GDI.80)
741 INT16 WINAPI
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
743 return GetDeviceCaps( hdc
, cap
);
747 /***********************************************************************
748 * GetDeviceCaps32 (GDI32.171)
750 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
752 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
758 /* Device capabilities for the printer */
762 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
765 if(Escape(hdc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
767 case PHYSICALOFFSETX
:
768 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
770 case PHYSICALOFFSETY
:
771 if(Escape(hdc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
774 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
777 if(Escape(hdc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
781 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
)))
783 GDI_HEAP_UNLOCK( hdc
);
787 TRACE("(%04x,%d): returning %d\n",
788 hdc
, cap
, *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
) );
789 ret
= *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
);
790 GDI_HEAP_UNLOCK( hdc
);
795 /***********************************************************************
796 * SetBkColor16 (GDI.1)
798 COLORREF WINAPI
SetBkColor16( HDC16 hdc
, COLORREF color
)
800 return SetBkColor( hdc
, color
);
804 /***********************************************************************
805 * SetBkColor32 (GDI32.305)
807 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
810 DC
* dc
= DC_GetDCPtr( hdc
);
812 if (!dc
) return 0x80000000;
813 if (dc
->funcs
->pSetBkColor
)
814 oldColor
= dc
->funcs
->pSetBkColor(dc
, color
);
816 oldColor
= dc
->w
.backgroundColor
;
817 dc
->w
.backgroundColor
= color
;
819 GDI_HEAP_UNLOCK( hdc
);
824 /***********************************************************************
825 * SetTextColor16 (GDI.9)
827 COLORREF WINAPI
SetTextColor16( HDC16 hdc
, COLORREF color
)
829 return SetTextColor( hdc
, color
);
833 /***********************************************************************
834 * SetTextColor32 (GDI32.338)
836 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
839 DC
* dc
= DC_GetDCPtr( hdc
);
841 if (!dc
) return 0x80000000;
842 if (dc
->funcs
->pSetTextColor
)
843 oldColor
= dc
->funcs
->pSetTextColor(dc
, color
);
845 oldColor
= dc
->w
.textColor
;
846 dc
->w
.textColor
= color
;
848 GDI_HEAP_UNLOCK( hdc
);
852 /***********************************************************************
853 * SetTextAlign16 (GDI.346)
855 UINT16 WINAPI
SetTextAlign16( HDC16 hdc
, UINT16 align
)
857 return SetTextAlign( hdc
, align
);
861 /***********************************************************************
862 * SetTextAlign (GDI32.336)
864 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
867 DC
*dc
= DC_GetDCPtr( hdc
);
869 if (dc
->funcs
->pSetTextAlign
)
870 prevAlign
= dc
->funcs
->pSetTextAlign(dc
, align
);
872 prevAlign
= dc
->w
.textAlign
;
873 dc
->w
.textAlign
= align
;
875 GDI_HEAP_UNLOCK( hdc
);
879 /***********************************************************************
880 * GetDCOrgEx (GDI32.168)
882 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
886 if (!lpp
) return FALSE
;
887 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return FALSE
;
889 #ifndef X_DISPLAY_MISSING
890 if (!(dc
->w
.flags
& DC_MEMORY
))
892 X11DRV_PDEVICE
*physDev
;
894 int w
, h
, border
, depth
;
896 physDev
= (X11DRV_PDEVICE
*) dc
->physDev
;
898 /* FIXME: this is not correct for managed windows */
899 TSXGetGeometry( display
, physDev
->drawable
, &root
,
900 (int*)&lpp
->x
, (int*)&lpp
->y
, &w
, &h
, &border
, &depth
);
903 #endif /* !defined(X_DISPLAY_MISSING) */
906 lpp
->x
+= dc
->w
.DCOrgX
; lpp
->y
+= dc
->w
.DCOrgY
;
907 GDI_HEAP_UNLOCK( hDC
);
912 /***********************************************************************
915 DWORD WINAPI
GetDCOrg16( HDC16 hdc
)
918 if( GetDCOrgEx( hdc
, &pt
) )
919 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
924 /***********************************************************************
927 DWORD WINAPI
SetDCOrg16( HDC16 hdc
, INT16 x
, INT16 y
)
930 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
932 prevOrg
= dc
->w
.DCOrgX
| (dc
->w
.DCOrgY
<< 16);
935 GDI_HEAP_UNLOCK( hdc
);
940 /***********************************************************************
941 * GetGraphicsMode (GDI32.188)
943 INT WINAPI
GetGraphicsMode( HDC hdc
)
945 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
947 return dc
->w
.GraphicsMode
;
951 /***********************************************************************
952 * SetGraphicsMode (GDI32.317)
954 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
957 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
959 /* One would think that setting the graphics mode to GM_COMPATIBLE
960 * would also reset the world transformation matrix to the unity
961 * matrix. However, in Windows, this is not the case. This doesn't
962 * make a lot of sense to me, but that's the way it is.
966 if ((mode
<= 0) || (mode
> GM_LAST
)) return 0;
967 ret
= dc
->w
.GraphicsMode
;
968 dc
->w
.GraphicsMode
= mode
;
973 /***********************************************************************
974 * GetArcDirection16 (GDI.524)
976 INT16 WINAPI
GetArcDirection16( HDC16 hdc
)
978 return GetArcDirection( (HDC
)hdc
);
982 /***********************************************************************
983 * GetArcDirection32 (GDI32.141)
985 INT WINAPI
GetArcDirection( HDC hdc
)
987 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
992 return dc
->w
.ArcDirection
;
996 /***********************************************************************
997 * SetArcDirection16 (GDI.525)
999 INT16 WINAPI
SetArcDirection16( HDC16 hdc
, INT16 nDirection
)
1001 return SetArcDirection( (HDC
)hdc
, (INT
)nDirection
);
1005 /***********************************************************************
1006 * SetArcDirection32 (GDI32.302)
1008 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1010 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1016 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1018 SetLastError(ERROR_INVALID_PARAMETER
);
1022 nOldDirection
= dc
->w
.ArcDirection
;
1023 dc
->w
.ArcDirection
= nDirection
;
1025 return nOldDirection
;
1029 /***********************************************************************
1030 * GetWorldTransform (GDI32.244)
1032 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1034 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1041 *xform
= dc
->w
.xformWorld2Wnd
;
1047 /***********************************************************************
1048 * SetWorldTransform (GDI32.346)
1050 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1052 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1056 SetLastError( ERROR_INVALID_HANDLE
);
1063 /* Check that graphics mode is GM_ADVANCED */
1064 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1067 dc
->w
.xformWorld2Wnd
= *xform
;
1069 DC_UpdateXforms( dc
);
1075 /****************************************************************************
1076 * ModifyWorldTransform [GDI32.253]
1077 * Modifies the world transformation for a device context.
1080 * hdc [I] Handle to device context
1081 * xform [I] XFORM structure that will be used to modify the world
1083 * iMode [I] Specifies in what way to modify the world transformation
1086 * Resets the world transformation to the identity matrix.
1087 * The parameter xform is ignored.
1089 * Multiplies xform into the world transformation matrix from
1092 * Multiplies xform into the world transformation matrix from
1097 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1100 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
1102 /* Check for illegal parameters */
1105 SetLastError( ERROR_INVALID_HANDLE
);
1111 /* Check that graphics mode is GM_ADVANCED */
1112 if (dc
->w
.GraphicsMode
!=GM_ADVANCED
)
1118 dc
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1119 dc
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1120 dc
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1121 dc
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1122 dc
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1123 dc
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1125 case MWT_LEFTMULTIPLY
:
1126 CombineTransform( &dc
->w
.xformWorld2Wnd
, xform
,
1127 &dc
->w
.xformWorld2Wnd
);
1129 case MWT_RIGHTMULTIPLY
:
1130 CombineTransform( &dc
->w
.xformWorld2Wnd
, &dc
->w
.xformWorld2Wnd
,
1137 DC_UpdateXforms( dc
);
1143 /****************************************************************************
1144 * CombineTransform [GDI32.20]
1145 * Combines two transformation matrices.
1148 * xformResult [O] Stores the result of combining the two matrices
1149 * xform1 [I] Specifies the first matrix to apply
1150 * xform2 [I] Specifies the second matrix to apply
1153 * The same matrix can be passed in for more than one of the parameters.
1157 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1158 const XFORM
*xform2
)
1162 /* Check for illegal parameters */
1163 if (!xformResult
|| !xform1
|| !xform2
)
1166 /* Create the result in a temporary XFORM, since xformResult may be
1167 * equal to xform1 or xform2 */
1168 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1169 xform1
->eM12
* xform2
->eM21
;
1170 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1171 xform1
->eM12
* xform2
->eM22
;
1172 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1173 xform1
->eM22
* xform2
->eM21
;
1174 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1175 xform1
->eM22
* xform2
->eM22
;
1176 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1177 xform1
->eDy
* xform2
->eM21
+
1179 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1180 xform1
->eDy
* xform2
->eM22
+
1183 /* Copy the result to xformResult */
1184 *xformResult
= xformTemp
;
1190 /***********************************************************************
1191 * SetDCHook (GDI.190)
1193 /* ### start build ### */
1194 extern WORD CALLBACK
GDI_CallTo16_word_wwll(FARPROC16
,WORD
,WORD
,LONG
,LONG
);
1195 /* ### stop build ### */
1196 BOOL16 WINAPI
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
1198 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1199 if (!dc
) return FALSE
;
1202 * Note: We store the original SEGPTR 'hookProc' as we need to be
1203 * able to return it verbatim in GetDCHook,
1205 * On the other hand, we still call THUNK_Alloc and store the
1206 * 32-bit thunk into another DC member, because THUNK_Alloc
1207 * recognizes the (typical) case that the 'hookProc' is indeed
1208 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1210 * We could perform that test every time the hook is about to
1211 * be called (or else we could live with the 32->16->32 detour),
1212 * but this way is the most efficient ...
1215 dc
->hookProc
= hookProc
;
1216 dc
->dwHookData
= dwHookData
;
1218 THUNK_Free( (FARPROC
)dc
->hookThunk
);
1219 dc
->hookThunk
= (DCHOOKPROC
)
1220 THUNK_Alloc( hookProc
, (RELAY
)GDI_CallTo16_word_wwll
);
1222 GDI_HEAP_UNLOCK( hdc
);
1227 /***********************************************************************
1228 * GetDCHook (GDI.191)
1230 DWORD WINAPI
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
1232 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
1234 *phookProc
= dc
->hookProc
;
1235 GDI_HEAP_UNLOCK( hdc
);
1236 return dc
->dwHookData
;
1240 /***********************************************************************
1241 * SetHookFlags (GDI.192)
1243 WORD WINAPI
SetHookFlags16(HDC16 hDC
, WORD flags
)
1245 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
1249 WORD wRet
= dc
->w
.flags
& DC_DIRTY
;
1251 /* "Undocumented Windows" info is slightly confusing.
1254 TRACE("hDC %04x, flags %04x\n",hDC
,flags
);
1256 if( flags
& DCHF_INVALIDATEVISRGN
)
1257 dc
->w
.flags
|= DC_DIRTY
;
1258 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1259 dc
->w
.flags
&= ~DC_DIRTY
;
1260 GDI_HEAP_UNLOCK( hDC
);
1266 /***********************************************************************
1267 * SetICMMode (GDI32.318)
1269 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1271 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1272 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1273 if (iEnableICM
== ICM_ON
) return 0;
1274 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1279 /***********************************************************************
1280 * GetColorSpace (GDI32.165)
1282 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1284 /*FIXME Need to to whatever GetColorSpace actually does */
1288 /***********************************************************************
1289 * CreateColorSpaceA (GDI32.???)
1291 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1297 /***********************************************************************
1298 * CreateColorSpaceW (GDI32.???)
1300 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1306 /***********************************************************************
1307 * DeleteColorSpace (GDI32.???)
1309 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1316 /***********************************************************************
1317 * SetColorSpace (GDI32.???)
1319 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1326 /***********************************************************************
1327 * GetBoundsRect16 (GDI.194)
1329 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1331 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1334 /***********************************************************************
1335 * GetBoundsRect32 (GDI32.147)
1337 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1339 FIXME("(): stub\n");
1340 return DCB_RESET
; /* bounding rectangle always empty */
1343 /***********************************************************************
1344 * SetBoundsRect16 (GDI.193)
1346 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1348 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1349 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1351 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1354 /***********************************************************************
1355 * SetBoundsRect32 (GDI32.307)
1357 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1359 FIXME("(): stub\n");
1360 return DCB_DISABLE
; /* bounding rectangle always empty */
1363 /***********************************************************************
1366 * Disables GDI, switches back to text mode.
1367 * We don't have to do anything here,
1368 * just let console support handle everything
1370 void WINAPI
Death16(HDC16 hDC
)
1372 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC
);
1375 /***********************************************************************
1376 * Resurrection (GDI.122)
1378 * Restores GDI functionality
1380 void WINAPI
Resurrection16(HDC16 hDC
,
1381 WORD w1
, WORD w2
, WORD w3
, WORD w4
, WORD w5
, WORD w6
)
1383 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC
, w1
, w2
, w3
, w4
, w5
, w6
);
1386 /***********************************************************************
1387 * GetLayout (GDI32.321)
1389 * Gets left->right or right->left text layout flags of a dc.
1390 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1393 DWORD WINAPI
GetLayout(HDC hdc
)
1395 FIXME("(%08x): stub\n", hdc
);
1396 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1400 /***********************************************************************
1401 * SetLayout (GDI32.450)
1403 * Sets left->right or right->left text layout flags of a dc.
1404 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1407 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1409 FIXME("(%08x,%08lx): stub\n", hdc
, layout
);
1410 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);