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
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 );
44 static const struct gdi_obj_funcs dc_funcs =
46 NULL, /* pSelectObject */
47 NULL, /* pGetObjectA */
48 NULL, /* pGetObjectW */
49 NULL, /* pUnrealizeObject */
50 DC_DeleteObject /* pDeleteObject */
54 static inline DC *get_dc_obj( HDC hdc )
56 DC *dc = GDI_GetObjPtr( hdc, 0 );
59 if ((dc->header.type != OBJ_DC) &&
60 (dc->header.type != OBJ_MEMDC) &&
61 (dc->header.type != OBJ_METADC) &&
62 (dc->header.type != OBJ_ENHMETADC))
64 GDI_ReleaseObj( hdc );
65 SetLastError( ERROR_INVALID_HANDLE );
72 /***********************************************************************
75 DC *alloc_dc_ptr( const DC_FUNCTIONS *funcs, WORD magic )
79 if (!(dc = HeapAlloc( GetProcessHeap(), 0, sizeof(*dc) ))) return NULL;
83 dc->thread = GetCurrentThreadId();
99 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
104 dc->hMetaClipRgn = 0;
106 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
107 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
108 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
111 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
113 dc->font_code_page = CP_ACP;
114 dc->ROPmode = R2_COPYPEN;
115 dc->polyFillMode = ALTERNATE;
116 dc->stretchBltMode = BLACKONWHITE;
117 dc->relAbsMode = ABSOLUTE;
118 dc->backgroundMode = OPAQUE;
119 dc->backgroundColor = RGB( 255, 255, 255 );
120 dc->dcBrushColor = RGB( 255, 255, 255 );
121 dc->dcPenColor = RGB( 0, 0, 0 );
122 dc->textColor = RGB( 0, 0, 0 );
125 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
129 dc->MapMode = MM_TEXT;
130 dc->GraphicsMode = GM_COMPATIBLE;
131 dc->pAbortProc = NULL;
134 dc->ArcDirection = AD_COUNTERCLOCKWISE;
135 dc->xformWorld2Wnd.eM11 = 1.0f;
136 dc->xformWorld2Wnd.eM12 = 0.0f;
137 dc->xformWorld2Wnd.eM21 = 0.0f;
138 dc->xformWorld2Wnd.eM22 = 1.0f;
139 dc->xformWorld2Wnd.eDx = 0.0f;
140 dc->xformWorld2Wnd.eDy = 0.0f;
141 dc->xformWorld2Vport = dc->xformWorld2Wnd;
142 dc->xformVport2World = dc->xformWorld2Wnd;
143 dc->vport2WorldValid = TRUE;
144 dc->BoundsRect.left = 0;
145 dc->BoundsRect.top = 0;
146 dc->BoundsRect.right = 0;
147 dc->BoundsRect.bottom = 0;
148 dc->saved_visrgn = NULL;
149 PATH_InitGdiPath(&dc->path);
151 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
153 HeapFree( GetProcessHeap(), 0, dc );
161 /***********************************************************************
164 BOOL free_dc_ptr( DC *dc )
166 assert( dc->refcount == 1 );
167 if (free_gdi_handle( dc->hSelf ) != dc) return FALSE; /* shouldn't happen */
168 return HeapFree( GetProcessHeap(), 0, dc );
172 /***********************************************************************
175 * Retrieve a DC pointer but release the GDI lock.
177 DC *get_dc_ptr( HDC hdc )
179 DC *dc = get_dc_obj( hdc );
180 if (!dc) return NULL;
182 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
184 dc->thread = GetCurrentThreadId();
186 else if (dc->thread != GetCurrentThreadId())
188 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
189 GDI_ReleaseObj( hdc );
192 else InterlockedIncrement( &dc->refcount );
194 GDI_ReleaseObj( hdc );
199 /***********************************************************************
202 void release_dc_ptr( DC *dc )
207 ref = InterlockedDecrement( &dc->refcount );
209 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
213 /***********************************************************************
216 * Make sure the DC vis region is up to date.
217 * This function may call up to USER so the GDI lock should _not_
218 * be held when calling it.
220 void update_dc( DC *dc )
222 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookThunk)
223 dc->hookThunk( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
227 /***********************************************************************
230 static BOOL DC_DeleteObject( HGDIOBJ handle )
232 return DeleteDC( handle );
236 /***********************************************************************
239 * Setup device-specific DC values for a newly created DC.
241 void DC_InitDC( DC* dc )
243 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
244 SetTextColor( dc->hSelf, dc->textColor );
245 SetBkColor( dc->hSelf, dc->backgroundColor );
246 SelectObject( dc->hSelf, dc->hPen );
247 SelectObject( dc->hSelf, dc->hBrush );
248 SelectObject( dc->hSelf, dc->hFont );
249 CLIPPING_UpdateGCRegion( dc );
253 /***********************************************************************
256 * Computes the inverse of the transformation xformSrc and stores it to
257 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
260 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
264 determinant = xformSrc->eM11*xformSrc->eM22 -
265 xformSrc->eM12*xformSrc->eM21;
266 if (determinant > -1e-12 && determinant < 1e-12)
269 xformDest->eM11 = xformSrc->eM22 / determinant;
270 xformDest->eM12 = -xformSrc->eM12 / determinant;
271 xformDest->eM21 = -xformSrc->eM21 / determinant;
272 xformDest->eM22 = xformSrc->eM11 / determinant;
273 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
274 xformSrc->eDy * xformDest->eM21;
275 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
276 xformSrc->eDy * xformDest->eM22;
282 /***********************************************************************
285 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
286 * fields of the specified DC by creating a transformation that
287 * represents the current mapping mode and combining it with the DC's
288 * world transform. This function should be called whenever the
289 * parameters associated with the mapping mode (window and viewport
290 * extents and origins) or the world transform change.
292 void DC_UpdateXforms( DC *dc )
294 XFORM xformWnd2Vport, oldworld2vport;
295 double scaleX, scaleY;
297 /* Construct a transformation to do the window-to-viewport conversion */
298 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
299 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
300 xformWnd2Vport.eM11 = scaleX;
301 xformWnd2Vport.eM12 = 0.0;
302 xformWnd2Vport.eM21 = 0.0;
303 xformWnd2Vport.eM22 = scaleY;
304 xformWnd2Vport.eDx = (double)dc->vportOrgX -
305 scaleX * (double)dc->wndOrgX;
306 xformWnd2Vport.eDy = (double)dc->vportOrgY -
307 scaleY * (double)dc->wndOrgY;
309 oldworld2vport = dc->xformWorld2Vport;
310 /* Combine with the world transformation */
311 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
314 /* Create inverse of world-to-viewport transformation */
315 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
316 &dc->xformVport2World );
318 /* Reselect the font and pen back into the dc so that the size
320 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
321 !GdiIsMetaFileDC(dc->hSelf))
323 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
324 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
329 /***********************************************************************
330 * get_dc_state (Not a Windows API)
332 HDC get_dc_state( HDC hdc )
337 if (!(dc = get_dc_ptr( hdc ))) return 0;
338 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc ))))
340 release_dc_ptr( dc );
344 newdc->flags = dc->flags | DC_SAVED;
345 newdc->layout = dc->layout;
346 newdc->hPen = dc->hPen;
347 newdc->hBrush = dc->hBrush;
348 newdc->hFont = dc->hFont;
349 newdc->hBitmap = dc->hBitmap;
350 newdc->hDevice = dc->hDevice;
351 newdc->hPalette = dc->hPalette;
352 newdc->ROPmode = dc->ROPmode;
353 newdc->polyFillMode = dc->polyFillMode;
354 newdc->stretchBltMode = dc->stretchBltMode;
355 newdc->relAbsMode = dc->relAbsMode;
356 newdc->backgroundMode = dc->backgroundMode;
357 newdc->backgroundColor = dc->backgroundColor;
358 newdc->textColor = dc->textColor;
359 newdc->dcBrushColor = dc->dcBrushColor;
360 newdc->dcPenColor = dc->dcPenColor;
361 newdc->brushOrgX = dc->brushOrgX;
362 newdc->brushOrgY = dc->brushOrgY;
363 newdc->textAlign = dc->textAlign;
364 newdc->charExtra = dc->charExtra;
365 newdc->breakExtra = dc->breakExtra;
366 newdc->breakRem = dc->breakRem;
367 newdc->MapMode = dc->MapMode;
368 newdc->GraphicsMode = dc->GraphicsMode;
369 newdc->CursPosX = dc->CursPosX;
370 newdc->CursPosY = dc->CursPosY;
371 newdc->ArcDirection = dc->ArcDirection;
372 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
373 newdc->xformWorld2Vport = dc->xformWorld2Vport;
374 newdc->xformVport2World = dc->xformVport2World;
375 newdc->vport2WorldValid = dc->vport2WorldValid;
376 newdc->wndOrgX = dc->wndOrgX;
377 newdc->wndOrgY = dc->wndOrgY;
378 newdc->wndExtX = dc->wndExtX;
379 newdc->wndExtY = dc->wndExtY;
380 newdc->vportOrgX = dc->vportOrgX;
381 newdc->vportOrgY = dc->vportOrgY;
382 newdc->vportExtX = dc->vportExtX;
383 newdc->vportExtY = dc->vportExtY;
384 newdc->BoundsRect = dc->BoundsRect;
385 newdc->gdiFont = dc->gdiFont;
387 newdc->thread = GetCurrentThreadId();
389 newdc->saveLevel = 0;
392 PATH_InitGdiPath( &newdc->path );
394 newdc->pAbortProc = NULL;
395 newdc->hookThunk = NULL;
397 newdc->saved_visrgn = NULL;
399 if (!(newdc->hSelf = alloc_gdi_handle( &newdc->header, dc->header.type, &dc_funcs )))
401 HeapFree( GetProcessHeap(), 0, newdc );
402 release_dc_ptr( dc );
405 handle = newdc->hSelf;
406 TRACE("(%p): returning %p\n", hdc, handle );
408 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
413 newdc->hMetaClipRgn = 0;
416 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
417 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
421 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
422 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
424 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
426 release_dc_ptr( newdc );
427 release_dc_ptr( dc );
432 /***********************************************************************
433 * set_dc_state (Not a Windows API)
435 void set_dc_state( HDC hdc, HDC hdcs )
439 if (!(dc = get_dc_ptr( hdc ))) return;
440 if (!(dcs = get_dc_ptr( hdcs )))
442 release_dc_ptr( dc );
445 if (!(dcs->flags & DC_SAVED))
447 release_dc_ptr( dc );
448 release_dc_ptr( dcs );
451 TRACE("%p %p\n", hdc, hdcs );
454 dc->flags = dcs->flags & ~DC_SAVED;
455 dc->layout = dcs->layout;
456 dc->hDevice = dcs->hDevice;
457 dc->ROPmode = dcs->ROPmode;
458 dc->polyFillMode = dcs->polyFillMode;
459 dc->stretchBltMode = dcs->stretchBltMode;
460 dc->relAbsMode = dcs->relAbsMode;
461 dc->backgroundMode = dcs->backgroundMode;
462 dc->backgroundColor = dcs->backgroundColor;
463 dc->textColor = dcs->textColor;
464 dc->dcBrushColor = dcs->dcBrushColor;
465 dc->dcPenColor = dcs->dcPenColor;
466 dc->brushOrgX = dcs->brushOrgX;
467 dc->brushOrgY = dcs->brushOrgY;
468 dc->textAlign = dcs->textAlign;
469 dc->charExtra = dcs->charExtra;
470 dc->breakExtra = dcs->breakExtra;
471 dc->breakRem = dcs->breakRem;
472 dc->MapMode = dcs->MapMode;
473 dc->GraphicsMode = dcs->GraphicsMode;
474 dc->CursPosX = dcs->CursPosX;
475 dc->CursPosY = dcs->CursPosY;
476 dc->ArcDirection = dcs->ArcDirection;
477 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
478 dc->xformWorld2Vport = dcs->xformWorld2Vport;
479 dc->xformVport2World = dcs->xformVport2World;
480 dc->vport2WorldValid = dcs->vport2WorldValid;
481 dc->BoundsRect = dcs->BoundsRect;
483 dc->wndOrgX = dcs->wndOrgX;
484 dc->wndOrgY = dcs->wndOrgY;
485 dc->wndExtX = dcs->wndExtX;
486 dc->wndExtY = dcs->wndExtY;
487 dc->vportOrgX = dcs->vportOrgX;
488 dc->vportOrgY = dcs->vportOrgY;
489 dc->vportExtX = dcs->vportExtX;
490 dc->vportExtY = dcs->vportExtY;
494 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
495 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
499 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
504 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
505 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
509 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
512 CLIPPING_UpdateGCRegion( dc );
514 SelectObject( hdc, dcs->hBitmap );
515 SelectObject( hdc, dcs->hBrush );
516 SelectObject( hdc, dcs->hFont );
517 SelectObject( hdc, dcs->hPen );
518 SetBkColor( hdc, dcs->backgroundColor);
519 SetTextColor( hdc, dcs->textColor);
520 GDISelectPalette( hdc, dcs->hPalette, FALSE );
521 release_dc_ptr( dc );
522 release_dc_ptr( dcs );
526 /***********************************************************************
529 INT WINAPI SaveDC( HDC hdc )
535 dc = get_dc_ptr( hdc );
538 if(dc->funcs->pSaveDC)
540 ret = dc->funcs->pSaveDC( dc->physDev );
542 ret = ++dc->saveLevel;
543 release_dc_ptr( dc );
547 if (!(hdcs = get_dc_state( hdc )))
549 release_dc_ptr( dc );
552 dcs = get_dc_ptr( hdcs );
554 /* Copy path. The reason why path saving / restoring is in SaveDC/
555 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
556 * functions are only in Win16 (which doesn't have paths) and that
557 * SetDCState doesn't allow us to signal an error (which can happen
558 * when copying paths).
560 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
562 release_dc_ptr( dc );
563 release_dc_ptr( dcs );
568 dcs->saved_dc = dc->saved_dc;
570 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
571 ret = ++dc->saveLevel;
572 release_dc_ptr( dcs );
573 release_dc_ptr( dc );
578 /***********************************************************************
579 * RestoreDC (GDI32.@)
581 BOOL WINAPI RestoreDC( HDC hdc, INT level )
586 TRACE("%p %d\n", hdc, level );
587 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
589 if(abs(level) > dc->saveLevel || level == 0)
591 release_dc_ptr( dc );
597 if(dc->funcs->pRestoreDC)
599 success = dc->funcs->pRestoreDC( dc->physDev, level );
600 if(level < 0) level = dc->saveLevel + level + 1;
602 dc->saveLevel = level - 1;
603 release_dc_ptr( dc );
607 if (level < 0) level = dc->saveLevel + level + 1;
609 while (dc->saveLevel >= level)
611 HDC hdcs = dc->saved_dc;
612 if (!(dcs = get_dc_ptr( hdcs )))
617 dc->saved_dc = dcs->saved_dc;
619 if (--dc->saveLevel < level)
621 set_dc_state( hdc, hdcs );
622 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
623 /* FIXME: This might not be quite right, since we're
624 * returning FALSE but still destroying the saved DC state */
627 release_dc_ptr( dcs );
630 release_dc_ptr( dc );
635 /***********************************************************************
636 * CreateDCW (GDI32.@)
638 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
639 const DEVMODEW *initData )
643 const DC_FUNCTIONS *funcs;
648 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
652 ERR( "no device found for %s\n", debugstr_w(device) );
655 strcpyW(buf, driver);
658 if (!(funcs = DRIVER_load_driver( buf )))
660 ERR( "no driver found for %s\n", debugstr_w(buf) );
663 if (!(dc = alloc_dc_ptr( funcs, OBJ_DC ))) goto error;
666 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
667 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
669 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
670 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
672 if (dc->funcs->pCreateDC &&
673 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
675 WARN("creation aborted by device\n" );
679 SetRectRgn( dc->hVisRgn, 0, 0,
680 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
683 release_dc_ptr( dc );
687 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
688 if (dc) free_dc_ptr( dc );
689 DRIVER_release_driver( funcs );
694 /***********************************************************************
695 * CreateDCA (GDI32.@)
697 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
698 const DEVMODEA *initData )
700 UNICODE_STRING driverW, deviceW, outputW;
704 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
705 else driverW.Buffer = NULL;
707 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
708 else deviceW.Buffer = NULL;
710 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
711 else outputW.Buffer = NULL;
716 /* don't convert initData for DISPLAY driver, it's not used */
717 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
718 initDataW = GdiConvertToDevmodeW(initData);
721 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
723 RtlFreeUnicodeString(&driverW);
724 RtlFreeUnicodeString(&deviceW);
725 RtlFreeUnicodeString(&outputW);
726 HeapFree(GetProcessHeap(), 0, initDataW);
731 /***********************************************************************
732 * CreateICA (GDI32.@)
734 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
735 const DEVMODEA* initData )
737 /* Nothing special yet for ICs */
738 return CreateDCA( driver, device, output, initData );
742 /***********************************************************************
743 * CreateICW (GDI32.@)
745 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
746 const DEVMODEW* initData )
748 /* Nothing special yet for ICs */
749 return CreateDCW( driver, device, output, initData );
753 /***********************************************************************
754 * CreateCompatibleDC (GDI32.@)
756 HDC WINAPI CreateCompatibleDC( HDC hdc )
760 const DC_FUNCTIONS *funcs = NULL;
761 PHYSDEV physDev = NULL;
765 if ((origDC = get_dc_ptr( hdc )))
767 if (GetObjectType( hdc ) == OBJ_DC)
769 funcs = origDC->funcs;
770 physDev = origDC->physDev;
772 release_dc_ptr( origDC );
773 if (funcs) funcs = DRIVER_get_driver( funcs );
775 else if (hdc) return 0;
777 if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
779 if (!(dc = alloc_dc_ptr( funcs, OBJ_MEMDC ))) goto error;
781 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
783 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
784 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
786 /* Copy the driver-specific physical device info into
787 * the new DC. The driver may use this read-only info
788 * while creating the compatible DC below. */
789 dc->physDev = physDev;
792 if (dc->funcs->pCreateDC &&
793 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
795 WARN("creation aborted by device\n");
800 release_dc_ptr( dc );
804 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
805 if (dc) free_dc_ptr( dc );
806 DRIVER_release_driver( funcs );
811 /***********************************************************************
814 BOOL WINAPI DeleteDC( HDC hdc )
816 const DC_FUNCTIONS *funcs = NULL;
823 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
824 if (dc->refcount != 1)
826 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
827 release_dc_ptr( dc );
831 /* Call hook procedure to check whether is it OK to delete this DC */
832 if (dc->hookThunk && !dc->hookThunk( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
834 release_dc_ptr( dc );
838 while (dc->saveLevel)
841 HDC hdcs = dc->saved_dc;
842 if (!(dcs = get_dc_ptr( hdcs ))) break;
843 dc->saved_dc = dcs->saved_dc;
845 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
846 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
847 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
848 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
849 PATH_DestroyGdiPath(&dcs->path);
853 if (!(dc->flags & DC_SAVED))
855 SelectObject( hdc, GetStockObject(BLACK_PEN) );
856 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
857 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
858 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
860 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
864 while (dc->saved_visrgn)
866 struct saved_visrgn *next = dc->saved_visrgn->next;
867 DeleteObject( dc->saved_visrgn->hrgn );
868 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
869 dc->saved_visrgn = next;
871 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
872 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
873 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
874 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
875 PATH_DestroyGdiPath(&dc->path);
878 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
883 /***********************************************************************
886 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
891 if ((dc = get_dc_ptr( hdc )))
893 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
894 release_dc_ptr( dc );
900 /***********************************************************************
903 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
908 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
909 else devmodeW = NULL;
911 ret = ResetDCW(hdc, devmodeW);
913 HeapFree(GetProcessHeap(), 0, devmodeW);
918 /***********************************************************************
919 * GetDeviceCaps (GDI32.@)
921 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
926 if ((dc = get_dc_ptr( hdc )))
928 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
929 else switch(cap) /* return meaningful values for some entries */
931 case HORZRES: ret = 640; break;
932 case VERTRES: ret = 480; break;
933 case BITSPIXEL: ret = 1; break;
934 case PLANES: ret = 1; break;
935 case NUMCOLORS: ret = 2; break;
936 case ASPECTX: ret = 36; break;
937 case ASPECTY: ret = 36; break;
938 case ASPECTXY: ret = 51; break;
939 case LOGPIXELSX: ret = 72; break;
940 case LOGPIXELSY: ret = 72; break;
941 case SIZEPALETTE: ret = 2; break;
943 release_dc_ptr( dc );
949 /***********************************************************************
950 * GetBkColor (GDI32.@)
952 COLORREF WINAPI GetBkColor( HDC hdc )
955 DC * dc = get_dc_ptr( hdc );
958 ret = dc->backgroundColor;
959 release_dc_ptr( dc );
965 /***********************************************************************
966 * SetBkColor (GDI32.@)
968 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
971 DC * dc = get_dc_ptr( hdc );
973 TRACE("hdc=%p color=0x%08x\n", hdc, color);
975 if (!dc) return CLR_INVALID;
976 oldColor = dc->backgroundColor;
977 if (dc->funcs->pSetBkColor)
979 color = dc->funcs->pSetBkColor(dc->physDev, color);
980 if (color == CLR_INVALID) /* don't change it */
983 oldColor = CLR_INVALID;
986 dc->backgroundColor = color;
987 release_dc_ptr( dc );
992 /***********************************************************************
993 * GetTextColor (GDI32.@)
995 COLORREF WINAPI GetTextColor( HDC hdc )
998 DC * dc = get_dc_ptr( hdc );
1001 ret = dc->textColor;
1002 release_dc_ptr( dc );
1008 /***********************************************************************
1009 * SetTextColor (GDI32.@)
1011 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
1014 DC * dc = get_dc_ptr( hdc );
1016 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
1018 if (!dc) return CLR_INVALID;
1019 oldColor = dc->textColor;
1020 if (dc->funcs->pSetTextColor)
1022 color = dc->funcs->pSetTextColor(dc->physDev, color);
1023 if (color == CLR_INVALID) /* don't change it */
1026 oldColor = CLR_INVALID;
1029 dc->textColor = color;
1030 release_dc_ptr( dc );
1035 /***********************************************************************
1036 * GetTextAlign (GDI32.@)
1038 UINT WINAPI GetTextAlign( HDC hdc )
1041 DC * dc = get_dc_ptr( hdc );
1044 ret = dc->textAlign;
1045 release_dc_ptr( dc );
1051 /***********************************************************************
1052 * SetTextAlign (GDI32.@)
1054 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1057 DC *dc = get_dc_ptr( hdc );
1059 TRACE("hdc=%p align=%d\n", hdc, align);
1061 if (!dc) return 0x0;
1062 ret = dc->textAlign;
1063 if (dc->funcs->pSetTextAlign)
1064 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1066 if (ret != GDI_ERROR)
1067 dc->textAlign = align;
1068 release_dc_ptr( dc );
1072 /***********************************************************************
1073 * GetDCOrgEx (GDI32.@)
1075 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1079 if (!lpp) return FALSE;
1080 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1082 lpp->x = lpp->y = 0;
1083 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1084 release_dc_ptr( dc );
1089 /***********************************************************************
1090 * GetGraphicsMode (GDI32.@)
1092 INT WINAPI GetGraphicsMode( HDC hdc )
1095 DC * dc = get_dc_ptr( hdc );
1098 ret = dc->GraphicsMode;
1099 release_dc_ptr( dc );
1105 /***********************************************************************
1106 * SetGraphicsMode (GDI32.@)
1108 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1111 DC *dc = get_dc_ptr( hdc );
1113 /* One would think that setting the graphics mode to GM_COMPATIBLE
1114 * would also reset the world transformation matrix to the unity
1115 * matrix. However, in Windows, this is not the case. This doesn't
1116 * make a lot of sense to me, but that's the way it is.
1119 if ((mode > 0) && (mode <= GM_LAST))
1121 ret = dc->GraphicsMode;
1122 dc->GraphicsMode = mode;
1124 release_dc_ptr( dc );
1129 /***********************************************************************
1130 * GetArcDirection (GDI32.@)
1132 INT WINAPI GetArcDirection( HDC hdc )
1135 DC * dc = get_dc_ptr( hdc );
1138 ret = dc->ArcDirection;
1139 release_dc_ptr( dc );
1145 /***********************************************************************
1146 * SetArcDirection (GDI32.@)
1148 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1151 INT nOldDirection = 0;
1153 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1155 SetLastError(ERROR_INVALID_PARAMETER);
1159 if ((dc = get_dc_ptr( hdc )))
1161 if (dc->funcs->pSetArcDirection)
1163 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1165 nOldDirection = dc->ArcDirection;
1166 dc->ArcDirection = nDirection;
1167 release_dc_ptr( dc );
1169 return nOldDirection;
1173 /***********************************************************************
1174 * GetWorldTransform (GDI32.@)
1176 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1179 if (!xform) return FALSE;
1180 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1181 *xform = dc->xformWorld2Wnd;
1182 release_dc_ptr( dc );
1187 /***********************************************************************
1188 * GetTransform (GDI32.@)
1190 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1192 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1193 FIXME("stub: don't know what to do for code %x\n", unknown );
1198 /***********************************************************************
1199 * SetWorldTransform (GDI32.@)
1201 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1206 if (!xform) return FALSE;
1208 dc = get_dc_ptr( hdc );
1209 if (!dc) return FALSE;
1211 /* Check that graphics mode is GM_ADVANCED */
1212 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1214 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1215 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1217 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1218 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) goto done;
1220 if (dc->funcs->pSetWorldTransform)
1222 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1223 if (!ret) goto done;
1226 dc->xformWorld2Wnd = *xform;
1227 DC_UpdateXforms( dc );
1230 release_dc_ptr( dc );
1235 /****************************************************************************
1236 * ModifyWorldTransform [GDI32.@]
1237 * Modifies the world transformation for a device context.
1240 * hdc [I] Handle to device context
1241 * xform [I] XFORM structure that will be used to modify the world
1243 * iMode [I] Specifies in what way to modify the world transformation
1246 * Resets the world transformation to the identity matrix.
1247 * The parameter xform is ignored.
1249 * Multiplies xform into the world transformation matrix from
1252 * Multiplies xform into the world transformation matrix from
1257 * Failure: FALSE. Use GetLastError() to determine the cause.
1259 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1263 DC *dc = get_dc_ptr( hdc );
1265 /* Check for illegal parameters */
1266 if (!dc) return FALSE;
1267 if (!xform && iMode != MWT_IDENTITY) goto done;
1269 /* Check that graphics mode is GM_ADVANCED */
1270 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1272 if (dc->funcs->pModifyWorldTransform)
1274 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1275 if (!ret) goto done;
1281 dc->xformWorld2Wnd.eM11 = 1.0f;
1282 dc->xformWorld2Wnd.eM12 = 0.0f;
1283 dc->xformWorld2Wnd.eM21 = 0.0f;
1284 dc->xformWorld2Wnd.eM22 = 1.0f;
1285 dc->xformWorld2Wnd.eDx = 0.0f;
1286 dc->xformWorld2Wnd.eDy = 0.0f;
1288 case MWT_LEFTMULTIPLY:
1289 CombineTransform( &dc->xformWorld2Wnd, xform,
1290 &dc->xformWorld2Wnd );
1292 case MWT_RIGHTMULTIPLY:
1293 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1300 DC_UpdateXforms( dc );
1303 release_dc_ptr( dc );
1308 /****************************************************************************
1309 * CombineTransform [GDI32.@]
1310 * Combines two transformation matrices.
1313 * xformResult [O] Stores the result of combining the two matrices
1314 * xform1 [I] Specifies the first matrix to apply
1315 * xform2 [I] Specifies the second matrix to apply
1318 * The same matrix can be passed in for more than one of the parameters.
1322 * Failure: FALSE. Use GetLastError() to determine the cause.
1324 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1325 const XFORM *xform2 )
1329 /* Check for illegal parameters */
1330 if (!xformResult || !xform1 || !xform2)
1333 /* Create the result in a temporary XFORM, since xformResult may be
1334 * equal to xform1 or xform2 */
1335 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1336 xform1->eM12 * xform2->eM21;
1337 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1338 xform1->eM12 * xform2->eM22;
1339 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1340 xform1->eM22 * xform2->eM21;
1341 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1342 xform1->eM22 * xform2->eM22;
1343 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1344 xform1->eDy * xform2->eM21 +
1346 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1347 xform1->eDy * xform2->eM22 +
1350 /* Copy the result to xformResult */
1351 *xformResult = xformTemp;
1357 /***********************************************************************
1358 * SetDCHook (GDI32.@)
1360 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1362 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1364 DC *dc = get_dc_ptr( hdc );
1366 if (!dc) return FALSE;
1368 if (!(dc->flags & DC_SAVED))
1370 dc->dwHookData = dwHookData;
1371 dc->hookThunk = hookProc;
1373 release_dc_ptr( dc );
1378 /***********************************************************************
1379 * GetDCHook (GDI32.@)
1381 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1383 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1385 DC *dc = get_dc_ptr( hdc );
1389 if (proc) *proc = dc->hookThunk;
1390 ret = dc->dwHookData;
1391 release_dc_ptr( dc );
1396 /* relay function to call the 16-bit DC hook proc */
1397 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1401 DC *dc = get_dc_ptr( hdc );
1403 if (!dc) return FALSE;
1406 args[5] = HDC_16(hdc);
1408 args[3] = HIWORD(data);
1409 args[2] = LOWORD(data);
1410 args[1] = HIWORD(lParam);
1411 args[0] = LOWORD(lParam);
1412 WOWCallback16Ex( (DWORD)dc->hookProc, WCB16_PASCAL, sizeof(args), args, &ret );
1414 release_dc_ptr( dc );
1418 /***********************************************************************
1419 * SetDCHook (GDI.190)
1421 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1423 DC *dc = get_dc_ptr( HDC_32(hdc16) );
1425 if (!dc) return FALSE;
1426 if (!(dc->flags & DC_SAVED))
1428 dc->dwHookData = dwHookData;
1429 dc->hookThunk = call_dc_hook16;
1430 dc->hookProc = hookProc;
1432 release_dc_ptr( dc );
1437 /***********************************************************************
1438 * GetDCHook (GDI.191)
1440 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1442 HDC hdc = HDC_32( hdc16 );
1443 DC *dc = get_dc_ptr( hdc );
1447 *phookProc = dc->hookProc;
1448 ret = dc->dwHookData;
1449 release_dc_ptr( dc );
1454 /***********************************************************************
1455 * SetHookFlags (GDI32.@)
1457 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1459 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1461 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1466 /* "Undocumented Windows" info is slightly confusing. */
1468 TRACE("hDC %p, flags %04x\n",hdc,flags);
1470 if (flags & DCHF_INVALIDATEVISRGN)
1471 ret = InterlockedExchange( &dc->dirty, 1 );
1472 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1473 ret = InterlockedExchange( &dc->dirty, 0 );
1475 GDI_ReleaseObj( dc );
1479 /***********************************************************************
1480 * SetICMMode (GDI32.@)
1482 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1484 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1485 if (iEnableICM == ICM_OFF) return ICM_OFF;
1486 if (iEnableICM == ICM_ON) return 0;
1487 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1491 /***********************************************************************
1492 * GetDeviceGammaRamp (GDI32.@)
1494 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1497 DC *dc = get_dc_ptr( hDC );
1501 if (dc->funcs->pGetDeviceGammaRamp)
1502 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1503 release_dc_ptr( dc );
1508 /***********************************************************************
1509 * SetDeviceGammaRamp (GDI32.@)
1511 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1514 DC *dc = get_dc_ptr( hDC );
1518 if (dc->funcs->pSetDeviceGammaRamp)
1519 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1520 release_dc_ptr( dc );
1525 /***********************************************************************
1526 * GetColorSpace (GDI32.@)
1528 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1530 /*FIXME Need to to whatever GetColorSpace actually does */
1534 /***********************************************************************
1535 * CreateColorSpaceA (GDI32.@)
1537 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1543 /***********************************************************************
1544 * CreateColorSpaceW (GDI32.@)
1546 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1552 /***********************************************************************
1553 * DeleteColorSpace (GDI32.@)
1555 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1562 /***********************************************************************
1563 * SetColorSpace (GDI32.@)
1565 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1572 /***********************************************************************
1573 * GetBoundsRect (GDI32.@)
1575 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1578 DC *dc = get_dc_ptr( hdc );
1580 if ( !dc ) return 0;
1582 if (rect) *rect = dc->BoundsRect;
1584 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1586 if (flags & DCB_RESET)
1588 dc->BoundsRect.left = 0;
1589 dc->BoundsRect.top = 0;
1590 dc->BoundsRect.right = 0;
1591 dc->BoundsRect.bottom = 0;
1592 dc->flags &= ~DC_BOUNDS_SET;
1594 release_dc_ptr( dc );
1599 /***********************************************************************
1600 * SetBoundsRect (GDI32.@)
1602 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1607 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1608 if (!(dc = get_dc_ptr( hdc ))) return 0;
1610 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1611 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1613 if (flags & DCB_RESET)
1615 dc->BoundsRect.left = 0;
1616 dc->BoundsRect.top = 0;
1617 dc->BoundsRect.right = 0;
1618 dc->BoundsRect.bottom = 0;
1619 dc->flags &= ~DC_BOUNDS_SET;
1622 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1624 if (dc->flags & DC_BOUNDS_SET)
1626 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1627 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1628 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1629 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1633 dc->BoundsRect = *rect;
1634 dc->flags |= DC_BOUNDS_SET;
1638 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1639 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1641 release_dc_ptr( dc );
1646 /***********************************************************************
1647 * GetRelAbs (GDI32.@)
1649 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1652 DC *dc = get_dc_ptr( hdc );
1655 ret = dc->relAbsMode;
1656 release_dc_ptr( dc );
1664 /***********************************************************************
1665 * GetBkMode (GDI32.@)
1667 INT WINAPI GetBkMode( HDC hdc )
1670 DC * dc = get_dc_ptr( hdc );
1673 ret = dc->backgroundMode;
1674 release_dc_ptr( dc );
1680 /***********************************************************************
1681 * SetBkMode (GDI32.@)
1683 INT WINAPI SetBkMode( HDC hdc, INT mode )
1687 if ((mode <= 0) || (mode > BKMODE_LAST))
1689 SetLastError(ERROR_INVALID_PARAMETER);
1692 if (!(dc = get_dc_ptr( hdc ))) return 0;
1694 ret = dc->backgroundMode;
1695 if (dc->funcs->pSetBkMode)
1696 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1699 dc->backgroundMode = mode;
1700 release_dc_ptr( dc );
1705 /***********************************************************************
1708 INT WINAPI GetROP2( HDC hdc )
1711 DC * dc = get_dc_ptr( hdc );
1715 release_dc_ptr( dc );
1721 /***********************************************************************
1724 INT WINAPI SetROP2( HDC hdc, INT mode )
1728 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1730 SetLastError(ERROR_INVALID_PARAMETER);
1733 if (!(dc = get_dc_ptr( hdc ))) return 0;
1735 if (dc->funcs->pSetROP2)
1736 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1740 release_dc_ptr( dc );
1745 /***********************************************************************
1746 * SetRelAbs (GDI32.@)
1748 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1752 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1754 SetLastError(ERROR_INVALID_PARAMETER);
1757 if (!(dc = get_dc_ptr( hdc ))) return 0;
1758 if (dc->funcs->pSetRelAbs)
1759 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1762 ret = dc->relAbsMode;
1763 dc->relAbsMode = mode;
1765 release_dc_ptr( dc );
1770 /***********************************************************************
1771 * GetPolyFillMode (GDI32.@)
1773 INT WINAPI GetPolyFillMode( HDC hdc )
1776 DC * dc = get_dc_ptr( hdc );
1779 ret = dc->polyFillMode;
1780 release_dc_ptr( dc );
1786 /***********************************************************************
1787 * SetPolyFillMode (GDI32.@)
1789 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1793 if ((mode <= 0) || (mode > POLYFILL_LAST))
1795 SetLastError(ERROR_INVALID_PARAMETER);
1798 if (!(dc = get_dc_ptr( hdc ))) return 0;
1799 ret = dc->polyFillMode;
1800 if (dc->funcs->pSetPolyFillMode)
1801 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1804 dc->polyFillMode = mode;
1805 release_dc_ptr( dc );
1810 /***********************************************************************
1811 * GetStretchBltMode (GDI32.@)
1813 INT WINAPI GetStretchBltMode( HDC hdc )
1816 DC * dc = get_dc_ptr( hdc );
1819 ret = dc->stretchBltMode;
1820 release_dc_ptr( dc );
1826 /***********************************************************************
1827 * SetStretchBltMode (GDI32.@)
1829 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1833 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1835 SetLastError(ERROR_INVALID_PARAMETER);
1838 if (!(dc = get_dc_ptr( hdc ))) return 0;
1839 ret = dc->stretchBltMode;
1840 if (dc->funcs->pSetStretchBltMode)
1841 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1844 dc->stretchBltMode = mode;
1845 release_dc_ptr( dc );
1850 /***********************************************************************
1851 * GetMapMode (GDI32.@)
1853 INT WINAPI GetMapMode( HDC hdc )
1856 DC * dc = get_dc_ptr( hdc );
1860 release_dc_ptr( dc );
1866 /***********************************************************************
1867 * GetBrushOrgEx (GDI32.@)
1869 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1871 DC * dc = get_dc_ptr( hdc );
1872 if (!dc) return FALSE;
1873 pt->x = dc->brushOrgX;
1874 pt->y = dc->brushOrgY;
1875 release_dc_ptr( dc );
1880 /***********************************************************************
1881 * GetCurrentPositionEx (GDI32.@)
1883 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1885 DC * dc = get_dc_ptr( hdc );
1886 if (!dc) return FALSE;
1887 pt->x = dc->CursPosX;
1888 pt->y = dc->CursPosY;
1889 release_dc_ptr( dc );
1894 /***********************************************************************
1895 * GetViewportExtEx (GDI32.@)
1897 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1899 DC * dc = get_dc_ptr( hdc );
1900 if (!dc) return FALSE;
1901 size->cx = dc->vportExtX;
1902 size->cy = dc->vportExtY;
1903 release_dc_ptr( dc );
1908 /***********************************************************************
1909 * GetViewportOrgEx (GDI32.@)
1911 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1913 DC * dc = get_dc_ptr( hdc );
1914 if (!dc) return FALSE;
1915 pt->x = dc->vportOrgX;
1916 pt->y = dc->vportOrgY;
1917 release_dc_ptr( dc );
1922 /***********************************************************************
1923 * GetWindowExtEx (GDI32.@)
1925 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1927 DC * dc = get_dc_ptr( hdc );
1928 if (!dc) return FALSE;
1929 size->cx = dc->wndExtX;
1930 size->cy = dc->wndExtY;
1931 release_dc_ptr( dc );
1936 /***********************************************************************
1937 * GetWindowOrgEx (GDI32.@)
1939 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1941 DC * dc = get_dc_ptr( hdc );
1942 if (!dc) return FALSE;
1943 pt->x = dc->wndOrgX;
1944 pt->y = dc->wndOrgY;
1945 release_dc_ptr( dc );
1950 /***********************************************************************
1951 * GetLayout (GDI32.@)
1953 * Gets left->right or right->left text layout flags of a dc.
1956 DWORD WINAPI GetLayout(HDC hdc)
1958 DWORD layout = GDI_ERROR;
1960 DC * dc = get_dc_ptr( hdc );
1963 layout = dc->layout;
1964 release_dc_ptr( dc );
1967 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1972 /***********************************************************************
1973 * SetLayout (GDI32.@)
1975 * Sets left->right or right->left text layout flags of a dc.
1978 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1980 DWORD oldlayout = GDI_ERROR;
1982 DC * dc = get_dc_ptr( hdc );
1985 oldlayout = dc->layout;
1986 dc->layout = layout;
1987 release_dc_ptr( dc );
1990 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1995 /***********************************************************************
1996 * GetDCBrushColor (GDI32.@)
1998 * Retrieves the current brush color for the specified device
2002 COLORREF WINAPI GetDCBrushColor(HDC hdc)
2005 COLORREF dcBrushColor = CLR_INVALID;
2007 TRACE("hdc(%p)\n", hdc);
2009 dc = get_dc_ptr( hdc );
2012 dcBrushColor = dc->dcBrushColor;
2013 release_dc_ptr( dc );
2016 return dcBrushColor;
2019 /***********************************************************************
2020 * SetDCBrushColor (GDI32.@)
2022 * Sets the current device context (DC) brush color to the specified
2023 * color value. If the device cannot represent the specified color
2024 * value, the color is set to the nearest physical color.
2027 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2030 COLORREF oldClr = CLR_INVALID;
2032 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2034 dc = get_dc_ptr( hdc );
2037 if (dc->funcs->pSetDCBrushColor)
2038 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2039 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2041 /* If DC_BRUSH is selected, update driver pen color */
2042 HBRUSH hBrush = CreateSolidBrush( crColor );
2043 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2044 DeleteObject( hBrush );
2047 if (crColor != CLR_INVALID)
2049 oldClr = dc->dcBrushColor;
2050 dc->dcBrushColor = crColor;
2053 release_dc_ptr( dc );
2059 /***********************************************************************
2060 * GetDCPenColor (GDI32.@)
2062 * Retrieves the current pen color for the specified device
2066 COLORREF WINAPI GetDCPenColor(HDC hdc)
2069 COLORREF dcPenColor = CLR_INVALID;
2071 TRACE("hdc(%p)\n", hdc);
2073 dc = get_dc_ptr( hdc );
2076 dcPenColor = dc->dcPenColor;
2077 release_dc_ptr( dc );
2083 /***********************************************************************
2084 * SetDCPenColor (GDI32.@)
2086 * Sets the current device context (DC) pen color to the specified
2087 * color value. If the device cannot represent the specified color
2088 * value, the color is set to the nearest physical color.
2091 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2094 COLORREF oldClr = CLR_INVALID;
2096 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2098 dc = get_dc_ptr( hdc );
2101 if (dc->funcs->pSetDCPenColor)
2102 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2103 else if (dc->hPen == GetStockObject( DC_PEN ))
2105 /* If DC_PEN is selected, update the driver pen color */
2106 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2107 HPEN hPen = CreatePenIndirect( &logpen );
2108 dc->funcs->pSelectPen( dc->physDev, hPen );
2109 DeleteObject( hPen );
2112 if (crColor != CLR_INVALID)
2114 oldClr = dc->dcPenColor;
2115 dc->dcPenColor = crColor;
2118 release_dc_ptr( dc );
2124 /***********************************************************************
2125 * CancelDC (GDI32.@)
2127 BOOL WINAPI CancelDC(HDC hdc)
2133 /***********************************************************************
2134 * SetVirtualResolution (GDI32.@)
2136 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2138 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2140 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2144 /*******************************************************************
2145 * GetMiterLimit [GDI32.@]
2149 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2154 TRACE("(%p,%p)\n", hdc, peLimit);
2156 dc = get_dc_ptr( hdc );
2160 *peLimit = dc->miterLimit;
2162 release_dc_ptr( dc );
2168 /*******************************************************************
2169 * SetMiterLimit [GDI32.@]
2173 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2178 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2180 dc = get_dc_ptr( hdc );
2184 *peOldLimit = dc->miterLimit;
2185 dc->miterLimit = eNewLimit;
2186 release_dc_ptr( dc );
2192 /*******************************************************************
2193 * GdiIsMetaPrintDC [GDI32.@]
2195 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2201 /*******************************************************************
2202 * GdiIsMetaFileDC [GDI32.@]
2204 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2208 switch( GetObjectType( hdc ) )
2217 /*******************************************************************
2218 * GdiIsPlayMetafileDC [GDI32.@]
2220 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)