winecfg: Update the Danish translation.
[wine/multimedia.git] / dlls / gdi32 / dc.c
blobf3a62bde0048349beaf879f375713e739bfb5621
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 "wownt32.h"
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc);
40 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
42 static BOOL DC_DeleteObject( HGDIOBJ handle );
44 static const struct gdi_obj_funcs dc_funcs =
46 NULL, /* pSelectObject */
47 NULL, /* pGetObjectA */
48 NULL, /* pGetObjectW */
49 NULL, /* pUnrealizeObject */
50 DC_DeleteObject /* pDeleteObject */
54 static inline DC *get_dc_obj( HDC hdc )
56 DC *dc = GDI_GetObjPtr( hdc, 0 );
57 if (!dc) return NULL;
59 if ((dc->header.type != OBJ_DC) &&
60 (dc->header.type != OBJ_MEMDC) &&
61 (dc->header.type != OBJ_METADC) &&
62 (dc->header.type != OBJ_ENHMETADC))
64 GDI_ReleaseObj( hdc );
65 SetLastError( ERROR_INVALID_HANDLE );
66 dc = NULL;
68 return dc;
72 /***********************************************************************
73 * alloc_dc_ptr
75 DC *alloc_dc_ptr( const DC_FUNCTIONS *funcs, WORD magic )
77 DC *dc;
79 if (!(dc = HeapAlloc( GetProcessHeap(), 0, sizeof(*dc) ))) return NULL;
81 dc->funcs = funcs;
82 dc->physDev = NULL;
83 dc->thread = GetCurrentThreadId();
84 dc->refcount = 1;
85 dc->dirty = 0;
86 dc->saveLevel = 0;
87 dc->saved_dc = 0;
88 dc->dwHookData = 0;
89 dc->hookProc = NULL;
90 dc->wndOrgX = 0;
91 dc->wndOrgY = 0;
92 dc->wndExtX = 1;
93 dc->wndExtY = 1;
94 dc->vportOrgX = 0;
95 dc->vportOrgY = 0;
96 dc->vportExtX = 1;
97 dc->vportExtY = 1;
98 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
99 dc->flags = 0;
100 dc->layout = 0;
101 dc->hClipRgn = 0;
102 dc->hMetaRgn = 0;
103 dc->hMetaClipRgn = 0;
104 dc->hVisRgn = 0;
105 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
106 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
107 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
108 dc->hBitmap = 0;
109 dc->hDevice = 0;
110 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
111 dc->gdiFont = 0;
112 dc->font_code_page = CP_ACP;
113 dc->ROPmode = R2_COPYPEN;
114 dc->polyFillMode = ALTERNATE;
115 dc->stretchBltMode = BLACKONWHITE;
116 dc->relAbsMode = ABSOLUTE;
117 dc->backgroundMode = OPAQUE;
118 dc->backgroundColor = RGB( 255, 255, 255 );
119 dc->dcBrushColor = RGB( 255, 255, 255 );
120 dc->dcPenColor = RGB( 0, 0, 0 );
121 dc->textColor = RGB( 0, 0, 0 );
122 dc->brushOrgX = 0;
123 dc->brushOrgY = 0;
124 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
125 dc->charExtra = 0;
126 dc->breakExtra = 0;
127 dc->breakRem = 0;
128 dc->MapMode = MM_TEXT;
129 dc->GraphicsMode = GM_COMPATIBLE;
130 dc->pAbortProc = NULL;
131 dc->CursPosX = 0;
132 dc->CursPosY = 0;
133 dc->ArcDirection = AD_COUNTERCLOCKWISE;
134 dc->xformWorld2Wnd.eM11 = 1.0f;
135 dc->xformWorld2Wnd.eM12 = 0.0f;
136 dc->xformWorld2Wnd.eM21 = 0.0f;
137 dc->xformWorld2Wnd.eM22 = 1.0f;
138 dc->xformWorld2Wnd.eDx = 0.0f;
139 dc->xformWorld2Wnd.eDy = 0.0f;
140 dc->xformWorld2Vport = dc->xformWorld2Wnd;
141 dc->xformVport2World = dc->xformWorld2Wnd;
142 dc->vport2WorldValid = TRUE;
143 dc->BoundsRect.left = 0;
144 dc->BoundsRect.top = 0;
145 dc->BoundsRect.right = 0;
146 dc->BoundsRect.bottom = 0;
147 PATH_InitGdiPath(&dc->path);
149 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
151 HeapFree( GetProcessHeap(), 0, dc );
152 dc = NULL;
154 return dc;
159 /***********************************************************************
160 * free_dc_ptr
162 BOOL free_dc_ptr( DC *dc )
164 assert( dc->refcount == 1 );
165 if (free_gdi_handle( dc->hSelf ) != dc) return FALSE; /* shouldn't happen */
166 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
167 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
168 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
169 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
170 PATH_DestroyGdiPath( &dc->path );
171 return HeapFree( GetProcessHeap(), 0, dc );
175 /***********************************************************************
176 * get_dc_ptr
178 * Retrieve a DC pointer but release the GDI lock.
180 DC *get_dc_ptr( HDC hdc )
182 DC *dc = get_dc_obj( hdc );
183 if (!dc) return NULL;
185 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
187 dc->thread = GetCurrentThreadId();
189 else if (dc->thread != GetCurrentThreadId())
191 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
192 GDI_ReleaseObj( hdc );
193 return NULL;
195 else InterlockedIncrement( &dc->refcount );
197 GDI_ReleaseObj( hdc );
198 return dc;
202 /***********************************************************************
203 * release_dc_ptr
205 void release_dc_ptr( DC *dc )
207 LONG ref;
209 dc->thread = 0;
210 ref = InterlockedDecrement( &dc->refcount );
211 assert( ref >= 0 );
212 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
216 /***********************************************************************
217 * update_dc
219 * Make sure the DC vis region is up to date.
220 * This function may call up to USER so the GDI lock should _not_
221 * be held when calling it.
223 void update_dc( DC *dc )
225 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookProc)
226 dc->hookProc( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
230 /***********************************************************************
231 * DC_DeleteObject
233 static BOOL DC_DeleteObject( HGDIOBJ handle )
235 return DeleteDC( handle );
239 /***********************************************************************
240 * DC_InitDC
242 * Setup device-specific DC values for a newly created DC.
244 void DC_InitDC( DC* dc )
246 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
247 SetTextColor( dc->hSelf, dc->textColor );
248 SetBkColor( dc->hSelf, dc->backgroundColor );
249 SelectObject( dc->hSelf, dc->hPen );
250 SelectObject( dc->hSelf, dc->hBrush );
251 SelectObject( dc->hSelf, dc->hFont );
252 CLIPPING_UpdateGCRegion( dc );
253 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
257 /***********************************************************************
258 * DC_InvertXform
260 * Computes the inverse of the transformation xformSrc and stores it to
261 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
262 * is singular.
264 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
266 double determinant;
268 determinant = xformSrc->eM11*xformSrc->eM22 -
269 xformSrc->eM12*xformSrc->eM21;
270 if (determinant > -1e-12 && determinant < 1e-12)
271 return FALSE;
273 xformDest->eM11 = xformSrc->eM22 / determinant;
274 xformDest->eM12 = -xformSrc->eM12 / determinant;
275 xformDest->eM21 = -xformSrc->eM21 / determinant;
276 xformDest->eM22 = xformSrc->eM11 / determinant;
277 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
278 xformSrc->eDy * xformDest->eM21;
279 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
280 xformSrc->eDy * xformDest->eM22;
282 return TRUE;
285 /* Construct a transformation to do the window-to-viewport conversion */
286 static void construct_window_to_viewport(DC *dc, XFORM *xform)
288 double scaleX, scaleY;
289 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
290 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
292 xform->eM11 = scaleX;
293 xform->eM12 = 0.0;
294 xform->eM21 = 0.0;
295 xform->eM22 = scaleY;
296 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
297 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
300 /***********************************************************************
301 * DC_UpdateXforms
303 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
304 * fields of the specified DC by creating a transformation that
305 * represents the current mapping mode and combining it with the DC's
306 * world transform. This function should be called whenever the
307 * parameters associated with the mapping mode (window and viewport
308 * extents and origins) or the world transform change.
310 void DC_UpdateXforms( DC *dc )
312 XFORM xformWnd2Vport, oldworld2vport;
314 construct_window_to_viewport(dc, &xformWnd2Vport);
316 oldworld2vport = dc->xformWorld2Vport;
317 /* Combine with the world transformation */
318 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
319 &xformWnd2Vport );
321 /* Create inverse of world-to-viewport transformation */
322 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
323 &dc->xformVport2World );
325 /* Reselect the font and pen back into the dc so that the size
326 gets updated. */
327 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
328 !GdiIsMetaFileDC(dc->hSelf))
330 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
331 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
336 /***********************************************************************
337 * save_dc_state
339 INT save_dc_state( HDC hdc )
341 DC * newdc, * dc;
342 INT ret;
344 if (!(dc = get_dc_ptr( hdc ))) return 0;
345 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc ))))
347 release_dc_ptr( dc );
348 return 0;
351 newdc->flags = dc->flags | DC_SAVED;
352 newdc->layout = dc->layout;
353 newdc->hPen = dc->hPen;
354 newdc->hBrush = dc->hBrush;
355 newdc->hFont = dc->hFont;
356 newdc->hBitmap = dc->hBitmap;
357 newdc->hDevice = dc->hDevice;
358 newdc->hPalette = dc->hPalette;
359 newdc->ROPmode = dc->ROPmode;
360 newdc->polyFillMode = dc->polyFillMode;
361 newdc->stretchBltMode = dc->stretchBltMode;
362 newdc->relAbsMode = dc->relAbsMode;
363 newdc->backgroundMode = dc->backgroundMode;
364 newdc->backgroundColor = dc->backgroundColor;
365 newdc->textColor = dc->textColor;
366 newdc->dcBrushColor = dc->dcBrushColor;
367 newdc->dcPenColor = dc->dcPenColor;
368 newdc->brushOrgX = dc->brushOrgX;
369 newdc->brushOrgY = dc->brushOrgY;
370 newdc->textAlign = dc->textAlign;
371 newdc->charExtra = dc->charExtra;
372 newdc->breakExtra = dc->breakExtra;
373 newdc->breakRem = dc->breakRem;
374 newdc->MapMode = dc->MapMode;
375 newdc->GraphicsMode = dc->GraphicsMode;
376 newdc->CursPosX = dc->CursPosX;
377 newdc->CursPosY = dc->CursPosY;
378 newdc->ArcDirection = dc->ArcDirection;
379 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
380 newdc->xformWorld2Vport = dc->xformWorld2Vport;
381 newdc->xformVport2World = dc->xformVport2World;
382 newdc->vport2WorldValid = dc->vport2WorldValid;
383 newdc->wndOrgX = dc->wndOrgX;
384 newdc->wndOrgY = dc->wndOrgY;
385 newdc->wndExtX = dc->wndExtX;
386 newdc->wndExtY = dc->wndExtY;
387 newdc->vportOrgX = dc->vportOrgX;
388 newdc->vportOrgY = dc->vportOrgY;
389 newdc->vportExtX = dc->vportExtX;
390 newdc->vportExtY = dc->vportExtY;
391 newdc->virtual_res = dc->virtual_res;
392 newdc->virtual_size = dc->virtual_size;
393 newdc->BoundsRect = dc->BoundsRect;
394 newdc->gdiFont = dc->gdiFont;
396 newdc->thread = GetCurrentThreadId();
397 newdc->refcount = 1;
398 newdc->saveLevel = 0;
399 newdc->saved_dc = 0;
401 PATH_InitGdiPath( &newdc->path );
403 newdc->pAbortProc = NULL;
404 newdc->hookProc = NULL;
406 if (!(newdc->hSelf = alloc_gdi_handle( &newdc->header, dc->header.type, &dc_funcs )))
408 HeapFree( GetProcessHeap(), 0, newdc );
409 release_dc_ptr( dc );
410 return 0;
413 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
415 newdc->hVisRgn = 0;
416 newdc->hClipRgn = 0;
417 newdc->hMetaRgn = 0;
418 newdc->hMetaClipRgn = 0;
419 if (dc->hClipRgn)
421 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
422 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
424 if (dc->hMetaRgn)
426 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
427 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
429 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
431 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
433 release_dc_ptr( dc );
434 free_dc_ptr( newdc );
435 return 0;
438 newdc->saved_dc = dc->saved_dc;
439 dc->saved_dc = newdc->hSelf;
440 ret = ++dc->saveLevel;
441 release_dc_ptr( newdc );
442 release_dc_ptr( dc );
443 return ret;
447 /***********************************************************************
448 * restore_dc_state
450 BOOL restore_dc_state( HDC hdc, INT level )
452 HDC hdcs, first_dcs;
453 DC *dc, *dcs;
454 INT save_level;
456 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
458 /* find the state level to restore */
460 if (abs(level) > dc->saveLevel || level == 0)
462 release_dc_ptr( dc );
463 return FALSE;
465 if (level < 0) level = dc->saveLevel + level + 1;
466 first_dcs = dc->saved_dc;
467 for (hdcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
469 if (!(dcs = get_dc_ptr( hdcs )))
471 release_dc_ptr( dc );
472 return FALSE;
474 hdcs = dcs->saved_dc;
475 release_dc_ptr( dcs );
478 /* restore the state */
480 if (!(dcs = get_dc_ptr( hdcs )))
482 release_dc_ptr( dc );
483 return FALSE;
485 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
487 release_dc_ptr( dcs );
488 release_dc_ptr( dc );
489 return FALSE;
492 dc->flags = dcs->flags & ~DC_SAVED;
493 dc->layout = dcs->layout;
494 dc->hDevice = dcs->hDevice;
495 dc->ROPmode = dcs->ROPmode;
496 dc->polyFillMode = dcs->polyFillMode;
497 dc->stretchBltMode = dcs->stretchBltMode;
498 dc->relAbsMode = dcs->relAbsMode;
499 dc->backgroundMode = dcs->backgroundMode;
500 dc->backgroundColor = dcs->backgroundColor;
501 dc->textColor = dcs->textColor;
502 dc->dcBrushColor = dcs->dcBrushColor;
503 dc->dcPenColor = dcs->dcPenColor;
504 dc->brushOrgX = dcs->brushOrgX;
505 dc->brushOrgY = dcs->brushOrgY;
506 dc->textAlign = dcs->textAlign;
507 dc->charExtra = dcs->charExtra;
508 dc->breakExtra = dcs->breakExtra;
509 dc->breakRem = dcs->breakRem;
510 dc->MapMode = dcs->MapMode;
511 dc->GraphicsMode = dcs->GraphicsMode;
512 dc->CursPosX = dcs->CursPosX;
513 dc->CursPosY = dcs->CursPosY;
514 dc->ArcDirection = dcs->ArcDirection;
515 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
516 dc->xformWorld2Vport = dcs->xformWorld2Vport;
517 dc->xformVport2World = dcs->xformVport2World;
518 dc->vport2WorldValid = dcs->vport2WorldValid;
519 dc->BoundsRect = dcs->BoundsRect;
521 dc->wndOrgX = dcs->wndOrgX;
522 dc->wndOrgY = dcs->wndOrgY;
523 dc->wndExtX = dcs->wndExtX;
524 dc->wndExtY = dcs->wndExtY;
525 dc->vportOrgX = dcs->vportOrgX;
526 dc->vportOrgY = dcs->vportOrgY;
527 dc->vportExtX = dcs->vportExtX;
528 dc->vportExtY = dcs->vportExtY;
529 dc->virtual_res = dcs->virtual_res;
530 dc->virtual_size = dcs->virtual_size;
532 if (dcs->hClipRgn)
534 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
535 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
537 else
539 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
540 dc->hClipRgn = 0;
542 if (dcs->hMetaRgn)
544 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
545 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
547 else
549 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
550 dc->hMetaRgn = 0;
552 CLIPPING_UpdateGCRegion( dc );
554 SelectObject( hdc, dcs->hBitmap );
555 SelectObject( hdc, dcs->hBrush );
556 SelectObject( hdc, dcs->hFont );
557 SelectObject( hdc, dcs->hPen );
558 SetBkColor( hdc, dcs->backgroundColor);
559 SetTextColor( hdc, dcs->textColor);
560 GDISelectPalette( hdc, dcs->hPalette, FALSE );
562 dc->saved_dc = dcs->saved_dc;
563 dcs->saved_dc = 0;
564 dc->saveLevel = save_level - 1;
566 release_dc_ptr( dcs );
568 /* now destroy all the saved DCs */
570 while (first_dcs)
572 if (!(dcs = get_dc_ptr( first_dcs ))) break;
573 hdcs = dcs->saved_dc;
574 free_dc_ptr( dcs );
575 first_dcs = hdcs;
577 release_dc_ptr( dc );
578 return TRUE;
582 /***********************************************************************
583 * SaveDC (GDI32.@)
585 INT WINAPI SaveDC( HDC hdc )
587 DC * dc;
588 INT ret;
590 if (!(dc = get_dc_ptr( hdc ))) return 0;
592 if(dc->funcs->pSaveDC)
593 ret = dc->funcs->pSaveDC( dc->physDev );
594 else
595 ret = save_dc_state( hdc );
597 release_dc_ptr( dc );
598 return ret;
602 /***********************************************************************
603 * RestoreDC (GDI32.@)
605 BOOL WINAPI RestoreDC( HDC hdc, INT level )
607 DC *dc;
608 BOOL success;
610 TRACE("%p %d\n", hdc, level );
611 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
612 update_dc( dc );
614 if(dc->funcs->pRestoreDC)
615 success = dc->funcs->pRestoreDC( dc->physDev, level );
616 else
617 success = restore_dc_state( hdc, level );
619 release_dc_ptr( dc );
620 return success;
624 /***********************************************************************
625 * CreateDCW (GDI32.@)
627 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
628 const DEVMODEW *initData )
630 HDC hdc;
631 DC * dc;
632 const DC_FUNCTIONS *funcs;
633 WCHAR buf[300];
635 GDI_CheckNotLock();
637 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
639 if (!driver)
641 ERR( "no device found for %s\n", debugstr_w(device) );
642 return 0;
644 strcpyW(buf, driver);
647 if (!(funcs = DRIVER_load_driver( buf )))
649 ERR( "no driver found for %s\n", debugstr_w(buf) );
650 return 0;
652 if (!(dc = alloc_dc_ptr( funcs, OBJ_DC ))) goto error;
653 hdc = dc->hSelf;
655 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
656 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
658 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
659 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
661 if (dc->funcs->pCreateDC &&
662 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
664 WARN("creation aborted by device\n" );
665 goto error;
668 SetRectRgn( dc->hVisRgn, 0, 0,
669 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
671 DC_InitDC( dc );
672 release_dc_ptr( dc );
673 return hdc;
675 error:
676 if (dc) free_dc_ptr( dc );
677 return 0;
681 /***********************************************************************
682 * CreateDCA (GDI32.@)
684 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
685 const DEVMODEA *initData )
687 UNICODE_STRING driverW, deviceW, outputW;
688 DEVMODEW *initDataW;
689 HDC ret;
691 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
692 else driverW.Buffer = NULL;
694 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
695 else deviceW.Buffer = NULL;
697 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
698 else outputW.Buffer = NULL;
700 initDataW = NULL;
701 if (initData)
703 /* don't convert initData for DISPLAY driver, it's not used */
704 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
705 initDataW = GdiConvertToDevmodeW(initData);
708 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
710 RtlFreeUnicodeString(&driverW);
711 RtlFreeUnicodeString(&deviceW);
712 RtlFreeUnicodeString(&outputW);
713 HeapFree(GetProcessHeap(), 0, initDataW);
714 return ret;
718 /***********************************************************************
719 * CreateICA (GDI32.@)
721 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
722 const DEVMODEA* initData )
724 /* Nothing special yet for ICs */
725 return CreateDCA( driver, device, output, initData );
729 /***********************************************************************
730 * CreateICW (GDI32.@)
732 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
733 const DEVMODEW* initData )
735 /* Nothing special yet for ICs */
736 return CreateDCW( driver, device, output, initData );
740 /***********************************************************************
741 * CreateCompatibleDC (GDI32.@)
743 HDC WINAPI CreateCompatibleDC( HDC hdc )
745 DC *dc, *origDC;
746 HDC ret;
747 const DC_FUNCTIONS *funcs = NULL;
748 PHYSDEV physDev = NULL;
750 GDI_CheckNotLock();
752 if (hdc)
754 if (!(origDC = get_dc_ptr( hdc ))) return 0;
755 if (GetObjectType( hdc ) == OBJ_DC)
757 funcs = origDC->funcs;
758 physDev = origDC->physDev;
760 release_dc_ptr( origDC );
763 if (!funcs && !(funcs = DRIVER_get_display_driver())) return 0;
765 if (!(dc = alloc_dc_ptr( funcs, OBJ_MEMDC ))) goto error;
767 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
769 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
770 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
772 /* Copy the driver-specific physical device info into
773 * the new DC. The driver may use this read-only info
774 * while creating the compatible DC below. */
775 dc->physDev = physDev;
776 ret = dc->hSelf;
778 if (dc->funcs->pCreateDC &&
779 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
781 WARN("creation aborted by device\n");
782 goto error;
785 DC_InitDC( dc );
786 release_dc_ptr( dc );
787 return ret;
789 error:
790 if (dc) free_dc_ptr( dc );
791 return 0;
795 /***********************************************************************
796 * DeleteDC (GDI32.@)
798 BOOL WINAPI DeleteDC( HDC hdc )
800 DC * dc;
802 TRACE("%p\n", hdc );
804 GDI_CheckNotLock();
806 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
807 if (dc->refcount != 1)
809 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
810 release_dc_ptr( dc );
811 return FALSE;
814 /* Call hook procedure to check whether is it OK to delete this DC */
815 if (dc->hookProc && !dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
817 release_dc_ptr( dc );
818 return TRUE;
821 while (dc->saveLevel)
823 DC * dcs;
824 HDC hdcs = dc->saved_dc;
825 if (!(dcs = get_dc_ptr( hdcs ))) break;
826 dc->saved_dc = dcs->saved_dc;
827 dc->saveLevel--;
828 free_dc_ptr( dcs );
831 if (!(dc->flags & DC_SAVED))
833 SelectObject( hdc, GetStockObject(BLACK_PEN) );
834 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
835 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
836 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
837 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
838 dc->physDev = NULL;
841 free_dc_ptr( dc );
842 return TRUE;
846 /***********************************************************************
847 * ResetDCW (GDI32.@)
849 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
851 DC *dc;
852 HDC ret = hdc;
854 if ((dc = get_dc_ptr( hdc )))
856 if (dc->funcs->pResetDC)
858 ret = dc->funcs->pResetDC( dc->physDev, devmode );
859 if (ret) /* reset the visible region */
861 dc->dirty = 0;
862 SetRectRgn( dc->hVisRgn, 0, 0, GetDeviceCaps( hdc, DESKTOPHORZRES ),
863 GetDeviceCaps( hdc, DESKTOPVERTRES ) );
864 CLIPPING_UpdateGCRegion( dc );
867 release_dc_ptr( dc );
869 return ret;
873 /***********************************************************************
874 * ResetDCA (GDI32.@)
876 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
878 DEVMODEW *devmodeW;
879 HDC ret;
881 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
882 else devmodeW = NULL;
884 ret = ResetDCW(hdc, devmodeW);
886 HeapFree(GetProcessHeap(), 0, devmodeW);
887 return ret;
891 /***********************************************************************
892 * GetDeviceCaps (GDI32.@)
894 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
896 DC *dc;
897 INT ret = 0;
899 if ((dc = get_dc_ptr( hdc )))
901 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
902 else switch(cap) /* return meaningful values for some entries */
904 case HORZRES: ret = 640; break;
905 case VERTRES: ret = 480; break;
906 case BITSPIXEL: ret = 1; break;
907 case PLANES: ret = 1; break;
908 case NUMCOLORS: ret = 2; break;
909 case ASPECTX: ret = 36; break;
910 case ASPECTY: ret = 36; break;
911 case ASPECTXY: ret = 51; break;
912 case LOGPIXELSX: ret = 72; break;
913 case LOGPIXELSY: ret = 72; break;
914 case SIZEPALETTE: ret = 2; break;
916 release_dc_ptr( dc );
918 return ret;
922 /***********************************************************************
923 * GetBkColor (GDI32.@)
925 COLORREF WINAPI GetBkColor( HDC hdc )
927 COLORREF ret = 0;
928 DC * dc = get_dc_ptr( hdc );
929 if (dc)
931 ret = dc->backgroundColor;
932 release_dc_ptr( dc );
934 return ret;
938 /***********************************************************************
939 * SetBkColor (GDI32.@)
941 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
943 COLORREF oldColor;
944 DC * dc = get_dc_ptr( hdc );
946 TRACE("hdc=%p color=0x%08x\n", hdc, color);
948 if (!dc) return CLR_INVALID;
949 oldColor = dc->backgroundColor;
950 if (dc->funcs->pSetBkColor)
952 color = dc->funcs->pSetBkColor(dc->physDev, color);
953 if (color == CLR_INVALID) /* don't change it */
955 color = oldColor;
956 oldColor = CLR_INVALID;
959 dc->backgroundColor = color;
960 release_dc_ptr( dc );
961 return oldColor;
965 /***********************************************************************
966 * GetTextColor (GDI32.@)
968 COLORREF WINAPI GetTextColor( HDC hdc )
970 COLORREF ret = 0;
971 DC * dc = get_dc_ptr( hdc );
972 if (dc)
974 ret = dc->textColor;
975 release_dc_ptr( dc );
977 return ret;
981 /***********************************************************************
982 * SetTextColor (GDI32.@)
984 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
986 COLORREF oldColor;
987 DC * dc = get_dc_ptr( hdc );
989 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
991 if (!dc) return CLR_INVALID;
992 oldColor = dc->textColor;
993 if (dc->funcs->pSetTextColor)
995 color = dc->funcs->pSetTextColor(dc->physDev, color);
996 if (color == CLR_INVALID) /* don't change it */
998 color = oldColor;
999 oldColor = CLR_INVALID;
1002 dc->textColor = color;
1003 release_dc_ptr( dc );
1004 return oldColor;
1008 /***********************************************************************
1009 * GetTextAlign (GDI32.@)
1011 UINT WINAPI GetTextAlign( HDC hdc )
1013 UINT ret = 0;
1014 DC * dc = get_dc_ptr( hdc );
1015 if (dc)
1017 ret = dc->textAlign;
1018 release_dc_ptr( dc );
1020 return ret;
1024 /***********************************************************************
1025 * SetTextAlign (GDI32.@)
1027 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1029 UINT ret;
1030 DC *dc = get_dc_ptr( hdc );
1032 TRACE("hdc=%p align=%d\n", hdc, align);
1034 if (!dc) return 0x0;
1035 ret = dc->textAlign;
1036 if (dc->funcs->pSetTextAlign)
1037 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1038 ret = GDI_ERROR;
1039 if (ret != GDI_ERROR)
1040 dc->textAlign = align;
1041 release_dc_ptr( dc );
1042 return ret;
1045 /***********************************************************************
1046 * GetDCOrgEx (GDI32.@)
1048 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1050 DC * dc;
1052 if (!lpp) return FALSE;
1053 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1055 lpp->x = lpp->y = 0;
1056 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1057 release_dc_ptr( dc );
1058 return TRUE;
1062 /***********************************************************************
1063 * GetGraphicsMode (GDI32.@)
1065 INT WINAPI GetGraphicsMode( HDC hdc )
1067 INT ret = 0;
1068 DC * dc = get_dc_ptr( hdc );
1069 if (dc)
1071 ret = dc->GraphicsMode;
1072 release_dc_ptr( dc );
1074 return ret;
1078 /***********************************************************************
1079 * SetGraphicsMode (GDI32.@)
1081 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1083 INT ret = 0;
1084 DC *dc = get_dc_ptr( hdc );
1086 /* One would think that setting the graphics mode to GM_COMPATIBLE
1087 * would also reset the world transformation matrix to the unity
1088 * matrix. However, in Windows, this is not the case. This doesn't
1089 * make a lot of sense to me, but that's the way it is.
1091 if (!dc) return 0;
1092 if ((mode > 0) && (mode <= GM_LAST))
1094 ret = dc->GraphicsMode;
1095 dc->GraphicsMode = mode;
1097 release_dc_ptr( dc );
1098 return ret;
1102 /***********************************************************************
1103 * GetArcDirection (GDI32.@)
1105 INT WINAPI GetArcDirection( HDC hdc )
1107 INT ret = 0;
1108 DC * dc = get_dc_ptr( hdc );
1109 if (dc)
1111 ret = dc->ArcDirection;
1112 release_dc_ptr( dc );
1114 return ret;
1118 /***********************************************************************
1119 * SetArcDirection (GDI32.@)
1121 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1123 DC * dc;
1124 INT nOldDirection = 0;
1126 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1128 SetLastError(ERROR_INVALID_PARAMETER);
1129 return 0;
1132 if ((dc = get_dc_ptr( hdc )))
1134 if (dc->funcs->pSetArcDirection)
1136 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1138 nOldDirection = dc->ArcDirection;
1139 dc->ArcDirection = nDirection;
1140 release_dc_ptr( dc );
1142 return nOldDirection;
1146 /***********************************************************************
1147 * GetWorldTransform (GDI32.@)
1149 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1151 DC * dc;
1152 if (!xform) return FALSE;
1153 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1154 *xform = dc->xformWorld2Wnd;
1155 release_dc_ptr( dc );
1156 return TRUE;
1160 /***********************************************************************
1161 * GetTransform (GDI32.@)
1163 * Undocumented
1165 * Returns one of the co-ordinate space transforms
1167 * PARAMS
1168 * hdc [I] Device context.
1169 * which [I] Which xform to return:
1170 * 0x203 World -> Page transform (that set by SetWorldTransform).
1171 * 0x304 Page -> Device transform (the mapping mode transform).
1172 * 0x204 World -> Device transform (the combination of the above two).
1173 * 0x402 Device -> World transform (the inversion of the above).
1174 * xform [O] The xform.
1177 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1179 BOOL ret = TRUE;
1180 DC *dc = get_dc_ptr( hdc );
1181 if (!dc) return FALSE;
1183 switch(which)
1185 case 0x203:
1186 *xform = dc->xformWorld2Wnd;
1187 break;
1189 case 0x304:
1190 construct_window_to_viewport(dc, xform);
1191 break;
1193 case 0x204:
1194 *xform = dc->xformWorld2Vport;
1195 break;
1197 case 0x402:
1198 *xform = dc->xformVport2World;
1199 break;
1201 default:
1202 FIXME("Unknown code %x\n", which);
1203 ret = FALSE;
1206 release_dc_ptr( dc );
1207 return ret;
1211 /***********************************************************************
1212 * SetWorldTransform (GDI32.@)
1214 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1216 BOOL ret = FALSE;
1217 DC *dc;
1219 if (!xform) return FALSE;
1221 dc = get_dc_ptr( hdc );
1222 if (!dc) return FALSE;
1224 /* Check that graphics mode is GM_ADVANCED */
1225 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1227 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1228 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1230 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1231 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) goto done;
1233 if (dc->funcs->pSetWorldTransform)
1235 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1236 if (!ret) goto done;
1239 dc->xformWorld2Wnd = *xform;
1240 DC_UpdateXforms( dc );
1241 ret = TRUE;
1242 done:
1243 release_dc_ptr( dc );
1244 return ret;
1248 /****************************************************************************
1249 * ModifyWorldTransform [GDI32.@]
1250 * Modifies the world transformation for a device context.
1252 * PARAMS
1253 * hdc [I] Handle to device context
1254 * xform [I] XFORM structure that will be used to modify the world
1255 * transformation
1256 * iMode [I] Specifies in what way to modify the world transformation
1257 * Possible values:
1258 * MWT_IDENTITY
1259 * Resets the world transformation to the identity matrix.
1260 * The parameter xform is ignored.
1261 * MWT_LEFTMULTIPLY
1262 * Multiplies xform into the world transformation matrix from
1263 * the left.
1264 * MWT_RIGHTMULTIPLY
1265 * Multiplies xform into the world transformation matrix from
1266 * the right.
1268 * RETURNS
1269 * Success: TRUE.
1270 * Failure: FALSE. Use GetLastError() to determine the cause.
1272 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1273 DWORD iMode )
1275 BOOL ret = FALSE;
1276 DC *dc = get_dc_ptr( hdc );
1278 /* Check for illegal parameters */
1279 if (!dc) return FALSE;
1280 if (!xform && iMode != MWT_IDENTITY) goto done;
1282 /* Check that graphics mode is GM_ADVANCED */
1283 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1285 if (dc->funcs->pModifyWorldTransform)
1287 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1288 if (!ret) goto done;
1291 switch (iMode)
1293 case MWT_IDENTITY:
1294 dc->xformWorld2Wnd.eM11 = 1.0f;
1295 dc->xformWorld2Wnd.eM12 = 0.0f;
1296 dc->xformWorld2Wnd.eM21 = 0.0f;
1297 dc->xformWorld2Wnd.eM22 = 1.0f;
1298 dc->xformWorld2Wnd.eDx = 0.0f;
1299 dc->xformWorld2Wnd.eDy = 0.0f;
1300 break;
1301 case MWT_LEFTMULTIPLY:
1302 CombineTransform( &dc->xformWorld2Wnd, xform,
1303 &dc->xformWorld2Wnd );
1304 break;
1305 case MWT_RIGHTMULTIPLY:
1306 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1307 xform );
1308 break;
1309 default:
1310 goto done;
1313 DC_UpdateXforms( dc );
1314 ret = TRUE;
1315 done:
1316 release_dc_ptr( dc );
1317 return ret;
1321 /****************************************************************************
1322 * CombineTransform [GDI32.@]
1323 * Combines two transformation matrices.
1325 * PARAMS
1326 * xformResult [O] Stores the result of combining the two matrices
1327 * xform1 [I] Specifies the first matrix to apply
1328 * xform2 [I] Specifies the second matrix to apply
1330 * REMARKS
1331 * The same matrix can be passed in for more than one of the parameters.
1333 * RETURNS
1334 * Success: TRUE.
1335 * Failure: FALSE. Use GetLastError() to determine the cause.
1337 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1338 const XFORM *xform2 )
1340 XFORM xformTemp;
1342 /* Check for illegal parameters */
1343 if (!xformResult || !xform1 || !xform2)
1344 return FALSE;
1346 /* Create the result in a temporary XFORM, since xformResult may be
1347 * equal to xform1 or xform2 */
1348 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1349 xform1->eM12 * xform2->eM21;
1350 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1351 xform1->eM12 * xform2->eM22;
1352 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1353 xform1->eM22 * xform2->eM21;
1354 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1355 xform1->eM22 * xform2->eM22;
1356 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1357 xform1->eDy * xform2->eM21 +
1358 xform2->eDx;
1359 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1360 xform1->eDy * xform2->eM22 +
1361 xform2->eDy;
1363 /* Copy the result to xformResult */
1364 *xformResult = xformTemp;
1366 return TRUE;
1370 /***********************************************************************
1371 * SetDCHook (GDI32.@)
1373 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1375 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1377 DC *dc = get_dc_ptr( hdc );
1379 if (!dc) return FALSE;
1381 if (!(dc->flags & DC_SAVED))
1383 dc->dwHookData = dwHookData;
1384 dc->hookProc = hookProc;
1386 release_dc_ptr( dc );
1387 return TRUE;
1391 /***********************************************************************
1392 * GetDCHook (GDI32.@)
1394 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1396 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1398 DC *dc = get_dc_ptr( hdc );
1399 DWORD_PTR ret;
1401 if (!dc) return 0;
1402 if (proc) *proc = dc->hookProc;
1403 ret = dc->dwHookData;
1404 release_dc_ptr( dc );
1405 return ret;
1409 /***********************************************************************
1410 * SetHookFlags (GDI32.@)
1412 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1414 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1416 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1417 LONG ret = 0;
1419 if (!dc) return 0;
1421 /* "Undocumented Windows" info is slightly confusing. */
1423 TRACE("hDC %p, flags %04x\n",hdc,flags);
1425 if (flags & DCHF_INVALIDATEVISRGN)
1426 ret = InterlockedExchange( &dc->dirty, 1 );
1427 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1428 ret = InterlockedExchange( &dc->dirty, 0 );
1430 GDI_ReleaseObj( dc );
1431 return ret;
1434 /***********************************************************************
1435 * SetICMMode (GDI32.@)
1437 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1439 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1440 if (iEnableICM == ICM_OFF) return ICM_OFF;
1441 if (iEnableICM == ICM_ON) return 0;
1442 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1443 return 0;
1446 /***********************************************************************
1447 * GetDeviceGammaRamp (GDI32.@)
1449 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1451 BOOL ret = FALSE;
1452 DC *dc = get_dc_ptr( hDC );
1454 if( dc )
1456 if (dc->funcs->pGetDeviceGammaRamp)
1457 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1458 release_dc_ptr( dc );
1460 return ret;
1463 /***********************************************************************
1464 * SetDeviceGammaRamp (GDI32.@)
1466 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1468 BOOL ret = FALSE;
1469 DC *dc = get_dc_ptr( hDC );
1471 if( dc )
1473 if (dc->funcs->pSetDeviceGammaRamp)
1474 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1475 release_dc_ptr( dc );
1477 return ret;
1480 /***********************************************************************
1481 * GetColorSpace (GDI32.@)
1483 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1485 /*FIXME Need to to whatever GetColorSpace actually does */
1486 return 0;
1489 /***********************************************************************
1490 * CreateColorSpaceA (GDI32.@)
1492 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1494 FIXME( "stub\n" );
1495 return 0;
1498 /***********************************************************************
1499 * CreateColorSpaceW (GDI32.@)
1501 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1503 FIXME( "stub\n" );
1504 return 0;
1507 /***********************************************************************
1508 * DeleteColorSpace (GDI32.@)
1510 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1512 FIXME( "stub\n" );
1514 return TRUE;
1517 /***********************************************************************
1518 * SetColorSpace (GDI32.@)
1520 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1522 FIXME( "stub\n" );
1524 return hColorSpace;
1527 /***********************************************************************
1528 * GetBoundsRect (GDI32.@)
1530 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1532 UINT ret;
1533 DC *dc = get_dc_ptr( hdc );
1535 if ( !dc ) return 0;
1537 if (rect)
1539 *rect = dc->BoundsRect;
1540 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1542 else
1543 ret = 0;
1545 if (flags & DCB_RESET)
1547 dc->BoundsRect.left = 0;
1548 dc->BoundsRect.top = 0;
1549 dc->BoundsRect.right = 0;
1550 dc->BoundsRect.bottom = 0;
1551 dc->flags &= ~DC_BOUNDS_SET;
1553 release_dc_ptr( dc );
1554 return ret;
1558 /***********************************************************************
1559 * SetBoundsRect (GDI32.@)
1561 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1563 UINT ret;
1564 DC *dc;
1566 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1567 if (!(dc = get_dc_ptr( hdc ))) return 0;
1569 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1570 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1572 if (flags & DCB_RESET)
1574 dc->BoundsRect.left = 0;
1575 dc->BoundsRect.top = 0;
1576 dc->BoundsRect.right = 0;
1577 dc->BoundsRect.bottom = 0;
1578 dc->flags &= ~DC_BOUNDS_SET;
1581 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1583 if (dc->flags & DC_BOUNDS_SET)
1585 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1586 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1587 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1588 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1590 else
1592 dc->BoundsRect = *rect;
1593 dc->flags |= DC_BOUNDS_SET;
1597 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1598 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1600 release_dc_ptr( dc );
1601 return ret;
1605 /***********************************************************************
1606 * GetRelAbs (GDI32.@)
1608 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1610 INT ret = 0;
1611 DC *dc = get_dc_ptr( hdc );
1612 if (dc)
1614 ret = dc->relAbsMode;
1615 release_dc_ptr( dc );
1617 return ret;
1623 /***********************************************************************
1624 * GetBkMode (GDI32.@)
1626 INT WINAPI GetBkMode( HDC hdc )
1628 INT ret = 0;
1629 DC * dc = get_dc_ptr( hdc );
1630 if (dc)
1632 ret = dc->backgroundMode;
1633 release_dc_ptr( dc );
1635 return ret;
1639 /***********************************************************************
1640 * SetBkMode (GDI32.@)
1642 INT WINAPI SetBkMode( HDC hdc, INT mode )
1644 INT ret;
1645 DC *dc;
1646 if ((mode <= 0) || (mode > BKMODE_LAST))
1648 SetLastError(ERROR_INVALID_PARAMETER);
1649 return 0;
1651 if (!(dc = get_dc_ptr( hdc ))) return 0;
1653 ret = dc->backgroundMode;
1654 if (dc->funcs->pSetBkMode)
1655 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1656 ret = 0;
1657 if (ret)
1658 dc->backgroundMode = mode;
1659 release_dc_ptr( dc );
1660 return ret;
1664 /***********************************************************************
1665 * GetROP2 (GDI32.@)
1667 INT WINAPI GetROP2( HDC hdc )
1669 INT ret = 0;
1670 DC * dc = get_dc_ptr( hdc );
1671 if (dc)
1673 ret = dc->ROPmode;
1674 release_dc_ptr( dc );
1676 return ret;
1680 /***********************************************************************
1681 * SetROP2 (GDI32.@)
1683 INT WINAPI SetROP2( HDC hdc, INT mode )
1685 INT ret;
1686 DC *dc;
1687 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1689 SetLastError(ERROR_INVALID_PARAMETER);
1690 return 0;
1692 if (!(dc = get_dc_ptr( hdc ))) return 0;
1693 ret = dc->ROPmode;
1694 if (dc->funcs->pSetROP2)
1695 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1696 ret = 0;
1697 if (ret)
1698 dc->ROPmode = mode;
1699 release_dc_ptr( dc );
1700 return ret;
1704 /***********************************************************************
1705 * SetRelAbs (GDI32.@)
1707 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1709 INT ret;
1710 DC *dc;
1711 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1713 SetLastError(ERROR_INVALID_PARAMETER);
1714 return 0;
1716 if (!(dc = get_dc_ptr( hdc ))) return 0;
1717 if (dc->funcs->pSetRelAbs)
1718 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1719 else
1721 ret = dc->relAbsMode;
1722 dc->relAbsMode = mode;
1724 release_dc_ptr( dc );
1725 return ret;
1729 /***********************************************************************
1730 * GetPolyFillMode (GDI32.@)
1732 INT WINAPI GetPolyFillMode( HDC hdc )
1734 INT ret = 0;
1735 DC * dc = get_dc_ptr( hdc );
1736 if (dc)
1738 ret = dc->polyFillMode;
1739 release_dc_ptr( dc );
1741 return ret;
1745 /***********************************************************************
1746 * SetPolyFillMode (GDI32.@)
1748 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1750 INT ret;
1751 DC *dc;
1752 if ((mode <= 0) || (mode > POLYFILL_LAST))
1754 SetLastError(ERROR_INVALID_PARAMETER);
1755 return 0;
1757 if (!(dc = get_dc_ptr( hdc ))) return 0;
1758 ret = dc->polyFillMode;
1759 if (dc->funcs->pSetPolyFillMode)
1760 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1761 ret = 0;
1762 if (ret)
1763 dc->polyFillMode = mode;
1764 release_dc_ptr( dc );
1765 return ret;
1769 /***********************************************************************
1770 * GetStretchBltMode (GDI32.@)
1772 INT WINAPI GetStretchBltMode( HDC hdc )
1774 INT ret = 0;
1775 DC * dc = get_dc_ptr( hdc );
1776 if (dc)
1778 ret = dc->stretchBltMode;
1779 release_dc_ptr( dc );
1781 return ret;
1785 /***********************************************************************
1786 * SetStretchBltMode (GDI32.@)
1788 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1790 INT ret;
1791 DC *dc;
1792 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1794 SetLastError(ERROR_INVALID_PARAMETER);
1795 return 0;
1797 if (!(dc = get_dc_ptr( hdc ))) return 0;
1798 ret = dc->stretchBltMode;
1799 if (dc->funcs->pSetStretchBltMode)
1800 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1801 ret = 0;
1802 if (ret)
1803 dc->stretchBltMode = mode;
1804 release_dc_ptr( dc );
1805 return ret;
1809 /***********************************************************************
1810 * GetMapMode (GDI32.@)
1812 INT WINAPI GetMapMode( HDC hdc )
1814 INT ret = 0;
1815 DC * dc = get_dc_ptr( hdc );
1816 if (dc)
1818 ret = dc->MapMode;
1819 release_dc_ptr( dc );
1821 return ret;
1825 /***********************************************************************
1826 * GetBrushOrgEx (GDI32.@)
1828 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1830 DC * dc = get_dc_ptr( hdc );
1831 if (!dc) return FALSE;
1832 pt->x = dc->brushOrgX;
1833 pt->y = dc->brushOrgY;
1834 release_dc_ptr( dc );
1835 return TRUE;
1839 /***********************************************************************
1840 * GetCurrentPositionEx (GDI32.@)
1842 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1844 DC * dc = get_dc_ptr( hdc );
1845 if (!dc) return FALSE;
1846 pt->x = dc->CursPosX;
1847 pt->y = dc->CursPosY;
1848 release_dc_ptr( dc );
1849 return TRUE;
1853 /***********************************************************************
1854 * GetViewportExtEx (GDI32.@)
1856 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1858 DC * dc = get_dc_ptr( hdc );
1859 if (!dc) return FALSE;
1860 size->cx = dc->vportExtX;
1861 size->cy = dc->vportExtY;
1862 release_dc_ptr( dc );
1863 return TRUE;
1867 /***********************************************************************
1868 * GetViewportOrgEx (GDI32.@)
1870 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1872 DC * dc = get_dc_ptr( hdc );
1873 if (!dc) return FALSE;
1874 pt->x = dc->vportOrgX;
1875 pt->y = dc->vportOrgY;
1876 release_dc_ptr( dc );
1877 return TRUE;
1881 /***********************************************************************
1882 * GetWindowExtEx (GDI32.@)
1884 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1886 DC * dc = get_dc_ptr( hdc );
1887 if (!dc) return FALSE;
1888 size->cx = dc->wndExtX;
1889 size->cy = dc->wndExtY;
1890 release_dc_ptr( dc );
1891 return TRUE;
1895 /***********************************************************************
1896 * GetWindowOrgEx (GDI32.@)
1898 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1900 DC * dc = get_dc_ptr( hdc );
1901 if (!dc) return FALSE;
1902 pt->x = dc->wndOrgX;
1903 pt->y = dc->wndOrgY;
1904 release_dc_ptr( dc );
1905 return TRUE;
1909 /***********************************************************************
1910 * GetLayout (GDI32.@)
1912 * Gets left->right or right->left text layout flags of a dc.
1915 DWORD WINAPI GetLayout(HDC hdc)
1917 DWORD layout = GDI_ERROR;
1919 DC * dc = get_dc_ptr( hdc );
1920 if (dc)
1922 layout = dc->layout;
1923 release_dc_ptr( dc );
1926 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1928 return layout;
1931 /***********************************************************************
1932 * SetLayout (GDI32.@)
1934 * Sets left->right or right->left text layout flags of a dc.
1937 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1939 DWORD oldlayout = GDI_ERROR;
1941 DC * dc = get_dc_ptr( hdc );
1942 if (dc)
1944 oldlayout = dc->layout;
1945 dc->layout = layout;
1946 release_dc_ptr( dc );
1949 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
1951 return oldlayout;
1954 /***********************************************************************
1955 * GetDCBrushColor (GDI32.@)
1957 * Retrieves the current brush color for the specified device
1958 * context (DC).
1961 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1963 DC *dc;
1964 COLORREF dcBrushColor = CLR_INVALID;
1966 TRACE("hdc(%p)\n", hdc);
1968 dc = get_dc_ptr( hdc );
1969 if (dc)
1971 dcBrushColor = dc->dcBrushColor;
1972 release_dc_ptr( dc );
1975 return dcBrushColor;
1978 /***********************************************************************
1979 * SetDCBrushColor (GDI32.@)
1981 * Sets the current device context (DC) brush color to the specified
1982 * color value. If the device cannot represent the specified color
1983 * value, the color is set to the nearest physical color.
1986 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1988 DC *dc;
1989 COLORREF oldClr = CLR_INVALID;
1991 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
1993 dc = get_dc_ptr( hdc );
1994 if (dc)
1996 if (dc->funcs->pSetDCBrushColor)
1997 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
1998 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2000 /* If DC_BRUSH is selected, update driver pen color */
2001 HBRUSH hBrush = CreateSolidBrush( crColor );
2002 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2003 DeleteObject( hBrush );
2006 if (crColor != CLR_INVALID)
2008 oldClr = dc->dcBrushColor;
2009 dc->dcBrushColor = crColor;
2012 release_dc_ptr( dc );
2015 return oldClr;
2018 /***********************************************************************
2019 * GetDCPenColor (GDI32.@)
2021 * Retrieves the current pen color for the specified device
2022 * context (DC).
2025 COLORREF WINAPI GetDCPenColor(HDC hdc)
2027 DC *dc;
2028 COLORREF dcPenColor = CLR_INVALID;
2030 TRACE("hdc(%p)\n", hdc);
2032 dc = get_dc_ptr( hdc );
2033 if (dc)
2035 dcPenColor = dc->dcPenColor;
2036 release_dc_ptr( dc );
2039 return dcPenColor;
2042 /***********************************************************************
2043 * SetDCPenColor (GDI32.@)
2045 * Sets the current device context (DC) pen color to the specified
2046 * color value. If the device cannot represent the specified color
2047 * value, the color is set to the nearest physical color.
2050 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2052 DC *dc;
2053 COLORREF oldClr = CLR_INVALID;
2055 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2057 dc = get_dc_ptr( hdc );
2058 if (dc)
2060 if (dc->funcs->pSetDCPenColor)
2061 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2062 else if (dc->hPen == GetStockObject( DC_PEN ))
2064 /* If DC_PEN is selected, update the driver pen color */
2065 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2066 HPEN hPen = CreatePenIndirect( &logpen );
2067 dc->funcs->pSelectPen( dc->physDev, hPen );
2068 DeleteObject( hPen );
2071 if (crColor != CLR_INVALID)
2073 oldClr = dc->dcPenColor;
2074 dc->dcPenColor = crColor;
2077 release_dc_ptr( dc );
2080 return oldClr;
2083 /***********************************************************************
2084 * CancelDC (GDI32.@)
2086 BOOL WINAPI CancelDC(HDC hdc)
2088 FIXME("stub\n");
2089 return TRUE;
2092 /*******************************************************************
2093 * GetMiterLimit [GDI32.@]
2097 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2099 BOOL bRet = FALSE;
2100 DC *dc;
2102 TRACE("(%p,%p)\n", hdc, peLimit);
2104 dc = get_dc_ptr( hdc );
2105 if (dc)
2107 if (peLimit)
2108 *peLimit = dc->miterLimit;
2110 release_dc_ptr( dc );
2111 bRet = TRUE;
2113 return bRet;
2116 /*******************************************************************
2117 * SetMiterLimit [GDI32.@]
2121 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2123 BOOL bRet = FALSE;
2124 DC *dc;
2126 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2128 dc = get_dc_ptr( hdc );
2129 if (dc)
2131 if (peOldLimit)
2132 *peOldLimit = dc->miterLimit;
2133 dc->miterLimit = eNewLimit;
2134 release_dc_ptr( dc );
2135 bRet = TRUE;
2137 return bRet;
2140 /*******************************************************************
2141 * GdiIsMetaPrintDC [GDI32.@]
2143 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2145 FIXME("%p\n", hdc);
2146 return FALSE;
2149 /*******************************************************************
2150 * GdiIsMetaFileDC [GDI32.@]
2152 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2154 TRACE("%p\n", hdc);
2156 switch( GetObjectType( hdc ) )
2158 case OBJ_METADC:
2159 case OBJ_ENHMETADC:
2160 return TRUE;
2162 return FALSE;
2165 /*******************************************************************
2166 * GdiIsPlayMetafileDC [GDI32.@]
2168 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)
2170 FIXME("%p\n", hdc);
2171 return FALSE;