oleaut32: When marshalling VT_CARRAY, only marshall by reference for appropriate...
[wine/multimedia.git] / dlls / gdi32 / dc.c
blobe4f31814099c4c122c8f9c8507dd0aff819466f3
1 /*
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
21 #include "config.h"
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "winerror.h"
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 );
56 if (!dc) return NULL;
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 );
65 dc = NULL;
67 return dc;
71 /***********************************************************************
72 * alloc_dc_ptr
74 DC *alloc_dc_ptr( WORD magic )
76 DC *dc;
78 if (!(dc = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dc) ))) return NULL;
80 dc->nulldrv.funcs = &null_driver;
81 dc->physDev = &dc->nulldrv;
82 dc->thread = GetCurrentThreadId();
83 dc->refcount = 1;
84 dc->wndExtX = 1;
85 dc->wndExtY = 1;
86 dc->vportExtX = 1;
87 dc->vportExtY = 1;
88 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
89 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
90 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
91 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
92 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
93 dc->font_code_page = CP_ACP;
94 dc->ROPmode = R2_COPYPEN;
95 dc->polyFillMode = ALTERNATE;
96 dc->stretchBltMode = BLACKONWHITE;
97 dc->relAbsMode = ABSOLUTE;
98 dc->backgroundMode = OPAQUE;
99 dc->backgroundColor = RGB( 255, 255, 255 );
100 dc->dcBrushColor = RGB( 255, 255, 255 );
101 dc->dcPenColor = RGB( 0, 0, 0 );
102 dc->textColor = RGB( 0, 0, 0 );
103 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
104 dc->MapMode = MM_TEXT;
105 dc->GraphicsMode = GM_COMPATIBLE;
106 dc->ArcDirection = AD_COUNTERCLOCKWISE;
107 dc->xformWorld2Wnd.eM11 = 1.0f;
108 dc->xformWorld2Wnd.eM12 = 0.0f;
109 dc->xformWorld2Wnd.eM21 = 0.0f;
110 dc->xformWorld2Wnd.eM22 = 1.0f;
111 dc->xformWorld2Wnd.eDx = 0.0f;
112 dc->xformWorld2Wnd.eDy = 0.0f;
113 dc->xformWorld2Vport = dc->xformWorld2Wnd;
114 dc->xformVport2World = dc->xformWorld2Wnd;
115 dc->vport2WorldValid = TRUE;
117 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
119 HeapFree( GetProcessHeap(), 0, dc );
120 return NULL;
122 dc->nulldrv.hdc = dc->hSelf;
124 if (font_driver && !font_driver->pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL ))
126 free_dc_ptr( dc );
127 return NULL;
129 return dc;
134 /***********************************************************************
135 * free_dc_state
137 static void free_dc_state( DC *dc )
139 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
140 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
141 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
142 if (dc->region) DeleteObject( dc->region );
143 if (dc->path) free_gdi_path( dc->path );
144 HeapFree( GetProcessHeap(), 0, dc );
148 /***********************************************************************
149 * free_dc_ptr
151 void free_dc_ptr( DC *dc )
153 assert( dc->refcount == 1 );
155 while (dc->physDev != &dc->nulldrv)
157 PHYSDEV physdev = pop_dc_driver( &dc->physDev );
158 physdev->funcs->pDeleteDC( physdev );
159 if (physdev == dc->dibdrv) dc->dibdrv = NULL;
161 if (dc->dibdrv) dc->dibdrv->funcs->pDeleteDC( dc->dibdrv );
162 free_gdi_handle( dc->hSelf );
163 free_dc_state( dc );
167 /***********************************************************************
168 * get_dc_ptr
170 * Retrieve a DC pointer but release the GDI lock.
172 DC *get_dc_ptr( HDC hdc )
174 DC *dc = get_dc_obj( hdc );
175 if (!dc) return NULL;
177 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
179 dc->thread = GetCurrentThreadId();
181 else if (dc->thread != GetCurrentThreadId())
183 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
184 GDI_ReleaseObj( hdc );
185 return NULL;
187 else InterlockedIncrement( &dc->refcount );
189 GDI_ReleaseObj( hdc );
190 return dc;
194 /***********************************************************************
195 * release_dc_ptr
197 void release_dc_ptr( DC *dc )
199 LONG ref;
201 dc->thread = 0;
202 ref = InterlockedDecrement( &dc->refcount );
203 assert( ref >= 0 );
204 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
208 /***********************************************************************
209 * update_dc
211 * Make sure the DC vis region is up to date.
212 * This function may call up to USER so the GDI lock should _not_
213 * be held when calling it.
215 void update_dc( DC *dc )
217 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
218 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
222 /***********************************************************************
223 * DC_DeleteObject
225 static BOOL DC_DeleteObject( HGDIOBJ handle )
227 return DeleteDC( handle );
231 /***********************************************************************
232 * DC_InitDC
234 * Setup device-specific DC values for a newly created DC.
236 void DC_InitDC( DC* dc )
238 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette );
239 physdev->funcs->pRealizeDefaultPalette( physdev );
240 SetTextColor( dc->hSelf, dc->textColor );
241 SetBkColor( dc->hSelf, dc->backgroundColor );
242 SelectObject( dc->hSelf, dc->hPen );
243 SelectObject( dc->hSelf, dc->hBrush );
244 SelectObject( dc->hSelf, dc->hFont );
245 update_dc_clipping( dc );
246 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
250 /***********************************************************************
251 * DC_InvertXform
253 * Computes the inverse of the transformation xformSrc and stores it to
254 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
255 * is singular.
257 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
259 double determinant;
261 determinant = xformSrc->eM11*xformSrc->eM22 -
262 xformSrc->eM12*xformSrc->eM21;
263 if (determinant > -1e-12 && determinant < 1e-12)
264 return FALSE;
266 xformDest->eM11 = xformSrc->eM22 / determinant;
267 xformDest->eM12 = -xformSrc->eM12 / determinant;
268 xformDest->eM21 = -xformSrc->eM21 / determinant;
269 xformDest->eM22 = xformSrc->eM11 / determinant;
270 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
271 xformSrc->eDy * xformDest->eM21;
272 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
273 xformSrc->eDy * xformDest->eM22;
275 return TRUE;
278 /* Construct a transformation to do the window-to-viewport conversion */
279 static void construct_window_to_viewport(DC *dc, XFORM *xform)
281 double scaleX, scaleY;
282 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
283 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
285 if (dc->layout & LAYOUT_RTL) scaleX = -scaleX;
286 xform->eM11 = scaleX;
287 xform->eM12 = 0.0;
288 xform->eM21 = 0.0;
289 xform->eM22 = scaleY;
290 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
291 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
292 if (dc->layout & LAYOUT_RTL) xform->eDx = dc->vis_rect.right - dc->vis_rect.left - 1 - xform->eDx;
295 /***********************************************************************
296 * DC_UpdateXforms
298 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
299 * fields of the specified DC by creating a transformation that
300 * represents the current mapping mode and combining it with the DC's
301 * world transform. This function should be called whenever the
302 * parameters associated with the mapping mode (window and viewport
303 * extents and origins) or the world transform change.
305 void DC_UpdateXforms( DC *dc )
307 XFORM xformWnd2Vport, oldworld2vport;
309 construct_window_to_viewport(dc, &xformWnd2Vport);
311 oldworld2vport = dc->xformWorld2Vport;
312 /* Combine with the world transformation */
313 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
314 &xformWnd2Vport );
316 /* Create inverse of world-to-viewport transformation */
317 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
318 &dc->xformVport2World );
320 /* Reselect the font and pen back into the dc so that the size
321 gets updated. */
322 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
323 !GdiIsMetaFileDC(dc->hSelf))
325 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
326 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
331 /***********************************************************************
332 * nulldrv_SaveDC
334 INT nulldrv_SaveDC( PHYSDEV dev )
336 DC *newdc, *dc = get_nulldrv_dc( dev );
338 if (!(newdc = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*newdc )))) return 0;
339 newdc->flags = dc->flags;
340 newdc->layout = dc->layout;
341 newdc->hPen = dc->hPen;
342 newdc->hBrush = dc->hBrush;
343 newdc->hFont = dc->hFont;
344 newdc->hBitmap = dc->hBitmap;
345 newdc->hDevice = dc->hDevice;
346 newdc->hPalette = dc->hPalette;
347 newdc->ROPmode = dc->ROPmode;
348 newdc->polyFillMode = dc->polyFillMode;
349 newdc->stretchBltMode = dc->stretchBltMode;
350 newdc->relAbsMode = dc->relAbsMode;
351 newdc->backgroundMode = dc->backgroundMode;
352 newdc->backgroundColor = dc->backgroundColor;
353 newdc->textColor = dc->textColor;
354 newdc->dcBrushColor = dc->dcBrushColor;
355 newdc->dcPenColor = dc->dcPenColor;
356 newdc->brushOrgX = dc->brushOrgX;
357 newdc->brushOrgY = dc->brushOrgY;
358 newdc->mapperFlags = dc->mapperFlags;
359 newdc->textAlign = dc->textAlign;
360 newdc->charExtra = dc->charExtra;
361 newdc->breakExtra = dc->breakExtra;
362 newdc->breakRem = dc->breakRem;
363 newdc->MapMode = dc->MapMode;
364 newdc->GraphicsMode = dc->GraphicsMode;
365 newdc->CursPosX = dc->CursPosX;
366 newdc->CursPosY = dc->CursPosY;
367 newdc->ArcDirection = dc->ArcDirection;
368 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
369 newdc->xformWorld2Vport = dc->xformWorld2Vport;
370 newdc->xformVport2World = dc->xformVport2World;
371 newdc->vport2WorldValid = dc->vport2WorldValid;
372 newdc->wndOrgX = dc->wndOrgX;
373 newdc->wndOrgY = dc->wndOrgY;
374 newdc->wndExtX = dc->wndExtX;
375 newdc->wndExtY = dc->wndExtY;
376 newdc->vportOrgX = dc->vportOrgX;
377 newdc->vportOrgY = dc->vportOrgY;
378 newdc->vportExtX = dc->vportExtX;
379 newdc->vportExtY = dc->vportExtY;
380 newdc->virtual_res = dc->virtual_res;
381 newdc->virtual_size = dc->virtual_size;
382 newdc->BoundsRect = dc->BoundsRect;
383 newdc->gdiFont = dc->gdiFont;
385 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
387 if (dc->hClipRgn)
389 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
390 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
392 if (dc->hMetaRgn)
394 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
395 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
398 if (!PATH_SavePath( newdc, dc ))
400 release_dc_ptr( dc );
401 free_dc_state( newdc );
402 return 0;
405 newdc->saved_dc = dc->saved_dc;
406 dc->saved_dc = newdc;
407 return ++dc->saveLevel;
411 /***********************************************************************
412 * restore_dc_state
414 BOOL nulldrv_RestoreDC( PHYSDEV dev, INT level )
416 DC *dcs, *first_dcs, *dc = get_nulldrv_dc( dev );
417 INT save_level;
419 /* find the state level to restore */
421 if (abs(level) > dc->saveLevel || level == 0) return FALSE;
422 if (level < 0) level = dc->saveLevel + level + 1;
423 first_dcs = dc->saved_dc;
424 for (dcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
425 dcs = dcs->saved_dc;
427 /* restore the state */
429 if (!PATH_RestorePath( dc, dcs )) return FALSE;
431 dc->flags = dcs->flags;
432 dc->layout = dcs->layout;
433 dc->hDevice = dcs->hDevice;
434 dc->ROPmode = dcs->ROPmode;
435 dc->polyFillMode = dcs->polyFillMode;
436 dc->stretchBltMode = dcs->stretchBltMode;
437 dc->relAbsMode = dcs->relAbsMode;
438 dc->backgroundMode = dcs->backgroundMode;
439 dc->backgroundColor = dcs->backgroundColor;
440 dc->textColor = dcs->textColor;
441 dc->dcBrushColor = dcs->dcBrushColor;
442 dc->dcPenColor = dcs->dcPenColor;
443 dc->brushOrgX = dcs->brushOrgX;
444 dc->brushOrgY = dcs->brushOrgY;
445 dc->mapperFlags = dcs->mapperFlags;
446 dc->textAlign = dcs->textAlign;
447 dc->charExtra = dcs->charExtra;
448 dc->breakExtra = dcs->breakExtra;
449 dc->breakRem = dcs->breakRem;
450 dc->MapMode = dcs->MapMode;
451 dc->GraphicsMode = dcs->GraphicsMode;
452 dc->CursPosX = dcs->CursPosX;
453 dc->CursPosY = dcs->CursPosY;
454 dc->ArcDirection = dcs->ArcDirection;
455 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
456 dc->xformWorld2Vport = dcs->xformWorld2Vport;
457 dc->xformVport2World = dcs->xformVport2World;
458 dc->vport2WorldValid = dcs->vport2WorldValid;
459 dc->BoundsRect = dcs->BoundsRect;
461 dc->wndOrgX = dcs->wndOrgX;
462 dc->wndOrgY = dcs->wndOrgY;
463 dc->wndExtX = dcs->wndExtX;
464 dc->wndExtY = dcs->wndExtY;
465 dc->vportOrgX = dcs->vportOrgX;
466 dc->vportOrgY = dcs->vportOrgY;
467 dc->vportExtX = dcs->vportExtX;
468 dc->vportExtY = dcs->vportExtY;
469 dc->virtual_res = dcs->virtual_res;
470 dc->virtual_size = dcs->virtual_size;
472 if (dcs->hClipRgn)
474 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
475 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
477 else
479 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
480 dc->hClipRgn = 0;
482 if (dcs->hMetaRgn)
484 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
485 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
487 else
489 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
490 dc->hMetaRgn = 0;
492 DC_UpdateXforms( dc );
493 update_dc_clipping( dc );
495 SelectObject( dev->hdc, dcs->hBitmap );
496 SelectObject( dev->hdc, dcs->hBrush );
497 SelectObject( dev->hdc, dcs->hFont );
498 SelectObject( dev->hdc, dcs->hPen );
499 SetBkColor( dev->hdc, dcs->backgroundColor);
500 SetTextColor( dev->hdc, dcs->textColor);
501 GDISelectPalette( dev->hdc, dcs->hPalette, FALSE );
503 dc->saved_dc = dcs->saved_dc;
504 dcs->saved_dc = 0;
505 dc->saveLevel = save_level - 1;
507 /* now destroy all the saved DCs */
509 while (first_dcs)
511 DC *next = first_dcs->saved_dc;
512 free_dc_state( first_dcs );
513 first_dcs = next;
515 return TRUE;
519 /***********************************************************************
520 * SaveDC (GDI32.@)
522 INT WINAPI SaveDC( HDC hdc )
524 DC * dc;
525 INT ret = 0;
527 if ((dc = get_dc_ptr( hdc )))
529 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSaveDC );
530 ret = physdev->funcs->pSaveDC( physdev );
531 release_dc_ptr( dc );
533 return ret;
537 /***********************************************************************
538 * RestoreDC (GDI32.@)
540 BOOL WINAPI RestoreDC( HDC hdc, INT level )
542 DC *dc;
543 BOOL success = FALSE;
545 TRACE("%p %d\n", hdc, level );
546 if ((dc = get_dc_ptr( hdc )))
548 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRestoreDC );
549 update_dc( dc );
550 success = physdev->funcs->pRestoreDC( physdev, level );
551 release_dc_ptr( dc );
553 return success;
557 /***********************************************************************
558 * CreateDCW (GDI32.@)
560 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
561 const DEVMODEW *initData )
563 HDC hdc;
564 DC * dc;
565 const struct gdi_dc_funcs *funcs;
566 WCHAR buf[300];
568 GDI_CheckNotLock();
570 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
572 if (!driver)
574 ERR( "no device found for %s\n", debugstr_w(device) );
575 return 0;
577 strcpyW(buf, driver);
580 if (!(funcs = DRIVER_load_driver( buf )))
582 ERR( "no driver found for %s\n", debugstr_w(buf) );
583 return 0;
585 if (!(dc = alloc_dc_ptr( OBJ_DC ))) return 0;
586 hdc = dc->hSelf;
588 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
590 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
591 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
593 if (funcs->pCreateDC)
595 if (!funcs->pCreateDC( &dc->physDev, buf, device, output, initData ))
597 WARN("creation aborted by device\n" );
598 free_dc_ptr( dc );
599 return 0;
603 dc->vis_rect.left = 0;
604 dc->vis_rect.top = 0;
605 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
606 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
608 DC_InitDC( dc );
609 release_dc_ptr( dc );
610 return hdc;
614 /***********************************************************************
615 * CreateDCA (GDI32.@)
617 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
618 const DEVMODEA *initData )
620 UNICODE_STRING driverW, deviceW, outputW;
621 DEVMODEW *initDataW;
622 HDC ret;
624 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
625 else driverW.Buffer = NULL;
627 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
628 else deviceW.Buffer = NULL;
630 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
631 else outputW.Buffer = NULL;
633 initDataW = NULL;
634 if (initData)
636 /* don't convert initData for DISPLAY driver, it's not used */
637 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
638 initDataW = GdiConvertToDevmodeW(initData);
641 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
643 RtlFreeUnicodeString(&driverW);
644 RtlFreeUnicodeString(&deviceW);
645 RtlFreeUnicodeString(&outputW);
646 HeapFree(GetProcessHeap(), 0, initDataW);
647 return ret;
651 /***********************************************************************
652 * CreateICA (GDI32.@)
654 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
655 const DEVMODEA* initData )
657 /* Nothing special yet for ICs */
658 return CreateDCA( driver, device, output, initData );
662 /***********************************************************************
663 * CreateICW (GDI32.@)
665 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
666 const DEVMODEW* initData )
668 /* Nothing special yet for ICs */
669 return CreateDCW( driver, device, output, initData );
673 /***********************************************************************
674 * CreateCompatibleDC (GDI32.@)
676 HDC WINAPI CreateCompatibleDC( HDC hdc )
678 DC *dc, *origDC;
679 HDC ret;
680 const struct gdi_dc_funcs *funcs = &null_driver;
681 PHYSDEV physDev = NULL;
683 GDI_CheckNotLock();
685 if (hdc)
687 if (!(origDC = get_dc_ptr( hdc ))) return 0;
688 physDev = GET_DC_PHYSDEV( origDC, pCreateCompatibleDC );
689 funcs = physDev->funcs;
690 release_dc_ptr( origDC );
693 if (!(dc = alloc_dc_ptr( OBJ_MEMDC ))) return 0;
695 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
697 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
698 dc->vis_rect.left = 0;
699 dc->vis_rect.top = 0;
700 dc->vis_rect.right = 1;
701 dc->vis_rect.bottom = 1;
703 ret = dc->hSelf;
705 if (!funcs->pCreateCompatibleDC( physDev, &dc->physDev ))
707 WARN("creation aborted by device\n");
708 free_dc_ptr( dc );
709 return 0;
711 DC_InitDC( dc );
712 release_dc_ptr( dc );
713 return ret;
717 /***********************************************************************
718 * DeleteDC (GDI32.@)
720 BOOL WINAPI DeleteDC( HDC hdc )
722 DC * dc;
724 TRACE("%p\n", hdc );
726 GDI_CheckNotLock();
728 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
729 if (dc->refcount != 1)
731 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
732 release_dc_ptr( dc );
733 return FALSE;
736 /* Call hook procedure to check whether is it OK to delete this DC */
737 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
739 release_dc_ptr( dc );
740 return TRUE;
743 while (dc->saveLevel)
745 DC *dcs = dc->saved_dc;
746 dc->saved_dc = dcs->saved_dc;
747 dc->saveLevel--;
748 free_dc_state( dcs );
751 AbortPath( hdc );
752 SelectObject( hdc, GetStockObject(BLACK_PEN) );
753 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
754 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
755 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
757 free_dc_ptr( dc );
758 return TRUE;
762 /***********************************************************************
763 * ResetDCW (GDI32.@)
765 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
767 DC *dc;
768 HDC ret = 0;
770 if ((dc = get_dc_ptr( hdc )))
772 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pResetDC );
773 ret = physdev->funcs->pResetDC( physdev, devmode );
774 if (ret) /* reset the visible region */
776 dc->dirty = 0;
777 dc->vis_rect.left = 0;
778 dc->vis_rect.top = 0;
779 dc->vis_rect.right = GetDeviceCaps( hdc, DESKTOPHORZRES );
780 dc->vis_rect.bottom = GetDeviceCaps( hdc, DESKTOPVERTRES );
781 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
782 dc->hVisRgn = 0;
783 update_dc_clipping( dc );
785 release_dc_ptr( dc );
787 return ret;
791 /***********************************************************************
792 * ResetDCA (GDI32.@)
794 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
796 DEVMODEW *devmodeW;
797 HDC ret;
799 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
800 else devmodeW = NULL;
802 ret = ResetDCW(hdc, devmodeW);
804 HeapFree(GetProcessHeap(), 0, devmodeW);
805 return ret;
809 /***********************************************************************
810 * GetDeviceCaps (GDI32.@)
812 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
814 DC *dc;
815 INT ret = 0;
817 if ((dc = get_dc_ptr( hdc )))
819 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceCaps );
820 ret = physdev->funcs->pGetDeviceCaps( physdev, cap );
821 release_dc_ptr( dc );
823 return ret;
827 /***********************************************************************
828 * GetBkColor (GDI32.@)
830 COLORREF WINAPI GetBkColor( HDC hdc )
832 COLORREF ret = 0;
833 DC * dc = get_dc_ptr( hdc );
834 if (dc)
836 ret = dc->backgroundColor;
837 release_dc_ptr( dc );
839 return ret;
843 /***********************************************************************
844 * SetBkColor (GDI32.@)
846 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
848 COLORREF ret = CLR_INVALID;
849 DC * dc = get_dc_ptr( hdc );
851 TRACE("hdc=%p color=0x%08x\n", hdc, color);
853 if (dc)
855 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor );
856 ret = dc->backgroundColor;
857 dc->backgroundColor = physdev->funcs->pSetBkColor( physdev, color );
858 release_dc_ptr( dc );
860 return ret;
864 /***********************************************************************
865 * GetTextColor (GDI32.@)
867 COLORREF WINAPI GetTextColor( HDC hdc )
869 COLORREF ret = 0;
870 DC * dc = get_dc_ptr( hdc );
871 if (dc)
873 ret = dc->textColor;
874 release_dc_ptr( dc );
876 return ret;
880 /***********************************************************************
881 * SetTextColor (GDI32.@)
883 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
885 COLORREF ret = CLR_INVALID;
886 DC * dc = get_dc_ptr( hdc );
888 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
890 if (dc)
892 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextColor );
893 ret = dc->textColor;
894 dc->textColor = physdev->funcs->pSetTextColor( physdev, color );
895 release_dc_ptr( dc );
897 return ret;
901 /***********************************************************************
902 * GetTextAlign (GDI32.@)
904 UINT WINAPI GetTextAlign( HDC hdc )
906 UINT ret = 0;
907 DC * dc = get_dc_ptr( hdc );
908 if (dc)
910 ret = dc->textAlign;
911 release_dc_ptr( dc );
913 return ret;
917 /***********************************************************************
918 * SetTextAlign (GDI32.@)
920 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
922 UINT ret = GDI_ERROR;
923 DC *dc = get_dc_ptr( hdc );
925 TRACE("hdc=%p align=%d\n", hdc, align);
927 if (dc)
929 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetTextAlign );
930 align = physdev->funcs->pSetTextAlign( physdev, align );
931 if (align != GDI_ERROR)
933 ret = dc->textAlign;
934 dc->textAlign = align;
936 release_dc_ptr( dc );
938 return ret;
941 /***********************************************************************
942 * GetDCOrgEx (GDI32.@)
944 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
946 DC * dc;
948 if (!lpp) return FALSE;
949 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
950 lpp->x = dc->vis_rect.left;
951 lpp->y = dc->vis_rect.top;
952 release_dc_ptr( dc );
953 return TRUE;
957 /***********************************************************************
958 * GetGraphicsMode (GDI32.@)
960 INT WINAPI GetGraphicsMode( HDC hdc )
962 INT ret = 0;
963 DC * dc = get_dc_ptr( hdc );
964 if (dc)
966 ret = dc->GraphicsMode;
967 release_dc_ptr( dc );
969 return ret;
973 /***********************************************************************
974 * SetGraphicsMode (GDI32.@)
976 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
978 INT ret = 0;
979 DC *dc = get_dc_ptr( hdc );
981 /* One would think that setting the graphics mode to GM_COMPATIBLE
982 * would also reset the world transformation matrix to the unity
983 * matrix. However, in Windows, this is not the case. This doesn't
984 * make a lot of sense to me, but that's the way it is.
986 if (!dc) return 0;
987 if ((mode > 0) && (mode <= GM_LAST))
989 ret = dc->GraphicsMode;
990 dc->GraphicsMode = mode;
992 release_dc_ptr( dc );
993 return ret;
997 /***********************************************************************
998 * GetArcDirection (GDI32.@)
1000 INT WINAPI GetArcDirection( HDC hdc )
1002 INT ret = 0;
1003 DC * dc = get_dc_ptr( hdc );
1004 if (dc)
1006 ret = dc->ArcDirection;
1007 release_dc_ptr( dc );
1009 return ret;
1013 /***********************************************************************
1014 * SetArcDirection (GDI32.@)
1016 INT WINAPI SetArcDirection( HDC hdc, INT dir )
1018 DC * dc;
1019 INT ret = 0;
1021 if (dir != AD_COUNTERCLOCKWISE && dir != AD_CLOCKWISE)
1023 SetLastError(ERROR_INVALID_PARAMETER);
1024 return 0;
1027 if ((dc = get_dc_ptr( hdc )))
1029 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetArcDirection );
1030 dir = physdev->funcs->pSetArcDirection( physdev, dir );
1031 if (dir)
1033 ret = dc->ArcDirection;
1034 dc->ArcDirection = dir;
1036 release_dc_ptr( dc );
1038 return ret;
1042 /***********************************************************************
1043 * GetWorldTransform (GDI32.@)
1045 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1047 DC * dc;
1048 if (!xform) return FALSE;
1049 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1050 *xform = dc->xformWorld2Wnd;
1051 release_dc_ptr( dc );
1052 return TRUE;
1056 /***********************************************************************
1057 * GetTransform (GDI32.@)
1059 * Undocumented
1061 * Returns one of the co-ordinate space transforms
1063 * PARAMS
1064 * hdc [I] Device context.
1065 * which [I] Which xform to return:
1066 * 0x203 World -> Page transform (that set by SetWorldTransform).
1067 * 0x304 Page -> Device transform (the mapping mode transform).
1068 * 0x204 World -> Device transform (the combination of the above two).
1069 * 0x402 Device -> World transform (the inversion of the above).
1070 * xform [O] The xform.
1073 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1075 BOOL ret = TRUE;
1076 DC *dc = get_dc_ptr( hdc );
1077 if (!dc) return FALSE;
1079 switch(which)
1081 case 0x203:
1082 *xform = dc->xformWorld2Wnd;
1083 break;
1085 case 0x304:
1086 construct_window_to_viewport(dc, xform);
1087 break;
1089 case 0x204:
1090 *xform = dc->xformWorld2Vport;
1091 break;
1093 case 0x402:
1094 *xform = dc->xformVport2World;
1095 break;
1097 default:
1098 FIXME("Unknown code %x\n", which);
1099 ret = FALSE;
1102 release_dc_ptr( dc );
1103 return ret;
1107 /****************************************************************************
1108 * CombineTransform [GDI32.@]
1109 * Combines two transformation matrices.
1111 * PARAMS
1112 * xformResult [O] Stores the result of combining the two matrices
1113 * xform1 [I] Specifies the first matrix to apply
1114 * xform2 [I] Specifies the second matrix to apply
1116 * REMARKS
1117 * The same matrix can be passed in for more than one of the parameters.
1119 * RETURNS
1120 * Success: TRUE.
1121 * Failure: FALSE. Use GetLastError() to determine the cause.
1123 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1124 const XFORM *xform2 )
1126 XFORM xformTemp;
1128 /* Check for illegal parameters */
1129 if (!xformResult || !xform1 || !xform2)
1130 return FALSE;
1132 /* Create the result in a temporary XFORM, since xformResult may be
1133 * equal to xform1 or xform2 */
1134 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1135 xform1->eM12 * xform2->eM21;
1136 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1137 xform1->eM12 * xform2->eM22;
1138 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1139 xform1->eM22 * xform2->eM21;
1140 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1141 xform1->eM22 * xform2->eM22;
1142 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1143 xform1->eDy * xform2->eM21 +
1144 xform2->eDx;
1145 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1146 xform1->eDy * xform2->eM22 +
1147 xform2->eDy;
1149 /* Copy the result to xformResult */
1150 *xformResult = xformTemp;
1152 return TRUE;
1156 /***********************************************************************
1157 * SetDCHook (GDI32.@)
1159 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1161 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1163 DC *dc = get_dc_ptr( hdc );
1165 if (!dc) return FALSE;
1167 dc->dwHookData = dwHookData;
1168 dc->hookProc = hookProc;
1169 release_dc_ptr( dc );
1170 return TRUE;
1174 /***********************************************************************
1175 * GetDCHook (GDI32.@)
1177 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1179 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1181 DC *dc = get_dc_ptr( hdc );
1182 DWORD_PTR ret;
1184 if (!dc) return 0;
1185 if (proc) *proc = dc->hookProc;
1186 ret = dc->dwHookData;
1187 release_dc_ptr( dc );
1188 return ret;
1192 /***********************************************************************
1193 * SetHookFlags (GDI32.@)
1195 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1197 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1199 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1200 LONG ret = 0;
1202 if (!dc) return 0;
1204 /* "Undocumented Windows" info is slightly confusing. */
1206 TRACE("hDC %p, flags %04x\n",hdc,flags);
1208 if (flags & DCHF_INVALIDATEVISRGN)
1209 ret = InterlockedExchange( &dc->dirty, 1 );
1210 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1211 ret = InterlockedExchange( &dc->dirty, 0 );
1213 GDI_ReleaseObj( hdc );
1214 return ret;
1217 /***********************************************************************
1218 * SetICMMode (GDI32.@)
1220 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1222 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1223 if (iEnableICM == ICM_OFF) return ICM_OFF;
1224 if (iEnableICM == ICM_ON) return 0;
1225 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1226 return 0;
1229 /***********************************************************************
1230 * GetDeviceGammaRamp (GDI32.@)
1232 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1234 BOOL ret = FALSE;
1235 DC *dc = get_dc_ptr( hDC );
1237 TRACE("%p, %p\n", hDC, ptr);
1238 if( dc )
1240 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetDeviceGammaRamp );
1241 ret = physdev->funcs->pGetDeviceGammaRamp( physdev, ptr );
1242 release_dc_ptr( dc );
1244 return ret;
1247 /***********************************************************************
1248 * SetDeviceGammaRamp (GDI32.@)
1250 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1252 BOOL ret = FALSE;
1253 DC *dc = get_dc_ptr( hDC );
1255 TRACE("%p, %p\n", hDC, ptr);
1256 if( dc )
1258 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDeviceGammaRamp );
1259 ret = physdev->funcs->pSetDeviceGammaRamp( physdev, ptr );
1260 release_dc_ptr( dc );
1262 return ret;
1265 /***********************************************************************
1266 * GetColorSpace (GDI32.@)
1268 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1270 /*FIXME Need to do whatever GetColorSpace actually does */
1271 return 0;
1274 /***********************************************************************
1275 * CreateColorSpaceA (GDI32.@)
1277 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1279 FIXME( "stub\n" );
1280 return 0;
1283 /***********************************************************************
1284 * CreateColorSpaceW (GDI32.@)
1286 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1288 FIXME( "stub\n" );
1289 return 0;
1292 /***********************************************************************
1293 * DeleteColorSpace (GDI32.@)
1295 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1297 FIXME( "stub\n" );
1299 return TRUE;
1302 /***********************************************************************
1303 * SetColorSpace (GDI32.@)
1305 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1307 FIXME( "stub\n" );
1309 return hColorSpace;
1312 /***********************************************************************
1313 * GetBoundsRect (GDI32.@)
1315 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1317 UINT ret = 0;
1318 DC *dc = get_dc_ptr( hdc );
1320 if ( !dc ) return 0;
1322 if (rect)
1324 *rect = dc->BoundsRect;
1325 ret = is_rect_empty( rect ) ? DCB_RESET : DCB_SET;
1326 DPtoLP( hdc, (POINT *)rect, 2 );
1328 if (flags & DCB_RESET)
1330 dc->BoundsRect.left = 0;
1331 dc->BoundsRect.top = 0;
1332 dc->BoundsRect.right = 0;
1333 dc->BoundsRect.bottom = 0;
1335 release_dc_ptr( dc );
1336 return ret;
1340 /***********************************************************************
1341 * SetBoundsRect (GDI32.@)
1343 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1345 UINT ret;
1346 DC *dc;
1348 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1349 if (!(dc = get_dc_ptr( hdc ))) return 0;
1351 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1352 (is_rect_empty( &dc->BoundsRect ) ? DCB_RESET : DCB_SET);
1354 if (flags & DCB_RESET)
1356 dc->BoundsRect.left = 0;
1357 dc->BoundsRect.top = 0;
1358 dc->BoundsRect.right = 0;
1359 dc->BoundsRect.bottom = 0;
1362 if ((flags & DCB_ACCUMULATE) && rect)
1364 RECT rc = *rect;
1366 LPtoDP( hdc, (POINT *)&rc, 2 );
1367 if (!is_rect_empty( &rc ))
1369 if (!is_rect_empty( &dc->BoundsRect))
1371 dc->BoundsRect.left = min( dc->BoundsRect.left, rc.left );
1372 dc->BoundsRect.top = min( dc->BoundsRect.top, rc.top );
1373 dc->BoundsRect.right = max( dc->BoundsRect.right, rc.right );
1374 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rc.bottom );
1376 else dc->BoundsRect = rc;
1380 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1381 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1383 release_dc_ptr( dc );
1384 return ret;
1388 /***********************************************************************
1389 * GetRelAbs (GDI32.@)
1391 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1393 INT ret = 0;
1394 DC *dc = get_dc_ptr( hdc );
1395 if (dc)
1397 ret = dc->relAbsMode;
1398 release_dc_ptr( dc );
1400 return ret;
1406 /***********************************************************************
1407 * GetBkMode (GDI32.@)
1409 INT WINAPI GetBkMode( HDC hdc )
1411 INT ret = 0;
1412 DC * dc = get_dc_ptr( hdc );
1413 if (dc)
1415 ret = dc->backgroundMode;
1416 release_dc_ptr( dc );
1418 return ret;
1422 /***********************************************************************
1423 * SetBkMode (GDI32.@)
1425 INT WINAPI SetBkMode( HDC hdc, INT mode )
1427 INT ret = 0;
1428 DC *dc;
1430 if ((mode <= 0) || (mode > BKMODE_LAST))
1432 SetLastError(ERROR_INVALID_PARAMETER);
1433 return 0;
1435 if ((dc = get_dc_ptr( hdc )))
1437 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkMode );
1438 mode = physdev->funcs->pSetBkMode( physdev, mode );
1439 if (mode)
1441 ret = dc->backgroundMode;
1442 dc->backgroundMode = mode;
1444 release_dc_ptr( dc );
1446 return ret;
1450 /***********************************************************************
1451 * GetROP2 (GDI32.@)
1453 INT WINAPI GetROP2( HDC hdc )
1455 INT ret = 0;
1456 DC * dc = get_dc_ptr( hdc );
1457 if (dc)
1459 ret = dc->ROPmode;
1460 release_dc_ptr( dc );
1462 return ret;
1466 /***********************************************************************
1467 * SetROP2 (GDI32.@)
1469 INT WINAPI SetROP2( HDC hdc, INT mode )
1471 INT ret = 0;
1472 DC *dc;
1474 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1476 SetLastError(ERROR_INVALID_PARAMETER);
1477 return 0;
1479 if ((dc = get_dc_ptr( hdc )))
1481 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetROP2 );
1482 mode = physdev->funcs->pSetROP2( physdev, mode );
1483 if (mode)
1485 ret = dc->ROPmode;
1486 dc->ROPmode = mode;
1488 release_dc_ptr( dc );
1490 return ret;
1494 /***********************************************************************
1495 * SetRelAbs (GDI32.@)
1497 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1499 INT ret = 0;
1500 DC *dc;
1502 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1504 SetLastError(ERROR_INVALID_PARAMETER);
1505 return 0;
1507 if ((dc = get_dc_ptr( hdc )))
1509 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetRelAbs );
1510 mode = physdev->funcs->pSetRelAbs( physdev, mode );
1511 if (mode)
1513 ret = dc->relAbsMode;
1514 dc->relAbsMode = mode;
1516 release_dc_ptr( dc );
1518 return ret;
1522 /***********************************************************************
1523 * GetPolyFillMode (GDI32.@)
1525 INT WINAPI GetPolyFillMode( HDC hdc )
1527 INT ret = 0;
1528 DC * dc = get_dc_ptr( hdc );
1529 if (dc)
1531 ret = dc->polyFillMode;
1532 release_dc_ptr( dc );
1534 return ret;
1538 /***********************************************************************
1539 * SetPolyFillMode (GDI32.@)
1541 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1543 INT ret = 0;
1544 DC *dc;
1546 if ((mode <= 0) || (mode > POLYFILL_LAST))
1548 SetLastError(ERROR_INVALID_PARAMETER);
1549 return 0;
1551 if ((dc = get_dc_ptr( hdc )))
1553 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPolyFillMode );
1554 mode = physdev->funcs->pSetPolyFillMode( physdev, mode );
1555 if (mode)
1557 ret = dc->polyFillMode;
1558 dc->polyFillMode = mode;
1560 release_dc_ptr( dc );
1562 return ret;
1566 /***********************************************************************
1567 * GetStretchBltMode (GDI32.@)
1569 INT WINAPI GetStretchBltMode( HDC hdc )
1571 INT ret = 0;
1572 DC * dc = get_dc_ptr( hdc );
1573 if (dc)
1575 ret = dc->stretchBltMode;
1576 release_dc_ptr( dc );
1578 return ret;
1582 /***********************************************************************
1583 * SetStretchBltMode (GDI32.@)
1585 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1587 INT ret = 0;
1588 DC *dc;
1590 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1592 SetLastError(ERROR_INVALID_PARAMETER);
1593 return 0;
1595 if ((dc = get_dc_ptr( hdc )))
1597 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetStretchBltMode );
1598 mode = physdev->funcs->pSetStretchBltMode( physdev, mode );
1599 if (mode)
1601 ret = dc->stretchBltMode;
1602 dc->stretchBltMode = mode;
1604 release_dc_ptr( dc );
1606 return ret;
1610 /***********************************************************************
1611 * GetMapMode (GDI32.@)
1613 INT WINAPI GetMapMode( HDC hdc )
1615 INT ret = 0;
1616 DC * dc = get_dc_ptr( hdc );
1617 if (dc)
1619 ret = dc->MapMode;
1620 release_dc_ptr( dc );
1622 return ret;
1626 /***********************************************************************
1627 * GetBrushOrgEx (GDI32.@)
1629 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1631 DC * dc = get_dc_ptr( hdc );
1632 if (!dc) return FALSE;
1633 pt->x = dc->brushOrgX;
1634 pt->y = dc->brushOrgY;
1635 release_dc_ptr( dc );
1636 return TRUE;
1640 /***********************************************************************
1641 * GetCurrentPositionEx (GDI32.@)
1643 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1645 DC * dc = get_dc_ptr( hdc );
1646 if (!dc) return FALSE;
1647 pt->x = dc->CursPosX;
1648 pt->y = dc->CursPosY;
1649 release_dc_ptr( dc );
1650 return TRUE;
1654 /***********************************************************************
1655 * GetViewportExtEx (GDI32.@)
1657 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1659 DC * dc = get_dc_ptr( hdc );
1660 if (!dc) return FALSE;
1661 size->cx = dc->vportExtX;
1662 size->cy = dc->vportExtY;
1663 release_dc_ptr( dc );
1664 return TRUE;
1668 /***********************************************************************
1669 * GetViewportOrgEx (GDI32.@)
1671 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1673 DC * dc = get_dc_ptr( hdc );
1674 if (!dc) return FALSE;
1675 pt->x = dc->vportOrgX;
1676 pt->y = dc->vportOrgY;
1677 release_dc_ptr( dc );
1678 return TRUE;
1682 /***********************************************************************
1683 * GetWindowExtEx (GDI32.@)
1685 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1687 DC * dc = get_dc_ptr( hdc );
1688 if (!dc) return FALSE;
1689 size->cx = dc->wndExtX;
1690 size->cy = dc->wndExtY;
1691 release_dc_ptr( dc );
1692 return TRUE;
1696 /***********************************************************************
1697 * GetWindowOrgEx (GDI32.@)
1699 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1701 DC * dc = get_dc_ptr( hdc );
1702 if (!dc) return FALSE;
1703 pt->x = dc->wndOrgX;
1704 pt->y = dc->wndOrgY;
1705 release_dc_ptr( dc );
1706 return TRUE;
1710 /***********************************************************************
1711 * GetLayout (GDI32.@)
1713 * Gets left->right or right->left text layout flags of a dc.
1716 DWORD WINAPI GetLayout(HDC hdc)
1718 DWORD layout = GDI_ERROR;
1720 DC * dc = get_dc_ptr( hdc );
1721 if (dc)
1723 layout = dc->layout;
1724 release_dc_ptr( dc );
1727 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1729 return layout;
1732 /***********************************************************************
1733 * SetLayout (GDI32.@)
1735 * Sets left->right or right->left text layout flags of a dc.
1738 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1740 DWORD oldlayout = GDI_ERROR;
1742 DC * dc = get_dc_ptr( hdc );
1743 if (dc)
1745 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetLayout );
1746 layout = physdev->funcs->pSetLayout( physdev, layout );
1747 if (layout != GDI_ERROR)
1749 oldlayout = dc->layout;
1750 dc->layout = layout;
1751 if (layout != oldlayout)
1753 if (layout & LAYOUT_RTL) dc->MapMode = MM_ANISOTROPIC;
1754 DC_UpdateXforms( dc );
1757 release_dc_ptr( dc );
1760 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1762 return oldlayout;
1765 /***********************************************************************
1766 * GetDCBrushColor (GDI32.@)
1768 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1770 DC *dc;
1771 COLORREF dcBrushColor = CLR_INVALID;
1773 TRACE("hdc(%p)\n", hdc);
1775 dc = get_dc_ptr( hdc );
1776 if (dc)
1778 dcBrushColor = dc->dcBrushColor;
1779 release_dc_ptr( dc );
1782 return dcBrushColor;
1785 /***********************************************************************
1786 * SetDCBrushColor (GDI32.@)
1788 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1790 DC *dc;
1791 COLORREF oldClr = CLR_INVALID;
1793 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1795 dc = get_dc_ptr( hdc );
1796 if (dc)
1798 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCBrushColor );
1799 crColor = physdev->funcs->pSetDCBrushColor( physdev, crColor );
1800 if (crColor != CLR_INVALID)
1802 oldClr = dc->dcBrushColor;
1803 dc->dcBrushColor = crColor;
1805 release_dc_ptr( dc );
1808 return oldClr;
1811 /***********************************************************************
1812 * GetDCPenColor (GDI32.@)
1814 COLORREF WINAPI GetDCPenColor(HDC hdc)
1816 DC *dc;
1817 COLORREF dcPenColor = CLR_INVALID;
1819 TRACE("hdc(%p)\n", hdc);
1821 dc = get_dc_ptr( hdc );
1822 if (dc)
1824 dcPenColor = dc->dcPenColor;
1825 release_dc_ptr( dc );
1828 return dcPenColor;
1831 /***********************************************************************
1832 * SetDCPenColor (GDI32.@)
1834 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1836 DC *dc;
1837 COLORREF oldClr = CLR_INVALID;
1839 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1841 dc = get_dc_ptr( hdc );
1842 if (dc)
1844 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetDCPenColor );
1845 crColor = physdev->funcs->pSetDCPenColor( physdev, crColor );
1846 if (crColor != CLR_INVALID)
1848 oldClr = dc->dcPenColor;
1849 dc->dcPenColor = crColor;
1851 release_dc_ptr( dc );
1854 return oldClr;
1857 /***********************************************************************
1858 * CancelDC (GDI32.@)
1860 BOOL WINAPI CancelDC(HDC hdc)
1862 FIXME("stub\n");
1863 return TRUE;
1866 /*******************************************************************
1867 * GetMiterLimit [GDI32.@]
1871 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1873 BOOL bRet = FALSE;
1874 DC *dc;
1876 TRACE("(%p,%p)\n", hdc, peLimit);
1878 dc = get_dc_ptr( hdc );
1879 if (dc)
1881 if (peLimit)
1882 *peLimit = dc->miterLimit;
1884 release_dc_ptr( dc );
1885 bRet = TRUE;
1887 return bRet;
1890 /*******************************************************************
1891 * SetMiterLimit [GDI32.@]
1895 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1897 BOOL bRet = FALSE;
1898 DC *dc;
1900 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
1902 dc = get_dc_ptr( hdc );
1903 if (dc)
1905 if (peOldLimit)
1906 *peOldLimit = dc->miterLimit;
1907 dc->miterLimit = eNewLimit;
1908 release_dc_ptr( dc );
1909 bRet = TRUE;
1911 return bRet;
1914 /*******************************************************************
1915 * GdiIsMetaPrintDC [GDI32.@]
1917 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
1919 FIXME("%p\n", hdc);
1920 return FALSE;
1923 /*******************************************************************
1924 * GdiIsMetaFileDC [GDI32.@]
1926 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
1928 TRACE("%p\n", hdc);
1930 switch( GetObjectType( hdc ) )
1932 case OBJ_METADC:
1933 case OBJ_ENHMETADC:
1934 return TRUE;
1936 return FALSE;
1939 /*******************************************************************
1940 * GdiIsPlayMetafileDC [GDI32.@]
1942 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)
1944 FIXME("%p\n", hdc);
1945 return FALSE;