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"
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dc);
41 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
43 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
45 static const struct gdi_obj_funcs dc_funcs =
47 NULL, /* pSelectObject */
48 NULL, /* pGetObject16 */
49 NULL, /* pGetObjectA */
50 NULL, /* pGetObjectW */
51 NULL, /* pUnrealizeObject */
52 DC_DeleteObject /* pDeleteObject */
55 /***********************************************************************
58 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
63 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
81 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
88 dc->hPen = GetStockObject( BLACK_PEN );
89 dc->hBrush = GetStockObject( WHITE_BRUSH );
90 dc->hFont = GetStockObject( SYSTEM_FONT );
93 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
95 dc->ROPmode = R2_COPYPEN;
96 dc->polyFillMode = ALTERNATE;
97 dc->stretchBltMode = BLACKONWHITE;
98 dc->relAbsMode = ABSOLUTE;
99 dc->backgroundMode = OPAQUE;
100 dc->backgroundColor = RGB( 255, 255, 255 );
101 dc->dcBrushColor = RGB( 255, 255, 255 );
102 dc->dcPenColor = RGB( 0, 0, 0 );
103 dc->textColor = RGB( 0, 0, 0 );
106 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
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 dc->BoundsRect.left = 0;
126 dc->BoundsRect.top = 0;
127 dc->BoundsRect.right = 0;
128 dc->BoundsRect.bottom = 0;
129 dc->saved_visrgn = NULL;
130 PATH_InitGdiPath(&dc->path);
136 /***********************************************************************
139 DC *DC_GetDCPtr( HDC hdc )
141 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
142 if (!ptr) return NULL;
143 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
144 (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
145 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
146 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
148 GDI_ReleaseObj( hdc );
149 SetLastError( ERROR_INVALID_HANDLE );
153 /***********************************************************************
156 * Retrieve a DC ptr while making sure the visRgn is updated.
157 * This function may call up to USER so the GDI lock should _not_
158 * be held when calling it.
160 DC *DC_GetDCUpdate( HDC hdc )
162 DC *dc = DC_GetDCPtr( hdc );
163 if (!dc) return NULL;
164 while (dc->flags & DC_DIRTY)
166 DCHOOKPROC proc = dc->hookThunk;
167 dc->flags &= ~DC_DIRTY;
170 DWORD data = dc->dwHookData;
171 GDI_ReleaseObj( hdc );
172 proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
173 if (!(dc = DC_GetDCPtr( hdc ))) break;
174 /* otherwise restart the loop in case it became dirty again in the meantime */
181 /***********************************************************************
184 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
186 GDI_ReleaseObj( handle );
187 return DeleteDC( handle );
191 /***********************************************************************
194 * Setup device-specific DC values for a newly created DC.
196 void DC_InitDC( DC* dc )
198 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
199 SetTextColor( dc->hSelf, dc->textColor );
200 SetBkColor( dc->hSelf, dc->backgroundColor );
201 SelectObject( dc->hSelf, dc->hPen );
202 SelectObject( dc->hSelf, dc->hBrush );
203 SelectObject( dc->hSelf, dc->hFont );
204 CLIPPING_UpdateGCRegion( dc );
208 /***********************************************************************
211 * Computes the inverse of the transformation xformSrc and stores it to
212 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
215 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
219 determinant = xformSrc->eM11*xformSrc->eM22 -
220 xformSrc->eM12*xformSrc->eM21;
221 if (determinant > -1e-12 && determinant < 1e-12)
224 xformDest->eM11 = xformSrc->eM22 / determinant;
225 xformDest->eM12 = -xformSrc->eM12 / determinant;
226 xformDest->eM21 = -xformSrc->eM21 / determinant;
227 xformDest->eM22 = xformSrc->eM11 / determinant;
228 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
229 xformSrc->eDy * xformDest->eM21;
230 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
231 xformSrc->eDy * xformDest->eM22;
237 /***********************************************************************
240 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
241 * fields of the specified DC by creating a transformation that
242 * represents the current mapping mode and combining it with the DC's
243 * world transform. This function should be called whenever the
244 * parameters associated with the mapping mode (window and viewport
245 * extents and origins) or the world transform change.
247 void DC_UpdateXforms( DC *dc )
249 XFORM xformWnd2Vport, oldworld2vport;
250 FLOAT scaleX, scaleY;
252 /* Construct a transformation to do the window-to-viewport conversion */
253 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
254 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
255 xformWnd2Vport.eM11 = scaleX;
256 xformWnd2Vport.eM12 = 0.0;
257 xformWnd2Vport.eM21 = 0.0;
258 xformWnd2Vport.eM22 = scaleY;
259 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
260 scaleX * (FLOAT)dc->wndOrgX;
261 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
262 scaleY * (FLOAT)dc->wndOrgY;
264 oldworld2vport = dc->xformWorld2Vport;
265 /* Combine with the world transformation */
266 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
269 /* Create inverse of world-to-viewport transformation */
270 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
271 &dc->xformVport2World );
273 /* Reselect the font and pen back into the dc so that the size
275 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
277 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
278 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
283 /***********************************************************************
284 * GetDCState (Not a Windows API)
286 HDC WINAPI GetDCState( HDC hdc )
291 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
292 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
294 GDI_ReleaseObj( hdc );
297 TRACE("(%p): returning %p\n", hdc, handle );
299 newdc->flags = dc->flags | DC_SAVED;
300 newdc->layout = dc->layout;
301 newdc->hPen = dc->hPen;
302 newdc->hBrush = dc->hBrush;
303 newdc->hFont = dc->hFont;
304 newdc->hBitmap = dc->hBitmap;
305 newdc->hDevice = dc->hDevice;
306 newdc->hPalette = dc->hPalette;
307 newdc->ROPmode = dc->ROPmode;
308 newdc->polyFillMode = dc->polyFillMode;
309 newdc->stretchBltMode = dc->stretchBltMode;
310 newdc->relAbsMode = dc->relAbsMode;
311 newdc->backgroundMode = dc->backgroundMode;
312 newdc->backgroundColor = dc->backgroundColor;
313 newdc->textColor = dc->textColor;
314 newdc->dcBrushColor = dc->dcBrushColor;
315 newdc->dcPenColor = dc->dcPenColor;
316 newdc->brushOrgX = dc->brushOrgX;
317 newdc->brushOrgY = dc->brushOrgY;
318 newdc->textAlign = dc->textAlign;
319 newdc->charExtra = dc->charExtra;
320 newdc->breakExtra = dc->breakExtra;
321 newdc->breakRem = dc->breakRem;
322 newdc->MapMode = dc->MapMode;
323 newdc->GraphicsMode = dc->GraphicsMode;
324 newdc->CursPosX = dc->CursPosX;
325 newdc->CursPosY = dc->CursPosY;
326 newdc->ArcDirection = dc->ArcDirection;
327 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
328 newdc->xformWorld2Vport = dc->xformWorld2Vport;
329 newdc->xformVport2World = dc->xformVport2World;
330 newdc->vport2WorldValid = dc->vport2WorldValid;
331 newdc->wndOrgX = dc->wndOrgX;
332 newdc->wndOrgY = dc->wndOrgY;
333 newdc->wndExtX = dc->wndExtX;
334 newdc->wndExtY = dc->wndExtY;
335 newdc->vportOrgX = dc->vportOrgX;
336 newdc->vportOrgY = dc->vportOrgY;
337 newdc->vportExtX = dc->vportExtX;
338 newdc->vportExtY = dc->vportExtY;
339 newdc->BoundsRect = dc->BoundsRect;
341 newdc->hSelf = (HDC)handle;
342 newdc->saveLevel = 0;
345 PATH_InitGdiPath( &newdc->path );
347 newdc->pAbortProc = NULL;
348 newdc->hookThunk = NULL;
350 newdc->saved_visrgn = NULL;
352 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
357 newdc->hMetaClipRgn = 0;
360 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
361 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
365 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
366 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
368 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
371 newdc->gdiFont = dc->gdiFont;
375 GDI_ReleaseObj( handle );
376 GDI_ReleaseObj( hdc );
381 /***********************************************************************
382 * SetDCState (Not a Windows API)
384 void WINAPI SetDCState( HDC hdc, HDC hdcs )
388 if (!(dc = DC_GetDCUpdate( hdc ))) return;
389 if (!(dcs = DC_GetDCPtr( hdcs )))
391 GDI_ReleaseObj( hdc );
394 if (!dcs->flags & DC_SAVED)
396 GDI_ReleaseObj( hdc );
397 GDI_ReleaseObj( hdcs );
400 TRACE("%p %p\n", hdc, hdcs );
402 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
403 dc->layout = dcs->layout;
404 dc->hDevice = dcs->hDevice;
405 dc->ROPmode = dcs->ROPmode;
406 dc->polyFillMode = dcs->polyFillMode;
407 dc->stretchBltMode = dcs->stretchBltMode;
408 dc->relAbsMode = dcs->relAbsMode;
409 dc->backgroundMode = dcs->backgroundMode;
410 dc->backgroundColor = dcs->backgroundColor;
411 dc->textColor = dcs->textColor;
412 dc->dcBrushColor = dcs->dcBrushColor;
413 dc->dcPenColor = dcs->dcPenColor;
414 dc->brushOrgX = dcs->brushOrgX;
415 dc->brushOrgY = dcs->brushOrgY;
416 dc->textAlign = dcs->textAlign;
417 dc->charExtra = dcs->charExtra;
418 dc->breakExtra = dcs->breakExtra;
419 dc->breakRem = dcs->breakRem;
420 dc->MapMode = dcs->MapMode;
421 dc->GraphicsMode = dcs->GraphicsMode;
422 dc->CursPosX = dcs->CursPosX;
423 dc->CursPosY = dcs->CursPosY;
424 dc->ArcDirection = dcs->ArcDirection;
425 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
426 dc->xformWorld2Vport = dcs->xformWorld2Vport;
427 dc->xformVport2World = dcs->xformVport2World;
428 dc->vport2WorldValid = dcs->vport2WorldValid;
429 dc->BoundsRect = dcs->BoundsRect;
431 dc->wndOrgX = dcs->wndOrgX;
432 dc->wndOrgY = dcs->wndOrgY;
433 dc->wndExtX = dcs->wndExtX;
434 dc->wndExtY = dcs->wndExtY;
435 dc->vportOrgX = dcs->vportOrgX;
436 dc->vportOrgY = dcs->vportOrgY;
437 dc->vportExtX = dcs->vportExtX;
438 dc->vportExtY = dcs->vportExtY;
442 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
443 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
447 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
452 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
453 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
457 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
460 CLIPPING_UpdateGCRegion( dc );
462 SelectObject( hdc, dcs->hBitmap );
463 SelectObject( hdc, dcs->hBrush );
464 SelectObject( hdc, dcs->hFont );
465 SelectObject( hdc, dcs->hPen );
466 SetBkColor( hdc, dcs->backgroundColor);
467 SetTextColor( hdc, dcs->textColor);
468 GDISelectPalette( hdc, dcs->hPalette, FALSE );
469 GDI_ReleaseObj( hdcs );
470 GDI_ReleaseObj( hdc );
474 /***********************************************************************
475 * GetDCState (GDI.179)
477 HDC16 WINAPI GetDCState16( HDC16 hdc )
479 return HDC_16( GetDCState( HDC_32(hdc) ));
483 /***********************************************************************
484 * SetDCState (GDI.180)
486 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
488 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
492 /***********************************************************************
495 INT WINAPI SaveDC( HDC hdc )
501 dc = DC_GetDCPtr( hdc );
504 if(dc->funcs->pSaveDC)
506 ret = dc->funcs->pSaveDC( dc->physDev );
508 ret = ++dc->saveLevel;
509 GDI_ReleaseObj( hdc );
513 if (!(hdcs = GetDCState( hdc )))
515 GDI_ReleaseObj( hdc );
518 dcs = DC_GetDCPtr( hdcs );
520 /* Copy path. The reason why path saving / restoring is in SaveDC/
521 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
522 * functions are only in Win16 (which doesn't have paths) and that
523 * SetDCState doesn't allow us to signal an error (which can happen
524 * when copying paths).
526 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
528 GDI_ReleaseObj( hdc );
529 GDI_ReleaseObj( hdcs );
534 dcs->saved_dc = dc->saved_dc;
536 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
537 ret = ++dc->saveLevel;
538 GDI_ReleaseObj( hdcs );
539 GDI_ReleaseObj( hdc );
544 /***********************************************************************
545 * RestoreDC (GDI32.@)
547 BOOL WINAPI RestoreDC( HDC hdc, INT level )
552 TRACE("%p %d\n", hdc, level );
553 dc = DC_GetDCUpdate( hdc );
554 if(!dc) return FALSE;
556 if(abs(level) > dc->saveLevel || level == 0)
558 GDI_ReleaseObj( hdc );
562 if(dc->funcs->pRestoreDC)
564 success = dc->funcs->pRestoreDC( dc->physDev, level );
565 if(level < 0) level = dc->saveLevel + level + 1;
567 dc->saveLevel = level - 1;
568 GDI_ReleaseObj( hdc );
572 if (level < 0) level = dc->saveLevel + level + 1;
574 while (dc->saveLevel >= level)
576 HDC hdcs = dc->saved_dc;
577 if (!(dcs = DC_GetDCPtr( hdcs )))
579 GDI_ReleaseObj( hdc );
582 dc->saved_dc = dcs->saved_dc;
584 if (--dc->saveLevel < level)
586 SetDCState( hdc, hdcs );
587 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
588 /* FIXME: This might not be quite right, since we're
589 * returning FALSE but still destroying the saved DC state */
592 GDI_ReleaseObj( hdcs );
593 GDI_ReleaseObj( hdc );
595 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
597 GDI_ReleaseObj( hdc );
602 /***********************************************************************
603 * CreateDCW (GDI32.@)
605 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
606 const DEVMODEW *initData )
610 const DC_FUNCTIONS *funcs;
615 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
619 ERR( "no device found for %s\n", debugstr_w(device) );
622 strcpyW(buf, driver);
625 if (!(funcs = DRIVER_load_driver( buf )))
627 ERR( "no driver found for %s\n", debugstr_w(buf) );
630 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
632 DRIVER_release_driver( funcs );
637 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
639 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
640 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
642 if (dc->funcs->pCreateDC &&
643 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
645 WARN("creation aborted by device\n" );
646 GDI_FreeObject( dc->hSelf, dc );
647 DRIVER_release_driver( funcs );
651 dc->hVisRgn = CreateRectRgn( 0, 0, GetDeviceCaps( hdc, HORZRES ),
652 GetDeviceCaps( hdc, VERTRES ) );
655 GDI_ReleaseObj( hdc );
660 /***********************************************************************
661 * CreateDCA (GDI32.@)
663 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
664 const DEVMODEA *initData )
666 UNICODE_STRING driverW, deviceW, outputW;
670 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
671 else driverW.Buffer = NULL;
673 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
674 else deviceW.Buffer = NULL;
676 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
677 else outputW.Buffer = NULL;
682 /* don't convert initData for DISPLAY driver, it's not used */
683 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
684 initDataW = GdiConvertToDevmodeW(initData);
687 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
689 RtlFreeUnicodeString(&driverW);
690 RtlFreeUnicodeString(&deviceW);
691 RtlFreeUnicodeString(&outputW);
692 HeapFree(GetProcessHeap(), 0, initDataW);
697 /***********************************************************************
698 * CreateICA (GDI32.@)
700 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
701 const DEVMODEA* initData )
703 /* Nothing special yet for ICs */
704 return CreateDCA( driver, device, output, initData );
708 /***********************************************************************
709 * CreateICW (GDI32.@)
711 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
712 const DEVMODEW* initData )
714 /* Nothing special yet for ICs */
715 return CreateDCW( driver, device, output, initData );
719 /***********************************************************************
720 * CreateCompatibleDC (GDI32.@)
722 HDC WINAPI CreateCompatibleDC( HDC hdc )
725 const DC_FUNCTIONS *funcs;
730 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
732 funcs = origDC->funcs;
733 physDev = origDC->physDev;
734 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
735 funcs = DRIVER_get_driver( funcs );
739 funcs = DRIVER_load_driver( displayW );
743 if (!funcs) return 0;
745 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
747 DRIVER_release_driver( funcs );
751 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
753 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
755 /* Copy the driver-specific physical device info into
756 * the new DC. The driver may use this read-only info
757 * while creating the compatible DC below. */
758 dc->physDev = physDev;
760 if (dc->funcs->pCreateDC &&
761 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
763 WARN("creation aborted by device\n");
764 GDI_FreeObject( dc->hSelf, dc );
765 DRIVER_release_driver( funcs );
769 dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
772 GDI_ReleaseObj( dc->hSelf );
777 /***********************************************************************
780 BOOL WINAPI DeleteDC( HDC hdc )
782 const DC_FUNCTIONS *funcs = NULL;
789 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
791 /* Call hook procedure to check whether is it OK to delete this DC */
794 DCHOOKPROC proc = dc->hookThunk;
795 DWORD data = dc->dwHookData;
796 GDI_ReleaseObj( hdc );
797 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
798 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
801 while (dc->saveLevel)
804 HDC hdcs = dc->saved_dc;
805 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
806 dc->saved_dc = dcs->saved_dc;
808 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
809 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
810 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
811 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
812 PATH_DestroyGdiPath(&dcs->path);
813 GDI_FreeObject( hdcs, dcs );
816 if (!(dc->flags & DC_SAVED))
818 SelectObject( hdc, GetStockObject(BLACK_PEN) );
819 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
820 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
821 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
823 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
827 while (dc->saved_visrgn)
829 struct saved_visrgn *next = dc->saved_visrgn->next;
830 DeleteObject( dc->saved_visrgn->hrgn );
831 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
832 dc->saved_visrgn = next;
834 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
835 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
836 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
837 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
838 PATH_DestroyGdiPath(&dc->path);
840 GDI_FreeObject( hdc, dc );
841 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
846 /***********************************************************************
849 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
854 if ((dc = DC_GetDCPtr( hdc )))
856 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
857 GDI_ReleaseObj( hdc );
863 /***********************************************************************
866 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
871 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
872 else devmodeW = NULL;
874 ret = ResetDCW(hdc, devmodeW);
876 HeapFree(GetProcessHeap(), 0, devmodeW);
881 /***********************************************************************
882 * GetDeviceCaps (GDI32.@)
884 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
889 if ((dc = DC_GetDCPtr( hdc )))
891 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
892 else switch(cap) /* return meaningful values for some entries */
894 case HORZRES: ret = 640; break;
895 case VERTRES: ret = 480; break;
896 case BITSPIXEL: ret = 1; break;
897 case PLANES: ret = 1; break;
898 case NUMCOLORS: ret = 2; break;
899 case ASPECTX: ret = 36; break;
900 case ASPECTY: ret = 36; break;
901 case ASPECTXY: ret = 51; break;
902 case LOGPIXELSX: ret = 72; break;
903 case LOGPIXELSY: ret = 72; break;
904 case SIZEPALETTE: ret = 2; break;
906 GDI_ReleaseObj( hdc );
912 /***********************************************************************
913 * GetBkColor (GDI32.@)
915 COLORREF WINAPI GetBkColor( HDC hdc )
918 DC * dc = DC_GetDCPtr( hdc );
921 ret = dc->backgroundColor;
922 GDI_ReleaseObj( hdc );
928 /***********************************************************************
929 * SetBkColor (GDI32.@)
931 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
934 DC * dc = DC_GetDCPtr( hdc );
936 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
938 if (!dc) return CLR_INVALID;
939 oldColor = dc->backgroundColor;
940 if (dc->funcs->pSetBkColor)
942 color = dc->funcs->pSetBkColor(dc->physDev, color);
943 if (color == CLR_INVALID) /* don't change it */
946 oldColor = CLR_INVALID;
949 dc->backgroundColor = color;
950 GDI_ReleaseObj( hdc );
955 /***********************************************************************
956 * GetTextColor (GDI32.@)
958 COLORREF WINAPI GetTextColor( HDC hdc )
961 DC * dc = DC_GetDCPtr( hdc );
965 GDI_ReleaseObj( hdc );
971 /***********************************************************************
972 * SetTextColor (GDI32.@)
974 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
977 DC * dc = DC_GetDCPtr( hdc );
979 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
981 if (!dc) return CLR_INVALID;
982 oldColor = dc->textColor;
983 if (dc->funcs->pSetTextColor)
985 color = dc->funcs->pSetTextColor(dc->physDev, color);
986 if (color == CLR_INVALID) /* don't change it */
989 oldColor = CLR_INVALID;
992 dc->textColor = color;
993 GDI_ReleaseObj( hdc );
998 /***********************************************************************
999 * GetTextAlign (GDI32.@)
1001 UINT WINAPI GetTextAlign( HDC hdc )
1004 DC * dc = DC_GetDCPtr( hdc );
1007 ret = dc->textAlign;
1008 GDI_ReleaseObj( hdc );
1014 /***********************************************************************
1015 * SetTextAlign (GDI32.@)
1017 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1020 DC *dc = DC_GetDCPtr( hdc );
1022 TRACE("hdc=%p align=%d\n", hdc, align);
1024 if (!dc) return 0x0;
1025 ret = dc->textAlign;
1026 if (dc->funcs->pSetTextAlign)
1027 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1029 if (ret != GDI_ERROR)
1030 dc->textAlign = align;
1031 GDI_ReleaseObj( hdc );
1035 /***********************************************************************
1036 * GetDCOrgEx (GDI32.@)
1038 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1042 if (!lpp) return FALSE;
1043 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
1045 lpp->x = lpp->y = 0;
1046 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1047 GDI_ReleaseObj( hDC );
1052 /***********************************************************************
1053 * SetDCOrg (GDI.117)
1055 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1058 HDC hdc = HDC_32( hdc16 );
1059 DC *dc = DC_GetDCPtr( hdc );
1061 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1062 GDI_ReleaseObj( hdc );
1067 /***********************************************************************
1068 * GetGraphicsMode (GDI32.@)
1070 INT WINAPI GetGraphicsMode( HDC hdc )
1073 DC * dc = DC_GetDCPtr( hdc );
1076 ret = dc->GraphicsMode;
1077 GDI_ReleaseObj( hdc );
1083 /***********************************************************************
1084 * SetGraphicsMode (GDI32.@)
1086 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1089 DC *dc = DC_GetDCPtr( hdc );
1091 /* One would think that setting the graphics mode to GM_COMPATIBLE
1092 * would also reset the world transformation matrix to the unity
1093 * matrix. However, in Windows, this is not the case. This doesn't
1094 * make a lot of sense to me, but that's the way it is.
1097 if ((mode > 0) && (mode <= GM_LAST))
1099 ret = dc->GraphicsMode;
1100 dc->GraphicsMode = mode;
1102 GDI_ReleaseObj( hdc );
1107 /***********************************************************************
1108 * GetArcDirection (GDI32.@)
1110 INT WINAPI GetArcDirection( HDC hdc )
1113 DC * dc = DC_GetDCPtr( hdc );
1116 ret = dc->ArcDirection;
1117 GDI_ReleaseObj( hdc );
1123 /***********************************************************************
1124 * SetArcDirection (GDI32.@)
1126 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1129 INT nOldDirection = 0;
1131 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1133 SetLastError(ERROR_INVALID_PARAMETER);
1137 if ((dc = DC_GetDCPtr( hdc )))
1139 if (dc->funcs->pSetArcDirection)
1141 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1143 nOldDirection = dc->ArcDirection;
1144 dc->ArcDirection = nDirection;
1145 GDI_ReleaseObj( hdc );
1147 return nOldDirection;
1151 /***********************************************************************
1152 * GetWorldTransform (GDI32.@)
1154 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1157 if (!xform) return FALSE;
1158 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1159 *xform = dc->xformWorld2Wnd;
1160 GDI_ReleaseObj( hdc );
1165 /***********************************************************************
1166 * GetTransform (GDI32.@)
1168 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1170 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1171 FIXME("stub: don't know what to do for code %lx\n", unknown );
1176 /***********************************************************************
1177 * SetWorldTransform (GDI32.@)
1179 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1182 DC *dc = DC_GetDCPtr( hdc );
1184 if (!dc) return FALSE;
1185 if (!xform) goto done;
1187 /* Check that graphics mode is GM_ADVANCED */
1188 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1190 if (dc->funcs->pSetWorldTransform)
1192 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1193 if (!ret) goto done;
1196 dc->xformWorld2Wnd = *xform;
1197 DC_UpdateXforms( dc );
1200 GDI_ReleaseObj( hdc );
1205 /****************************************************************************
1206 * ModifyWorldTransform [GDI32.@]
1207 * Modifies the world transformation for a device context.
1210 * hdc [I] Handle to device context
1211 * xform [I] XFORM structure that will be used to modify the world
1213 * iMode [I] Specifies in what way to modify the world transformation
1216 * Resets the world transformation to the identity matrix.
1217 * The parameter xform is ignored.
1219 * Multiplies xform into the world transformation matrix from
1222 * Multiplies xform into the world transformation matrix from
1227 * Failure: FALSE. Use GetLastError() to determine the cause.
1229 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1233 DC *dc = DC_GetDCPtr( hdc );
1235 /* Check for illegal parameters */
1236 if (!dc) return FALSE;
1237 if (!xform && iMode != MWT_IDENTITY) goto done;
1239 /* Check that graphics mode is GM_ADVANCED */
1240 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1242 if (dc->funcs->pModifyWorldTransform)
1244 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1245 if (!ret) goto done;
1251 dc->xformWorld2Wnd.eM11 = 1.0f;
1252 dc->xformWorld2Wnd.eM12 = 0.0f;
1253 dc->xformWorld2Wnd.eM21 = 0.0f;
1254 dc->xformWorld2Wnd.eM22 = 1.0f;
1255 dc->xformWorld2Wnd.eDx = 0.0f;
1256 dc->xformWorld2Wnd.eDy = 0.0f;
1258 case MWT_LEFTMULTIPLY:
1259 CombineTransform( &dc->xformWorld2Wnd, xform,
1260 &dc->xformWorld2Wnd );
1262 case MWT_RIGHTMULTIPLY:
1263 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1270 DC_UpdateXforms( dc );
1273 GDI_ReleaseObj( hdc );
1278 /****************************************************************************
1279 * CombineTransform [GDI32.@]
1280 * Combines two transformation matrices.
1283 * xformResult [O] Stores the result of combining the two matrices
1284 * xform1 [I] Specifies the first matrix to apply
1285 * xform2 [I] Specifies the second matrix to apply
1288 * The same matrix can be passed in for more than one of the parameters.
1292 * Failure: FALSE. Use GetLastError() to determine the cause.
1294 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1295 const XFORM *xform2 )
1299 /* Check for illegal parameters */
1300 if (!xformResult || !xform1 || !xform2)
1303 /* Create the result in a temporary XFORM, since xformResult may be
1304 * equal to xform1 or xform2 */
1305 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1306 xform1->eM12 * xform2->eM21;
1307 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1308 xform1->eM12 * xform2->eM22;
1309 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1310 xform1->eM22 * xform2->eM21;
1311 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1312 xform1->eM22 * xform2->eM22;
1313 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1314 xform1->eDy * xform2->eM21 +
1316 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1317 xform1->eDy * xform2->eM22 +
1320 /* Copy the result to xformResult */
1321 *xformResult = xformTemp;
1327 /***********************************************************************
1328 * SetDCHook (GDI32.@)
1330 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1332 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1334 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1336 if (!dc) return FALSE;
1338 if (!(dc->flags & DC_SAVED))
1340 dc->dwHookData = dwHookData;
1341 dc->hookThunk = hookProc;
1343 GDI_ReleaseObj( hdc );
1348 /* relay function to call the 16-bit DC hook proc */
1349 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1353 FARPROC16 proc = NULL;
1354 HDC hdc = HDC_32( hdc16 );
1355 DC *dc = DC_GetDCPtr( hdc );
1357 if (!dc) return FALSE;
1358 proc = dc->hookProc;
1359 GDI_ReleaseObj( hdc );
1360 if (!proc) return FALSE;
1363 args[3] = HIWORD(data);
1364 args[2] = LOWORD(data);
1365 args[1] = HIWORD(lParam);
1366 args[0] = LOWORD(lParam);
1367 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1371 /***********************************************************************
1372 * SetDCHook (GDI.190)
1374 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1376 HDC hdc = HDC_32( hdc16 );
1377 DC *dc = DC_GetDCPtr( hdc );
1378 if (!dc) return FALSE;
1380 dc->hookProc = hookProc;
1381 GDI_ReleaseObj( hdc );
1382 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1386 /***********************************************************************
1387 * GetDCHook (GDI.191)
1389 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1391 HDC hdc = HDC_32( hdc16 );
1392 DC *dc = DC_GetDCPtr( hdc );
1396 *phookProc = dc->hookProc;
1397 ret = dc->dwHookData;
1398 GDI_ReleaseObj( hdc );
1403 /***********************************************************************
1404 * SetHookFlags (GDI.192)
1406 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1408 HDC hdc = HDC_32( hdc16 );
1409 DC *dc = DC_GetDCPtr( hdc );
1413 WORD wRet = dc->flags & DC_DIRTY;
1415 /* "Undocumented Windows" info is slightly confusing.
1418 TRACE("hDC %p, flags %04x\n",hdc,flags);
1420 if( flags & DCHF_INVALIDATEVISRGN )
1421 dc->flags |= DC_DIRTY;
1422 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1423 dc->flags &= ~DC_DIRTY;
1424 GDI_ReleaseObj( hdc );
1430 /***********************************************************************
1431 * SetICMMode (GDI32.@)
1433 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1435 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1436 if (iEnableICM == ICM_OFF) return ICM_OFF;
1437 if (iEnableICM == ICM_ON) return 0;
1438 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1442 /***********************************************************************
1443 * GetDeviceGammaRamp (GDI32.@)
1445 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1448 DC *dc = DC_GetDCPtr( hDC );
1452 if (dc->funcs->pGetDeviceGammaRamp)
1453 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1454 GDI_ReleaseObj( hDC );
1459 /***********************************************************************
1460 * SetDeviceGammaRamp (GDI32.@)
1462 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1465 DC *dc = DC_GetDCPtr( hDC );
1469 if (dc->funcs->pSetDeviceGammaRamp)
1470 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1471 GDI_ReleaseObj( hDC );
1476 /***********************************************************************
1477 * GetColorSpace (GDI32.@)
1479 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1481 /*FIXME Need to to whatever GetColorSpace actually does */
1485 /***********************************************************************
1486 * CreateColorSpaceA (GDI32.@)
1488 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1494 /***********************************************************************
1495 * CreateColorSpaceW (GDI32.@)
1497 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1503 /***********************************************************************
1504 * DeleteColorSpace (GDI32.@)
1506 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1513 /***********************************************************************
1514 * SetColorSpace (GDI32.@)
1516 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1523 /***********************************************************************
1524 * GetBoundsRect (GDI32.@)
1526 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1529 DC *dc = DC_GetDCPtr( hdc );
1531 if ( !dc ) return 0;
1533 if (rect) *rect = dc->BoundsRect;
1535 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1537 if (flags & DCB_RESET)
1539 dc->BoundsRect.left = 0;
1540 dc->BoundsRect.top = 0;
1541 dc->BoundsRect.right = 0;
1542 dc->BoundsRect.bottom = 0;
1543 dc->flags &= ~DC_BOUNDS_SET;
1545 GDI_ReleaseObj( hdc );
1550 /***********************************************************************
1551 * SetBoundsRect (GDI32.@)
1553 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1558 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1559 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1561 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1562 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1564 if (flags & DCB_RESET)
1566 dc->BoundsRect.left = 0;
1567 dc->BoundsRect.top = 0;
1568 dc->BoundsRect.right = 0;
1569 dc->BoundsRect.bottom = 0;
1570 dc->flags &= ~DC_BOUNDS_SET;
1573 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1575 if (dc->flags & DC_BOUNDS_SET)
1577 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1578 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1579 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1580 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1584 dc->BoundsRect = *rect;
1585 dc->flags |= DC_BOUNDS_SET;
1589 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1590 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1592 GDI_ReleaseObj( hdc );
1597 /***********************************************************************
1598 * GetRelAbs (GDI32.@)
1600 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1603 DC *dc = DC_GetDCPtr( hdc );
1604 if (dc) ret = dc->relAbsMode;
1605 GDI_ReleaseObj( hdc );
1612 /***********************************************************************
1613 * GetBkMode (GDI32.@)
1615 INT WINAPI GetBkMode( HDC hdc )
1618 DC * dc = DC_GetDCPtr( hdc );
1621 ret = dc->backgroundMode;
1622 GDI_ReleaseObj( hdc );
1628 /***********************************************************************
1629 * SetBkMode (GDI32.@)
1631 INT WINAPI SetBkMode( HDC hdc, INT mode )
1635 if ((mode <= 0) || (mode > BKMODE_LAST))
1637 SetLastError(ERROR_INVALID_PARAMETER);
1640 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1642 ret = dc->backgroundMode;
1643 if (dc->funcs->pSetBkMode)
1644 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1647 dc->backgroundMode = mode;
1648 GDI_ReleaseObj( hdc );
1653 /***********************************************************************
1656 INT WINAPI GetROP2( HDC hdc )
1659 DC * dc = DC_GetDCPtr( hdc );
1663 GDI_ReleaseObj( hdc );
1669 /***********************************************************************
1672 INT WINAPI SetROP2( HDC hdc, INT mode )
1676 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1678 SetLastError(ERROR_INVALID_PARAMETER);
1681 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1683 if (dc->funcs->pSetROP2)
1684 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1688 GDI_ReleaseObj( hdc );
1693 /***********************************************************************
1694 * SetRelAbs (GDI32.@)
1696 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1700 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1702 SetLastError(ERROR_INVALID_PARAMETER);
1705 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1706 if (dc->funcs->pSetRelAbs)
1707 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1710 ret = dc->relAbsMode;
1711 dc->relAbsMode = mode;
1713 GDI_ReleaseObj( hdc );
1718 /***********************************************************************
1719 * GetPolyFillMode (GDI32.@)
1721 INT WINAPI GetPolyFillMode( HDC hdc )
1724 DC * dc = DC_GetDCPtr( hdc );
1727 ret = dc->polyFillMode;
1728 GDI_ReleaseObj( hdc );
1734 /***********************************************************************
1735 * SetPolyFillMode (GDI32.@)
1737 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1741 if ((mode <= 0) || (mode > POLYFILL_LAST))
1743 SetLastError(ERROR_INVALID_PARAMETER);
1746 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1747 ret = dc->polyFillMode;
1748 if (dc->funcs->pSetPolyFillMode)
1749 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1752 dc->polyFillMode = mode;
1753 GDI_ReleaseObj( hdc );
1758 /***********************************************************************
1759 * GetStretchBltMode (GDI32.@)
1761 INT WINAPI GetStretchBltMode( HDC hdc )
1764 DC * dc = DC_GetDCPtr( hdc );
1767 ret = dc->stretchBltMode;
1768 GDI_ReleaseObj( hdc );
1774 /***********************************************************************
1775 * SetStretchBltMode (GDI32.@)
1777 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1781 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1783 SetLastError(ERROR_INVALID_PARAMETER);
1786 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1787 ret = dc->stretchBltMode;
1788 if (dc->funcs->pSetStretchBltMode)
1789 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1792 dc->stretchBltMode = mode;
1793 GDI_ReleaseObj( hdc );
1798 /***********************************************************************
1799 * GetMapMode (GDI32.@)
1801 INT WINAPI GetMapMode( HDC hdc )
1804 DC * dc = DC_GetDCPtr( hdc );
1808 GDI_ReleaseObj( hdc );
1814 /***********************************************************************
1815 * GetBrushOrgEx (GDI32.@)
1817 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1819 DC * dc = DC_GetDCPtr( hdc );
1820 if (!dc) return FALSE;
1821 pt->x = dc->brushOrgX;
1822 pt->y = dc->brushOrgY;
1823 GDI_ReleaseObj( hdc );
1828 /***********************************************************************
1829 * GetCurrentPositionEx (GDI32.@)
1831 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1833 DC * dc = DC_GetDCPtr( hdc );
1834 if (!dc) return FALSE;
1835 pt->x = dc->CursPosX;
1836 pt->y = dc->CursPosY;
1837 GDI_ReleaseObj( hdc );
1842 /***********************************************************************
1843 * GetViewportExtEx (GDI32.@)
1845 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1847 DC * dc = DC_GetDCPtr( hdc );
1848 if (!dc) return FALSE;
1849 size->cx = dc->vportExtX;
1850 size->cy = dc->vportExtY;
1851 GDI_ReleaseObj( hdc );
1856 /***********************************************************************
1857 * GetViewportOrgEx (GDI32.@)
1859 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1861 DC * dc = DC_GetDCPtr( hdc );
1862 if (!dc) return FALSE;
1863 pt->x = dc->vportOrgX;
1864 pt->y = dc->vportOrgY;
1865 GDI_ReleaseObj( hdc );
1870 /***********************************************************************
1871 * GetWindowExtEx (GDI32.@)
1873 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1875 DC * dc = DC_GetDCPtr( hdc );
1876 if (!dc) return FALSE;
1877 size->cx = dc->wndExtX;
1878 size->cy = dc->wndExtY;
1879 GDI_ReleaseObj( hdc );
1884 /***********************************************************************
1885 * GetWindowOrgEx (GDI32.@)
1887 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1889 DC * dc = DC_GetDCPtr( hdc );
1890 if (!dc) return FALSE;
1891 pt->x = dc->wndOrgX;
1892 pt->y = dc->wndOrgY;
1893 GDI_ReleaseObj( hdc );
1898 /***********************************************************************
1899 * InquireVisRgn (GDI.131)
1901 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1904 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1907 ret = HRGN_16(dc->hVisRgn);
1908 GDI_ReleaseObj( HDC_32(hdc) );
1914 /***********************************************************************
1915 * GetClipRgn (GDI.173)
1917 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
1920 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1923 ret = HRGN_16(dc->hClipRgn);
1924 GDI_ReleaseObj( HDC_32(hdc) );
1930 /***********************************************************************
1931 * GetLayout (GDI32.@)
1933 * Gets left->right or right->left text layout flags of a dc.
1936 DWORD WINAPI GetLayout(HDC hdc)
1938 DWORD layout = GDI_ERROR;
1940 DC * dc = DC_GetDCPtr( hdc );
1943 layout = dc->layout;
1944 GDI_ReleaseObj( hdc );
1947 TRACE("hdc : %p, layout : %08lx\n", hdc, layout);
1952 /***********************************************************************
1953 * SetLayout (GDI32.@)
1955 * Sets left->right or right->left text layout flags of a dc.
1958 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1960 DWORD oldlayout = GDI_ERROR;
1962 DC * dc = DC_GetDCPtr( hdc );
1965 oldlayout = dc->layout;
1966 dc->layout = layout;
1967 GDI_ReleaseObj( hdc );
1970 TRACE("hdc : %p, old layout : %08lx, new layout : %08lx\n", hdc, oldlayout, layout);
1975 /***********************************************************************
1976 * GetDCBrushColor (GDI32.@)
1978 * Retrieves the current brush color for the specified device
1982 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1985 COLORREF dcBrushColor = CLR_INVALID;
1987 TRACE("hdc(%p)\n", hdc);
1989 dc = DC_GetDCPtr( hdc );
1992 dcBrushColor = dc->dcBrushColor;
1993 GDI_ReleaseObj( hdc );
1996 return dcBrushColor;
1999 /***********************************************************************
2000 * SetDCBrushColor (GDI32.@)
2002 * Sets the current device context (DC) brush color to the specified
2003 * color value. If the device cannot represent the specified color
2004 * value, the color is set to the nearest physical color.
2007 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2010 COLORREF oldClr = CLR_INVALID;
2012 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
2014 dc = DC_GetDCPtr( hdc );
2017 if (dc->funcs->pSetDCBrushColor)
2018 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2019 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2021 /* If DC_BRUSH is selected, update driver pen color */
2022 HBRUSH hBrush = CreateSolidBrush( crColor );
2023 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2024 DeleteObject( hBrush );
2027 if (crColor != CLR_INVALID)
2029 oldClr = dc->dcBrushColor;
2030 dc->dcBrushColor = crColor;
2033 GDI_ReleaseObj( hdc );
2039 /***********************************************************************
2040 * GetDCPenColor (GDI32.@)
2042 * Retrieves the current pen color for the specified device
2046 COLORREF WINAPI GetDCPenColor(HDC hdc)
2049 COLORREF dcPenColor = CLR_INVALID;
2051 TRACE("hdc(%p)\n", hdc);
2053 dc = DC_GetDCPtr( hdc );
2056 dcPenColor = dc->dcPenColor;
2057 GDI_ReleaseObj( hdc );
2063 /***********************************************************************
2064 * SetDCPenColor (GDI32.@)
2066 * Sets the current device context (DC) pen color to the specified
2067 * color value. If the device cannot represent the specified color
2068 * value, the color is set to the nearest physical color.
2071 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2074 COLORREF oldClr = CLR_INVALID;
2076 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
2078 dc = DC_GetDCPtr( hdc );
2081 if (dc->funcs->pSetDCPenColor)
2082 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2083 else if (dc->hPen == GetStockObject( DC_PEN ))
2085 /* If DC_PEN is selected, update the driver pen color */
2086 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2087 HPEN hPen = CreatePenIndirect( &logpen );
2088 dc->funcs->pSelectPen( dc->physDev, hPen );
2089 DeleteObject( hPen );
2092 if (crColor != CLR_INVALID)
2094 oldClr = dc->dcPenColor;
2095 dc->dcPenColor = crColor;
2098 GDI_ReleaseObj( hdc );
2104 /***********************************************************************
2105 * SetVirtualResolution (GDI32.@)
2107 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2109 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2111 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
2115 /*******************************************************************
2116 * GetMiterLimit [GDI32.@]
2120 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2125 TRACE("(%p,%p)\n", hdc, peLimit);
2127 dc = DC_GetDCPtr( hdc );
2131 *peLimit = dc->miterLimit;
2133 GDI_ReleaseObj( hdc );
2139 /*******************************************************************
2140 * SetMiterLimit [GDI32.@]
2144 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2149 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2151 dc = DC_GetDCPtr( hdc );
2155 *peOldLimit = dc->miterLimit;
2156 dc->miterLimit = eNewLimit;
2157 GDI_ReleaseObj( hdc );
2163 /*******************************************************************
2164 * GdiIsMetaPrintDC [GDI32.@]
2166 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2172 /*******************************************************************
2173 * GdiIsMetaFileDC [GDI32.@]
2175 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2179 switch( GetObjectType( hdc ) )
2188 /*******************************************************************
2189 * GdiIsPlayMetafileDC [GDI32.@]
2191 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)