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
33 #include "wine/winuser16.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
41 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
);
43 static const struct gdi_obj_funcs dc_funcs
=
45 NULL
, /* pSelectObject */
46 NULL
, /* pGetObject16 */
47 NULL
, /* pGetObjectA */
48 NULL
, /* pGetObjectW */
49 NULL
, /* pUnrealizeObject */
50 DC_DeleteObject
/* pDeleteObject */
53 /***********************************************************************
56 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
, WORD magic
)
61 if (!(dc
= GDI_AllocObject( sizeof(*dc
), magic
, (HGDIOBJ
*)&hdc
, &dc_funcs
))) return NULL
;
82 dc
->hPen
= GetStockObject( BLACK_PEN
);
83 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
84 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
87 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
89 dc
->ROPmode
= R2_COPYPEN
;
90 dc
->polyFillMode
= ALTERNATE
;
91 dc
->stretchBltMode
= BLACKONWHITE
;
92 dc
->relAbsMode
= ABSOLUTE
;
93 dc
->backgroundMode
= OPAQUE
;
94 dc
->backgroundColor
= RGB( 255, 255, 255 );
95 dc
->textColor
= RGB( 0, 0, 0 );
98 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
100 dc
->breakTotalExtra
= 0;
104 dc
->totalExtent
.left
= 0;
105 dc
->totalExtent
.top
= 0;
106 dc
->totalExtent
.right
= 0;
107 dc
->totalExtent
.bottom
= 0;
108 dc
->bitsPerPixel
= 1;
109 dc
->MapMode
= MM_TEXT
;
110 dc
->GraphicsMode
= GM_COMPATIBLE
;
111 dc
->pAbortProc
= NULL
;
114 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
115 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
116 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
117 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
118 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
119 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
120 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
121 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
122 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
123 dc
->vport2WorldValid
= TRUE
;
124 PATH_InitGdiPath(&dc
->path
);
130 /***********************************************************************
133 DC
*DC_GetDCPtr( HDC hdc
)
135 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
136 if (!ptr
) return NULL
;
137 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
138 (GDIMAGIC(ptr
->wMagic
) == MEMORY_DC_MAGIC
) ||
139 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
140 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
142 GDI_ReleaseObj( hdc
);
143 SetLastError( ERROR_INVALID_HANDLE
);
147 /***********************************************************************
150 * Retrieve a DC ptr while making sure the visRgn is updated.
151 * This function may call up to USER so the GDI lock should _not_
152 * be held when calling it.
154 DC
*DC_GetDCUpdate( HDC hdc
)
156 DC
*dc
= DC_GetDCPtr( hdc
);
157 if (!dc
) return NULL
;
158 while (dc
->flags
& DC_DIRTY
)
160 DCHOOKPROC proc
= dc
->hookThunk
;
161 dc
->flags
&= ~DC_DIRTY
;
164 DWORD data
= dc
->dwHookData
;
165 GDI_ReleaseObj( hdc
);
166 proc( HDC_16(hdc
), DCHC_INVALIDVISRGN
, data
, 0 );
167 if (!(dc
= DC_GetDCPtr( hdc
))) break;
168 /* otherwise restart the loop in case it became dirty again in the meantime */
175 /***********************************************************************
178 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
180 GDI_ReleaseObj( handle
);
181 return DeleteDC( handle
);
185 /***********************************************************************
188 * Setup device-specific DC values for a newly created DC.
190 void DC_InitDC( DC
* dc
)
192 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
193 SetTextColor( dc
->hSelf
, dc
->textColor
);
194 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
195 SelectObject( dc
->hSelf
, dc
->hPen
);
196 SelectObject( dc
->hSelf
, dc
->hBrush
);
197 SelectObject( dc
->hSelf
, dc
->hFont
);
198 CLIPPING_UpdateGCRegion( dc
);
202 /***********************************************************************
205 * Computes the inverse of the transformation xformSrc and stores it to
206 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
209 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
213 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
214 xformSrc
->eM12
*xformSrc
->eM21
;
215 if (determinant
> -1e-12 && determinant
< 1e-12)
218 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
219 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
220 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
221 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
222 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
223 xformSrc
->eDy
* xformDest
->eM21
;
224 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
225 xformSrc
->eDy
* xformDest
->eM22
;
231 /***********************************************************************
234 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
235 * fields of the specified DC by creating a transformation that
236 * represents the current mapping mode and combining it with the DC's
237 * world transform. This function should be called whenever the
238 * parameters associated with the mapping mode (window and viewport
239 * extents and origins) or the world transform change.
241 void DC_UpdateXforms( DC
*dc
)
243 XFORM xformWnd2Vport
;
244 FLOAT scaleX
, scaleY
;
246 /* Construct a transformation to do the window-to-viewport conversion */
247 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
248 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
249 xformWnd2Vport
.eM11
= scaleX
;
250 xformWnd2Vport
.eM12
= 0.0;
251 xformWnd2Vport
.eM21
= 0.0;
252 xformWnd2Vport
.eM22
= scaleY
;
253 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
254 scaleX
* (FLOAT
)dc
->wndOrgX
;
255 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
256 scaleY
* (FLOAT
)dc
->wndOrgY
;
258 /* Combine with the world transformation */
259 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
262 /* Create inverse of world-to-viewport transformation */
263 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
264 &dc
->xformVport2World
);
266 /* Reselect the font back into the dc so that the font size
268 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
272 /***********************************************************************
273 * GetDCState (Not a Windows API)
275 HDC WINAPI
GetDCState( HDC hdc
)
280 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
281 if (!(newdc
= GDI_AllocObject( sizeof(DC
), GDIMAGIC(dc
->header
.wMagic
), &handle
, &dc_funcs
)))
283 GDI_ReleaseObj( hdc
);
286 TRACE("(%p): returning %p\n", hdc
, handle
);
288 newdc
->flags
= dc
->flags
| DC_SAVED
;
289 newdc
->hPen
= dc
->hPen
;
290 newdc
->hBrush
= dc
->hBrush
;
291 newdc
->hFont
= dc
->hFont
;
292 newdc
->hBitmap
= dc
->hBitmap
;
293 newdc
->hDevice
= dc
->hDevice
;
294 newdc
->hPalette
= dc
->hPalette
;
295 newdc
->totalExtent
= dc
->totalExtent
;
296 newdc
->bitsPerPixel
= dc
->bitsPerPixel
;
297 newdc
->ROPmode
= dc
->ROPmode
;
298 newdc
->polyFillMode
= dc
->polyFillMode
;
299 newdc
->stretchBltMode
= dc
->stretchBltMode
;
300 newdc
->relAbsMode
= dc
->relAbsMode
;
301 newdc
->backgroundMode
= dc
->backgroundMode
;
302 newdc
->backgroundColor
= dc
->backgroundColor
;
303 newdc
->textColor
= dc
->textColor
;
304 newdc
->brushOrgX
= dc
->brushOrgX
;
305 newdc
->brushOrgY
= dc
->brushOrgY
;
306 newdc
->textAlign
= dc
->textAlign
;
307 newdc
->charExtra
= dc
->charExtra
;
308 newdc
->breakTotalExtra
= dc
->breakTotalExtra
;
309 newdc
->breakCount
= dc
->breakCount
;
310 newdc
->breakExtra
= dc
->breakExtra
;
311 newdc
->breakRem
= dc
->breakRem
;
312 newdc
->MapMode
= dc
->MapMode
;
313 newdc
->GraphicsMode
= dc
->GraphicsMode
;
314 newdc
->CursPosX
= dc
->CursPosX
;
315 newdc
->CursPosY
= dc
->CursPosY
;
316 newdc
->ArcDirection
= dc
->ArcDirection
;
317 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
318 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
319 newdc
->xformVport2World
= dc
->xformVport2World
;
320 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
321 newdc
->wndOrgX
= dc
->wndOrgX
;
322 newdc
->wndOrgY
= dc
->wndOrgY
;
323 newdc
->wndExtX
= dc
->wndExtX
;
324 newdc
->wndExtY
= dc
->wndExtY
;
325 newdc
->vportOrgX
= dc
->vportOrgX
;
326 newdc
->vportOrgY
= dc
->vportOrgY
;
327 newdc
->vportExtX
= dc
->vportExtX
;
328 newdc
->vportExtY
= dc
->vportExtY
;
330 newdc
->hSelf
= (HDC
)handle
;
331 newdc
->saveLevel
= 0;
333 PATH_InitGdiPath( &newdc
->path
);
335 newdc
->pAbortProc
= NULL
;
336 newdc
->hookThunk
= NULL
;
339 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
341 newdc
->hGCClipRgn
= newdc
->hVisRgn
= 0;
344 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
345 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
351 newdc
->gdiFont
= dc
->gdiFont
;
355 GDI_ReleaseObj( handle
);
356 GDI_ReleaseObj( hdc
);
361 /***********************************************************************
362 * SetDCState (Not a Windows API)
364 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
368 if (!(dc
= DC_GetDCUpdate( hdc
))) return;
369 if (!(dcs
= DC_GetDCPtr( hdcs
)))
371 GDI_ReleaseObj( hdc
);
374 if (!dcs
->flags
& DC_SAVED
)
376 GDI_ReleaseObj( hdc
);
377 GDI_ReleaseObj( hdcs
);
380 TRACE("%p %p\n", hdc
, hdcs
);
382 dc
->flags
= dcs
->flags
& ~(DC_SAVED
| DC_DIRTY
);
383 dc
->hDevice
= dcs
->hDevice
;
384 dc
->totalExtent
= dcs
->totalExtent
;
385 dc
->ROPmode
= dcs
->ROPmode
;
386 dc
->polyFillMode
= dcs
->polyFillMode
;
387 dc
->stretchBltMode
= dcs
->stretchBltMode
;
388 dc
->relAbsMode
= dcs
->relAbsMode
;
389 dc
->backgroundMode
= dcs
->backgroundMode
;
390 dc
->backgroundColor
= dcs
->backgroundColor
;
391 dc
->textColor
= dcs
->textColor
;
392 dc
->brushOrgX
= dcs
->brushOrgX
;
393 dc
->brushOrgY
= dcs
->brushOrgY
;
394 dc
->textAlign
= dcs
->textAlign
;
395 dc
->charExtra
= dcs
->charExtra
;
396 dc
->breakTotalExtra
= dcs
->breakTotalExtra
;
397 dc
->breakCount
= dcs
->breakCount
;
398 dc
->breakExtra
= dcs
->breakExtra
;
399 dc
->breakRem
= dcs
->breakRem
;
400 dc
->MapMode
= dcs
->MapMode
;
401 dc
->GraphicsMode
= dcs
->GraphicsMode
;
402 dc
->CursPosX
= dcs
->CursPosX
;
403 dc
->CursPosY
= dcs
->CursPosY
;
404 dc
->ArcDirection
= dcs
->ArcDirection
;
405 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
406 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
407 dc
->xformVport2World
= dcs
->xformVport2World
;
408 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
410 dc
->wndOrgX
= dcs
->wndOrgX
;
411 dc
->wndOrgY
= dcs
->wndOrgY
;
412 dc
->wndExtX
= dcs
->wndExtX
;
413 dc
->wndExtY
= dcs
->wndExtY
;
414 dc
->vportOrgX
= dcs
->vportOrgX
;
415 dc
->vportOrgY
= dcs
->vportOrgY
;
416 dc
->vportExtX
= dcs
->vportExtX
;
417 dc
->vportExtY
= dcs
->vportExtY
;
419 if (GDIMAGIC(dc
->header
.wMagic
) != MEMORY_DC_MAGIC
) dc
->bitsPerPixel
= dcs
->bitsPerPixel
;
423 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
424 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
428 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
431 CLIPPING_UpdateGCRegion( dc
);
433 SelectObject( hdc
, dcs
->hBitmap
);
434 SelectObject( hdc
, dcs
->hBrush
);
435 SelectObject( hdc
, dcs
->hFont
);
436 SelectObject( hdc
, dcs
->hPen
);
437 SetBkColor( hdc
, dcs
->backgroundColor
);
438 SetTextColor( hdc
, dcs
->textColor
);
439 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
440 GDI_ReleaseObj( hdcs
);
441 GDI_ReleaseObj( hdc
);
445 /***********************************************************************
446 * GetDCState (GDI.179)
448 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
450 return HDC_16( GetDCState( HDC_32(hdc
) ));
454 /***********************************************************************
455 * SetDCState (GDI.180)
457 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
459 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
463 /***********************************************************************
466 INT WINAPI
SaveDC( HDC hdc
)
472 dc
= DC_GetDCPtr( hdc
);
475 if(dc
->funcs
->pSaveDC
)
477 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
478 GDI_ReleaseObj( hdc
);
482 if (!(hdcs
= GetDCState( hdc
)))
484 GDI_ReleaseObj( hdc
);
487 dcs
= DC_GetDCPtr( hdcs
);
489 /* Copy path. The reason why path saving / restoring is in SaveDC/
490 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
491 * functions are only in Win16 (which doesn't have paths) and that
492 * SetDCState doesn't allow us to signal an error (which can happen
493 * when copying paths).
495 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
497 GDI_ReleaseObj( hdc
);
498 GDI_ReleaseObj( hdcs
);
503 dcs
->header
.hNext
= dc
->header
.hNext
;
504 dc
->header
.hNext
= HDC_16(hdcs
);
505 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
506 ret
= ++dc
->saveLevel
;
507 GDI_ReleaseObj( hdcs
);
508 GDI_ReleaseObj( hdc
);
513 /***********************************************************************
514 * RestoreDC (GDI32.@)
516 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
521 TRACE("%p %d\n", hdc
, level
);
522 dc
= DC_GetDCUpdate( hdc
);
523 if(!dc
) return FALSE
;
524 if(dc
->funcs
->pRestoreDC
)
526 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
527 GDI_ReleaseObj( hdc
);
531 if (level
== -1) level
= dc
->saveLevel
;
533 /* This pair of checks disagrees with MSDN "Platform SDK:
534 Windows GDI" July 2000 which says all negative values
535 for level will be interpreted as an instance relative
536 to the current state. Restricting it to just -1 does
538 || (level
> dc
->saveLevel
))
540 GDI_ReleaseObj( hdc
);
545 while (dc
->saveLevel
>= level
)
547 HDC hdcs
= HDC_32(dc
->header
.hNext
);
548 if (!(dcs
= DC_GetDCPtr( hdcs
)))
550 GDI_ReleaseObj( hdc
);
553 dc
->header
.hNext
= dcs
->header
.hNext
;
554 if (--dc
->saveLevel
< level
)
556 SetDCState( hdc
, hdcs
);
557 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
558 /* FIXME: This might not be quite right, since we're
559 * returning FALSE but still destroying the saved DC state */
562 GDI_ReleaseObj( hdcs
);
563 GDI_ReleaseObj( hdc
);
565 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
567 GDI_ReleaseObj( hdc
);
572 /***********************************************************************
573 * CreateDCW (GDI32.@)
575 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
576 const DEVMODEW
*initData
)
580 const DC_FUNCTIONS
*funcs
;
585 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
587 if (!driver
) return 0;
588 strcpyW(buf
, driver
);
591 if (!(funcs
= DRIVER_load_driver( buf
)))
593 ERR( "no driver found for %s\n", debugstr_w(buf
) );
596 if (!(dc
= DC_AllocDC( funcs
, DC_MAGIC
)))
598 DRIVER_release_driver( funcs
);
602 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
604 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
605 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
607 if (dc
->funcs
->pCreateDC
&&
608 !dc
->funcs
->pCreateDC( dc
, &dc
->physDev
, buf
, device
, output
, initData
))
610 WARN("creation aborted by device\n" );
611 GDI_FreeObject( dc
->hSelf
, dc
);
612 DRIVER_release_driver( funcs
);
616 dc
->totalExtent
.left
= 0;
617 dc
->totalExtent
.top
= 0;
618 dc
->totalExtent
.right
= GetDeviceCaps( dc
->hSelf
, HORZRES
);
619 dc
->totalExtent
.bottom
= GetDeviceCaps( dc
->hSelf
, VERTRES
);
620 dc
->hVisRgn
= CreateRectRgnIndirect( &dc
->totalExtent
);
624 GDI_ReleaseObj( hdc
);
629 /***********************************************************************
630 * CreateDCA (GDI32.@)
632 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
633 const DEVMODEA
*initData
)
635 UNICODE_STRING driverW
, deviceW
, outputW
;
639 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
640 else driverW
.Buffer
= NULL
;
642 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
643 else deviceW
.Buffer
= NULL
;
645 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
646 else outputW
.Buffer
= NULL
;
648 if (initData
) initDataW
= GdiConvertToDevmodeW(initData
);
649 else initDataW
= NULL
;
651 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
653 RtlFreeUnicodeString(&driverW
);
654 RtlFreeUnicodeString(&deviceW
);
655 RtlFreeUnicodeString(&outputW
);
656 if (initDataW
) HeapFree(GetProcessHeap(), 0, initDataW
);
661 /***********************************************************************
662 * CreateICA (GDI32.@)
664 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
665 const DEVMODEA
* initData
)
667 /* Nothing special yet for ICs */
668 return CreateDCA( driver
, device
, output
, initData
);
672 /***********************************************************************
673 * CreateICW (GDI32.@)
675 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
676 const DEVMODEW
* initData
)
678 /* Nothing special yet for ICs */
679 return CreateDCW( driver
, device
, output
, initData
);
683 /***********************************************************************
684 * CreateCompatibleDC (GDI32.@)
686 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
689 const DC_FUNCTIONS
*funcs
;
694 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
696 funcs
= origDC
->funcs
;
697 physDev
= origDC
->physDev
;
698 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
699 funcs
= DRIVER_get_driver( funcs
);
703 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
704 funcs
= DRIVER_load_driver( displayW
);
708 if (!funcs
) return 0;
710 if (!(dc
= DC_AllocDC( funcs
, MEMORY_DC_MAGIC
)))
712 DRIVER_release_driver( funcs
);
716 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
718 dc
->bitsPerPixel
= 1;
719 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
721 /* Copy the driver-specific physical device info into
722 * the new DC. The driver may use this read-only info
723 * while creating the compatible DC below. */
724 dc
->physDev
= physDev
;
726 if (dc
->funcs
->pCreateDC
&&
727 !dc
->funcs
->pCreateDC( dc
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
729 WARN("creation aborted by device\n");
730 GDI_FreeObject( dc
->hSelf
, dc
);
731 DRIVER_release_driver( funcs
);
735 dc
->totalExtent
.left
= 0;
736 dc
->totalExtent
.top
= 0;
737 dc
->totalExtent
.right
= 1; /* default bitmap is 1x1 */
738 dc
->totalExtent
.bottom
= 1;
739 dc
->hVisRgn
= CreateRectRgnIndirect( &dc
->totalExtent
);
742 GDI_ReleaseObj( dc
->hSelf
);
747 /***********************************************************************
750 BOOL WINAPI
DeleteDC( HDC hdc
)
752 const DC_FUNCTIONS
*funcs
= NULL
;
759 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
761 /* Call hook procedure to check whether is it OK to delete this DC */
764 DCHOOKPROC proc
= dc
->hookThunk
;
765 DWORD data
= dc
->dwHookData
;
766 GDI_ReleaseObj( hdc
);
767 if (!proc( HDC_16(hdc
), DCHC_DELETEDC
, data
, 0 )) return FALSE
;
768 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
771 while (dc
->saveLevel
)
774 HDC hdcs
= HDC_32(dc
->header
.hNext
);
775 if (!(dcs
= DC_GetDCPtr( hdcs
))) break;
776 dc
->header
.hNext
= dcs
->header
.hNext
;
778 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
779 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
780 if (dcs
->hGCClipRgn
) DeleteObject( dcs
->hGCClipRgn
);
781 PATH_DestroyGdiPath(&dcs
->path
);
782 GDI_FreeObject( hdcs
, dcs
);
785 if (!(dc
->flags
& DC_SAVED
))
787 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
788 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
789 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
790 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
792 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
796 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
797 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
798 if (dc
->hGCClipRgn
) DeleteObject( dc
->hGCClipRgn
);
799 PATH_DestroyGdiPath(&dc
->path
);
801 GDI_FreeObject( hdc
, dc
);
802 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
807 /***********************************************************************
810 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
815 if ((dc
= DC_GetDCPtr( hdc
)))
817 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
818 GDI_ReleaseObj( hdc
);
824 /***********************************************************************
827 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
829 return ResetDCA(hdc
, (const DEVMODEA
*)devmode
); /* FIXME */
833 /***********************************************************************
834 * GetDeviceCaps (GDI32.@)
836 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
841 if ((dc
= DC_GetDCPtr( hdc
)))
843 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
844 GDI_ReleaseObj( hdc
);
850 /***********************************************************************
851 * SetBkColor (GDI32.@)
853 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
856 DC
* dc
= DC_GetDCPtr( hdc
);
858 if (!dc
) return CLR_INVALID
;
859 oldColor
= dc
->backgroundColor
;
860 if (dc
->funcs
->pSetBkColor
)
862 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
863 if (color
== CLR_INVALID
) /* don't change it */
866 oldColor
= CLR_INVALID
;
869 dc
->backgroundColor
= color
;
870 GDI_ReleaseObj( hdc
);
875 /***********************************************************************
876 * SetTextColor (GDI32.@)
878 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
881 DC
* dc
= DC_GetDCPtr( hdc
);
883 if (!dc
) return CLR_INVALID
;
884 oldColor
= dc
->textColor
;
885 if (dc
->funcs
->pSetTextColor
)
887 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
888 if (color
== CLR_INVALID
) /* don't change it */
891 oldColor
= CLR_INVALID
;
894 dc
->textColor
= color
;
895 GDI_ReleaseObj( hdc
);
900 /***********************************************************************
901 * SetTextAlign (GDI32.@)
903 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
906 DC
*dc
= DC_GetDCPtr( hdc
);
908 if (dc
->funcs
->pSetTextAlign
)
909 prevAlign
= dc
->funcs
->pSetTextAlign(dc
->physDev
, align
);
911 prevAlign
= dc
->textAlign
;
912 dc
->textAlign
= align
;
914 GDI_ReleaseObj( hdc
);
918 /***********************************************************************
919 * GetDCOrgEx (GDI32.@)
921 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
925 if (!lpp
) return FALSE
;
926 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
929 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
930 GDI_ReleaseObj( hDC
);
935 /***********************************************************************
938 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
941 HDC hdc
= HDC_32( hdc16
);
942 DC
*dc
= DC_GetDCPtr( hdc
);
944 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
945 GDI_ReleaseObj( hdc
);
950 /***********************************************************************
951 * SetGraphicsMode (GDI32.@)
953 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
956 DC
*dc
= DC_GetDCPtr( hdc
);
958 /* One would think that setting the graphics mode to GM_COMPATIBLE
959 * would also reset the world transformation matrix to the unity
960 * matrix. However, in Windows, this is not the case. This doesn't
961 * make a lot of sense to me, but that's the way it is.
964 if ((mode
> 0) && (mode
<= GM_LAST
))
966 ret
= dc
->GraphicsMode
;
967 dc
->GraphicsMode
= mode
;
969 GDI_ReleaseObj( hdc
);
974 /***********************************************************************
975 * SetArcDirection (GDI32.@)
977 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
980 INT nOldDirection
= 0;
982 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
984 SetLastError(ERROR_INVALID_PARAMETER
);
988 if ((dc
= DC_GetDCPtr( hdc
)))
990 nOldDirection
= dc
->ArcDirection
;
991 dc
->ArcDirection
= nDirection
;
992 GDI_ReleaseObj( hdc
);
994 return nOldDirection
;
998 /***********************************************************************
999 * GetWorldTransform (GDI32.@)
1001 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1004 if (!xform
) return FALSE
;
1005 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1006 *xform
= dc
->xformWorld2Wnd
;
1007 GDI_ReleaseObj( hdc
);
1012 /***********************************************************************
1013 * GetTransform (GDI32.@)
1015 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1017 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1018 ERR("stub: don't know what to do for code %lx\n", unknown
);
1023 /***********************************************************************
1024 * SetWorldTransform (GDI32.@)
1026 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1029 DC
*dc
= DC_GetDCPtr( hdc
);
1031 if (!dc
) return FALSE
;
1032 if (!xform
) goto done
;
1034 /* Check that graphics mode is GM_ADVANCED */
1035 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1037 if (dc
->funcs
->pSetWorldTransform
)
1039 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1040 if (!ret
) goto done
;
1043 dc
->xformWorld2Wnd
= *xform
;
1044 DC_UpdateXforms( dc
);
1047 GDI_ReleaseObj( hdc
);
1052 /****************************************************************************
1053 * ModifyWorldTransform [GDI32.@]
1054 * Modifies the world transformation for a device context.
1057 * hdc [I] Handle to device context
1058 * xform [I] XFORM structure that will be used to modify the world
1060 * iMode [I] Specifies in what way to modify the world transformation
1063 * Resets the world transformation to the identity matrix.
1064 * The parameter xform is ignored.
1066 * Multiplies xform into the world transformation matrix from
1069 * Multiplies xform into the world transformation matrix from
1074 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1078 DC
*dc
= DC_GetDCPtr( hdc
);
1080 /* Check for illegal parameters */
1081 if (!dc
) return FALSE
;
1082 if (!xform
) goto done
;
1084 /* Check that graphics mode is GM_ADVANCED */
1085 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1087 if (dc
->funcs
->pModifyWorldTransform
)
1089 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1090 if (!ret
) goto done
;
1096 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1097 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1098 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1099 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1100 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1101 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1103 case MWT_LEFTMULTIPLY
:
1104 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1105 &dc
->xformWorld2Wnd
);
1107 case MWT_RIGHTMULTIPLY
:
1108 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1115 DC_UpdateXforms( dc
);
1118 GDI_ReleaseObj( hdc
);
1123 /****************************************************************************
1124 * CombineTransform [GDI32.@]
1125 * Combines two transformation matrices.
1128 * xformResult [O] Stores the result of combining the two matrices
1129 * xform1 [I] Specifies the first matrix to apply
1130 * xform2 [I] Specifies the second matrix to apply
1133 * The same matrix can be passed in for more than one of the parameters.
1137 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1138 const XFORM
*xform2
)
1142 /* Check for illegal parameters */
1143 if (!xformResult
|| !xform1
|| !xform2
)
1146 /* Create the result in a temporary XFORM, since xformResult may be
1147 * equal to xform1 or xform2 */
1148 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1149 xform1
->eM12
* xform2
->eM21
;
1150 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1151 xform1
->eM12
* xform2
->eM22
;
1152 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1153 xform1
->eM22
* xform2
->eM21
;
1154 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1155 xform1
->eM22
* xform2
->eM22
;
1156 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1157 xform1
->eDy
* xform2
->eM21
+
1159 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1160 xform1
->eDy
* xform2
->eM22
+
1163 /* Copy the result to xformResult */
1164 *xformResult
= xformTemp
;
1170 /***********************************************************************
1171 * SetDCHook (GDI32.@)
1173 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1175 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1177 DC
*dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
);
1179 if (!dc
) return FALSE
;
1181 if (!(dc
->flags
& DC_SAVED
))
1183 dc
->dwHookData
= dwHookData
;
1184 dc
->hookThunk
= hookProc
;
1186 GDI_ReleaseObj( hdc
);
1191 /* relay function to call the 16-bit DC hook proc */
1192 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc16
, WORD code
, DWORD data
, LPARAM lParam
)
1196 FARPROC16 proc
= NULL
;
1197 HDC hdc
= HDC_32( hdc16
);
1198 DC
*dc
= DC_GetDCPtr( hdc
);
1200 if (!dc
) return FALSE
;
1201 proc
= dc
->hookProc
;
1202 GDI_ReleaseObj( hdc
);
1203 if (!proc
) return FALSE
;
1206 args
[3] = HIWORD(data
);
1207 args
[2] = LOWORD(data
);
1208 args
[1] = HIWORD(lParam
);
1209 args
[0] = LOWORD(lParam
);
1210 WOWCallback16Ex( (DWORD
)proc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1214 /***********************************************************************
1215 * SetDCHook (GDI.190)
1217 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1219 HDC hdc
= HDC_32( hdc16
);
1220 DC
*dc
= DC_GetDCPtr( hdc
);
1221 if (!dc
) return FALSE
;
1223 dc
->hookProc
= hookProc
;
1224 GDI_ReleaseObj( hdc
);
1225 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1229 /***********************************************************************
1230 * GetDCHook (GDI.191)
1232 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1234 HDC hdc
= HDC_32( hdc16
);
1235 DC
*dc
= DC_GetDCPtr( hdc
);
1239 *phookProc
= dc
->hookProc
;
1240 ret
= dc
->dwHookData
;
1241 GDI_ReleaseObj( hdc
);
1246 /***********************************************************************
1247 * SetHookFlags (GDI.192)
1249 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1251 HDC hdc
= HDC_32( hdc16
);
1252 DC
*dc
= DC_GetDCPtr( hdc
);
1256 WORD wRet
= dc
->flags
& DC_DIRTY
;
1258 /* "Undocumented Windows" info is slightly confusing.
1261 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1263 if( flags
& DCHF_INVALIDATEVISRGN
)
1264 dc
->flags
|= DC_DIRTY
;
1265 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1266 dc
->flags
&= ~DC_DIRTY
;
1267 GDI_ReleaseObj( hdc
);
1273 /***********************************************************************
1274 * SetICMMode (GDI32.@)
1276 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1278 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1279 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1280 if (iEnableICM
== ICM_ON
) return 0;
1281 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1285 /***********************************************************************
1286 * GetDeviceGammaRamp (GDI32.@)
1288 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1291 DC
*dc
= DC_GetDCPtr( hDC
);
1295 if (dc
->funcs
->pGetDeviceGammaRamp
)
1296 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1297 GDI_ReleaseObj( hDC
);
1302 /***********************************************************************
1303 * SetDeviceGammaRamp (GDI32.@)
1305 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1308 DC
*dc
= DC_GetDCPtr( hDC
);
1312 if (dc
->funcs
->pSetDeviceGammaRamp
)
1313 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1314 GDI_ReleaseObj( hDC
);
1319 /***********************************************************************
1320 * GetColorSpace (GDI32.@)
1322 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1324 /*FIXME Need to to whatever GetColorSpace actually does */
1328 /***********************************************************************
1329 * CreateColorSpaceA (GDI32.@)
1331 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1337 /***********************************************************************
1338 * CreateColorSpaceW (GDI32.@)
1340 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1346 /***********************************************************************
1347 * DeleteColorSpace (GDI32.@)
1349 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1356 /***********************************************************************
1357 * SetColorSpace (GDI32.@)
1359 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1366 /***********************************************************************
1367 * GetBoundsRect (GDI.194)
1369 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1371 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1374 /***********************************************************************
1375 * GetBoundsRect (GDI32.@)
1377 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1379 FIXME("(): stub\n");
1380 return DCB_RESET
; /* bounding rectangle always empty */
1383 /***********************************************************************
1384 * SetBoundsRect (GDI.193)
1386 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1388 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1389 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1391 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1394 /***********************************************************************
1395 * SetBoundsRect (GDI32.@)
1397 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1399 FIXME("(): stub\n");
1400 return DCB_DISABLE
; /* bounding rectangle always empty */
1404 /***********************************************************************
1405 * GetRelAbs (GDI32.@)
1407 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1410 DC
*dc
= DC_GetDCPtr( hdc
);
1411 if (dc
) ret
= dc
->relAbsMode
;
1412 GDI_ReleaseObj( hdc
);
1416 /***********************************************************************
1417 * GetLayout (GDI32.@)
1419 * Gets left->right or right->left text layout flags of a dc.
1420 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1423 DWORD WINAPI
GetLayout(HDC hdc
)
1425 FIXME("(%p): stub\n", hdc
);
1426 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1430 /***********************************************************************
1431 * SetLayout (GDI32.@)
1433 * Sets left->right or right->left text layout flags of a dc.
1434 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1437 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1439 FIXME("(%p,%08lx): stub\n", hdc
, layout
);
1440 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1444 /***********************************************************************
1445 * SetDCBrushColor (GDI32.@)
1447 * Sets the current device context (DC) brush color to the specified
1448 * color value. If the device cannot represent the specified color
1449 * value, the color is set to the nearest physical color.
1452 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1454 FIXME("(%p, %08lx): stub\n", hdc
, crColor
);
1455 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1459 /***********************************************************************
1460 * SetVirtualResolution (GDI32.@)
1462 * Undocumented on msdn. Called when PowerPoint XP saves a file.
1464 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
1466 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);