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"
35 #include "gdi_private.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
;
81 dc
->hPen
= GetStockObject( BLACK_PEN
);
82 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
83 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
86 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
88 dc
->ROPmode
= R2_COPYPEN
;
89 dc
->polyFillMode
= ALTERNATE
;
90 dc
->stretchBltMode
= BLACKONWHITE
;
91 dc
->relAbsMode
= ABSOLUTE
;
92 dc
->backgroundMode
= OPAQUE
;
93 dc
->backgroundColor
= RGB( 255, 255, 255 );
94 dc
->dcBrushColor
= RGB( 255, 255, 255 );
95 dc
->dcPenColor
= RGB( 0, 0, 0 );
96 dc
->textColor
= RGB( 0, 0, 0 );
99 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
103 dc
->MapMode
= MM_TEXT
;
104 dc
->GraphicsMode
= GM_COMPATIBLE
;
105 dc
->pAbortProc
= NULL
;
108 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
109 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
110 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
111 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
112 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
113 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
114 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
115 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
116 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
117 dc
->vport2WorldValid
= TRUE
;
118 dc
->BoundsRect
.left
= 0;
119 dc
->BoundsRect
.top
= 0;
120 dc
->BoundsRect
.right
= 0;
121 dc
->BoundsRect
.bottom
= 0;
122 PATH_InitGdiPath(&dc
->path
);
128 /***********************************************************************
131 DC
*DC_GetDCPtr( HDC hdc
)
133 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
134 if (!ptr
) return NULL
;
135 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
136 (GDIMAGIC(ptr
->wMagic
) == MEMORY_DC_MAGIC
) ||
137 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
138 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
140 GDI_ReleaseObj( hdc
);
141 SetLastError( ERROR_INVALID_HANDLE
);
145 /***********************************************************************
148 * Retrieve a DC ptr while making sure the visRgn is updated.
149 * This function may call up to USER so the GDI lock should _not_
150 * be held when calling it.
152 DC
*DC_GetDCUpdate( HDC hdc
)
154 DC
*dc
= DC_GetDCPtr( hdc
);
155 if (!dc
) return NULL
;
156 while (dc
->flags
& DC_DIRTY
)
158 DCHOOKPROC proc
= dc
->hookThunk
;
159 dc
->flags
&= ~DC_DIRTY
;
162 DWORD data
= dc
->dwHookData
;
163 GDI_ReleaseObj( hdc
);
164 proc( HDC_16(hdc
), DCHC_INVALIDVISRGN
, data
, 0 );
165 if (!(dc
= DC_GetDCPtr( hdc
))) break;
166 /* otherwise restart the loop in case it became dirty again in the meantime */
173 /***********************************************************************
176 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
178 GDI_ReleaseObj( handle
);
179 return DeleteDC( handle
);
183 /***********************************************************************
186 * Setup device-specific DC values for a newly created DC.
188 void DC_InitDC( DC
* dc
)
190 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
191 SetTextColor( dc
->hSelf
, dc
->textColor
);
192 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
193 SelectObject( dc
->hSelf
, dc
->hPen
);
194 SelectObject( dc
->hSelf
, dc
->hBrush
);
195 SelectObject( dc
->hSelf
, dc
->hFont
);
196 CLIPPING_UpdateGCRegion( dc
);
200 /***********************************************************************
203 * Computes the inverse of the transformation xformSrc and stores it to
204 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
207 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
211 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
212 xformSrc
->eM12
*xformSrc
->eM21
;
213 if (determinant
> -1e-12 && determinant
< 1e-12)
216 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
217 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
218 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
219 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
220 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
221 xformSrc
->eDy
* xformDest
->eM21
;
222 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
223 xformSrc
->eDy
* xformDest
->eM22
;
229 /***********************************************************************
232 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
233 * fields of the specified DC by creating a transformation that
234 * represents the current mapping mode and combining it with the DC's
235 * world transform. This function should be called whenever the
236 * parameters associated with the mapping mode (window and viewport
237 * extents and origins) or the world transform change.
239 void DC_UpdateXforms( DC
*dc
)
241 XFORM xformWnd2Vport
, oldworld2vport
;
242 FLOAT scaleX
, scaleY
;
244 /* Construct a transformation to do the window-to-viewport conversion */
245 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
246 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
247 xformWnd2Vport
.eM11
= scaleX
;
248 xformWnd2Vport
.eM12
= 0.0;
249 xformWnd2Vport
.eM21
= 0.0;
250 xformWnd2Vport
.eM22
= scaleY
;
251 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
252 scaleX
* (FLOAT
)dc
->wndOrgX
;
253 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
254 scaleY
* (FLOAT
)dc
->wndOrgY
;
256 oldworld2vport
= dc
->xformWorld2Vport
;
257 /* Combine with the world transformation */
258 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
261 /* Create inverse of world-to-viewport transformation */
262 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
263 &dc
->xformVport2World
);
265 /* Reselect the font and pen back into the dc so that the size
267 if(memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)))
269 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
270 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_PEN
));
275 /***********************************************************************
276 * GetDCState (Not a Windows API)
278 HDC WINAPI
GetDCState( HDC hdc
)
283 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
284 if (!(newdc
= GDI_AllocObject( sizeof(DC
), GDIMAGIC(dc
->header
.wMagic
), &handle
, &dc_funcs
)))
286 GDI_ReleaseObj( hdc
);
289 TRACE("(%p): returning %p\n", hdc
, handle
);
291 newdc
->flags
= dc
->flags
| DC_SAVED
;
292 newdc
->hPen
= dc
->hPen
;
293 newdc
->hBrush
= dc
->hBrush
;
294 newdc
->hFont
= dc
->hFont
;
295 newdc
->hBitmap
= dc
->hBitmap
;
296 newdc
->hDevice
= dc
->hDevice
;
297 newdc
->hPalette
= dc
->hPalette
;
298 newdc
->ROPmode
= dc
->ROPmode
;
299 newdc
->polyFillMode
= dc
->polyFillMode
;
300 newdc
->stretchBltMode
= dc
->stretchBltMode
;
301 newdc
->relAbsMode
= dc
->relAbsMode
;
302 newdc
->backgroundMode
= dc
->backgroundMode
;
303 newdc
->backgroundColor
= dc
->backgroundColor
;
304 newdc
->textColor
= dc
->textColor
;
305 newdc
->dcBrushColor
= dc
->dcBrushColor
;
306 newdc
->dcPenColor
= dc
->dcPenColor
;
307 newdc
->brushOrgX
= dc
->brushOrgX
;
308 newdc
->brushOrgY
= dc
->brushOrgY
;
309 newdc
->textAlign
= dc
->textAlign
;
310 newdc
->charExtra
= dc
->charExtra
;
311 newdc
->breakExtra
= dc
->breakExtra
;
312 newdc
->breakRem
= dc
->breakRem
;
313 newdc
->MapMode
= dc
->MapMode
;
314 newdc
->GraphicsMode
= dc
->GraphicsMode
;
315 newdc
->CursPosX
= dc
->CursPosX
;
316 newdc
->CursPosY
= dc
->CursPosY
;
317 newdc
->ArcDirection
= dc
->ArcDirection
;
318 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
319 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
320 newdc
->xformVport2World
= dc
->xformVport2World
;
321 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
322 newdc
->wndOrgX
= dc
->wndOrgX
;
323 newdc
->wndOrgY
= dc
->wndOrgY
;
324 newdc
->wndExtX
= dc
->wndExtX
;
325 newdc
->wndExtY
= dc
->wndExtY
;
326 newdc
->vportOrgX
= dc
->vportOrgX
;
327 newdc
->vportOrgY
= dc
->vportOrgY
;
328 newdc
->vportExtX
= dc
->vportExtX
;
329 newdc
->vportExtY
= dc
->vportExtY
;
330 newdc
->BoundsRect
= dc
->BoundsRect
;
332 newdc
->hSelf
= (HDC
)handle
;
333 newdc
->saveLevel
= 0;
335 PATH_InitGdiPath( &newdc
->path
);
337 newdc
->pAbortProc
= NULL
;
338 newdc
->hookThunk
= NULL
;
341 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
346 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
347 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
353 newdc
->gdiFont
= dc
->gdiFont
;
357 GDI_ReleaseObj( handle
);
358 GDI_ReleaseObj( hdc
);
363 /***********************************************************************
364 * SetDCState (Not a Windows API)
366 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
370 if (!(dc
= DC_GetDCUpdate( hdc
))) return;
371 if (!(dcs
= DC_GetDCPtr( hdcs
)))
373 GDI_ReleaseObj( hdc
);
376 if (!dcs
->flags
& DC_SAVED
)
378 GDI_ReleaseObj( hdc
);
379 GDI_ReleaseObj( hdcs
);
382 TRACE("%p %p\n", hdc
, hdcs
);
384 dc
->flags
= dcs
->flags
& ~(DC_SAVED
| DC_DIRTY
);
385 dc
->hDevice
= dcs
->hDevice
;
386 dc
->ROPmode
= dcs
->ROPmode
;
387 dc
->polyFillMode
= dcs
->polyFillMode
;
388 dc
->stretchBltMode
= dcs
->stretchBltMode
;
389 dc
->relAbsMode
= dcs
->relAbsMode
;
390 dc
->backgroundMode
= dcs
->backgroundMode
;
391 dc
->backgroundColor
= dcs
->backgroundColor
;
392 dc
->textColor
= dcs
->textColor
;
393 dc
->dcBrushColor
= dcs
->dcBrushColor
;
394 dc
->dcPenColor
= dcs
->dcPenColor
;
395 dc
->brushOrgX
= dcs
->brushOrgX
;
396 dc
->brushOrgY
= dcs
->brushOrgY
;
397 dc
->textAlign
= dcs
->textAlign
;
398 dc
->charExtra
= dcs
->charExtra
;
399 dc
->breakExtra
= dcs
->breakExtra
;
400 dc
->breakRem
= dcs
->breakRem
;
401 dc
->MapMode
= dcs
->MapMode
;
402 dc
->GraphicsMode
= dcs
->GraphicsMode
;
403 dc
->CursPosX
= dcs
->CursPosX
;
404 dc
->CursPosY
= dcs
->CursPosY
;
405 dc
->ArcDirection
= dcs
->ArcDirection
;
406 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
407 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
408 dc
->xformVport2World
= dcs
->xformVport2World
;
409 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
410 dc
->BoundsRect
= dcs
->BoundsRect
;
412 dc
->wndOrgX
= dcs
->wndOrgX
;
413 dc
->wndOrgY
= dcs
->wndOrgY
;
414 dc
->wndExtX
= dcs
->wndExtX
;
415 dc
->wndExtY
= dcs
->wndExtY
;
416 dc
->vportOrgX
= dcs
->vportOrgX
;
417 dc
->vportOrgY
= dcs
->vportOrgY
;
418 dc
->vportExtX
= dcs
->vportExtX
;
419 dc
->vportExtY
= dcs
->vportExtY
;
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
);
603 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
605 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
606 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
608 if (dc
->funcs
->pCreateDC
&&
609 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
611 WARN("creation aborted by device\n" );
612 GDI_FreeObject( dc
->hSelf
, dc
);
613 DRIVER_release_driver( funcs
);
617 dc
->hVisRgn
= CreateRectRgn( 0, 0, GetDeviceCaps( hdc
, HORZRES
),
618 GetDeviceCaps( hdc
, VERTRES
) );
621 GDI_ReleaseObj( hdc
);
626 /***********************************************************************
627 * CreateDCA (GDI32.@)
629 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
630 const DEVMODEA
*initData
)
632 UNICODE_STRING driverW
, deviceW
, outputW
;
636 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
637 else driverW
.Buffer
= NULL
;
639 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
640 else deviceW
.Buffer
= NULL
;
642 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
643 else outputW
.Buffer
= NULL
;
645 if (initData
) initDataW
= GdiConvertToDevmodeW(initData
);
646 else initDataW
= NULL
;
648 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
650 RtlFreeUnicodeString(&driverW
);
651 RtlFreeUnicodeString(&deviceW
);
652 RtlFreeUnicodeString(&outputW
);
653 if (initDataW
) HeapFree(GetProcessHeap(), 0, initDataW
);
658 /***********************************************************************
659 * CreateICA (GDI32.@)
661 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
662 const DEVMODEA
* initData
)
664 /* Nothing special yet for ICs */
665 return CreateDCA( driver
, device
, output
, initData
);
669 /***********************************************************************
670 * CreateICW (GDI32.@)
672 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
673 const DEVMODEW
* initData
)
675 /* Nothing special yet for ICs */
676 return CreateDCW( driver
, device
, output
, initData
);
680 /***********************************************************************
681 * CreateCompatibleDC (GDI32.@)
683 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
686 const DC_FUNCTIONS
*funcs
;
691 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
693 funcs
= origDC
->funcs
;
694 physDev
= origDC
->physDev
;
695 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
696 funcs
= DRIVER_get_driver( funcs
);
700 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
701 funcs
= DRIVER_load_driver( displayW
);
705 if (!funcs
) return 0;
707 if (!(dc
= DC_AllocDC( funcs
, MEMORY_DC_MAGIC
)))
709 DRIVER_release_driver( funcs
);
713 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
715 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
717 /* Copy the driver-specific physical device info into
718 * the new DC. The driver may use this read-only info
719 * while creating the compatible DC below. */
720 dc
->physDev
= physDev
;
722 if (dc
->funcs
->pCreateDC
&&
723 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
725 WARN("creation aborted by device\n");
726 GDI_FreeObject( dc
->hSelf
, dc
);
727 DRIVER_release_driver( funcs
);
731 dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
734 GDI_ReleaseObj( dc
->hSelf
);
739 /***********************************************************************
742 BOOL WINAPI
DeleteDC( HDC hdc
)
744 const DC_FUNCTIONS
*funcs
= NULL
;
751 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
753 /* Call hook procedure to check whether is it OK to delete this DC */
756 DCHOOKPROC proc
= dc
->hookThunk
;
757 DWORD data
= dc
->dwHookData
;
758 GDI_ReleaseObj( hdc
);
759 if (!proc( HDC_16(hdc
), DCHC_DELETEDC
, data
, 0 )) return FALSE
;
760 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
763 while (dc
->saveLevel
)
766 HDC hdcs
= HDC_32(dc
->header
.hNext
);
767 if (!(dcs
= DC_GetDCPtr( hdcs
))) break;
768 dc
->header
.hNext
= dcs
->header
.hNext
;
770 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
771 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
772 PATH_DestroyGdiPath(&dcs
->path
);
773 GDI_FreeObject( hdcs
, dcs
);
776 if (!(dc
->flags
& DC_SAVED
))
778 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
779 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
780 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
781 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
783 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
787 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
788 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
789 PATH_DestroyGdiPath(&dc
->path
);
791 GDI_FreeObject( hdc
, dc
);
792 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
797 /***********************************************************************
800 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
805 if ((dc
= DC_GetDCPtr( hdc
)))
807 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
808 GDI_ReleaseObj( hdc
);
814 /***********************************************************************
817 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
822 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
823 else devmodeW
= NULL
;
825 ret
= ResetDCW(hdc
, devmodeW
);
827 if (devmodeW
) HeapFree(GetProcessHeap(), 0, devmodeW
);
832 /***********************************************************************
833 * GetDeviceCaps (GDI32.@)
835 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
840 if ((dc
= DC_GetDCPtr( hdc
)))
842 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
843 GDI_ReleaseObj( hdc
);
849 /***********************************************************************
850 * GetBkColor (GDI32.@)
852 COLORREF WINAPI
GetBkColor( HDC hdc
)
855 DC
* dc
= DC_GetDCPtr( hdc
);
858 ret
= dc
->backgroundColor
;
859 GDI_ReleaseObj( hdc
);
865 /***********************************************************************
866 * SetBkColor (GDI32.@)
868 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
871 DC
* dc
= DC_GetDCPtr( hdc
);
873 TRACE("hdc=%p color=0x%08lx\n", hdc
, color
);
875 if (!dc
) return CLR_INVALID
;
876 oldColor
= dc
->backgroundColor
;
877 if (dc
->funcs
->pSetBkColor
)
879 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
880 if (color
== CLR_INVALID
) /* don't change it */
883 oldColor
= CLR_INVALID
;
886 dc
->backgroundColor
= color
;
887 GDI_ReleaseObj( hdc
);
892 /***********************************************************************
893 * GetTextColor (GDI32.@)
895 COLORREF WINAPI
GetTextColor( HDC hdc
)
898 DC
* dc
= DC_GetDCPtr( hdc
);
902 GDI_ReleaseObj( hdc
);
908 /***********************************************************************
909 * SetTextColor (GDI32.@)
911 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
914 DC
* dc
= DC_GetDCPtr( hdc
);
916 TRACE(" hdc=%p color=0x%08lx\n", hdc
, color
);
918 if (!dc
) return CLR_INVALID
;
919 oldColor
= dc
->textColor
;
920 if (dc
->funcs
->pSetTextColor
)
922 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
923 if (color
== CLR_INVALID
) /* don't change it */
926 oldColor
= CLR_INVALID
;
929 dc
->textColor
= color
;
930 GDI_ReleaseObj( hdc
);
935 /***********************************************************************
936 * GetTextAlign (GDI32.@)
938 UINT WINAPI
GetTextAlign( HDC hdc
)
941 DC
* dc
= DC_GetDCPtr( hdc
);
945 GDI_ReleaseObj( hdc
);
951 /***********************************************************************
952 * SetTextAlign (GDI32.@)
954 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
957 DC
*dc
= DC_GetDCPtr( hdc
);
959 TRACE("hdc=%p align=%d\n", hdc
, align
);
962 if (dc
->funcs
->pSetTextAlign
)
963 prevAlign
= dc
->funcs
->pSetTextAlign(dc
->physDev
, align
);
965 prevAlign
= dc
->textAlign
;
966 dc
->textAlign
= align
;
968 GDI_ReleaseObj( hdc
);
972 /***********************************************************************
973 * GetDCOrgEx (GDI32.@)
975 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
979 if (!lpp
) return FALSE
;
980 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
983 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
984 GDI_ReleaseObj( hDC
);
989 /***********************************************************************
992 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
995 HDC hdc
= HDC_32( hdc16
);
996 DC
*dc
= DC_GetDCPtr( hdc
);
998 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
999 GDI_ReleaseObj( hdc
);
1004 /***********************************************************************
1005 * GetGraphicsMode (GDI32.@)
1007 INT WINAPI
GetGraphicsMode( HDC hdc
)
1010 DC
* dc
= DC_GetDCPtr( hdc
);
1013 ret
= dc
->GraphicsMode
;
1014 GDI_ReleaseObj( hdc
);
1020 /***********************************************************************
1021 * SetGraphicsMode (GDI32.@)
1023 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1026 DC
*dc
= DC_GetDCPtr( hdc
);
1028 /* One would think that setting the graphics mode to GM_COMPATIBLE
1029 * would also reset the world transformation matrix to the unity
1030 * matrix. However, in Windows, this is not the case. This doesn't
1031 * make a lot of sense to me, but that's the way it is.
1034 if ((mode
> 0) && (mode
<= GM_LAST
))
1036 ret
= dc
->GraphicsMode
;
1037 dc
->GraphicsMode
= mode
;
1039 GDI_ReleaseObj( hdc
);
1044 /***********************************************************************
1045 * GetArcDirection (GDI32.@)
1047 INT WINAPI
GetArcDirection( HDC hdc
)
1050 DC
* dc
= DC_GetDCPtr( hdc
);
1053 ret
= dc
->ArcDirection
;
1054 GDI_ReleaseObj( hdc
);
1060 /***********************************************************************
1061 * SetArcDirection (GDI32.@)
1063 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1066 INT nOldDirection
= 0;
1068 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1070 SetLastError(ERROR_INVALID_PARAMETER
);
1074 if ((dc
= DC_GetDCPtr( hdc
)))
1076 if (dc
->funcs
->pSetArcDirection
)
1078 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1080 nOldDirection
= dc
->ArcDirection
;
1081 dc
->ArcDirection
= nDirection
;
1082 GDI_ReleaseObj( hdc
);
1084 return nOldDirection
;
1088 /***********************************************************************
1089 * GetWorldTransform (GDI32.@)
1091 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1094 if (!xform
) return FALSE
;
1095 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1096 *xform
= dc
->xformWorld2Wnd
;
1097 GDI_ReleaseObj( hdc
);
1102 /***********************************************************************
1103 * GetTransform (GDI32.@)
1105 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1107 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1108 FIXME("stub: don't know what to do for code %lx\n", unknown
);
1113 /***********************************************************************
1114 * SetWorldTransform (GDI32.@)
1116 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1119 DC
*dc
= DC_GetDCPtr( hdc
);
1121 if (!dc
) return FALSE
;
1122 if (!xform
) goto done
;
1124 /* Check that graphics mode is GM_ADVANCED */
1125 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1127 if (dc
->funcs
->pSetWorldTransform
)
1129 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1130 if (!ret
) goto done
;
1133 dc
->xformWorld2Wnd
= *xform
;
1134 DC_UpdateXforms( dc
);
1137 GDI_ReleaseObj( hdc
);
1142 /****************************************************************************
1143 * ModifyWorldTransform [GDI32.@]
1144 * Modifies the world transformation for a device context.
1147 * hdc [I] Handle to device context
1148 * xform [I] XFORM structure that will be used to modify the world
1150 * iMode [I] Specifies in what way to modify the world transformation
1153 * Resets the world transformation to the identity matrix.
1154 * The parameter xform is ignored.
1156 * Multiplies xform into the world transformation matrix from
1159 * Multiplies xform into the world transformation matrix from
1164 * Failure: FALSE. Use GetLastError() to determine the cause.
1166 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1170 DC
*dc
= DC_GetDCPtr( hdc
);
1172 /* Check for illegal parameters */
1173 if (!dc
) return FALSE
;
1174 if (!xform
) goto done
;
1176 /* Check that graphics mode is GM_ADVANCED */
1177 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1179 if (dc
->funcs
->pModifyWorldTransform
)
1181 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1182 if (!ret
) goto done
;
1188 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1189 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1190 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1191 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1192 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1193 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1195 case MWT_LEFTMULTIPLY
:
1196 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1197 &dc
->xformWorld2Wnd
);
1199 case MWT_RIGHTMULTIPLY
:
1200 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1207 DC_UpdateXforms( dc
);
1210 GDI_ReleaseObj( hdc
);
1215 /****************************************************************************
1216 * CombineTransform [GDI32.@]
1217 * Combines two transformation matrices.
1220 * xformResult [O] Stores the result of combining the two matrices
1221 * xform1 [I] Specifies the first matrix to apply
1222 * xform2 [I] Specifies the second matrix to apply
1225 * The same matrix can be passed in for more than one of the parameters.
1229 * Failure: FALSE. Use GetLastError() to determine the cause.
1231 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1232 const XFORM
*xform2
)
1236 /* Check for illegal parameters */
1237 if (!xformResult
|| !xform1
|| !xform2
)
1240 /* Create the result in a temporary XFORM, since xformResult may be
1241 * equal to xform1 or xform2 */
1242 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1243 xform1
->eM12
* xform2
->eM21
;
1244 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1245 xform1
->eM12
* xform2
->eM22
;
1246 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1247 xform1
->eM22
* xform2
->eM21
;
1248 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1249 xform1
->eM22
* xform2
->eM22
;
1250 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1251 xform1
->eDy
* xform2
->eM21
+
1253 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1254 xform1
->eDy
* xform2
->eM22
+
1257 /* Copy the result to xformResult */
1258 *xformResult
= xformTemp
;
1264 /***********************************************************************
1265 * SetDCHook (GDI32.@)
1267 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1269 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1271 DC
*dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
);
1273 if (!dc
) return FALSE
;
1275 if (!(dc
->flags
& DC_SAVED
))
1277 dc
->dwHookData
= dwHookData
;
1278 dc
->hookThunk
= hookProc
;
1280 GDI_ReleaseObj( hdc
);
1285 /* relay function to call the 16-bit DC hook proc */
1286 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc16
, WORD code
, DWORD data
, LPARAM lParam
)
1290 FARPROC16 proc
= NULL
;
1291 HDC hdc
= HDC_32( hdc16
);
1292 DC
*dc
= DC_GetDCPtr( hdc
);
1294 if (!dc
) return FALSE
;
1295 proc
= dc
->hookProc
;
1296 GDI_ReleaseObj( hdc
);
1297 if (!proc
) return FALSE
;
1300 args
[3] = HIWORD(data
);
1301 args
[2] = LOWORD(data
);
1302 args
[1] = HIWORD(lParam
);
1303 args
[0] = LOWORD(lParam
);
1304 WOWCallback16Ex( (DWORD
)proc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1308 /***********************************************************************
1309 * SetDCHook (GDI.190)
1311 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1313 HDC hdc
= HDC_32( hdc16
);
1314 DC
*dc
= DC_GetDCPtr( hdc
);
1315 if (!dc
) return FALSE
;
1317 dc
->hookProc
= hookProc
;
1318 GDI_ReleaseObj( hdc
);
1319 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1323 /***********************************************************************
1324 * GetDCHook (GDI.191)
1326 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1328 HDC hdc
= HDC_32( hdc16
);
1329 DC
*dc
= DC_GetDCPtr( hdc
);
1333 *phookProc
= dc
->hookProc
;
1334 ret
= dc
->dwHookData
;
1335 GDI_ReleaseObj( hdc
);
1340 /***********************************************************************
1341 * SetHookFlags (GDI.192)
1343 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1345 HDC hdc
= HDC_32( hdc16
);
1346 DC
*dc
= DC_GetDCPtr( hdc
);
1350 WORD wRet
= dc
->flags
& DC_DIRTY
;
1352 /* "Undocumented Windows" info is slightly confusing.
1355 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1357 if( flags
& DCHF_INVALIDATEVISRGN
)
1358 dc
->flags
|= DC_DIRTY
;
1359 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1360 dc
->flags
&= ~DC_DIRTY
;
1361 GDI_ReleaseObj( hdc
);
1367 /***********************************************************************
1368 * SetICMMode (GDI32.@)
1370 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1372 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1373 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1374 if (iEnableICM
== ICM_ON
) return 0;
1375 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1379 /***********************************************************************
1380 * GetDeviceGammaRamp (GDI32.@)
1382 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1385 DC
*dc
= DC_GetDCPtr( hDC
);
1389 if (dc
->funcs
->pGetDeviceGammaRamp
)
1390 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1391 GDI_ReleaseObj( hDC
);
1396 /***********************************************************************
1397 * SetDeviceGammaRamp (GDI32.@)
1399 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1402 DC
*dc
= DC_GetDCPtr( hDC
);
1406 if (dc
->funcs
->pSetDeviceGammaRamp
)
1407 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1408 GDI_ReleaseObj( hDC
);
1413 /***********************************************************************
1414 * GetColorSpace (GDI32.@)
1416 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1418 /*FIXME Need to to whatever GetColorSpace actually does */
1422 /***********************************************************************
1423 * CreateColorSpaceA (GDI32.@)
1425 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1431 /***********************************************************************
1432 * CreateColorSpaceW (GDI32.@)
1434 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1440 /***********************************************************************
1441 * DeleteColorSpace (GDI32.@)
1443 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1450 /***********************************************************************
1451 * SetColorSpace (GDI32.@)
1453 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1460 /***********************************************************************
1461 * GetBoundsRect (GDI32.@)
1463 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1466 DC
*dc
= DC_GetDCPtr( hdc
);
1468 if ( !dc
) return 0;
1470 if (rect
) *rect
= dc
->BoundsRect
;
1472 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1474 if (flags
& DCB_RESET
)
1476 dc
->BoundsRect
.left
= 0;
1477 dc
->BoundsRect
.top
= 0;
1478 dc
->BoundsRect
.right
= 0;
1479 dc
->BoundsRect
.bottom
= 0;
1480 dc
->flags
&= ~DC_BOUNDS_SET
;
1482 GDI_ReleaseObj( hdc
);
1487 /***********************************************************************
1488 * SetBoundsRect (GDI32.@)
1490 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1495 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1496 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1498 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1499 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1501 if (flags
& DCB_RESET
)
1503 dc
->BoundsRect
.left
= 0;
1504 dc
->BoundsRect
.top
= 0;
1505 dc
->BoundsRect
.right
= 0;
1506 dc
->BoundsRect
.bottom
= 0;
1507 dc
->flags
&= ~DC_BOUNDS_SET
;
1510 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1512 if (dc
->flags
& DC_BOUNDS_SET
)
1514 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1515 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1516 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1517 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1521 dc
->BoundsRect
= *rect
;
1522 dc
->flags
|= DC_BOUNDS_SET
;
1526 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1527 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1529 GDI_ReleaseObj( hdc
);
1534 /***********************************************************************
1535 * GetRelAbs (GDI32.@)
1537 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1540 DC
*dc
= DC_GetDCPtr( hdc
);
1541 if (dc
) ret
= dc
->relAbsMode
;
1542 GDI_ReleaseObj( hdc
);
1549 /***********************************************************************
1550 * GetBkMode (GDI32.@)
1552 INT WINAPI
GetBkMode( HDC hdc
)
1555 DC
* dc
= DC_GetDCPtr( hdc
);
1558 ret
= dc
->backgroundMode
;
1559 GDI_ReleaseObj( hdc
);
1565 /***********************************************************************
1566 * SetBkMode (GDI32.@)
1568 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1572 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1574 SetLastError(ERROR_INVALID_PARAMETER
);
1577 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1578 if (dc
->funcs
->pSetBkMode
)
1579 ret
= dc
->funcs
->pSetBkMode( dc
->physDev
, mode
);
1582 ret
= dc
->backgroundMode
;
1583 dc
->backgroundMode
= mode
;
1585 GDI_ReleaseObj( hdc
);
1590 /***********************************************************************
1593 INT WINAPI
GetROP2( HDC hdc
)
1596 DC
* dc
= DC_GetDCPtr( hdc
);
1600 GDI_ReleaseObj( hdc
);
1606 /***********************************************************************
1609 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1613 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1615 SetLastError(ERROR_INVALID_PARAMETER
);
1618 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1619 if (dc
->funcs
->pSetROP2
)
1620 ret
= dc
->funcs
->pSetROP2( dc
->physDev
, mode
);
1626 GDI_ReleaseObj( hdc
);
1631 /***********************************************************************
1632 * SetRelAbs (GDI32.@)
1634 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1638 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1640 SetLastError(ERROR_INVALID_PARAMETER
);
1643 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1644 if (dc
->funcs
->pSetRelAbs
)
1645 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1648 ret
= dc
->relAbsMode
;
1649 dc
->relAbsMode
= mode
;
1651 GDI_ReleaseObj( hdc
);
1656 /***********************************************************************
1657 * GetPolyFillMode (GDI32.@)
1659 INT WINAPI
GetPolyFillMode( HDC hdc
)
1662 DC
* dc
= DC_GetDCPtr( hdc
);
1665 ret
= dc
->polyFillMode
;
1666 GDI_ReleaseObj( hdc
);
1672 /***********************************************************************
1673 * SetPolyFillMode (GDI32.@)
1675 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1679 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1681 SetLastError(ERROR_INVALID_PARAMETER
);
1684 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1685 if (dc
->funcs
->pSetPolyFillMode
)
1686 ret
= dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
);
1689 ret
= dc
->polyFillMode
;
1690 dc
->polyFillMode
= mode
;
1692 GDI_ReleaseObj( hdc
);
1697 /***********************************************************************
1698 * GetStretchBltMode (GDI32.@)
1700 INT WINAPI
GetStretchBltMode( HDC hdc
)
1703 DC
* dc
= DC_GetDCPtr( hdc
);
1706 ret
= dc
->stretchBltMode
;
1707 GDI_ReleaseObj( hdc
);
1713 /***********************************************************************
1714 * SetStretchBltMode (GDI32.@)
1716 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1720 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1722 SetLastError(ERROR_INVALID_PARAMETER
);
1725 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1726 if (dc
->funcs
->pSetStretchBltMode
)
1727 ret
= dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
);
1730 ret
= dc
->stretchBltMode
;
1731 dc
->stretchBltMode
= mode
;
1733 GDI_ReleaseObj( hdc
);
1738 /***********************************************************************
1739 * GetMapMode (GDI32.@)
1741 INT WINAPI
GetMapMode( HDC hdc
)
1744 DC
* dc
= DC_GetDCPtr( hdc
);
1748 GDI_ReleaseObj( hdc
);
1754 /***********************************************************************
1755 * GetBrushOrgEx (GDI32.@)
1757 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1759 DC
* dc
= DC_GetDCPtr( hdc
);
1760 if (!dc
) return FALSE
;
1761 pt
->x
= dc
->brushOrgX
;
1762 pt
->y
= dc
->brushOrgY
;
1763 GDI_ReleaseObj( hdc
);
1768 /***********************************************************************
1769 * GetCurrentPositionEx (GDI32.@)
1771 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1773 DC
* dc
= DC_GetDCPtr( hdc
);
1774 if (!dc
) return FALSE
;
1775 pt
->x
= dc
->CursPosX
;
1776 pt
->y
= dc
->CursPosY
;
1777 GDI_ReleaseObj( hdc
);
1782 /***********************************************************************
1783 * GetViewportExtEx (GDI32.@)
1785 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1787 DC
* dc
= DC_GetDCPtr( hdc
);
1788 if (!dc
) return FALSE
;
1789 size
->cx
= dc
->vportExtX
;
1790 size
->cy
= dc
->vportExtY
;
1791 GDI_ReleaseObj( hdc
);
1796 /***********************************************************************
1797 * GetViewportOrgEx (GDI32.@)
1799 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1801 DC
* dc
= DC_GetDCPtr( hdc
);
1802 if (!dc
) return FALSE
;
1803 pt
->x
= dc
->vportOrgX
;
1804 pt
->y
= dc
->vportOrgY
;
1805 GDI_ReleaseObj( hdc
);
1810 /***********************************************************************
1811 * GetWindowExtEx (GDI32.@)
1813 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1815 DC
* dc
= DC_GetDCPtr( hdc
);
1816 if (!dc
) return FALSE
;
1817 size
->cx
= dc
->wndExtX
;
1818 size
->cy
= dc
->wndExtY
;
1819 GDI_ReleaseObj( hdc
);
1824 /***********************************************************************
1825 * GetWindowOrgEx (GDI32.@)
1827 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1829 DC
* dc
= DC_GetDCPtr( hdc
);
1830 if (!dc
) return FALSE
;
1831 pt
->x
= dc
->wndOrgX
;
1832 pt
->y
= dc
->wndOrgY
;
1833 GDI_ReleaseObj( hdc
);
1838 /***********************************************************************
1839 * InquireVisRgn (GDI.131)
1841 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1844 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1847 ret
= HRGN_16(dc
->hVisRgn
);
1848 GDI_ReleaseObj( HDC_32(hdc
) );
1854 /***********************************************************************
1855 * GetClipRgn (GDI.173)
1857 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1860 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1863 ret
= HRGN_16(dc
->hClipRgn
);
1864 GDI_ReleaseObj( HDC_32(hdc
) );
1870 /***********************************************************************
1871 * GetLayout (GDI32.@)
1873 * Gets left->right or right->left text layout flags of a dc.
1874 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1877 DWORD WINAPI
GetLayout(HDC hdc
)
1879 FIXME("(%p): stub\n", hdc
);
1880 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1884 /***********************************************************************
1885 * SetLayout (GDI32.@)
1887 * Sets left->right or right->left text layout flags of a dc.
1888 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1891 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1893 FIXME("(%p,%08lx): stub\n", hdc
, layout
);
1894 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1898 /***********************************************************************
1899 * GetDCBrushColor (GDI32.@)
1901 * Retrieves the current brush color for the specified device
1905 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1908 COLORREF dcBrushColor
= CLR_INVALID
;
1910 TRACE("hdc(%p)\n", hdc
);
1912 dc
= DC_GetDCPtr( hdc
);
1915 dcBrushColor
= dc
->dcBrushColor
;
1916 GDI_ReleaseObj( hdc
);
1919 return dcBrushColor
;
1922 /***********************************************************************
1923 * SetDCBrushColor (GDI32.@)
1925 * Sets the current device context (DC) brush color to the specified
1926 * color value. If the device cannot represent the specified color
1927 * value, the color is set to the nearest physical color.
1930 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1933 COLORREF oldClr
= CLR_INVALID
;
1935 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
1937 dc
= DC_GetDCPtr( hdc
);
1940 if (dc
->funcs
->pSetDCBrushColor
)
1941 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
1942 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
1944 /* If DC_BRUSH is selected, update driver pen color */
1945 HBRUSH hBrush
= CreateSolidBrush( crColor
);
1946 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
1947 DeleteObject( hBrush
);
1950 if (crColor
!= CLR_INVALID
)
1952 oldClr
= dc
->dcBrushColor
;
1953 dc
->dcBrushColor
= crColor
;
1956 GDI_ReleaseObj( hdc
);
1962 /***********************************************************************
1963 * GetDCPenColor (GDI32.@)
1965 * Retrieves the current pen color for the specified device
1969 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1972 COLORREF dcPenColor
= CLR_INVALID
;
1974 TRACE("hdc(%p)\n", hdc
);
1976 dc
= DC_GetDCPtr( hdc
);
1979 dcPenColor
= dc
->dcPenColor
;
1980 GDI_ReleaseObj( hdc
);
1986 /***********************************************************************
1987 * SetDCPenColor (GDI32.@)
1989 * Sets the current device context (DC) pen color to the specified
1990 * color value. If the device cannot represent the specified color
1991 * value, the color is set to the nearest physical color.
1994 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1997 COLORREF oldClr
= CLR_INVALID
;
1999 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
2001 dc
= DC_GetDCPtr( hdc
);
2004 if (dc
->funcs
->pSetDCPenColor
)
2005 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2006 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2008 /* If DC_PEN is selected, update the driver pen color */
2009 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2010 HPEN hPen
= CreatePenIndirect( &logpen
);
2011 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2012 DeleteObject( hPen
);
2015 if (crColor
!= CLR_INVALID
)
2017 oldClr
= dc
->dcPenColor
;
2018 dc
->dcPenColor
= crColor
;
2021 GDI_ReleaseObj( hdc
);
2027 /***********************************************************************
2028 * SetVirtualResolution (GDI32.@)
2030 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2032 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2034 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);