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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/winuser16.h"
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc);
40 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
42 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
44 static const struct gdi_obj_funcs dc_funcs =
46 NULL, /* pSelectObject */
47 NULL, /* pGetObject16 */
48 NULL, /* pGetObjectA */
49 NULL, /* pGetObjectW */
50 NULL, /* pUnrealizeObject */
51 DC_DeleteObject /* pDeleteObject */
54 /***********************************************************************
57 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
62 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
80 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
87 dc->hPen = GetStockObject( BLACK_PEN );
88 dc->hBrush = GetStockObject( WHITE_BRUSH );
89 dc->hFont = GetStockObject( SYSTEM_FONT );
92 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
94 dc->ROPmode = R2_COPYPEN;
95 dc->polyFillMode = ALTERNATE;
96 dc->stretchBltMode = BLACKONWHITE;
97 dc->relAbsMode = ABSOLUTE;
98 dc->backgroundMode = OPAQUE;
99 dc->backgroundColor = RGB( 255, 255, 255 );
100 dc->dcBrushColor = RGB( 255, 255, 255 );
101 dc->dcPenColor = RGB( 0, 0, 0 );
102 dc->textColor = RGB( 0, 0, 0 );
105 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
109 dc->MapMode = MM_TEXT;
110 dc->GraphicsMode = GM_COMPATIBLE;
111 dc->pAbortProc = NULL;
114 dc->ArcDirection = AD_COUNTERCLOCKWISE;
115 dc->xformWorld2Wnd.eM11 = 1.0f;
116 dc->xformWorld2Wnd.eM12 = 0.0f;
117 dc->xformWorld2Wnd.eM21 = 0.0f;
118 dc->xformWorld2Wnd.eM22 = 1.0f;
119 dc->xformWorld2Wnd.eDx = 0.0f;
120 dc->xformWorld2Wnd.eDy = 0.0f;
121 dc->xformWorld2Vport = dc->xformWorld2Wnd;
122 dc->xformVport2World = dc->xformWorld2Wnd;
123 dc->vport2WorldValid = TRUE;
124 dc->BoundsRect.left = 0;
125 dc->BoundsRect.top = 0;
126 dc->BoundsRect.right = 0;
127 dc->BoundsRect.bottom = 0;
128 dc->saved_visrgn = NULL;
129 PATH_InitGdiPath(&dc->path);
135 /***********************************************************************
138 DC *DC_GetDCPtr( HDC hdc )
140 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
141 if (!ptr) return NULL;
142 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
143 (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
144 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
145 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
147 GDI_ReleaseObj( hdc );
148 SetLastError( ERROR_INVALID_HANDLE );
152 /***********************************************************************
155 * Retrieve a DC ptr while making sure the visRgn is updated.
156 * This function may call up to USER so the GDI lock should _not_
157 * be held when calling it.
159 DC *DC_GetDCUpdate( HDC hdc )
161 DC *dc = DC_GetDCPtr( hdc );
162 if (!dc) return NULL;
163 while (dc->flags & DC_DIRTY)
165 DCHOOKPROC proc = dc->hookThunk;
166 dc->flags &= ~DC_DIRTY;
169 DWORD_PTR data = dc->dwHookData;
170 DC_ReleaseDCPtr( dc );
171 proc( hdc, DCHC_INVALIDVISRGN, data, 0 );
172 if (!(dc = DC_GetDCPtr( hdc ))) break;
173 /* otherwise restart the loop in case it became dirty again in the meantime */
180 /***********************************************************************
183 void DC_ReleaseDCPtr( DC *dc )
185 GDI_ReleaseObj( dc->hSelf );
189 /***********************************************************************
192 BOOL DC_FreeDCPtr( DC *dc )
194 return GDI_FreeObject( dc->hSelf, dc );
198 /***********************************************************************
201 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
203 DC_ReleaseDCPtr( obj );
204 return DeleteDC( handle );
208 /***********************************************************************
211 * Setup device-specific DC values for a newly created DC.
213 void DC_InitDC( DC* dc )
215 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
216 SetTextColor( dc->hSelf, dc->textColor );
217 SetBkColor( dc->hSelf, dc->backgroundColor );
218 SelectObject( dc->hSelf, dc->hPen );
219 SelectObject( dc->hSelf, dc->hBrush );
220 SelectObject( dc->hSelf, dc->hFont );
221 CLIPPING_UpdateGCRegion( dc );
225 /***********************************************************************
228 * Computes the inverse of the transformation xformSrc and stores it to
229 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
232 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
236 determinant = xformSrc->eM11*xformSrc->eM22 -
237 xformSrc->eM12*xformSrc->eM21;
238 if (determinant > -1e-12 && determinant < 1e-12)
241 xformDest->eM11 = xformSrc->eM22 / determinant;
242 xformDest->eM12 = -xformSrc->eM12 / determinant;
243 xformDest->eM21 = -xformSrc->eM21 / determinant;
244 xformDest->eM22 = xformSrc->eM11 / determinant;
245 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
246 xformSrc->eDy * xformDest->eM21;
247 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
248 xformSrc->eDy * xformDest->eM22;
254 /***********************************************************************
257 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
258 * fields of the specified DC by creating a transformation that
259 * represents the current mapping mode and combining it with the DC's
260 * world transform. This function should be called whenever the
261 * parameters associated with the mapping mode (window and viewport
262 * extents and origins) or the world transform change.
264 void DC_UpdateXforms( DC *dc )
266 XFORM xformWnd2Vport, oldworld2vport;
267 FLOAT scaleX, scaleY;
269 /* Construct a transformation to do the window-to-viewport conversion */
270 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
271 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
272 xformWnd2Vport.eM11 = scaleX;
273 xformWnd2Vport.eM12 = 0.0;
274 xformWnd2Vport.eM21 = 0.0;
275 xformWnd2Vport.eM22 = scaleY;
276 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
277 scaleX * (FLOAT)dc->wndOrgX;
278 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
279 scaleY * (FLOAT)dc->wndOrgY;
281 oldworld2vport = dc->xformWorld2Vport;
282 /* Combine with the world transformation */
283 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
286 /* Create inverse of world-to-viewport transformation */
287 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
288 &dc->xformVport2World );
290 /* Reselect the font and pen back into the dc so that the size
292 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
294 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
295 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
300 /***********************************************************************
301 * GetDCState (Not a Windows API)
303 HDC WINAPI GetDCState( HDC hdc )
308 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
309 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
311 DC_ReleaseDCPtr( dc );
314 TRACE("(%p): returning %p\n", hdc, handle );
316 newdc->flags = dc->flags | DC_SAVED;
317 newdc->layout = dc->layout;
318 newdc->hPen = dc->hPen;
319 newdc->hBrush = dc->hBrush;
320 newdc->hFont = dc->hFont;
321 newdc->hBitmap = dc->hBitmap;
322 newdc->hDevice = dc->hDevice;
323 newdc->hPalette = dc->hPalette;
324 newdc->ROPmode = dc->ROPmode;
325 newdc->polyFillMode = dc->polyFillMode;
326 newdc->stretchBltMode = dc->stretchBltMode;
327 newdc->relAbsMode = dc->relAbsMode;
328 newdc->backgroundMode = dc->backgroundMode;
329 newdc->backgroundColor = dc->backgroundColor;
330 newdc->textColor = dc->textColor;
331 newdc->dcBrushColor = dc->dcBrushColor;
332 newdc->dcPenColor = dc->dcPenColor;
333 newdc->brushOrgX = dc->brushOrgX;
334 newdc->brushOrgY = dc->brushOrgY;
335 newdc->textAlign = dc->textAlign;
336 newdc->charExtra = dc->charExtra;
337 newdc->breakExtra = dc->breakExtra;
338 newdc->breakRem = dc->breakRem;
339 newdc->MapMode = dc->MapMode;
340 newdc->GraphicsMode = dc->GraphicsMode;
341 newdc->CursPosX = dc->CursPosX;
342 newdc->CursPosY = dc->CursPosY;
343 newdc->ArcDirection = dc->ArcDirection;
344 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
345 newdc->xformWorld2Vport = dc->xformWorld2Vport;
346 newdc->xformVport2World = dc->xformVport2World;
347 newdc->vport2WorldValid = dc->vport2WorldValid;
348 newdc->wndOrgX = dc->wndOrgX;
349 newdc->wndOrgY = dc->wndOrgY;
350 newdc->wndExtX = dc->wndExtX;
351 newdc->wndExtY = dc->wndExtY;
352 newdc->vportOrgX = dc->vportOrgX;
353 newdc->vportOrgY = dc->vportOrgY;
354 newdc->vportExtX = dc->vportExtX;
355 newdc->vportExtY = dc->vportExtY;
356 newdc->BoundsRect = dc->BoundsRect;
358 newdc->hSelf = (HDC)handle;
359 newdc->saveLevel = 0;
362 PATH_InitGdiPath( &newdc->path );
364 newdc->pAbortProc = NULL;
365 newdc->hookThunk = NULL;
367 newdc->saved_visrgn = NULL;
369 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
374 newdc->hMetaClipRgn = 0;
377 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
378 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
382 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
383 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
385 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
388 newdc->gdiFont = dc->gdiFont;
392 DC_ReleaseDCPtr( newdc );
393 DC_ReleaseDCPtr( dc );
398 /***********************************************************************
399 * SetDCState (Not a Windows API)
401 void WINAPI SetDCState( HDC hdc, HDC hdcs )
405 if (!(dc = DC_GetDCUpdate( hdc ))) return;
406 if (!(dcs = DC_GetDCPtr( hdcs )))
408 DC_ReleaseDCPtr( dc );
411 if (!dcs->flags & DC_SAVED)
413 DC_ReleaseDCPtr( dc );
414 DC_ReleaseDCPtr( dcs );
417 TRACE("%p %p\n", hdc, hdcs );
419 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
420 dc->layout = dcs->layout;
421 dc->hDevice = dcs->hDevice;
422 dc->ROPmode = dcs->ROPmode;
423 dc->polyFillMode = dcs->polyFillMode;
424 dc->stretchBltMode = dcs->stretchBltMode;
425 dc->relAbsMode = dcs->relAbsMode;
426 dc->backgroundMode = dcs->backgroundMode;
427 dc->backgroundColor = dcs->backgroundColor;
428 dc->textColor = dcs->textColor;
429 dc->dcBrushColor = dcs->dcBrushColor;
430 dc->dcPenColor = dcs->dcPenColor;
431 dc->brushOrgX = dcs->brushOrgX;
432 dc->brushOrgY = dcs->brushOrgY;
433 dc->textAlign = dcs->textAlign;
434 dc->charExtra = dcs->charExtra;
435 dc->breakExtra = dcs->breakExtra;
436 dc->breakRem = dcs->breakRem;
437 dc->MapMode = dcs->MapMode;
438 dc->GraphicsMode = dcs->GraphicsMode;
439 dc->CursPosX = dcs->CursPosX;
440 dc->CursPosY = dcs->CursPosY;
441 dc->ArcDirection = dcs->ArcDirection;
442 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
443 dc->xformWorld2Vport = dcs->xformWorld2Vport;
444 dc->xformVport2World = dcs->xformVport2World;
445 dc->vport2WorldValid = dcs->vport2WorldValid;
446 dc->BoundsRect = dcs->BoundsRect;
448 dc->wndOrgX = dcs->wndOrgX;
449 dc->wndOrgY = dcs->wndOrgY;
450 dc->wndExtX = dcs->wndExtX;
451 dc->wndExtY = dcs->wndExtY;
452 dc->vportOrgX = dcs->vportOrgX;
453 dc->vportOrgY = dcs->vportOrgY;
454 dc->vportExtX = dcs->vportExtX;
455 dc->vportExtY = dcs->vportExtY;
459 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
460 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
464 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
469 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
470 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
474 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
477 CLIPPING_UpdateGCRegion( dc );
479 SelectObject( hdc, dcs->hBitmap );
480 SelectObject( hdc, dcs->hBrush );
481 SelectObject( hdc, dcs->hFont );
482 SelectObject( hdc, dcs->hPen );
483 SetBkColor( hdc, dcs->backgroundColor);
484 SetTextColor( hdc, dcs->textColor);
485 GDISelectPalette( hdc, dcs->hPalette, FALSE );
486 DC_ReleaseDCPtr( dcs );
487 DC_ReleaseDCPtr( dc );
491 /***********************************************************************
492 * GetDCState (GDI.179)
494 HDC16 WINAPI GetDCState16( HDC16 hdc )
496 return HDC_16( GetDCState( HDC_32(hdc) ));
500 /***********************************************************************
501 * SetDCState (GDI.180)
503 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
505 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
509 /***********************************************************************
512 INT WINAPI SaveDC( HDC hdc )
518 dc = DC_GetDCPtr( hdc );
521 if(dc->funcs->pSaveDC)
523 ret = dc->funcs->pSaveDC( dc->physDev );
525 ret = ++dc->saveLevel;
526 DC_ReleaseDCPtr( dc );
530 if (!(hdcs = GetDCState( hdc )))
532 DC_ReleaseDCPtr( dc );
535 dcs = DC_GetDCPtr( hdcs );
537 /* Copy path. The reason why path saving / restoring is in SaveDC/
538 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
539 * functions are only in Win16 (which doesn't have paths) and that
540 * SetDCState doesn't allow us to signal an error (which can happen
541 * when copying paths).
543 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
545 DC_ReleaseDCPtr( dc );
546 DC_ReleaseDCPtr( dcs );
551 dcs->saved_dc = dc->saved_dc;
553 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
554 ret = ++dc->saveLevel;
555 DC_ReleaseDCPtr( dcs );
556 DC_ReleaseDCPtr( dc );
561 /***********************************************************************
562 * RestoreDC (GDI32.@)
564 BOOL WINAPI RestoreDC( HDC hdc, INT level )
569 TRACE("%p %d\n", hdc, level );
570 dc = DC_GetDCUpdate( hdc );
571 if(!dc) return FALSE;
573 if(abs(level) > dc->saveLevel || level == 0)
575 DC_ReleaseDCPtr( dc );
579 if(dc->funcs->pRestoreDC)
581 success = dc->funcs->pRestoreDC( dc->physDev, level );
582 if(level < 0) level = dc->saveLevel + level + 1;
584 dc->saveLevel = level - 1;
585 DC_ReleaseDCPtr( dc );
589 if (level < 0) level = dc->saveLevel + level + 1;
591 while (dc->saveLevel >= level)
593 HDC hdcs = dc->saved_dc;
594 if (!(dcs = DC_GetDCPtr( hdcs )))
596 DC_ReleaseDCPtr( dc );
599 dc->saved_dc = dcs->saved_dc;
601 if (--dc->saveLevel < level)
603 SetDCState( hdc, hdcs );
604 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
605 /* FIXME: This might not be quite right, since we're
606 * returning FALSE but still destroying the saved DC state */
609 DC_ReleaseDCPtr( dcs );
610 DC_ReleaseDCPtr( dc );
612 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
614 DC_ReleaseDCPtr( dc );
619 /***********************************************************************
620 * CreateDCW (GDI32.@)
622 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
623 const DEVMODEW *initData )
627 const DC_FUNCTIONS *funcs;
632 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
636 ERR( "no device found for %s\n", debugstr_w(device) );
639 strcpyW(buf, driver);
642 if (!(funcs = DRIVER_load_driver( buf )))
644 ERR( "no driver found for %s\n", debugstr_w(buf) );
647 if (!(dc = DC_AllocDC( funcs, DC_MAGIC ))) goto error;
650 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
651 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
653 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
654 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
656 if (dc->funcs->pCreateDC &&
657 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
659 WARN("creation aborted by device\n" );
663 SetRectRgn( dc->hVisRgn, 0, 0,
664 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
667 DC_ReleaseDCPtr( dc );
671 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
672 if (dc) DC_FreeDCPtr( dc );
673 DRIVER_release_driver( funcs );
678 /***********************************************************************
679 * CreateDCA (GDI32.@)
681 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
682 const DEVMODEA *initData )
684 UNICODE_STRING driverW, deviceW, outputW;
688 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
689 else driverW.Buffer = NULL;
691 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
692 else deviceW.Buffer = NULL;
694 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
695 else outputW.Buffer = NULL;
700 /* don't convert initData for DISPLAY driver, it's not used */
701 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
702 initDataW = GdiConvertToDevmodeW(initData);
705 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
707 RtlFreeUnicodeString(&driverW);
708 RtlFreeUnicodeString(&deviceW);
709 RtlFreeUnicodeString(&outputW);
710 HeapFree(GetProcessHeap(), 0, initDataW);
715 /***********************************************************************
716 * CreateICA (GDI32.@)
718 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
719 const DEVMODEA* initData )
721 /* Nothing special yet for ICs */
722 return CreateDCA( driver, device, output, initData );
726 /***********************************************************************
727 * CreateICW (GDI32.@)
729 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
730 const DEVMODEW* initData )
732 /* Nothing special yet for ICs */
733 return CreateDCW( driver, device, output, initData );
737 /***********************************************************************
738 * CreateCompatibleDC (GDI32.@)
740 HDC WINAPI CreateCompatibleDC( HDC hdc )
743 const DC_FUNCTIONS *funcs;
748 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
750 funcs = origDC->funcs;
751 physDev = origDC->physDev;
752 DC_ReleaseDCPtr( origDC ); /* can't hold the lock while loading the driver */
753 funcs = DRIVER_get_driver( funcs );
757 funcs = DRIVER_load_driver( displayW );
761 if (!funcs) return 0;
763 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC ))) goto error;
765 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
767 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
768 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
770 /* Copy the driver-specific physical device info into
771 * the new DC. The driver may use this read-only info
772 * while creating the compatible DC below. */
773 dc->physDev = physDev;
775 if (dc->funcs->pCreateDC &&
776 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
778 WARN("creation aborted by device\n");
783 DC_ReleaseDCPtr( dc );
787 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
788 if (dc) DC_FreeDCPtr( dc );
789 DRIVER_release_driver( funcs );
794 /***********************************************************************
797 BOOL WINAPI DeleteDC( HDC hdc )
799 const DC_FUNCTIONS *funcs = NULL;
806 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
808 /* Call hook procedure to check whether is it OK to delete this DC */
811 DCHOOKPROC proc = dc->hookThunk;
812 DWORD_PTR data = dc->dwHookData;
813 DC_ReleaseDCPtr( dc );
814 if (!proc( hdc, DCHC_DELETEDC, data, 0 )) return FALSE;
815 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
818 while (dc->saveLevel)
821 HDC hdcs = dc->saved_dc;
822 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
823 dc->saved_dc = dcs->saved_dc;
825 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
826 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
827 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
828 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
829 PATH_DestroyGdiPath(&dcs->path);
833 if (!(dc->flags & DC_SAVED))
835 SelectObject( hdc, GetStockObject(BLACK_PEN) );
836 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
837 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
838 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
840 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
844 while (dc->saved_visrgn)
846 struct saved_visrgn *next = dc->saved_visrgn->next;
847 DeleteObject( dc->saved_visrgn->hrgn );
848 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
849 dc->saved_visrgn = next;
851 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
852 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
853 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
854 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
855 PATH_DestroyGdiPath(&dc->path);
858 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
863 /***********************************************************************
866 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
871 if ((dc = DC_GetDCPtr( hdc )))
873 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
874 DC_ReleaseDCPtr( dc );
880 /***********************************************************************
883 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
888 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
889 else devmodeW = NULL;
891 ret = ResetDCW(hdc, devmodeW);
893 HeapFree(GetProcessHeap(), 0, devmodeW);
898 /***********************************************************************
899 * GetDeviceCaps (GDI32.@)
901 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
906 if ((dc = DC_GetDCPtr( hdc )))
908 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
909 else switch(cap) /* return meaningful values for some entries */
911 case HORZRES: ret = 640; break;
912 case VERTRES: ret = 480; break;
913 case BITSPIXEL: ret = 1; break;
914 case PLANES: ret = 1; break;
915 case NUMCOLORS: ret = 2; break;
916 case ASPECTX: ret = 36; break;
917 case ASPECTY: ret = 36; break;
918 case ASPECTXY: ret = 51; break;
919 case LOGPIXELSX: ret = 72; break;
920 case LOGPIXELSY: ret = 72; break;
921 case SIZEPALETTE: ret = 2; break;
923 DC_ReleaseDCPtr( dc );
929 /***********************************************************************
930 * GetBkColor (GDI32.@)
932 COLORREF WINAPI GetBkColor( HDC hdc )
935 DC * dc = DC_GetDCPtr( hdc );
938 ret = dc->backgroundColor;
939 DC_ReleaseDCPtr( dc );
945 /***********************************************************************
946 * SetBkColor (GDI32.@)
948 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
951 DC * dc = DC_GetDCPtr( hdc );
953 TRACE("hdc=%p color=0x%08x\n", hdc, color);
955 if (!dc) return CLR_INVALID;
956 oldColor = dc->backgroundColor;
957 if (dc->funcs->pSetBkColor)
959 color = dc->funcs->pSetBkColor(dc->physDev, color);
960 if (color == CLR_INVALID) /* don't change it */
963 oldColor = CLR_INVALID;
966 dc->backgroundColor = color;
967 DC_ReleaseDCPtr( dc );
972 /***********************************************************************
973 * GetTextColor (GDI32.@)
975 COLORREF WINAPI GetTextColor( HDC hdc )
978 DC * dc = DC_GetDCPtr( hdc );
982 DC_ReleaseDCPtr( dc );
988 /***********************************************************************
989 * SetTextColor (GDI32.@)
991 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
994 DC * dc = DC_GetDCPtr( hdc );
996 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
998 if (!dc) return CLR_INVALID;
999 oldColor = dc->textColor;
1000 if (dc->funcs->pSetTextColor)
1002 color = dc->funcs->pSetTextColor(dc->physDev, color);
1003 if (color == CLR_INVALID) /* don't change it */
1006 oldColor = CLR_INVALID;
1009 dc->textColor = color;
1010 DC_ReleaseDCPtr( dc );
1015 /***********************************************************************
1016 * GetTextAlign (GDI32.@)
1018 UINT WINAPI GetTextAlign( HDC hdc )
1021 DC * dc = DC_GetDCPtr( hdc );
1024 ret = dc->textAlign;
1025 DC_ReleaseDCPtr( dc );
1031 /***********************************************************************
1032 * SetTextAlign (GDI32.@)
1034 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1037 DC *dc = DC_GetDCPtr( hdc );
1039 TRACE("hdc=%p align=%d\n", hdc, align);
1041 if (!dc) return 0x0;
1042 ret = dc->textAlign;
1043 if (dc->funcs->pSetTextAlign)
1044 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1046 if (ret != GDI_ERROR)
1047 dc->textAlign = align;
1048 DC_ReleaseDCPtr( dc );
1052 /***********************************************************************
1053 * GetDCOrgEx (GDI32.@)
1055 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1059 if (!lpp) return FALSE;
1060 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
1062 lpp->x = lpp->y = 0;
1063 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1064 DC_ReleaseDCPtr( dc );
1069 /***********************************************************************
1070 * SetDCOrg (GDI.117)
1072 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1075 HDC hdc = HDC_32( hdc16 );
1076 DC *dc = DC_GetDCPtr( hdc );
1078 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1079 DC_ReleaseDCPtr( dc );
1084 /***********************************************************************
1085 * GetGraphicsMode (GDI32.@)
1087 INT WINAPI GetGraphicsMode( HDC hdc )
1090 DC * dc = DC_GetDCPtr( hdc );
1093 ret = dc->GraphicsMode;
1094 DC_ReleaseDCPtr( dc );
1100 /***********************************************************************
1101 * SetGraphicsMode (GDI32.@)
1103 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1106 DC *dc = DC_GetDCPtr( hdc );
1108 /* One would think that setting the graphics mode to GM_COMPATIBLE
1109 * would also reset the world transformation matrix to the unity
1110 * matrix. However, in Windows, this is not the case. This doesn't
1111 * make a lot of sense to me, but that's the way it is.
1114 if ((mode > 0) && (mode <= GM_LAST))
1116 ret = dc->GraphicsMode;
1117 dc->GraphicsMode = mode;
1119 DC_ReleaseDCPtr( dc );
1124 /***********************************************************************
1125 * GetArcDirection (GDI32.@)
1127 INT WINAPI GetArcDirection( HDC hdc )
1130 DC * dc = DC_GetDCPtr( hdc );
1133 ret = dc->ArcDirection;
1134 DC_ReleaseDCPtr( dc );
1140 /***********************************************************************
1141 * SetArcDirection (GDI32.@)
1143 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1146 INT nOldDirection = 0;
1148 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1150 SetLastError(ERROR_INVALID_PARAMETER);
1154 if ((dc = DC_GetDCPtr( hdc )))
1156 if (dc->funcs->pSetArcDirection)
1158 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1160 nOldDirection = dc->ArcDirection;
1161 dc->ArcDirection = nDirection;
1162 DC_ReleaseDCPtr( dc );
1164 return nOldDirection;
1168 /***********************************************************************
1169 * GetWorldTransform (GDI32.@)
1171 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1174 if (!xform) return FALSE;
1175 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1176 *xform = dc->xformWorld2Wnd;
1177 DC_ReleaseDCPtr( dc );
1182 /***********************************************************************
1183 * GetTransform (GDI32.@)
1185 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1187 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1188 FIXME("stub: don't know what to do for code %x\n", unknown );
1193 /***********************************************************************
1194 * SetWorldTransform (GDI32.@)
1196 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1199 DC *dc = DC_GetDCPtr( hdc );
1201 if (!dc) return FALSE;
1202 if (!xform) goto done;
1204 /* Check that graphics mode is GM_ADVANCED */
1205 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1207 if (dc->funcs->pSetWorldTransform)
1209 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1210 if (!ret) goto done;
1213 dc->xformWorld2Wnd = *xform;
1214 DC_UpdateXforms( dc );
1217 DC_ReleaseDCPtr( dc );
1222 /****************************************************************************
1223 * ModifyWorldTransform [GDI32.@]
1224 * Modifies the world transformation for a device context.
1227 * hdc [I] Handle to device context
1228 * xform [I] XFORM structure that will be used to modify the world
1230 * iMode [I] Specifies in what way to modify the world transformation
1233 * Resets the world transformation to the identity matrix.
1234 * The parameter xform is ignored.
1236 * Multiplies xform into the world transformation matrix from
1239 * Multiplies xform into the world transformation matrix from
1244 * Failure: FALSE. Use GetLastError() to determine the cause.
1246 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1250 DC *dc = DC_GetDCPtr( hdc );
1252 /* Check for illegal parameters */
1253 if (!dc) return FALSE;
1254 if (!xform && iMode != MWT_IDENTITY) goto done;
1256 /* Check that graphics mode is GM_ADVANCED */
1257 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1259 if (dc->funcs->pModifyWorldTransform)
1261 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1262 if (!ret) goto done;
1268 dc->xformWorld2Wnd.eM11 = 1.0f;
1269 dc->xformWorld2Wnd.eM12 = 0.0f;
1270 dc->xformWorld2Wnd.eM21 = 0.0f;
1271 dc->xformWorld2Wnd.eM22 = 1.0f;
1272 dc->xformWorld2Wnd.eDx = 0.0f;
1273 dc->xformWorld2Wnd.eDy = 0.0f;
1275 case MWT_LEFTMULTIPLY:
1276 CombineTransform( &dc->xformWorld2Wnd, xform,
1277 &dc->xformWorld2Wnd );
1279 case MWT_RIGHTMULTIPLY:
1280 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1287 DC_UpdateXforms( dc );
1290 DC_ReleaseDCPtr( dc );
1295 /****************************************************************************
1296 * CombineTransform [GDI32.@]
1297 * Combines two transformation matrices.
1300 * xformResult [O] Stores the result of combining the two matrices
1301 * xform1 [I] Specifies the first matrix to apply
1302 * xform2 [I] Specifies the second matrix to apply
1305 * The same matrix can be passed in for more than one of the parameters.
1309 * Failure: FALSE. Use GetLastError() to determine the cause.
1311 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1312 const XFORM *xform2 )
1316 /* Check for illegal parameters */
1317 if (!xformResult || !xform1 || !xform2)
1320 /* Create the result in a temporary XFORM, since xformResult may be
1321 * equal to xform1 or xform2 */
1322 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1323 xform1->eM12 * xform2->eM21;
1324 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1325 xform1->eM12 * xform2->eM22;
1326 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1327 xform1->eM22 * xform2->eM21;
1328 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1329 xform1->eM22 * xform2->eM22;
1330 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1331 xform1->eDy * xform2->eM21 +
1333 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1334 xform1->eDy * xform2->eM22 +
1337 /* Copy the result to xformResult */
1338 *xformResult = xformTemp;
1344 /***********************************************************************
1345 * SetDCHook (GDI32.@)
1347 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1349 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1351 DC *dc = DC_GetDCPtr( hdc );
1353 if (!dc) return FALSE;
1355 if (!(dc->flags & DC_SAVED))
1357 dc->dwHookData = dwHookData;
1358 dc->hookThunk = hookProc;
1360 DC_ReleaseDCPtr( dc );
1365 /* relay function to call the 16-bit DC hook proc */
1366 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1370 FARPROC16 proc = NULL;
1371 DC *dc = DC_GetDCPtr( hdc );
1373 if (!dc) return FALSE;
1374 proc = dc->hookProc;
1375 DC_ReleaseDCPtr( dc );
1376 if (!proc) return FALSE;
1377 args[5] = HDC_16(hdc);
1379 args[3] = HIWORD(data);
1380 args[2] = LOWORD(data);
1381 args[1] = HIWORD(lParam);
1382 args[0] = LOWORD(lParam);
1383 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1387 /***********************************************************************
1388 * SetDCHook (GDI.190)
1390 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1392 HDC hdc = HDC_32( hdc16 );
1393 DC *dc = DC_GetDCPtr( hdc );
1394 if (!dc) return FALSE;
1396 dc->hookProc = hookProc;
1397 DC_ReleaseDCPtr( dc );
1398 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1402 /***********************************************************************
1403 * GetDCHook (GDI.191)
1405 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1407 HDC hdc = HDC_32( hdc16 );
1408 DC *dc = DC_GetDCPtr( hdc );
1412 *phookProc = dc->hookProc;
1413 ret = dc->dwHookData;
1414 DC_ReleaseDCPtr( dc );
1419 /***********************************************************************
1420 * SetHookFlags (GDI.192)
1422 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1424 HDC hdc = HDC_32( hdc16 );
1425 DC *dc = DC_GetDCPtr( hdc );
1429 WORD wRet = dc->flags & DC_DIRTY;
1431 /* "Undocumented Windows" info is slightly confusing.
1434 TRACE("hDC %p, flags %04x\n",hdc,flags);
1436 if( flags & DCHF_INVALIDATEVISRGN )
1437 dc->flags |= DC_DIRTY;
1438 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1439 dc->flags &= ~DC_DIRTY;
1440 DC_ReleaseDCPtr( dc );
1446 /***********************************************************************
1447 * SetICMMode (GDI32.@)
1449 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1451 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1452 if (iEnableICM == ICM_OFF) return ICM_OFF;
1453 if (iEnableICM == ICM_ON) return 0;
1454 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1458 /***********************************************************************
1459 * GetDeviceGammaRamp (GDI32.@)
1461 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1464 DC *dc = DC_GetDCPtr( hDC );
1468 if (dc->funcs->pGetDeviceGammaRamp)
1469 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1470 DC_ReleaseDCPtr( dc );
1475 /***********************************************************************
1476 * SetDeviceGammaRamp (GDI32.@)
1478 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1481 DC *dc = DC_GetDCPtr( hDC );
1485 if (dc->funcs->pSetDeviceGammaRamp)
1486 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1487 DC_ReleaseDCPtr( dc );
1492 /***********************************************************************
1493 * GetColorSpace (GDI32.@)
1495 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1497 /*FIXME Need to to whatever GetColorSpace actually does */
1501 /***********************************************************************
1502 * CreateColorSpaceA (GDI32.@)
1504 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1510 /***********************************************************************
1511 * CreateColorSpaceW (GDI32.@)
1513 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1519 /***********************************************************************
1520 * DeleteColorSpace (GDI32.@)
1522 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1529 /***********************************************************************
1530 * SetColorSpace (GDI32.@)
1532 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1539 /***********************************************************************
1540 * GetBoundsRect (GDI32.@)
1542 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1545 DC *dc = DC_GetDCPtr( hdc );
1547 if ( !dc ) return 0;
1549 if (rect) *rect = dc->BoundsRect;
1551 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1553 if (flags & DCB_RESET)
1555 dc->BoundsRect.left = 0;
1556 dc->BoundsRect.top = 0;
1557 dc->BoundsRect.right = 0;
1558 dc->BoundsRect.bottom = 0;
1559 dc->flags &= ~DC_BOUNDS_SET;
1561 DC_ReleaseDCPtr( dc );
1566 /***********************************************************************
1567 * SetBoundsRect (GDI32.@)
1569 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1574 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1575 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1577 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1578 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1580 if (flags & DCB_RESET)
1582 dc->BoundsRect.left = 0;
1583 dc->BoundsRect.top = 0;
1584 dc->BoundsRect.right = 0;
1585 dc->BoundsRect.bottom = 0;
1586 dc->flags &= ~DC_BOUNDS_SET;
1589 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1591 if (dc->flags & DC_BOUNDS_SET)
1593 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1594 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1595 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1596 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1600 dc->BoundsRect = *rect;
1601 dc->flags |= DC_BOUNDS_SET;
1605 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1606 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1608 DC_ReleaseDCPtr( dc );
1613 /***********************************************************************
1614 * GetRelAbs (GDI32.@)
1616 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1619 DC *dc = DC_GetDCPtr( hdc );
1622 ret = dc->relAbsMode;
1623 DC_ReleaseDCPtr( dc );
1631 /***********************************************************************
1632 * GetBkMode (GDI32.@)
1634 INT WINAPI GetBkMode( HDC hdc )
1637 DC * dc = DC_GetDCPtr( hdc );
1640 ret = dc->backgroundMode;
1641 DC_ReleaseDCPtr( dc );
1647 /***********************************************************************
1648 * SetBkMode (GDI32.@)
1650 INT WINAPI SetBkMode( HDC hdc, INT mode )
1654 if ((mode <= 0) || (mode > BKMODE_LAST))
1656 SetLastError(ERROR_INVALID_PARAMETER);
1659 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1661 ret = dc->backgroundMode;
1662 if (dc->funcs->pSetBkMode)
1663 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1666 dc->backgroundMode = mode;
1667 DC_ReleaseDCPtr( dc );
1672 /***********************************************************************
1675 INT WINAPI GetROP2( HDC hdc )
1678 DC * dc = DC_GetDCPtr( hdc );
1682 DC_ReleaseDCPtr( dc );
1688 /***********************************************************************
1691 INT WINAPI SetROP2( HDC hdc, INT mode )
1695 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1697 SetLastError(ERROR_INVALID_PARAMETER);
1700 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1702 if (dc->funcs->pSetROP2)
1703 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1707 DC_ReleaseDCPtr( dc );
1712 /***********************************************************************
1713 * SetRelAbs (GDI32.@)
1715 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1719 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1721 SetLastError(ERROR_INVALID_PARAMETER);
1724 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1725 if (dc->funcs->pSetRelAbs)
1726 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1729 ret = dc->relAbsMode;
1730 dc->relAbsMode = mode;
1732 DC_ReleaseDCPtr( dc );
1737 /***********************************************************************
1738 * GetPolyFillMode (GDI32.@)
1740 INT WINAPI GetPolyFillMode( HDC hdc )
1743 DC * dc = DC_GetDCPtr( hdc );
1746 ret = dc->polyFillMode;
1747 DC_ReleaseDCPtr( dc );
1753 /***********************************************************************
1754 * SetPolyFillMode (GDI32.@)
1756 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1760 if ((mode <= 0) || (mode > POLYFILL_LAST))
1762 SetLastError(ERROR_INVALID_PARAMETER);
1765 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1766 ret = dc->polyFillMode;
1767 if (dc->funcs->pSetPolyFillMode)
1768 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1771 dc->polyFillMode = mode;
1772 DC_ReleaseDCPtr( dc );
1777 /***********************************************************************
1778 * GetStretchBltMode (GDI32.@)
1780 INT WINAPI GetStretchBltMode( HDC hdc )
1783 DC * dc = DC_GetDCPtr( hdc );
1786 ret = dc->stretchBltMode;
1787 DC_ReleaseDCPtr( dc );
1793 /***********************************************************************
1794 * SetStretchBltMode (GDI32.@)
1796 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1800 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1802 SetLastError(ERROR_INVALID_PARAMETER);
1805 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1806 ret = dc->stretchBltMode;
1807 if (dc->funcs->pSetStretchBltMode)
1808 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1811 dc->stretchBltMode = mode;
1812 DC_ReleaseDCPtr( dc );
1817 /***********************************************************************
1818 * GetMapMode (GDI32.@)
1820 INT WINAPI GetMapMode( HDC hdc )
1823 DC * dc = DC_GetDCPtr( hdc );
1827 DC_ReleaseDCPtr( dc );
1833 /***********************************************************************
1834 * GetBrushOrgEx (GDI32.@)
1836 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1838 DC * dc = DC_GetDCPtr( hdc );
1839 if (!dc) return FALSE;
1840 pt->x = dc->brushOrgX;
1841 pt->y = dc->brushOrgY;
1842 DC_ReleaseDCPtr( dc );
1847 /***********************************************************************
1848 * GetCurrentPositionEx (GDI32.@)
1850 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1852 DC * dc = DC_GetDCPtr( hdc );
1853 if (!dc) return FALSE;
1854 pt->x = dc->CursPosX;
1855 pt->y = dc->CursPosY;
1856 DC_ReleaseDCPtr( dc );
1861 /***********************************************************************
1862 * GetViewportExtEx (GDI32.@)
1864 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1866 DC * dc = DC_GetDCPtr( hdc );
1867 if (!dc) return FALSE;
1868 size->cx = dc->vportExtX;
1869 size->cy = dc->vportExtY;
1870 DC_ReleaseDCPtr( dc );
1875 /***********************************************************************
1876 * GetViewportOrgEx (GDI32.@)
1878 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1880 DC * dc = DC_GetDCPtr( hdc );
1881 if (!dc) return FALSE;
1882 pt->x = dc->vportOrgX;
1883 pt->y = dc->vportOrgY;
1884 DC_ReleaseDCPtr( dc );
1889 /***********************************************************************
1890 * GetWindowExtEx (GDI32.@)
1892 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1894 DC * dc = DC_GetDCPtr( hdc );
1895 if (!dc) return FALSE;
1896 size->cx = dc->wndExtX;
1897 size->cy = dc->wndExtY;
1898 DC_ReleaseDCPtr( dc );
1903 /***********************************************************************
1904 * GetWindowOrgEx (GDI32.@)
1906 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1908 DC * dc = DC_GetDCPtr( hdc );
1909 if (!dc) return FALSE;
1910 pt->x = dc->wndOrgX;
1911 pt->y = dc->wndOrgY;
1912 DC_ReleaseDCPtr( dc );
1917 /***********************************************************************
1918 * InquireVisRgn (GDI.131)
1920 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1923 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1926 ret = HRGN_16(dc->hVisRgn);
1927 DC_ReleaseDCPtr( dc );
1933 /***********************************************************************
1934 * GetClipRgn (GDI.173)
1936 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
1939 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1942 ret = HRGN_16(dc->hClipRgn);
1943 DC_ReleaseDCPtr( dc );
1949 /***********************************************************************
1950 * GetLayout (GDI32.@)
1952 * Gets left->right or right->left text layout flags of a dc.
1955 DWORD WINAPI GetLayout(HDC hdc)
1957 DWORD layout = GDI_ERROR;
1959 DC * dc = DC_GetDCPtr( hdc );
1962 layout = dc->layout;
1963 DC_ReleaseDCPtr( dc );
1966 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1971 /***********************************************************************
1972 * SetLayout (GDI32.@)
1974 * Sets left->right or right->left text layout flags of a dc.
1977 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1979 DWORD oldlayout = GDI_ERROR;
1981 DC * dc = DC_GetDCPtr( hdc );
1984 oldlayout = dc->layout;
1985 dc->layout = layout;
1986 DC_ReleaseDCPtr( dc );
1989 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1994 /***********************************************************************
1995 * GetDCBrushColor (GDI32.@)
1997 * Retrieves the current brush color for the specified device
2001 COLORREF WINAPI GetDCBrushColor(HDC hdc)
2004 COLORREF dcBrushColor = CLR_INVALID;
2006 TRACE("hdc(%p)\n", hdc);
2008 dc = DC_GetDCPtr( hdc );
2011 dcBrushColor = dc->dcBrushColor;
2012 DC_ReleaseDCPtr( dc );
2015 return dcBrushColor;
2018 /***********************************************************************
2019 * SetDCBrushColor (GDI32.@)
2021 * Sets the current device context (DC) brush color to the specified
2022 * color value. If the device cannot represent the specified color
2023 * value, the color is set to the nearest physical color.
2026 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2029 COLORREF oldClr = CLR_INVALID;
2031 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2033 dc = DC_GetDCPtr( hdc );
2036 if (dc->funcs->pSetDCBrushColor)
2037 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2038 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2040 /* If DC_BRUSH is selected, update driver pen color */
2041 HBRUSH hBrush = CreateSolidBrush( crColor );
2042 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2043 DeleteObject( hBrush );
2046 if (crColor != CLR_INVALID)
2048 oldClr = dc->dcBrushColor;
2049 dc->dcBrushColor = crColor;
2052 DC_ReleaseDCPtr( dc );
2058 /***********************************************************************
2059 * GetDCPenColor (GDI32.@)
2061 * Retrieves the current pen color for the specified device
2065 COLORREF WINAPI GetDCPenColor(HDC hdc)
2068 COLORREF dcPenColor = CLR_INVALID;
2070 TRACE("hdc(%p)\n", hdc);
2072 dc = DC_GetDCPtr( hdc );
2075 dcPenColor = dc->dcPenColor;
2076 DC_ReleaseDCPtr( dc );
2082 /***********************************************************************
2083 * SetDCPenColor (GDI32.@)
2085 * Sets the current device context (DC) pen color to the specified
2086 * color value. If the device cannot represent the specified color
2087 * value, the color is set to the nearest physical color.
2090 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2093 COLORREF oldClr = CLR_INVALID;
2095 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2097 dc = DC_GetDCPtr( hdc );
2100 if (dc->funcs->pSetDCPenColor)
2101 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2102 else if (dc->hPen == GetStockObject( DC_PEN ))
2104 /* If DC_PEN is selected, update the driver pen color */
2105 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2106 HPEN hPen = CreatePenIndirect( &logpen );
2107 dc->funcs->pSelectPen( dc->physDev, hPen );
2108 DeleteObject( hPen );
2111 if (crColor != CLR_INVALID)
2113 oldClr = dc->dcPenColor;
2114 dc->dcPenColor = crColor;
2117 DC_ReleaseDCPtr( dc );
2123 /***********************************************************************
2124 * CancelDC (GDI32.@)
2126 BOOL WINAPI CancelDC(HDC hdc)
2132 /***********************************************************************
2133 * SetVirtualResolution (GDI32.@)
2135 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2137 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2139 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2143 /*******************************************************************
2144 * GetMiterLimit [GDI32.@]
2148 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2153 TRACE("(%p,%p)\n", hdc, peLimit);
2155 dc = DC_GetDCPtr( hdc );
2159 *peLimit = dc->miterLimit;
2161 DC_ReleaseDCPtr( dc );
2167 /*******************************************************************
2168 * SetMiterLimit [GDI32.@]
2172 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2177 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2179 dc = DC_GetDCPtr( hdc );
2183 *peOldLimit = dc->miterLimit;
2184 dc->miterLimit = eNewLimit;
2185 DC_ReleaseDCPtr( dc );
2191 /*******************************************************************
2192 * GdiIsMetaPrintDC [GDI32.@]
2194 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2200 /*******************************************************************
2201 * GdiIsMetaFileDC [GDI32.@]
2203 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2207 switch( GetObjectType( hdc ) )
2216 /*******************************************************************
2217 * GdiIsPlayMetafileDC [GDI32.@]
2219 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)