2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/winuser16.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
36 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
);
38 static const struct gdi_obj_funcs dc_funcs
=
40 NULL
, /* pSelectObject */
41 NULL
, /* pGetObject16 */
42 NULL
, /* pGetObjectA */
43 NULL
, /* pGetObjectW */
44 NULL
, /* pUnrealizeObject */
45 DC_DeleteObject
/* pDeleteObject */
48 /***********************************************************************
51 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
, WORD magic
)
56 if (!(dc
= GDI_AllocObject( sizeof(*dc
), magic
, (HGDIOBJ
*)&hdc
, &dc_funcs
))) return NULL
;
77 dc
->hPen
= GetStockObject( BLACK_PEN
);
78 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
79 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
82 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
84 dc
->ROPmode
= R2_COPYPEN
;
85 dc
->polyFillMode
= ALTERNATE
;
86 dc
->stretchBltMode
= BLACKONWHITE
;
87 dc
->relAbsMode
= ABSOLUTE
;
88 dc
->backgroundMode
= OPAQUE
;
89 dc
->backgroundColor
= RGB( 255, 255, 255 );
90 dc
->textColor
= RGB( 0, 0, 0 );
93 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
95 dc
->breakTotalExtra
= 0;
99 dc
->totalExtent
.left
= 0;
100 dc
->totalExtent
.top
= 0;
101 dc
->totalExtent
.right
= 0;
102 dc
->totalExtent
.bottom
= 0;
103 dc
->bitsPerPixel
= 1;
104 dc
->MapMode
= MM_TEXT
;
105 dc
->GraphicsMode
= GM_COMPATIBLE
;
106 dc
->pAbortProc
= NULL
;
109 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
110 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
111 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
112 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
113 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
114 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
115 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
116 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
117 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
118 dc
->vport2WorldValid
= TRUE
;
119 PATH_InitGdiPath(&dc
->path
);
125 /***********************************************************************
128 DC
*DC_GetDCPtr( HDC hdc
)
130 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
131 if (!ptr
) return NULL
;
132 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
133 (GDIMAGIC(ptr
->wMagic
) == MEMORY_DC_MAGIC
) ||
134 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
135 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
137 GDI_ReleaseObj( hdc
);
138 SetLastError( ERROR_INVALID_HANDLE
);
142 /***********************************************************************
145 * Retrieve a DC ptr while making sure the visRgn is updated.
146 * This function may call up to USER so the GDI lock should _not_
147 * be held when calling it.
149 DC
*DC_GetDCUpdate( HDC hdc
)
151 DC
*dc
= DC_GetDCPtr( hdc
);
152 if (!dc
) return NULL
;
153 while (dc
->flags
& DC_DIRTY
)
155 DCHOOKPROC proc
= dc
->hookThunk
;
156 dc
->flags
&= ~DC_DIRTY
;
159 DWORD data
= dc
->dwHookData
;
160 GDI_ReleaseObj( hdc
);
161 proc( HDC_16(hdc
), DCHC_INVALIDVISRGN
, data
, 0 );
162 if (!(dc
= DC_GetDCPtr( hdc
))) break;
163 /* otherwise restart the loop in case it became dirty again in the meantime */
170 /***********************************************************************
173 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
175 GDI_ReleaseObj( handle
);
176 return DeleteDC( handle
);
180 /***********************************************************************
183 * Setup device-specific DC values for a newly created DC.
185 void DC_InitDC( DC
* dc
)
187 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
188 SetTextColor( dc
->hSelf
, dc
->textColor
);
189 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
190 SelectObject( dc
->hSelf
, dc
->hPen
);
191 SelectObject( dc
->hSelf
, dc
->hBrush
);
192 SelectObject( dc
->hSelf
, dc
->hFont
);
193 CLIPPING_UpdateGCRegion( dc
);
197 /***********************************************************************
200 * Computes the inverse of the transformation xformSrc and stores it to
201 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
204 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
208 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
209 xformSrc
->eM12
*xformSrc
->eM21
;
210 if (determinant
> -1e-12 && determinant
< 1e-12)
213 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
214 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
215 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
216 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
217 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
218 xformSrc
->eDy
* xformDest
->eM21
;
219 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
220 xformSrc
->eDy
* xformDest
->eM22
;
226 /***********************************************************************
229 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
230 * fields of the specified DC by creating a transformation that
231 * represents the current mapping mode and combining it with the DC's
232 * world transform. This function should be called whenever the
233 * parameters associated with the mapping mode (window and viewport
234 * extents and origins) or the world transform change.
236 void DC_UpdateXforms( DC
*dc
)
238 XFORM xformWnd2Vport
;
239 FLOAT scaleX
, scaleY
;
241 /* Construct a transformation to do the window-to-viewport conversion */
242 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
243 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
244 xformWnd2Vport
.eM11
= scaleX
;
245 xformWnd2Vport
.eM12
= 0.0;
246 xformWnd2Vport
.eM21
= 0.0;
247 xformWnd2Vport
.eM22
= scaleY
;
248 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
249 scaleX
* (FLOAT
)dc
->wndOrgX
;
250 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
251 scaleY
* (FLOAT
)dc
->wndOrgY
;
253 /* Combine with the world transformation */
254 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
257 /* Create inverse of world-to-viewport transformation */
258 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
259 &dc
->xformVport2World
);
261 /* Reselect the font back into the dc so that the font size
263 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
267 /***********************************************************************
268 * GetDCState (Not a Windows API)
270 HDC WINAPI
GetDCState( HDC hdc
)
275 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
276 if (!(newdc
= GDI_AllocObject( sizeof(DC
), GDIMAGIC(dc
->header
.wMagic
), &handle
, &dc_funcs
)))
278 GDI_ReleaseObj( hdc
);
281 TRACE("(%p): returning %p\n", hdc
, handle
);
283 newdc
->flags
= dc
->flags
| DC_SAVED
;
284 newdc
->hPen
= dc
->hPen
;
285 newdc
->hBrush
= dc
->hBrush
;
286 newdc
->hFont
= dc
->hFont
;
287 newdc
->hBitmap
= dc
->hBitmap
;
288 newdc
->hDevice
= dc
->hDevice
;
289 newdc
->hPalette
= dc
->hPalette
;
290 newdc
->totalExtent
= dc
->totalExtent
;
291 newdc
->bitsPerPixel
= dc
->bitsPerPixel
;
292 newdc
->ROPmode
= dc
->ROPmode
;
293 newdc
->polyFillMode
= dc
->polyFillMode
;
294 newdc
->stretchBltMode
= dc
->stretchBltMode
;
295 newdc
->relAbsMode
= dc
->relAbsMode
;
296 newdc
->backgroundMode
= dc
->backgroundMode
;
297 newdc
->backgroundColor
= dc
->backgroundColor
;
298 newdc
->textColor
= dc
->textColor
;
299 newdc
->brushOrgX
= dc
->brushOrgX
;
300 newdc
->brushOrgY
= dc
->brushOrgY
;
301 newdc
->textAlign
= dc
->textAlign
;
302 newdc
->charExtra
= dc
->charExtra
;
303 newdc
->breakTotalExtra
= dc
->breakTotalExtra
;
304 newdc
->breakCount
= dc
->breakCount
;
305 newdc
->breakExtra
= dc
->breakExtra
;
306 newdc
->breakRem
= dc
->breakRem
;
307 newdc
->MapMode
= dc
->MapMode
;
308 newdc
->GraphicsMode
= dc
->GraphicsMode
;
309 newdc
->CursPosX
= dc
->CursPosX
;
310 newdc
->CursPosY
= dc
->CursPosY
;
311 newdc
->ArcDirection
= dc
->ArcDirection
;
312 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
313 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
314 newdc
->xformVport2World
= dc
->xformVport2World
;
315 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
316 newdc
->wndOrgX
= dc
->wndOrgX
;
317 newdc
->wndOrgY
= dc
->wndOrgY
;
318 newdc
->wndExtX
= dc
->wndExtX
;
319 newdc
->wndExtY
= dc
->wndExtY
;
320 newdc
->vportOrgX
= dc
->vportOrgX
;
321 newdc
->vportOrgY
= dc
->vportOrgY
;
322 newdc
->vportExtX
= dc
->vportExtX
;
323 newdc
->vportExtY
= dc
->vportExtY
;
325 newdc
->hSelf
= (HDC
)handle
;
326 newdc
->saveLevel
= 0;
328 PATH_InitGdiPath( &newdc
->path
);
330 newdc
->pAbortProc
= NULL
;
331 newdc
->hookThunk
= NULL
;
334 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
336 newdc
->hGCClipRgn
= newdc
->hVisRgn
= 0;
339 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
340 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
346 newdc
->gdiFont
= dc
->gdiFont
;
350 GDI_ReleaseObj( handle
);
351 GDI_ReleaseObj( hdc
);
356 /***********************************************************************
357 * SetDCState (Not a Windows API)
359 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
363 if (!(dc
= DC_GetDCUpdate( hdc
))) return;
364 if (!(dcs
= DC_GetDCPtr( hdcs
)))
366 GDI_ReleaseObj( hdc
);
369 if (!dcs
->flags
& DC_SAVED
)
371 GDI_ReleaseObj( hdc
);
372 GDI_ReleaseObj( hdcs
);
375 TRACE("%p %p\n", hdc
, hdcs
);
377 dc
->flags
= dcs
->flags
& ~(DC_SAVED
| DC_DIRTY
);
378 dc
->hDevice
= dcs
->hDevice
;
379 dc
->totalExtent
= dcs
->totalExtent
;
380 dc
->ROPmode
= dcs
->ROPmode
;
381 dc
->polyFillMode
= dcs
->polyFillMode
;
382 dc
->stretchBltMode
= dcs
->stretchBltMode
;
383 dc
->relAbsMode
= dcs
->relAbsMode
;
384 dc
->backgroundMode
= dcs
->backgroundMode
;
385 dc
->backgroundColor
= dcs
->backgroundColor
;
386 dc
->textColor
= dcs
->textColor
;
387 dc
->brushOrgX
= dcs
->brushOrgX
;
388 dc
->brushOrgY
= dcs
->brushOrgY
;
389 dc
->textAlign
= dcs
->textAlign
;
390 dc
->charExtra
= dcs
->charExtra
;
391 dc
->breakTotalExtra
= dcs
->breakTotalExtra
;
392 dc
->breakCount
= dcs
->breakCount
;
393 dc
->breakExtra
= dcs
->breakExtra
;
394 dc
->breakRem
= dcs
->breakRem
;
395 dc
->MapMode
= dcs
->MapMode
;
396 dc
->GraphicsMode
= dcs
->GraphicsMode
;
397 dc
->CursPosX
= dcs
->CursPosX
;
398 dc
->CursPosY
= dcs
->CursPosY
;
399 dc
->ArcDirection
= dcs
->ArcDirection
;
400 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
401 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
402 dc
->xformVport2World
= dcs
->xformVport2World
;
403 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
405 dc
->wndOrgX
= dcs
->wndOrgX
;
406 dc
->wndOrgY
= dcs
->wndOrgY
;
407 dc
->wndExtX
= dcs
->wndExtX
;
408 dc
->wndExtY
= dcs
->wndExtY
;
409 dc
->vportOrgX
= dcs
->vportOrgX
;
410 dc
->vportOrgY
= dcs
->vportOrgY
;
411 dc
->vportExtX
= dcs
->vportExtX
;
412 dc
->vportExtY
= dcs
->vportExtY
;
414 if (GDIMAGIC(dc
->header
.wMagic
) != MEMORY_DC_MAGIC
) dc
->bitsPerPixel
= dcs
->bitsPerPixel
;
418 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
419 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
423 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
426 CLIPPING_UpdateGCRegion( dc
);
428 SelectObject( hdc
, dcs
->hBitmap
);
429 SelectObject( hdc
, dcs
->hBrush
);
430 SelectObject( hdc
, dcs
->hFont
);
431 SelectObject( hdc
, dcs
->hPen
);
432 SetBkColor( hdc
, dcs
->backgroundColor
);
433 SetTextColor( hdc
, dcs
->textColor
);
434 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
435 GDI_ReleaseObj( hdcs
);
436 GDI_ReleaseObj( hdc
);
440 /***********************************************************************
441 * GetDCState (GDI.179)
443 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
445 return HDC_16( GetDCState( HDC_32(hdc
) ));
449 /***********************************************************************
450 * SetDCState (GDI.180)
452 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
454 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
458 /***********************************************************************
461 INT WINAPI
SaveDC( HDC hdc
)
467 dc
= DC_GetDCPtr( hdc
);
470 if(dc
->funcs
->pSaveDC
)
472 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
473 GDI_ReleaseObj( hdc
);
477 if (!(hdcs
= GetDCState( hdc
)))
479 GDI_ReleaseObj( hdc
);
482 dcs
= DC_GetDCPtr( hdcs
);
484 /* Copy path. The reason why path saving / restoring is in SaveDC/
485 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
486 * functions are only in Win16 (which doesn't have paths) and that
487 * SetDCState doesn't allow us to signal an error (which can happen
488 * when copying paths).
490 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
492 GDI_ReleaseObj( hdc
);
493 GDI_ReleaseObj( hdcs
);
498 dcs
->header
.hNext
= dc
->header
.hNext
;
499 dc
->header
.hNext
= HDC_16(hdcs
);
500 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
501 ret
= ++dc
->saveLevel
;
502 GDI_ReleaseObj( hdcs
);
503 GDI_ReleaseObj( hdc
);
508 /***********************************************************************
509 * RestoreDC (GDI32.@)
511 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
516 TRACE("%p %d\n", hdc
, level
);
517 dc
= DC_GetDCUpdate( hdc
);
518 if(!dc
) return FALSE
;
519 if(dc
->funcs
->pRestoreDC
)
521 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
522 GDI_ReleaseObj( hdc
);
526 if (level
== -1) level
= dc
->saveLevel
;
528 /* This pair of checks disagrees with MSDN "Platform SDK:
529 Windows GDI" July 2000 which says all negative values
530 for level will be interpreted as an instance relative
531 to the current state. Restricting it to just -1 does
533 || (level
> dc
->saveLevel
))
535 GDI_ReleaseObj( hdc
);
540 while (dc
->saveLevel
>= level
)
542 HDC hdcs
= HDC_32(dc
->header
.hNext
);
543 if (!(dcs
= DC_GetDCPtr( hdcs
)))
545 GDI_ReleaseObj( hdc
);
548 dc
->header
.hNext
= dcs
->header
.hNext
;
549 if (--dc
->saveLevel
< level
)
551 SetDCState( hdc
, hdcs
);
552 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
553 /* FIXME: This might not be quite right, since we're
554 * returning FALSE but still destroying the saved DC state */
557 GDI_ReleaseObj( hdcs
);
558 GDI_ReleaseObj( hdc
);
560 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
562 GDI_ReleaseObj( hdc
);
567 /***********************************************************************
568 * CreateDCA (GDI32.@)
570 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
571 const DEVMODEA
*initData
)
575 const DC_FUNCTIONS
*funcs
;
580 if (!device
|| !DRIVER_GetDriverName( device
, buf
, sizeof(buf
) ))
582 if (!driver
) return 0;
586 if (!(funcs
= DRIVER_load_driver( buf
)))
588 ERR( "no driver found for %s\n", buf
);
591 if (!(dc
= DC_AllocDC( funcs
, DC_MAGIC
)))
593 DRIVER_release_driver( funcs
);
597 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
599 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
600 debugstr_a(driver
), debugstr_a(device
), debugstr_a(output
), dc
->hSelf
);
602 if (dc
->funcs
->pCreateDC
&&
603 !dc
->funcs
->pCreateDC( dc
, &dc
->physDev
, buf
, device
, output
, initData
))
605 WARN("creation aborted by device\n" );
606 GDI_FreeObject( dc
->hSelf
, dc
);
607 DRIVER_release_driver( funcs
);
611 dc
->totalExtent
.left
= 0;
612 dc
->totalExtent
.top
= 0;
613 dc
->totalExtent
.right
= GetDeviceCaps( dc
->hSelf
, HORZRES
);
614 dc
->totalExtent
.bottom
= GetDeviceCaps( dc
->hSelf
, VERTRES
);
615 dc
->hVisRgn
= CreateRectRgnIndirect( &dc
->totalExtent
);
619 GDI_ReleaseObj( hdc
);
624 /***********************************************************************
625 * CreateDCW (GDI32.@)
627 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
628 const DEVMODEW
*initData
)
630 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
631 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
632 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
633 HDC res
= CreateDCA( driverA
, deviceA
, outputA
,
634 (const DEVMODEA
*)initData
/*FIXME*/ );
635 HeapFree( GetProcessHeap(), 0, driverA
);
636 HeapFree( GetProcessHeap(), 0, deviceA
);
637 HeapFree( GetProcessHeap(), 0, outputA
);
642 /***********************************************************************
643 * CreateICA (GDI32.@)
645 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
646 const DEVMODEA
* initData
)
648 /* Nothing special yet for ICs */
649 return CreateDCA( driver
, device
, output
, initData
);
653 /***********************************************************************
654 * CreateICW (GDI32.@)
656 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
657 const DEVMODEW
* initData
)
659 /* Nothing special yet for ICs */
660 return CreateDCW( driver
, device
, output
, initData
);
664 /***********************************************************************
665 * CreateCompatibleDC (GDI32.@)
667 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
670 const DC_FUNCTIONS
*funcs
;
675 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
677 funcs
= origDC
->funcs
;
678 physDev
= origDC
->physDev
;
679 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
680 funcs
= DRIVER_get_driver( funcs
);
684 funcs
= DRIVER_load_driver( "DISPLAY" );
688 if (!funcs
) return 0;
690 if (!(dc
= DC_AllocDC( funcs
, MEMORY_DC_MAGIC
)))
692 DRIVER_release_driver( funcs
);
696 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
698 dc
->bitsPerPixel
= 1;
699 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
701 /* Copy the driver-specific physical device info into
702 * the new DC. The driver may use this read-only info
703 * while creating the compatible DC below. */
704 dc
->physDev
= physDev
;
706 if (dc
->funcs
->pCreateDC
&&
707 !dc
->funcs
->pCreateDC( dc
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
709 WARN("creation aborted by device\n");
710 GDI_FreeObject( dc
->hSelf
, dc
);
711 DRIVER_release_driver( funcs
);
715 dc
->totalExtent
.left
= 0;
716 dc
->totalExtent
.top
= 0;
717 dc
->totalExtent
.right
= 1; /* default bitmap is 1x1 */
718 dc
->totalExtent
.bottom
= 1;
719 dc
->hVisRgn
= CreateRectRgnIndirect( &dc
->totalExtent
);
722 GDI_ReleaseObj( dc
->hSelf
);
727 /***********************************************************************
730 BOOL WINAPI
DeleteDC( HDC hdc
)
732 const DC_FUNCTIONS
*funcs
= NULL
;
739 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
741 /* Call hook procedure to check whether is it OK to delete this DC */
744 DCHOOKPROC proc
= dc
->hookThunk
;
745 DWORD data
= dc
->dwHookData
;
746 GDI_ReleaseObj( hdc
);
747 if (!proc( HDC_16(hdc
), DCHC_DELETEDC
, data
, 0 )) return FALSE
;
748 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
751 while (dc
->saveLevel
)
754 HDC hdcs
= HDC_32(dc
->header
.hNext
);
755 if (!(dcs
= DC_GetDCPtr( hdcs
))) break;
756 dc
->header
.hNext
= dcs
->header
.hNext
;
758 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
759 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
760 if (dcs
->hGCClipRgn
) DeleteObject( dcs
->hGCClipRgn
);
761 PATH_DestroyGdiPath(&dcs
->path
);
762 GDI_FreeObject( hdcs
, dcs
);
765 if (!(dc
->flags
& DC_SAVED
))
767 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
768 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
769 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
770 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
772 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
776 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
777 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
778 if (dc
->hGCClipRgn
) DeleteObject( dc
->hGCClipRgn
);
779 PATH_DestroyGdiPath(&dc
->path
);
781 GDI_FreeObject( hdc
, dc
);
782 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
787 /***********************************************************************
790 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
795 if ((dc
= DC_GetDCPtr( hdc
)))
797 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
798 GDI_ReleaseObj( hdc
);
804 /***********************************************************************
807 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
809 return ResetDCA(hdc
, (const DEVMODEA
*)devmode
); /* FIXME */
813 /***********************************************************************
814 * GetDeviceCaps (GDI32.@)
816 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
821 if ((dc
= DC_GetDCPtr( hdc
)))
823 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
824 GDI_ReleaseObj( hdc
);
830 /***********************************************************************
831 * SetBkColor (GDI32.@)
833 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
836 DC
* dc
= DC_GetDCPtr( hdc
);
838 if (!dc
) return CLR_INVALID
;
839 oldColor
= dc
->backgroundColor
;
840 if (dc
->funcs
->pSetBkColor
)
842 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
843 if (color
== CLR_INVALID
) /* don't change it */
846 oldColor
= CLR_INVALID
;
849 dc
->backgroundColor
= color
;
850 GDI_ReleaseObj( hdc
);
855 /***********************************************************************
856 * SetTextColor (GDI32.@)
858 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
861 DC
* dc
= DC_GetDCPtr( hdc
);
863 if (!dc
) return CLR_INVALID
;
864 oldColor
= dc
->textColor
;
865 if (dc
->funcs
->pSetTextColor
)
867 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
868 if (color
== CLR_INVALID
) /* don't change it */
871 oldColor
= CLR_INVALID
;
874 dc
->textColor
= color
;
875 GDI_ReleaseObj( hdc
);
880 /***********************************************************************
881 * SetTextAlign (GDI32.@)
883 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
886 DC
*dc
= DC_GetDCPtr( hdc
);
888 if (dc
->funcs
->pSetTextAlign
)
889 prevAlign
= dc
->funcs
->pSetTextAlign(dc
->physDev
, align
);
891 prevAlign
= dc
->textAlign
;
892 dc
->textAlign
= align
;
894 GDI_ReleaseObj( hdc
);
898 /***********************************************************************
899 * GetDCOrgEx (GDI32.@)
901 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
905 if (!lpp
) return FALSE
;
906 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
909 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
910 GDI_ReleaseObj( hDC
);
915 /***********************************************************************
918 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
921 HDC hdc
= HDC_32( hdc16
);
922 DC
*dc
= DC_GetDCPtr( hdc
);
924 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
925 GDI_ReleaseObj( hdc
);
930 /***********************************************************************
931 * SetGraphicsMode (GDI32.@)
933 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
936 DC
*dc
= DC_GetDCPtr( hdc
);
938 /* One would think that setting the graphics mode to GM_COMPATIBLE
939 * would also reset the world transformation matrix to the unity
940 * matrix. However, in Windows, this is not the case. This doesn't
941 * make a lot of sense to me, but that's the way it is.
944 if ((mode
> 0) && (mode
<= GM_LAST
))
946 ret
= dc
->GraphicsMode
;
947 dc
->GraphicsMode
= mode
;
949 GDI_ReleaseObj( hdc
);
954 /***********************************************************************
955 * SetArcDirection (GDI32.@)
957 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
960 INT nOldDirection
= 0;
962 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
964 SetLastError(ERROR_INVALID_PARAMETER
);
968 if ((dc
= DC_GetDCPtr( hdc
)))
970 nOldDirection
= dc
->ArcDirection
;
971 dc
->ArcDirection
= nDirection
;
972 GDI_ReleaseObj( hdc
);
974 return nOldDirection
;
978 /***********************************************************************
979 * GetWorldTransform (GDI32.@)
981 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
984 if (!xform
) return FALSE
;
985 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
986 *xform
= dc
->xformWorld2Wnd
;
987 GDI_ReleaseObj( hdc
);
992 /***********************************************************************
993 * GetTransform (GDI32.@)
995 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
997 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
998 ERR("stub: don't know what to do for code %lx\n", unknown
);
1003 /***********************************************************************
1004 * SetWorldTransform (GDI32.@)
1006 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1009 DC
*dc
= DC_GetDCPtr( hdc
);
1011 if (!dc
) return FALSE
;
1012 if (!xform
) goto done
;
1014 /* Check that graphics mode is GM_ADVANCED */
1015 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1017 if (dc
->funcs
->pSetWorldTransform
)
1019 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1020 if (!ret
) goto done
;
1023 dc
->xformWorld2Wnd
= *xform
;
1024 DC_UpdateXforms( dc
);
1027 GDI_ReleaseObj( hdc
);
1032 /****************************************************************************
1033 * ModifyWorldTransform [GDI32.@]
1034 * Modifies the world transformation for a device context.
1037 * hdc [I] Handle to device context
1038 * xform [I] XFORM structure that will be used to modify the world
1040 * iMode [I] Specifies in what way to modify the world transformation
1043 * Resets the world transformation to the identity matrix.
1044 * The parameter xform is ignored.
1046 * Multiplies xform into the world transformation matrix from
1049 * Multiplies xform into the world transformation matrix from
1054 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1058 DC
*dc
= DC_GetDCPtr( hdc
);
1060 /* Check for illegal parameters */
1061 if (!dc
) return FALSE
;
1062 if (!xform
) goto done
;
1064 /* Check that graphics mode is GM_ADVANCED */
1065 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1067 if (dc
->funcs
->pModifyWorldTransform
)
1069 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1070 if (!ret
) goto done
;
1076 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1077 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1078 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1079 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1080 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1081 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1083 case MWT_LEFTMULTIPLY
:
1084 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1085 &dc
->xformWorld2Wnd
);
1087 case MWT_RIGHTMULTIPLY
:
1088 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1095 DC_UpdateXforms( dc
);
1098 GDI_ReleaseObj( hdc
);
1103 /****************************************************************************
1104 * CombineTransform [GDI32.@]
1105 * Combines two transformation matrices.
1108 * xformResult [O] Stores the result of combining the two matrices
1109 * xform1 [I] Specifies the first matrix to apply
1110 * xform2 [I] Specifies the second matrix to apply
1113 * The same matrix can be passed in for more than one of the parameters.
1117 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1118 const XFORM
*xform2
)
1122 /* Check for illegal parameters */
1123 if (!xformResult
|| !xform1
|| !xform2
)
1126 /* Create the result in a temporary XFORM, since xformResult may be
1127 * equal to xform1 or xform2 */
1128 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1129 xform1
->eM12
* xform2
->eM21
;
1130 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1131 xform1
->eM12
* xform2
->eM22
;
1132 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1133 xform1
->eM22
* xform2
->eM21
;
1134 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1135 xform1
->eM22
* xform2
->eM22
;
1136 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1137 xform1
->eDy
* xform2
->eM21
+
1139 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1140 xform1
->eDy
* xform2
->eM22
+
1143 /* Copy the result to xformResult */
1144 *xformResult
= xformTemp
;
1150 /***********************************************************************
1151 * SetDCHook (GDI32.@)
1153 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1155 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1157 DC
*dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
);
1159 if (!dc
) return FALSE
;
1161 if (!(dc
->flags
& DC_SAVED
))
1163 dc
->dwHookData
= dwHookData
;
1164 dc
->hookThunk
= hookProc
;
1166 GDI_ReleaseObj( hdc
);
1171 /* relay function to call the 16-bit DC hook proc */
1172 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc16
, WORD code
, DWORD data
, LPARAM lParam
)
1176 FARPROC16 proc
= NULL
;
1177 HDC hdc
= HDC_32( hdc16
);
1178 DC
*dc
= DC_GetDCPtr( hdc
);
1180 if (!dc
) return FALSE
;
1181 proc
= dc
->hookProc
;
1182 GDI_ReleaseObj( hdc
);
1183 if (!proc
) return FALSE
;
1186 args
[3] = HIWORD(data
);
1187 args
[2] = LOWORD(data
);
1188 args
[1] = HIWORD(lParam
);
1189 args
[0] = LOWORD(lParam
);
1190 WOWCallback16Ex( (DWORD
)proc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1194 /***********************************************************************
1195 * SetDCHook (GDI.190)
1197 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1199 HDC hdc
= HDC_32( hdc16
);
1200 DC
*dc
= DC_GetDCPtr( hdc
);
1201 if (!dc
) return FALSE
;
1203 dc
->hookProc
= hookProc
;
1204 GDI_ReleaseObj( hdc
);
1205 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1209 /***********************************************************************
1210 * GetDCHook (GDI.191)
1212 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1214 HDC hdc
= HDC_32( hdc16
);
1215 DC
*dc
= DC_GetDCPtr( hdc
);
1219 *phookProc
= dc
->hookProc
;
1220 ret
= dc
->dwHookData
;
1221 GDI_ReleaseObj( hdc
);
1226 /***********************************************************************
1227 * SetHookFlags (GDI.192)
1229 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1231 HDC hdc
= HDC_32( hdc16
);
1232 DC
*dc
= DC_GetDCPtr( hdc
);
1236 WORD wRet
= dc
->flags
& DC_DIRTY
;
1238 /* "Undocumented Windows" info is slightly confusing.
1241 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1243 if( flags
& DCHF_INVALIDATEVISRGN
)
1244 dc
->flags
|= DC_DIRTY
;
1245 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1246 dc
->flags
&= ~DC_DIRTY
;
1247 GDI_ReleaseObj( hdc
);
1253 /***********************************************************************
1254 * SetICMMode (GDI32.@)
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
;
1265 /***********************************************************************
1266 * GetDeviceGammaRamp (GDI32.@)
1268 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1271 DC
*dc
= DC_GetDCPtr( hDC
);
1275 if (dc
->funcs
->pGetDeviceGammaRamp
)
1276 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1277 GDI_ReleaseObj( hDC
);
1282 /***********************************************************************
1283 * SetDeviceGammaRamp (GDI32.@)
1285 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1288 DC
*dc
= DC_GetDCPtr( hDC
);
1292 if (dc
->funcs
->pSetDeviceGammaRamp
)
1293 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1294 GDI_ReleaseObj( hDC
);
1299 /***********************************************************************
1300 * GetColorSpace (GDI32.@)
1302 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1304 /*FIXME Need to to whatever GetColorSpace actually does */
1308 /***********************************************************************
1309 * CreateColorSpaceA (GDI32.@)
1311 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1317 /***********************************************************************
1318 * CreateColorSpaceW (GDI32.@)
1320 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1326 /***********************************************************************
1327 * DeleteColorSpace (GDI32.@)
1329 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1336 /***********************************************************************
1337 * SetColorSpace (GDI32.@)
1339 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1346 /***********************************************************************
1347 * GetBoundsRect (GDI.194)
1349 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1351 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1354 /***********************************************************************
1355 * GetBoundsRect (GDI32.@)
1357 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1359 FIXME("(): stub\n");
1360 return DCB_RESET
; /* bounding rectangle always empty */
1363 /***********************************************************************
1364 * SetBoundsRect (GDI.193)
1366 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1368 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1369 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1371 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1374 /***********************************************************************
1375 * SetBoundsRect (GDI32.@)
1377 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1379 FIXME("(): stub\n");
1380 return DCB_DISABLE
; /* bounding rectangle always empty */
1384 /***********************************************************************
1385 * GetRelAbs (GDI32.@)
1387 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1390 DC
*dc
= DC_GetDCPtr( hdc
);
1391 if (dc
) ret
= dc
->relAbsMode
;
1392 GDI_ReleaseObj( hdc
);
1396 /***********************************************************************
1397 * GetLayout (GDI32.@)
1399 * Gets left->right or right->left text layout flags of a dc.
1400 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1403 DWORD WINAPI
GetLayout(HDC hdc
)
1405 FIXME("(%p): stub\n", hdc
);
1406 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1410 /***********************************************************************
1411 * SetLayout (GDI32.@)
1413 * Sets left->right or right->left text layout flags of a dc.
1414 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1417 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1419 FIXME("(%p,%08lx): stub\n", hdc
, layout
);
1420 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1424 /***********************************************************************
1425 * SetDCBrushColor (GDI32.@)
1427 * Sets the current device context (DC) brush color to the specified
1428 * color value. If the device cannot represent the specified color
1429 * value, the color is set to the nearest physical color.
1432 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1434 FIXME("(%p, %08lx): stub\n", hdc
, crColor
);
1435 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1439 /***********************************************************************
1440 * SetVirtualResolution (GDI32.@)
1442 * Undocumented on msdn. Called when powerpoint xp saves a file.
1444 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
1446 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);