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
;
82 dc
->hPen
= GetStockObject( BLACK_PEN
);
83 dc
->hBrush
= GetStockObject( WHITE_BRUSH
);
84 dc
->hFont
= GetStockObject( SYSTEM_FONT
);
87 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
89 dc
->ROPmode
= R2_COPYPEN
;
90 dc
->polyFillMode
= ALTERNATE
;
91 dc
->stretchBltMode
= BLACKONWHITE
;
92 dc
->relAbsMode
= ABSOLUTE
;
93 dc
->backgroundMode
= OPAQUE
;
94 dc
->backgroundColor
= RGB( 255, 255, 255 );
95 dc
->dcBrushColor
= RGB( 255, 255, 255 );
96 dc
->dcPenColor
= RGB( 0, 0, 0 );
97 dc
->textColor
= RGB( 0, 0, 0 );
100 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
102 dc
->breakTotalExtra
= 0;
106 dc
->totalExtent
.left
= 0;
107 dc
->totalExtent
.top
= 0;
108 dc
->totalExtent
.right
= 0;
109 dc
->totalExtent
.bottom
= 0;
110 dc
->MapMode
= MM_TEXT
;
111 dc
->GraphicsMode
= GM_COMPATIBLE
;
112 dc
->pAbortProc
= NULL
;
115 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
116 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
117 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
118 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
119 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
120 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
121 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
122 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
123 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
124 dc
->vport2WorldValid
= TRUE
;
125 PATH_InitGdiPath(&dc
->path
);
131 /***********************************************************************
134 DC
*DC_GetDCPtr( HDC hdc
)
136 GDIOBJHDR
*ptr
= GDI_GetObjPtr( hdc
, MAGIC_DONTCARE
);
137 if (!ptr
) return NULL
;
138 if ((GDIMAGIC(ptr
->wMagic
) == DC_MAGIC
) ||
139 (GDIMAGIC(ptr
->wMagic
) == MEMORY_DC_MAGIC
) ||
140 (GDIMAGIC(ptr
->wMagic
) == METAFILE_DC_MAGIC
) ||
141 (GDIMAGIC(ptr
->wMagic
) == ENHMETAFILE_DC_MAGIC
))
143 GDI_ReleaseObj( hdc
);
144 SetLastError( ERROR_INVALID_HANDLE
);
148 /***********************************************************************
151 * Retrieve a DC ptr while making sure the visRgn is updated.
152 * This function may call up to USER so the GDI lock should _not_
153 * be held when calling it.
155 DC
*DC_GetDCUpdate( HDC hdc
)
157 DC
*dc
= DC_GetDCPtr( hdc
);
158 if (!dc
) return NULL
;
159 while (dc
->flags
& DC_DIRTY
)
161 DCHOOKPROC proc
= dc
->hookThunk
;
162 dc
->flags
&= ~DC_DIRTY
;
165 DWORD data
= dc
->dwHookData
;
166 GDI_ReleaseObj( hdc
);
167 proc( HDC_16(hdc
), DCHC_INVALIDVISRGN
, data
, 0 );
168 if (!(dc
= DC_GetDCPtr( hdc
))) break;
169 /* otherwise restart the loop in case it became dirty again in the meantime */
176 /***********************************************************************
179 static BOOL
DC_DeleteObject( HGDIOBJ handle
, void *obj
)
181 GDI_ReleaseObj( handle
);
182 return DeleteDC( handle
);
186 /***********************************************************************
189 * Setup device-specific DC values for a newly created DC.
191 void DC_InitDC( DC
* dc
)
193 if (dc
->funcs
->pRealizeDefaultPalette
) dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
194 SetTextColor( dc
->hSelf
, dc
->textColor
);
195 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
196 SelectObject( dc
->hSelf
, dc
->hPen
);
197 SelectObject( dc
->hSelf
, dc
->hBrush
);
198 SelectObject( dc
->hSelf
, dc
->hFont
);
199 CLIPPING_UpdateGCRegion( dc
);
203 /***********************************************************************
206 * Computes the inverse of the transformation xformSrc and stores it to
207 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
210 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
214 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
215 xformSrc
->eM12
*xformSrc
->eM21
;
216 if (determinant
> -1e-12 && determinant
< 1e-12)
219 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
220 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
221 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
222 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
223 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
224 xformSrc
->eDy
* xformDest
->eM21
;
225 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
226 xformSrc
->eDy
* xformDest
->eM22
;
232 /***********************************************************************
235 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
236 * fields of the specified DC by creating a transformation that
237 * represents the current mapping mode and combining it with the DC's
238 * world transform. This function should be called whenever the
239 * parameters associated with the mapping mode (window and viewport
240 * extents and origins) or the world transform change.
242 void DC_UpdateXforms( DC
*dc
)
244 XFORM xformWnd2Vport
, oldworld2vport
;
245 FLOAT scaleX
, scaleY
;
247 /* Construct a transformation to do the window-to-viewport conversion */
248 scaleX
= (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
;
249 scaleY
= (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
;
250 xformWnd2Vport
.eM11
= scaleX
;
251 xformWnd2Vport
.eM12
= 0.0;
252 xformWnd2Vport
.eM21
= 0.0;
253 xformWnd2Vport
.eM22
= scaleY
;
254 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
-
255 scaleX
* (FLOAT
)dc
->wndOrgX
;
256 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
-
257 scaleY
* (FLOAT
)dc
->wndOrgY
;
259 oldworld2vport
= dc
->xformWorld2Vport
;
260 /* Combine with the world transformation */
261 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
264 /* Create inverse of world-to-viewport transformation */
265 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
266 &dc
->xformVport2World
);
268 /* Reselect the font back into the dc so that the font size
270 if(memcmp(&oldworld2vport
, &dc
->xformWorld2Vport
, sizeof(oldworld2vport
)))
271 SelectObject(dc
->hSelf
, GetCurrentObject(dc
->hSelf
, OBJ_FONT
));
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
->totalExtent
= dc
->totalExtent
;
299 newdc
->ROPmode
= dc
->ROPmode
;
300 newdc
->polyFillMode
= dc
->polyFillMode
;
301 newdc
->stretchBltMode
= dc
->stretchBltMode
;
302 newdc
->relAbsMode
= dc
->relAbsMode
;
303 newdc
->backgroundMode
= dc
->backgroundMode
;
304 newdc
->backgroundColor
= dc
->backgroundColor
;
305 newdc
->textColor
= dc
->textColor
;
306 newdc
->dcBrushColor
= dc
->dcBrushColor
;
307 newdc
->dcPenColor
= dc
->dcPenColor
;
308 newdc
->brushOrgX
= dc
->brushOrgX
;
309 newdc
->brushOrgY
= dc
->brushOrgY
;
310 newdc
->textAlign
= dc
->textAlign
;
311 newdc
->charExtra
= dc
->charExtra
;
312 newdc
->breakTotalExtra
= dc
->breakTotalExtra
;
313 newdc
->breakCount
= dc
->breakCount
;
314 newdc
->breakExtra
= dc
->breakExtra
;
315 newdc
->breakRem
= dc
->breakRem
;
316 newdc
->MapMode
= dc
->MapMode
;
317 newdc
->GraphicsMode
= dc
->GraphicsMode
;
318 newdc
->CursPosX
= dc
->CursPosX
;
319 newdc
->CursPosY
= dc
->CursPosY
;
320 newdc
->ArcDirection
= dc
->ArcDirection
;
321 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
322 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
323 newdc
->xformVport2World
= dc
->xformVport2World
;
324 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
325 newdc
->wndOrgX
= dc
->wndOrgX
;
326 newdc
->wndOrgY
= dc
->wndOrgY
;
327 newdc
->wndExtX
= dc
->wndExtX
;
328 newdc
->wndExtY
= dc
->wndExtY
;
329 newdc
->vportOrgX
= dc
->vportOrgX
;
330 newdc
->vportOrgY
= dc
->vportOrgY
;
331 newdc
->vportExtX
= dc
->vportExtX
;
332 newdc
->vportExtY
= dc
->vportExtY
;
334 newdc
->hSelf
= (HDC
)handle
;
335 newdc
->saveLevel
= 0;
337 PATH_InitGdiPath( &newdc
->path
);
339 newdc
->pAbortProc
= NULL
;
340 newdc
->hookThunk
= NULL
;
343 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
345 newdc
->hGCClipRgn
= newdc
->hVisRgn
= 0;
348 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
349 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
355 newdc
->gdiFont
= dc
->gdiFont
;
359 GDI_ReleaseObj( handle
);
360 GDI_ReleaseObj( hdc
);
365 /***********************************************************************
366 * SetDCState (Not a Windows API)
368 void WINAPI
SetDCState( HDC hdc
, HDC hdcs
)
372 if (!(dc
= DC_GetDCUpdate( hdc
))) return;
373 if (!(dcs
= DC_GetDCPtr( hdcs
)))
375 GDI_ReleaseObj( hdc
);
378 if (!dcs
->flags
& DC_SAVED
)
380 GDI_ReleaseObj( hdc
);
381 GDI_ReleaseObj( hdcs
);
384 TRACE("%p %p\n", hdc
, hdcs
);
386 dc
->flags
= dcs
->flags
& ~(DC_SAVED
| DC_DIRTY
);
387 dc
->hDevice
= dcs
->hDevice
;
388 dc
->totalExtent
= dcs
->totalExtent
;
389 dc
->ROPmode
= dcs
->ROPmode
;
390 dc
->polyFillMode
= dcs
->polyFillMode
;
391 dc
->stretchBltMode
= dcs
->stretchBltMode
;
392 dc
->relAbsMode
= dcs
->relAbsMode
;
393 dc
->backgroundMode
= dcs
->backgroundMode
;
394 dc
->backgroundColor
= dcs
->backgroundColor
;
395 dc
->textColor
= dcs
->textColor
;
396 dc
->dcBrushColor
= dcs
->dcBrushColor
;
397 dc
->dcPenColor
= dcs
->dcPenColor
;
398 dc
->brushOrgX
= dcs
->brushOrgX
;
399 dc
->brushOrgY
= dcs
->brushOrgY
;
400 dc
->textAlign
= dcs
->textAlign
;
401 dc
->charExtra
= dcs
->charExtra
;
402 dc
->breakTotalExtra
= dcs
->breakTotalExtra
;
403 dc
->breakCount
= dcs
->breakCount
;
404 dc
->breakExtra
= dcs
->breakExtra
;
405 dc
->breakRem
= dcs
->breakRem
;
406 dc
->MapMode
= dcs
->MapMode
;
407 dc
->GraphicsMode
= dcs
->GraphicsMode
;
408 dc
->CursPosX
= dcs
->CursPosX
;
409 dc
->CursPosY
= dcs
->CursPosY
;
410 dc
->ArcDirection
= dcs
->ArcDirection
;
411 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
412 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
413 dc
->xformVport2World
= dcs
->xformVport2World
;
414 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
416 dc
->wndOrgX
= dcs
->wndOrgX
;
417 dc
->wndOrgY
= dcs
->wndOrgY
;
418 dc
->wndExtX
= dcs
->wndExtX
;
419 dc
->wndExtY
= dcs
->wndExtY
;
420 dc
->vportOrgX
= dcs
->vportOrgX
;
421 dc
->vportOrgY
= dcs
->vportOrgY
;
422 dc
->vportExtX
= dcs
->vportExtX
;
423 dc
->vportExtY
= dcs
->vportExtY
;
427 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
432 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
435 CLIPPING_UpdateGCRegion( dc
);
437 SelectObject( hdc
, dcs
->hBitmap
);
438 SelectObject( hdc
, dcs
->hBrush
);
439 SelectObject( hdc
, dcs
->hFont
);
440 SelectObject( hdc
, dcs
->hPen
);
441 SetBkColor( hdc
, dcs
->backgroundColor
);
442 SetTextColor( hdc
, dcs
->textColor
);
443 GDISelectPalette( hdc
, dcs
->hPalette
, FALSE
);
444 GDI_ReleaseObj( hdcs
);
445 GDI_ReleaseObj( hdc
);
449 /***********************************************************************
450 * GetDCState (GDI.179)
452 HDC16 WINAPI
GetDCState16( HDC16 hdc
)
454 return HDC_16( GetDCState( HDC_32(hdc
) ));
458 /***********************************************************************
459 * SetDCState (GDI.180)
461 void WINAPI
SetDCState16( HDC16 hdc
, HDC16 hdcs
)
463 SetDCState( HDC_32(hdc
), HDC_32(hdcs
) );
467 /***********************************************************************
470 INT WINAPI
SaveDC( HDC hdc
)
476 dc
= DC_GetDCPtr( hdc
);
479 if(dc
->funcs
->pSaveDC
)
481 ret
= dc
->funcs
->pSaveDC( dc
->physDev
);
482 GDI_ReleaseObj( hdc
);
486 if (!(hdcs
= GetDCState( hdc
)))
488 GDI_ReleaseObj( hdc
);
491 dcs
= DC_GetDCPtr( hdcs
);
493 /* Copy path. The reason why path saving / restoring is in SaveDC/
494 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
495 * functions are only in Win16 (which doesn't have paths) and that
496 * SetDCState doesn't allow us to signal an error (which can happen
497 * when copying paths).
499 if (!PATH_AssignGdiPath( &dcs
->path
, &dc
->path
))
501 GDI_ReleaseObj( hdc
);
502 GDI_ReleaseObj( hdcs
);
507 dcs
->header
.hNext
= dc
->header
.hNext
;
508 dc
->header
.hNext
= HDC_16(hdcs
);
509 TRACE("(%p): returning %d\n", hdc
, dc
->saveLevel
+1 );
510 ret
= ++dc
->saveLevel
;
511 GDI_ReleaseObj( hdcs
);
512 GDI_ReleaseObj( hdc
);
517 /***********************************************************************
518 * RestoreDC (GDI32.@)
520 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
525 TRACE("%p %d\n", hdc
, level
);
526 dc
= DC_GetDCUpdate( hdc
);
527 if(!dc
) return FALSE
;
528 if(dc
->funcs
->pRestoreDC
)
530 success
= dc
->funcs
->pRestoreDC( dc
->physDev
, level
);
531 GDI_ReleaseObj( hdc
);
535 if (level
== -1) level
= dc
->saveLevel
;
537 /* This pair of checks disagrees with MSDN "Platform SDK:
538 Windows GDI" July 2000 which says all negative values
539 for level will be interpreted as an instance relative
540 to the current state. Restricting it to just -1 does
542 || (level
> dc
->saveLevel
))
544 GDI_ReleaseObj( hdc
);
549 while (dc
->saveLevel
>= level
)
551 HDC hdcs
= HDC_32(dc
->header
.hNext
);
552 if (!(dcs
= DC_GetDCPtr( hdcs
)))
554 GDI_ReleaseObj( hdc
);
557 dc
->header
.hNext
= dcs
->header
.hNext
;
558 if (--dc
->saveLevel
< level
)
560 SetDCState( hdc
, hdcs
);
561 if (!PATH_AssignGdiPath( &dc
->path
, &dcs
->path
))
562 /* FIXME: This might not be quite right, since we're
563 * returning FALSE but still destroying the saved DC state */
566 GDI_ReleaseObj( hdcs
);
567 GDI_ReleaseObj( hdc
);
569 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
571 GDI_ReleaseObj( hdc
);
576 /***********************************************************************
577 * CreateDCW (GDI32.@)
579 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
580 const DEVMODEW
*initData
)
584 const DC_FUNCTIONS
*funcs
;
589 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
591 if (!driver
) return 0;
592 strcpyW(buf
, driver
);
595 if (!(funcs
= DRIVER_load_driver( buf
)))
597 ERR( "no driver found for %s\n", debugstr_w(buf
) );
600 if (!(dc
= DC_AllocDC( funcs
, DC_MAGIC
)))
602 DRIVER_release_driver( funcs
);
606 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
608 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
609 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
611 if (dc
->funcs
->pCreateDC
&&
612 !dc
->funcs
->pCreateDC( dc
, &dc
->physDev
, buf
, device
, output
, initData
))
614 WARN("creation aborted by device\n" );
615 GDI_FreeObject( dc
->hSelf
, dc
);
616 DRIVER_release_driver( funcs
);
620 dc
->totalExtent
.left
= 0;
621 dc
->totalExtent
.top
= 0;
622 dc
->totalExtent
.right
= GetDeviceCaps( dc
->hSelf
, HORZRES
);
623 dc
->totalExtent
.bottom
= GetDeviceCaps( dc
->hSelf
, VERTRES
);
624 dc
->hVisRgn
= CreateRectRgnIndirect( &dc
->totalExtent
);
628 GDI_ReleaseObj( hdc
);
633 /***********************************************************************
634 * CreateDCA (GDI32.@)
636 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
637 const DEVMODEA
*initData
)
639 UNICODE_STRING driverW
, deviceW
, outputW
;
643 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
644 else driverW
.Buffer
= NULL
;
646 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
647 else deviceW
.Buffer
= NULL
;
649 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
650 else outputW
.Buffer
= NULL
;
652 if (initData
) initDataW
= GdiConvertToDevmodeW(initData
);
653 else initDataW
= NULL
;
655 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
657 RtlFreeUnicodeString(&driverW
);
658 RtlFreeUnicodeString(&deviceW
);
659 RtlFreeUnicodeString(&outputW
);
660 if (initDataW
) HeapFree(GetProcessHeap(), 0, initDataW
);
665 /***********************************************************************
666 * CreateICA (GDI32.@)
668 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
669 const DEVMODEA
* initData
)
671 /* Nothing special yet for ICs */
672 return CreateDCA( driver
, device
, output
, initData
);
676 /***********************************************************************
677 * CreateICW (GDI32.@)
679 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
680 const DEVMODEW
* initData
)
682 /* Nothing special yet for ICs */
683 return CreateDCW( driver
, device
, output
, initData
);
687 /***********************************************************************
688 * CreateCompatibleDC (GDI32.@)
690 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
693 const DC_FUNCTIONS
*funcs
;
698 if ((origDC
= GDI_GetObjPtr( hdc
, DC_MAGIC
)))
700 funcs
= origDC
->funcs
;
701 physDev
= origDC
->physDev
;
702 GDI_ReleaseObj( hdc
); /* can't hold the lock while loading the driver */
703 funcs
= DRIVER_get_driver( funcs
);
707 static const WCHAR displayW
[] = { 'd','i','s','p','l','a','y',0 };
708 funcs
= DRIVER_load_driver( displayW
);
712 if (!funcs
) return 0;
714 if (!(dc
= DC_AllocDC( funcs
, MEMORY_DC_MAGIC
)))
716 DRIVER_release_driver( funcs
);
720 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
722 dc
->hBitmap
= GetStockObject( DEFAULT_BITMAP
);
724 /* Copy the driver-specific physical device info into
725 * the new DC. The driver may use this read-only info
726 * while creating the compatible DC below. */
727 dc
->physDev
= physDev
;
729 if (dc
->funcs
->pCreateDC
&&
730 !dc
->funcs
->pCreateDC( dc
, &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
732 WARN("creation aborted by device\n");
733 GDI_FreeObject( dc
->hSelf
, dc
);
734 DRIVER_release_driver( funcs
);
738 dc
->totalExtent
.left
= 0;
739 dc
->totalExtent
.top
= 0;
740 dc
->totalExtent
.right
= 1; /* default bitmap is 1x1 */
741 dc
->totalExtent
.bottom
= 1;
742 dc
->hVisRgn
= CreateRectRgnIndirect( &dc
->totalExtent
);
745 GDI_ReleaseObj( dc
->hSelf
);
750 /***********************************************************************
753 BOOL WINAPI
DeleteDC( HDC hdc
)
755 const DC_FUNCTIONS
*funcs
= NULL
;
762 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
764 /* Call hook procedure to check whether is it OK to delete this DC */
767 DCHOOKPROC proc
= dc
->hookThunk
;
768 DWORD data
= dc
->dwHookData
;
769 GDI_ReleaseObj( hdc
);
770 if (!proc( HDC_16(hdc
), DCHC_DELETEDC
, data
, 0 )) return FALSE
;
771 if (!(dc
= DC_GetDCPtr( hdc
))) return TRUE
; /* deleted by the hook */
774 while (dc
->saveLevel
)
777 HDC hdcs
= HDC_32(dc
->header
.hNext
);
778 if (!(dcs
= DC_GetDCPtr( hdcs
))) break;
779 dc
->header
.hNext
= dcs
->header
.hNext
;
781 if (dcs
->hClipRgn
) DeleteObject( dcs
->hClipRgn
);
782 if (dcs
->hVisRgn
) DeleteObject( dcs
->hVisRgn
);
783 if (dcs
->hGCClipRgn
) DeleteObject( dcs
->hGCClipRgn
);
784 PATH_DestroyGdiPath(&dcs
->path
);
785 GDI_FreeObject( hdcs
, dcs
);
788 if (!(dc
->flags
& DC_SAVED
))
790 SelectObject( hdc
, GetStockObject(BLACK_PEN
) );
791 SelectObject( hdc
, GetStockObject(WHITE_BRUSH
) );
792 SelectObject( hdc
, GetStockObject(SYSTEM_FONT
) );
793 SelectObject( hdc
, GetStockObject(DEFAULT_BITMAP
) );
795 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
->physDev
);
799 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
800 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
801 if (dc
->hGCClipRgn
) DeleteObject( dc
->hGCClipRgn
);
802 PATH_DestroyGdiPath(&dc
->path
);
804 GDI_FreeObject( hdc
, dc
);
805 if (funcs
) DRIVER_release_driver( funcs
); /* do that after releasing the GDI lock */
810 /***********************************************************************
813 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
818 if ((dc
= DC_GetDCPtr( hdc
)))
820 if (dc
->funcs
->pResetDC
) ret
= dc
->funcs
->pResetDC( dc
->physDev
, devmode
);
821 GDI_ReleaseObj( hdc
);
827 /***********************************************************************
830 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
835 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
836 else devmodeW
= NULL
;
838 ret
= ResetDCW(hdc
, devmodeW
);
840 if (devmodeW
) HeapFree(GetProcessHeap(), 0, devmodeW
);
845 /***********************************************************************
846 * GetDeviceCaps (GDI32.@)
848 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
853 if ((dc
= DC_GetDCPtr( hdc
)))
855 if (dc
->funcs
->pGetDeviceCaps
) ret
= dc
->funcs
->pGetDeviceCaps( dc
->physDev
, cap
);
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 * SetTextColor (GDI32.@)
892 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
895 DC
* dc
= DC_GetDCPtr( hdc
);
897 TRACE(" hdc=%p color=0x%08lx\n", hdc
, color
);
899 if (!dc
) return CLR_INVALID
;
900 oldColor
= dc
->textColor
;
901 if (dc
->funcs
->pSetTextColor
)
903 color
= dc
->funcs
->pSetTextColor(dc
->physDev
, color
);
904 if (color
== CLR_INVALID
) /* don't change it */
907 oldColor
= CLR_INVALID
;
910 dc
->textColor
= color
;
911 GDI_ReleaseObj( hdc
);
916 /***********************************************************************
917 * SetTextAlign (GDI32.@)
919 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
922 DC
*dc
= DC_GetDCPtr( hdc
);
924 TRACE("hdc=%p align=%d\n", hdc
, align
);
927 if (dc
->funcs
->pSetTextAlign
)
928 prevAlign
= dc
->funcs
->pSetTextAlign(dc
->physDev
, align
);
930 prevAlign
= dc
->textAlign
;
931 dc
->textAlign
= align
;
933 GDI_ReleaseObj( hdc
);
937 /***********************************************************************
938 * GetDCOrgEx (GDI32.@)
940 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
944 if (!lpp
) return FALSE
;
945 if (!(dc
= DC_GetDCPtr( hDC
))) return FALSE
;
948 if (dc
->funcs
->pGetDCOrgEx
) dc
->funcs
->pGetDCOrgEx( dc
->physDev
, lpp
);
949 GDI_ReleaseObj( hDC
);
954 /***********************************************************************
957 DWORD WINAPI
SetDCOrg16( HDC16 hdc16
, INT16 x
, INT16 y
)
960 HDC hdc
= HDC_32( hdc16
);
961 DC
*dc
= DC_GetDCPtr( hdc
);
963 if (dc
->funcs
->pSetDCOrg
) prevOrg
= dc
->funcs
->pSetDCOrg( dc
->physDev
, x
, y
);
964 GDI_ReleaseObj( hdc
);
969 /***********************************************************************
970 * SetGraphicsMode (GDI32.@)
972 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
975 DC
*dc
= DC_GetDCPtr( hdc
);
977 /* One would think that setting the graphics mode to GM_COMPATIBLE
978 * would also reset the world transformation matrix to the unity
979 * matrix. However, in Windows, this is not the case. This doesn't
980 * make a lot of sense to me, but that's the way it is.
983 if ((mode
> 0) && (mode
<= GM_LAST
))
985 ret
= dc
->GraphicsMode
;
986 dc
->GraphicsMode
= mode
;
988 GDI_ReleaseObj( hdc
);
993 /***********************************************************************
994 * SetArcDirection (GDI32.@)
996 INT WINAPI
SetArcDirection( HDC hdc
, INT nDirection
)
999 INT nOldDirection
= 0;
1001 if (nDirection
!=AD_COUNTERCLOCKWISE
&& nDirection
!=AD_CLOCKWISE
)
1003 SetLastError(ERROR_INVALID_PARAMETER
);
1007 if ((dc
= DC_GetDCPtr( hdc
)))
1009 if (dc
->funcs
->pSetArcDirection
)
1011 dc
->funcs
->pSetArcDirection(dc
->physDev
, nDirection
);
1013 nOldDirection
= dc
->ArcDirection
;
1014 dc
->ArcDirection
= nDirection
;
1015 GDI_ReleaseObj( hdc
);
1017 return nOldDirection
;
1021 /***********************************************************************
1022 * GetWorldTransform (GDI32.@)
1024 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1027 if (!xform
) return FALSE
;
1028 if (!(dc
= DC_GetDCPtr( hdc
))) return FALSE
;
1029 *xform
= dc
->xformWorld2Wnd
;
1030 GDI_ReleaseObj( hdc
);
1035 /***********************************************************************
1036 * GetTransform (GDI32.@)
1038 BOOL WINAPI
GetTransform( HDC hdc
, DWORD unknown
, LPXFORM xform
)
1040 if (unknown
== 0x0203) return GetWorldTransform( hdc
, xform
);
1041 FIXME("stub: don't know what to do for code %lx\n", unknown
);
1046 /***********************************************************************
1047 * SetWorldTransform (GDI32.@)
1049 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
1052 DC
*dc
= DC_GetDCPtr( hdc
);
1054 if (!dc
) return FALSE
;
1055 if (!xform
) goto done
;
1057 /* Check that graphics mode is GM_ADVANCED */
1058 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1060 if (dc
->funcs
->pSetWorldTransform
)
1062 ret
= dc
->funcs
->pSetWorldTransform(dc
->physDev
, xform
);
1063 if (!ret
) goto done
;
1066 dc
->xformWorld2Wnd
= *xform
;
1067 DC_UpdateXforms( dc
);
1070 GDI_ReleaseObj( hdc
);
1075 /****************************************************************************
1076 * ModifyWorldTransform [GDI32.@]
1077 * Modifies the world transformation for a device context.
1080 * hdc [I] Handle to device context
1081 * xform [I] XFORM structure that will be used to modify the world
1083 * iMode [I] Specifies in what way to modify the world transformation
1086 * Resets the world transformation to the identity matrix.
1087 * The parameter xform is ignored.
1089 * Multiplies xform into the world transformation matrix from
1092 * Multiplies xform into the world transformation matrix from
1097 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
,
1101 DC
*dc
= DC_GetDCPtr( hdc
);
1103 /* Check for illegal parameters */
1104 if (!dc
) return FALSE
;
1105 if (!xform
) goto done
;
1107 /* Check that graphics mode is GM_ADVANCED */
1108 if (dc
->GraphicsMode
!=GM_ADVANCED
) goto done
;
1110 if (dc
->funcs
->pModifyWorldTransform
)
1112 ret
= dc
->funcs
->pModifyWorldTransform(dc
->physDev
, xform
, iMode
);
1113 if (!ret
) goto done
;
1119 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
1120 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
1121 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
1122 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
1123 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
1124 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
1126 case MWT_LEFTMULTIPLY
:
1127 CombineTransform( &dc
->xformWorld2Wnd
, xform
,
1128 &dc
->xformWorld2Wnd
);
1130 case MWT_RIGHTMULTIPLY
:
1131 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
,
1138 DC_UpdateXforms( dc
);
1141 GDI_ReleaseObj( hdc
);
1146 /****************************************************************************
1147 * CombineTransform [GDI32.@]
1148 * Combines two transformation matrices.
1151 * xformResult [O] Stores the result of combining the two matrices
1152 * xform1 [I] Specifies the first matrix to apply
1153 * xform2 [I] Specifies the second matrix to apply
1156 * The same matrix can be passed in for more than one of the parameters.
1160 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1161 const XFORM
*xform2
)
1165 /* Check for illegal parameters */
1166 if (!xformResult
|| !xform1
|| !xform2
)
1169 /* Create the result in a temporary XFORM, since xformResult may be
1170 * equal to xform1 or xform2 */
1171 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1172 xform1
->eM12
* xform2
->eM21
;
1173 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1174 xform1
->eM12
* xform2
->eM22
;
1175 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1176 xform1
->eM22
* xform2
->eM21
;
1177 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1178 xform1
->eM22
* xform2
->eM22
;
1179 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1180 xform1
->eDy
* xform2
->eM21
+
1182 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1183 xform1
->eDy
* xform2
->eM22
+
1186 /* Copy the result to xformResult */
1187 *xformResult
= xformTemp
;
1193 /***********************************************************************
1194 * SetDCHook (GDI32.@)
1196 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1198 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD dwHookData
)
1200 DC
*dc
= GDI_GetObjPtr( hdc
, DC_MAGIC
);
1202 if (!dc
) return FALSE
;
1204 if (!(dc
->flags
& DC_SAVED
))
1206 dc
->dwHookData
= dwHookData
;
1207 dc
->hookThunk
= hookProc
;
1209 GDI_ReleaseObj( hdc
);
1214 /* relay function to call the 16-bit DC hook proc */
1215 static BOOL16 WINAPI
call_dc_hook16( HDC16 hdc16
, WORD code
, DWORD data
, LPARAM lParam
)
1219 FARPROC16 proc
= NULL
;
1220 HDC hdc
= HDC_32( hdc16
);
1221 DC
*dc
= DC_GetDCPtr( hdc
);
1223 if (!dc
) return FALSE
;
1224 proc
= dc
->hookProc
;
1225 GDI_ReleaseObj( hdc
);
1226 if (!proc
) return FALSE
;
1229 args
[3] = HIWORD(data
);
1230 args
[2] = LOWORD(data
);
1231 args
[1] = HIWORD(lParam
);
1232 args
[0] = LOWORD(lParam
);
1233 WOWCallback16Ex( (DWORD
)proc
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
1237 /***********************************************************************
1238 * SetDCHook (GDI.190)
1240 BOOL16 WINAPI
SetDCHook16( HDC16 hdc16
, FARPROC16 hookProc
, DWORD dwHookData
)
1242 HDC hdc
= HDC_32( hdc16
);
1243 DC
*dc
= DC_GetDCPtr( hdc
);
1244 if (!dc
) return FALSE
;
1246 dc
->hookProc
= hookProc
;
1247 GDI_ReleaseObj( hdc
);
1248 return SetDCHook( hdc
, call_dc_hook16
, dwHookData
);
1252 /***********************************************************************
1253 * GetDCHook (GDI.191)
1255 DWORD WINAPI
GetDCHook16( HDC16 hdc16
, FARPROC16
*phookProc
)
1257 HDC hdc
= HDC_32( hdc16
);
1258 DC
*dc
= DC_GetDCPtr( hdc
);
1262 *phookProc
= dc
->hookProc
;
1263 ret
= dc
->dwHookData
;
1264 GDI_ReleaseObj( hdc
);
1269 /***********************************************************************
1270 * SetHookFlags (GDI.192)
1272 WORD WINAPI
SetHookFlags16(HDC16 hdc16
, WORD flags
)
1274 HDC hdc
= HDC_32( hdc16
);
1275 DC
*dc
= DC_GetDCPtr( hdc
);
1279 WORD wRet
= dc
->flags
& DC_DIRTY
;
1281 /* "Undocumented Windows" info is slightly confusing.
1284 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1286 if( flags
& DCHF_INVALIDATEVISRGN
)
1287 dc
->flags
|= DC_DIRTY
;
1288 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1289 dc
->flags
&= ~DC_DIRTY
;
1290 GDI_ReleaseObj( hdc
);
1296 /***********************************************************************
1297 * SetICMMode (GDI32.@)
1299 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1301 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1302 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1303 if (iEnableICM
== ICM_ON
) return 0;
1304 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1308 /***********************************************************************
1309 * GetDeviceGammaRamp (GDI32.@)
1311 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1314 DC
*dc
= DC_GetDCPtr( hDC
);
1318 if (dc
->funcs
->pGetDeviceGammaRamp
)
1319 ret
= dc
->funcs
->pGetDeviceGammaRamp(dc
->physDev
, ptr
);
1320 GDI_ReleaseObj( hDC
);
1325 /***********************************************************************
1326 * SetDeviceGammaRamp (GDI32.@)
1328 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1331 DC
*dc
= DC_GetDCPtr( hDC
);
1335 if (dc
->funcs
->pSetDeviceGammaRamp
)
1336 ret
= dc
->funcs
->pSetDeviceGammaRamp(dc
->physDev
, ptr
);
1337 GDI_ReleaseObj( hDC
);
1342 /***********************************************************************
1343 * GetColorSpace (GDI32.@)
1345 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1347 /*FIXME Need to to whatever GetColorSpace actually does */
1351 /***********************************************************************
1352 * CreateColorSpaceA (GDI32.@)
1354 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1360 /***********************************************************************
1361 * CreateColorSpaceW (GDI32.@)
1363 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1369 /***********************************************************************
1370 * DeleteColorSpace (GDI32.@)
1372 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1379 /***********************************************************************
1380 * SetColorSpace (GDI32.@)
1382 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1389 /***********************************************************************
1390 * GetBoundsRect (GDI.194)
1392 UINT16 WINAPI
GetBoundsRect16(HDC16 hdc
, LPRECT16 rect
, UINT16 flags
)
1394 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1397 /***********************************************************************
1398 * GetBoundsRect (GDI32.@)
1400 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1402 FIXME("(): stub\n");
1403 return DCB_RESET
; /* bounding rectangle always empty */
1406 /***********************************************************************
1407 * SetBoundsRect (GDI.193)
1409 UINT16 WINAPI
SetBoundsRect16(HDC16 hdc
, const RECT16
* rect
, UINT16 flags
)
1411 if ( (flags
& DCB_ACCUMULATE
) || (flags
& DCB_ENABLE
) )
1412 FIXME("(%04x, %p, %04x): stub\n", hdc
, rect
, flags
);
1414 return DCB_RESET
| DCB_DISABLE
; /* bounding rectangle always empty and disabled*/
1417 /***********************************************************************
1418 * SetBoundsRect (GDI32.@)
1420 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1422 FIXME("(): stub\n");
1423 return DCB_DISABLE
; /* bounding rectangle always empty */
1427 /***********************************************************************
1428 * GetRelAbs (GDI32.@)
1430 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1433 DC
*dc
= DC_GetDCPtr( hdc
);
1434 if (dc
) ret
= dc
->relAbsMode
;
1435 GDI_ReleaseObj( hdc
);
1439 /***********************************************************************
1440 * GetLayout (GDI32.@)
1442 * Gets left->right or right->left text layout flags of a dc.
1443 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1446 DWORD WINAPI
GetLayout(HDC hdc
)
1448 FIXME("(%p): stub\n", hdc
);
1449 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1453 /***********************************************************************
1454 * SetLayout (GDI32.@)
1456 * Sets left->right or right->left text layout flags of a dc.
1457 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1460 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1462 FIXME("(%p,%08lx): stub\n", hdc
, layout
);
1463 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1467 /***********************************************************************
1468 * GetDCBrushColor (GDI32.@)
1470 * Retrieves the current brush color for the specified device
1474 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1477 COLORREF dcBrushColor
= CLR_INVALID
;
1479 TRACE("hdc(%p)\n", hdc
);
1481 dc
= DC_GetDCPtr( hdc
);
1484 dcBrushColor
= dc
->dcBrushColor
;
1485 GDI_ReleaseObj( hdc
);
1488 return dcBrushColor
;
1491 /***********************************************************************
1492 * SetDCBrushColor (GDI32.@)
1494 * Sets the current device context (DC) brush color to the specified
1495 * color value. If the device cannot represent the specified color
1496 * value, the color is set to the nearest physical color.
1499 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1502 COLORREF oldClr
= CLR_INVALID
;
1504 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
1506 dc
= DC_GetDCPtr( hdc
);
1509 if (dc
->funcs
->pSetDCBrushColor
)
1510 crColor
= dc
->funcs
->pSetDCBrushColor( dc
->physDev
, crColor
);
1511 else if (dc
->hBrush
== GetStockObject( DC_BRUSH
))
1513 /* If DC_BRUSH is selected, update driver pen color */
1514 HBRUSH hBrush
= CreateSolidBrush( crColor
);
1515 dc
->funcs
->pSelectBrush( dc
->physDev
, hBrush
);
1516 DeleteObject( hBrush
);
1519 if (crColor
!= CLR_INVALID
)
1521 oldClr
= dc
->dcBrushColor
;
1522 dc
->dcBrushColor
= crColor
;
1525 GDI_ReleaseObj( hdc
);
1531 /***********************************************************************
1532 * GetDCPenColor (GDI32.@)
1534 * Retrieves the current pen color for the specified device
1538 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1541 COLORREF dcPenColor
= CLR_INVALID
;
1543 TRACE("hdc(%p)\n", hdc
);
1545 dc
= DC_GetDCPtr( hdc
);
1548 dcPenColor
= dc
->dcPenColor
;
1549 GDI_ReleaseObj( hdc
);
1555 /***********************************************************************
1556 * SetDCPenColor (GDI32.@)
1558 * Sets the current device context (DC) pen color to the specified
1559 * color value. If the device cannot represent the specified color
1560 * value, the color is set to the nearest physical color.
1563 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
1566 COLORREF oldClr
= CLR_INVALID
;
1568 TRACE("hdc(%p) crColor(%08lx)\n", hdc
, crColor
);
1570 dc
= DC_GetDCPtr( hdc
);
1573 if (dc
->funcs
->pSetDCPenColor
)
1574 crColor
= dc
->funcs
->pSetDCPenColor( dc
->physDev
, crColor
);
1575 else if (dc
->hPen
== GetStockObject( DC_PEN
))
1577 /* If DC_PEN is selected, update the driver pen color */
1578 LOGPEN logpen
= { PS_SOLID
, { 0, 0 }, crColor
};
1579 HPEN hPen
= CreatePenIndirect( &logpen
);
1580 dc
->funcs
->pSelectPen( dc
->physDev
, hPen
);
1581 DeleteObject( hPen
);
1584 if (crColor
!= CLR_INVALID
)
1586 oldClr
= dc
->dcPenColor
;
1587 dc
->dcPenColor
= crColor
;
1590 GDI_ReleaseObj( hdc
);
1596 /***********************************************************************
1597 * SetVirtualResolution (GDI32.@)
1599 * Undocumented on msdn. Called when PowerPoint XP saves a file.
1601 DWORD WINAPI
SetVirtualResolution(HDC hdc
, DWORD dw2
, DWORD dw3
, DWORD dw4
, DWORD dw5
)
1603 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc
, dw2
, dw3
, dw4
, dw5
);