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 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
169 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
170 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
171 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
172 PATH_DestroyGdiPath( &dc->path );
173 return HeapFree( GetProcessHeap(), 0, dc );
177 /***********************************************************************
180 * Retrieve a DC pointer but release the GDI lock.
182 DC *get_dc_ptr( HDC hdc )
184 DC *dc = get_dc_obj( hdc );
185 if (!dc) return NULL;
187 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
189 dc->thread = GetCurrentThreadId();
191 else if (dc->thread != GetCurrentThreadId())
193 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
194 GDI_ReleaseObj( hdc );
197 else InterlockedIncrement( &dc->refcount );
199 GDI_ReleaseObj( hdc );
204 /***********************************************************************
207 void release_dc_ptr( DC *dc )
212 ref = InterlockedDecrement( &dc->refcount );
214 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
218 /***********************************************************************
221 * Make sure the DC vis region is up to date.
222 * This function may call up to USER so the GDI lock should _not_
223 * be held when calling it.
225 void update_dc( DC *dc )
227 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookThunk)
228 dc->hookThunk( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
232 /***********************************************************************
235 static BOOL DC_DeleteObject( HGDIOBJ handle )
237 return DeleteDC( handle );
241 /***********************************************************************
244 * Setup device-specific DC values for a newly created DC.
246 void DC_InitDC( DC* dc )
248 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
249 SetTextColor( dc->hSelf, dc->textColor );
250 SetBkColor( dc->hSelf, dc->backgroundColor );
251 SelectObject( dc->hSelf, dc->hPen );
252 SelectObject( dc->hSelf, dc->hBrush );
253 SelectObject( dc->hSelf, dc->hFont );
254 CLIPPING_UpdateGCRegion( dc );
258 /***********************************************************************
261 * Computes the inverse of the transformation xformSrc and stores it to
262 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
265 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
269 determinant = xformSrc->eM11*xformSrc->eM22 -
270 xformSrc->eM12*xformSrc->eM21;
271 if (determinant > -1e-12 && determinant < 1e-12)
274 xformDest->eM11 = xformSrc->eM22 / determinant;
275 xformDest->eM12 = -xformSrc->eM12 / determinant;
276 xformDest->eM21 = -xformSrc->eM21 / determinant;
277 xformDest->eM22 = xformSrc->eM11 / determinant;
278 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
279 xformSrc->eDy * xformDest->eM21;
280 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
281 xformSrc->eDy * xformDest->eM22;
287 /***********************************************************************
290 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
291 * fields of the specified DC by creating a transformation that
292 * represents the current mapping mode and combining it with the DC's
293 * world transform. This function should be called whenever the
294 * parameters associated with the mapping mode (window and viewport
295 * extents and origins) or the world transform change.
297 void DC_UpdateXforms( DC *dc )
299 XFORM xformWnd2Vport, oldworld2vport;
300 double scaleX, scaleY;
302 /* Construct a transformation to do the window-to-viewport conversion */
303 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
304 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
305 xformWnd2Vport.eM11 = scaleX;
306 xformWnd2Vport.eM12 = 0.0;
307 xformWnd2Vport.eM21 = 0.0;
308 xformWnd2Vport.eM22 = scaleY;
309 xformWnd2Vport.eDx = (double)dc->vportOrgX -
310 scaleX * (double)dc->wndOrgX;
311 xformWnd2Vport.eDy = (double)dc->vportOrgY -
312 scaleY * (double)dc->wndOrgY;
314 oldworld2vport = dc->xformWorld2Vport;
315 /* Combine with the world transformation */
316 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
319 /* Create inverse of world-to-viewport transformation */
320 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
321 &dc->xformVport2World );
323 /* Reselect the font and pen back into the dc so that the size
325 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
326 !GdiIsMetaFileDC(dc->hSelf))
328 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
329 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
334 /***********************************************************************
337 INT save_dc_state( HDC hdc )
342 if (!(dc = get_dc_ptr( hdc ))) return 0;
343 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc ))))
345 release_dc_ptr( dc );
349 newdc->flags = dc->flags | DC_SAVED;
350 newdc->layout = dc->layout;
351 newdc->hPen = dc->hPen;
352 newdc->hBrush = dc->hBrush;
353 newdc->hFont = dc->hFont;
354 newdc->hBitmap = dc->hBitmap;
355 newdc->hDevice = dc->hDevice;
356 newdc->hPalette = dc->hPalette;
357 newdc->ROPmode = dc->ROPmode;
358 newdc->polyFillMode = dc->polyFillMode;
359 newdc->stretchBltMode = dc->stretchBltMode;
360 newdc->relAbsMode = dc->relAbsMode;
361 newdc->backgroundMode = dc->backgroundMode;
362 newdc->backgroundColor = dc->backgroundColor;
363 newdc->textColor = dc->textColor;
364 newdc->dcBrushColor = dc->dcBrushColor;
365 newdc->dcPenColor = dc->dcPenColor;
366 newdc->brushOrgX = dc->brushOrgX;
367 newdc->brushOrgY = dc->brushOrgY;
368 newdc->textAlign = dc->textAlign;
369 newdc->charExtra = dc->charExtra;
370 newdc->breakExtra = dc->breakExtra;
371 newdc->breakRem = dc->breakRem;
372 newdc->MapMode = dc->MapMode;
373 newdc->GraphicsMode = dc->GraphicsMode;
374 newdc->CursPosX = dc->CursPosX;
375 newdc->CursPosY = dc->CursPosY;
376 newdc->ArcDirection = dc->ArcDirection;
377 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
378 newdc->xformWorld2Vport = dc->xformWorld2Vport;
379 newdc->xformVport2World = dc->xformVport2World;
380 newdc->vport2WorldValid = dc->vport2WorldValid;
381 newdc->wndOrgX = dc->wndOrgX;
382 newdc->wndOrgY = dc->wndOrgY;
383 newdc->wndExtX = dc->wndExtX;
384 newdc->wndExtY = dc->wndExtY;
385 newdc->vportOrgX = dc->vportOrgX;
386 newdc->vportOrgY = dc->vportOrgY;
387 newdc->vportExtX = dc->vportExtX;
388 newdc->vportExtY = dc->vportExtY;
389 newdc->BoundsRect = dc->BoundsRect;
390 newdc->gdiFont = dc->gdiFont;
392 newdc->thread = GetCurrentThreadId();
394 newdc->saveLevel = 0;
397 PATH_InitGdiPath( &newdc->path );
399 newdc->pAbortProc = NULL;
400 newdc->hookThunk = NULL;
402 newdc->saved_visrgn = NULL;
404 if (!(newdc->hSelf = alloc_gdi_handle( &newdc->header, dc->header.type, &dc_funcs )))
406 HeapFree( GetProcessHeap(), 0, newdc );
407 release_dc_ptr( dc );
411 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
416 newdc->hMetaClipRgn = 0;
419 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
420 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
424 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
425 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
427 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
429 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
431 release_dc_ptr( dc );
432 free_dc_ptr( newdc );
436 newdc->saved_dc = dc->saved_dc;
437 dc->saved_dc = newdc->hSelf;
438 ret = ++dc->saveLevel;
439 release_dc_ptr( newdc );
440 release_dc_ptr( dc );
445 /***********************************************************************
448 BOOL restore_dc_state( HDC hdc, INT level )
454 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
456 /* find the state level to restore */
458 if (abs(level) > dc->saveLevel || level == 0)
460 release_dc_ptr( dc );
463 if (level < 0) level = dc->saveLevel + level + 1;
464 first_dcs = dc->saved_dc;
465 for (hdcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
467 if (!(dcs = get_dc_ptr( hdcs )))
469 release_dc_ptr( dc );
472 hdcs = dcs->saved_dc;
473 release_dc_ptr( dcs );
476 /* restore the state */
478 if (!(dcs = get_dc_ptr( hdcs )))
480 release_dc_ptr( dc );
483 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
485 release_dc_ptr( dcs );
486 release_dc_ptr( dc );
490 dc->flags = dcs->flags & ~DC_SAVED;
491 dc->layout = dcs->layout;
492 dc->hDevice = dcs->hDevice;
493 dc->ROPmode = dcs->ROPmode;
494 dc->polyFillMode = dcs->polyFillMode;
495 dc->stretchBltMode = dcs->stretchBltMode;
496 dc->relAbsMode = dcs->relAbsMode;
497 dc->backgroundMode = dcs->backgroundMode;
498 dc->backgroundColor = dcs->backgroundColor;
499 dc->textColor = dcs->textColor;
500 dc->dcBrushColor = dcs->dcBrushColor;
501 dc->dcPenColor = dcs->dcPenColor;
502 dc->brushOrgX = dcs->brushOrgX;
503 dc->brushOrgY = dcs->brushOrgY;
504 dc->textAlign = dcs->textAlign;
505 dc->charExtra = dcs->charExtra;
506 dc->breakExtra = dcs->breakExtra;
507 dc->breakRem = dcs->breakRem;
508 dc->MapMode = dcs->MapMode;
509 dc->GraphicsMode = dcs->GraphicsMode;
510 dc->CursPosX = dcs->CursPosX;
511 dc->CursPosY = dcs->CursPosY;
512 dc->ArcDirection = dcs->ArcDirection;
513 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
514 dc->xformWorld2Vport = dcs->xformWorld2Vport;
515 dc->xformVport2World = dcs->xformVport2World;
516 dc->vport2WorldValid = dcs->vport2WorldValid;
517 dc->BoundsRect = dcs->BoundsRect;
519 dc->wndOrgX = dcs->wndOrgX;
520 dc->wndOrgY = dcs->wndOrgY;
521 dc->wndExtX = dcs->wndExtX;
522 dc->wndExtY = dcs->wndExtY;
523 dc->vportOrgX = dcs->vportOrgX;
524 dc->vportOrgY = dcs->vportOrgY;
525 dc->vportExtX = dcs->vportExtX;
526 dc->vportExtY = dcs->vportExtY;
530 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
531 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
535 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
540 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
541 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
545 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
548 CLIPPING_UpdateGCRegion( dc );
550 SelectObject( hdc, dcs->hBitmap );
551 SelectObject( hdc, dcs->hBrush );
552 SelectObject( hdc, dcs->hFont );
553 SelectObject( hdc, dcs->hPen );
554 SetBkColor( hdc, dcs->backgroundColor);
555 SetTextColor( hdc, dcs->textColor);
556 GDISelectPalette( hdc, dcs->hPalette, FALSE );
558 dc->saved_dc = dcs->saved_dc;
560 dc->saveLevel = save_level - 1;
562 release_dc_ptr( dcs );
564 /* now destroy all the saved DCs */
568 if (!(dcs = get_dc_ptr( first_dcs ))) break;
569 hdcs = dcs->saved_dc;
573 release_dc_ptr( dc );
578 /***********************************************************************
581 INT WINAPI SaveDC( HDC hdc )
586 if (!(dc = get_dc_ptr( hdc ))) return 0;
588 if(dc->funcs->pSaveDC)
589 ret = dc->funcs->pSaveDC( dc->physDev );
591 ret = save_dc_state( hdc );
593 release_dc_ptr( dc );
598 /***********************************************************************
599 * RestoreDC (GDI32.@)
601 BOOL WINAPI RestoreDC( HDC hdc, INT level )
606 TRACE("%p %d\n", hdc, level );
607 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
610 if(dc->funcs->pRestoreDC)
611 success = dc->funcs->pRestoreDC( dc->physDev, level );
613 success = restore_dc_state( hdc, level );
615 release_dc_ptr( dc );
620 /***********************************************************************
621 * CreateDCW (GDI32.@)
623 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
624 const DEVMODEW *initData )
628 const DC_FUNCTIONS *funcs;
633 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
637 ERR( "no device found for %s\n", debugstr_w(device) );
640 strcpyW(buf, driver);
643 if (!(funcs = DRIVER_load_driver( buf )))
645 ERR( "no driver found for %s\n", debugstr_w(buf) );
648 if (!(dc = alloc_dc_ptr( funcs, OBJ_DC ))) goto error;
651 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
652 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
654 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
655 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
657 if (dc->funcs->pCreateDC &&
658 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
660 WARN("creation aborted by device\n" );
664 SetRectRgn( dc->hVisRgn, 0, 0,
665 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
668 release_dc_ptr( dc );
672 if (dc) free_dc_ptr( dc );
673 DRIVER_release_driver( funcs );
678 /***********************************************************************
679 * CreateDCA (GDI32.@)
681 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
682 const DEVMODEA *initData )
684 UNICODE_STRING driverW, deviceW, outputW;
688 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
689 else driverW.Buffer = NULL;
691 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
692 else deviceW.Buffer = NULL;
694 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
695 else outputW.Buffer = NULL;
700 /* don't convert initData for DISPLAY driver, it's not used */
701 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
702 initDataW = GdiConvertToDevmodeW(initData);
705 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
707 RtlFreeUnicodeString(&driverW);
708 RtlFreeUnicodeString(&deviceW);
709 RtlFreeUnicodeString(&outputW);
710 HeapFree(GetProcessHeap(), 0, initDataW);
715 /***********************************************************************
716 * CreateICA (GDI32.@)
718 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
719 const DEVMODEA* initData )
721 /* Nothing special yet for ICs */
722 return CreateDCA( driver, device, output, initData );
726 /***********************************************************************
727 * CreateICW (GDI32.@)
729 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
730 const DEVMODEW* initData )
732 /* Nothing special yet for ICs */
733 return CreateDCW( driver, device, output, initData );
737 /***********************************************************************
738 * CreateCompatibleDC (GDI32.@)
740 HDC WINAPI CreateCompatibleDC( HDC hdc )
744 const DC_FUNCTIONS *funcs = NULL;
745 PHYSDEV physDev = NULL;
749 if ((origDC = get_dc_ptr( hdc )))
751 if (GetObjectType( hdc ) == OBJ_DC)
753 funcs = origDC->funcs;
754 physDev = origDC->physDev;
756 release_dc_ptr( origDC );
757 if (funcs) funcs = DRIVER_get_driver( funcs );
759 else if (hdc) return 0;
761 if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
763 if (!(dc = alloc_dc_ptr( funcs, OBJ_MEMDC ))) goto error;
765 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
767 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
768 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
770 /* Copy the driver-specific physical device info into
771 * the new DC. The driver may use this read-only info
772 * while creating the compatible DC below. */
773 dc->physDev = physDev;
776 if (dc->funcs->pCreateDC &&
777 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
779 WARN("creation aborted by device\n");
784 release_dc_ptr( dc );
788 if (dc) free_dc_ptr( dc );
789 DRIVER_release_driver( funcs );
794 /***********************************************************************
797 BOOL WINAPI DeleteDC( HDC hdc )
799 const DC_FUNCTIONS *funcs = NULL;
806 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
807 if (dc->refcount != 1)
809 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
810 release_dc_ptr( dc );
814 /* Call hook procedure to check whether is it OK to delete this DC */
815 if (dc->hookThunk && !dc->hookThunk( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
817 release_dc_ptr( dc );
821 while (dc->saveLevel)
824 HDC hdcs = dc->saved_dc;
825 if (!(dcs = get_dc_ptr( hdcs ))) break;
826 dc->saved_dc = dcs->saved_dc;
831 if (!(dc->flags & DC_SAVED))
833 SelectObject( hdc, GetStockObject(BLACK_PEN) );
834 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
835 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
836 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
838 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
842 while (dc->saved_visrgn)
844 struct saved_visrgn *next = dc->saved_visrgn->next;
845 DeleteObject( dc->saved_visrgn->hrgn );
846 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
847 dc->saved_visrgn = next;
851 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
856 /***********************************************************************
859 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
864 if ((dc = get_dc_ptr( hdc )))
866 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
867 release_dc_ptr( dc );
873 /***********************************************************************
876 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
881 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
882 else devmodeW = NULL;
884 ret = ResetDCW(hdc, devmodeW);
886 HeapFree(GetProcessHeap(), 0, devmodeW);
891 /***********************************************************************
892 * GetDeviceCaps (GDI32.@)
894 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
899 if ((dc = get_dc_ptr( hdc )))
901 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
902 else switch(cap) /* return meaningful values for some entries */
904 case HORZRES: ret = 640; break;
905 case VERTRES: ret = 480; break;
906 case BITSPIXEL: ret = 1; break;
907 case PLANES: ret = 1; break;
908 case NUMCOLORS: ret = 2; break;
909 case ASPECTX: ret = 36; break;
910 case ASPECTY: ret = 36; break;
911 case ASPECTXY: ret = 51; break;
912 case LOGPIXELSX: ret = 72; break;
913 case LOGPIXELSY: ret = 72; break;
914 case SIZEPALETTE: ret = 2; break;
916 release_dc_ptr( dc );
922 /***********************************************************************
923 * GetBkColor (GDI32.@)
925 COLORREF WINAPI GetBkColor( HDC hdc )
928 DC * dc = get_dc_ptr( hdc );
931 ret = dc->backgroundColor;
932 release_dc_ptr( dc );
938 /***********************************************************************
939 * SetBkColor (GDI32.@)
941 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
944 DC * dc = get_dc_ptr( hdc );
946 TRACE("hdc=%p color=0x%08x\n", hdc, color);
948 if (!dc) return CLR_INVALID;
949 oldColor = dc->backgroundColor;
950 if (dc->funcs->pSetBkColor)
952 color = dc->funcs->pSetBkColor(dc->physDev, color);
953 if (color == CLR_INVALID) /* don't change it */
956 oldColor = CLR_INVALID;
959 dc->backgroundColor = color;
960 release_dc_ptr( dc );
965 /***********************************************************************
966 * GetTextColor (GDI32.@)
968 COLORREF WINAPI GetTextColor( HDC hdc )
971 DC * dc = get_dc_ptr( hdc );
975 release_dc_ptr( dc );
981 /***********************************************************************
982 * SetTextColor (GDI32.@)
984 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
987 DC * dc = get_dc_ptr( hdc );
989 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
991 if (!dc) return CLR_INVALID;
992 oldColor = dc->textColor;
993 if (dc->funcs->pSetTextColor)
995 color = dc->funcs->pSetTextColor(dc->physDev, color);
996 if (color == CLR_INVALID) /* don't change it */
999 oldColor = CLR_INVALID;
1002 dc->textColor = color;
1003 release_dc_ptr( dc );
1008 /***********************************************************************
1009 * GetTextAlign (GDI32.@)
1011 UINT WINAPI GetTextAlign( HDC hdc )
1014 DC * dc = get_dc_ptr( hdc );
1017 ret = dc->textAlign;
1018 release_dc_ptr( dc );
1024 /***********************************************************************
1025 * SetTextAlign (GDI32.@)
1027 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1030 DC *dc = get_dc_ptr( hdc );
1032 TRACE("hdc=%p align=%d\n", hdc, align);
1034 if (!dc) return 0x0;
1035 ret = dc->textAlign;
1036 if (dc->funcs->pSetTextAlign)
1037 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1039 if (ret != GDI_ERROR)
1040 dc->textAlign = align;
1041 release_dc_ptr( dc );
1045 /***********************************************************************
1046 * GetDCOrgEx (GDI32.@)
1048 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1052 if (!lpp) return FALSE;
1053 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1055 lpp->x = lpp->y = 0;
1056 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1057 release_dc_ptr( dc );
1062 /***********************************************************************
1063 * GetGraphicsMode (GDI32.@)
1065 INT WINAPI GetGraphicsMode( HDC hdc )
1068 DC * dc = get_dc_ptr( hdc );
1071 ret = dc->GraphicsMode;
1072 release_dc_ptr( dc );
1078 /***********************************************************************
1079 * SetGraphicsMode (GDI32.@)
1081 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1084 DC *dc = get_dc_ptr( hdc );
1086 /* One would think that setting the graphics mode to GM_COMPATIBLE
1087 * would also reset the world transformation matrix to the unity
1088 * matrix. However, in Windows, this is not the case. This doesn't
1089 * make a lot of sense to me, but that's the way it is.
1092 if ((mode > 0) && (mode <= GM_LAST))
1094 ret = dc->GraphicsMode;
1095 dc->GraphicsMode = mode;
1097 release_dc_ptr( dc );
1102 /***********************************************************************
1103 * GetArcDirection (GDI32.@)
1105 INT WINAPI GetArcDirection( HDC hdc )
1108 DC * dc = get_dc_ptr( hdc );
1111 ret = dc->ArcDirection;
1112 release_dc_ptr( dc );
1118 /***********************************************************************
1119 * SetArcDirection (GDI32.@)
1121 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1124 INT nOldDirection = 0;
1126 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1128 SetLastError(ERROR_INVALID_PARAMETER);
1132 if ((dc = get_dc_ptr( hdc )))
1134 if (dc->funcs->pSetArcDirection)
1136 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1138 nOldDirection = dc->ArcDirection;
1139 dc->ArcDirection = nDirection;
1140 release_dc_ptr( dc );
1142 return nOldDirection;
1146 /***********************************************************************
1147 * GetWorldTransform (GDI32.@)
1149 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1152 if (!xform) return FALSE;
1153 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1154 *xform = dc->xformWorld2Wnd;
1155 release_dc_ptr( dc );
1160 /***********************************************************************
1161 * GetTransform (GDI32.@)
1163 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1165 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1166 FIXME("stub: don't know what to do for code %x\n", unknown );
1171 /***********************************************************************
1172 * SetWorldTransform (GDI32.@)
1174 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1179 if (!xform) return FALSE;
1181 dc = get_dc_ptr( hdc );
1182 if (!dc) return FALSE;
1184 /* Check that graphics mode is GM_ADVANCED */
1185 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1187 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1188 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1190 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1191 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) goto done;
1193 if (dc->funcs->pSetWorldTransform)
1195 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1196 if (!ret) goto done;
1199 dc->xformWorld2Wnd = *xform;
1200 DC_UpdateXforms( dc );
1203 release_dc_ptr( dc );
1208 /****************************************************************************
1209 * ModifyWorldTransform [GDI32.@]
1210 * Modifies the world transformation for a device context.
1213 * hdc [I] Handle to device context
1214 * xform [I] XFORM structure that will be used to modify the world
1216 * iMode [I] Specifies in what way to modify the world transformation
1219 * Resets the world transformation to the identity matrix.
1220 * The parameter xform is ignored.
1222 * Multiplies xform into the world transformation matrix from
1225 * Multiplies xform into the world transformation matrix from
1230 * Failure: FALSE. Use GetLastError() to determine the cause.
1232 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1236 DC *dc = get_dc_ptr( hdc );
1238 /* Check for illegal parameters */
1239 if (!dc) return FALSE;
1240 if (!xform && iMode != MWT_IDENTITY) goto done;
1242 /* Check that graphics mode is GM_ADVANCED */
1243 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1245 if (dc->funcs->pModifyWorldTransform)
1247 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1248 if (!ret) goto done;
1254 dc->xformWorld2Wnd.eM11 = 1.0f;
1255 dc->xformWorld2Wnd.eM12 = 0.0f;
1256 dc->xformWorld2Wnd.eM21 = 0.0f;
1257 dc->xformWorld2Wnd.eM22 = 1.0f;
1258 dc->xformWorld2Wnd.eDx = 0.0f;
1259 dc->xformWorld2Wnd.eDy = 0.0f;
1261 case MWT_LEFTMULTIPLY:
1262 CombineTransform( &dc->xformWorld2Wnd, xform,
1263 &dc->xformWorld2Wnd );
1265 case MWT_RIGHTMULTIPLY:
1266 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1273 DC_UpdateXforms( dc );
1276 release_dc_ptr( dc );
1281 /****************************************************************************
1282 * CombineTransform [GDI32.@]
1283 * Combines two transformation matrices.
1286 * xformResult [O] Stores the result of combining the two matrices
1287 * xform1 [I] Specifies the first matrix to apply
1288 * xform2 [I] Specifies the second matrix to apply
1291 * The same matrix can be passed in for more than one of the parameters.
1295 * Failure: FALSE. Use GetLastError() to determine the cause.
1297 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1298 const XFORM *xform2 )
1302 /* Check for illegal parameters */
1303 if (!xformResult || !xform1 || !xform2)
1306 /* Create the result in a temporary XFORM, since xformResult may be
1307 * equal to xform1 or xform2 */
1308 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1309 xform1->eM12 * xform2->eM21;
1310 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1311 xform1->eM12 * xform2->eM22;
1312 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1313 xform1->eM22 * xform2->eM21;
1314 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1315 xform1->eM22 * xform2->eM22;
1316 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1317 xform1->eDy * xform2->eM21 +
1319 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1320 xform1->eDy * xform2->eM22 +
1323 /* Copy the result to xformResult */
1324 *xformResult = xformTemp;
1330 /***********************************************************************
1331 * SetDCHook (GDI32.@)
1333 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1335 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1337 DC *dc = get_dc_ptr( hdc );
1339 if (!dc) return FALSE;
1341 if (!(dc->flags & DC_SAVED))
1343 dc->dwHookData = dwHookData;
1344 dc->hookThunk = hookProc;
1346 release_dc_ptr( dc );
1351 /***********************************************************************
1352 * GetDCHook (GDI32.@)
1354 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1356 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1358 DC *dc = get_dc_ptr( hdc );
1362 if (proc) *proc = dc->hookThunk;
1363 ret = dc->dwHookData;
1364 release_dc_ptr( dc );
1369 /* relay function to call the 16-bit DC hook proc */
1370 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1374 DC *dc = get_dc_ptr( hdc );
1376 if (!dc) return FALSE;
1379 args[5] = HDC_16(hdc);
1381 args[3] = HIWORD(data);
1382 args[2] = LOWORD(data);
1383 args[1] = HIWORD(lParam);
1384 args[0] = LOWORD(lParam);
1385 WOWCallback16Ex( (DWORD)dc->hookProc, WCB16_PASCAL, sizeof(args), args, &ret );
1387 release_dc_ptr( dc );
1391 /***********************************************************************
1392 * SetDCHook (GDI.190)
1394 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1396 DC *dc = get_dc_ptr( HDC_32(hdc16) );
1398 if (!dc) return FALSE;
1399 if (!(dc->flags & DC_SAVED))
1401 dc->dwHookData = dwHookData;
1402 dc->hookThunk = call_dc_hook16;
1403 dc->hookProc = hookProc;
1405 release_dc_ptr( dc );
1410 /***********************************************************************
1411 * GetDCHook (GDI.191)
1413 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1415 HDC hdc = HDC_32( hdc16 );
1416 DC *dc = get_dc_ptr( hdc );
1420 *phookProc = dc->hookProc;
1421 ret = dc->dwHookData;
1422 release_dc_ptr( dc );
1427 /***********************************************************************
1428 * SetHookFlags (GDI32.@)
1430 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1432 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1434 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1439 /* "Undocumented Windows" info is slightly confusing. */
1441 TRACE("hDC %p, flags %04x\n",hdc,flags);
1443 if (flags & DCHF_INVALIDATEVISRGN)
1444 ret = InterlockedExchange( &dc->dirty, 1 );
1445 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1446 ret = InterlockedExchange( &dc->dirty, 0 );
1448 GDI_ReleaseObj( dc );
1452 /***********************************************************************
1453 * SetICMMode (GDI32.@)
1455 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1457 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1458 if (iEnableICM == ICM_OFF) return ICM_OFF;
1459 if (iEnableICM == ICM_ON) return 0;
1460 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1464 /***********************************************************************
1465 * GetDeviceGammaRamp (GDI32.@)
1467 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1470 DC *dc = get_dc_ptr( hDC );
1474 if (dc->funcs->pGetDeviceGammaRamp)
1475 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1476 release_dc_ptr( dc );
1481 /***********************************************************************
1482 * SetDeviceGammaRamp (GDI32.@)
1484 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1487 DC *dc = get_dc_ptr( hDC );
1491 if (dc->funcs->pSetDeviceGammaRamp)
1492 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1493 release_dc_ptr( dc );
1498 /***********************************************************************
1499 * GetColorSpace (GDI32.@)
1501 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1503 /*FIXME Need to to whatever GetColorSpace actually does */
1507 /***********************************************************************
1508 * CreateColorSpaceA (GDI32.@)
1510 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1516 /***********************************************************************
1517 * CreateColorSpaceW (GDI32.@)
1519 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1525 /***********************************************************************
1526 * DeleteColorSpace (GDI32.@)
1528 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1535 /***********************************************************************
1536 * SetColorSpace (GDI32.@)
1538 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1545 /***********************************************************************
1546 * GetBoundsRect (GDI32.@)
1548 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1551 DC *dc = get_dc_ptr( hdc );
1553 if ( !dc ) return 0;
1555 if (rect) *rect = dc->BoundsRect;
1557 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1559 if (flags & DCB_RESET)
1561 dc->BoundsRect.left = 0;
1562 dc->BoundsRect.top = 0;
1563 dc->BoundsRect.right = 0;
1564 dc->BoundsRect.bottom = 0;
1565 dc->flags &= ~DC_BOUNDS_SET;
1567 release_dc_ptr( dc );
1572 /***********************************************************************
1573 * SetBoundsRect (GDI32.@)
1575 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1580 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1581 if (!(dc = get_dc_ptr( hdc ))) return 0;
1583 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1584 ((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;
1595 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1597 if (dc->flags & DC_BOUNDS_SET)
1599 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1600 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1601 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1602 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1606 dc->BoundsRect = *rect;
1607 dc->flags |= DC_BOUNDS_SET;
1611 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1612 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1614 release_dc_ptr( dc );
1619 /***********************************************************************
1620 * GetRelAbs (GDI32.@)
1622 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1625 DC *dc = get_dc_ptr( hdc );
1628 ret = dc->relAbsMode;
1629 release_dc_ptr( dc );
1637 /***********************************************************************
1638 * GetBkMode (GDI32.@)
1640 INT WINAPI GetBkMode( HDC hdc )
1643 DC * dc = get_dc_ptr( hdc );
1646 ret = dc->backgroundMode;
1647 release_dc_ptr( dc );
1653 /***********************************************************************
1654 * SetBkMode (GDI32.@)
1656 INT WINAPI SetBkMode( HDC hdc, INT mode )
1660 if ((mode <= 0) || (mode > BKMODE_LAST))
1662 SetLastError(ERROR_INVALID_PARAMETER);
1665 if (!(dc = get_dc_ptr( hdc ))) return 0;
1667 ret = dc->backgroundMode;
1668 if (dc->funcs->pSetBkMode)
1669 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1672 dc->backgroundMode = mode;
1673 release_dc_ptr( dc );
1678 /***********************************************************************
1681 INT WINAPI GetROP2( HDC hdc )
1684 DC * dc = get_dc_ptr( hdc );
1688 release_dc_ptr( dc );
1694 /***********************************************************************
1697 INT WINAPI SetROP2( HDC hdc, INT mode )
1701 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1703 SetLastError(ERROR_INVALID_PARAMETER);
1706 if (!(dc = get_dc_ptr( hdc ))) return 0;
1708 if (dc->funcs->pSetROP2)
1709 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1713 release_dc_ptr( dc );
1718 /***********************************************************************
1719 * SetRelAbs (GDI32.@)
1721 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1725 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1727 SetLastError(ERROR_INVALID_PARAMETER);
1730 if (!(dc = get_dc_ptr( hdc ))) return 0;
1731 if (dc->funcs->pSetRelAbs)
1732 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1735 ret = dc->relAbsMode;
1736 dc->relAbsMode = mode;
1738 release_dc_ptr( dc );
1743 /***********************************************************************
1744 * GetPolyFillMode (GDI32.@)
1746 INT WINAPI GetPolyFillMode( HDC hdc )
1749 DC * dc = get_dc_ptr( hdc );
1752 ret = dc->polyFillMode;
1753 release_dc_ptr( dc );
1759 /***********************************************************************
1760 * SetPolyFillMode (GDI32.@)
1762 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1766 if ((mode <= 0) || (mode > POLYFILL_LAST))
1768 SetLastError(ERROR_INVALID_PARAMETER);
1771 if (!(dc = get_dc_ptr( hdc ))) return 0;
1772 ret = dc->polyFillMode;
1773 if (dc->funcs->pSetPolyFillMode)
1774 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1777 dc->polyFillMode = mode;
1778 release_dc_ptr( dc );
1783 /***********************************************************************
1784 * GetStretchBltMode (GDI32.@)
1786 INT WINAPI GetStretchBltMode( HDC hdc )
1789 DC * dc = get_dc_ptr( hdc );
1792 ret = dc->stretchBltMode;
1793 release_dc_ptr( dc );
1799 /***********************************************************************
1800 * SetStretchBltMode (GDI32.@)
1802 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1806 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1808 SetLastError(ERROR_INVALID_PARAMETER);
1811 if (!(dc = get_dc_ptr( hdc ))) return 0;
1812 ret = dc->stretchBltMode;
1813 if (dc->funcs->pSetStretchBltMode)
1814 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1817 dc->stretchBltMode = mode;
1818 release_dc_ptr( dc );
1823 /***********************************************************************
1824 * GetMapMode (GDI32.@)
1826 INT WINAPI GetMapMode( HDC hdc )
1829 DC * dc = get_dc_ptr( hdc );
1833 release_dc_ptr( dc );
1839 /***********************************************************************
1840 * GetBrushOrgEx (GDI32.@)
1842 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1844 DC * dc = get_dc_ptr( hdc );
1845 if (!dc) return FALSE;
1846 pt->x = dc->brushOrgX;
1847 pt->y = dc->brushOrgY;
1848 release_dc_ptr( dc );
1853 /***********************************************************************
1854 * GetCurrentPositionEx (GDI32.@)
1856 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1858 DC * dc = get_dc_ptr( hdc );
1859 if (!dc) return FALSE;
1860 pt->x = dc->CursPosX;
1861 pt->y = dc->CursPosY;
1862 release_dc_ptr( dc );
1867 /***********************************************************************
1868 * GetViewportExtEx (GDI32.@)
1870 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1872 DC * dc = get_dc_ptr( hdc );
1873 if (!dc) return FALSE;
1874 size->cx = dc->vportExtX;
1875 size->cy = dc->vportExtY;
1876 release_dc_ptr( dc );
1881 /***********************************************************************
1882 * GetViewportOrgEx (GDI32.@)
1884 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1886 DC * dc = get_dc_ptr( hdc );
1887 if (!dc) return FALSE;
1888 pt->x = dc->vportOrgX;
1889 pt->y = dc->vportOrgY;
1890 release_dc_ptr( dc );
1895 /***********************************************************************
1896 * GetWindowExtEx (GDI32.@)
1898 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1900 DC * dc = get_dc_ptr( hdc );
1901 if (!dc) return FALSE;
1902 size->cx = dc->wndExtX;
1903 size->cy = dc->wndExtY;
1904 release_dc_ptr( dc );
1909 /***********************************************************************
1910 * GetWindowOrgEx (GDI32.@)
1912 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1914 DC * dc = get_dc_ptr( hdc );
1915 if (!dc) return FALSE;
1916 pt->x = dc->wndOrgX;
1917 pt->y = dc->wndOrgY;
1918 release_dc_ptr( dc );
1923 /***********************************************************************
1924 * GetLayout (GDI32.@)
1926 * Gets left->right or right->left text layout flags of a dc.
1929 DWORD WINAPI GetLayout(HDC hdc)
1931 DWORD layout = GDI_ERROR;
1933 DC * dc = get_dc_ptr( hdc );
1936 layout = dc->layout;
1937 release_dc_ptr( dc );
1940 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1945 /***********************************************************************
1946 * SetLayout (GDI32.@)
1948 * Sets left->right or right->left text layout flags of a dc.
1951 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1953 DWORD oldlayout = GDI_ERROR;
1955 DC * dc = get_dc_ptr( hdc );
1958 oldlayout = dc->layout;
1959 dc->layout = layout;
1960 release_dc_ptr( dc );
1963 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1968 /***********************************************************************
1969 * GetDCBrushColor (GDI32.@)
1971 * Retrieves the current brush color for the specified device
1975 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1978 COLORREF dcBrushColor = CLR_INVALID;
1980 TRACE("hdc(%p)\n", hdc);
1982 dc = get_dc_ptr( hdc );
1985 dcBrushColor = dc->dcBrushColor;
1986 release_dc_ptr( dc );
1989 return dcBrushColor;
1992 /***********************************************************************
1993 * SetDCBrushColor (GDI32.@)
1995 * Sets the current device context (DC) brush color to the specified
1996 * color value. If the device cannot represent the specified color
1997 * value, the color is set to the nearest physical color.
2000 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2003 COLORREF oldClr = CLR_INVALID;
2005 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2007 dc = get_dc_ptr( hdc );
2010 if (dc->funcs->pSetDCBrushColor)
2011 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2012 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2014 /* If DC_BRUSH is selected, update driver pen color */
2015 HBRUSH hBrush = CreateSolidBrush( crColor );
2016 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2017 DeleteObject( hBrush );
2020 if (crColor != CLR_INVALID)
2022 oldClr = dc->dcBrushColor;
2023 dc->dcBrushColor = crColor;
2026 release_dc_ptr( dc );
2032 /***********************************************************************
2033 * GetDCPenColor (GDI32.@)
2035 * Retrieves the current pen color for the specified device
2039 COLORREF WINAPI GetDCPenColor(HDC hdc)
2042 COLORREF dcPenColor = CLR_INVALID;
2044 TRACE("hdc(%p)\n", hdc);
2046 dc = get_dc_ptr( hdc );
2049 dcPenColor = dc->dcPenColor;
2050 release_dc_ptr( dc );
2056 /***********************************************************************
2057 * SetDCPenColor (GDI32.@)
2059 * Sets the current device context (DC) pen color to the specified
2060 * color value. If the device cannot represent the specified color
2061 * value, the color is set to the nearest physical color.
2064 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2067 COLORREF oldClr = CLR_INVALID;
2069 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2071 dc = get_dc_ptr( hdc );
2074 if (dc->funcs->pSetDCPenColor)
2075 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2076 else if (dc->hPen == GetStockObject( DC_PEN ))
2078 /* If DC_PEN is selected, update the driver pen color */
2079 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2080 HPEN hPen = CreatePenIndirect( &logpen );
2081 dc->funcs->pSelectPen( dc->physDev, hPen );
2082 DeleteObject( hPen );
2085 if (crColor != CLR_INVALID)
2087 oldClr = dc->dcPenColor;
2088 dc->dcPenColor = crColor;
2091 release_dc_ptr( dc );
2097 /***********************************************************************
2098 * CancelDC (GDI32.@)
2100 BOOL WINAPI CancelDC(HDC hdc)
2106 /***********************************************************************
2107 * SetVirtualResolution (GDI32.@)
2109 * Undocumented on msdn. Called when PowerPoint XP saves a file.
2111 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
2113 FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2117 /*******************************************************************
2118 * GetMiterLimit [GDI32.@]
2122 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2127 TRACE("(%p,%p)\n", hdc, peLimit);
2129 dc = get_dc_ptr( hdc );
2133 *peLimit = dc->miterLimit;
2135 release_dc_ptr( dc );
2141 /*******************************************************************
2142 * SetMiterLimit [GDI32.@]
2146 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2151 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2153 dc = get_dc_ptr( hdc );
2157 *peOldLimit = dc->miterLimit;
2158 dc->miterLimit = eNewLimit;
2159 release_dc_ptr( dc );
2165 /*******************************************************************
2166 * GdiIsMetaPrintDC [GDI32.@]
2168 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2174 /*******************************************************************
2175 * GdiIsMetaFileDC [GDI32.@]
2177 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2181 switch( GetObjectType( hdc ) )
2190 /*******************************************************************
2191 * GdiIsPlayMetafileDC [GDI32.@]
2193 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)