Added another possible windows failure mode.
[wine/gsoc_dplay.git] / objects / dc.c
blobef67b886114e1d7c694af73695872086aebfd275
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "winerror.h"
32 #include "wownt32.h"
33 #include "wine/winuser16.h"
34 #include "gdi.h"
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dc);
41 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
43 static const struct gdi_obj_funcs dc_funcs =
45 NULL, /* pSelectObject */
46 NULL, /* pGetObject16 */
47 NULL, /* pGetObjectA */
48 NULL, /* pGetObjectW */
49 NULL, /* pUnrealizeObject */
50 DC_DeleteObject /* pDeleteObject */
53 /***********************************************************************
54 * DC_AllocDC
56 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
58 HDC hdc;
59 DC *dc;
61 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
63 dc->hSelf = hdc;
64 dc->funcs = funcs;
65 dc->physDev = NULL;
66 dc->saveLevel = 0;
67 dc->dwHookData = 0;
68 dc->hookProc = NULL;
69 dc->hookThunk = NULL;
70 dc->wndOrgX = 0;
71 dc->wndOrgY = 0;
72 dc->wndExtX = 1;
73 dc->wndExtY = 1;
74 dc->vportOrgX = 0;
75 dc->vportOrgY = 0;
76 dc->vportExtX = 1;
77 dc->vportExtY = 1;
78 dc->flags = 0;
79 dc->hClipRgn = 0;
80 dc->hVisRgn = 0;
81 dc->hPen = GetStockObject( BLACK_PEN );
82 dc->hBrush = GetStockObject( WHITE_BRUSH );
83 dc->hFont = GetStockObject( SYSTEM_FONT );
84 dc->hBitmap = 0;
85 dc->hDevice = 0;
86 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
87 dc->gdiFont = 0;
88 dc->ROPmode = R2_COPYPEN;
89 dc->polyFillMode = ALTERNATE;
90 dc->stretchBltMode = BLACKONWHITE;
91 dc->relAbsMode = ABSOLUTE;
92 dc->backgroundMode = OPAQUE;
93 dc->backgroundColor = RGB( 255, 255, 255 );
94 dc->dcBrushColor = RGB( 255, 255, 255 );
95 dc->dcPenColor = RGB( 0, 0, 0 );
96 dc->textColor = RGB( 0, 0, 0 );
97 dc->brushOrgX = 0;
98 dc->brushOrgY = 0;
99 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
100 dc->charExtra = 0;
101 dc->breakExtra = 0;
102 dc->breakRem = 0;
103 dc->MapMode = MM_TEXT;
104 dc->GraphicsMode = GM_COMPATIBLE;
105 dc->pAbortProc = NULL;
106 dc->CursPosX = 0;
107 dc->CursPosY = 0;
108 dc->ArcDirection = AD_COUNTERCLOCKWISE;
109 dc->xformWorld2Wnd.eM11 = 1.0f;
110 dc->xformWorld2Wnd.eM12 = 0.0f;
111 dc->xformWorld2Wnd.eM21 = 0.0f;
112 dc->xformWorld2Wnd.eM22 = 1.0f;
113 dc->xformWorld2Wnd.eDx = 0.0f;
114 dc->xformWorld2Wnd.eDy = 0.0f;
115 dc->xformWorld2Vport = dc->xformWorld2Wnd;
116 dc->xformVport2World = dc->xformWorld2Wnd;
117 dc->vport2WorldValid = TRUE;
118 dc->BoundsRect.left = 0;
119 dc->BoundsRect.top = 0;
120 dc->BoundsRect.right = 0;
121 dc->BoundsRect.bottom = 0;
122 PATH_InitGdiPath(&dc->path);
123 return dc;
128 /***********************************************************************
129 * DC_GetDCPtr
131 DC *DC_GetDCPtr( HDC hdc )
133 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
134 if (!ptr) return NULL;
135 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
136 (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
137 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
138 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
139 return (DC *)ptr;
140 GDI_ReleaseObj( hdc );
141 SetLastError( ERROR_INVALID_HANDLE );
142 return NULL;
145 /***********************************************************************
146 * DC_GetDCUpdate
148 * Retrieve a DC ptr while making sure the visRgn is updated.
149 * This function may call up to USER so the GDI lock should _not_
150 * be held when calling it.
152 DC *DC_GetDCUpdate( HDC hdc )
154 DC *dc = DC_GetDCPtr( hdc );
155 if (!dc) return NULL;
156 while (dc->flags & DC_DIRTY)
158 DCHOOKPROC proc = dc->hookThunk;
159 dc->flags &= ~DC_DIRTY;
160 if (proc)
162 DWORD data = dc->dwHookData;
163 GDI_ReleaseObj( hdc );
164 proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
165 if (!(dc = DC_GetDCPtr( hdc ))) break;
166 /* otherwise restart the loop in case it became dirty again in the meantime */
169 return dc;
173 /***********************************************************************
174 * DC_DeleteObject
176 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
178 GDI_ReleaseObj( handle );
179 return DeleteDC( handle );
183 /***********************************************************************
184 * DC_InitDC
186 * Setup device-specific DC values for a newly created DC.
188 void DC_InitDC( DC* dc )
190 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
191 SetTextColor( dc->hSelf, dc->textColor );
192 SetBkColor( dc->hSelf, dc->backgroundColor );
193 SelectObject( dc->hSelf, dc->hPen );
194 SelectObject( dc->hSelf, dc->hBrush );
195 SelectObject( dc->hSelf, dc->hFont );
196 CLIPPING_UpdateGCRegion( dc );
200 /***********************************************************************
201 * DC_InvertXform
203 * Computes the inverse of the transformation xformSrc and stores it to
204 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
205 * is singular.
207 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
209 FLOAT determinant;
211 determinant = xformSrc->eM11*xformSrc->eM22 -
212 xformSrc->eM12*xformSrc->eM21;
213 if (determinant > -1e-12 && determinant < 1e-12)
214 return FALSE;
216 xformDest->eM11 = xformSrc->eM22 / determinant;
217 xformDest->eM12 = -xformSrc->eM12 / determinant;
218 xformDest->eM21 = -xformSrc->eM21 / determinant;
219 xformDest->eM22 = xformSrc->eM11 / determinant;
220 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
221 xformSrc->eDy * xformDest->eM21;
222 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
223 xformSrc->eDy * xformDest->eM22;
225 return TRUE;
229 /***********************************************************************
230 * DC_UpdateXforms
232 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
233 * fields of the specified DC by creating a transformation that
234 * represents the current mapping mode and combining it with the DC's
235 * world transform. This function should be called whenever the
236 * parameters associated with the mapping mode (window and viewport
237 * extents and origins) or the world transform change.
239 void DC_UpdateXforms( DC *dc )
241 XFORM xformWnd2Vport, oldworld2vport;
242 FLOAT scaleX, scaleY;
244 /* Construct a transformation to do the window-to-viewport conversion */
245 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
246 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
247 xformWnd2Vport.eM11 = scaleX;
248 xformWnd2Vport.eM12 = 0.0;
249 xformWnd2Vport.eM21 = 0.0;
250 xformWnd2Vport.eM22 = scaleY;
251 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
252 scaleX * (FLOAT)dc->wndOrgX;
253 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
254 scaleY * (FLOAT)dc->wndOrgY;
256 oldworld2vport = dc->xformWorld2Vport;
257 /* Combine with the world transformation */
258 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
259 &xformWnd2Vport );
261 /* Create inverse of world-to-viewport transformation */
262 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
263 &dc->xformVport2World );
265 /* Reselect the font back into the dc so that the font size
266 gets updated. */
267 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
268 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
272 /***********************************************************************
273 * GetDCState (Not a Windows API)
275 HDC WINAPI GetDCState( HDC hdc )
277 DC * newdc, * dc;
278 HGDIOBJ handle;
280 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
281 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
283 GDI_ReleaseObj( hdc );
284 return 0;
286 TRACE("(%p): returning %p\n", hdc, handle );
288 newdc->flags = dc->flags | DC_SAVED;
289 newdc->hPen = dc->hPen;
290 newdc->hBrush = dc->hBrush;
291 newdc->hFont = dc->hFont;
292 newdc->hBitmap = dc->hBitmap;
293 newdc->hDevice = dc->hDevice;
294 newdc->hPalette = dc->hPalette;
295 newdc->ROPmode = dc->ROPmode;
296 newdc->polyFillMode = dc->polyFillMode;
297 newdc->stretchBltMode = dc->stretchBltMode;
298 newdc->relAbsMode = dc->relAbsMode;
299 newdc->backgroundMode = dc->backgroundMode;
300 newdc->backgroundColor = dc->backgroundColor;
301 newdc->textColor = dc->textColor;
302 newdc->dcBrushColor = dc->dcBrushColor;
303 newdc->dcPenColor = dc->dcPenColor;
304 newdc->brushOrgX = dc->brushOrgX;
305 newdc->brushOrgY = dc->brushOrgY;
306 newdc->textAlign = dc->textAlign;
307 newdc->charExtra = dc->charExtra;
308 newdc->breakExtra = dc->breakExtra;
309 newdc->breakRem = dc->breakRem;
310 newdc->MapMode = dc->MapMode;
311 newdc->GraphicsMode = dc->GraphicsMode;
312 newdc->CursPosX = dc->CursPosX;
313 newdc->CursPosY = dc->CursPosY;
314 newdc->ArcDirection = dc->ArcDirection;
315 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
316 newdc->xformWorld2Vport = dc->xformWorld2Vport;
317 newdc->xformVport2World = dc->xformVport2World;
318 newdc->vport2WorldValid = dc->vport2WorldValid;
319 newdc->wndOrgX = dc->wndOrgX;
320 newdc->wndOrgY = dc->wndOrgY;
321 newdc->wndExtX = dc->wndExtX;
322 newdc->wndExtY = dc->wndExtY;
323 newdc->vportOrgX = dc->vportOrgX;
324 newdc->vportOrgY = dc->vportOrgY;
325 newdc->vportExtX = dc->vportExtX;
326 newdc->vportExtY = dc->vportExtY;
327 newdc->BoundsRect = dc->BoundsRect;
329 newdc->hSelf = (HDC)handle;
330 newdc->saveLevel = 0;
332 PATH_InitGdiPath( &newdc->path );
334 newdc->pAbortProc = NULL;
335 newdc->hookThunk = NULL;
336 newdc->hookProc = 0;
338 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
340 newdc->hVisRgn = 0;
341 if (dc->hClipRgn)
343 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
344 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
346 else
347 newdc->hClipRgn = 0;
349 if(dc->gdiFont) {
350 newdc->gdiFont = dc->gdiFont;
351 } else
352 newdc->gdiFont = 0;
354 GDI_ReleaseObj( handle );
355 GDI_ReleaseObj( hdc );
356 return handle;
360 /***********************************************************************
361 * SetDCState (Not a Windows API)
363 void WINAPI SetDCState( HDC hdc, HDC hdcs )
365 DC *dc, *dcs;
367 if (!(dc = DC_GetDCUpdate( hdc ))) return;
368 if (!(dcs = DC_GetDCPtr( hdcs )))
370 GDI_ReleaseObj( hdc );
371 return;
373 if (!dcs->flags & DC_SAVED)
375 GDI_ReleaseObj( hdc );
376 GDI_ReleaseObj( hdcs );
377 return;
379 TRACE("%p %p\n", hdc, hdcs );
381 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
382 dc->hDevice = dcs->hDevice;
383 dc->ROPmode = dcs->ROPmode;
384 dc->polyFillMode = dcs->polyFillMode;
385 dc->stretchBltMode = dcs->stretchBltMode;
386 dc->relAbsMode = dcs->relAbsMode;
387 dc->backgroundMode = dcs->backgroundMode;
388 dc->backgroundColor = dcs->backgroundColor;
389 dc->textColor = dcs->textColor;
390 dc->dcBrushColor = dcs->dcBrushColor;
391 dc->dcPenColor = dcs->dcPenColor;
392 dc->brushOrgX = dcs->brushOrgX;
393 dc->brushOrgY = dcs->brushOrgY;
394 dc->textAlign = dcs->textAlign;
395 dc->charExtra = dcs->charExtra;
396 dc->breakExtra = dcs->breakExtra;
397 dc->breakRem = dcs->breakRem;
398 dc->MapMode = dcs->MapMode;
399 dc->GraphicsMode = dcs->GraphicsMode;
400 dc->CursPosX = dcs->CursPosX;
401 dc->CursPosY = dcs->CursPosY;
402 dc->ArcDirection = dcs->ArcDirection;
403 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
404 dc->xformWorld2Vport = dcs->xformWorld2Vport;
405 dc->xformVport2World = dcs->xformVport2World;
406 dc->vport2WorldValid = dcs->vport2WorldValid;
407 dc->BoundsRect = dcs->BoundsRect;
409 dc->wndOrgX = dcs->wndOrgX;
410 dc->wndOrgY = dcs->wndOrgY;
411 dc->wndExtX = dcs->wndExtX;
412 dc->wndExtY = dcs->wndExtY;
413 dc->vportOrgX = dcs->vportOrgX;
414 dc->vportOrgY = dcs->vportOrgY;
415 dc->vportExtX = dcs->vportExtX;
416 dc->vportExtY = dcs->vportExtY;
418 if (dcs->hClipRgn)
420 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
421 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
423 else
425 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
426 dc->hClipRgn = 0;
428 CLIPPING_UpdateGCRegion( dc );
430 SelectObject( hdc, dcs->hBitmap );
431 SelectObject( hdc, dcs->hBrush );
432 SelectObject( hdc, dcs->hFont );
433 SelectObject( hdc, dcs->hPen );
434 SetBkColor( hdc, dcs->backgroundColor);
435 SetTextColor( hdc, dcs->textColor);
436 GDISelectPalette( hdc, dcs->hPalette, FALSE );
437 GDI_ReleaseObj( hdcs );
438 GDI_ReleaseObj( hdc );
442 /***********************************************************************
443 * GetDCState (GDI.179)
445 HDC16 WINAPI GetDCState16( HDC16 hdc )
447 return HDC_16( GetDCState( HDC_32(hdc) ));
451 /***********************************************************************
452 * SetDCState (GDI.180)
454 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
456 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
460 /***********************************************************************
461 * SaveDC (GDI32.@)
463 INT WINAPI SaveDC( HDC hdc )
465 HDC hdcs;
466 DC * dc, * dcs;
467 INT ret;
469 dc = DC_GetDCPtr( hdc );
470 if (!dc) return 0;
472 if(dc->funcs->pSaveDC)
474 ret = dc->funcs->pSaveDC( dc->physDev );
475 GDI_ReleaseObj( hdc );
476 return ret;
479 if (!(hdcs = GetDCState( hdc )))
481 GDI_ReleaseObj( hdc );
482 return 0;
484 dcs = DC_GetDCPtr( hdcs );
486 /* Copy path. The reason why path saving / restoring is in SaveDC/
487 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
488 * functions are only in Win16 (which doesn't have paths) and that
489 * SetDCState doesn't allow us to signal an error (which can happen
490 * when copying paths).
492 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
494 GDI_ReleaseObj( hdc );
495 GDI_ReleaseObj( hdcs );
496 DeleteDC( hdcs );
497 return 0;
500 dcs->header.hNext = dc->header.hNext;
501 dc->header.hNext = HDC_16(hdcs);
502 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
503 ret = ++dc->saveLevel;
504 GDI_ReleaseObj( hdcs );
505 GDI_ReleaseObj( hdc );
506 return ret;
510 /***********************************************************************
511 * RestoreDC (GDI32.@)
513 BOOL WINAPI RestoreDC( HDC hdc, INT level )
515 DC * dc, * dcs;
516 BOOL success;
518 TRACE("%p %d\n", hdc, level );
519 dc = DC_GetDCUpdate( hdc );
520 if(!dc) return FALSE;
521 if(dc->funcs->pRestoreDC)
523 success = dc->funcs->pRestoreDC( dc->physDev, level );
524 GDI_ReleaseObj( hdc );
525 return success;
528 if (level == -1) level = dc->saveLevel;
529 if ((level < 1)
530 /* This pair of checks disagrees with MSDN "Platform SDK:
531 Windows GDI" July 2000 which says all negative values
532 for level will be interpreted as an instance relative
533 to the current state. Restricting it to just -1 does
534 not satisfy this */
535 || (level > dc->saveLevel))
537 GDI_ReleaseObj( hdc );
538 return FALSE;
541 success=TRUE;
542 while (dc->saveLevel >= level)
544 HDC hdcs = HDC_32(dc->header.hNext);
545 if (!(dcs = DC_GetDCPtr( hdcs )))
547 GDI_ReleaseObj( hdc );
548 return FALSE;
550 dc->header.hNext = dcs->header.hNext;
551 if (--dc->saveLevel < level)
553 SetDCState( hdc, hdcs );
554 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
555 /* FIXME: This might not be quite right, since we're
556 * returning FALSE but still destroying the saved DC state */
557 success=FALSE;
559 GDI_ReleaseObj( hdcs );
560 GDI_ReleaseObj( hdc );
561 DeleteDC( hdcs );
562 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
564 GDI_ReleaseObj( hdc );
565 return success;
569 /***********************************************************************
570 * CreateDCW (GDI32.@)
572 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
573 const DEVMODEW *initData )
575 HDC hdc;
576 DC * dc;
577 const DC_FUNCTIONS *funcs;
578 WCHAR buf[300];
580 GDI_CheckNotLock();
582 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
584 if (!driver) return 0;
585 strcpyW(buf, driver);
588 if (!(funcs = DRIVER_load_driver( buf )))
590 ERR( "no driver found for %s\n", debugstr_w(buf) );
591 return 0;
593 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
595 DRIVER_release_driver( funcs );
596 return 0;
598 hdc = dc->hSelf;
600 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
602 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
603 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
605 if (dc->funcs->pCreateDC &&
606 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
608 WARN("creation aborted by device\n" );
609 GDI_FreeObject( dc->hSelf, dc );
610 DRIVER_release_driver( funcs );
611 return 0;
614 dc->hVisRgn = CreateRectRgn( 0, 0, GetDeviceCaps( hdc, HORZRES ),
615 GetDeviceCaps( hdc, VERTRES ) );
617 DC_InitDC( dc );
618 GDI_ReleaseObj( hdc );
619 return hdc;
623 /***********************************************************************
624 * CreateDCA (GDI32.@)
626 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
627 const DEVMODEA *initData )
629 UNICODE_STRING driverW, deviceW, outputW;
630 DEVMODEW *initDataW;
631 HDC ret;
633 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
634 else driverW.Buffer = NULL;
636 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
637 else deviceW.Buffer = NULL;
639 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
640 else outputW.Buffer = NULL;
642 if (initData) initDataW = GdiConvertToDevmodeW(initData);
643 else initDataW = NULL;
645 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
647 RtlFreeUnicodeString(&driverW);
648 RtlFreeUnicodeString(&deviceW);
649 RtlFreeUnicodeString(&outputW);
650 if (initDataW) HeapFree(GetProcessHeap(), 0, initDataW);
651 return ret;
655 /***********************************************************************
656 * CreateICA (GDI32.@)
658 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
659 const DEVMODEA* initData )
661 /* Nothing special yet for ICs */
662 return CreateDCA( driver, device, output, initData );
666 /***********************************************************************
667 * CreateICW (GDI32.@)
669 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
670 const DEVMODEW* initData )
672 /* Nothing special yet for ICs */
673 return CreateDCW( driver, device, output, initData );
677 /***********************************************************************
678 * CreateCompatibleDC (GDI32.@)
680 HDC WINAPI CreateCompatibleDC( HDC hdc )
682 DC *dc, *origDC;
683 const DC_FUNCTIONS *funcs;
684 PHYSDEV physDev;
686 GDI_CheckNotLock();
688 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
690 funcs = origDC->funcs;
691 physDev = origDC->physDev;
692 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
693 funcs = DRIVER_get_driver( funcs );
695 else
697 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
698 funcs = DRIVER_load_driver( displayW );
699 physDev = NULL;
702 if (!funcs) return 0;
704 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
706 DRIVER_release_driver( funcs );
707 return 0;
710 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
712 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
714 /* Copy the driver-specific physical device info into
715 * the new DC. The driver may use this read-only info
716 * while creating the compatible DC below. */
717 dc->physDev = physDev;
719 if (dc->funcs->pCreateDC &&
720 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
722 WARN("creation aborted by device\n");
723 GDI_FreeObject( dc->hSelf, dc );
724 DRIVER_release_driver( funcs );
725 return 0;
728 dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ); /* default bitmap is 1x1 */
730 DC_InitDC( dc );
731 GDI_ReleaseObj( dc->hSelf );
732 return dc->hSelf;
736 /***********************************************************************
737 * DeleteDC (GDI32.@)
739 BOOL WINAPI DeleteDC( HDC hdc )
741 const DC_FUNCTIONS *funcs = NULL;
742 DC * dc;
744 TRACE("%p\n", hdc );
746 GDI_CheckNotLock();
748 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
750 /* Call hook procedure to check whether is it OK to delete this DC */
751 if (dc->hookThunk)
753 DCHOOKPROC proc = dc->hookThunk;
754 DWORD data = dc->dwHookData;
755 GDI_ReleaseObj( hdc );
756 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
757 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
760 while (dc->saveLevel)
762 DC * dcs;
763 HDC hdcs = HDC_32(dc->header.hNext);
764 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
765 dc->header.hNext = dcs->header.hNext;
766 dc->saveLevel--;
767 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
768 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
769 PATH_DestroyGdiPath(&dcs->path);
770 GDI_FreeObject( hdcs, dcs );
773 if (!(dc->flags & DC_SAVED))
775 SelectObject( hdc, GetStockObject(BLACK_PEN) );
776 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
777 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
778 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
779 funcs = dc->funcs;
780 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
781 dc->physDev = NULL;
784 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
785 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
786 PATH_DestroyGdiPath(&dc->path);
788 GDI_FreeObject( hdc, dc );
789 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
790 return TRUE;
794 /***********************************************************************
795 * ResetDCW (GDI32.@)
797 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
799 DC *dc;
800 HDC ret = hdc;
802 if ((dc = DC_GetDCPtr( hdc )))
804 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
805 GDI_ReleaseObj( hdc );
807 return ret;
811 /***********************************************************************
812 * ResetDCA (GDI32.@)
814 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
816 DEVMODEW *devmodeW;
817 HDC ret;
819 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
820 else devmodeW = NULL;
822 ret = ResetDCW(hdc, devmodeW);
824 if (devmodeW) HeapFree(GetProcessHeap(), 0, devmodeW);
825 return ret;
829 /***********************************************************************
830 * GetDeviceCaps (GDI32.@)
832 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
834 DC *dc;
835 INT ret = 0;
837 if ((dc = DC_GetDCPtr( hdc )))
839 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
840 GDI_ReleaseObj( hdc );
842 return ret;
846 /***********************************************************************
847 * SetBkColor (GDI32.@)
849 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
851 COLORREF oldColor;
852 DC * dc = DC_GetDCPtr( hdc );
854 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
856 if (!dc) return CLR_INVALID;
857 oldColor = dc->backgroundColor;
858 if (dc->funcs->pSetBkColor)
860 color = dc->funcs->pSetBkColor(dc->physDev, color);
861 if (color == CLR_INVALID) /* don't change it */
863 color = oldColor;
864 oldColor = CLR_INVALID;
867 dc->backgroundColor = color;
868 GDI_ReleaseObj( hdc );
869 return oldColor;
873 /***********************************************************************
874 * SetTextColor (GDI32.@)
876 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
878 COLORREF oldColor;
879 DC * dc = DC_GetDCPtr( hdc );
881 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
883 if (!dc) return CLR_INVALID;
884 oldColor = dc->textColor;
885 if (dc->funcs->pSetTextColor)
887 color = dc->funcs->pSetTextColor(dc->physDev, color);
888 if (color == CLR_INVALID) /* don't change it */
890 color = oldColor;
891 oldColor = CLR_INVALID;
894 dc->textColor = color;
895 GDI_ReleaseObj( hdc );
896 return oldColor;
900 /***********************************************************************
901 * SetTextAlign (GDI32.@)
903 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
905 UINT prevAlign;
906 DC *dc = DC_GetDCPtr( hdc );
908 TRACE("hdc=%p align=%d\n", hdc, align);
910 if (!dc) return 0x0;
911 if (dc->funcs->pSetTextAlign)
912 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
913 else {
914 prevAlign = dc->textAlign;
915 dc->textAlign = align;
917 GDI_ReleaseObj( hdc );
918 return prevAlign;
921 /***********************************************************************
922 * GetDCOrgEx (GDI32.@)
924 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
926 DC * dc;
928 if (!lpp) return FALSE;
929 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
931 lpp->x = lpp->y = 0;
932 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
933 GDI_ReleaseObj( hDC );
934 return TRUE;
938 /***********************************************************************
939 * SetDCOrg (GDI.117)
941 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
943 DWORD prevOrg = 0;
944 HDC hdc = HDC_32( hdc16 );
945 DC *dc = DC_GetDCPtr( hdc );
946 if (!dc) return 0;
947 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
948 GDI_ReleaseObj( hdc );
949 return prevOrg;
953 /***********************************************************************
954 * SetGraphicsMode (GDI32.@)
956 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
958 INT ret = 0;
959 DC *dc = DC_GetDCPtr( hdc );
961 /* One would think that setting the graphics mode to GM_COMPATIBLE
962 * would also reset the world transformation matrix to the unity
963 * matrix. However, in Windows, this is not the case. This doesn't
964 * make a lot of sense to me, but that's the way it is.
966 if (!dc) return 0;
967 if ((mode > 0) && (mode <= GM_LAST))
969 ret = dc->GraphicsMode;
970 dc->GraphicsMode = mode;
972 GDI_ReleaseObj( hdc );
973 return ret;
977 /***********************************************************************
978 * SetArcDirection (GDI32.@)
980 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
982 DC * dc;
983 INT nOldDirection = 0;
985 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
987 SetLastError(ERROR_INVALID_PARAMETER);
988 return 0;
991 if ((dc = DC_GetDCPtr( hdc )))
993 if (dc->funcs->pSetArcDirection)
995 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
997 nOldDirection = dc->ArcDirection;
998 dc->ArcDirection = nDirection;
999 GDI_ReleaseObj( hdc );
1001 return nOldDirection;
1005 /***********************************************************************
1006 * GetWorldTransform (GDI32.@)
1008 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1010 DC * dc;
1011 if (!xform) return FALSE;
1012 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1013 *xform = dc->xformWorld2Wnd;
1014 GDI_ReleaseObj( hdc );
1015 return TRUE;
1019 /***********************************************************************
1020 * GetTransform (GDI32.@)
1022 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1024 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1025 FIXME("stub: don't know what to do for code %lx\n", unknown );
1026 return FALSE;
1030 /***********************************************************************
1031 * SetWorldTransform (GDI32.@)
1033 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1035 BOOL ret = FALSE;
1036 DC *dc = DC_GetDCPtr( hdc );
1038 if (!dc) return FALSE;
1039 if (!xform) goto done;
1041 /* Check that graphics mode is GM_ADVANCED */
1042 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1044 if (dc->funcs->pSetWorldTransform)
1046 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1047 if (!ret) goto done;
1050 dc->xformWorld2Wnd = *xform;
1051 DC_UpdateXforms( dc );
1052 ret = TRUE;
1053 done:
1054 GDI_ReleaseObj( hdc );
1055 return ret;
1059 /****************************************************************************
1060 * ModifyWorldTransform [GDI32.@]
1061 * Modifies the world transformation for a device context.
1063 * PARAMS
1064 * hdc [I] Handle to device context
1065 * xform [I] XFORM structure that will be used to modify the world
1066 * transformation
1067 * iMode [I] Specifies in what way to modify the world transformation
1068 * Possible values:
1069 * MWT_IDENTITY
1070 * Resets the world transformation to the identity matrix.
1071 * The parameter xform is ignored.
1072 * MWT_LEFTMULTIPLY
1073 * Multiplies xform into the world transformation matrix from
1074 * the left.
1075 * MWT_RIGHTMULTIPLY
1076 * Multiplies xform into the world transformation matrix from
1077 * the right.
1079 * RETURNS
1080 * Success: TRUE.
1081 * Failure: FALSE. Use GetLastError() to determine the cause.
1083 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1084 DWORD iMode )
1086 BOOL ret = FALSE;
1087 DC *dc = DC_GetDCPtr( hdc );
1089 /* Check for illegal parameters */
1090 if (!dc) return FALSE;
1091 if (!xform) goto done;
1093 /* Check that graphics mode is GM_ADVANCED */
1094 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1096 if (dc->funcs->pModifyWorldTransform)
1098 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1099 if (!ret) goto done;
1102 switch (iMode)
1104 case MWT_IDENTITY:
1105 dc->xformWorld2Wnd.eM11 = 1.0f;
1106 dc->xformWorld2Wnd.eM12 = 0.0f;
1107 dc->xformWorld2Wnd.eM21 = 0.0f;
1108 dc->xformWorld2Wnd.eM22 = 1.0f;
1109 dc->xformWorld2Wnd.eDx = 0.0f;
1110 dc->xformWorld2Wnd.eDy = 0.0f;
1111 break;
1112 case MWT_LEFTMULTIPLY:
1113 CombineTransform( &dc->xformWorld2Wnd, xform,
1114 &dc->xformWorld2Wnd );
1115 break;
1116 case MWT_RIGHTMULTIPLY:
1117 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1118 xform );
1119 break;
1120 default:
1121 goto done;
1124 DC_UpdateXforms( dc );
1125 ret = TRUE;
1126 done:
1127 GDI_ReleaseObj( hdc );
1128 return ret;
1132 /****************************************************************************
1133 * CombineTransform [GDI32.@]
1134 * Combines two transformation matrices.
1136 * PARAMS
1137 * xformResult [O] Stores the result of combining the two matrices
1138 * xform1 [I] Specifies the first matrix to apply
1139 * xform2 [I] Specifies the second matrix to apply
1141 * REMARKS
1142 * The same matrix can be passed in for more than one of the parameters.
1144 * RETURNS
1145 * Success: TRUE.
1146 * Failure: FALSE. Use GetLastError() to determine the cause.
1148 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1149 const XFORM *xform2 )
1151 XFORM xformTemp;
1153 /* Check for illegal parameters */
1154 if (!xformResult || !xform1 || !xform2)
1155 return FALSE;
1157 /* Create the result in a temporary XFORM, since xformResult may be
1158 * equal to xform1 or xform2 */
1159 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1160 xform1->eM12 * xform2->eM21;
1161 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1162 xform1->eM12 * xform2->eM22;
1163 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1164 xform1->eM22 * xform2->eM21;
1165 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1166 xform1->eM22 * xform2->eM22;
1167 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1168 xform1->eDy * xform2->eM21 +
1169 xform2->eDx;
1170 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1171 xform1->eDy * xform2->eM22 +
1172 xform2->eDy;
1174 /* Copy the result to xformResult */
1175 *xformResult = xformTemp;
1177 return TRUE;
1181 /***********************************************************************
1182 * SetDCHook (GDI32.@)
1184 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1186 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1188 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1190 if (!dc) return FALSE;
1192 if (!(dc->flags & DC_SAVED))
1194 dc->dwHookData = dwHookData;
1195 dc->hookThunk = hookProc;
1197 GDI_ReleaseObj( hdc );
1198 return TRUE;
1202 /* relay function to call the 16-bit DC hook proc */
1203 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1205 WORD args[6];
1206 DWORD ret;
1207 FARPROC16 proc = NULL;
1208 HDC hdc = HDC_32( hdc16 );
1209 DC *dc = DC_GetDCPtr( hdc );
1211 if (!dc) return FALSE;
1212 proc = dc->hookProc;
1213 GDI_ReleaseObj( hdc );
1214 if (!proc) return FALSE;
1215 args[5] = hdc16;
1216 args[4] = code;
1217 args[3] = HIWORD(data);
1218 args[2] = LOWORD(data);
1219 args[1] = HIWORD(lParam);
1220 args[0] = LOWORD(lParam);
1221 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1222 return LOWORD(ret);
1225 /***********************************************************************
1226 * SetDCHook (GDI.190)
1228 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1230 HDC hdc = HDC_32( hdc16 );
1231 DC *dc = DC_GetDCPtr( hdc );
1232 if (!dc) return FALSE;
1234 dc->hookProc = hookProc;
1235 GDI_ReleaseObj( hdc );
1236 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1240 /***********************************************************************
1241 * GetDCHook (GDI.191)
1243 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1245 HDC hdc = HDC_32( hdc16 );
1246 DC *dc = DC_GetDCPtr( hdc );
1247 DWORD ret;
1249 if (!dc) return 0;
1250 *phookProc = dc->hookProc;
1251 ret = dc->dwHookData;
1252 GDI_ReleaseObj( hdc );
1253 return ret;
1257 /***********************************************************************
1258 * SetHookFlags (GDI.192)
1260 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1262 HDC hdc = HDC_32( hdc16 );
1263 DC *dc = DC_GetDCPtr( hdc );
1265 if( dc )
1267 WORD wRet = dc->flags & DC_DIRTY;
1269 /* "Undocumented Windows" info is slightly confusing.
1272 TRACE("hDC %p, flags %04x\n",hdc,flags);
1274 if( flags & DCHF_INVALIDATEVISRGN )
1275 dc->flags |= DC_DIRTY;
1276 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1277 dc->flags &= ~DC_DIRTY;
1278 GDI_ReleaseObj( hdc );
1279 return wRet;
1281 return 0;
1284 /***********************************************************************
1285 * SetICMMode (GDI32.@)
1287 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1289 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1290 if (iEnableICM == ICM_OFF) return ICM_OFF;
1291 if (iEnableICM == ICM_ON) return 0;
1292 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1293 return 0;
1296 /***********************************************************************
1297 * GetDeviceGammaRamp (GDI32.@)
1299 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1301 BOOL ret = FALSE;
1302 DC *dc = DC_GetDCPtr( hDC );
1304 if( dc )
1306 if (dc->funcs->pGetDeviceGammaRamp)
1307 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1308 GDI_ReleaseObj( hDC );
1310 return ret;
1313 /***********************************************************************
1314 * SetDeviceGammaRamp (GDI32.@)
1316 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1318 BOOL ret = FALSE;
1319 DC *dc = DC_GetDCPtr( hDC );
1321 if( dc )
1323 if (dc->funcs->pSetDeviceGammaRamp)
1324 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1325 GDI_ReleaseObj( hDC );
1327 return ret;
1330 /***********************************************************************
1331 * GetColorSpace (GDI32.@)
1333 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1335 /*FIXME Need to to whatever GetColorSpace actually does */
1336 return 0;
1339 /***********************************************************************
1340 * CreateColorSpaceA (GDI32.@)
1342 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1344 FIXME( "stub\n" );
1345 return 0;
1348 /***********************************************************************
1349 * CreateColorSpaceW (GDI32.@)
1351 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1353 FIXME( "stub\n" );
1354 return 0;
1357 /***********************************************************************
1358 * DeleteColorSpace (GDI32.@)
1360 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1362 FIXME( "stub\n" );
1364 return TRUE;
1367 /***********************************************************************
1368 * SetColorSpace (GDI32.@)
1370 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1372 FIXME( "stub\n" );
1374 return hColorSpace;
1377 /***********************************************************************
1378 * GetBoundsRect (GDI32.@)
1380 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1382 UINT ret;
1383 DC *dc = DC_GetDCPtr( hdc );
1385 if ( !dc ) return 0;
1387 if (rect) *rect = dc->BoundsRect;
1389 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1391 if (flags & DCB_RESET)
1393 dc->BoundsRect.left = 0;
1394 dc->BoundsRect.top = 0;
1395 dc->BoundsRect.right = 0;
1396 dc->BoundsRect.bottom = 0;
1397 dc->flags &= ~DC_BOUNDS_SET;
1399 GDI_ReleaseObj( hdc );
1400 return ret;
1404 /***********************************************************************
1405 * SetBoundsRect (GDI32.@)
1407 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1409 UINT ret;
1410 DC *dc;
1412 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1413 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
1415 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1416 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1418 if (flags & DCB_RESET)
1420 dc->BoundsRect.left = 0;
1421 dc->BoundsRect.top = 0;
1422 dc->BoundsRect.right = 0;
1423 dc->BoundsRect.bottom = 0;
1424 dc->flags &= ~DC_BOUNDS_SET;
1427 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1429 if (dc->flags & DC_BOUNDS_SET)
1431 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1432 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1433 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1434 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1436 else
1438 dc->BoundsRect = *rect;
1439 dc->flags |= DC_BOUNDS_SET;
1443 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1444 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1446 GDI_ReleaseObj( hdc );
1447 return ret;
1451 /***********************************************************************
1452 * GetRelAbs (GDI32.@)
1454 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1456 INT ret = 0;
1457 DC *dc = DC_GetDCPtr( hdc );
1458 if (dc) ret = dc->relAbsMode;
1459 GDI_ReleaseObj( hdc );
1460 return ret;
1463 /***********************************************************************
1464 * GetLayout (GDI32.@)
1466 * Gets left->right or right->left text layout flags of a dc.
1467 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1470 DWORD WINAPI GetLayout(HDC hdc)
1472 FIXME("(%p): stub\n", hdc);
1473 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1474 return 0;
1477 /***********************************************************************
1478 * SetLayout (GDI32.@)
1480 * Sets left->right or right->left text layout flags of a dc.
1481 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1484 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1486 FIXME("(%p,%08lx): stub\n", hdc, layout);
1487 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1488 return 0;
1491 /***********************************************************************
1492 * GetDCBrushColor (GDI32.@)
1494 * Retrieves the current brush color for the specified device
1495 * context (DC).
1498 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1500 DC *dc;
1501 COLORREF dcBrushColor = CLR_INVALID;
1503 TRACE("hdc(%p)\n", hdc);
1505 dc = DC_GetDCPtr( hdc );
1506 if (dc)
1508 dcBrushColor = dc->dcBrushColor;
1509 GDI_ReleaseObj( hdc );
1512 return dcBrushColor;
1515 /***********************************************************************
1516 * SetDCBrushColor (GDI32.@)
1518 * Sets the current device context (DC) brush color to the specified
1519 * color value. If the device cannot represent the specified color
1520 * value, the color is set to the nearest physical color.
1523 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1525 DC *dc;
1526 COLORREF oldClr = CLR_INVALID;
1528 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1530 dc = DC_GetDCPtr( hdc );
1531 if (dc)
1533 if (dc->funcs->pSetDCBrushColor)
1534 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
1535 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
1537 /* If DC_BRUSH is selected, update driver pen color */
1538 HBRUSH hBrush = CreateSolidBrush( crColor );
1539 dc->funcs->pSelectBrush( dc->physDev, hBrush );
1540 DeleteObject( hBrush );
1543 if (crColor != CLR_INVALID)
1545 oldClr = dc->dcBrushColor;
1546 dc->dcBrushColor = crColor;
1549 GDI_ReleaseObj( hdc );
1552 return oldClr;
1555 /***********************************************************************
1556 * GetDCPenColor (GDI32.@)
1558 * Retrieves the current pen color for the specified device
1559 * context (DC).
1562 COLORREF WINAPI GetDCPenColor(HDC hdc)
1564 DC *dc;
1565 COLORREF dcPenColor = CLR_INVALID;
1567 TRACE("hdc(%p)\n", hdc);
1569 dc = DC_GetDCPtr( hdc );
1570 if (dc)
1572 dcPenColor = dc->dcPenColor;
1573 GDI_ReleaseObj( hdc );
1576 return dcPenColor;
1579 /***********************************************************************
1580 * SetDCPenColor (GDI32.@)
1582 * Sets the current device context (DC) pen color to the specified
1583 * color value. If the device cannot represent the specified color
1584 * value, the color is set to the nearest physical color.
1587 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1589 DC *dc;
1590 COLORREF oldClr = CLR_INVALID;
1592 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1594 dc = DC_GetDCPtr( hdc );
1595 if (dc)
1597 if (dc->funcs->pSetDCPenColor)
1598 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
1599 else if (dc->hPen == GetStockObject( DC_PEN ))
1601 /* If DC_PEN is selected, update the driver pen color */
1602 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
1603 HPEN hPen = CreatePenIndirect( &logpen );
1604 dc->funcs->pSelectPen( dc->physDev, hPen );
1605 DeleteObject( hPen );
1608 if (crColor != CLR_INVALID)
1610 oldClr = dc->dcPenColor;
1611 dc->dcPenColor = crColor;
1614 GDI_ReleaseObj( hdc );
1617 return oldClr;
1620 /***********************************************************************
1621 * SetVirtualResolution (GDI32.@)
1623 * Undocumented on msdn. Called when PowerPoint XP saves a file.
1625 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
1627 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
1628 return FALSE;