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, 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 */
55 static inline DC *get_dc_obj( HDC hdc )
57 DC *dc = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
60 if ((GDIMAGIC(dc->header.wMagic) != DC_MAGIC) &&
61 (GDIMAGIC(dc->header.wMagic) != MEMORY_DC_MAGIC) &&
62 (GDIMAGIC(dc->header.wMagic) != METAFILE_DC_MAGIC) &&
63 (GDIMAGIC(dc->header.wMagic) != ENHMETAFILE_DC_MAGIC))
65 GDI_ReleaseObj( hdc );
66 SetLastError( ERROR_INVALID_HANDLE );
73 /***********************************************************************
76 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
81 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
86 dc->thread = GetCurrentThreadId();
102 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
107 dc->hMetaClipRgn = 0;
109 dc->hPen = GetStockObject( BLACK_PEN );
110 dc->hBrush = GetStockObject( WHITE_BRUSH );
111 dc->hFont = GetStockObject( SYSTEM_FONT );
114 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
116 dc->ROPmode = R2_COPYPEN;
117 dc->polyFillMode = ALTERNATE;
118 dc->stretchBltMode = BLACKONWHITE;
119 dc->relAbsMode = ABSOLUTE;
120 dc->backgroundMode = OPAQUE;
121 dc->backgroundColor = RGB( 255, 255, 255 );
122 dc->dcBrushColor = RGB( 255, 255, 255 );
123 dc->dcPenColor = RGB( 0, 0, 0 );
124 dc->textColor = RGB( 0, 0, 0 );
127 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
131 dc->MapMode = MM_TEXT;
132 dc->GraphicsMode = GM_COMPATIBLE;
133 dc->pAbortProc = NULL;
136 dc->ArcDirection = AD_COUNTERCLOCKWISE;
137 dc->xformWorld2Wnd.eM11 = 1.0f;
138 dc->xformWorld2Wnd.eM12 = 0.0f;
139 dc->xformWorld2Wnd.eM21 = 0.0f;
140 dc->xformWorld2Wnd.eM22 = 1.0f;
141 dc->xformWorld2Wnd.eDx = 0.0f;
142 dc->xformWorld2Wnd.eDy = 0.0f;
143 dc->xformWorld2Vport = dc->xformWorld2Wnd;
144 dc->xformVport2World = dc->xformWorld2Wnd;
145 dc->vport2WorldValid = TRUE;
146 dc->BoundsRect.left = 0;
147 dc->BoundsRect.top = 0;
148 dc->BoundsRect.right = 0;
149 dc->BoundsRect.bottom = 0;
150 dc->saved_visrgn = NULL;
151 PATH_InitGdiPath(&dc->path);
157 /***********************************************************************
160 DC *DC_GetDCPtr( HDC hdc )
162 DC *dc = get_dc_obj( hdc );
163 if (!dc) return NULL;
165 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
167 dc->thread = GetCurrentThreadId();
169 else if (dc->thread != GetCurrentThreadId())
171 GDI_ReleaseObj( hdc );
172 SetLastError( ERROR_ACCESS_DENIED );
175 else InterlockedIncrement( &dc->refcount );
180 /***********************************************************************
183 * Retrieve a DC ptr while making sure the visRgn is updated.
184 * This function may call up to USER so the GDI lock should _not_
185 * be held when calling it.
187 DC *DC_GetDCUpdate( HDC hdc )
189 DC *dc = DC_GetDCPtr( hdc );
190 if (!dc) return NULL;
191 while (InterlockedExchange( &dc->dirty, 0 ))
193 DCHOOKPROC proc = dc->hookThunk;
196 DWORD_PTR data = dc->dwHookData;
197 DC_ReleaseDCPtr( dc );
198 proc( hdc, DCHC_INVALIDVISRGN, data, 0 );
199 if (!(dc = DC_GetDCPtr( hdc ))) break;
200 /* otherwise restart the loop in case it became dirty again in the meantime */
207 /***********************************************************************
210 void DC_ReleaseDCPtr( DC *dc )
212 release_dc_ptr( dc );
213 GDI_ReleaseObj( dc->hSelf );
217 /***********************************************************************
220 BOOL DC_FreeDCPtr( DC *dc )
222 assert( dc->refcount == 1 );
223 return GDI_FreeObject( dc->hSelf, dc );
227 /***********************************************************************
230 * Retrieve a DC pointer but release the GDI lock.
232 DC *get_dc_ptr( HDC hdc )
234 DC *dc = get_dc_obj( hdc );
235 if (!dc) return NULL;
237 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
239 dc->thread = GetCurrentThreadId();
241 else if (dc->thread != GetCurrentThreadId())
243 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
244 GDI_ReleaseObj( hdc );
247 else InterlockedIncrement( &dc->refcount );
249 GDI_ReleaseObj( hdc );
254 /***********************************************************************
257 void release_dc_ptr( DC *dc )
262 ref = InterlockedDecrement( &dc->refcount );
264 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
268 /***********************************************************************
271 * Make sure the DC vis region is up to date.
272 * This function may call up to USER so the GDI lock should _not_
273 * be held when calling it.
275 void update_dc( DC *dc )
277 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookThunk)
278 dc->hookThunk( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
282 /***********************************************************************
285 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
287 GDI_ReleaseObj( handle );
288 return DeleteDC( handle );
292 /***********************************************************************
295 * Setup device-specific DC values for a newly created DC.
297 void DC_InitDC( DC* dc )
299 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
300 SetTextColor( dc->hSelf, dc->textColor );
301 SetBkColor( dc->hSelf, dc->backgroundColor );
302 SelectObject( dc->hSelf, dc->hPen );
303 SelectObject( dc->hSelf, dc->hBrush );
304 SelectObject( dc->hSelf, dc->hFont );
305 CLIPPING_UpdateGCRegion( dc );
309 /***********************************************************************
312 * Computes the inverse of the transformation xformSrc and stores it to
313 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
316 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
320 determinant = xformSrc->eM11*xformSrc->eM22 -
321 xformSrc->eM12*xformSrc->eM21;
322 if (determinant > -1e-12 && determinant < 1e-12)
325 xformDest->eM11 = xformSrc->eM22 / determinant;
326 xformDest->eM12 = -xformSrc->eM12 / determinant;
327 xformDest->eM21 = -xformSrc->eM21 / determinant;
328 xformDest->eM22 = xformSrc->eM11 / determinant;
329 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
330 xformSrc->eDy * xformDest->eM21;
331 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
332 xformSrc->eDy * xformDest->eM22;
338 /***********************************************************************
341 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
342 * fields of the specified DC by creating a transformation that
343 * represents the current mapping mode and combining it with the DC's
344 * world transform. This function should be called whenever the
345 * parameters associated with the mapping mode (window and viewport
346 * extents and origins) or the world transform change.
348 void DC_UpdateXforms( DC *dc )
350 XFORM xformWnd2Vport, oldworld2vport;
351 FLOAT scaleX, scaleY;
353 /* Construct a transformation to do the window-to-viewport conversion */
354 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
355 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
356 xformWnd2Vport.eM11 = scaleX;
357 xformWnd2Vport.eM12 = 0.0;
358 xformWnd2Vport.eM21 = 0.0;
359 xformWnd2Vport.eM22 = scaleY;
360 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
361 scaleX * (FLOAT)dc->wndOrgX;
362 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
363 scaleY * (FLOAT)dc->wndOrgY;
365 oldworld2vport = dc->xformWorld2Vport;
366 /* Combine with the world transformation */
367 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
370 /* Create inverse of world-to-viewport transformation */
371 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
372 &dc->xformVport2World );
374 /* Reselect the font and pen back into the dc so that the size
376 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
378 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
379 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
384 /***********************************************************************
385 * GetDCState (Not a Windows API)
387 HDC WINAPI GetDCState( HDC hdc )
392 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
393 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
395 DC_ReleaseDCPtr( dc );
398 TRACE("(%p): returning %p\n", hdc, handle );
400 newdc->flags = dc->flags | DC_SAVED;
401 newdc->layout = dc->layout;
402 newdc->hPen = dc->hPen;
403 newdc->hBrush = dc->hBrush;
404 newdc->hFont = dc->hFont;
405 newdc->hBitmap = dc->hBitmap;
406 newdc->hDevice = dc->hDevice;
407 newdc->hPalette = dc->hPalette;
408 newdc->ROPmode = dc->ROPmode;
409 newdc->polyFillMode = dc->polyFillMode;
410 newdc->stretchBltMode = dc->stretchBltMode;
411 newdc->relAbsMode = dc->relAbsMode;
412 newdc->backgroundMode = dc->backgroundMode;
413 newdc->backgroundColor = dc->backgroundColor;
414 newdc->textColor = dc->textColor;
415 newdc->dcBrushColor = dc->dcBrushColor;
416 newdc->dcPenColor = dc->dcPenColor;
417 newdc->brushOrgX = dc->brushOrgX;
418 newdc->brushOrgY = dc->brushOrgY;
419 newdc->textAlign = dc->textAlign;
420 newdc->charExtra = dc->charExtra;
421 newdc->breakExtra = dc->breakExtra;
422 newdc->breakRem = dc->breakRem;
423 newdc->MapMode = dc->MapMode;
424 newdc->GraphicsMode = dc->GraphicsMode;
425 newdc->CursPosX = dc->CursPosX;
426 newdc->CursPosY = dc->CursPosY;
427 newdc->ArcDirection = dc->ArcDirection;
428 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
429 newdc->xformWorld2Vport = dc->xformWorld2Vport;
430 newdc->xformVport2World = dc->xformVport2World;
431 newdc->vport2WorldValid = dc->vport2WorldValid;
432 newdc->wndOrgX = dc->wndOrgX;
433 newdc->wndOrgY = dc->wndOrgY;
434 newdc->wndExtX = dc->wndExtX;
435 newdc->wndExtY = dc->wndExtY;
436 newdc->vportOrgX = dc->vportOrgX;
437 newdc->vportOrgY = dc->vportOrgY;
438 newdc->vportExtX = dc->vportExtX;
439 newdc->vportExtY = dc->vportExtY;
440 newdc->BoundsRect = dc->BoundsRect;
442 newdc->hSelf = (HDC)handle;
443 newdc->thread = GetCurrentThreadId();
445 newdc->saveLevel = 0;
448 PATH_InitGdiPath( &newdc->path );
450 newdc->pAbortProc = NULL;
451 newdc->hookThunk = NULL;
453 newdc->saved_visrgn = NULL;
455 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
460 newdc->hMetaClipRgn = 0;
463 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
464 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
468 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
469 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
471 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
474 newdc->gdiFont = dc->gdiFont;
478 DC_ReleaseDCPtr( newdc );
479 DC_ReleaseDCPtr( dc );
484 /***********************************************************************
485 * SetDCState (Not a Windows API)
487 void WINAPI SetDCState( HDC hdc, HDC hdcs )
491 if (!(dc = DC_GetDCUpdate( hdc ))) return;
492 if (!(dcs = DC_GetDCPtr( hdcs )))
494 DC_ReleaseDCPtr( dc );
497 if (!dcs->flags & DC_SAVED)
499 DC_ReleaseDCPtr( dc );
500 DC_ReleaseDCPtr( dcs );
503 TRACE("%p %p\n", hdc, hdcs );
505 dc->flags = dcs->flags & ~DC_SAVED;
506 dc->layout = dcs->layout;
507 dc->hDevice = dcs->hDevice;
508 dc->ROPmode = dcs->ROPmode;
509 dc->polyFillMode = dcs->polyFillMode;
510 dc->stretchBltMode = dcs->stretchBltMode;
511 dc->relAbsMode = dcs->relAbsMode;
512 dc->backgroundMode = dcs->backgroundMode;
513 dc->backgroundColor = dcs->backgroundColor;
514 dc->textColor = dcs->textColor;
515 dc->dcBrushColor = dcs->dcBrushColor;
516 dc->dcPenColor = dcs->dcPenColor;
517 dc->brushOrgX = dcs->brushOrgX;
518 dc->brushOrgY = dcs->brushOrgY;
519 dc->textAlign = dcs->textAlign;
520 dc->charExtra = dcs->charExtra;
521 dc->breakExtra = dcs->breakExtra;
522 dc->breakRem = dcs->breakRem;
523 dc->MapMode = dcs->MapMode;
524 dc->GraphicsMode = dcs->GraphicsMode;
525 dc->CursPosX = dcs->CursPosX;
526 dc->CursPosY = dcs->CursPosY;
527 dc->ArcDirection = dcs->ArcDirection;
528 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
529 dc->xformWorld2Vport = dcs->xformWorld2Vport;
530 dc->xformVport2World = dcs->xformVport2World;
531 dc->vport2WorldValid = dcs->vport2WorldValid;
532 dc->BoundsRect = dcs->BoundsRect;
534 dc->wndOrgX = dcs->wndOrgX;
535 dc->wndOrgY = dcs->wndOrgY;
536 dc->wndExtX = dcs->wndExtX;
537 dc->wndExtY = dcs->wndExtY;
538 dc->vportOrgX = dcs->vportOrgX;
539 dc->vportOrgY = dcs->vportOrgY;
540 dc->vportExtX = dcs->vportExtX;
541 dc->vportExtY = dcs->vportExtY;
545 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
546 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
550 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
555 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
556 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
560 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
563 CLIPPING_UpdateGCRegion( dc );
565 SelectObject( hdc, dcs->hBitmap );
566 SelectObject( hdc, dcs->hBrush );
567 SelectObject( hdc, dcs->hFont );
568 SelectObject( hdc, dcs->hPen );
569 SetBkColor( hdc, dcs->backgroundColor);
570 SetTextColor( hdc, dcs->textColor);
571 GDISelectPalette( hdc, dcs->hPalette, FALSE );
572 DC_ReleaseDCPtr( dcs );
573 DC_ReleaseDCPtr( dc );
577 /***********************************************************************
578 * GetDCState (GDI.179)
580 HDC16 WINAPI GetDCState16( HDC16 hdc )
582 return HDC_16( GetDCState( HDC_32(hdc) ));
586 /***********************************************************************
587 * SetDCState (GDI.180)
589 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
591 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
595 /***********************************************************************
598 INT WINAPI SaveDC( HDC hdc )
604 dc = DC_GetDCPtr( hdc );
607 if(dc->funcs->pSaveDC)
609 ret = dc->funcs->pSaveDC( dc->physDev );
611 ret = ++dc->saveLevel;
612 DC_ReleaseDCPtr( dc );
616 if (!(hdcs = GetDCState( hdc )))
618 DC_ReleaseDCPtr( dc );
621 dcs = DC_GetDCPtr( hdcs );
623 /* Copy path. The reason why path saving / restoring is in SaveDC/
624 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
625 * functions are only in Win16 (which doesn't have paths) and that
626 * SetDCState doesn't allow us to signal an error (which can happen
627 * when copying paths).
629 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
631 DC_ReleaseDCPtr( dc );
632 DC_ReleaseDCPtr( dcs );
637 dcs->saved_dc = dc->saved_dc;
639 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
640 ret = ++dc->saveLevel;
641 DC_ReleaseDCPtr( dcs );
642 DC_ReleaseDCPtr( dc );
647 /***********************************************************************
648 * RestoreDC (GDI32.@)
650 BOOL WINAPI RestoreDC( HDC hdc, INT level )
655 TRACE("%p %d\n", hdc, level );
656 dc = DC_GetDCUpdate( hdc );
657 if(!dc) return FALSE;
659 if(abs(level) > dc->saveLevel || level == 0)
661 DC_ReleaseDCPtr( dc );
665 if(dc->funcs->pRestoreDC)
667 success = dc->funcs->pRestoreDC( dc->physDev, level );
668 if(level < 0) level = dc->saveLevel + level + 1;
670 dc->saveLevel = level - 1;
671 DC_ReleaseDCPtr( dc );
675 if (level < 0) level = dc->saveLevel + level + 1;
677 while (dc->saveLevel >= level)
679 HDC hdcs = dc->saved_dc;
680 if (!(dcs = DC_GetDCPtr( hdcs )))
682 DC_ReleaseDCPtr( dc );
685 dc->saved_dc = dcs->saved_dc;
687 if (--dc->saveLevel < level)
689 SetDCState( hdc, hdcs );
690 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
691 /* FIXME: This might not be quite right, since we're
692 * returning FALSE but still destroying the saved DC state */
695 DC_ReleaseDCPtr( dcs );
696 DC_ReleaseDCPtr( dc );
698 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
700 DC_ReleaseDCPtr( dc );
705 /***********************************************************************
706 * CreateDCW (GDI32.@)
708 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
709 const DEVMODEW *initData )
713 const DC_FUNCTIONS *funcs;
718 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
722 ERR( "no device found for %s\n", debugstr_w(device) );
725 strcpyW(buf, driver);
728 if (!(funcs = DRIVER_load_driver( buf )))
730 ERR( "no driver found for %s\n", debugstr_w(buf) );
733 if (!(dc = DC_AllocDC( funcs, DC_MAGIC ))) goto error;
736 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
737 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
739 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
740 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
742 if (dc->funcs->pCreateDC &&
743 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
745 WARN("creation aborted by device\n" );
749 SetRectRgn( dc->hVisRgn, 0, 0,
750 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
753 DC_ReleaseDCPtr( dc );
757 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
758 if (dc) DC_FreeDCPtr( dc );
759 DRIVER_release_driver( funcs );
764 /***********************************************************************
765 * CreateDCA (GDI32.@)
767 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
768 const DEVMODEA *initData )
770 UNICODE_STRING driverW, deviceW, outputW;
774 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
775 else driverW.Buffer = NULL;
777 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
778 else deviceW.Buffer = NULL;
780 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
781 else outputW.Buffer = NULL;
786 /* don't convert initData for DISPLAY driver, it's not used */
787 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
788 initDataW = GdiConvertToDevmodeW(initData);
791 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
793 RtlFreeUnicodeString(&driverW);
794 RtlFreeUnicodeString(&deviceW);
795 RtlFreeUnicodeString(&outputW);
796 HeapFree(GetProcessHeap(), 0, initDataW);
801 /***********************************************************************
802 * CreateICA (GDI32.@)
804 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
805 const DEVMODEA* initData )
807 /* Nothing special yet for ICs */
808 return CreateDCA( driver, device, output, initData );
812 /***********************************************************************
813 * CreateICW (GDI32.@)
815 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
816 const DEVMODEW* initData )
818 /* Nothing special yet for ICs */
819 return CreateDCW( driver, device, output, initData );
823 /***********************************************************************
824 * CreateCompatibleDC (GDI32.@)
826 HDC WINAPI CreateCompatibleDC( HDC hdc )
829 const DC_FUNCTIONS *funcs = NULL;
830 PHYSDEV physDev = NULL;
834 if ((origDC = DC_GetDCPtr( hdc )))
836 if (GetObjectType( hdc ) == OBJ_DC)
838 funcs = origDC->funcs;
839 physDev = origDC->physDev;
841 DC_ReleaseDCPtr( origDC ); /* can't hold the lock while loading the driver */
842 if (funcs) funcs = DRIVER_get_driver( funcs );
845 if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
847 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC ))) goto error;
849 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
851 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
852 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
854 /* Copy the driver-specific physical device info into
855 * the new DC. The driver may use this read-only info
856 * while creating the compatible DC below. */
857 dc->physDev = physDev;
859 if (dc->funcs->pCreateDC &&
860 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
862 WARN("creation aborted by device\n");
867 DC_ReleaseDCPtr( dc );
871 if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
872 if (dc) DC_FreeDCPtr( dc );
873 DRIVER_release_driver( funcs );
878 /***********************************************************************
881 BOOL WINAPI DeleteDC( HDC hdc )
883 const DC_FUNCTIONS *funcs = NULL;
890 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
891 if (dc->refcount != 1)
893 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
894 DC_ReleaseDCPtr( dc );
898 /* Call hook procedure to check whether is it OK to delete this DC */
901 DCHOOKPROC proc = dc->hookThunk;
902 DWORD_PTR data = dc->dwHookData;
903 DC_ReleaseDCPtr( dc );
904 if (!proc( hdc, DCHC_DELETEDC, data, 0 )) return FALSE;
905 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
908 while (dc->saveLevel)
911 HDC hdcs = dc->saved_dc;
912 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
913 dc->saved_dc = dcs->saved_dc;
915 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
916 if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
917 if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
918 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
919 PATH_DestroyGdiPath(&dcs->path);
923 if (!(dc->flags & DC_SAVED))
925 SelectObject( hdc, GetStockObject(BLACK_PEN) );
926 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
927 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
928 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
930 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
934 while (dc->saved_visrgn)
936 struct saved_visrgn *next = dc->saved_visrgn->next;
937 DeleteObject( dc->saved_visrgn->hrgn );
938 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
939 dc->saved_visrgn = next;
941 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
942 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
943 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
944 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
945 PATH_DestroyGdiPath(&dc->path);
948 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
953 /***********************************************************************
956 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
961 if ((dc = DC_GetDCPtr( hdc )))
963 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
964 DC_ReleaseDCPtr( dc );
970 /***********************************************************************
973 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
978 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
979 else devmodeW = NULL;
981 ret = ResetDCW(hdc, devmodeW);
983 HeapFree(GetProcessHeap(), 0, devmodeW);
988 /***********************************************************************
989 * GetDeviceCaps (GDI32.@)
991 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
996 if ((dc = DC_GetDCPtr( hdc )))
998 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
999 else switch(cap) /* return meaningful values for some entries */
1001 case HORZRES: ret = 640; break;
1002 case VERTRES: ret = 480; break;
1003 case BITSPIXEL: ret = 1; break;
1004 case PLANES: ret = 1; break;
1005 case NUMCOLORS: ret = 2; break;
1006 case ASPECTX: ret = 36; break;
1007 case ASPECTY: ret = 36; break;
1008 case ASPECTXY: ret = 51; break;
1009 case LOGPIXELSX: ret = 72; break;
1010 case LOGPIXELSY: ret = 72; break;
1011 case SIZEPALETTE: ret = 2; break;
1013 DC_ReleaseDCPtr( dc );
1019 /***********************************************************************
1020 * GetBkColor (GDI32.@)
1022 COLORREF WINAPI GetBkColor( HDC hdc )
1025 DC * dc = DC_GetDCPtr( hdc );
1028 ret = dc->backgroundColor;
1029 DC_ReleaseDCPtr( dc );
1035 /***********************************************************************
1036 * SetBkColor (GDI32.@)
1038 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
1041 DC * dc = DC_GetDCPtr( hdc );
1043 TRACE("hdc=%p color=0x%08x\n", hdc, color);
1045 if (!dc) return CLR_INVALID;
1046 oldColor = dc->backgroundColor;
1047 if (dc->funcs->pSetBkColor)
1049 color = dc->funcs->pSetBkColor(dc->physDev, color);
1050 if (color == CLR_INVALID) /* don't change it */
1053 oldColor = CLR_INVALID;
1056 dc->backgroundColor = color;
1057 DC_ReleaseDCPtr( dc );
1062 /***********************************************************************
1063 * GetTextColor (GDI32.@)
1065 COLORREF WINAPI GetTextColor( HDC hdc )
1068 DC * dc = DC_GetDCPtr( hdc );
1071 ret = dc->textColor;
1072 DC_ReleaseDCPtr( dc );
1078 /***********************************************************************
1079 * SetTextColor (GDI32.@)
1081 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
1084 DC * dc = DC_GetDCPtr( hdc );
1086 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
1088 if (!dc) return CLR_INVALID;
1089 oldColor = dc->textColor;
1090 if (dc->funcs->pSetTextColor)
1092 color = dc->funcs->pSetTextColor(dc->physDev, color);
1093 if (color == CLR_INVALID) /* don't change it */
1096 oldColor = CLR_INVALID;
1099 dc->textColor = color;
1100 DC_ReleaseDCPtr( dc );
1105 /***********************************************************************
1106 * GetTextAlign (GDI32.@)
1108 UINT WINAPI GetTextAlign( HDC hdc )
1111 DC * dc = DC_GetDCPtr( hdc );
1114 ret = dc->textAlign;
1115 DC_ReleaseDCPtr( dc );
1121 /***********************************************************************
1122 * SetTextAlign (GDI32.@)
1124 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1127 DC *dc = DC_GetDCPtr( hdc );
1129 TRACE("hdc=%p align=%d\n", hdc, align);
1131 if (!dc) return 0x0;
1132 ret = dc->textAlign;
1133 if (dc->funcs->pSetTextAlign)
1134 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1136 if (ret != GDI_ERROR)
1137 dc->textAlign = align;
1138 DC_ReleaseDCPtr( dc );
1142 /***********************************************************************
1143 * GetDCOrgEx (GDI32.@)
1145 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1149 if (!lpp) return FALSE;
1150 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
1152 lpp->x = lpp->y = 0;
1153 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1154 DC_ReleaseDCPtr( dc );
1159 /***********************************************************************
1160 * SetDCOrg (GDI.117)
1162 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
1165 HDC hdc = HDC_32( hdc16 );
1166 DC *dc = DC_GetDCPtr( hdc );
1168 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1169 DC_ReleaseDCPtr( dc );
1174 /***********************************************************************
1175 * GetGraphicsMode (GDI32.@)
1177 INT WINAPI GetGraphicsMode( HDC hdc )
1180 DC * dc = DC_GetDCPtr( hdc );
1183 ret = dc->GraphicsMode;
1184 DC_ReleaseDCPtr( dc );
1190 /***********************************************************************
1191 * SetGraphicsMode (GDI32.@)
1193 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1196 DC *dc = DC_GetDCPtr( hdc );
1198 /* One would think that setting the graphics mode to GM_COMPATIBLE
1199 * would also reset the world transformation matrix to the unity
1200 * matrix. However, in Windows, this is not the case. This doesn't
1201 * make a lot of sense to me, but that's the way it is.
1204 if ((mode > 0) && (mode <= GM_LAST))
1206 ret = dc->GraphicsMode;
1207 dc->GraphicsMode = mode;
1209 DC_ReleaseDCPtr( dc );
1214 /***********************************************************************
1215 * GetArcDirection (GDI32.@)
1217 INT WINAPI GetArcDirection( HDC hdc )
1220 DC * dc = DC_GetDCPtr( hdc );
1223 ret = dc->ArcDirection;
1224 DC_ReleaseDCPtr( dc );
1230 /***********************************************************************
1231 * SetArcDirection (GDI32.@)
1233 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1236 INT nOldDirection = 0;
1238 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1240 SetLastError(ERROR_INVALID_PARAMETER);
1244 if ((dc = DC_GetDCPtr( hdc )))
1246 if (dc->funcs->pSetArcDirection)
1248 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1250 nOldDirection = dc->ArcDirection;
1251 dc->ArcDirection = nDirection;
1252 DC_ReleaseDCPtr( dc );
1254 return nOldDirection;
1258 /***********************************************************************
1259 * GetWorldTransform (GDI32.@)
1261 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1264 if (!xform) return FALSE;
1265 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1266 *xform = dc->xformWorld2Wnd;
1267 DC_ReleaseDCPtr( dc );
1272 /***********************************************************************
1273 * GetTransform (GDI32.@)
1275 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1277 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1278 FIXME("stub: don't know what to do for code %x\n", unknown );
1283 /***********************************************************************
1284 * SetWorldTransform (GDI32.@)
1286 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1289 DC *dc = DC_GetDCPtr( hdc );
1291 if (!dc) return FALSE;
1292 if (!xform) goto done;
1294 /* Check that graphics mode is GM_ADVANCED */
1295 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1297 if (dc->funcs->pSetWorldTransform)
1299 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1300 if (!ret) goto done;
1303 dc->xformWorld2Wnd = *xform;
1304 DC_UpdateXforms( dc );
1307 DC_ReleaseDCPtr( dc );
1312 /****************************************************************************
1313 * ModifyWorldTransform [GDI32.@]
1314 * Modifies the world transformation for a device context.
1317 * hdc [I] Handle to device context
1318 * xform [I] XFORM structure that will be used to modify the world
1320 * iMode [I] Specifies in what way to modify the world transformation
1323 * Resets the world transformation to the identity matrix.
1324 * The parameter xform is ignored.
1326 * Multiplies xform into the world transformation matrix from
1329 * Multiplies xform into the world transformation matrix from
1334 * Failure: FALSE. Use GetLastError() to determine the cause.
1336 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1340 DC *dc = DC_GetDCPtr( hdc );
1342 /* Check for illegal parameters */
1343 if (!dc) return FALSE;
1344 if (!xform && iMode != MWT_IDENTITY) goto done;
1346 /* Check that graphics mode is GM_ADVANCED */
1347 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1349 if (dc->funcs->pModifyWorldTransform)
1351 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1352 if (!ret) goto done;
1358 dc->xformWorld2Wnd.eM11 = 1.0f;
1359 dc->xformWorld2Wnd.eM12 = 0.0f;
1360 dc->xformWorld2Wnd.eM21 = 0.0f;
1361 dc->xformWorld2Wnd.eM22 = 1.0f;
1362 dc->xformWorld2Wnd.eDx = 0.0f;
1363 dc->xformWorld2Wnd.eDy = 0.0f;
1365 case MWT_LEFTMULTIPLY:
1366 CombineTransform( &dc->xformWorld2Wnd, xform,
1367 &dc->xformWorld2Wnd );
1369 case MWT_RIGHTMULTIPLY:
1370 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1377 DC_UpdateXforms( dc );
1380 DC_ReleaseDCPtr( dc );
1385 /****************************************************************************
1386 * CombineTransform [GDI32.@]
1387 * Combines two transformation matrices.
1390 * xformResult [O] Stores the result of combining the two matrices
1391 * xform1 [I] Specifies the first matrix to apply
1392 * xform2 [I] Specifies the second matrix to apply
1395 * The same matrix can be passed in for more than one of the parameters.
1399 * Failure: FALSE. Use GetLastError() to determine the cause.
1401 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1402 const XFORM *xform2 )
1406 /* Check for illegal parameters */
1407 if (!xformResult || !xform1 || !xform2)
1410 /* Create the result in a temporary XFORM, since xformResult may be
1411 * equal to xform1 or xform2 */
1412 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1413 xform1->eM12 * xform2->eM21;
1414 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1415 xform1->eM12 * xform2->eM22;
1416 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1417 xform1->eM22 * xform2->eM21;
1418 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1419 xform1->eM22 * xform2->eM22;
1420 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1421 xform1->eDy * xform2->eM21 +
1423 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1424 xform1->eDy * xform2->eM22 +
1427 /* Copy the result to xformResult */
1428 *xformResult = xformTemp;
1434 /***********************************************************************
1435 * SetDCHook (GDI32.@)
1437 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1439 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1441 DC *dc = DC_GetDCPtr( hdc );
1443 if (!dc) return FALSE;
1445 if (!(dc->flags & DC_SAVED))
1447 dc->dwHookData = dwHookData;
1448 dc->hookThunk = hookProc;
1450 DC_ReleaseDCPtr( dc );
1455 /* relay function to call the 16-bit DC hook proc */
1456 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1460 FARPROC16 proc = NULL;
1461 DC *dc = DC_GetDCPtr( hdc );
1463 if (!dc) return FALSE;
1464 proc = dc->hookProc;
1465 DC_ReleaseDCPtr( dc );
1466 if (!proc) return FALSE;
1467 args[5] = HDC_16(hdc);
1469 args[3] = HIWORD(data);
1470 args[2] = LOWORD(data);
1471 args[1] = HIWORD(lParam);
1472 args[0] = LOWORD(lParam);
1473 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1477 /***********************************************************************
1478 * SetDCHook (GDI.190)
1480 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1482 HDC hdc = HDC_32( hdc16 );
1483 DC *dc = DC_GetDCPtr( hdc );
1484 if (!dc) return FALSE;
1486 dc->hookProc = hookProc;
1487 DC_ReleaseDCPtr( dc );
1488 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1492 /***********************************************************************
1493 * GetDCHook (GDI.191)
1495 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1497 HDC hdc = HDC_32( hdc16 );
1498 DC *dc = DC_GetDCPtr( hdc );
1502 *phookProc = dc->hookProc;
1503 ret = dc->dwHookData;
1504 DC_ReleaseDCPtr( dc );
1509 /***********************************************************************
1510 * SetHookFlags (GDI.192)
1512 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1514 HDC hdc = HDC_32( hdc16 );
1515 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1520 /* "Undocumented Windows" info is slightly confusing. */
1522 TRACE("hDC %p, flags %04x\n",hdc,flags);
1524 if (flags & DCHF_INVALIDATEVISRGN)
1525 ret = InterlockedExchange( &dc->dirty, 1 );
1526 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1527 ret = InterlockedExchange( &dc->dirty, 0 );
1529 GDI_ReleaseObj( dc );
1533 /***********************************************************************
1534 * SetICMMode (GDI32.@)
1536 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1538 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1539 if (iEnableICM == ICM_OFF) return ICM_OFF;
1540 if (iEnableICM == ICM_ON) return 0;
1541 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1545 /***********************************************************************
1546 * GetDeviceGammaRamp (GDI32.@)
1548 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1551 DC *dc = DC_GetDCPtr( hDC );
1555 if (dc->funcs->pGetDeviceGammaRamp)
1556 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1557 DC_ReleaseDCPtr( dc );
1562 /***********************************************************************
1563 * SetDeviceGammaRamp (GDI32.@)
1565 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1568 DC *dc = DC_GetDCPtr( hDC );
1572 if (dc->funcs->pSetDeviceGammaRamp)
1573 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1574 DC_ReleaseDCPtr( dc );
1579 /***********************************************************************
1580 * GetColorSpace (GDI32.@)
1582 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1584 /*FIXME Need to to whatever GetColorSpace actually does */
1588 /***********************************************************************
1589 * CreateColorSpaceA (GDI32.@)
1591 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1597 /***********************************************************************
1598 * CreateColorSpaceW (GDI32.@)
1600 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1606 /***********************************************************************
1607 * DeleteColorSpace (GDI32.@)
1609 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1616 /***********************************************************************
1617 * SetColorSpace (GDI32.@)
1619 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1626 /***********************************************************************
1627 * GetBoundsRect (GDI32.@)
1629 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1632 DC *dc = DC_GetDCPtr( hdc );
1634 if ( !dc ) return 0;
1636 if (rect) *rect = dc->BoundsRect;
1638 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1640 if (flags & DCB_RESET)
1642 dc->BoundsRect.left = 0;
1643 dc->BoundsRect.top = 0;
1644 dc->BoundsRect.right = 0;
1645 dc->BoundsRect.bottom = 0;
1646 dc->flags &= ~DC_BOUNDS_SET;
1648 DC_ReleaseDCPtr( dc );
1653 /***********************************************************************
1654 * SetBoundsRect (GDI32.@)
1656 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1661 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1662 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1664 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1665 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1667 if (flags & DCB_RESET)
1669 dc->BoundsRect.left = 0;
1670 dc->BoundsRect.top = 0;
1671 dc->BoundsRect.right = 0;
1672 dc->BoundsRect.bottom = 0;
1673 dc->flags &= ~DC_BOUNDS_SET;
1676 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1678 if (dc->flags & DC_BOUNDS_SET)
1680 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1681 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1682 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1683 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1687 dc->BoundsRect = *rect;
1688 dc->flags |= DC_BOUNDS_SET;
1692 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1693 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1695 DC_ReleaseDCPtr( dc );
1700 /***********************************************************************
1701 * GetRelAbs (GDI32.@)
1703 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1706 DC *dc = DC_GetDCPtr( hdc );
1709 ret = dc->relAbsMode;
1710 DC_ReleaseDCPtr( dc );
1718 /***********************************************************************
1719 * GetBkMode (GDI32.@)
1721 INT WINAPI GetBkMode( HDC hdc )
1724 DC * dc = DC_GetDCPtr( hdc );
1727 ret = dc->backgroundMode;
1728 DC_ReleaseDCPtr( dc );
1734 /***********************************************************************
1735 * SetBkMode (GDI32.@)
1737 INT WINAPI SetBkMode( HDC hdc, INT mode )
1741 if ((mode <= 0) || (mode > BKMODE_LAST))
1743 SetLastError(ERROR_INVALID_PARAMETER);
1746 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1748 ret = dc->backgroundMode;
1749 if (dc->funcs->pSetBkMode)
1750 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1753 dc->backgroundMode = mode;
1754 DC_ReleaseDCPtr( dc );
1759 /***********************************************************************
1762 INT WINAPI GetROP2( HDC hdc )
1765 DC * dc = DC_GetDCPtr( hdc );
1769 DC_ReleaseDCPtr( dc );
1775 /***********************************************************************
1778 INT WINAPI SetROP2( HDC hdc, INT mode )
1782 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1784 SetLastError(ERROR_INVALID_PARAMETER);
1787 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1789 if (dc->funcs->pSetROP2)
1790 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1794 DC_ReleaseDCPtr( dc );
1799 /***********************************************************************
1800 * SetRelAbs (GDI32.@)
1802 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1806 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1808 SetLastError(ERROR_INVALID_PARAMETER);
1811 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1812 if (dc->funcs->pSetRelAbs)
1813 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1816 ret = dc->relAbsMode;
1817 dc->relAbsMode = mode;
1819 DC_ReleaseDCPtr( dc );
1824 /***********************************************************************
1825 * GetPolyFillMode (GDI32.@)
1827 INT WINAPI GetPolyFillMode( HDC hdc )
1830 DC * dc = DC_GetDCPtr( hdc );
1833 ret = dc->polyFillMode;
1834 DC_ReleaseDCPtr( dc );
1840 /***********************************************************************
1841 * SetPolyFillMode (GDI32.@)
1843 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1847 if ((mode <= 0) || (mode > POLYFILL_LAST))
1849 SetLastError(ERROR_INVALID_PARAMETER);
1852 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1853 ret = dc->polyFillMode;
1854 if (dc->funcs->pSetPolyFillMode)
1855 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1858 dc->polyFillMode = mode;
1859 DC_ReleaseDCPtr( dc );
1864 /***********************************************************************
1865 * GetStretchBltMode (GDI32.@)
1867 INT WINAPI GetStretchBltMode( HDC hdc )
1870 DC * dc = DC_GetDCPtr( hdc );
1873 ret = dc->stretchBltMode;
1874 DC_ReleaseDCPtr( dc );
1880 /***********************************************************************
1881 * SetStretchBltMode (GDI32.@)
1883 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1887 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1889 SetLastError(ERROR_INVALID_PARAMETER);
1892 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1893 ret = dc->stretchBltMode;
1894 if (dc->funcs->pSetStretchBltMode)
1895 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1898 dc->stretchBltMode = mode;
1899 DC_ReleaseDCPtr( dc );
1904 /***********************************************************************
1905 * GetMapMode (GDI32.@)
1907 INT WINAPI GetMapMode( HDC hdc )
1910 DC * dc = DC_GetDCPtr( hdc );
1914 DC_ReleaseDCPtr( dc );
1920 /***********************************************************************
1921 * GetBrushOrgEx (GDI32.@)
1923 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1925 DC * dc = DC_GetDCPtr( hdc );
1926 if (!dc) return FALSE;
1927 pt->x = dc->brushOrgX;
1928 pt->y = dc->brushOrgY;
1929 DC_ReleaseDCPtr( dc );
1934 /***********************************************************************
1935 * GetCurrentPositionEx (GDI32.@)
1937 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1939 DC * dc = DC_GetDCPtr( hdc );
1940 if (!dc) return FALSE;
1941 pt->x = dc->CursPosX;
1942 pt->y = dc->CursPosY;
1943 DC_ReleaseDCPtr( dc );
1948 /***********************************************************************
1949 * GetViewportExtEx (GDI32.@)
1951 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1953 DC * dc = DC_GetDCPtr( hdc );
1954 if (!dc) return FALSE;
1955 size->cx = dc->vportExtX;
1956 size->cy = dc->vportExtY;
1957 DC_ReleaseDCPtr( dc );
1962 /***********************************************************************
1963 * GetViewportOrgEx (GDI32.@)
1965 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1967 DC * dc = DC_GetDCPtr( hdc );
1968 if (!dc) return FALSE;
1969 pt->x = dc->vportOrgX;
1970 pt->y = dc->vportOrgY;
1971 DC_ReleaseDCPtr( dc );
1976 /***********************************************************************
1977 * GetWindowExtEx (GDI32.@)
1979 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1981 DC * dc = DC_GetDCPtr( hdc );
1982 if (!dc) return FALSE;
1983 size->cx = dc->wndExtX;
1984 size->cy = dc->wndExtY;
1985 DC_ReleaseDCPtr( dc );
1990 /***********************************************************************
1991 * GetWindowOrgEx (GDI32.@)
1993 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1995 DC * dc = DC_GetDCPtr( hdc );
1996 if (!dc) return FALSE;
1997 pt->x = dc->wndOrgX;
1998 pt->y = dc->wndOrgY;
1999 DC_ReleaseDCPtr( dc );
2004 /***********************************************************************
2005 * InquireVisRgn (GDI.131)
2007 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
2010 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
2013 ret = HRGN_16(dc->hVisRgn);
2014 DC_ReleaseDCPtr( dc );
2020 /***********************************************************************
2021 * GetClipRgn (GDI.173)
2023 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
2026 DC * dc = DC_GetDCPtr( HDC_32(hdc) );
2029 ret = HRGN_16(dc->hClipRgn);
2030 DC_ReleaseDCPtr( dc );
2036 /***********************************************************************
2037 * GetLayout (GDI32.@)
2039 * Gets left->right or right->left text layout flags of a dc.
2042 DWORD WINAPI GetLayout(HDC hdc)
2044 DWORD layout = GDI_ERROR;
2046 DC * dc = DC_GetDCPtr( hdc );
2049 layout = dc->layout;
2050 DC_ReleaseDCPtr( dc );
2053 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
2058 /***********************************************************************
2059 * SetLayout (GDI32.@)
2061 * Sets left->right or right->left text layout flags of a dc.
2064 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
2066 DWORD oldlayout = GDI_ERROR;
2068 DC * dc = DC_GetDCPtr( hdc );
2071 oldlayout = dc->layout;
2072 dc->layout = layout;
2073 DC_ReleaseDCPtr( dc );
2076 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
2081 /***********************************************************************
2082 * GetDCBrushColor (GDI32.@)
2084 * Retrieves the current brush color for the specified device
2088 COLORREF WINAPI GetDCBrushColor(HDC hdc)
2091 COLORREF dcBrushColor = CLR_INVALID;
2093 TRACE("hdc(%p)\n", hdc);
2095 dc = DC_GetDCPtr( hdc );
2098 dcBrushColor = dc->dcBrushColor;
2099 DC_ReleaseDCPtr( dc );
2102 return dcBrushColor;
2105 /***********************************************************************
2106 * SetDCBrushColor (GDI32.@)
2108 * Sets the current device context (DC) brush color to the specified
2109 * color value. If the device cannot represent the specified color
2110 * value, the color is set to the nearest physical color.
2113 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2116 COLORREF oldClr = CLR_INVALID;
2118 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2120 dc = DC_GetDCPtr( hdc );
2123 if (dc->funcs->pSetDCBrushColor)
2124 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2125 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2127 /* If DC_BRUSH is selected, update driver pen color */
2128 HBRUSH hBrush = CreateSolidBrush( crColor );
2129 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2130 DeleteObject( hBrush );
2133 if (crColor != CLR_INVALID)
2135 oldClr = dc->dcBrushColor;
2136 dc->dcBrushColor = crColor;
2139 DC_ReleaseDCPtr( dc );
2145 /***********************************************************************
2146 * GetDCPenColor (GDI32.@)
2148 * Retrieves the current pen color for the specified device
2152 COLORREF WINAPI GetDCPenColor(HDC hdc)
2155 COLORREF dcPenColor = CLR_INVALID;
2157 TRACE("hdc(%p)\n", hdc);
2159 dc = DC_GetDCPtr( hdc );
2162 dcPenColor = dc->dcPenColor;
2163 DC_ReleaseDCPtr( dc );
2169 /***********************************************************************
2170 * SetDCPenColor (GDI32.@)
2172 * Sets the current device context (DC) pen color to the specified
2173 * color value. If the device cannot represent the specified color
2174 * value, the color is set to the nearest physical color.
2177 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2180 COLORREF oldClr = CLR_INVALID;
2182 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2184 dc = DC_GetDCPtr( hdc );
2187 if (dc->funcs->pSetDCPenColor)
2188 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2189 else if (dc->hPen == GetStockObject( DC_PEN ))
2191 /* If DC_PEN is selected, update the driver pen color */
2192 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2193 HPEN hPen = CreatePenIndirect( &logpen );
2194 dc->funcs->pSelectPen( dc->physDev, hPen );
2195 DeleteObject( hPen );
2198 if (crColor != CLR_INVALID)
2200 oldClr = dc->dcPenColor;
2201 dc->dcPenColor = crColor;
2204 DC_ReleaseDCPtr( dc );
2210 /***********************************************************************
2211 * CancelDC (GDI32.@)
2213 BOOL WINAPI CancelDC(HDC hdc)
2219 /***********************************************************************
2220 * SetVirtualResolution (GDI32.@)
2222 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2224 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2226 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2230 /*******************************************************************
2231 * GetMiterLimit [GDI32.@]
2235 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2240 TRACE("(%p,%p)\n", hdc, peLimit);
2242 dc = DC_GetDCPtr( hdc );
2246 *peLimit = dc->miterLimit;
2248 DC_ReleaseDCPtr( dc );
2254 /*******************************************************************
2255 * SetMiterLimit [GDI32.@]
2259 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2264 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2266 dc = DC_GetDCPtr( hdc );
2270 *peOldLimit = dc->miterLimit;
2271 dc->miterLimit = eNewLimit;
2272 DC_ReleaseDCPtr( dc );
2278 /*******************************************************************
2279 * GdiIsMetaPrintDC [GDI32.@]
2281 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2287 /*******************************************************************
2288 * GdiIsMetaFileDC [GDI32.@]
2290 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2294 switch( GetObjectType( hdc ) )
2303 /*******************************************************************
2304 * GdiIsPlayMetafileDC [GDI32.@]
2306 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)