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;
82 dc->thread = GetCurrentThreadId();
97 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
102 dc->hMetaClipRgn = 0;
104 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
105 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
106 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
109 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
111 dc->font_code_page = CP_ACP;
112 dc->ROPmode = R2_COPYPEN;
113 dc->polyFillMode = ALTERNATE;
114 dc->stretchBltMode = BLACKONWHITE;
115 dc->relAbsMode = ABSOLUTE;
116 dc->backgroundMode = OPAQUE;
117 dc->backgroundColor = RGB( 255, 255, 255 );
118 dc->dcBrushColor = RGB( 255, 255, 255 );
119 dc->dcPenColor = RGB( 0, 0, 0 );
120 dc->textColor = RGB( 0, 0, 0 );
123 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
127 dc->MapMode = MM_TEXT;
128 dc->GraphicsMode = GM_COMPATIBLE;
129 dc->pAbortProc = NULL;
132 dc->ArcDirection = AD_COUNTERCLOCKWISE;
133 dc->xformWorld2Wnd.eM11 = 1.0f;
134 dc->xformWorld2Wnd.eM12 = 0.0f;
135 dc->xformWorld2Wnd.eM21 = 0.0f;
136 dc->xformWorld2Wnd.eM22 = 1.0f;
137 dc->xformWorld2Wnd.eDx = 0.0f;
138 dc->xformWorld2Wnd.eDy = 0.0f;
139 dc->xformWorld2Vport = dc->xformWorld2Wnd;
140 dc->xformVport2World = dc->xformWorld2Wnd;
141 dc->vport2WorldValid = TRUE;
142 dc->BoundsRect.left = 0;
143 dc->BoundsRect.top = 0;
144 dc->BoundsRect.right = 0;
145 dc->BoundsRect.bottom = 0;
146 PATH_InitGdiPath(&dc->path);
148 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
150 HeapFree( GetProcessHeap(), 0, dc );
158 /***********************************************************************
161 BOOL free_dc_ptr( DC *dc )
163 assert( dc->refcount == 1 );
164 if (free_gdi_handle( dc->hSelf ) != dc) return FALSE; /* shouldn't happen */
165 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
166 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
167 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
168 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
169 PATH_DestroyGdiPath( &dc->path );
170 return HeapFree( GetProcessHeap(), 0, dc );
174 /***********************************************************************
177 * Retrieve a DC pointer but release the GDI lock.
179 DC *get_dc_ptr( HDC hdc )
181 DC *dc = get_dc_obj( hdc );
182 if (!dc) return NULL;
184 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
186 dc->thread = GetCurrentThreadId();
188 else if (dc->thread != GetCurrentThreadId())
190 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
191 GDI_ReleaseObj( hdc );
194 else InterlockedIncrement( &dc->refcount );
196 GDI_ReleaseObj( hdc );
201 /***********************************************************************
204 void release_dc_ptr( DC *dc )
209 ref = InterlockedDecrement( &dc->refcount );
211 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
215 /***********************************************************************
218 * Make sure the DC vis region is up to date.
219 * This function may call up to USER so the GDI lock should _not_
220 * be held when calling it.
222 void update_dc( DC *dc )
224 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
225 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
229 /***********************************************************************
232 static BOOL DC_DeleteObject( HGDIOBJ handle )
234 return DeleteDC( handle );
238 /***********************************************************************
241 * Setup device-specific DC values for a newly created DC.
243 void DC_InitDC( DC* dc )
245 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
246 SetTextColor( dc->hSelf, dc->textColor );
247 SetBkColor( dc->hSelf, dc->backgroundColor );
248 SelectObject( dc->hSelf, dc->hPen );
249 SelectObject( dc->hSelf, dc->hBrush );
250 SelectObject( dc->hSelf, dc->hFont );
251 CLIPPING_UpdateGCRegion( dc );
252 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
256 /***********************************************************************
259 * Computes the inverse of the transformation xformSrc and stores it to
260 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
263 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
267 determinant = xformSrc->eM11*xformSrc->eM22 -
268 xformSrc->eM12*xformSrc->eM21;
269 if (determinant > -1e-12 && determinant < 1e-12)
272 xformDest->eM11 = xformSrc->eM22 / determinant;
273 xformDest->eM12 = -xformSrc->eM12 / determinant;
274 xformDest->eM21 = -xformSrc->eM21 / determinant;
275 xformDest->eM22 = xformSrc->eM11 / determinant;
276 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
277 xformSrc->eDy * xformDest->eM21;
278 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
279 xformSrc->eDy * xformDest->eM22;
284 /* Construct a transformation to do the window-to-viewport conversion */
285 static void construct_window_to_viewport(DC *dc, XFORM *xform)
287 double scaleX, scaleY;
288 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
289 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
291 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
292 xform->eM11 = scaleX;
295 xform->eM22 = scaleY;
296 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
297 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
298 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
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;
407 if (!(newdc->hSelf = alloc_gdi_handle( &newdc->header, dc->header.type, &dc_funcs )))
409 HeapFree( GetProcessHeap(), 0, newdc );
410 release_dc_ptr( dc );
414 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
419 newdc->hMetaClipRgn = 0;
422 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
423 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
427 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
430 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
432 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
434 release_dc_ptr( dc );
435 free_dc_ptr( newdc );
439 newdc->saved_dc = dc->saved_dc;
440 dc->saved_dc = newdc->hSelf;
441 ret = ++dc->saveLevel;
442 release_dc_ptr( newdc );
443 release_dc_ptr( dc );
448 /***********************************************************************
451 BOOL restore_dc_state( HDC hdc, INT level )
457 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
459 /* find the state level to restore */
461 if (abs(level) > dc->saveLevel || level == 0)
463 release_dc_ptr( dc );
466 if (level < 0) level = dc->saveLevel + level + 1;
467 first_dcs = dc->saved_dc;
468 for (hdcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
470 if (!(dcs = get_dc_ptr( hdcs )))
472 release_dc_ptr( dc );
475 hdcs = dcs->saved_dc;
476 release_dc_ptr( dcs );
479 /* restore the state */
481 if (!(dcs = get_dc_ptr( hdcs )))
483 release_dc_ptr( dc );
486 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
488 release_dc_ptr( dcs );
489 release_dc_ptr( dc );
493 dc->flags = dcs->flags & ~DC_SAVED;
494 dc->layout = dcs->layout;
495 dc->hDevice = dcs->hDevice;
496 dc->ROPmode = dcs->ROPmode;
497 dc->polyFillMode = dcs->polyFillMode;
498 dc->stretchBltMode = dcs->stretchBltMode;
499 dc->relAbsMode = dcs->relAbsMode;
500 dc->backgroundMode = dcs->backgroundMode;
501 dc->backgroundColor = dcs->backgroundColor;
502 dc->textColor = dcs->textColor;
503 dc->dcBrushColor = dcs->dcBrushColor;
504 dc->dcPenColor = dcs->dcPenColor;
505 dc->brushOrgX = dcs->brushOrgX;
506 dc->brushOrgY = dcs->brushOrgY;
507 dc->textAlign = dcs->textAlign;
508 dc->charExtra = dcs->charExtra;
509 dc->breakExtra = dcs->breakExtra;
510 dc->breakRem = dcs->breakRem;
511 dc->MapMode = dcs->MapMode;
512 dc->GraphicsMode = dcs->GraphicsMode;
513 dc->CursPosX = dcs->CursPosX;
514 dc->CursPosY = dcs->CursPosY;
515 dc->ArcDirection = dcs->ArcDirection;
516 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
517 dc->xformWorld2Vport = dcs->xformWorld2Vport;
518 dc->xformVport2World = dcs->xformVport2World;
519 dc->vport2WorldValid = dcs->vport2WorldValid;
520 dc->BoundsRect = dcs->BoundsRect;
522 dc->wndOrgX = dcs->wndOrgX;
523 dc->wndOrgY = dcs->wndOrgY;
524 dc->wndExtX = dcs->wndExtX;
525 dc->wndExtY = dcs->wndExtY;
526 dc->vportOrgX = dcs->vportOrgX;
527 dc->vportOrgY = dcs->vportOrgY;
528 dc->vportExtX = dcs->vportExtX;
529 dc->vportExtY = dcs->vportExtY;
530 dc->virtual_res = dcs->virtual_res;
531 dc->virtual_size = dcs->virtual_size;
535 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
536 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
540 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
545 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
546 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
550 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
553 DC_UpdateXforms( dc );
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 dc->vis_rect.left = 0;
671 dc->vis_rect.top = 0;
672 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
673 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
674 SetRectRgn(dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top, dc->vis_rect.right, dc->vis_rect.bottom);
677 release_dc_ptr( dc );
681 if (dc) free_dc_ptr( dc );
686 /***********************************************************************
687 * CreateDCA (GDI32.@)
689 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
690 const DEVMODEA *initData )
692 UNICODE_STRING driverW, deviceW, outputW;
696 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
697 else driverW.Buffer = NULL;
699 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
700 else deviceW.Buffer = NULL;
702 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
703 else outputW.Buffer = NULL;
708 /* don't convert initData for DISPLAY driver, it's not used */
709 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
710 initDataW = GdiConvertToDevmodeW(initData);
713 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
715 RtlFreeUnicodeString(&driverW);
716 RtlFreeUnicodeString(&deviceW);
717 RtlFreeUnicodeString(&outputW);
718 HeapFree(GetProcessHeap(), 0, initDataW);
723 /***********************************************************************
724 * CreateICA (GDI32.@)
726 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
727 const DEVMODEA* initData )
729 /* Nothing special yet for ICs */
730 return CreateDCA( driver, device, output, initData );
734 /***********************************************************************
735 * CreateICW (GDI32.@)
737 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
738 const DEVMODEW* initData )
740 /* Nothing special yet for ICs */
741 return CreateDCW( driver, device, output, initData );
745 /***********************************************************************
746 * CreateCompatibleDC (GDI32.@)
748 HDC WINAPI CreateCompatibleDC( HDC hdc )
752 const DC_FUNCTIONS *funcs = NULL;
753 PHYSDEV physDev = NULL;
759 if (!(origDC = get_dc_ptr( hdc ))) return 0;
760 if (GetObjectType( hdc ) == OBJ_DC)
762 funcs = origDC->funcs;
763 physDev = origDC->physDev;
765 release_dc_ptr( origDC );
768 if (!funcs && !(funcs = DRIVER_get_display_driver())) return 0;
770 if (!(dc = alloc_dc_ptr( funcs, OBJ_MEMDC ))) goto error;
772 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
774 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
775 dc->vis_rect.left = 0;
776 dc->vis_rect.top = 0;
777 dc->vis_rect.right = 1;
778 dc->vis_rect.bottom = 1;
779 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
781 /* Copy the driver-specific physical device info into
782 * the new DC. The driver may use this read-only info
783 * while creating the compatible DC below. */
784 dc->physDev = physDev;
787 if (dc->funcs->pCreateDC &&
788 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
790 WARN("creation aborted by device\n");
795 release_dc_ptr( dc );
799 if (dc) free_dc_ptr( dc );
804 /***********************************************************************
807 BOOL WINAPI DeleteDC( HDC hdc )
815 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
816 if (dc->refcount != 1)
818 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
819 release_dc_ptr( dc );
823 /* Call hook procedure to check whether is it OK to delete this DC */
824 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
826 release_dc_ptr( dc );
830 while (dc->saveLevel)
833 HDC hdcs = dc->saved_dc;
834 if (!(dcs = get_dc_ptr( hdcs ))) break;
835 dc->saved_dc = dcs->saved_dc;
840 if (!(dc->flags & DC_SAVED))
842 SelectObject( hdc, GetStockObject(BLACK_PEN) );
843 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
844 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
845 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
846 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
855 /***********************************************************************
858 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
863 if ((dc = get_dc_ptr( hdc )))
865 if (dc->funcs->pResetDC)
867 ret = dc->funcs->pResetDC( dc->physDev, devmode );
868 if (ret) /* reset the visible region */
871 dc->vis_rect.left = 0;
872 dc->vis_rect.top = 0;
873 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
874 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
875 SetRectRgn( dc->hVisRgn, dc->vis_rect.left, dc->vis_rect.top,
876 dc->vis_rect.right, dc->vis_rect.bottom );
877 CLIPPING_UpdateGCRegion( dc );
880 release_dc_ptr( dc );
886 /***********************************************************************
889 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
894 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
895 else devmodeW = NULL;
897 ret = ResetDCW(hdc, devmodeW);
899 HeapFree(GetProcessHeap(), 0, devmodeW);
904 /***********************************************************************
905 * GetDeviceCaps (GDI32.@)
907 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
912 if ((dc = get_dc_ptr( hdc )))
914 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
915 else switch(cap) /* return meaningful values for some entries */
917 case HORZRES: ret = 640; break;
918 case VERTRES: ret = 480; break;
919 case BITSPIXEL: ret = 1; break;
920 case PLANES: ret = 1; break;
921 case NUMCOLORS: ret = 2; break;
922 case ASPECTX: ret = 36; break;
923 case ASPECTY: ret = 36; break;
924 case ASPECTXY: ret = 51; break;
925 case LOGPIXELSX: ret = 72; break;
926 case LOGPIXELSY: ret = 72; break;
927 case SIZEPALETTE: ret = 2; break;
929 ret = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
930 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
931 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
934 release_dc_ptr( dc );
940 /***********************************************************************
941 * GetBkColor (GDI32.@)
943 COLORREF WINAPI GetBkColor( HDC hdc )
946 DC * dc = get_dc_ptr( hdc );
949 ret = dc->backgroundColor;
950 release_dc_ptr( dc );
956 /***********************************************************************
957 * SetBkColor (GDI32.@)
959 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
962 DC * dc = get_dc_ptr( hdc );
964 TRACE("hdc=%p color=0x%08x\n", hdc, color);
966 if (!dc) return CLR_INVALID;
967 oldColor = dc->backgroundColor;
968 if (dc->funcs->pSetBkColor)
970 color = dc->funcs->pSetBkColor(dc->physDev, color);
971 if (color == CLR_INVALID) /* don't change it */
974 oldColor = CLR_INVALID;
977 dc->backgroundColor = color;
978 release_dc_ptr( dc );
983 /***********************************************************************
984 * GetTextColor (GDI32.@)
986 COLORREF WINAPI GetTextColor( HDC hdc )
989 DC * dc = get_dc_ptr( hdc );
993 release_dc_ptr( dc );
999 /***********************************************************************
1000 * SetTextColor (GDI32.@)
1002 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
1005 DC * dc = get_dc_ptr( hdc );
1007 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
1009 if (!dc) return CLR_INVALID;
1010 oldColor = dc->textColor;
1011 if (dc->funcs->pSetTextColor)
1013 color = dc->funcs->pSetTextColor(dc->physDev, color);
1014 if (color == CLR_INVALID) /* don't change it */
1017 oldColor = CLR_INVALID;
1020 dc->textColor = color;
1021 release_dc_ptr( dc );
1026 /***********************************************************************
1027 * GetTextAlign (GDI32.@)
1029 UINT WINAPI GetTextAlign( HDC hdc )
1032 DC * dc = get_dc_ptr( hdc );
1035 ret = dc->textAlign;
1036 release_dc_ptr( dc );
1042 /***********************************************************************
1043 * SetTextAlign (GDI32.@)
1045 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1048 DC *dc = get_dc_ptr( hdc );
1050 TRACE("hdc=%p align=%d\n", hdc, align);
1052 if (!dc) return 0x0;
1053 ret = dc->textAlign;
1054 if (dc->funcs->pSetTextAlign)
1055 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1057 if (ret != GDI_ERROR)
1058 dc->textAlign = align;
1059 release_dc_ptr( dc );
1063 /***********************************************************************
1064 * GetDCOrgEx (GDI32.@)
1066 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1070 if (!lpp) return FALSE;
1071 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1072 lpp->x = dc->vis_rect.left;
1073 lpp->y = dc->vis_rect.top;
1074 release_dc_ptr( dc );
1079 /***********************************************************************
1080 * GetGraphicsMode (GDI32.@)
1082 INT WINAPI GetGraphicsMode( HDC hdc )
1085 DC * dc = get_dc_ptr( hdc );
1088 ret = dc->GraphicsMode;
1089 release_dc_ptr( dc );
1095 /***********************************************************************
1096 * SetGraphicsMode (GDI32.@)
1098 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1101 DC *dc = get_dc_ptr( hdc );
1103 /* One would think that setting the graphics mode to GM_COMPATIBLE
1104 * would also reset the world transformation matrix to the unity
1105 * matrix. However, in Windows, this is not the case. This doesn't
1106 * make a lot of sense to me, but that's the way it is.
1109 if ((mode > 0) && (mode <= GM_LAST))
1111 ret = dc->GraphicsMode;
1112 dc->GraphicsMode = mode;
1114 release_dc_ptr( dc );
1119 /***********************************************************************
1120 * GetArcDirection (GDI32.@)
1122 INT WINAPI GetArcDirection( HDC hdc )
1125 DC * dc = get_dc_ptr( hdc );
1128 ret = dc->ArcDirection;
1129 release_dc_ptr( dc );
1135 /***********************************************************************
1136 * SetArcDirection (GDI32.@)
1138 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1141 INT nOldDirection = 0;
1143 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1145 SetLastError(ERROR_INVALID_PARAMETER);
1149 if ((dc = get_dc_ptr( hdc )))
1151 if (dc->funcs->pSetArcDirection)
1153 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1155 nOldDirection = dc->ArcDirection;
1156 dc->ArcDirection = nDirection;
1157 release_dc_ptr( dc );
1159 return nOldDirection;
1163 /***********************************************************************
1164 * GetWorldTransform (GDI32.@)
1166 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1169 if (!xform) return FALSE;
1170 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1171 *xform = dc->xformWorld2Wnd;
1172 release_dc_ptr( dc );
1177 /***********************************************************************
1178 * GetTransform (GDI32.@)
1182 * Returns one of the co-ordinate space transforms
1185 * hdc [I] Device context.
1186 * which [I] Which xform to return:
1187 * 0x203 World -> Page transform (that set by SetWorldTransform).
1188 * 0x304 Page -> Device transform (the mapping mode transform).
1189 * 0x204 World -> Device transform (the combination of the above two).
1190 * 0x402 Device -> World transform (the inversion of the above).
1191 * xform [O] The xform.
1194 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1197 DC *dc = get_dc_ptr( hdc );
1198 if (!dc) return FALSE;
1203 *xform = dc->xformWorld2Wnd;
1207 construct_window_to_viewport(dc, xform);
1211 *xform = dc->xformWorld2Vport;
1215 *xform = dc->xformVport2World;
1219 FIXME("Unknown code %x\n", which);
1223 release_dc_ptr( dc );
1228 /***********************************************************************
1229 * SetWorldTransform (GDI32.@)
1231 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1236 if (!xform) return FALSE;
1238 dc = get_dc_ptr( hdc );
1239 if (!dc) return FALSE;
1241 /* Check that graphics mode is GM_ADVANCED */
1242 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1244 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1245 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1247 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1248 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) goto done;
1250 if (dc->funcs->pSetWorldTransform)
1252 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1253 if (!ret) goto done;
1256 dc->xformWorld2Wnd = *xform;
1257 DC_UpdateXforms( dc );
1260 release_dc_ptr( dc );
1265 /****************************************************************************
1266 * ModifyWorldTransform [GDI32.@]
1267 * Modifies the world transformation for a device context.
1270 * hdc [I] Handle to device context
1271 * xform [I] XFORM structure that will be used to modify the world
1273 * iMode [I] Specifies in what way to modify the world transformation
1276 * Resets the world transformation to the identity matrix.
1277 * The parameter xform is ignored.
1279 * Multiplies xform into the world transformation matrix from
1282 * Multiplies xform into the world transformation matrix from
1287 * Failure: FALSE. Use GetLastError() to determine the cause.
1289 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1293 DC *dc = get_dc_ptr( hdc );
1295 /* Check for illegal parameters */
1296 if (!dc) return FALSE;
1297 if (!xform && iMode != MWT_IDENTITY) goto done;
1299 /* Check that graphics mode is GM_ADVANCED */
1300 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1302 if (dc->funcs->pModifyWorldTransform)
1304 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1305 if (!ret) goto done;
1311 dc->xformWorld2Wnd.eM11 = 1.0f;
1312 dc->xformWorld2Wnd.eM12 = 0.0f;
1313 dc->xformWorld2Wnd.eM21 = 0.0f;
1314 dc->xformWorld2Wnd.eM22 = 1.0f;
1315 dc->xformWorld2Wnd.eDx = 0.0f;
1316 dc->xformWorld2Wnd.eDy = 0.0f;
1318 case MWT_LEFTMULTIPLY:
1319 CombineTransform( &dc->xformWorld2Wnd, xform,
1320 &dc->xformWorld2Wnd );
1322 case MWT_RIGHTMULTIPLY:
1323 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1330 DC_UpdateXforms( dc );
1333 release_dc_ptr( dc );
1338 /****************************************************************************
1339 * CombineTransform [GDI32.@]
1340 * Combines two transformation matrices.
1343 * xformResult [O] Stores the result of combining the two matrices
1344 * xform1 [I] Specifies the first matrix to apply
1345 * xform2 [I] Specifies the second matrix to apply
1348 * The same matrix can be passed in for more than one of the parameters.
1352 * Failure: FALSE. Use GetLastError() to determine the cause.
1354 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1355 const XFORM *xform2 )
1359 /* Check for illegal parameters */
1360 if (!xformResult || !xform1 || !xform2)
1363 /* Create the result in a temporary XFORM, since xformResult may be
1364 * equal to xform1 or xform2 */
1365 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1366 xform1->eM12 * xform2->eM21;
1367 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1368 xform1->eM12 * xform2->eM22;
1369 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1370 xform1->eM22 * xform2->eM21;
1371 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1372 xform1->eM22 * xform2->eM22;
1373 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1374 xform1->eDy * xform2->eM21 +
1376 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1377 xform1->eDy * xform2->eM22 +
1380 /* Copy the result to xformResult */
1381 *xformResult = xformTemp;
1387 /***********************************************************************
1388 * SetDCHook (GDI32.@)
1390 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1392 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1394 DC *dc = get_dc_ptr( hdc );
1396 if (!dc) return FALSE;
1398 if (!(dc->flags & DC_SAVED))
1400 dc->dwHookData = dwHookData;
1401 dc->hookProc = hookProc;
1403 release_dc_ptr( dc );
1408 /***********************************************************************
1409 * GetDCHook (GDI32.@)
1411 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1413 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1415 DC *dc = get_dc_ptr( hdc );
1419 if (proc) *proc = dc->hookProc;
1420 ret = dc->dwHookData;
1421 release_dc_ptr( dc );
1426 /***********************************************************************
1427 * SetHookFlags (GDI32.@)
1429 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1431 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1433 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1438 /* "Undocumented Windows" info is slightly confusing. */
1440 TRACE("hDC %p, flags %04x\n",hdc,flags);
1442 if (flags & DCHF_INVALIDATEVISRGN)
1443 ret = InterlockedExchange( &dc->dirty, 1 );
1444 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1445 ret = InterlockedExchange( &dc->dirty, 0 );
1447 GDI_ReleaseObj( hdc );
1451 /***********************************************************************
1452 * SetICMMode (GDI32.@)
1454 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1456 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1457 if (iEnableICM == ICM_OFF) return ICM_OFF;
1458 if (iEnableICM == ICM_ON) return 0;
1459 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1463 /***********************************************************************
1464 * GetDeviceGammaRamp (GDI32.@)
1466 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1469 DC *dc = get_dc_ptr( hDC );
1473 if (dc->funcs->pGetDeviceGammaRamp)
1474 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1475 release_dc_ptr( dc );
1480 /***********************************************************************
1481 * SetDeviceGammaRamp (GDI32.@)
1483 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1486 DC *dc = get_dc_ptr( hDC );
1490 if (dc->funcs->pSetDeviceGammaRamp)
1491 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1492 release_dc_ptr( dc );
1497 /***********************************************************************
1498 * GetColorSpace (GDI32.@)
1500 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1502 /*FIXME Need to to whatever GetColorSpace actually does */
1506 /***********************************************************************
1507 * CreateColorSpaceA (GDI32.@)
1509 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1515 /***********************************************************************
1516 * CreateColorSpaceW (GDI32.@)
1518 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1524 /***********************************************************************
1525 * DeleteColorSpace (GDI32.@)
1527 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1534 /***********************************************************************
1535 * SetColorSpace (GDI32.@)
1537 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1544 /***********************************************************************
1545 * GetBoundsRect (GDI32.@)
1547 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1550 DC *dc = get_dc_ptr( hdc );
1552 if ( !dc ) return 0;
1556 *rect = dc->BoundsRect;
1557 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1562 if (flags & DCB_RESET)
1564 dc->BoundsRect.left = 0;
1565 dc->BoundsRect.top = 0;
1566 dc->BoundsRect.right = 0;
1567 dc->BoundsRect.bottom = 0;
1568 dc->flags &= ~DC_BOUNDS_SET;
1570 release_dc_ptr( dc );
1575 /***********************************************************************
1576 * SetBoundsRect (GDI32.@)
1578 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1583 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1584 if (!(dc = get_dc_ptr( hdc ))) return 0;
1586 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1587 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1589 if (flags & DCB_RESET)
1591 dc->BoundsRect.left = 0;
1592 dc->BoundsRect.top = 0;
1593 dc->BoundsRect.right = 0;
1594 dc->BoundsRect.bottom = 0;
1595 dc->flags &= ~DC_BOUNDS_SET;
1598 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1600 if (dc->flags & DC_BOUNDS_SET)
1602 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1603 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1604 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1605 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1609 dc->BoundsRect = *rect;
1610 dc->flags |= DC_BOUNDS_SET;
1614 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1615 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1617 release_dc_ptr( dc );
1622 /***********************************************************************
1623 * GetRelAbs (GDI32.@)
1625 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1628 DC *dc = get_dc_ptr( hdc );
1631 ret = dc->relAbsMode;
1632 release_dc_ptr( dc );
1640 /***********************************************************************
1641 * GetBkMode (GDI32.@)
1643 INT WINAPI GetBkMode( HDC hdc )
1646 DC * dc = get_dc_ptr( hdc );
1649 ret = dc->backgroundMode;
1650 release_dc_ptr( dc );
1656 /***********************************************************************
1657 * SetBkMode (GDI32.@)
1659 INT WINAPI SetBkMode( HDC hdc, INT mode )
1663 if ((mode <= 0) || (mode > BKMODE_LAST))
1665 SetLastError(ERROR_INVALID_PARAMETER);
1668 if (!(dc = get_dc_ptr( hdc ))) return 0;
1670 ret = dc->backgroundMode;
1671 if (dc->funcs->pSetBkMode)
1672 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1675 dc->backgroundMode = mode;
1676 release_dc_ptr( dc );
1681 /***********************************************************************
1684 INT WINAPI GetROP2( HDC hdc )
1687 DC * dc = get_dc_ptr( hdc );
1691 release_dc_ptr( dc );
1697 /***********************************************************************
1700 INT WINAPI SetROP2( HDC hdc, INT mode )
1704 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1706 SetLastError(ERROR_INVALID_PARAMETER);
1709 if (!(dc = get_dc_ptr( hdc ))) return 0;
1711 if (dc->funcs->pSetROP2)
1712 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1716 release_dc_ptr( dc );
1721 /***********************************************************************
1722 * SetRelAbs (GDI32.@)
1724 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1728 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1730 SetLastError(ERROR_INVALID_PARAMETER);
1733 if (!(dc = get_dc_ptr( hdc ))) return 0;
1734 if (dc->funcs->pSetRelAbs)
1735 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1738 ret = dc->relAbsMode;
1739 dc->relAbsMode = mode;
1741 release_dc_ptr( dc );
1746 /***********************************************************************
1747 * GetPolyFillMode (GDI32.@)
1749 INT WINAPI GetPolyFillMode( HDC hdc )
1752 DC * dc = get_dc_ptr( hdc );
1755 ret = dc->polyFillMode;
1756 release_dc_ptr( dc );
1762 /***********************************************************************
1763 * SetPolyFillMode (GDI32.@)
1765 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1769 if ((mode <= 0) || (mode > POLYFILL_LAST))
1771 SetLastError(ERROR_INVALID_PARAMETER);
1774 if (!(dc = get_dc_ptr( hdc ))) return 0;
1775 ret = dc->polyFillMode;
1776 if (dc->funcs->pSetPolyFillMode)
1777 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1780 dc->polyFillMode = mode;
1781 release_dc_ptr( dc );
1786 /***********************************************************************
1787 * GetStretchBltMode (GDI32.@)
1789 INT WINAPI GetStretchBltMode( HDC hdc )
1792 DC * dc = get_dc_ptr( hdc );
1795 ret = dc->stretchBltMode;
1796 release_dc_ptr( dc );
1802 /***********************************************************************
1803 * SetStretchBltMode (GDI32.@)
1805 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1809 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1811 SetLastError(ERROR_INVALID_PARAMETER);
1814 if (!(dc = get_dc_ptr( hdc ))) return 0;
1815 ret = dc->stretchBltMode;
1816 if (dc->funcs->pSetStretchBltMode)
1817 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1820 dc->stretchBltMode = mode;
1821 release_dc_ptr( dc );
1826 /***********************************************************************
1827 * GetMapMode (GDI32.@)
1829 INT WINAPI GetMapMode( HDC hdc )
1832 DC * dc = get_dc_ptr( hdc );
1836 release_dc_ptr( dc );
1842 /***********************************************************************
1843 * GetBrushOrgEx (GDI32.@)
1845 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1847 DC * dc = get_dc_ptr( hdc );
1848 if (!dc) return FALSE;
1849 pt->x = dc->brushOrgX;
1850 pt->y = dc->brushOrgY;
1851 release_dc_ptr( dc );
1856 /***********************************************************************
1857 * GetCurrentPositionEx (GDI32.@)
1859 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1861 DC * dc = get_dc_ptr( hdc );
1862 if (!dc) return FALSE;
1863 pt->x = dc->CursPosX;
1864 pt->y = dc->CursPosY;
1865 release_dc_ptr( dc );
1870 /***********************************************************************
1871 * GetViewportExtEx (GDI32.@)
1873 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1875 DC * dc = get_dc_ptr( hdc );
1876 if (!dc) return FALSE;
1877 size->cx = dc->vportExtX;
1878 size->cy = dc->vportExtY;
1879 release_dc_ptr( dc );
1884 /***********************************************************************
1885 * GetViewportOrgEx (GDI32.@)
1887 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1889 DC * dc = get_dc_ptr( hdc );
1890 if (!dc) return FALSE;
1891 pt->x = dc->vportOrgX;
1892 pt->y = dc->vportOrgY;
1893 release_dc_ptr( dc );
1898 /***********************************************************************
1899 * GetWindowExtEx (GDI32.@)
1901 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1903 DC * dc = get_dc_ptr( hdc );
1904 if (!dc) return FALSE;
1905 size->cx = dc->wndExtX;
1906 size->cy = dc->wndExtY;
1907 release_dc_ptr( dc );
1912 /***********************************************************************
1913 * GetWindowOrgEx (GDI32.@)
1915 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1917 DC * dc = get_dc_ptr( hdc );
1918 if (!dc) return FALSE;
1919 pt->x = dc->wndOrgX;
1920 pt->y = dc->wndOrgY;
1921 release_dc_ptr( dc );
1926 /***********************************************************************
1927 * GetLayout (GDI32.@)
1929 * Gets left->right or right->left text layout flags of a dc.
1932 DWORD WINAPI GetLayout(HDC hdc)
1934 DWORD layout = GDI_ERROR;
1936 DC * dc = get_dc_ptr( hdc );
1939 layout = dc->layout;
1940 release_dc_ptr( dc );
1943 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1948 /***********************************************************************
1949 * SetLayout (GDI32.@)
1951 * Sets left->right or right->left text layout flags of a dc.
1954 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1956 DWORD oldlayout = GDI_ERROR;
1958 DC * dc = get_dc_ptr( hdc );
1961 oldlayout = dc->layout;
1962 dc->layout = layout;
1963 if (layout != oldlayout)
1965 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1966 DC_UpdateXforms( dc );
1968 release_dc_ptr( dc );
1971 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1976 /***********************************************************************
1977 * GetDCBrushColor (GDI32.@)
1979 * Retrieves the current brush color for the specified device
1983 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1986 COLORREF dcBrushColor = CLR_INVALID;
1988 TRACE("hdc(%p)\n", hdc);
1990 dc = get_dc_ptr( hdc );
1993 dcBrushColor = dc->dcBrushColor;
1994 release_dc_ptr( dc );
1997 return dcBrushColor;
2000 /***********************************************************************
2001 * SetDCBrushColor (GDI32.@)
2003 * Sets the current device context (DC) brush color to the specified
2004 * color value. If the device cannot represent the specified color
2005 * value, the color is set to the nearest physical color.
2008 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2011 COLORREF oldClr = CLR_INVALID;
2013 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2015 dc = get_dc_ptr( hdc );
2018 if (dc->funcs->pSetDCBrushColor)
2019 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2020 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2022 /* If DC_BRUSH is selected, update driver pen color */
2023 HBRUSH hBrush = CreateSolidBrush( crColor );
2024 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2025 DeleteObject( hBrush );
2028 if (crColor != CLR_INVALID)
2030 oldClr = dc->dcBrushColor;
2031 dc->dcBrushColor = crColor;
2034 release_dc_ptr( dc );
2040 /***********************************************************************
2041 * GetDCPenColor (GDI32.@)
2043 * Retrieves the current pen color for the specified device
2047 COLORREF WINAPI GetDCPenColor(HDC hdc)
2050 COLORREF dcPenColor = CLR_INVALID;
2052 TRACE("hdc(%p)\n", hdc);
2054 dc = get_dc_ptr( hdc );
2057 dcPenColor = dc->dcPenColor;
2058 release_dc_ptr( dc );
2064 /***********************************************************************
2065 * SetDCPenColor (GDI32.@)
2067 * Sets the current device context (DC) pen color to the specified
2068 * color value. If the device cannot represent the specified color
2069 * value, the color is set to the nearest physical color.
2072 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2075 COLORREF oldClr = CLR_INVALID;
2077 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2079 dc = get_dc_ptr( hdc );
2082 if (dc->funcs->pSetDCPenColor)
2083 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2084 else if (dc->hPen == GetStockObject( DC_PEN ))
2086 /* If DC_PEN is selected, update the driver pen color */
2087 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2088 HPEN hPen = CreatePenIndirect( &logpen );
2089 dc->funcs->pSelectPen( dc->physDev, hPen );
2090 DeleteObject( hPen );
2093 if (crColor != CLR_INVALID)
2095 oldClr = dc->dcPenColor;
2096 dc->dcPenColor = crColor;
2099 release_dc_ptr( dc );
2105 /***********************************************************************
2106 * CancelDC (GDI32.@)
2108 BOOL WINAPI CancelDC(HDC hdc)
2114 /*******************************************************************
2115 * GetMiterLimit [GDI32.@]
2119 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2124 TRACE("(%p,%p)\n", hdc, peLimit);
2126 dc = get_dc_ptr( hdc );
2130 *peLimit = dc->miterLimit;
2132 release_dc_ptr( dc );
2138 /*******************************************************************
2139 * SetMiterLimit [GDI32.@]
2143 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2148 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2150 dc = get_dc_ptr( hdc );
2154 *peOldLimit = dc->miterLimit;
2155 dc->miterLimit = eNewLimit;
2156 release_dc_ptr( dc );
2162 /*******************************************************************
2163 * GdiIsMetaPrintDC [GDI32.@]
2165 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2171 /*******************************************************************
2172 * GdiIsMetaFileDC [GDI32.@]
2174 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2178 switch( GetObjectType( hdc ) )
2187 /*******************************************************************
2188 * GdiIsPlayMetafileDC [GDI32.@]
2190 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)