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 data = dc->dwHookData;
170 GDI_ReleaseObj( hdc );
171 proc( HDC_16(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 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
185 GDI_ReleaseObj( handle );
186 return DeleteDC( handle );
190 /***********************************************************************
193 * Setup device-specific DC values for a newly created DC.
195 void DC_InitDC( DC* dc )
197 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
198 SetTextColor( dc->hSelf, dc->textColor );
199 SetBkColor( dc->hSelf, dc->backgroundColor );
200 SelectObject( dc->hSelf, dc->hPen );
201 SelectObject( dc->hSelf, dc->hBrush );
202 SelectObject( dc->hSelf, dc->hFont );
203 CLIPPING_UpdateGCRegion( dc );
207 /***********************************************************************
210 * Computes the inverse of the transformation xformSrc and stores it to
211 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
214 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
218 determinant = xformSrc->eM11*xformSrc->eM22 -
219 xformSrc->eM12*xformSrc->eM21;
220 if (determinant > -1e-12 && determinant < 1e-12)
223 xformDest->eM11 = xformSrc->eM22 / determinant;
224 xformDest->eM12 = -xformSrc->eM12 / determinant;
225 xformDest->eM21 = -xformSrc->eM21 / determinant;
226 xformDest->eM22 = xformSrc->eM11 / determinant;
227 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
228 xformSrc->eDy * xformDest->eM21;
229 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
230 xformSrc->eDy * xformDest->eM22;
236 /***********************************************************************
239 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
240 * fields of the specified DC by creating a transformation that
241 * represents the current mapping mode and combining it with the DC's
242 * world transform. This function should be called whenever the
243 * parameters associated with the mapping mode (window and viewport
244 * extents and origins) or the world transform change.
246 void DC_UpdateXforms( DC *dc )
248 XFORM xformWnd2Vport, oldworld2vport;
249 FLOAT scaleX, scaleY;
251 /* Construct a transformation to do the window-to-viewport conversion */
252 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
253 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
254 xformWnd2Vport.eM11 = scaleX;
255 xformWnd2Vport.eM12 = 0.0;
256 xformWnd2Vport.eM21 = 0.0;
257 xformWnd2Vport.eM22 = scaleY;
258 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
259 scaleX * (FLOAT)dc->wndOrgX;
260 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
261 scaleY * (FLOAT)dc->wndOrgY;
263 oldworld2vport = dc->xformWorld2Vport;
264 /* Combine with the world transformation */
265 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
268 /* Create inverse of world-to-viewport transformation */
269 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
270 &dc->xformVport2World );
272 /* Reselect the font and pen back into the dc so that the size
274 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
276 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
277 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
282 /***********************************************************************
283 * GetDCState (Not a Windows API)
285 HDC WINAPI GetDCState( HDC hdc )
290 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
291 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
293 GDI_ReleaseObj( hdc );
296 TRACE("(%p): returning %p\n", hdc, handle );
298 newdc->flags = dc->flags | DC_SAVED;
299 newdc->layout = dc->layout;
300 newdc->hPen = dc->hPen;
301 newdc->hBrush = dc->hBrush;
302 newdc->hFont = dc->hFont;
303 newdc->hBitmap = dc->hBitmap;
304 newdc->hDevice = dc->hDevice;
305 newdc->hPalette = dc->hPalette;
306 newdc->ROPmode = dc->ROPmode;
307 newdc->polyFillMode = dc->polyFillMode;
308 newdc->stretchBltMode = dc->stretchBltMode;
309 newdc->relAbsMode = dc->relAbsMode;
310 newdc->backgroundMode = dc->backgroundMode;
311 newdc->backgroundColor = dc->backgroundColor;
312 newdc->textColor = dc->textColor;
313 newdc->dcBrushColor = dc->dcBrushColor;
314 newdc->dcPenColor = dc->dcPenColor;
315 newdc->brushOrgX = dc->brushOrgX;
316 newdc->brushOrgY = dc->brushOrgY;
317 newdc->textAlign = dc->textAlign;
318 newdc->charExtra = dc->charExtra;
319 newdc->breakExtra = dc->breakExtra;
320 newdc->breakRem = dc->breakRem;
321 newdc->MapMode = dc->MapMode;
322 newdc->GraphicsMode = dc->GraphicsMode;
323 newdc->CursPosX = dc->CursPosX;
324 newdc->CursPosY = dc->CursPosY;
325 newdc->ArcDirection = dc->ArcDirection;
326 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
327 newdc->xformWorld2Vport = dc->xformWorld2Vport;
328 newdc->xformVport2World = dc->xformVport2World;
329 newdc->vport2WorldValid = dc->vport2WorldValid;
330 newdc->wndOrgX = dc->wndOrgX;
331 newdc->wndOrgY = dc->wndOrgY;
332 newdc->wndExtX = dc->wndExtX;
333 newdc->wndExtY = dc->wndExtY;
334 newdc->vportOrgX = dc->vportOrgX;
335 newdc->vportOrgY = dc->vportOrgY;
336 newdc->vportExtX = dc->vportExtX;
337 newdc->vportExtY = dc->vportExtY;
338 newdc->BoundsRect = dc->BoundsRect;
340 newdc->hSelf = (HDC)handle;
341 newdc->saveLevel = 0;
344 PATH_InitGdiPath( &newdc->path );
346 newdc->pAbortProc = NULL;
347 newdc->hookThunk = NULL;
349 newdc->saved_visrgn = NULL;
351 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
356 newdc->hMetaClipRgn = 0;
359 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
360 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
364 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
365 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
367 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
370 newdc->gdiFont = dc->gdiFont;
374 GDI_ReleaseObj( handle );
375 GDI_ReleaseObj( hdc );
380 /***********************************************************************
381 * SetDCState (Not a Windows API)
383 void WINAPI SetDCState( HDC hdc, HDC hdcs )
387 if (!(dc = DC_GetDCUpdate( hdc ))) return;
388 if (!(dcs = DC_GetDCPtr( hdcs )))
390 GDI_ReleaseObj( hdc );
393 if (!dcs->flags & DC_SAVED)
395 GDI_ReleaseObj( hdc );
396 GDI_ReleaseObj( hdcs );
399 TRACE("%p %p\n", hdc, hdcs );
401 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
402 dc->layout = dcs->layout;
403 dc->hDevice = dcs->hDevice;
404 dc->ROPmode = dcs->ROPmode;
405 dc->polyFillMode = dcs->polyFillMode;
406 dc->stretchBltMode = dcs->stretchBltMode;
407 dc->relAbsMode = dcs->relAbsMode;
408 dc->backgroundMode = dcs->backgroundMode;
409 dc->backgroundColor = dcs->backgroundColor;
410 dc->textColor = dcs->textColor;
411 dc->dcBrushColor = dcs->dcBrushColor;
412 dc->dcPenColor = dcs->dcPenColor;
413 dc->brushOrgX = dcs->brushOrgX;
414 dc->brushOrgY = dcs->brushOrgY;
415 dc->textAlign = dcs->textAlign;
416 dc->charExtra = dcs->charExtra;
417 dc->breakExtra = dcs->breakExtra;
418 dc->breakRem = dcs->breakRem;
419 dc->MapMode = dcs->MapMode;
420 dc->GraphicsMode = dcs->GraphicsMode;
421 dc->CursPosX = dcs->CursPosX;
422 dc->CursPosY = dcs->CursPosY;
423 dc->ArcDirection = dcs->ArcDirection;
424 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
425 dc->xformWorld2Vport = dcs->xformWorld2Vport;
426 dc->xformVport2World = dcs->xformVport2World;
427 dc->vport2WorldValid = dcs->vport2WorldValid;
428 dc->BoundsRect = dcs->BoundsRect;
430 dc->wndOrgX = dcs->wndOrgX;
431 dc->wndOrgY = dcs->wndOrgY;
432 dc->wndExtX = dcs->wndExtX;
433 dc->wndExtY = dcs->wndExtY;
434 dc->vportOrgX = dcs->vportOrgX;
435 dc->vportOrgY = dcs->vportOrgY;
436 dc->vportExtX = dcs->vportExtX;
437 dc->vportExtY = dcs->vportExtY;
441 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
442 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
446 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
451 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
452 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
456 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
459 CLIPPING_UpdateGCRegion( dc );
461 SelectObject( hdc, dcs->hBitmap );
462 SelectObject( hdc, dcs->hBrush );
463 SelectObject( hdc, dcs->hFont );
464 SelectObject( hdc, dcs->hPen );
465 SetBkColor( hdc, dcs->backgroundColor);
466 SetTextColor( hdc, dcs->textColor);
467 GDISelectPalette( hdc, dcs->hPalette, FALSE );
468 GDI_ReleaseObj( hdcs );
469 GDI_ReleaseObj( hdc );
473 /***********************************************************************
474 * GetDCState (GDI.179)
476 HDC16 WINAPI GetDCState16( HDC16 hdc )
478 return HDC_16( GetDCState( HDC_32(hdc) ));
482 /***********************************************************************
483 * SetDCState (GDI.180)
485 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
487 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
491 /***********************************************************************
494 INT WINAPI SaveDC( HDC hdc )
500 dc = DC_GetDCPtr( hdc );
503 if(dc->funcs->pSaveDC)
505 ret = dc->funcs->pSaveDC( dc->physDev );
507 ret = ++dc->saveLevel;
508 GDI_ReleaseObj( hdc );
512 if (!(hdcs = GetDCState( hdc )))
514 GDI_ReleaseObj( hdc );
517 dcs = DC_GetDCPtr( hdcs );
519 /* Copy path. The reason why path saving / restoring is in SaveDC/
520 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
521 * functions are only in Win16 (which doesn't have paths) and that
522 * SetDCState doesn't allow us to signal an error (which can happen
523 * when copying paths).
525 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
527 GDI_ReleaseObj( hdc );
528 GDI_ReleaseObj( hdcs );
533 dcs->saved_dc = dc->saved_dc;
535 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
536 ret = ++dc->saveLevel;
537 GDI_ReleaseObj( hdcs );
538 GDI_ReleaseObj( hdc );
543 /***********************************************************************
544 * RestoreDC (GDI32.@)
546 BOOL WINAPI RestoreDC( HDC hdc, INT level )
551 TRACE("%p %d\n", hdc, level );
552 dc = DC_GetDCUpdate( hdc );
553 if(!dc) return FALSE;
555 if(abs(level) > dc->saveLevel || level == 0)
557 GDI_ReleaseObj( hdc );
561 if(dc->funcs->pRestoreDC)
563 success = dc->funcs->pRestoreDC( dc->physDev, level );
564 if(level < 0) level = dc->saveLevel + level + 1;
566 dc->saveLevel = level - 1;
567 GDI_ReleaseObj( hdc );
571 if (level < 0) level = dc->saveLevel + level + 1;
573 while (dc->saveLevel >= level)
575 HDC hdcs = dc->saved_dc;
576 if (!(dcs = DC_GetDCPtr( hdcs )))
578 GDI_ReleaseObj( hdc );
581 dc->saved_dc = dcs->saved_dc;
583 if (--dc->saveLevel < level)
585 SetDCState( hdc, hdcs );
586 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
587 /* FIXME: This might not be quite right, since we're
588 * returning FALSE but still destroying the saved DC state */
591 GDI_ReleaseObj( hdcs );
592 GDI_ReleaseObj( hdc );
594 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
596 GDI_ReleaseObj( hdc );
601 /***********************************************************************
602 * CreateDCW (GDI32.@)
604 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
605 const DEVMODEW *initData )
609 const DC_FUNCTIONS *funcs;
614 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
618 ERR( "no device found for %s\n", debugstr_w(device) );
621 strcpyW(buf, driver);
624 if (!(funcs = DRIVER_load_driver( buf )))
626 ERR( "no driver found for %s\n", debugstr_w(buf) );
629 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
631 DRIVER_release_driver( funcs );
636 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
638 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
639 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
641 if (dc->funcs->pCreateDC &&
642 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
644 WARN("creation aborted by device\n" );
645 GDI_FreeObject( dc->hSelf, dc );
646 DRIVER_release_driver( funcs );
650 dc->hVisRgn = CreateRectRgn( 0, 0, GetDeviceCaps( hdc, HORZRES ),
651 GetDeviceCaps( hdc, VERTRES ) );
654 GDI_ReleaseObj( hdc );
659 /***********************************************************************
660 * CreateDCA (GDI32.@)
662 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
663 const DEVMODEA *initData )
665 UNICODE_STRING driverW, deviceW, outputW;
669 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
670 else driverW.Buffer = NULL;
672 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
673 else deviceW.Buffer = NULL;
675 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
676 else outputW.Buffer = NULL;
681 /* don't convert initData for DISPLAY driver, it's not used */
682 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
683 initDataW = GdiConvertToDevmodeW(initData);
686 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
688 RtlFreeUnicodeString(&driverW);
689 RtlFreeUnicodeString(&deviceW);
690 RtlFreeUnicodeString(&outputW);
691 HeapFree(GetProcessHeap(), 0, initDataW);
696 /***********************************************************************
697 * CreateICA (GDI32.@)
699 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
700 const DEVMODEA* initData )
702 /* Nothing special yet for ICs */
703 return CreateDCA( driver, device, output, initData );
707 /***********************************************************************
708 * CreateICW (GDI32.@)
710 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
711 const DEVMODEW* initData )
713 /* Nothing special yet for ICs */
714 return CreateDCW( driver, device, output, initData );
718 /***********************************************************************
719 * CreateCompatibleDC (GDI32.@)
721 HDC WINAPI CreateCompatibleDC( HDC hdc )
724 const DC_FUNCTIONS *funcs;
729 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
731 funcs = origDC->funcs;
732 physDev = origDC->physDev;
733 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
734 funcs = DRIVER_get_driver( funcs );
738 funcs = DRIVER_load_driver( displayW );
742 if (!funcs) return 0;
744 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
746 DRIVER_release_driver( funcs );
750 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
752 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
754 /* Copy the driver-specific physical device info into
755 * the new DC. The driver may use this read-only info
756 * while creating the compatible DC below. */
757 dc->physDev = physDev;
759 if (dc->funcs->pCreateDC &&
760 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
762 WARN("creation aborted by device\n");
763 GDI_FreeObject( dc->hSelf, dc );
764 DRIVER_release_driver( funcs );
768 dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
771 GDI_ReleaseObj( dc->hSelf );
776 /***********************************************************************
779 BOOL WINAPI DeleteDC( HDC hdc )
781 const DC_FUNCTIONS *funcs = NULL;
788 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
790 /* Call hook procedure to check whether is it OK to delete this DC */
793 DCHOOKPROC proc = dc->hookThunk;
794 DWORD data = dc->dwHookData;
795 GDI_ReleaseObj( hdc );
796 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
797 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
800 while (dc->saveLevel)
803 HDC hdcs = dc->saved_dc;
804 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
805 dc->saved_dc = dcs->saved_dc;
807 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
808 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
809 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
810 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
811 PATH_DestroyGdiPath(&dcs->path);
812 GDI_FreeObject( hdcs, dcs );
815 if (!(dc->flags & DC_SAVED))
817 SelectObject( hdc, GetStockObject(BLACK_PEN) );
818 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
819 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
820 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
822 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
826 while (dc->saved_visrgn)
828 struct saved_visrgn *next = dc->saved_visrgn->next;
829 DeleteObject( dc->saved_visrgn->hrgn );
830 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
831 dc->saved_visrgn = next;
833 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
834 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
835 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
836 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
837 PATH_DestroyGdiPath(&dc->path);
839 GDI_FreeObject( hdc, dc );
840 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
845 /***********************************************************************
848 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
853 if ((dc = DC_GetDCPtr( hdc )))
855 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
856 GDI_ReleaseObj( hdc );
862 /***********************************************************************
865 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
870 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
871 else devmodeW = NULL;
873 ret = ResetDCW(hdc, devmodeW);
875 HeapFree(GetProcessHeap(), 0, devmodeW);
880 /***********************************************************************
881 * GetDeviceCaps (GDI32.@)
883 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
888 if ((dc = DC_GetDCPtr( hdc )))
890 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
891 else switch(cap) /* return meaningful values for some entries */
893 case HORZRES: ret = 640; break;
894 case VERTRES: ret = 480; break;
895 case BITSPIXEL: ret = 1; break;
896 case PLANES: ret = 1; break;
897 case NUMCOLORS: ret = 2; break;
898 case ASPECTX: ret = 36; break;
899 case ASPECTY: ret = 36; break;
900 case ASPECTXY: ret = 51; break;
901 case LOGPIXELSX: ret = 72; break;
902 case LOGPIXELSY: ret = 72; break;
903 case SIZEPALETTE: ret = 2; break;
905 GDI_ReleaseObj( hdc );
911 /***********************************************************************
912 * GetBkColor (GDI32.@)
914 COLORREF WINAPI GetBkColor( HDC hdc )
917 DC * dc = DC_GetDCPtr( hdc );
920 ret = dc->backgroundColor;
921 GDI_ReleaseObj( hdc );
927 /***********************************************************************
928 * SetBkColor (GDI32.@)
930 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
933 DC * dc = DC_GetDCPtr( hdc );
935 TRACE("hdc=%p color=0x%08x\n", hdc, color);
937 if (!dc) return CLR_INVALID;
938 oldColor = dc->backgroundColor;
939 if (dc->funcs->pSetBkColor)
941 color = dc->funcs->pSetBkColor(dc->physDev, color);
942 if (color == CLR_INVALID) /* don't change it */
945 oldColor = CLR_INVALID;
948 dc->backgroundColor = color;
949 GDI_ReleaseObj( hdc );
954 /***********************************************************************
955 * GetTextColor (GDI32.@)
957 COLORREF WINAPI GetTextColor( HDC hdc )
960 DC * dc = DC_GetDCPtr( hdc );
964 GDI_ReleaseObj( hdc );
970 /***********************************************************************
971 * SetTextColor (GDI32.@)
973 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
976 DC * dc = DC_GetDCPtr( hdc );
978 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
980 if (!dc) return CLR_INVALID;
981 oldColor = dc->textColor;
982 if (dc->funcs->pSetTextColor)
984 color = dc->funcs->pSetTextColor(dc->physDev, color);
985 if (color == CLR_INVALID) /* don't change it */
988 oldColor = CLR_INVALID;
991 dc->textColor = color;
992 GDI_ReleaseObj( hdc );
997 /***********************************************************************
998 * GetTextAlign (GDI32.@)
1000 UINT WINAPI GetTextAlign( HDC hdc )
1003 DC * dc = DC_GetDCPtr( hdc );
1006 ret = dc->textAlign;
1007 GDI_ReleaseObj( hdc );
1013 /***********************************************************************
1014 * SetTextAlign (GDI32.@)
1016 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1019 DC *dc = DC_GetDCPtr( hdc );
1021 TRACE("hdc=%p align=%d\n", hdc, align);
1023 if (!dc) return 0x0;
1024 ret = dc->textAlign;
1025 if (dc->funcs->pSetTextAlign)
1026 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1028 if (ret != GDI_ERROR)
1029 dc->textAlign = align;
1030 GDI_ReleaseObj( hdc );
1034 /***********************************************************************
1035 * GetDCOrgEx (GDI32.@)
1037 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1041 if (!lpp) return FALSE;
1042 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
1044 lpp->x = lpp->y = 0;
1045 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1046 GDI_ReleaseObj( hDC );
1051 /***********************************************************************
1052 * SetDCOrg (GDI.117)
1054 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1057 HDC hdc = HDC_32( hdc16 );
1058 DC *dc = DC_GetDCPtr( hdc );
1060 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1061 GDI_ReleaseObj( hdc );
1066 /***********************************************************************
1067 * GetGraphicsMode (GDI32.@)
1069 INT WINAPI GetGraphicsMode( HDC hdc )
1072 DC * dc = DC_GetDCPtr( hdc );
1075 ret = dc->GraphicsMode;
1076 GDI_ReleaseObj( hdc );
1082 /***********************************************************************
1083 * SetGraphicsMode (GDI32.@)
1085 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1088 DC *dc = DC_GetDCPtr( hdc );
1090 /* One would think that setting the graphics mode to GM_COMPATIBLE
1091 * would also reset the world transformation matrix to the unity
1092 * matrix. However, in Windows, this is not the case. This doesn't
1093 * make a lot of sense to me, but that's the way it is.
1096 if ((mode > 0) && (mode <= GM_LAST))
1098 ret = dc->GraphicsMode;
1099 dc->GraphicsMode = mode;
1101 GDI_ReleaseObj( hdc );
1106 /***********************************************************************
1107 * GetArcDirection (GDI32.@)
1109 INT WINAPI GetArcDirection( HDC hdc )
1112 DC * dc = DC_GetDCPtr( hdc );
1115 ret = dc->ArcDirection;
1116 GDI_ReleaseObj( hdc );
1122 /***********************************************************************
1123 * SetArcDirection (GDI32.@)
1125 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1128 INT nOldDirection = 0;
1130 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1132 SetLastError(ERROR_INVALID_PARAMETER);
1136 if ((dc = DC_GetDCPtr( hdc )))
1138 if (dc->funcs->pSetArcDirection)
1140 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1142 nOldDirection = dc->ArcDirection;
1143 dc->ArcDirection = nDirection;
1144 GDI_ReleaseObj( hdc );
1146 return nOldDirection;
1150 /***********************************************************************
1151 * GetWorldTransform (GDI32.@)
1153 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1156 if (!xform) return FALSE;
1157 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1158 *xform = dc->xformWorld2Wnd;
1159 GDI_ReleaseObj( hdc );
1164 /***********************************************************************
1165 * GetTransform (GDI32.@)
1167 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1169 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1170 FIXME("stub: don't know what to do for code %x\n", unknown );
1175 /***********************************************************************
1176 * SetWorldTransform (GDI32.@)
1178 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1181 DC *dc = DC_GetDCPtr( hdc );
1183 if (!dc) return FALSE;
1184 if (!xform) goto done;
1186 /* Check that graphics mode is GM_ADVANCED */
1187 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1189 if (dc->funcs->pSetWorldTransform)
1191 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1192 if (!ret) goto done;
1195 dc->xformWorld2Wnd = *xform;
1196 DC_UpdateXforms( dc );
1199 GDI_ReleaseObj( hdc );
1204 /****************************************************************************
1205 * ModifyWorldTransform [GDI32.@]
1206 * Modifies the world transformation for a device context.
1209 * hdc [I] Handle to device context
1210 * xform [I] XFORM structure that will be used to modify the world
1212 * iMode [I] Specifies in what way to modify the world transformation
1215 * Resets the world transformation to the identity matrix.
1216 * The parameter xform is ignored.
1218 * Multiplies xform into the world transformation matrix from
1221 * Multiplies xform into the world transformation matrix from
1226 * Failure: FALSE. Use GetLastError() to determine the cause.
1228 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1232 DC *dc = DC_GetDCPtr( hdc );
1234 /* Check for illegal parameters */
1235 if (!dc) return FALSE;
1236 if (!xform && iMode != MWT_IDENTITY) goto done;
1238 /* Check that graphics mode is GM_ADVANCED */
1239 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1241 if (dc->funcs->pModifyWorldTransform)
1243 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1244 if (!ret) goto done;
1250 dc->xformWorld2Wnd.eM11 = 1.0f;
1251 dc->xformWorld2Wnd.eM12 = 0.0f;
1252 dc->xformWorld2Wnd.eM21 = 0.0f;
1253 dc->xformWorld2Wnd.eM22 = 1.0f;
1254 dc->xformWorld2Wnd.eDx = 0.0f;
1255 dc->xformWorld2Wnd.eDy = 0.0f;
1257 case MWT_LEFTMULTIPLY:
1258 CombineTransform( &dc->xformWorld2Wnd, xform,
1259 &dc->xformWorld2Wnd );
1261 case MWT_RIGHTMULTIPLY:
1262 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1269 DC_UpdateXforms( dc );
1272 GDI_ReleaseObj( hdc );
1277 /****************************************************************************
1278 * CombineTransform [GDI32.@]
1279 * Combines two transformation matrices.
1282 * xformResult [O] Stores the result of combining the two matrices
1283 * xform1 [I] Specifies the first matrix to apply
1284 * xform2 [I] Specifies the second matrix to apply
1287 * The same matrix can be passed in for more than one of the parameters.
1291 * Failure: FALSE. Use GetLastError() to determine the cause.
1293 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1294 const XFORM *xform2 )
1298 /* Check for illegal parameters */
1299 if (!xformResult || !xform1 || !xform2)
1302 /* Create the result in a temporary XFORM, since xformResult may be
1303 * equal to xform1 or xform2 */
1304 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1305 xform1->eM12 * xform2->eM21;
1306 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1307 xform1->eM12 * xform2->eM22;
1308 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1309 xform1->eM22 * xform2->eM21;
1310 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1311 xform1->eM22 * xform2->eM22;
1312 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1313 xform1->eDy * xform2->eM21 +
1315 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1316 xform1->eDy * xform2->eM22 +
1319 /* Copy the result to xformResult */
1320 *xformResult = xformTemp;
1326 /***********************************************************************
1327 * SetDCHook (GDI32.@)
1329 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1331 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1333 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1335 if (!dc) return FALSE;
1337 if (!(dc->flags & DC_SAVED))
1339 dc->dwHookData = dwHookData;
1340 dc->hookThunk = hookProc;
1342 GDI_ReleaseObj( hdc );
1347 /* relay function to call the 16-bit DC hook proc */
1348 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1352 FARPROC16 proc = NULL;
1353 HDC hdc = HDC_32( hdc16 );
1354 DC *dc = DC_GetDCPtr( hdc );
1356 if (!dc) return FALSE;
1357 proc = dc->hookProc;
1358 GDI_ReleaseObj( hdc );
1359 if (!proc) return FALSE;
1362 args[3] = HIWORD(data);
1363 args[2] = LOWORD(data);
1364 args[1] = HIWORD(lParam);
1365 args[0] = LOWORD(lParam);
1366 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1370 /***********************************************************************
1371 * SetDCHook (GDI.190)
1373 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1375 HDC hdc = HDC_32( hdc16 );
1376 DC *dc = DC_GetDCPtr( hdc );
1377 if (!dc) return FALSE;
1379 dc->hookProc = hookProc;
1380 GDI_ReleaseObj( hdc );
1381 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1385 /***********************************************************************
1386 * GetDCHook (GDI.191)
1388 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1390 HDC hdc = HDC_32( hdc16 );
1391 DC *dc = DC_GetDCPtr( hdc );
1395 *phookProc = dc->hookProc;
1396 ret = dc->dwHookData;
1397 GDI_ReleaseObj( hdc );
1402 /***********************************************************************
1403 * SetHookFlags (GDI.192)
1405 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1407 HDC hdc = HDC_32( hdc16 );
1408 DC *dc = DC_GetDCPtr( hdc );
1412 WORD wRet = dc->flags & DC_DIRTY;
1414 /* "Undocumented Windows" info is slightly confusing.
1417 TRACE("hDC %p, flags %04x\n",hdc,flags);
1419 if( flags & DCHF_INVALIDATEVISRGN )
1420 dc->flags |= DC_DIRTY;
1421 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1422 dc->flags &= ~DC_DIRTY;
1423 GDI_ReleaseObj( hdc );
1429 /***********************************************************************
1430 * SetICMMode (GDI32.@)
1432 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1434 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1435 if (iEnableICM == ICM_OFF) return ICM_OFF;
1436 if (iEnableICM == ICM_ON) return 0;
1437 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1441 /***********************************************************************
1442 * GetDeviceGammaRamp (GDI32.@)
1444 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1447 DC *dc = DC_GetDCPtr( hDC );
1451 if (dc->funcs->pGetDeviceGammaRamp)
1452 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1453 GDI_ReleaseObj( hDC );
1458 /***********************************************************************
1459 * SetDeviceGammaRamp (GDI32.@)
1461 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1464 DC *dc = DC_GetDCPtr( hDC );
1468 if (dc->funcs->pSetDeviceGammaRamp)
1469 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1470 GDI_ReleaseObj( hDC );
1475 /***********************************************************************
1476 * GetColorSpace (GDI32.@)
1478 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1480 /*FIXME Need to to whatever GetColorSpace actually does */
1484 /***********************************************************************
1485 * CreateColorSpaceA (GDI32.@)
1487 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1493 /***********************************************************************
1494 * CreateColorSpaceW (GDI32.@)
1496 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1502 /***********************************************************************
1503 * DeleteColorSpace (GDI32.@)
1505 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1512 /***********************************************************************
1513 * SetColorSpace (GDI32.@)
1515 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1522 /***********************************************************************
1523 * GetBoundsRect (GDI32.@)
1525 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1528 DC *dc = DC_GetDCPtr( hdc );
1530 if ( !dc ) return 0;
1532 if (rect) *rect = dc->BoundsRect;
1534 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1536 if (flags & DCB_RESET)
1538 dc->BoundsRect.left = 0;
1539 dc->BoundsRect.top = 0;
1540 dc->BoundsRect.right = 0;
1541 dc->BoundsRect.bottom = 0;
1542 dc->flags &= ~DC_BOUNDS_SET;
1544 GDI_ReleaseObj( hdc );
1549 /***********************************************************************
1550 * SetBoundsRect (GDI32.@)
1552 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1557 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1558 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1560 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1561 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1563 if (flags & DCB_RESET)
1565 dc->BoundsRect.left = 0;
1566 dc->BoundsRect.top = 0;
1567 dc->BoundsRect.right = 0;
1568 dc->BoundsRect.bottom = 0;
1569 dc->flags &= ~DC_BOUNDS_SET;
1572 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1574 if (dc->flags & DC_BOUNDS_SET)
1576 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1577 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1578 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1579 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1583 dc->BoundsRect = *rect;
1584 dc->flags |= DC_BOUNDS_SET;
1588 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1589 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1591 GDI_ReleaseObj( hdc );
1596 /***********************************************************************
1597 * GetRelAbs (GDI32.@)
1599 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1602 DC *dc = DC_GetDCPtr( hdc );
1603 if (dc) ret = dc->relAbsMode;
1604 GDI_ReleaseObj( hdc );
1611 /***********************************************************************
1612 * GetBkMode (GDI32.@)
1614 INT WINAPI GetBkMode( HDC hdc )
1617 DC * dc = DC_GetDCPtr( hdc );
1620 ret = dc->backgroundMode;
1621 GDI_ReleaseObj( hdc );
1627 /***********************************************************************
1628 * SetBkMode (GDI32.@)
1630 INT WINAPI SetBkMode( HDC hdc, INT mode )
1634 if ((mode <= 0) || (mode > BKMODE_LAST))
1636 SetLastError(ERROR_INVALID_PARAMETER);
1639 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1641 ret = dc->backgroundMode;
1642 if (dc->funcs->pSetBkMode)
1643 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1646 dc->backgroundMode = mode;
1647 GDI_ReleaseObj( hdc );
1652 /***********************************************************************
1655 INT WINAPI GetROP2( HDC hdc )
1658 DC * dc = DC_GetDCPtr( hdc );
1662 GDI_ReleaseObj( hdc );
1668 /***********************************************************************
1671 INT WINAPI SetROP2( HDC hdc, INT mode )
1675 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1677 SetLastError(ERROR_INVALID_PARAMETER);
1680 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1682 if (dc->funcs->pSetROP2)
1683 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1687 GDI_ReleaseObj( hdc );
1692 /***********************************************************************
1693 * SetRelAbs (GDI32.@)
1695 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1699 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1701 SetLastError(ERROR_INVALID_PARAMETER);
1704 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1705 if (dc->funcs->pSetRelAbs)
1706 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1709 ret = dc->relAbsMode;
1710 dc->relAbsMode = mode;
1712 GDI_ReleaseObj( hdc );
1717 /***********************************************************************
1718 * GetPolyFillMode (GDI32.@)
1720 INT WINAPI GetPolyFillMode( HDC hdc )
1723 DC * dc = DC_GetDCPtr( hdc );
1726 ret = dc->polyFillMode;
1727 GDI_ReleaseObj( hdc );
1733 /***********************************************************************
1734 * SetPolyFillMode (GDI32.@)
1736 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1740 if ((mode <= 0) || (mode > POLYFILL_LAST))
1742 SetLastError(ERROR_INVALID_PARAMETER);
1745 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1746 ret = dc->polyFillMode;
1747 if (dc->funcs->pSetPolyFillMode)
1748 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1751 dc->polyFillMode = mode;
1752 GDI_ReleaseObj( hdc );
1757 /***********************************************************************
1758 * GetStretchBltMode (GDI32.@)
1760 INT WINAPI GetStretchBltMode( HDC hdc )
1763 DC * dc = DC_GetDCPtr( hdc );
1766 ret = dc->stretchBltMode;
1767 GDI_ReleaseObj( hdc );
1773 /***********************************************************************
1774 * SetStretchBltMode (GDI32.@)
1776 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1780 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1782 SetLastError(ERROR_INVALID_PARAMETER);
1785 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1786 ret = dc->stretchBltMode;
1787 if (dc->funcs->pSetStretchBltMode)
1788 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1791 dc->stretchBltMode = mode;
1792 GDI_ReleaseObj( hdc );
1797 /***********************************************************************
1798 * GetMapMode (GDI32.@)
1800 INT WINAPI GetMapMode( HDC hdc )
1803 DC * dc = DC_GetDCPtr( hdc );
1807 GDI_ReleaseObj( hdc );
1813 /***********************************************************************
1814 * GetBrushOrgEx (GDI32.@)
1816 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1818 DC * dc = DC_GetDCPtr( hdc );
1819 if (!dc) return FALSE;
1820 pt->x = dc->brushOrgX;
1821 pt->y = dc->brushOrgY;
1822 GDI_ReleaseObj( hdc );
1827 /***********************************************************************
1828 * GetCurrentPositionEx (GDI32.@)
1830 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1832 DC * dc = DC_GetDCPtr( hdc );
1833 if (!dc) return FALSE;
1834 pt->x = dc->CursPosX;
1835 pt->y = dc->CursPosY;
1836 GDI_ReleaseObj( hdc );
1841 /***********************************************************************
1842 * GetViewportExtEx (GDI32.@)
1844 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1846 DC * dc = DC_GetDCPtr( hdc );
1847 if (!dc) return FALSE;
1848 size->cx = dc->vportExtX;
1849 size->cy = dc->vportExtY;
1850 GDI_ReleaseObj( hdc );
1855 /***********************************************************************
1856 * GetViewportOrgEx (GDI32.@)
1858 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1860 DC * dc = DC_GetDCPtr( hdc );
1861 if (!dc) return FALSE;
1862 pt->x = dc->vportOrgX;
1863 pt->y = dc->vportOrgY;
1864 GDI_ReleaseObj( hdc );
1869 /***********************************************************************
1870 * GetWindowExtEx (GDI32.@)
1872 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1874 DC * dc = DC_GetDCPtr( hdc );
1875 if (!dc) return FALSE;
1876 size->cx = dc->wndExtX;
1877 size->cy = dc->wndExtY;
1878 GDI_ReleaseObj( hdc );
1883 /***********************************************************************
1884 * GetWindowOrgEx (GDI32.@)
1886 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1888 DC * dc = DC_GetDCPtr( hdc );
1889 if (!dc) return FALSE;
1890 pt->x = dc->wndOrgX;
1891 pt->y = dc->wndOrgY;
1892 GDI_ReleaseObj( hdc );
1897 /***********************************************************************
1898 * InquireVisRgn (GDI.131)
1900 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
1903 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1906 ret = HRGN_16(dc->hVisRgn);
1907 GDI_ReleaseObj( HDC_32(hdc) );
1913 /***********************************************************************
1914 * GetClipRgn (GDI.173)
1916 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
1919 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
1922 ret = HRGN_16(dc->hClipRgn);
1923 GDI_ReleaseObj( HDC_32(hdc) );
1929 /***********************************************************************
1930 * GetLayout (GDI32.@)
1932 * Gets left->right or right->left text layout flags of a dc.
1935 DWORD WINAPI GetLayout(HDC hdc)
1937 DWORD layout = GDI_ERROR;
1939 DC * dc = DC_GetDCPtr( hdc );
1942 layout = dc->layout;
1943 GDI_ReleaseObj( hdc );
1946 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1951 /***********************************************************************
1952 * SetLayout (GDI32.@)
1954 * Sets left->right or right->left text layout flags of a dc.
1957 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1959 DWORD oldlayout = GDI_ERROR;
1961 DC * dc = DC_GetDCPtr( hdc );
1964 oldlayout = dc->layout;
1965 dc->layout = layout;
1966 GDI_ReleaseObj( hdc );
1969 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1974 /***********************************************************************
1975 * GetDCBrushColor (GDI32.@)
1977 * Retrieves the current brush color for the specified device
1981 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1984 COLORREF dcBrushColor = CLR_INVALID;
1986 TRACE("hdc(%p)\n", hdc);
1988 dc = DC_GetDCPtr( hdc );
1991 dcBrushColor = dc->dcBrushColor;
1992 GDI_ReleaseObj( hdc );
1995 return dcBrushColor;
1998 /***********************************************************************
1999 * SetDCBrushColor (GDI32.@)
2001 * Sets the current device context (DC) brush color to the specified
2002 * color value. If the device cannot represent the specified color
2003 * value, the color is set to the nearest physical color.
2006 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2009 COLORREF oldClr = CLR_INVALID;
2011 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2013 dc = DC_GetDCPtr( hdc );
2016 if (dc->funcs->pSetDCBrushColor)
2017 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2018 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2020 /* If DC_BRUSH is selected, update driver pen color */
2021 HBRUSH hBrush = CreateSolidBrush( crColor );
2022 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2023 DeleteObject( hBrush );
2026 if (crColor != CLR_INVALID)
2028 oldClr = dc->dcBrushColor;
2029 dc->dcBrushColor = crColor;
2032 GDI_ReleaseObj( hdc );
2038 /***********************************************************************
2039 * GetDCPenColor (GDI32.@)
2041 * Retrieves the current pen color for the specified device
2045 COLORREF WINAPI GetDCPenColor(HDC hdc)
2048 COLORREF dcPenColor = CLR_INVALID;
2050 TRACE("hdc(%p)\n", hdc);
2052 dc = DC_GetDCPtr( hdc );
2055 dcPenColor = dc->dcPenColor;
2056 GDI_ReleaseObj( hdc );
2062 /***********************************************************************
2063 * SetDCPenColor (GDI32.@)
2065 * Sets the current device context (DC) pen color to the specified
2066 * color value. If the device cannot represent the specified color
2067 * value, the color is set to the nearest physical color.
2070 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2073 COLORREF oldClr = CLR_INVALID;
2075 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2077 dc = DC_GetDCPtr( hdc );
2080 if (dc->funcs->pSetDCPenColor)
2081 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2082 else if (dc->hPen == GetStockObject( DC_PEN ))
2084 /* If DC_PEN is selected, update the driver pen color */
2085 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2086 HPEN hPen = CreatePenIndirect( &logpen );
2087 dc->funcs->pSelectPen( dc->physDev, hPen );
2088 DeleteObject( hPen );
2091 if (crColor != CLR_INVALID)
2093 oldClr = dc->dcPenColor;
2094 dc->dcPenColor = crColor;
2097 GDI_ReleaseObj( hdc );
2103 /***********************************************************************
2104 * SetVirtualResolution (GDI32.@)
2106 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2108 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2110 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2114 /*******************************************************************
2115 * GetMiterLimit [GDI32.@]
2119 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2124 TRACE("(%p,%p)\n", hdc, peLimit);
2126 dc = DC_GetDCPtr( hdc );
2130 *peLimit = dc->miterLimit;
2132 GDI_ReleaseObj( hdc );
2138 /*******************************************************************
2139 * SetMiterLimit [GDI32.@]
2143 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2148 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2150 dc = DC_GetDCPtr( hdc );
2154 *peOldLimit = dc->miterLimit;
2155 dc->miterLimit = eNewLimit;
2156 GDI_ReleaseObj( hdc );
2162 /*******************************************************************
2163 * GdiIsMetaPrintDC [GDI32.@]
2165 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2171 /*******************************************************************
2172 * GdiIsMetaFileDC [GDI32.@]
2174 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2178 switch( GetObjectType( hdc ) )
2187 /*******************************************************************
2188 * GdiIsPlayMetafileDC [GDI32.@]
2190 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)