2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "gdi_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dc);
39 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
41 static BOOL DC_DeleteObject( HGDIOBJ handle );
43 static const struct gdi_obj_funcs dc_funcs =
45 NULL, /* pSelectObject */
46 NULL, /* pGetObjectA */
47 NULL, /* pGetObjectW */
48 NULL, /* pUnrealizeObject */
49 DC_DeleteObject /* pDeleteObject */
53 static inline DC *get_dc_obj( HDC hdc )
55 DC *dc = GDI_GetObjPtr( hdc, 0 );
58 if ((dc->header.type != OBJ_DC) &&
59 (dc->header.type != OBJ_MEMDC) &&
60 (dc->header.type != OBJ_METADC) &&
61 (dc->header.type != OBJ_ENHMETADC))
63 GDI_ReleaseObj( hdc );
64 SetLastError( ERROR_INVALID_HANDLE );
71 /***********************************************************************
74 DC *alloc_dc_ptr( const DC_FUNCTIONS *funcs, WORD magic )
78 if (!(dc = HeapAlloc( GetProcessHeap(), 0, sizeof(*dc) ))) return NULL;
81 dc->nulldrv.funcs = &null_driver;
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 PATH_InitGdiPath(&dc->path);
149 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
151 HeapFree( GetProcessHeap(), 0, dc );
154 dc->nulldrv.hdc = dc->hSelf;
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 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
294 xform->eM11 = scaleX;
297 xform->eM22 = scaleY;
298 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
299 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
300 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
303 /***********************************************************************
306 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
307 * fields of the specified DC by creating a transformation that
308 * represents the current mapping mode and combining it with the DC's
309 * world transform. This function should be called whenever the
310 * parameters associated with the mapping mode (window and viewport
311 * extents and origins) or the world transform change.
313 void DC_UpdateXforms( DC *dc )
315 XFORM xformWnd2Vport, oldworld2vport;
317 construct_window_to_viewport(dc, &xformWnd2Vport);
319 oldworld2vport = dc->xformWorld2Vport;
320 /* Combine with the world transformation */
321 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
324 /* Create inverse of world-to-viewport transformation */
325 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
326 &dc->xformVport2World );
328 /* Reselect the font and pen back into the dc so that the size
330 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
331 !GdiIsMetaFileDC(dc->hSelf))
333 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
334 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
339 /***********************************************************************
342 INT save_dc_state( HDC hdc )
347 if (!(dc = get_dc_ptr( hdc ))) return 0;
348 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc ))))
350 release_dc_ptr( dc );
354 newdc->flags = dc->flags | DC_SAVED;
355 newdc->layout = dc->layout;
356 newdc->hPen = dc->hPen;
357 newdc->hBrush = dc->hBrush;
358 newdc->hFont = dc->hFont;
359 newdc->hBitmap = dc->hBitmap;
360 newdc->hDevice = dc->hDevice;
361 newdc->hPalette = dc->hPalette;
362 newdc->ROPmode = dc->ROPmode;
363 newdc->polyFillMode = dc->polyFillMode;
364 newdc->stretchBltMode = dc->stretchBltMode;
365 newdc->relAbsMode = dc->relAbsMode;
366 newdc->backgroundMode = dc->backgroundMode;
367 newdc->backgroundColor = dc->backgroundColor;
368 newdc->textColor = dc->textColor;
369 newdc->dcBrushColor = dc->dcBrushColor;
370 newdc->dcPenColor = dc->dcPenColor;
371 newdc->brushOrgX = dc->brushOrgX;
372 newdc->brushOrgY = dc->brushOrgY;
373 newdc->textAlign = dc->textAlign;
374 newdc->charExtra = dc->charExtra;
375 newdc->breakExtra = dc->breakExtra;
376 newdc->breakRem = dc->breakRem;
377 newdc->MapMode = dc->MapMode;
378 newdc->GraphicsMode = dc->GraphicsMode;
379 newdc->CursPosX = dc->CursPosX;
380 newdc->CursPosY = dc->CursPosY;
381 newdc->ArcDirection = dc->ArcDirection;
382 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
383 newdc->xformWorld2Vport = dc->xformWorld2Vport;
384 newdc->xformVport2World = dc->xformVport2World;
385 newdc->vport2WorldValid = dc->vport2WorldValid;
386 newdc->wndOrgX = dc->wndOrgX;
387 newdc->wndOrgY = dc->wndOrgY;
388 newdc->wndExtX = dc->wndExtX;
389 newdc->wndExtY = dc->wndExtY;
390 newdc->vportOrgX = dc->vportOrgX;
391 newdc->vportOrgY = dc->vportOrgY;
392 newdc->vportExtX = dc->vportExtX;
393 newdc->vportExtY = dc->vportExtY;
394 newdc->virtual_res = dc->virtual_res;
395 newdc->virtual_size = dc->virtual_size;
396 newdc->BoundsRect = dc->BoundsRect;
397 newdc->gdiFont = dc->gdiFont;
399 newdc->thread = GetCurrentThreadId();
401 newdc->saveLevel = 0;
404 PATH_InitGdiPath( &newdc->path );
406 newdc->pAbortProc = NULL;
407 newdc->hookProc = NULL;
409 if (!(newdc->hSelf = alloc_gdi_handle( &newdc->header, dc->header.type, &dc_funcs )))
411 HeapFree( GetProcessHeap(), 0, newdc );
412 release_dc_ptr( dc );
416 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
421 newdc->hMetaClipRgn = 0;
424 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
425 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
429 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
430 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
432 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
434 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
436 release_dc_ptr( dc );
437 free_dc_ptr( newdc );
441 newdc->saved_dc = dc->saved_dc;
442 dc->saved_dc = newdc->hSelf;
443 ret = ++dc->saveLevel;
444 release_dc_ptr( newdc );
445 release_dc_ptr( dc );
450 /***********************************************************************
453 BOOL restore_dc_state( HDC hdc, INT level )
459 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
461 /* find the state level to restore */
463 if (abs(level) > dc->saveLevel || level == 0)
465 release_dc_ptr( dc );
468 if (level < 0) level = dc->saveLevel + level + 1;
469 first_dcs = dc->saved_dc;
470 for (hdcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
472 if (!(dcs = get_dc_ptr( hdcs )))
474 release_dc_ptr( dc );
477 hdcs = dcs->saved_dc;
478 release_dc_ptr( dcs );
481 /* restore the state */
483 if (!(dcs = get_dc_ptr( hdcs )))
485 release_dc_ptr( dc );
488 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
490 release_dc_ptr( dcs );
491 release_dc_ptr( dc );
495 dc->flags = dcs->flags & ~DC_SAVED;
496 dc->layout = dcs->layout;
497 dc->hDevice = dcs->hDevice;
498 dc->ROPmode = dcs->ROPmode;
499 dc->polyFillMode = dcs->polyFillMode;
500 dc->stretchBltMode = dcs->stretchBltMode;
501 dc->relAbsMode = dcs->relAbsMode;
502 dc->backgroundMode = dcs->backgroundMode;
503 dc->backgroundColor = dcs->backgroundColor;
504 dc->textColor = dcs->textColor;
505 dc->dcBrushColor = dcs->dcBrushColor;
506 dc->dcPenColor = dcs->dcPenColor;
507 dc->brushOrgX = dcs->brushOrgX;
508 dc->brushOrgY = dcs->brushOrgY;
509 dc->textAlign = dcs->textAlign;
510 dc->charExtra = dcs->charExtra;
511 dc->breakExtra = dcs->breakExtra;
512 dc->breakRem = dcs->breakRem;
513 dc->MapMode = dcs->MapMode;
514 dc->GraphicsMode = dcs->GraphicsMode;
515 dc->CursPosX = dcs->CursPosX;
516 dc->CursPosY = dcs->CursPosY;
517 dc->ArcDirection = dcs->ArcDirection;
518 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
519 dc->xformWorld2Vport = dcs->xformWorld2Vport;
520 dc->xformVport2World = dcs->xformVport2World;
521 dc->vport2WorldValid = dcs->vport2WorldValid;
522 dc->BoundsRect = dcs->BoundsRect;
524 dc->wndOrgX = dcs->wndOrgX;
525 dc->wndOrgY = dcs->wndOrgY;
526 dc->wndExtX = dcs->wndExtX;
527 dc->wndExtY = dcs->wndExtY;
528 dc->vportOrgX = dcs->vportOrgX;
529 dc->vportOrgY = dcs->vportOrgY;
530 dc->vportExtX = dcs->vportExtX;
531 dc->vportExtY = dcs->vportExtY;
532 dc->virtual_res = dcs->virtual_res;
533 dc->virtual_size = dcs->virtual_size;
537 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
538 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
542 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
547 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
548 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
552 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
555 DC_UpdateXforms( dc );
556 CLIPPING_UpdateGCRegion( dc );
558 SelectObject( hdc, dcs->hBitmap );
559 SelectObject( hdc, dcs->hBrush );
560 SelectObject( hdc, dcs->hFont );
561 SelectObject( hdc, dcs->hPen );
562 SetBkColor( hdc, dcs->backgroundColor);
563 SetTextColor( hdc, dcs->textColor);
564 GDISelectPalette( hdc, dcs->hPalette, FALSE );
566 dc->saved_dc = dcs->saved_dc;
568 dc->saveLevel = save_level - 1;
570 release_dc_ptr( dcs );
572 /* now destroy all the saved DCs */
576 if (!(dcs = get_dc_ptr( first_dcs ))) break;
577 hdcs = dcs->saved_dc;
581 release_dc_ptr( dc );
586 /***********************************************************************
589 INT WINAPI SaveDC( HDC hdc )
594 if (!(dc = get_dc_ptr( hdc ))) return 0;
596 if(dc->funcs->pSaveDC)
597 ret = dc->funcs->pSaveDC( dc->physDev );
599 ret = save_dc_state( hdc );
601 release_dc_ptr( dc );
606 /***********************************************************************
607 * RestoreDC (GDI32.@)
609 BOOL WINAPI RestoreDC( HDC hdc, INT level )
614 TRACE("%p %d\n", hdc, level );
615 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
618 if(dc->funcs->pRestoreDC)
619 success = dc->funcs->pRestoreDC( dc->physDev, level );
621 success = restore_dc_state( hdc, level );
623 release_dc_ptr( dc );
628 /***********************************************************************
629 * CreateDCW (GDI32.@)
631 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
632 const DEVMODEW *initData )
636 const DC_FUNCTIONS *funcs;
641 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
645 ERR( "no device found for %s\n", debugstr_w(device) );
648 strcpyW(buf, driver);
651 if (!(funcs = DRIVER_load_driver( buf )))
653 ERR( "no driver found for %s\n", debugstr_w(buf) );
656 if (!(dc = alloc_dc_ptr( funcs, OBJ_DC ))) goto error;
659 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
660 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
662 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
663 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
665 if (dc->funcs->pCreateDC &&
666 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
668 WARN("creation aborted by device\n" );
672 dc->physDev->funcs = funcs;
673 dc->physDev->hdc = hdc;
674 dc->vis_rect.left = 0;
675 dc->vis_rect.top = 0;
676 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
677 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
678 SetRectRgn(dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top, dc->vis_rect.right, dc->vis_rect.bottom);
681 release_dc_ptr( dc );
685 if (dc) free_dc_ptr( dc );
690 /***********************************************************************
691 * CreateDCA (GDI32.@)
693 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
694 const DEVMODEA *initData )
696 UNICODE_STRING driverW, deviceW, outputW;
700 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
701 else driverW.Buffer = NULL;
703 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
704 else deviceW.Buffer = NULL;
706 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
707 else outputW.Buffer = NULL;
712 /* don't convert initData for DISPLAY driver, it's not used */
713 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
714 initDataW = GdiConvertToDevmodeW(initData);
717 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
719 RtlFreeUnicodeString(&driverW);
720 RtlFreeUnicodeString(&deviceW);
721 RtlFreeUnicodeString(&outputW);
722 HeapFree(GetProcessHeap(), 0, initDataW);
727 /***********************************************************************
728 * CreateICA (GDI32.@)
730 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
731 const DEVMODEA* initData )
733 /* Nothing special yet for ICs */
734 return CreateDCA( driver, device, output, initData );
738 /***********************************************************************
739 * CreateICW (GDI32.@)
741 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
742 const DEVMODEW* initData )
744 /* Nothing special yet for ICs */
745 return CreateDCW( driver, device, output, initData );
749 /***********************************************************************
750 * CreateCompatibleDC (GDI32.@)
752 HDC WINAPI CreateCompatibleDC( HDC hdc )
756 const DC_FUNCTIONS *funcs = NULL;
757 PHYSDEV physDev = NULL;
763 if (!(origDC = get_dc_ptr( hdc ))) return 0;
764 if (GetObjectType( hdc ) == OBJ_DC)
766 funcs = origDC->funcs;
767 physDev = origDC->physDev;
769 release_dc_ptr( origDC );
772 if (!funcs && !(funcs = DRIVER_get_display_driver())) return 0;
774 if (!(dc = alloc_dc_ptr( funcs, OBJ_MEMDC ))) goto error;
776 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
778 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
779 dc->vis_rect.left = 0;
780 dc->vis_rect.top = 0;
781 dc->vis_rect.right = 1;
782 dc->vis_rect.bottom = 1;
783 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
785 /* Copy the driver-specific physical device info into
786 * the new DC. The driver may use this read-only info
787 * while creating the compatible DC below. */
788 dc->physDev = physDev;
791 if (dc->funcs->pCreateDC &&
792 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
794 WARN("creation aborted by device\n");
798 dc->physDev->funcs = funcs;
799 dc->physDev->hdc = hdc;
801 release_dc_ptr( dc );
805 if (dc) free_dc_ptr( dc );
810 /***********************************************************************
813 BOOL WINAPI DeleteDC( HDC hdc )
821 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
822 if (dc->refcount != 1)
824 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
825 release_dc_ptr( dc );
829 /* Call hook procedure to check whether is it OK to delete this DC */
830 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
832 release_dc_ptr( dc );
836 while (dc->saveLevel)
839 HDC hdcs = dc->saved_dc;
840 if (!(dcs = get_dc_ptr( hdcs ))) break;
841 dc->saved_dc = dcs->saved_dc;
846 if (!(dc->flags & DC_SAVED))
848 SelectObject( hdc, GetStockObject(BLACK_PEN) );
849 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
850 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
851 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
852 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
861 /***********************************************************************
864 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
869 if ((dc = get_dc_ptr( hdc )))
871 if (dc->funcs->pResetDC)
873 ret = dc->funcs->pResetDC( dc->physDev, devmode );
874 if (ret) /* reset the visible region */
877 dc->vis_rect.left = 0;
878 dc->vis_rect.top = 0;
879 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
880 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
881 SetRectRgn( dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top,
882 dc->vis_rect.right, dc->vis_rect.bottom );
883 CLIPPING_UpdateGCRegion( dc );
886 release_dc_ptr( dc );
892 /***********************************************************************
895 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
900 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
901 else devmodeW = NULL;
903 ret = ResetDCW(hdc, devmodeW);
905 HeapFree(GetProcessHeap(), 0, devmodeW);
910 /***********************************************************************
911 * GetDeviceCaps (GDI32.@)
913 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
918 if ((dc = get_dc_ptr( hdc )))
920 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
921 else switch(cap) /* return meaningful values for some entries */
923 case HORZRES: ret = 640; break;
924 case VERTRES: ret = 480; break;
925 case BITSPIXEL: ret = 1; break;
926 case PLANES: ret = 1; break;
927 case NUMCOLORS: ret = 2; break;
928 case ASPECTX: ret = 36; break;
929 case ASPECTY: ret = 36; break;
930 case ASPECTXY: ret = 51; break;
931 case LOGPIXELSX: ret = 72; break;
932 case LOGPIXELSY: ret = 72; break;
933 case SIZEPALETTE: ret = 2; break;
935 ret = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
936 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
937 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
940 release_dc_ptr( dc );
946 /***********************************************************************
947 * GetBkColor (GDI32.@)
949 COLORREF WINAPI GetBkColor( HDC hdc )
952 DC * dc = get_dc_ptr( hdc );
955 ret = dc->backgroundColor;
956 release_dc_ptr( dc );
962 /***********************************************************************
963 * SetBkColor (GDI32.@)
965 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
968 DC * dc = get_dc_ptr( hdc );
970 TRACE("hdc=%p color=0x%08x\n", hdc, color);
972 if (!dc) return CLR_INVALID;
973 oldColor = dc->backgroundColor;
974 if (dc->funcs->pSetBkColor)
976 color = dc->funcs->pSetBkColor(dc->physDev, color);
977 if (color == CLR_INVALID) /* don't change it */
980 oldColor = CLR_INVALID;
983 dc->backgroundColor = color;
984 release_dc_ptr( dc );
989 /***********************************************************************
990 * GetTextColor (GDI32.@)
992 COLORREF WINAPI GetTextColor( HDC hdc )
995 DC * dc = get_dc_ptr( hdc );
999 release_dc_ptr( dc );
1005 /***********************************************************************
1006 * SetTextColor (GDI32.@)
1008 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
1011 DC * dc = get_dc_ptr( hdc );
1013 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
1015 if (!dc) return CLR_INVALID;
1016 oldColor = dc->textColor;
1017 if (dc->funcs->pSetTextColor)
1019 color = dc->funcs->pSetTextColor(dc->physDev, color);
1020 if (color == CLR_INVALID) /* don't change it */
1023 oldColor = CLR_INVALID;
1026 dc->textColor = color;
1027 release_dc_ptr( dc );
1032 /***********************************************************************
1033 * GetTextAlign (GDI32.@)
1035 UINT WINAPI GetTextAlign( HDC hdc )
1038 DC * dc = get_dc_ptr( hdc );
1041 ret = dc->textAlign;
1042 release_dc_ptr( dc );
1048 /***********************************************************************
1049 * SetTextAlign (GDI32.@)
1051 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1054 DC *dc = get_dc_ptr( hdc );
1056 TRACE("hdc=%p align=%d\n", hdc, align);
1058 if (!dc) return 0x0;
1059 ret = dc->textAlign;
1060 if (dc->funcs->pSetTextAlign)
1061 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1063 if (ret != GDI_ERROR)
1064 dc->textAlign = align;
1065 release_dc_ptr( dc );
1069 /***********************************************************************
1070 * GetDCOrgEx (GDI32.@)
1072 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1076 if (!lpp) return FALSE;
1077 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1078 lpp->x = dc->vis_rect.left;
1079 lpp->y = dc->vis_rect.top;
1080 release_dc_ptr( dc );
1085 /***********************************************************************
1086 * GetGraphicsMode (GDI32.@)
1088 INT WINAPI GetGraphicsMode( HDC hdc )
1091 DC * dc = get_dc_ptr( hdc );
1094 ret = dc->GraphicsMode;
1095 release_dc_ptr( dc );
1101 /***********************************************************************
1102 * SetGraphicsMode (GDI32.@)
1104 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1107 DC *dc = get_dc_ptr( hdc );
1109 /* One would think that setting the graphics mode to GM_COMPATIBLE
1110 * would also reset the world transformation matrix to the unity
1111 * matrix. However, in Windows, this is not the case. This doesn't
1112 * make a lot of sense to me, but that's the way it is.
1115 if ((mode > 0) && (mode <= GM_LAST))
1117 ret = dc->GraphicsMode;
1118 dc->GraphicsMode = mode;
1120 release_dc_ptr( dc );
1125 /***********************************************************************
1126 * GetArcDirection (GDI32.@)
1128 INT WINAPI GetArcDirection( HDC hdc )
1131 DC * dc = get_dc_ptr( hdc );
1134 ret = dc->ArcDirection;
1135 release_dc_ptr( dc );
1141 /***********************************************************************
1142 * SetArcDirection (GDI32.@)
1144 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1147 INT nOldDirection = 0;
1149 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1151 SetLastError(ERROR_INVALID_PARAMETER);
1155 if ((dc = get_dc_ptr( hdc )))
1157 if (dc->funcs->pSetArcDirection)
1159 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1161 nOldDirection = dc->ArcDirection;
1162 dc->ArcDirection = nDirection;
1163 release_dc_ptr( dc );
1165 return nOldDirection;
1169 /***********************************************************************
1170 * GetWorldTransform (GDI32.@)
1172 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1175 if (!xform) return FALSE;
1176 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1177 *xform = dc->xformWorld2Wnd;
1178 release_dc_ptr( dc );
1183 /***********************************************************************
1184 * GetTransform (GDI32.@)
1188 * Returns one of the co-ordinate space transforms
1191 * hdc [I] Device context.
1192 * which [I] Which xform to return:
1193 * 0x203 World -> Page transform (that set by SetWorldTransform).
1194 * 0x304 Page -> Device transform (the mapping mode transform).
1195 * 0x204 World -> Device transform (the combination of the above two).
1196 * 0x402 Device -> World transform (the inversion of the above).
1197 * xform [O] The xform.
1200 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1203 DC *dc = get_dc_ptr( hdc );
1204 if (!dc) return FALSE;
1209 *xform = dc->xformWorld2Wnd;
1213 construct_window_to_viewport(dc, xform);
1217 *xform = dc->xformWorld2Vport;
1221 *xform = dc->xformVport2World;
1225 FIXME("Unknown code %x\n", which);
1229 release_dc_ptr( dc );
1234 /***********************************************************************
1235 * SetWorldTransform (GDI32.@)
1237 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1242 if (!xform) return FALSE;
1244 dc = get_dc_ptr( hdc );
1245 if (!dc) return FALSE;
1247 /* Check that graphics mode is GM_ADVANCED */
1248 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1250 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1251 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1253 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1254 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) goto done;
1256 if (dc->funcs->pSetWorldTransform)
1258 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1259 if (!ret) goto done;
1262 dc->xformWorld2Wnd = *xform;
1263 DC_UpdateXforms( dc );
1266 release_dc_ptr( dc );
1271 /****************************************************************************
1272 * ModifyWorldTransform [GDI32.@]
1273 * Modifies the world transformation for a device context.
1276 * hdc [I] Handle to device context
1277 * xform [I] XFORM structure that will be used to modify the world
1279 * iMode [I] Specifies in what way to modify the world transformation
1282 * Resets the world transformation to the identity matrix.
1283 * The parameter xform is ignored.
1285 * Multiplies xform into the world transformation matrix from
1288 * Multiplies xform into the world transformation matrix from
1293 * Failure: FALSE. Use GetLastError() to determine the cause.
1295 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1299 DC *dc = get_dc_ptr( hdc );
1301 /* Check for illegal parameters */
1302 if (!dc) return FALSE;
1303 if (!xform && iMode != MWT_IDENTITY) goto done;
1305 /* Check that graphics mode is GM_ADVANCED */
1306 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1308 if (dc->funcs->pModifyWorldTransform)
1310 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1311 if (!ret) goto done;
1317 dc->xformWorld2Wnd.eM11 = 1.0f;
1318 dc->xformWorld2Wnd.eM12 = 0.0f;
1319 dc->xformWorld2Wnd.eM21 = 0.0f;
1320 dc->xformWorld2Wnd.eM22 = 1.0f;
1321 dc->xformWorld2Wnd.eDx = 0.0f;
1322 dc->xformWorld2Wnd.eDy = 0.0f;
1324 case MWT_LEFTMULTIPLY:
1325 CombineTransform( &dc->xformWorld2Wnd, xform,
1326 &dc->xformWorld2Wnd );
1328 case MWT_RIGHTMULTIPLY:
1329 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1336 DC_UpdateXforms( dc );
1339 release_dc_ptr( dc );
1344 /****************************************************************************
1345 * CombineTransform [GDI32.@]
1346 * Combines two transformation matrices.
1349 * xformResult [O] Stores the result of combining the two matrices
1350 * xform1 [I] Specifies the first matrix to apply
1351 * xform2 [I] Specifies the second matrix to apply
1354 * The same matrix can be passed in for more than one of the parameters.
1358 * Failure: FALSE. Use GetLastError() to determine the cause.
1360 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1361 const XFORM *xform2 )
1365 /* Check for illegal parameters */
1366 if (!xformResult || !xform1 || !xform2)
1369 /* Create the result in a temporary XFORM, since xformResult may be
1370 * equal to xform1 or xform2 */
1371 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1372 xform1->eM12 * xform2->eM21;
1373 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1374 xform1->eM12 * xform2->eM22;
1375 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1376 xform1->eM22 * xform2->eM21;
1377 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1378 xform1->eM22 * xform2->eM22;
1379 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1380 xform1->eDy * xform2->eM21 +
1382 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1383 xform1->eDy * xform2->eM22 +
1386 /* Copy the result to xformResult */
1387 *xformResult = xformTemp;
1393 /***********************************************************************
1394 * SetDCHook (GDI32.@)
1396 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1398 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1400 DC *dc = get_dc_ptr( hdc );
1402 if (!dc) return FALSE;
1404 if (!(dc->flags & DC_SAVED))
1406 dc->dwHookData = dwHookData;
1407 dc->hookProc = hookProc;
1409 release_dc_ptr( dc );
1414 /***********************************************************************
1415 * GetDCHook (GDI32.@)
1417 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1419 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1421 DC *dc = get_dc_ptr( hdc );
1425 if (proc) *proc = dc->hookProc;
1426 ret = dc->dwHookData;
1427 release_dc_ptr( dc );
1432 /***********************************************************************
1433 * SetHookFlags (GDI32.@)
1435 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1437 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1439 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1444 /* "Undocumented Windows" info is slightly confusing. */
1446 TRACE("hDC %p, flags %04x\n",hdc,flags);
1448 if (flags & DCHF_INVALIDATEVISRGN)
1449 ret = InterlockedExchange( &dc->dirty, 1 );
1450 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1451 ret = InterlockedExchange( &dc->dirty, 0 );
1453 GDI_ReleaseObj( hdc );
1457 /***********************************************************************
1458 * SetICMMode (GDI32.@)
1460 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1462 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1463 if (iEnableICM == ICM_OFF) return ICM_OFF;
1464 if (iEnableICM == ICM_ON) return 0;
1465 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1469 /***********************************************************************
1470 * GetDeviceGammaRamp (GDI32.@)
1472 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1475 DC *dc = get_dc_ptr( hDC );
1479 if (dc->funcs->pGetDeviceGammaRamp)
1480 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1481 release_dc_ptr( dc );
1486 /***********************************************************************
1487 * SetDeviceGammaRamp (GDI32.@)
1489 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1492 DC *dc = get_dc_ptr( hDC );
1496 if (dc->funcs->pSetDeviceGammaRamp)
1497 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1498 release_dc_ptr( dc );
1503 /***********************************************************************
1504 * GetColorSpace (GDI32.@)
1506 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1508 /*FIXME Need to to whatever GetColorSpace actually does */
1512 /***********************************************************************
1513 * CreateColorSpaceA (GDI32.@)
1515 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1521 /***********************************************************************
1522 * CreateColorSpaceW (GDI32.@)
1524 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1530 /***********************************************************************
1531 * DeleteColorSpace (GDI32.@)
1533 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1540 /***********************************************************************
1541 * SetColorSpace (GDI32.@)
1543 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1550 /***********************************************************************
1551 * GetBoundsRect (GDI32.@)
1553 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1556 DC *dc = get_dc_ptr( hdc );
1558 if ( !dc ) return 0;
1562 *rect = dc->BoundsRect;
1563 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1568 if (flags & DCB_RESET)
1570 dc->BoundsRect.left = 0;
1571 dc->BoundsRect.top = 0;
1572 dc->BoundsRect.right = 0;
1573 dc->BoundsRect.bottom = 0;
1574 dc->flags &= ~DC_BOUNDS_SET;
1576 release_dc_ptr( dc );
1581 /***********************************************************************
1582 * SetBoundsRect (GDI32.@)
1584 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1589 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1590 if (!(dc = get_dc_ptr( hdc ))) return 0;
1592 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1593 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1595 if (flags & DCB_RESET)
1597 dc->BoundsRect.left = 0;
1598 dc->BoundsRect.top = 0;
1599 dc->BoundsRect.right = 0;
1600 dc->BoundsRect.bottom = 0;
1601 dc->flags &= ~DC_BOUNDS_SET;
1604 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1606 if (dc->flags & DC_BOUNDS_SET)
1608 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1609 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1610 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1611 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1615 dc->BoundsRect = *rect;
1616 dc->flags |= DC_BOUNDS_SET;
1620 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1621 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1623 release_dc_ptr( dc );
1628 /***********************************************************************
1629 * GetRelAbs (GDI32.@)
1631 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1634 DC *dc = get_dc_ptr( hdc );
1637 ret = dc->relAbsMode;
1638 release_dc_ptr( dc );
1646 /***********************************************************************
1647 * GetBkMode (GDI32.@)
1649 INT WINAPI GetBkMode( HDC hdc )
1652 DC * dc = get_dc_ptr( hdc );
1655 ret = dc->backgroundMode;
1656 release_dc_ptr( dc );
1662 /***********************************************************************
1663 * SetBkMode (GDI32.@)
1665 INT WINAPI SetBkMode( HDC hdc, INT mode )
1669 if ((mode <= 0) || (mode > BKMODE_LAST))
1671 SetLastError(ERROR_INVALID_PARAMETER);
1674 if (!(dc = get_dc_ptr( hdc ))) return 0;
1676 ret = dc->backgroundMode;
1677 if (dc->funcs->pSetBkMode)
1678 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1681 dc->backgroundMode = mode;
1682 release_dc_ptr( dc );
1687 /***********************************************************************
1690 INT WINAPI GetROP2( HDC hdc )
1693 DC * dc = get_dc_ptr( hdc );
1697 release_dc_ptr( dc );
1703 /***********************************************************************
1706 INT WINAPI SetROP2( HDC hdc, INT mode )
1710 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1712 SetLastError(ERROR_INVALID_PARAMETER);
1715 if (!(dc = get_dc_ptr( hdc ))) return 0;
1717 if (dc->funcs->pSetROP2)
1718 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1722 release_dc_ptr( dc );
1727 /***********************************************************************
1728 * SetRelAbs (GDI32.@)
1730 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1734 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1736 SetLastError(ERROR_INVALID_PARAMETER);
1739 if (!(dc = get_dc_ptr( hdc ))) return 0;
1740 if (dc->funcs->pSetRelAbs)
1741 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1744 ret = dc->relAbsMode;
1745 dc->relAbsMode = mode;
1747 release_dc_ptr( dc );
1752 /***********************************************************************
1753 * GetPolyFillMode (GDI32.@)
1755 INT WINAPI GetPolyFillMode( HDC hdc )
1758 DC * dc = get_dc_ptr( hdc );
1761 ret = dc->polyFillMode;
1762 release_dc_ptr( dc );
1768 /***********************************************************************
1769 * SetPolyFillMode (GDI32.@)
1771 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1775 if ((mode <= 0) || (mode > POLYFILL_LAST))
1777 SetLastError(ERROR_INVALID_PARAMETER);
1780 if (!(dc = get_dc_ptr( hdc ))) return 0;
1781 ret = dc->polyFillMode;
1782 if (dc->funcs->pSetPolyFillMode)
1783 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1786 dc->polyFillMode = mode;
1787 release_dc_ptr( dc );
1792 /***********************************************************************
1793 * GetStretchBltMode (GDI32.@)
1795 INT WINAPI GetStretchBltMode( HDC hdc )
1798 DC * dc = get_dc_ptr( hdc );
1801 ret = dc->stretchBltMode;
1802 release_dc_ptr( dc );
1808 /***********************************************************************
1809 * SetStretchBltMode (GDI32.@)
1811 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1815 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1817 SetLastError(ERROR_INVALID_PARAMETER);
1820 if (!(dc = get_dc_ptr( hdc ))) return 0;
1821 ret = dc->stretchBltMode;
1822 if (dc->funcs->pSetStretchBltMode)
1823 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1826 dc->stretchBltMode = mode;
1827 release_dc_ptr( dc );
1832 /***********************************************************************
1833 * GetMapMode (GDI32.@)
1835 INT WINAPI GetMapMode( HDC hdc )
1838 DC * dc = get_dc_ptr( hdc );
1842 release_dc_ptr( dc );
1848 /***********************************************************************
1849 * GetBrushOrgEx (GDI32.@)
1851 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1853 DC * dc = get_dc_ptr( hdc );
1854 if (!dc) return FALSE;
1855 pt->x = dc->brushOrgX;
1856 pt->y = dc->brushOrgY;
1857 release_dc_ptr( dc );
1862 /***********************************************************************
1863 * GetCurrentPositionEx (GDI32.@)
1865 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1867 DC * dc = get_dc_ptr( hdc );
1868 if (!dc) return FALSE;
1869 pt->x = dc->CursPosX;
1870 pt->y = dc->CursPosY;
1871 release_dc_ptr( dc );
1876 /***********************************************************************
1877 * GetViewportExtEx (GDI32.@)
1879 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1881 DC * dc = get_dc_ptr( hdc );
1882 if (!dc) return FALSE;
1883 size->cx = dc->vportExtX;
1884 size->cy = dc->vportExtY;
1885 release_dc_ptr( dc );
1890 /***********************************************************************
1891 * GetViewportOrgEx (GDI32.@)
1893 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1895 DC * dc = get_dc_ptr( hdc );
1896 if (!dc) return FALSE;
1897 pt->x = dc->vportOrgX;
1898 pt->y = dc->vportOrgY;
1899 release_dc_ptr( dc );
1904 /***********************************************************************
1905 * GetWindowExtEx (GDI32.@)
1907 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1909 DC * dc = get_dc_ptr( hdc );
1910 if (!dc) return FALSE;
1911 size->cx = dc->wndExtX;
1912 size->cy = dc->wndExtY;
1913 release_dc_ptr( dc );
1918 /***********************************************************************
1919 * GetWindowOrgEx (GDI32.@)
1921 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1923 DC * dc = get_dc_ptr( hdc );
1924 if (!dc) return FALSE;
1925 pt->x = dc->wndOrgX;
1926 pt->y = dc->wndOrgY;
1927 release_dc_ptr( dc );
1932 /***********************************************************************
1933 * GetLayout (GDI32.@)
1935 * Gets left->right or right->left text layout flags of a dc.
1938 DWORD WINAPI GetLayout(HDC hdc)
1940 DWORD layout = GDI_ERROR;
1942 DC * dc = get_dc_ptr( hdc );
1945 layout = dc->layout;
1946 release_dc_ptr( dc );
1949 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1954 /***********************************************************************
1955 * SetLayout (GDI32.@)
1957 * Sets left->right or right->left text layout flags of a dc.
1960 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1962 DWORD oldlayout = GDI_ERROR;
1964 DC * dc = get_dc_ptr( hdc );
1967 oldlayout = dc->layout;
1968 dc->layout = layout;
1969 if (layout != oldlayout)
1971 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1972 DC_UpdateXforms( dc );
1974 release_dc_ptr( dc );
1977 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1982 /***********************************************************************
1983 * GetDCBrushColor (GDI32.@)
1985 * Retrieves the current brush color for the specified device
1989 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1992 COLORREF dcBrushColor = CLR_INVALID;
1994 TRACE("hdc(%p)\n", hdc);
1996 dc = get_dc_ptr( hdc );
1999 dcBrushColor = dc->dcBrushColor;
2000 release_dc_ptr( dc );
2003 return dcBrushColor;
2006 /***********************************************************************
2007 * SetDCBrushColor (GDI32.@)
2009 * Sets the current device context (DC) brush color to the specified
2010 * color value. If the device cannot represent the specified color
2011 * value, the color is set to the nearest physical color.
2014 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2017 COLORREF oldClr = CLR_INVALID;
2019 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2021 dc = get_dc_ptr( hdc );
2024 if (dc->funcs->pSetDCBrushColor)
2025 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2026 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2028 /* If DC_BRUSH is selected, update driver pen color */
2029 HBRUSH hBrush = CreateSolidBrush( crColor );
2030 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2031 DeleteObject( hBrush );
2034 if (crColor != CLR_INVALID)
2036 oldClr = dc->dcBrushColor;
2037 dc->dcBrushColor = crColor;
2040 release_dc_ptr( dc );
2046 /***********************************************************************
2047 * GetDCPenColor (GDI32.@)
2049 * Retrieves the current pen color for the specified device
2053 COLORREF WINAPI GetDCPenColor(HDC hdc)
2056 COLORREF dcPenColor = CLR_INVALID;
2058 TRACE("hdc(%p)\n", hdc);
2060 dc = get_dc_ptr( hdc );
2063 dcPenColor = dc->dcPenColor;
2064 release_dc_ptr( dc );
2070 /***********************************************************************
2071 * SetDCPenColor (GDI32.@)
2073 * Sets the current device context (DC) pen color to the specified
2074 * color value. If the device cannot represent the specified color
2075 * value, the color is set to the nearest physical color.
2078 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2081 COLORREF oldClr = CLR_INVALID;
2083 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2085 dc = get_dc_ptr( hdc );
2088 if (dc->funcs->pSetDCPenColor)
2089 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2090 else if (dc->hPen == GetStockObject( DC_PEN ))
2092 /* If DC_PEN is selected, update the driver pen color */
2093 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2094 HPEN hPen = CreatePenIndirect( &logpen );
2095 dc->funcs->pSelectPen( dc->physDev, hPen );
2096 DeleteObject( hPen );
2099 if (crColor != CLR_INVALID)
2101 oldClr = dc->dcPenColor;
2102 dc->dcPenColor = crColor;
2105 release_dc_ptr( dc );
2111 /***********************************************************************
2112 * CancelDC (GDI32.@)
2114 BOOL WINAPI CancelDC(HDC hdc)
2120 /*******************************************************************
2121 * GetMiterLimit [GDI32.@]
2125 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2130 TRACE("(%p,%p)\n", hdc, peLimit);
2132 dc = get_dc_ptr( hdc );
2136 *peLimit = dc->miterLimit;
2138 release_dc_ptr( dc );
2144 /*******************************************************************
2145 * SetMiterLimit [GDI32.@]
2149 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2154 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2156 dc = get_dc_ptr( hdc );
2160 *peOldLimit = dc->miterLimit;
2161 dc->miterLimit = eNewLimit;
2162 release_dc_ptr( dc );
2168 /*******************************************************************
2169 * GdiIsMetaPrintDC [GDI32.@]
2171 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2177 /*******************************************************************
2178 * GdiIsMetaFileDC [GDI32.@]
2180 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2184 switch( GetObjectType( hdc ) )
2193 /*******************************************************************
2194 * GdiIsPlayMetafileDC [GDI32.@]
2196 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)