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 back into the dc so that the font size
267 if(memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)))
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
->ROPmode
= dc
->ROPmode
;
296 newdc
->polyFillMode
= dc
->polyFillMode
;
297 newdc
->stretchBltMode
= dc
->stretchBltMode
;
298 newdc
->relAbsMode
= dc
->relAbsMode
;
299 newdc
->backgroundMode
= dc
->backgroundMode
;
300 newdc
->backgroundColor
= dc
->backgroundColor
;
301 newdc
->textColor
= dc
->textColor
;
302 newdc
->dcBrushColor
= dc
->dcBrushColor
;
303 newdc
->dcPenColor
= dc
->dcPenColor
;
304 newdc
->brushOrgX
= dc
->brushOrgX
;
305 newdc
->brushOrgY
= dc
->brushOrgY
;
306 newdc
->textAlign
= dc
->textAlign
;
307 newdc
->charExtra
= dc
->charExtra
;
308 newdc
->breakExtra
= dc
->breakExtra
;
309 newdc
->breakRem
= dc
->breakRem
;
310 newdc
->MapMode
= dc
->MapMode
;
311 newdc
->GraphicsMode
= dc
->GraphicsMode
;
312 newdc
->CursPosX
= dc
->CursPosX
;
313 newdc
->CursPosY
= dc
->CursPosY
;
314 newdc
->ArcDirection
= dc
->ArcDirection
;
315 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
316 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
317 newdc
->xformVport2World
= dc
->xformVport2World
;
318 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
319 newdc
->wndOrgX
= dc
->wndOrgX
;
320 newdc
->wndOrgY
= dc
->wndOrgY
;
321 newdc
->wndExtX
= dc
->wndExtX
;
322 newdc
->wndExtY
= dc
->wndExtY
;
323 newdc
->vportOrgX
= dc
->vportOrgX
;
324 newdc
->vportOrgY
= dc
->vportOrgY
;
325 newdc
->vportExtX
= dc
->vportExtX
;
326 newdc
->vportExtY
= dc
->vportExtY
;
327 newdc
->BoundsRect
= dc
->BoundsRect
;
329 newdc
->hSelf
= (HDC
)handle
;
330 newdc
->saveLevel
= 0;
332 PATH_InitGdiPath( &newdc
->path
);
334 newdc
->pAbortProc
= NULL
;
335 newdc
->hookThunk
= NULL
;
338 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
343 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
344 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
350 newdc
->gdiFont
= dc
->gdiFont
;
354 GDI_ReleaseObj( handle
);
355 GDI_ReleaseObj( hdc
);
360 /***********************************************************************
361 * SetDCState (Not a Windows API)
363 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
367 if (!(dc
= DC_GetDCUpdate( hdc
))) return;
368 if (!(dcs
= DC_GetDCPtr( hdcs
)))
370 GDI_ReleaseObj( hdc
);
373 if (!dcs
->flags
& DC_SAVED
)
375 GDI_ReleaseObj( hdc
);
376 GDI_ReleaseObj( hdcs
);
379 TRACE("%p %p\n", hdc
, hdcs
);
381 dc
->flags
= dcs
->flags
& ~(DC_SAVED
| DC_DIRTY
);
382 dc
->hDevice
= dcs
->hDevice
;
383 dc
->ROPmode
= dcs
->ROPmode
;
384 dc
->polyFillMode
= dcs
->polyFillMode
;
385 dc
->stretchBltMode
= dcs
->stretchBltMode
;
386 dc
->relAbsMode
= dcs
->relAbsMode
;
387 dc
->backgroundMode
= dcs
->backgroundMode
;
388 dc
->backgroundColor
= dcs
->backgroundColor
;
389 dc
->textColor
= dcs
->textColor
;
390 dc
->dcBrushColor
= dcs
->dcBrushColor
;
391 dc
->dcPenColor
= dcs
->dcPenColor
;
392 dc
->brushOrgX
= dcs
->brushOrgX
;
393 dc
->brushOrgY
= dcs
->brushOrgY
;
394 dc
->textAlign
= dcs
->textAlign
;
395 dc
->charExtra
= dcs
->charExtra
;
396 dc
->breakExtra
= dcs
->breakExtra
;
397 dc
->breakRem
= dcs
->breakRem
;
398 dc
->MapMode
= dcs
->MapMode
;
399 dc
->GraphicsMode
= dcs
->GraphicsMode
;
400 dc
->CursPosX
= dcs
->CursPosX
;
401 dc
->CursPosY
= dcs
->CursPosY
;
402 dc
->ArcDirection
= dcs
->ArcDirection
;
403 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
404 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
405 dc
->xformVport2World
= dcs
->xformVport2World
;
406 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
407 dc
->BoundsRect
= dcs
->BoundsRect
;
409 dc
->wndOrgX
= dcs
->wndOrgX
;
410 dc
->wndOrgY
= dcs
->wndOrgY
;
411 dc
->wndExtX
= dcs
->wndExtX
;
412 dc
->wndExtY
= dcs
->wndExtY
;
413 dc
->vportOrgX
= dcs
->vportOrgX
;
414 dc
->vportOrgY
= dcs
->vportOrgY
;
415 dc
->vportExtX
= dcs
->vportExtX
;
416 dc
->vportExtY
= dcs
->vportExtY
;
420 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
421 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
425 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
428 CLIPPING_UpdateGCRegion( dc
);
430 SelectObject( hdc
, dcs
->hBitmap
);
431 SelectObject( hdc
, dcs
->hBrush
);
432 SelectObject( hdc
, dcs
->hFont
);
433 SelectObject( hdc
, dcs
->hPen
);
434 SetBkColor( hdc
, dcs
->backgroundColor
);
435 SetTextColor( hdc
, dcs
->textColor
);
436 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
437 GDI_ReleaseObj( hdcs
);
438 GDI_ReleaseObj( hdc
);
442 /***********************************************************************
443 * GetDCState (GDI.179)
445 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
447 return HDC_16( GetDCState( HDC_32(hdc
) ));
451 /***********************************************************************
452 * SetDCState (GDI.180)
454 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
456 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
460 /***********************************************************************
463 INT WINAPI
SaveDC( HDC hdc
)
469 dc
= DC_GetDCPtr( hdc
);
472 if(dc
->funcs
->pSaveDC
)
474 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
475 GDI_ReleaseObj( hdc
);
479 if (!(hdcs
= GetDCState( hdc
)))
481 GDI_ReleaseObj( hdc
);
484 dcs
= DC_GetDCPtr( hdcs
);
486 /* Copy path. The reason why path saving / restoring is in SaveDC/
487 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
488 * functions are only in Win16 (which doesn't have paths) and that
489 * SetDCState doesn't allow us to signal an error (which can happen
490 * when copying paths).
492 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
494 GDI_ReleaseObj( hdc
);
495 GDI_ReleaseObj( hdcs
);
500 dcs
->header
.hNext
= dc
->header
.hNext
;
501 dc
->header
.hNext
= HDC_16(hdcs
);
502 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
503 ret
= ++dc
->saveLevel
;
504 GDI_ReleaseObj( hdcs
);
505 GDI_ReleaseObj( hdc
);
510 /***********************************************************************
511 * RestoreDC (GDI32.@)
513 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
518 TRACE("%p %d\n", hdc
, level
);
519 dc
= DC_GetDCUpdate( hdc
);
520 if(!dc
) return FALSE
;
521 if(dc
->funcs
->pRestoreDC
)
523 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
524 GDI_ReleaseObj( hdc
);
528 if (level
== -1) level
= dc
->saveLevel
;
530 /* This pair of checks disagrees with MSDN "Platform SDK:
531 Windows GDI" July 2000 which says all negative values
532 for level will be interpreted as an instance relative
533 to the current state. Restricting it to just -1 does
535 || (level
> dc
->saveLevel
))
537 GDI_ReleaseObj( hdc
);
542 while (dc
->saveLevel
>= level
)
544 HDC hdcs
= HDC_32(dc
->header
.hNext
);
545 if (!(dcs
= DC_GetDCPtr( hdcs
)))
547 GDI_ReleaseObj( hdc
);
550 dc
->header
.hNext
= dcs
->header
.hNext
;
551 if (--dc
->saveLevel
< level
)
553 SetDCState( hdc
, hdcs
);
554 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
555 /* FIXME: This might not be quite right, since we're
556 * returning FALSE but still destroying the saved DC state */
559 GDI_ReleaseObj( hdcs
);
560 GDI_ReleaseObj( hdc
);
562 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
564 GDI_ReleaseObj( hdc
);
569 /***********************************************************************
570 * CreateDCW (GDI32.@)
572 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
573 const DEVMODEW
*initData
)
577 const DC_FUNCTIONS
*funcs
;
582 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
584 if (!driver
) return 0;
585 strcpyW(buf
, driver
);
588 if (!(funcs
= DRIVER_load_driver( buf
)))
590 ERR( "no driver found for %s\n", debugstr_w(buf
) );
593 if (!(dc
= DC_AllocDC( funcs
, DC_MAGIC
)))
595 DRIVER_release_driver( funcs
);
600 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
602 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
603 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
605 if (dc
->funcs
->pCreateDC
&&
606 !dc
->funcs
->pCreateDC( hdc
, &dc
->physDev
, buf
, device
, output
, initData
))
608 WARN("creation aborted by device\n" );
609 GDI_FreeObject( dc
->hSelf
, dc
);
610 DRIVER_release_driver( funcs
);
614 dc
->hVisRgn
= CreateRectRgn( 0, 0, GetDeviceCaps( hdc
, HORZRES
),
615 GetDeviceCaps( hdc
, VERTRES
) );
618 GDI_ReleaseObj( hdc
);
623 /***********************************************************************
624 * CreateDCA (GDI32.@)
626 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
627 const DEVMODEA
*initData
)
629 UNICODE_STRING driverW
, deviceW
, outputW
;
633 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
634 else driverW
.Buffer
= NULL
;
636 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
637 else deviceW
.Buffer
= NULL
;
639 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
640 else outputW
.Buffer
= NULL
;
642 if (initData
) initDataW
= GdiConvertToDevmodeW(initData
);
643 else initDataW
= NULL
;
645 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
647 RtlFreeUnicodeString(&driverW
);
648 RtlFreeUnicodeString(&deviceW
);
649 RtlFreeUnicodeString(&outputW
);
650 if (initDataW
) HeapFree(GetProcessHeap(), 0, initDataW
);
655 /***********************************************************************
656 * CreateICA (GDI32.@)
658 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
659 const DEVMODEA
* initData
)
661 /* Nothing special yet for ICs */
662 return CreateDCA( driver
, device
, output
, initData
);
666 /***********************************************************************
667 * CreateICW (GDI32.@)
669 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
670 const DEVMODEW
* initData
)
672 /* Nothing special yet for ICs */
673 return CreateDCW( driver
, device
, output
, initData
);
677 /***********************************************************************
678 * CreateCompatibleDC (GDI32.@)
680 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
683 const DC_FUNCTIONS
*funcs
;
688 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
690 funcs
= origDC
->funcs
;
691 physDev
= origDC
->physDev
;
692 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
693 funcs
= DRIVER_get_driver( funcs
);
697 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
698 funcs
= DRIVER_load_driver( displayW
);
702 if (!funcs
) return 0;
704 if (!(dc
= DC_AllocDC( funcs
, MEMORY_DC_MAGIC
)))
706 DRIVER_release_driver( funcs
);
710 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
712 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
714 /* Copy the driver-specific physical device info into
715 * the new DC. The driver may use this read-only info
716 * while creating the compatible DC below. */
717 dc
->physDev
= physDev
;
719 if (dc
->funcs
->pCreateDC
&&
720 !dc
->funcs
->pCreateDC( dc
->hSelf
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
722 WARN("creation aborted by device\n");
723 GDI_FreeObject( dc
->hSelf
, dc
);
724 DRIVER_release_driver( funcs
);
728 dc
->hVisRgn
= CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
731 GDI_ReleaseObj( dc
->hSelf
);
736 /***********************************************************************
739 BOOL WINAPI
DeleteDC( HDC hdc
)
741 const DC_FUNCTIONS
*funcs
= NULL
;
748 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
750 /* Call hook procedure to check whether is it OK to delete this DC */
753 DCHOOKPROC proc
= dc
->hookThunk
;
754 DWORD data
= dc
->dwHookData
;
755 GDI_ReleaseObj( hdc
);
756 if (!proc( HDC_16(hdc
), DCHC_DELETEDC
, data
, 0 )) return FALSE
;
757 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
760 while (dc
->saveLevel
)
763 HDC hdcs
= HDC_32(dc
->header
.hNext
);
764 if (!(dcs
= DC_GetDCPtr( hdcs
))) break;
765 dc
->header
.hNext
= dcs
->header
.hNext
;
767 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
768 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
769 PATH_DestroyGdiPath(&dcs
->path
);
770 GDI_FreeObject( hdcs
, dcs
);
773 if (!(dc
->flags
& DC_SAVED
))
775 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
776 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
777 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
778 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
780 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
784 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
785 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
786 PATH_DestroyGdiPath(&dc
->path
);
788 GDI_FreeObject( hdc
, dc
);
789 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
794 /***********************************************************************
797 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
802 if ((dc
= DC_GetDCPtr( hdc
)))
804 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
805 GDI_ReleaseObj( hdc
);
811 /***********************************************************************
814 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
819 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
820 else devmodeW
= NULL
;
822 ret
= ResetDCW(hdc
, devmodeW
);
824 if (devmodeW
) HeapFree(GetProcessHeap(), 0, devmodeW
);
829 /***********************************************************************
830 * GetDeviceCaps (GDI32.@)
832 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
837 if ((dc
= DC_GetDCPtr( hdc
)))
839 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
840 GDI_ReleaseObj( hdc
);
846 /***********************************************************************
847 * GetBkColor (GDI32.@)
849 COLORREF WINAPI
GetBkColor( HDC hdc
)
852 DC
* dc
= DC_GetDCPtr( hdc
);
855 ret
= dc
->backgroundColor
;
856 GDI_ReleaseObj( hdc
);
862 /***********************************************************************
863 * SetBkColor (GDI32.@)
865 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
868 DC
* dc
= DC_GetDCPtr( hdc
);
870 TRACE("hdc=%p color=0x%08lx\n", hdc
, color
);
872 if (!dc
) return CLR_INVALID
;
873 oldColor
= dc
->backgroundColor
;
874 if (dc
->funcs
->pSetBkColor
)
876 color
= dc
->funcs
->pSetBkColor(dc
->physDev
, color
);
877 if (color
== CLR_INVALID
) /* don't change it */
880 oldColor
= CLR_INVALID
;
883 dc
->backgroundColor
= color
;
884 GDI_ReleaseObj( hdc
);
889 /***********************************************************************
890 * GetTextColor (GDI32.@)
892 COLORREF WINAPI
GetTextColor( HDC hdc
)
895 DC
* dc
= DC_GetDCPtr( hdc
);
899 GDI_ReleaseObj( hdc
);
905 /***********************************************************************
906 * SetTextColor (GDI32.@)
908 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
911 DC
* dc
= DC_GetDCPtr( hdc
);
913 TRACE(" hdc=%p color=0x%08lx\n", hdc
, color
);
915 if (!dc
) return CLR_INVALID
;
916 oldColor
= dc
->textColor
;
917 if (dc
->funcs
->pSetTextColor
)
919 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
920 if (color
== CLR_INVALID
) /* don't change it */
923 oldColor
= CLR_INVALID
;
926 dc
->textColor
= color
;
927 GDI_ReleaseObj( hdc
);
932 /***********************************************************************
933 * GetTextAlign (GDI32.@)
935 UINT WINAPI
GetTextAlign( HDC hdc
)
938 DC
* dc
= DC_GetDCPtr( hdc
);
942 GDI_ReleaseObj( hdc
);
948 /***********************************************************************
949 * SetTextAlign (GDI32.@)
951 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
954 DC
*dc
= DC_GetDCPtr( hdc
);
956 TRACE("hdc=%p align=%d\n", hdc
, align
);
959 if (dc
->funcs
->pSetTextAlign
)
960 prevAlign
= dc
->funcs
->pSetTextAlign(dc
->physDev
, align
);
962 prevAlign
= dc
->textAlign
;
963 dc
->textAlign
= align
;
965 GDI_ReleaseObj( hdc
);
969 /***********************************************************************
970 * GetDCOrgEx (GDI32.@)
972 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
976 if (!lpp
) return FALSE
;
977 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
980 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
981 GDI_ReleaseObj( hDC
);
986 /***********************************************************************
989 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
992 HDC hdc
= HDC_32( hdc16
);
993 DC
*dc
= DC_GetDCPtr( hdc
);
995 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
996 GDI_ReleaseObj( hdc
);
1001 /***********************************************************************
1002 * GetGraphicsMode (GDI32.@)
1004 INT WINAPI
GetGraphicsMode( HDC hdc
)
1007 DC
* dc
= DC_GetDCPtr( hdc
);
1010 ret
= dc
->GraphicsMode
;
1011 GDI_ReleaseObj( hdc
);
1017 /***********************************************************************
1018 * SetGraphicsMode (GDI32.@)
1020 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1023 DC
*dc
= DC_GetDCPtr( hdc
);
1025 /* One would think that setting the graphics mode to GM_COMPATIBLE
1026 * would also reset the world transformation matrix to the unity
1027 * matrix. However, in Windows, this is not the case. This doesn't
1028 * make a lot of sense to me, but that's the way it is.
1031 if ((mode
> 0) && (mode
<= GM_LAST
))
1033 ret
= dc
->GraphicsMode
;
1034 dc
->GraphicsMode
= mode
;
1036 GDI_ReleaseObj( hdc
);
1041 /***********************************************************************
1042 * GetArcDirection (GDI32.@)
1044 INT WINAPI
GetArcDirection( HDC hdc
)
1047 DC
* dc
= DC_GetDCPtr( hdc
);
1050 ret
= dc
->ArcDirection
;
1051 GDI_ReleaseObj( hdc
);
1057 /***********************************************************************
1058 * SetArcDirection (GDI32.@)
1060 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
1063 INT nOldDirection
= 0;
1065 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1067 SetLastError(ERROR_INVALID_PARAMETER
);
1071 if ((dc
= DC_GetDCPtr( hdc
)))
1073 if (dc
->funcs
->pSetArcDirection
)
1075 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1077 nOldDirection
= dc
->ArcDirection
;
1078 dc
->ArcDirection
= nDirection
;
1079 GDI_ReleaseObj( hdc
);
1081 return nOldDirection
;
1085 /***********************************************************************
1086 * GetWorldTransform (GDI32.@)
1088 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1091 if (!xform
) return FALSE
;
1092 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1093 *xform
= dc
->xformWorld2Wnd
;
1094 GDI_ReleaseObj( hdc
);
1099 /***********************************************************************
1100 * GetTransform (GDI32.@)
1102 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1104 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1105 FIXME("stub: don't know what to do for code %lx\n", unknown
);
1110 /***********************************************************************
1111 * SetWorldTransform (GDI32.@)
1113 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1116 DC
*dc
= DC_GetDCPtr( hdc
);
1118 if (!dc
) return FALSE
;
1119 if (!xform
) goto done
;
1121 /* Check that graphics mode is GM_ADVANCED */
1122 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1124 if (dc
->funcs
->pSetWorldTransform
)
1126 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1127 if (!ret
) goto done
;
1130 dc
->xformWorld2Wnd
= *xform
;
1131 DC_UpdateXforms( dc
);
1134 GDI_ReleaseObj( hdc
);
1139 /****************************************************************************
1140 * ModifyWorldTransform [GDI32.@]
1141 * Modifies the world transformation for a device context.
1144 * hdc [I] Handle to device context
1145 * xform [I] XFORM structure that will be used to modify the world
1147 * iMode [I] Specifies in what way to modify the world transformation
1150 * Resets the world transformation to the identity matrix.
1151 * The parameter xform is ignored.
1153 * Multiplies xform into the world transformation matrix from
1156 * Multiplies xform into the world transformation matrix from
1161 * Failure: FALSE. Use GetLastError() to determine the cause.
1163 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1167 DC
*dc
= DC_GetDCPtr( hdc
);
1169 /* Check for illegal parameters */
1170 if (!dc
) return FALSE
;
1171 if (!xform
) goto done
;
1173 /* Check that graphics mode is GM_ADVANCED */
1174 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1176 if (dc
->funcs
->pModifyWorldTransform
)
1178 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1179 if (!ret
) goto done
;
1185 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1186 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1187 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1188 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1189 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1190 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1192 case MWT_LEFTMULTIPLY
:
1193 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1194 &dc
->xformWorld2Wnd
);
1196 case MWT_RIGHTMULTIPLY
:
1197 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1204 DC_UpdateXforms( dc
);
1207 GDI_ReleaseObj( hdc
);
1212 /****************************************************************************
1213 * CombineTransform [GDI32.@]
1214 * Combines two transformation matrices.
1217 * xformResult [O] Stores the result of combining the two matrices
1218 * xform1 [I] Specifies the first matrix to apply
1219 * xform2 [I] Specifies the second matrix to apply
1222 * The same matrix can be passed in for more than one of the parameters.
1226 * Failure: FALSE. Use GetLastError() to determine the cause.
1228 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1229 const XFORM
*xform2
)
1233 /* Check for illegal parameters */
1234 if (!xformResult
|| !xform1
|| !xform2
)
1237 /* Create the result in a temporary XFORM, since xformResult may be
1238 * equal to xform1 or xform2 */
1239 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1240 xform1
->eM12
* xform2
->eM21
;
1241 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1242 xform1
->eM12
* xform2
->eM22
;
1243 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1244 xform1
->eM22
* xform2
->eM21
;
1245 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1246 xform1
->eM22
* xform2
->eM22
;
1247 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1248 xform1
->eDy
* xform2
->eM21
+
1250 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1251 xform1
->eDy
* xform2
->eM22
+
1254 /* Copy the result to xformResult */
1255 *xformResult
= xformTemp
;
1261 /***********************************************************************
1262 * SetDCHook (GDI32.@)
1264 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1266 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1268 DC
*dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
);
1270 if (!dc
) return FALSE
;
1272 if (!(dc
->flags
& DC_SAVED
))
1274 dc
->dwHookData
= dwHookData
;
1275 dc
->hookThunk
= hookProc
;
1277 GDI_ReleaseObj( hdc
);
1282 /* relay function to call the 16-bit DC hook proc */
1283 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc16
, WORD code
, DWORD data
, LPARAM lParam
)
1287 FARPROC16 proc
= NULL
;
1288 HDC hdc
= HDC_32( hdc16
);
1289 DC
*dc
= DC_GetDCPtr( hdc
);
1291 if (!dc
) return FALSE
;
1292 proc
= dc
->hookProc
;
1293 GDI_ReleaseObj( hdc
);
1294 if (!proc
) return FALSE
;
1297 args
[3] = HIWORD(data
);
1298 args
[2] = LOWORD(data
);
1299 args
[1] = HIWORD(lParam
);
1300 args
[0] = LOWORD(lParam
);
1301 WOWCallback16Ex( (DWORD
)proc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1305 /***********************************************************************
1306 * SetDCHook (GDI.190)
1308 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1310 HDC hdc
= HDC_32( hdc16
);
1311 DC
*dc
= DC_GetDCPtr( hdc
);
1312 if (!dc
) return FALSE
;
1314 dc
->hookProc
= hookProc
;
1315 GDI_ReleaseObj( hdc
);
1316 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1320 /***********************************************************************
1321 * GetDCHook (GDI.191)
1323 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1325 HDC hdc
= HDC_32( hdc16
);
1326 DC
*dc
= DC_GetDCPtr( hdc
);
1330 *phookProc
= dc
->hookProc
;
1331 ret
= dc
->dwHookData
;
1332 GDI_ReleaseObj( hdc
);
1337 /***********************************************************************
1338 * SetHookFlags (GDI.192)
1340 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1342 HDC hdc
= HDC_32( hdc16
);
1343 DC
*dc
= DC_GetDCPtr( hdc
);
1347 WORD wRet
= dc
->flags
& DC_DIRTY
;
1349 /* "Undocumented Windows" info is slightly confusing.
1352 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1354 if( flags
& DCHF_INVALIDATEVISRGN
)
1355 dc
->flags
|= DC_DIRTY
;
1356 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1357 dc
->flags
&= ~DC_DIRTY
;
1358 GDI_ReleaseObj( hdc
);
1364 /***********************************************************************
1365 * SetICMMode (GDI32.@)
1367 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1369 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1370 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1371 if (iEnableICM
== ICM_ON
) return 0;
1372 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1376 /***********************************************************************
1377 * GetDeviceGammaRamp (GDI32.@)
1379 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1382 DC
*dc
= DC_GetDCPtr( hDC
);
1386 if (dc
->funcs
->pGetDeviceGammaRamp
)
1387 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1388 GDI_ReleaseObj( hDC
);
1393 /***********************************************************************
1394 * SetDeviceGammaRamp (GDI32.@)
1396 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1399 DC
*dc
= DC_GetDCPtr( hDC
);
1403 if (dc
->funcs
->pSetDeviceGammaRamp
)
1404 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1405 GDI_ReleaseObj( hDC
);
1410 /***********************************************************************
1411 * GetColorSpace (GDI32.@)
1413 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1415 /*FIXME Need to to whatever GetColorSpace actually does */
1419 /***********************************************************************
1420 * CreateColorSpaceA (GDI32.@)
1422 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1428 /***********************************************************************
1429 * CreateColorSpaceW (GDI32.@)
1431 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1437 /***********************************************************************
1438 * DeleteColorSpace (GDI32.@)
1440 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1447 /***********************************************************************
1448 * SetColorSpace (GDI32.@)
1450 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1457 /***********************************************************************
1458 * GetBoundsRect (GDI32.@)
1460 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1463 DC
*dc
= DC_GetDCPtr( hdc
);
1465 if ( !dc
) return 0;
1467 if (rect
) *rect
= dc
->BoundsRect
;
1469 ret
= ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1471 if (flags
& DCB_RESET
)
1473 dc
->BoundsRect
.left
= 0;
1474 dc
->BoundsRect
.top
= 0;
1475 dc
->BoundsRect
.right
= 0;
1476 dc
->BoundsRect
.bottom
= 0;
1477 dc
->flags
&= ~DC_BOUNDS_SET
;
1479 GDI_ReleaseObj( hdc
);
1484 /***********************************************************************
1485 * SetBoundsRect (GDI32.@)
1487 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1492 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1493 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1495 ret
= ((dc
->flags
& DC_BOUNDS_ENABLE
) ? DCB_ENABLE
: DCB_DISABLE
) |
1496 ((dc
->flags
& DC_BOUNDS_SET
) ? DCB_SET
: DCB_RESET
);
1498 if (flags
& DCB_RESET
)
1500 dc
->BoundsRect
.left
= 0;
1501 dc
->BoundsRect
.top
= 0;
1502 dc
->BoundsRect
.right
= 0;
1503 dc
->BoundsRect
.bottom
= 0;
1504 dc
->flags
&= ~DC_BOUNDS_SET
;
1507 if ((flags
& DCB_ACCUMULATE
) && rect
&& rect
->left
< rect
->right
&& rect
->top
< rect
->bottom
)
1509 if (dc
->flags
& DC_BOUNDS_SET
)
1511 dc
->BoundsRect
.left
= min( dc
->BoundsRect
.left
, rect
->left
);
1512 dc
->BoundsRect
.top
= min( dc
->BoundsRect
.top
, rect
->top
);
1513 dc
->BoundsRect
.right
= max( dc
->BoundsRect
.right
, rect
->right
);
1514 dc
->BoundsRect
.bottom
= max( dc
->BoundsRect
.bottom
, rect
->bottom
);
1518 dc
->BoundsRect
= *rect
;
1519 dc
->flags
|= DC_BOUNDS_SET
;
1523 if (flags
& DCB_ENABLE
) dc
->flags
|= DC_BOUNDS_ENABLE
;
1524 if (flags
& DCB_DISABLE
) dc
->flags
&= ~DC_BOUNDS_ENABLE
;
1526 GDI_ReleaseObj( hdc
);
1531 /***********************************************************************
1532 * GetRelAbs (GDI32.@)
1534 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1537 DC
*dc
= DC_GetDCPtr( hdc
);
1538 if (dc
) ret
= dc
->relAbsMode
;
1539 GDI_ReleaseObj( hdc
);
1546 /***********************************************************************
1547 * GetBkMode (GDI32.@)
1549 INT WINAPI
GetBkMode( HDC hdc
)
1552 DC
* dc
= DC_GetDCPtr( hdc
);
1555 ret
= dc
->backgroundMode
;
1556 GDI_ReleaseObj( hdc
);
1562 /***********************************************************************
1563 * SetBkMode (GDI32.@)
1565 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1569 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1571 SetLastError(ERROR_INVALID_PARAMETER
);
1574 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1575 if (dc
->funcs
->pSetBkMode
)
1576 ret
= dc
->funcs
->pSetBkMode( dc
->physDev
, mode
);
1579 ret
= dc
->backgroundMode
;
1580 dc
->backgroundMode
= mode
;
1582 GDI_ReleaseObj( hdc
);
1587 /***********************************************************************
1590 INT WINAPI
GetROP2( HDC hdc
)
1593 DC
* dc
= DC_GetDCPtr( hdc
);
1597 GDI_ReleaseObj( hdc
);
1603 /***********************************************************************
1606 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1610 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1612 SetLastError(ERROR_INVALID_PARAMETER
);
1615 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1616 if (dc
->funcs
->pSetROP2
)
1617 ret
= dc
->funcs
->pSetROP2( dc
->physDev
, mode
);
1623 GDI_ReleaseObj( hdc
);
1628 /***********************************************************************
1629 * SetRelAbs (GDI32.@)
1631 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1635 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1637 SetLastError(ERROR_INVALID_PARAMETER
);
1640 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1641 if (dc
->funcs
->pSetRelAbs
)
1642 ret
= dc
->funcs
->pSetRelAbs( dc
->physDev
, mode
);
1645 ret
= dc
->relAbsMode
;
1646 dc
->relAbsMode
= mode
;
1648 GDI_ReleaseObj( hdc
);
1653 /***********************************************************************
1654 * GetPolyFillMode (GDI32.@)
1656 INT WINAPI
GetPolyFillMode( HDC hdc
)
1659 DC
* dc
= DC_GetDCPtr( hdc
);
1662 ret
= dc
->polyFillMode
;
1663 GDI_ReleaseObj( hdc
);
1669 /***********************************************************************
1670 * SetPolyFillMode (GDI32.@)
1672 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1676 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1678 SetLastError(ERROR_INVALID_PARAMETER
);
1681 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1682 if (dc
->funcs
->pSetPolyFillMode
)
1683 ret
= dc
->funcs
->pSetPolyFillMode( dc
->physDev
, mode
);
1686 ret
= dc
->polyFillMode
;
1687 dc
->polyFillMode
= mode
;
1689 GDI_ReleaseObj( hdc
);
1694 /***********************************************************************
1695 * GetStretchBltMode (GDI32.@)
1697 INT WINAPI
GetStretchBltMode( HDC hdc
)
1700 DC
* dc
= DC_GetDCPtr( hdc
);
1703 ret
= dc
->stretchBltMode
;
1704 GDI_ReleaseObj( hdc
);
1710 /***********************************************************************
1711 * SetStretchBltMode (GDI32.@)
1713 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1717 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1719 SetLastError(ERROR_INVALID_PARAMETER
);
1722 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
1723 if (dc
->funcs
->pSetStretchBltMode
)
1724 ret
= dc
->funcs
->pSetStretchBltMode( dc
->physDev
, mode
);
1727 ret
= dc
->stretchBltMode
;
1728 dc
->stretchBltMode
= mode
;
1730 GDI_ReleaseObj( hdc
);
1735 /***********************************************************************
1736 * GetMapMode (GDI32.@)
1738 INT WINAPI
GetMapMode( HDC hdc
)
1741 DC
* dc
= DC_GetDCPtr( hdc
);
1745 GDI_ReleaseObj( hdc
);
1751 /***********************************************************************
1752 * GetBrushOrgEx (GDI32.@)
1754 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1756 DC
* dc
= DC_GetDCPtr( hdc
);
1757 if (!dc
) return FALSE
;
1758 pt
->x
= dc
->brushOrgX
;
1759 pt
->y
= dc
->brushOrgY
;
1760 GDI_ReleaseObj( hdc
);
1765 /***********************************************************************
1766 * GetCurrentPositionEx (GDI32.@)
1768 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1770 DC
* dc
= DC_GetDCPtr( hdc
);
1771 if (!dc
) return FALSE
;
1772 pt
->x
= dc
->CursPosX
;
1773 pt
->y
= dc
->CursPosY
;
1774 GDI_ReleaseObj( hdc
);
1779 /***********************************************************************
1780 * GetViewportExtEx (GDI32.@)
1782 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1784 DC
* dc
= DC_GetDCPtr( hdc
);
1785 if (!dc
) return FALSE
;
1786 size
->cx
= dc
->vportExtX
;
1787 size
->cy
= dc
->vportExtY
;
1788 GDI_ReleaseObj( hdc
);
1793 /***********************************************************************
1794 * GetViewportOrgEx (GDI32.@)
1796 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1798 DC
* dc
= DC_GetDCPtr( hdc
);
1799 if (!dc
) return FALSE
;
1800 pt
->x
= dc
->vportOrgX
;
1801 pt
->y
= dc
->vportOrgY
;
1802 GDI_ReleaseObj( hdc
);
1807 /***********************************************************************
1808 * GetWindowExtEx (GDI32.@)
1810 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1812 DC
* dc
= DC_GetDCPtr( hdc
);
1813 if (!dc
) return FALSE
;
1814 size
->cx
= dc
->wndExtX
;
1815 size
->cy
= dc
->wndExtY
;
1816 GDI_ReleaseObj( hdc
);
1821 /***********************************************************************
1822 * GetWindowOrgEx (GDI32.@)
1824 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1826 DC
* dc
= DC_GetDCPtr( hdc
);
1827 if (!dc
) return FALSE
;
1828 pt
->x
= dc
->wndOrgX
;
1829 pt
->y
= dc
->wndOrgY
;
1830 GDI_ReleaseObj( hdc
);
1835 /***********************************************************************
1836 * InquireVisRgn (GDI.131)
1838 HRGN16 WINAPI
InquireVisRgn16( HDC16 hdc
)
1841 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1844 ret
= HRGN_16(dc
->hVisRgn
);
1845 GDI_ReleaseObj( HDC_32(hdc
) );
1851 /***********************************************************************
1852 * GetClipRgn (GDI.173)
1854 HRGN16 WINAPI
GetClipRgn16( HDC16 hdc
)
1857 DC
* dc
= DC_GetDCPtr( HDC_32(hdc
) );
1860 ret
= HRGN_16(dc
->hClipRgn
);
1861 GDI_ReleaseObj( HDC_32(hdc
) );
1867 /***********************************************************************
1868 * GetLayout (GDI32.@)
1870 * Gets left->right or right->left text layout flags of a dc.
1871 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1874 DWORD WINAPI
GetLayout(HDC hdc
)
1876 FIXME("(%p): stub\n", hdc
);
1877 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1881 /***********************************************************************
1882 * SetLayout (GDI32.@)
1884 * Sets left->right or right->left text layout flags of a dc.
1885 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1888 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1890 FIXME("(%p,%08lx): stub\n", hdc
, layout
);
1891 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1895 /***********************************************************************
1896 * GetDCBrushColor (GDI32.@)
1898 * Retrieves the current brush color for the specified device
1902 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1905 COLORREF dcBrushColor
= CLR_INVALID
;
1907 TRACE("hdc(%p)\n", hdc
);
1909 dc
= DC_GetDCPtr( hdc
);
1912 dcBrushColor
= dc
->dcBrushColor
;
1913 GDI_ReleaseObj( hdc
);
1916 return dcBrushColor
;
1919 /***********************************************************************
1920 * SetDCBrushColor (GDI32.@)
1922 * Sets the current device context (DC) brush color to the specified
1923 * color value. If the device cannot represent the specified color
1924 * value, the color is set to the nearest physical color.
1927 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1930 COLORREF oldClr
= CLR_INVALID
;
1932 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
1934 dc
= DC_GetDCPtr( hdc
);
1937 if (dc
->funcs
->pSetDCBrushColor
)
1938 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
1939 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
1941 /* If DC_BRUSH is selected, update driver pen color */
1942 HBRUSH hBrush
= CreateSolidBrush( crColor
);
1943 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
1944 DeleteObject( hBrush
);
1947 if (crColor
!= CLR_INVALID
)
1949 oldClr
= dc
->dcBrushColor
;
1950 dc
->dcBrushColor
= crColor
;
1953 GDI_ReleaseObj( hdc
);
1959 /***********************************************************************
1960 * GetDCPenColor (GDI32.@)
1962 * Retrieves the current pen color for the specified device
1966 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1969 COLORREF dcPenColor
= CLR_INVALID
;
1971 TRACE("hdc(%p)\n", hdc
);
1973 dc
= DC_GetDCPtr( hdc
);
1976 dcPenColor
= dc
->dcPenColor
;
1977 GDI_ReleaseObj( hdc
);
1983 /***********************************************************************
1984 * SetDCPenColor (GDI32.@)
1986 * Sets the current device context (DC) pen color to the specified
1987 * color value. If the device cannot represent the specified color
1988 * value, the color is set to the nearest physical color.
1991 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1994 COLORREF oldClr
= CLR_INVALID
;
1996 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
1998 dc
= DC_GetDCPtr( hdc
);
2001 if (dc
->funcs
->pSetDCPenColor
)
2002 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
2003 else if (dc
->hPen
== GetStockObject( DC_PEN
))
2005 /* If DC_PEN is selected, update the driver pen color */
2006 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
2007 HPEN hPen
= CreatePenIndirect( &logpen
);
2008 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
2009 DeleteObject( hPen
);
2012 if (crColor
!= CLR_INVALID
)
2014 oldClr
= dc
->dcPenColor
;
2015 dc
->dcPenColor
= crColor
;
2018 GDI_ReleaseObj( hdc
);
2024 /***********************************************************************
2025 * SetVirtualResolution (GDI32.@)
2027 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2029 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
2031 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);