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();
98 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
103 dc->hMetaClipRgn = 0;
105 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
106 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
107 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
110 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
112 dc->font_code_page = CP_ACP;
113 dc->ROPmode = R2_COPYPEN;
114 dc->polyFillMode = ALTERNATE;
115 dc->stretchBltMode = BLACKONWHITE;
116 dc->relAbsMode = ABSOLUTE;
117 dc->backgroundMode = OPAQUE;
118 dc->backgroundColor = RGB( 255, 255, 255 );
119 dc->dcBrushColor = RGB( 255, 255, 255 );
120 dc->dcPenColor = RGB( 0, 0, 0 );
121 dc->textColor = RGB( 0, 0, 0 );
124 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
128 dc->MapMode = MM_TEXT;
129 dc->GraphicsMode = GM_COMPATIBLE;
130 dc->pAbortProc = NULL;
133 dc->ArcDirection = AD_COUNTERCLOCKWISE;
134 dc->xformWorld2Wnd.eM11 = 1.0f;
135 dc->xformWorld2Wnd.eM12 = 0.0f;
136 dc->xformWorld2Wnd.eM21 = 0.0f;
137 dc->xformWorld2Wnd.eM22 = 1.0f;
138 dc->xformWorld2Wnd.eDx = 0.0f;
139 dc->xformWorld2Wnd.eDy = 0.0f;
140 dc->xformWorld2Vport = dc->xformWorld2Wnd;
141 dc->xformVport2World = dc->xformWorld2Wnd;
142 dc->vport2WorldValid = TRUE;
143 dc->BoundsRect.left = 0;
144 dc->BoundsRect.top = 0;
145 dc->BoundsRect.right = 0;
146 dc->BoundsRect.bottom = 0;
147 dc->saved_visrgn = NULL;
148 PATH_InitGdiPath(&dc->path);
150 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
152 HeapFree( GetProcessHeap(), 0, dc );
160 /***********************************************************************
163 BOOL free_dc_ptr( DC *dc )
165 assert( dc->refcount == 1 );
166 if (free_gdi_handle( dc->hSelf ) != dc) return FALSE; /* shouldn't happen */
167 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
168 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
169 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
170 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
171 PATH_DestroyGdiPath( &dc->path );
172 return HeapFree( GetProcessHeap(), 0, dc );
176 /***********************************************************************
179 * Retrieve a DC pointer but release the GDI lock.
181 DC *get_dc_ptr( HDC hdc )
183 DC *dc = get_dc_obj( hdc );
184 if (!dc) return NULL;
186 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
188 dc->thread = GetCurrentThreadId();
190 else if (dc->thread != GetCurrentThreadId())
192 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
193 GDI_ReleaseObj( hdc );
196 else InterlockedIncrement( &dc->refcount );
198 GDI_ReleaseObj( hdc );
203 /***********************************************************************
206 void release_dc_ptr( DC *dc )
211 ref = InterlockedDecrement( &dc->refcount );
213 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
217 /***********************************************************************
220 * Make sure the DC vis region is up to date.
221 * This function may call up to USER so the GDI lock should _not_
222 * be held when calling it.
224 void update_dc( DC *dc )
226 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
227 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
231 /***********************************************************************
234 static BOOL DC_DeleteObject( HGDIOBJ handle )
236 return DeleteDC( handle );
240 /***********************************************************************
243 * Setup device-specific DC values for a newly created DC.
245 void DC_InitDC( DC* dc )
247 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
248 SetTextColor( dc->hSelf, dc->textColor );
249 SetBkColor( dc->hSelf, dc->backgroundColor );
250 SelectObject( dc->hSelf, dc->hPen );
251 SelectObject( dc->hSelf, dc->hBrush );
252 SelectObject( dc->hSelf, dc->hFont );
253 CLIPPING_UpdateGCRegion( dc );
254 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
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;
286 /* Construct a transformation to do the window-to-viewport conversion */
287 static void construct_window_to_viewport(DC *dc, XFORM *xform)
289 double scaleX, scaleY;
290 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
291 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
293 xform->eM11 = scaleX;
296 xform->eM22 = scaleY;
297 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
298 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
301 /***********************************************************************
304 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
305 * fields of the specified DC by creating a transformation that
306 * represents the current mapping mode and combining it with the DC's
307 * world transform. This function should be called whenever the
308 * parameters associated with the mapping mode (window and viewport
309 * extents and origins) or the world transform change.
311 void DC_UpdateXforms( DC *dc )
313 XFORM xformWnd2Vport, oldworld2vport;
315 construct_window_to_viewport(dc, &xformWnd2Vport);
317 oldworld2vport = dc->xformWorld2Vport;
318 /* Combine with the world transformation */
319 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
322 /* Create inverse of world-to-viewport transformation */
323 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
324 &dc->xformVport2World );
326 /* Reselect the font and pen back into the dc so that the size
328 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
329 !GdiIsMetaFileDC(dc->hSelf))
331 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
332 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
337 /***********************************************************************
340 INT save_dc_state( HDC hdc )
345 if (!(dc = get_dc_ptr( hdc ))) return 0;
346 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc ))))
348 release_dc_ptr( dc );
352 newdc->flags = dc->flags | DC_SAVED;
353 newdc->layout = dc->layout;
354 newdc->hPen = dc->hPen;
355 newdc->hBrush = dc->hBrush;
356 newdc->hFont = dc->hFont;
357 newdc->hBitmap = dc->hBitmap;
358 newdc->hDevice = dc->hDevice;
359 newdc->hPalette = dc->hPalette;
360 newdc->ROPmode = dc->ROPmode;
361 newdc->polyFillMode = dc->polyFillMode;
362 newdc->stretchBltMode = dc->stretchBltMode;
363 newdc->relAbsMode = dc->relAbsMode;
364 newdc->backgroundMode = dc->backgroundMode;
365 newdc->backgroundColor = dc->backgroundColor;
366 newdc->textColor = dc->textColor;
367 newdc->dcBrushColor = dc->dcBrushColor;
368 newdc->dcPenColor = dc->dcPenColor;
369 newdc->brushOrgX = dc->brushOrgX;
370 newdc->brushOrgY = dc->brushOrgY;
371 newdc->textAlign = dc->textAlign;
372 newdc->charExtra = dc->charExtra;
373 newdc->breakExtra = dc->breakExtra;
374 newdc->breakRem = dc->breakRem;
375 newdc->MapMode = dc->MapMode;
376 newdc->GraphicsMode = dc->GraphicsMode;
377 newdc->CursPosX = dc->CursPosX;
378 newdc->CursPosY = dc->CursPosY;
379 newdc->ArcDirection = dc->ArcDirection;
380 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
381 newdc->xformWorld2Vport = dc->xformWorld2Vport;
382 newdc->xformVport2World = dc->xformVport2World;
383 newdc->vport2WorldValid = dc->vport2WorldValid;
384 newdc->wndOrgX = dc->wndOrgX;
385 newdc->wndOrgY = dc->wndOrgY;
386 newdc->wndExtX = dc->wndExtX;
387 newdc->wndExtY = dc->wndExtY;
388 newdc->vportOrgX = dc->vportOrgX;
389 newdc->vportOrgY = dc->vportOrgY;
390 newdc->vportExtX = dc->vportExtX;
391 newdc->vportExtY = dc->vportExtY;
392 newdc->virtual_res = dc->virtual_res;
393 newdc->virtual_size = dc->virtual_size;
394 newdc->BoundsRect = dc->BoundsRect;
395 newdc->gdiFont = dc->gdiFont;
397 newdc->thread = GetCurrentThreadId();
399 newdc->saveLevel = 0;
402 PATH_InitGdiPath( &newdc->path );
404 newdc->pAbortProc = NULL;
405 newdc->hookProc = NULL;
406 newdc->saved_visrgn = NULL;
408 if (!(newdc->hSelf = alloc_gdi_handle( &newdc->header, dc->header.type, &dc_funcs )))
410 HeapFree( GetProcessHeap(), 0, newdc );
411 release_dc_ptr( dc );
415 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
420 newdc->hMetaClipRgn = 0;
423 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
424 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
428 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
429 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
431 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
433 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
435 release_dc_ptr( dc );
436 free_dc_ptr( newdc );
440 newdc->saved_dc = dc->saved_dc;
441 dc->saved_dc = newdc->hSelf;
442 ret = ++dc->saveLevel;
443 release_dc_ptr( newdc );
444 release_dc_ptr( dc );
449 /***********************************************************************
452 BOOL restore_dc_state( HDC hdc, INT level )
458 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
460 /* find the state level to restore */
462 if (abs(level) > dc->saveLevel || level == 0)
464 release_dc_ptr( dc );
467 if (level < 0) level = dc->saveLevel + level + 1;
468 first_dcs = dc->saved_dc;
469 for (hdcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
471 if (!(dcs = get_dc_ptr( hdcs )))
473 release_dc_ptr( dc );
476 hdcs = dcs->saved_dc;
477 release_dc_ptr( dcs );
480 /* restore the state */
482 if (!(dcs = get_dc_ptr( hdcs )))
484 release_dc_ptr( dc );
487 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
489 release_dc_ptr( dcs );
490 release_dc_ptr( dc );
494 dc->flags = dcs->flags & ~DC_SAVED;
495 dc->layout = dcs->layout;
496 dc->hDevice = dcs->hDevice;
497 dc->ROPmode = dcs->ROPmode;
498 dc->polyFillMode = dcs->polyFillMode;
499 dc->stretchBltMode = dcs->stretchBltMode;
500 dc->relAbsMode = dcs->relAbsMode;
501 dc->backgroundMode = dcs->backgroundMode;
502 dc->backgroundColor = dcs->backgroundColor;
503 dc->textColor = dcs->textColor;
504 dc->dcBrushColor = dcs->dcBrushColor;
505 dc->dcPenColor = dcs->dcPenColor;
506 dc->brushOrgX = dcs->brushOrgX;
507 dc->brushOrgY = dcs->brushOrgY;
508 dc->textAlign = dcs->textAlign;
509 dc->charExtra = dcs->charExtra;
510 dc->breakExtra = dcs->breakExtra;
511 dc->breakRem = dcs->breakRem;
512 dc->MapMode = dcs->MapMode;
513 dc->GraphicsMode = dcs->GraphicsMode;
514 dc->CursPosX = dcs->CursPosX;
515 dc->CursPosY = dcs->CursPosY;
516 dc->ArcDirection = dcs->ArcDirection;
517 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
518 dc->xformWorld2Vport = dcs->xformWorld2Vport;
519 dc->xformVport2World = dcs->xformVport2World;
520 dc->vport2WorldValid = dcs->vport2WorldValid;
521 dc->BoundsRect = dcs->BoundsRect;
523 dc->wndOrgX = dcs->wndOrgX;
524 dc->wndOrgY = dcs->wndOrgY;
525 dc->wndExtX = dcs->wndExtX;
526 dc->wndExtY = dcs->wndExtY;
527 dc->vportOrgX = dcs->vportOrgX;
528 dc->vportOrgY = dcs->vportOrgY;
529 dc->vportExtX = dcs->vportExtX;
530 dc->vportExtY = dcs->vportExtY;
531 dc->virtual_res = dcs->virtual_res;
532 dc->virtual_size = dcs->virtual_size;
536 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
537 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
541 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
546 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
547 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
551 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
554 CLIPPING_UpdateGCRegion( dc );
556 SelectObject( hdc, dcs->hBitmap );
557 SelectObject( hdc, dcs->hBrush );
558 SelectObject( hdc, dcs->hFont );
559 SelectObject( hdc, dcs->hPen );
560 SetBkColor( hdc, dcs->backgroundColor);
561 SetTextColor( hdc, dcs->textColor);
562 GDISelectPalette( hdc, dcs->hPalette, FALSE );
564 dc->saved_dc = dcs->saved_dc;
566 dc->saveLevel = save_level - 1;
568 release_dc_ptr( dcs );
570 /* now destroy all the saved DCs */
574 if (!(dcs = get_dc_ptr( first_dcs ))) break;
575 hdcs = dcs->saved_dc;
579 release_dc_ptr( dc );
584 /***********************************************************************
587 INT WINAPI SaveDC( HDC hdc )
592 if (!(dc = get_dc_ptr( hdc ))) return 0;
594 if(dc->funcs->pSaveDC)
595 ret = dc->funcs->pSaveDC( dc->physDev );
597 ret = save_dc_state( hdc );
599 release_dc_ptr( dc );
604 /***********************************************************************
605 * RestoreDC (GDI32.@)
607 BOOL WINAPI RestoreDC( HDC hdc, INT level )
612 TRACE("%p %d\n", hdc, level );
613 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
616 if(dc->funcs->pRestoreDC)
617 success = dc->funcs->pRestoreDC( dc->physDev, level );
619 success = restore_dc_state( hdc, level );
621 release_dc_ptr( dc );
626 /***********************************************************************
627 * CreateDCW (GDI32.@)
629 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
630 const DEVMODEW *initData )
634 const DC_FUNCTIONS *funcs;
639 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
643 ERR( "no device found for %s\n", debugstr_w(device) );
646 strcpyW(buf, driver);
649 if (!(funcs = DRIVER_load_driver( buf )))
651 ERR( "no driver found for %s\n", debugstr_w(buf) );
654 if (!(dc = alloc_dc_ptr( funcs, OBJ_DC ))) goto error;
657 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
658 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
660 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
661 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
663 if (dc->funcs->pCreateDC &&
664 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
666 WARN("creation aborted by device\n" );
670 SetRectRgn( dc->hVisRgn, 0, 0,
671 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
674 release_dc_ptr( dc );
678 if (dc) free_dc_ptr( dc );
679 DRIVER_release_driver( funcs );
684 /***********************************************************************
685 * CreateDCA (GDI32.@)
687 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
688 const DEVMODEA *initData )
690 UNICODE_STRING driverW, deviceW, outputW;
694 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
695 else driverW.Buffer = NULL;
697 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
698 else deviceW.Buffer = NULL;
700 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
701 else outputW.Buffer = NULL;
706 /* don't convert initData for DISPLAY driver, it's not used */
707 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
708 initDataW = GdiConvertToDevmodeW(initData);
711 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
713 RtlFreeUnicodeString(&driverW);
714 RtlFreeUnicodeString(&deviceW);
715 RtlFreeUnicodeString(&outputW);
716 HeapFree(GetProcessHeap(), 0, initDataW);
721 /***********************************************************************
722 * CreateICA (GDI32.@)
724 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
725 const DEVMODEA* initData )
727 /* Nothing special yet for ICs */
728 return CreateDCA( driver, device, output, initData );
732 /***********************************************************************
733 * CreateICW (GDI32.@)
735 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
736 const DEVMODEW* initData )
738 /* Nothing special yet for ICs */
739 return CreateDCW( driver, device, output, initData );
743 /***********************************************************************
744 * CreateCompatibleDC (GDI32.@)
746 HDC WINAPI CreateCompatibleDC( HDC hdc )
750 const DC_FUNCTIONS *funcs = NULL;
751 PHYSDEV physDev = NULL;
755 if ((origDC = get_dc_ptr( hdc )))
757 if (GetObjectType( hdc ) == OBJ_DC)
759 funcs = origDC->funcs;
760 physDev = origDC->physDev;
762 release_dc_ptr( origDC );
763 if (funcs) funcs = DRIVER_get_driver( funcs );
765 else if (hdc) return 0;
767 if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
769 if (!(dc = alloc_dc_ptr( funcs, OBJ_MEMDC ))) goto error;
771 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
773 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
774 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
776 /* Copy the driver-specific physical device info into
777 * the new DC. The driver may use this read-only info
778 * while creating the compatible DC below. */
779 dc->physDev = physDev;
782 if (dc->funcs->pCreateDC &&
783 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
785 WARN("creation aborted by device\n");
790 release_dc_ptr( dc );
794 if (dc) free_dc_ptr( dc );
795 DRIVER_release_driver( funcs );
800 /***********************************************************************
803 BOOL WINAPI DeleteDC( HDC hdc )
805 const DC_FUNCTIONS *funcs = NULL;
812 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
813 if (dc->refcount != 1)
815 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
816 release_dc_ptr( dc );
820 /* Call hook procedure to check whether is it OK to delete this DC */
821 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
823 release_dc_ptr( dc );
827 while (dc->saveLevel)
830 HDC hdcs = dc->saved_dc;
831 if (!(dcs = get_dc_ptr( hdcs ))) break;
832 dc->saved_dc = dcs->saved_dc;
837 if (!(dc->flags & DC_SAVED))
839 SelectObject( hdc, GetStockObject(BLACK_PEN) );
840 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
841 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
842 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
844 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
848 while (dc->saved_visrgn)
850 struct saved_visrgn *next = dc->saved_visrgn->next;
851 DeleteObject( dc->saved_visrgn->hrgn );
852 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
853 dc->saved_visrgn = next;
857 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
862 /***********************************************************************
865 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
870 if ((dc = get_dc_ptr( hdc )))
872 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
873 release_dc_ptr( dc );
879 /***********************************************************************
882 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
887 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
888 else devmodeW = NULL;
890 ret = ResetDCW(hdc, devmodeW);
892 HeapFree(GetProcessHeap(), 0, devmodeW);
897 /***********************************************************************
898 * GetDeviceCaps (GDI32.@)
900 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
905 if ((dc = get_dc_ptr( hdc )))
907 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
908 else switch(cap) /* return meaningful values for some entries */
910 case HORZRES: ret = 640; break;
911 case VERTRES: ret = 480; break;
912 case BITSPIXEL: ret = 1; break;
913 case PLANES: ret = 1; break;
914 case NUMCOLORS: ret = 2; break;
915 case ASPECTX: ret = 36; break;
916 case ASPECTY: ret = 36; break;
917 case ASPECTXY: ret = 51; break;
918 case LOGPIXELSX: ret = 72; break;
919 case LOGPIXELSY: ret = 72; break;
920 case SIZEPALETTE: ret = 2; break;
922 release_dc_ptr( dc );
928 /***********************************************************************
929 * GetBkColor (GDI32.@)
931 COLORREF WINAPI GetBkColor( HDC hdc )
934 DC * dc = get_dc_ptr( hdc );
937 ret = dc->backgroundColor;
938 release_dc_ptr( dc );
944 /***********************************************************************
945 * SetBkColor (GDI32.@)
947 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
950 DC * dc = get_dc_ptr( hdc );
952 TRACE("hdc=%p color=0x%08x\n", hdc, color);
954 if (!dc) return CLR_INVALID;
955 oldColor = dc->backgroundColor;
956 if (dc->funcs->pSetBkColor)
958 color = dc->funcs->pSetBkColor(dc->physDev, color);
959 if (color == CLR_INVALID) /* don't change it */
962 oldColor = CLR_INVALID;
965 dc->backgroundColor = color;
966 release_dc_ptr( dc );
971 /***********************************************************************
972 * GetTextColor (GDI32.@)
974 COLORREF WINAPI GetTextColor( HDC hdc )
977 DC * dc = get_dc_ptr( hdc );
981 release_dc_ptr( dc );
987 /***********************************************************************
988 * SetTextColor (GDI32.@)
990 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
993 DC * dc = get_dc_ptr( hdc );
995 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
997 if (!dc) return CLR_INVALID;
998 oldColor = dc->textColor;
999 if (dc->funcs->pSetTextColor)
1001 color = dc->funcs->pSetTextColor(dc->physDev, color);
1002 if (color == CLR_INVALID) /* don't change it */
1005 oldColor = CLR_INVALID;
1008 dc->textColor = color;
1009 release_dc_ptr( dc );
1014 /***********************************************************************
1015 * GetTextAlign (GDI32.@)
1017 UINT WINAPI GetTextAlign( HDC hdc )
1020 DC * dc = get_dc_ptr( hdc );
1023 ret = dc->textAlign;
1024 release_dc_ptr( dc );
1030 /***********************************************************************
1031 * SetTextAlign (GDI32.@)
1033 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1036 DC *dc = get_dc_ptr( hdc );
1038 TRACE("hdc=%p align=%d\n", hdc, align);
1040 if (!dc) return 0x0;
1041 ret = dc->textAlign;
1042 if (dc->funcs->pSetTextAlign)
1043 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1045 if (ret != GDI_ERROR)
1046 dc->textAlign = align;
1047 release_dc_ptr( dc );
1051 /***********************************************************************
1052 * GetDCOrgEx (GDI32.@)
1054 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1058 if (!lpp) return FALSE;
1059 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1061 lpp->x = lpp->y = 0;
1062 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1063 release_dc_ptr( dc );
1068 /***********************************************************************
1069 * GetGraphicsMode (GDI32.@)
1071 INT WINAPI GetGraphicsMode( HDC hdc )
1074 DC * dc = get_dc_ptr( hdc );
1077 ret = dc->GraphicsMode;
1078 release_dc_ptr( dc );
1084 /***********************************************************************
1085 * SetGraphicsMode (GDI32.@)
1087 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1090 DC *dc = get_dc_ptr( hdc );
1092 /* One would think that setting the graphics mode to GM_COMPATIBLE
1093 * would also reset the world transformation matrix to the unity
1094 * matrix. However, in Windows, this is not the case. This doesn't
1095 * make a lot of sense to me, but that's the way it is.
1098 if ((mode > 0) && (mode <= GM_LAST))
1100 ret = dc->GraphicsMode;
1101 dc->GraphicsMode = mode;
1103 release_dc_ptr( dc );
1108 /***********************************************************************
1109 * GetArcDirection (GDI32.@)
1111 INT WINAPI GetArcDirection( HDC hdc )
1114 DC * dc = get_dc_ptr( hdc );
1117 ret = dc->ArcDirection;
1118 release_dc_ptr( dc );
1124 /***********************************************************************
1125 * SetArcDirection (GDI32.@)
1127 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1130 INT nOldDirection = 0;
1132 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1134 SetLastError(ERROR_INVALID_PARAMETER);
1138 if ((dc = get_dc_ptr( hdc )))
1140 if (dc->funcs->pSetArcDirection)
1142 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1144 nOldDirection = dc->ArcDirection;
1145 dc->ArcDirection = nDirection;
1146 release_dc_ptr( dc );
1148 return nOldDirection;
1152 /***********************************************************************
1153 * GetWorldTransform (GDI32.@)
1155 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1158 if (!xform) return FALSE;
1159 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1160 *xform = dc->xformWorld2Wnd;
1161 release_dc_ptr( dc );
1166 /***********************************************************************
1167 * GetTransform (GDI32.@)
1171 * Returns one of the co-ordinate space transforms
1174 * hdc [I] Device context.
1175 * which [I] Which xform to return:
1176 * 0x203 World -> Page transform (that set by SetWorldTransform).
1177 * 0x304 Page -> Device transform (the mapping mode transform).
1178 * 0x204 World -> Device transform (the combination of the above two).
1179 * 0x402 Device -> World transform (the inversion of the above).
1180 * xform [O] The xform.
1183 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1186 DC *dc = get_dc_ptr( hdc );
1187 if (!dc) return FALSE;
1192 *xform = dc->xformWorld2Wnd;
1196 construct_window_to_viewport(dc, xform);
1200 *xform = dc->xformWorld2Vport;
1204 *xform = dc->xformVport2World;
1208 FIXME("Unknown code %x\n", which);
1212 release_dc_ptr( dc );
1217 /***********************************************************************
1218 * SetWorldTransform (GDI32.@)
1220 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1225 if (!xform) return FALSE;
1227 dc = get_dc_ptr( hdc );
1228 if (!dc) return FALSE;
1230 /* Check that graphics mode is GM_ADVANCED */
1231 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1233 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1234 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1236 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1237 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) goto done;
1239 if (dc->funcs->pSetWorldTransform)
1241 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1242 if (!ret) goto done;
1245 dc->xformWorld2Wnd = *xform;
1246 DC_UpdateXforms( dc );
1249 release_dc_ptr( dc );
1254 /****************************************************************************
1255 * ModifyWorldTransform [GDI32.@]
1256 * Modifies the world transformation for a device context.
1259 * hdc [I] Handle to device context
1260 * xform [I] XFORM structure that will be used to modify the world
1262 * iMode [I] Specifies in what way to modify the world transformation
1265 * Resets the world transformation to the identity matrix.
1266 * The parameter xform is ignored.
1268 * Multiplies xform into the world transformation matrix from
1271 * Multiplies xform into the world transformation matrix from
1276 * Failure: FALSE. Use GetLastError() to determine the cause.
1278 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1282 DC *dc = get_dc_ptr( hdc );
1284 /* Check for illegal parameters */
1285 if (!dc) return FALSE;
1286 if (!xform && iMode != MWT_IDENTITY) goto done;
1288 /* Check that graphics mode is GM_ADVANCED */
1289 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1291 if (dc->funcs->pModifyWorldTransform)
1293 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1294 if (!ret) goto done;
1300 dc->xformWorld2Wnd.eM11 = 1.0f;
1301 dc->xformWorld2Wnd.eM12 = 0.0f;
1302 dc->xformWorld2Wnd.eM21 = 0.0f;
1303 dc->xformWorld2Wnd.eM22 = 1.0f;
1304 dc->xformWorld2Wnd.eDx = 0.0f;
1305 dc->xformWorld2Wnd.eDy = 0.0f;
1307 case MWT_LEFTMULTIPLY:
1308 CombineTransform( &dc->xformWorld2Wnd, xform,
1309 &dc->xformWorld2Wnd );
1311 case MWT_RIGHTMULTIPLY:
1312 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1319 DC_UpdateXforms( dc );
1322 release_dc_ptr( dc );
1327 /****************************************************************************
1328 * CombineTransform [GDI32.@]
1329 * Combines two transformation matrices.
1332 * xformResult [O] Stores the result of combining the two matrices
1333 * xform1 [I] Specifies the first matrix to apply
1334 * xform2 [I] Specifies the second matrix to apply
1337 * The same matrix can be passed in for more than one of the parameters.
1341 * Failure: FALSE. Use GetLastError() to determine the cause.
1343 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1344 const XFORM *xform2 )
1348 /* Check for illegal parameters */
1349 if (!xformResult || !xform1 || !xform2)
1352 /* Create the result in a temporary XFORM, since xformResult may be
1353 * equal to xform1 or xform2 */
1354 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1355 xform1->eM12 * xform2->eM21;
1356 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1357 xform1->eM12 * xform2->eM22;
1358 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1359 xform1->eM22 * xform2->eM21;
1360 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1361 xform1->eM22 * xform2->eM22;
1362 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1363 xform1->eDy * xform2->eM21 +
1365 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1366 xform1->eDy * xform2->eM22 +
1369 /* Copy the result to xformResult */
1370 *xformResult = xformTemp;
1376 /***********************************************************************
1377 * SetDCHook (GDI32.@)
1379 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1381 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1383 DC *dc = get_dc_ptr( hdc );
1385 if (!dc) return FALSE;
1387 if (!(dc->flags & DC_SAVED))
1389 dc->dwHookData = dwHookData;
1390 dc->hookProc = hookProc;
1392 release_dc_ptr( dc );
1397 /***********************************************************************
1398 * GetDCHook (GDI32.@)
1400 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1402 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1404 DC *dc = get_dc_ptr( hdc );
1408 if (proc) *proc = dc->hookProc;
1409 ret = dc->dwHookData;
1410 release_dc_ptr( dc );
1415 /***********************************************************************
1416 * SetHookFlags (GDI32.@)
1418 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1420 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1422 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1427 /* "Undocumented Windows" info is slightly confusing. */
1429 TRACE("hDC %p, flags %04x\n",hdc,flags);
1431 if (flags & DCHF_INVALIDATEVISRGN)
1432 ret = InterlockedExchange( &dc->dirty, 1 );
1433 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1434 ret = InterlockedExchange( &dc->dirty, 0 );
1436 GDI_ReleaseObj( dc );
1440 /***********************************************************************
1441 * SetICMMode (GDI32.@)
1443 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1445 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1446 if (iEnableICM == ICM_OFF) return ICM_OFF;
1447 if (iEnableICM == ICM_ON) return 0;
1448 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1452 /***********************************************************************
1453 * GetDeviceGammaRamp (GDI32.@)
1455 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1458 DC *dc = get_dc_ptr( hDC );
1462 if (dc->funcs->pGetDeviceGammaRamp)
1463 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1464 release_dc_ptr( dc );
1469 /***********************************************************************
1470 * SetDeviceGammaRamp (GDI32.@)
1472 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1475 DC *dc = get_dc_ptr( hDC );
1479 if (dc->funcs->pSetDeviceGammaRamp)
1480 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1481 release_dc_ptr( dc );
1486 /***********************************************************************
1487 * GetColorSpace (GDI32.@)
1489 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1491 /*FIXME Need to to whatever GetColorSpace actually does */
1495 /***********************************************************************
1496 * CreateColorSpaceA (GDI32.@)
1498 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1504 /***********************************************************************
1505 * CreateColorSpaceW (GDI32.@)
1507 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1513 /***********************************************************************
1514 * DeleteColorSpace (GDI32.@)
1516 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1523 /***********************************************************************
1524 * SetColorSpace (GDI32.@)
1526 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1533 /***********************************************************************
1534 * GetBoundsRect (GDI32.@)
1536 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1539 DC *dc = get_dc_ptr( hdc );
1541 if ( !dc ) return 0;
1543 if (rect) *rect = dc->BoundsRect;
1545 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1547 if (flags & DCB_RESET)
1549 dc->BoundsRect.left = 0;
1550 dc->BoundsRect.top = 0;
1551 dc->BoundsRect.right = 0;
1552 dc->BoundsRect.bottom = 0;
1553 dc->flags &= ~DC_BOUNDS_SET;
1555 release_dc_ptr( dc );
1560 /***********************************************************************
1561 * SetBoundsRect (GDI32.@)
1563 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1568 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1569 if (!(dc = get_dc_ptr( hdc ))) return 0;
1571 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1572 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1574 if (flags & DCB_RESET)
1576 dc->BoundsRect.left = 0;
1577 dc->BoundsRect.top = 0;
1578 dc->BoundsRect.right = 0;
1579 dc->BoundsRect.bottom = 0;
1580 dc->flags &= ~DC_BOUNDS_SET;
1583 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1585 if (dc->flags & DC_BOUNDS_SET)
1587 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1588 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1589 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1590 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1594 dc->BoundsRect = *rect;
1595 dc->flags |= DC_BOUNDS_SET;
1599 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1600 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1602 release_dc_ptr( dc );
1607 /***********************************************************************
1608 * GetRelAbs (GDI32.@)
1610 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1613 DC *dc = get_dc_ptr( hdc );
1616 ret = dc->relAbsMode;
1617 release_dc_ptr( dc );
1625 /***********************************************************************
1626 * GetBkMode (GDI32.@)
1628 INT WINAPI GetBkMode( HDC hdc )
1631 DC * dc = get_dc_ptr( hdc );
1634 ret = dc->backgroundMode;
1635 release_dc_ptr( dc );
1641 /***********************************************************************
1642 * SetBkMode (GDI32.@)
1644 INT WINAPI SetBkMode( HDC hdc, INT mode )
1648 if ((mode <= 0) || (mode > BKMODE_LAST))
1650 SetLastError(ERROR_INVALID_PARAMETER);
1653 if (!(dc = get_dc_ptr( hdc ))) return 0;
1655 ret = dc->backgroundMode;
1656 if (dc->funcs->pSetBkMode)
1657 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1660 dc->backgroundMode = mode;
1661 release_dc_ptr( dc );
1666 /***********************************************************************
1669 INT WINAPI GetROP2( HDC hdc )
1672 DC * dc = get_dc_ptr( hdc );
1676 release_dc_ptr( dc );
1682 /***********************************************************************
1685 INT WINAPI SetROP2( HDC hdc, INT mode )
1689 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1691 SetLastError(ERROR_INVALID_PARAMETER);
1694 if (!(dc = get_dc_ptr( hdc ))) return 0;
1696 if (dc->funcs->pSetROP2)
1697 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1701 release_dc_ptr( dc );
1706 /***********************************************************************
1707 * SetRelAbs (GDI32.@)
1709 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1713 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1715 SetLastError(ERROR_INVALID_PARAMETER);
1718 if (!(dc = get_dc_ptr( hdc ))) return 0;
1719 if (dc->funcs->pSetRelAbs)
1720 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1723 ret = dc->relAbsMode;
1724 dc->relAbsMode = mode;
1726 release_dc_ptr( dc );
1731 /***********************************************************************
1732 * GetPolyFillMode (GDI32.@)
1734 INT WINAPI GetPolyFillMode( HDC hdc )
1737 DC * dc = get_dc_ptr( hdc );
1740 ret = dc->polyFillMode;
1741 release_dc_ptr( dc );
1747 /***********************************************************************
1748 * SetPolyFillMode (GDI32.@)
1750 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1754 if ((mode <= 0) || (mode > POLYFILL_LAST))
1756 SetLastError(ERROR_INVALID_PARAMETER);
1759 if (!(dc = get_dc_ptr( hdc ))) return 0;
1760 ret = dc->polyFillMode;
1761 if (dc->funcs->pSetPolyFillMode)
1762 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1765 dc->polyFillMode = mode;
1766 release_dc_ptr( dc );
1771 /***********************************************************************
1772 * GetStretchBltMode (GDI32.@)
1774 INT WINAPI GetStretchBltMode( HDC hdc )
1777 DC * dc = get_dc_ptr( hdc );
1780 ret = dc->stretchBltMode;
1781 release_dc_ptr( dc );
1787 /***********************************************************************
1788 * SetStretchBltMode (GDI32.@)
1790 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1794 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1796 SetLastError(ERROR_INVALID_PARAMETER);
1799 if (!(dc = get_dc_ptr( hdc ))) return 0;
1800 ret = dc->stretchBltMode;
1801 if (dc->funcs->pSetStretchBltMode)
1802 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1805 dc->stretchBltMode = mode;
1806 release_dc_ptr( dc );
1811 /***********************************************************************
1812 * GetMapMode (GDI32.@)
1814 INT WINAPI GetMapMode( HDC hdc )
1817 DC * dc = get_dc_ptr( hdc );
1821 release_dc_ptr( dc );
1827 /***********************************************************************
1828 * GetBrushOrgEx (GDI32.@)
1830 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1832 DC * dc = get_dc_ptr( hdc );
1833 if (!dc) return FALSE;
1834 pt->x = dc->brushOrgX;
1835 pt->y = dc->brushOrgY;
1836 release_dc_ptr( dc );
1841 /***********************************************************************
1842 * GetCurrentPositionEx (GDI32.@)
1844 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1846 DC * dc = get_dc_ptr( hdc );
1847 if (!dc) return FALSE;
1848 pt->x = dc->CursPosX;
1849 pt->y = dc->CursPosY;
1850 release_dc_ptr( dc );
1855 /***********************************************************************
1856 * GetViewportExtEx (GDI32.@)
1858 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1860 DC * dc = get_dc_ptr( hdc );
1861 if (!dc) return FALSE;
1862 size->cx = dc->vportExtX;
1863 size->cy = dc->vportExtY;
1864 release_dc_ptr( dc );
1869 /***********************************************************************
1870 * GetViewportOrgEx (GDI32.@)
1872 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1874 DC * dc = get_dc_ptr( hdc );
1875 if (!dc) return FALSE;
1876 pt->x = dc->vportOrgX;
1877 pt->y = dc->vportOrgY;
1878 release_dc_ptr( dc );
1883 /***********************************************************************
1884 * GetWindowExtEx (GDI32.@)
1886 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1888 DC * dc = get_dc_ptr( hdc );
1889 if (!dc) return FALSE;
1890 size->cx = dc->wndExtX;
1891 size->cy = dc->wndExtY;
1892 release_dc_ptr( dc );
1897 /***********************************************************************
1898 * GetWindowOrgEx (GDI32.@)
1900 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1902 DC * dc = get_dc_ptr( hdc );
1903 if (!dc) return FALSE;
1904 pt->x = dc->wndOrgX;
1905 pt->y = dc->wndOrgY;
1906 release_dc_ptr( dc );
1911 /***********************************************************************
1912 * GetLayout (GDI32.@)
1914 * Gets left->right or right->left text layout flags of a dc.
1917 DWORD WINAPI GetLayout(HDC hdc)
1919 DWORD layout = GDI_ERROR;
1921 DC * dc = get_dc_ptr( hdc );
1924 layout = dc->layout;
1925 release_dc_ptr( dc );
1928 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1933 /***********************************************************************
1934 * SetLayout (GDI32.@)
1936 * Sets left->right or right->left text layout flags of a dc.
1939 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1941 DWORD oldlayout = GDI_ERROR;
1943 DC * dc = get_dc_ptr( hdc );
1946 oldlayout = dc->layout;
1947 dc->layout = layout;
1948 release_dc_ptr( dc );
1951 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1956 /***********************************************************************
1957 * GetDCBrushColor (GDI32.@)
1959 * Retrieves the current brush color for the specified device
1963 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1966 COLORREF dcBrushColor = CLR_INVALID;
1968 TRACE("hdc(%p)\n", hdc);
1970 dc = get_dc_ptr( hdc );
1973 dcBrushColor = dc->dcBrushColor;
1974 release_dc_ptr( dc );
1977 return dcBrushColor;
1980 /***********************************************************************
1981 * SetDCBrushColor (GDI32.@)
1983 * Sets the current device context (DC) brush color to the specified
1984 * color value. If the device cannot represent the specified color
1985 * value, the color is set to the nearest physical color.
1988 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1991 COLORREF oldClr = CLR_INVALID;
1993 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1995 dc = get_dc_ptr( hdc );
1998 if (dc->funcs->pSetDCBrushColor)
1999 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2000 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2002 /* If DC_BRUSH is selected, update driver pen color */
2003 HBRUSH hBrush = CreateSolidBrush( crColor );
2004 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2005 DeleteObject( hBrush );
2008 if (crColor != CLR_INVALID)
2010 oldClr = dc->dcBrushColor;
2011 dc->dcBrushColor = crColor;
2014 release_dc_ptr( dc );
2020 /***********************************************************************
2021 * GetDCPenColor (GDI32.@)
2023 * Retrieves the current pen color for the specified device
2027 COLORREF WINAPI GetDCPenColor(HDC hdc)
2030 COLORREF dcPenColor = CLR_INVALID;
2032 TRACE("hdc(%p)\n", hdc);
2034 dc = get_dc_ptr( hdc );
2037 dcPenColor = dc->dcPenColor;
2038 release_dc_ptr( dc );
2044 /***********************************************************************
2045 * SetDCPenColor (GDI32.@)
2047 * Sets the current device context (DC) pen color to the specified
2048 * color value. If the device cannot represent the specified color
2049 * value, the color is set to the nearest physical color.
2052 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2055 COLORREF oldClr = CLR_INVALID;
2057 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2059 dc = get_dc_ptr( hdc );
2062 if (dc->funcs->pSetDCPenColor)
2063 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2064 else if (dc->hPen == GetStockObject( DC_PEN ))
2066 /* If DC_PEN is selected, update the driver pen color */
2067 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2068 HPEN hPen = CreatePenIndirect( &logpen );
2069 dc->funcs->pSelectPen( dc->physDev, hPen );
2070 DeleteObject( hPen );
2073 if (crColor != CLR_INVALID)
2075 oldClr = dc->dcPenColor;
2076 dc->dcPenColor = crColor;
2079 release_dc_ptr( dc );
2085 /***********************************************************************
2086 * CancelDC (GDI32.@)
2088 BOOL WINAPI CancelDC(HDC hdc)
2094 /*******************************************************************
2095 * GetMiterLimit [GDI32.@]
2099 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2104 TRACE("(%p,%p)\n", hdc, peLimit);
2106 dc = get_dc_ptr( hdc );
2110 *peLimit = dc->miterLimit;
2112 release_dc_ptr( dc );
2118 /*******************************************************************
2119 * SetMiterLimit [GDI32.@]
2123 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2128 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2130 dc = get_dc_ptr( hdc );
2134 *peOldLimit = dc->miterLimit;
2135 dc->miterLimit = eNewLimit;
2136 release_dc_ptr( dc );
2142 /*******************************************************************
2143 * GdiIsMetaPrintDC [GDI32.@]
2145 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2151 /*******************************************************************
2152 * GdiIsMetaFileDC [GDI32.@]
2154 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2158 switch( GetObjectType( hdc ) )
2167 /*******************************************************************
2168 * GdiIsPlayMetafileDC [GDI32.@]
2170 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)