Added a new flag to wrc, to be used to assess translations
[wine/hacks.git] / objects / dc.c
blob1424b20b9f66c819879fdc210a19daa8982b07ca
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->hGCClipRgn = 0;
82 dc->hPen = GetStockObject( BLACK_PEN );
83 dc->hBrush = GetStockObject( WHITE_BRUSH );
84 dc->hFont = GetStockObject( SYSTEM_FONT );
85 dc->hBitmap = 0;
86 dc->hDevice = 0;
87 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
88 dc->gdiFont = 0;
89 dc->ROPmode = R2_COPYPEN;
90 dc->polyFillMode = ALTERNATE;
91 dc->stretchBltMode = BLACKONWHITE;
92 dc->relAbsMode = ABSOLUTE;
93 dc->backgroundMode = OPAQUE;
94 dc->backgroundColor = RGB( 255, 255, 255 );
95 dc->dcBrushColor = RGB( 255, 255, 255 );
96 dc->dcPenColor = RGB( 0, 0, 0 );
97 dc->textColor = RGB( 0, 0, 0 );
98 dc->brushOrgX = 0;
99 dc->brushOrgY = 0;
100 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
101 dc->charExtra = 0;
102 dc->breakTotalExtra = 0;
103 dc->breakCount = 0;
104 dc->breakExtra = 0;
105 dc->breakRem = 0;
106 dc->totalExtent.left = 0;
107 dc->totalExtent.top = 0;
108 dc->totalExtent.right = 0;
109 dc->totalExtent.bottom = 0;
110 dc->MapMode = MM_TEXT;
111 dc->GraphicsMode = GM_COMPATIBLE;
112 dc->pAbortProc = NULL;
113 dc->CursPosX = 0;
114 dc->CursPosY = 0;
115 dc->ArcDirection = AD_COUNTERCLOCKWISE;
116 dc->xformWorld2Wnd.eM11 = 1.0f;
117 dc->xformWorld2Wnd.eM12 = 0.0f;
118 dc->xformWorld2Wnd.eM21 = 0.0f;
119 dc->xformWorld2Wnd.eM22 = 1.0f;
120 dc->xformWorld2Wnd.eDx = 0.0f;
121 dc->xformWorld2Wnd.eDy = 0.0f;
122 dc->xformWorld2Vport = dc->xformWorld2Wnd;
123 dc->xformVport2World = dc->xformWorld2Wnd;
124 dc->vport2WorldValid = TRUE;
125 PATH_InitGdiPath(&dc->path);
126 return dc;
131 /***********************************************************************
132 * DC_GetDCPtr
134 DC *DC_GetDCPtr( HDC hdc )
136 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
137 if (!ptr) return NULL;
138 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
139 (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
140 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
141 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
142 return (DC *)ptr;
143 GDI_ReleaseObj( hdc );
144 SetLastError( ERROR_INVALID_HANDLE );
145 return NULL;
148 /***********************************************************************
149 * DC_GetDCUpdate
151 * Retrieve a DC ptr while making sure the visRgn is updated.
152 * This function may call up to USER so the GDI lock should _not_
153 * be held when calling it.
155 DC *DC_GetDCUpdate( HDC hdc )
157 DC *dc = DC_GetDCPtr( hdc );
158 if (!dc) return NULL;
159 while (dc->flags & DC_DIRTY)
161 DCHOOKPROC proc = dc->hookThunk;
162 dc->flags &= ~DC_DIRTY;
163 if (proc)
165 DWORD data = dc->dwHookData;
166 GDI_ReleaseObj( hdc );
167 proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
168 if (!(dc = DC_GetDCPtr( hdc ))) break;
169 /* otherwise restart the loop in case it became dirty again in the meantime */
172 return dc;
176 /***********************************************************************
177 * DC_DeleteObject
179 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
181 GDI_ReleaseObj( handle );
182 return DeleteDC( handle );
186 /***********************************************************************
187 * DC_InitDC
189 * Setup device-specific DC values for a newly created DC.
191 void DC_InitDC( DC* dc )
193 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
194 SetTextColor( dc->hSelf, dc->textColor );
195 SetBkColor( dc->hSelf, dc->backgroundColor );
196 SelectObject( dc->hSelf, dc->hPen );
197 SelectObject( dc->hSelf, dc->hBrush );
198 SelectObject( dc->hSelf, dc->hFont );
199 CLIPPING_UpdateGCRegion( dc );
203 /***********************************************************************
204 * DC_InvertXform
206 * Computes the inverse of the transformation xformSrc and stores it to
207 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
208 * is singular.
210 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
212 FLOAT determinant;
214 determinant = xformSrc->eM11*xformSrc->eM22 -
215 xformSrc->eM12*xformSrc->eM21;
216 if (determinant > -1e-12 && determinant < 1e-12)
217 return FALSE;
219 xformDest->eM11 = xformSrc->eM22 / determinant;
220 xformDest->eM12 = -xformSrc->eM12 / determinant;
221 xformDest->eM21 = -xformSrc->eM21 / determinant;
222 xformDest->eM22 = xformSrc->eM11 / determinant;
223 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
224 xformSrc->eDy * xformDest->eM21;
225 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
226 xformSrc->eDy * xformDest->eM22;
228 return TRUE;
232 /***********************************************************************
233 * DC_UpdateXforms
235 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
236 * fields of the specified DC by creating a transformation that
237 * represents the current mapping mode and combining it with the DC's
238 * world transform. This function should be called whenever the
239 * parameters associated with the mapping mode (window and viewport
240 * extents and origins) or the world transform change.
242 void DC_UpdateXforms( DC *dc )
244 XFORM xformWnd2Vport, oldworld2vport;
245 FLOAT scaleX, scaleY;
247 /* Construct a transformation to do the window-to-viewport conversion */
248 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
249 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
250 xformWnd2Vport.eM11 = scaleX;
251 xformWnd2Vport.eM12 = 0.0;
252 xformWnd2Vport.eM21 = 0.0;
253 xformWnd2Vport.eM22 = scaleY;
254 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
255 scaleX * (FLOAT)dc->wndOrgX;
256 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
257 scaleY * (FLOAT)dc->wndOrgY;
259 oldworld2vport = dc->xformWorld2Vport;
260 /* Combine with the world transformation */
261 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
262 &xformWnd2Vport );
264 /* Create inverse of world-to-viewport transformation */
265 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
266 &dc->xformVport2World );
268 /* Reselect the font back into the dc so that the font size
269 gets updated. */
270 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
271 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
275 /***********************************************************************
276 * GetDCState (Not a Windows API)
278 HDC WINAPI GetDCState( HDC hdc )
280 DC * newdc, * dc;
281 HGDIOBJ handle;
283 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
284 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
286 GDI_ReleaseObj( hdc );
287 return 0;
289 TRACE("(%p): returning %p\n", hdc, handle );
291 newdc->flags = dc->flags | DC_SAVED;
292 newdc->hPen = dc->hPen;
293 newdc->hBrush = dc->hBrush;
294 newdc->hFont = dc->hFont;
295 newdc->hBitmap = dc->hBitmap;
296 newdc->hDevice = dc->hDevice;
297 newdc->hPalette = dc->hPalette;
298 newdc->totalExtent = dc->totalExtent;
299 newdc->ROPmode = dc->ROPmode;
300 newdc->polyFillMode = dc->polyFillMode;
301 newdc->stretchBltMode = dc->stretchBltMode;
302 newdc->relAbsMode = dc->relAbsMode;
303 newdc->backgroundMode = dc->backgroundMode;
304 newdc->backgroundColor = dc->backgroundColor;
305 newdc->textColor = dc->textColor;
306 newdc->dcBrushColor = dc->dcBrushColor;
307 newdc->dcPenColor = dc->dcPenColor;
308 newdc->brushOrgX = dc->brushOrgX;
309 newdc->brushOrgY = dc->brushOrgY;
310 newdc->textAlign = dc->textAlign;
311 newdc->charExtra = dc->charExtra;
312 newdc->breakTotalExtra = dc->breakTotalExtra;
313 newdc->breakCount = dc->breakCount;
314 newdc->breakExtra = dc->breakExtra;
315 newdc->breakRem = dc->breakRem;
316 newdc->MapMode = dc->MapMode;
317 newdc->GraphicsMode = dc->GraphicsMode;
318 newdc->CursPosX = dc->CursPosX;
319 newdc->CursPosY = dc->CursPosY;
320 newdc->ArcDirection = dc->ArcDirection;
321 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
322 newdc->xformWorld2Vport = dc->xformWorld2Vport;
323 newdc->xformVport2World = dc->xformVport2World;
324 newdc->vport2WorldValid = dc->vport2WorldValid;
325 newdc->wndOrgX = dc->wndOrgX;
326 newdc->wndOrgY = dc->wndOrgY;
327 newdc->wndExtX = dc->wndExtX;
328 newdc->wndExtY = dc->wndExtY;
329 newdc->vportOrgX = dc->vportOrgX;
330 newdc->vportOrgY = dc->vportOrgY;
331 newdc->vportExtX = dc->vportExtX;
332 newdc->vportExtY = dc->vportExtY;
334 newdc->hSelf = (HDC)handle;
335 newdc->saveLevel = 0;
337 PATH_InitGdiPath( &newdc->path );
339 newdc->pAbortProc = NULL;
340 newdc->hookThunk = NULL;
341 newdc->hookProc = 0;
343 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
345 newdc->hGCClipRgn = newdc->hVisRgn = 0;
346 if (dc->hClipRgn)
348 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
349 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
351 else
352 newdc->hClipRgn = 0;
354 if(dc->gdiFont) {
355 newdc->gdiFont = dc->gdiFont;
356 } else
357 newdc->gdiFont = 0;
359 GDI_ReleaseObj( handle );
360 GDI_ReleaseObj( hdc );
361 return handle;
365 /***********************************************************************
366 * SetDCState (Not a Windows API)
368 void WINAPI SetDCState( HDC hdc, HDC hdcs )
370 DC *dc, *dcs;
372 if (!(dc = DC_GetDCUpdate( hdc ))) return;
373 if (!(dcs = DC_GetDCPtr( hdcs )))
375 GDI_ReleaseObj( hdc );
376 return;
378 if (!dcs->flags & DC_SAVED)
380 GDI_ReleaseObj( hdc );
381 GDI_ReleaseObj( hdcs );
382 return;
384 TRACE("%p %p\n", hdc, hdcs );
386 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
387 dc->hDevice = dcs->hDevice;
388 dc->totalExtent = dcs->totalExtent;
389 dc->ROPmode = dcs->ROPmode;
390 dc->polyFillMode = dcs->polyFillMode;
391 dc->stretchBltMode = dcs->stretchBltMode;
392 dc->relAbsMode = dcs->relAbsMode;
393 dc->backgroundMode = dcs->backgroundMode;
394 dc->backgroundColor = dcs->backgroundColor;
395 dc->textColor = dcs->textColor;
396 dc->dcBrushColor = dcs->dcBrushColor;
397 dc->dcPenColor = dcs->dcPenColor;
398 dc->brushOrgX = dcs->brushOrgX;
399 dc->brushOrgY = dcs->brushOrgY;
400 dc->textAlign = dcs->textAlign;
401 dc->charExtra = dcs->charExtra;
402 dc->breakTotalExtra = dcs->breakTotalExtra;
403 dc->breakCount = dcs->breakCount;
404 dc->breakExtra = dcs->breakExtra;
405 dc->breakRem = dcs->breakRem;
406 dc->MapMode = dcs->MapMode;
407 dc->GraphicsMode = dcs->GraphicsMode;
408 dc->CursPosX = dcs->CursPosX;
409 dc->CursPosY = dcs->CursPosY;
410 dc->ArcDirection = dcs->ArcDirection;
411 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
412 dc->xformWorld2Vport = dcs->xformWorld2Vport;
413 dc->xformVport2World = dcs->xformVport2World;
414 dc->vport2WorldValid = dcs->vport2WorldValid;
416 dc->wndOrgX = dcs->wndOrgX;
417 dc->wndOrgY = dcs->wndOrgY;
418 dc->wndExtX = dcs->wndExtX;
419 dc->wndExtY = dcs->wndExtY;
420 dc->vportOrgX = dcs->vportOrgX;
421 dc->vportOrgY = dcs->vportOrgY;
422 dc->vportExtX = dcs->vportExtX;
423 dc->vportExtY = dcs->vportExtY;
425 if (dcs->hClipRgn)
427 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
428 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
430 else
432 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
433 dc->hClipRgn = 0;
435 CLIPPING_UpdateGCRegion( dc );
437 SelectObject( hdc, dcs->hBitmap );
438 SelectObject( hdc, dcs->hBrush );
439 SelectObject( hdc, dcs->hFont );
440 SelectObject( hdc, dcs->hPen );
441 SetBkColor( hdc, dcs->backgroundColor);
442 SetTextColor( hdc, dcs->textColor);
443 GDISelectPalette( hdc, dcs->hPalette, FALSE );
444 GDI_ReleaseObj( hdcs );
445 GDI_ReleaseObj( hdc );
449 /***********************************************************************
450 * GetDCState (GDI.179)
452 HDC16 WINAPI GetDCState16( HDC16 hdc )
454 return HDC_16( GetDCState( HDC_32(hdc) ));
458 /***********************************************************************
459 * SetDCState (GDI.180)
461 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
463 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
467 /***********************************************************************
468 * SaveDC (GDI32.@)
470 INT WINAPI SaveDC( HDC hdc )
472 HDC hdcs;
473 DC * dc, * dcs;
474 INT ret;
476 dc = DC_GetDCPtr( hdc );
477 if (!dc) return 0;
479 if(dc->funcs->pSaveDC)
481 ret = dc->funcs->pSaveDC( dc->physDev );
482 GDI_ReleaseObj( hdc );
483 return ret;
486 if (!(hdcs = GetDCState( hdc )))
488 GDI_ReleaseObj( hdc );
489 return 0;
491 dcs = DC_GetDCPtr( hdcs );
493 /* Copy path. The reason why path saving / restoring is in SaveDC/
494 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
495 * functions are only in Win16 (which doesn't have paths) and that
496 * SetDCState doesn't allow us to signal an error (which can happen
497 * when copying paths).
499 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
501 GDI_ReleaseObj( hdc );
502 GDI_ReleaseObj( hdcs );
503 DeleteDC( hdcs );
504 return 0;
507 dcs->header.hNext = dc->header.hNext;
508 dc->header.hNext = HDC_16(hdcs);
509 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
510 ret = ++dc->saveLevel;
511 GDI_ReleaseObj( hdcs );
512 GDI_ReleaseObj( hdc );
513 return ret;
517 /***********************************************************************
518 * RestoreDC (GDI32.@)
520 BOOL WINAPI RestoreDC( HDC hdc, INT level )
522 DC * dc, * dcs;
523 BOOL success;
525 TRACE("%p %d\n", hdc, level );
526 dc = DC_GetDCUpdate( hdc );
527 if(!dc) return FALSE;
528 if(dc->funcs->pRestoreDC)
530 success = dc->funcs->pRestoreDC( dc->physDev, level );
531 GDI_ReleaseObj( hdc );
532 return success;
535 if (level == -1) level = dc->saveLevel;
536 if ((level < 1)
537 /* This pair of checks disagrees with MSDN "Platform SDK:
538 Windows GDI" July 2000 which says all negative values
539 for level will be interpreted as an instance relative
540 to the current state. Restricting it to just -1 does
541 not satisfy this */
542 || (level > dc->saveLevel))
544 GDI_ReleaseObj( hdc );
545 return FALSE;
548 success=TRUE;
549 while (dc->saveLevel >= level)
551 HDC hdcs = HDC_32(dc->header.hNext);
552 if (!(dcs = DC_GetDCPtr( hdcs )))
554 GDI_ReleaseObj( hdc );
555 return FALSE;
557 dc->header.hNext = dcs->header.hNext;
558 if (--dc->saveLevel < level)
560 SetDCState( hdc, hdcs );
561 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
562 /* FIXME: This might not be quite right, since we're
563 * returning FALSE but still destroying the saved DC state */
564 success=FALSE;
566 GDI_ReleaseObj( hdcs );
567 GDI_ReleaseObj( hdc );
568 DeleteDC( hdcs );
569 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
571 GDI_ReleaseObj( hdc );
572 return success;
576 /***********************************************************************
577 * CreateDCW (GDI32.@)
579 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
580 const DEVMODEW *initData )
582 HDC hdc;
583 DC * dc;
584 const DC_FUNCTIONS *funcs;
585 WCHAR buf[300];
587 GDI_CheckNotLock();
589 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
591 if (!driver) return 0;
592 strcpyW(buf, driver);
595 if (!(funcs = DRIVER_load_driver( buf )))
597 ERR( "no driver found for %s\n", debugstr_w(buf) );
598 return 0;
600 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
602 DRIVER_release_driver( funcs );
603 return 0;
606 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
608 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
609 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
611 if (dc->funcs->pCreateDC &&
612 !dc->funcs->pCreateDC( dc, &dc->physDev, buf, device, output, initData ))
614 WARN("creation aborted by device\n" );
615 GDI_FreeObject( dc->hSelf, dc );
616 DRIVER_release_driver( funcs );
617 return 0;
620 dc->totalExtent.left = 0;
621 dc->totalExtent.top = 0;
622 dc->totalExtent.right = GetDeviceCaps( dc->hSelf, HORZRES );
623 dc->totalExtent.bottom = GetDeviceCaps( dc->hSelf, VERTRES );
624 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
626 DC_InitDC( dc );
627 hdc = dc->hSelf;
628 GDI_ReleaseObj( hdc );
629 return hdc;
633 /***********************************************************************
634 * CreateDCA (GDI32.@)
636 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
637 const DEVMODEA *initData )
639 UNICODE_STRING driverW, deviceW, outputW;
640 DEVMODEW *initDataW;
641 HDC ret;
643 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
644 else driverW.Buffer = NULL;
646 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
647 else deviceW.Buffer = NULL;
649 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
650 else outputW.Buffer = NULL;
652 if (initData) initDataW = GdiConvertToDevmodeW(initData);
653 else initDataW = NULL;
655 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
657 RtlFreeUnicodeString(&driverW);
658 RtlFreeUnicodeString(&deviceW);
659 RtlFreeUnicodeString(&outputW);
660 if (initDataW) HeapFree(GetProcessHeap(), 0, initDataW);
661 return ret;
665 /***********************************************************************
666 * CreateICA (GDI32.@)
668 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
669 const DEVMODEA* initData )
671 /* Nothing special yet for ICs */
672 return CreateDCA( driver, device, output, initData );
676 /***********************************************************************
677 * CreateICW (GDI32.@)
679 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
680 const DEVMODEW* initData )
682 /* Nothing special yet for ICs */
683 return CreateDCW( driver, device, output, initData );
687 /***********************************************************************
688 * CreateCompatibleDC (GDI32.@)
690 HDC WINAPI CreateCompatibleDC( HDC hdc )
692 DC *dc, *origDC;
693 const DC_FUNCTIONS *funcs;
694 PHYSDEV physDev;
696 GDI_CheckNotLock();
698 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
700 funcs = origDC->funcs;
701 physDev = origDC->physDev;
702 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
703 funcs = DRIVER_get_driver( funcs );
705 else
707 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
708 funcs = DRIVER_load_driver( displayW );
709 physDev = NULL;
712 if (!funcs) return 0;
714 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
716 DRIVER_release_driver( funcs );
717 return 0;
720 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
722 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
724 /* Copy the driver-specific physical device info into
725 * the new DC. The driver may use this read-only info
726 * while creating the compatible DC below. */
727 dc->physDev = physDev;
729 if (dc->funcs->pCreateDC &&
730 !dc->funcs->pCreateDC( dc, &dc->physDev, NULL, NULL, NULL, NULL ))
732 WARN("creation aborted by device\n");
733 GDI_FreeObject( dc->hSelf, dc );
734 DRIVER_release_driver( funcs );
735 return 0;
738 dc->totalExtent.left = 0;
739 dc->totalExtent.top = 0;
740 dc->totalExtent.right = 1; /* default bitmap is 1x1 */
741 dc->totalExtent.bottom = 1;
742 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
744 DC_InitDC( dc );
745 GDI_ReleaseObj( dc->hSelf );
746 return dc->hSelf;
750 /***********************************************************************
751 * DeleteDC (GDI32.@)
753 BOOL WINAPI DeleteDC( HDC hdc )
755 const DC_FUNCTIONS *funcs = NULL;
756 DC * dc;
758 TRACE("%p\n", hdc );
760 GDI_CheckNotLock();
762 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
764 /* Call hook procedure to check whether is it OK to delete this DC */
765 if (dc->hookThunk)
767 DCHOOKPROC proc = dc->hookThunk;
768 DWORD data = dc->dwHookData;
769 GDI_ReleaseObj( hdc );
770 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
771 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
774 while (dc->saveLevel)
776 DC * dcs;
777 HDC hdcs = HDC_32(dc->header.hNext);
778 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
779 dc->header.hNext = dcs->header.hNext;
780 dc->saveLevel--;
781 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
782 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
783 if (dcs->hGCClipRgn) DeleteObject( dcs->hGCClipRgn );
784 PATH_DestroyGdiPath(&dcs->path);
785 GDI_FreeObject( hdcs, dcs );
788 if (!(dc->flags & DC_SAVED))
790 SelectObject( hdc, GetStockObject(BLACK_PEN) );
791 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
792 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
793 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
794 funcs = dc->funcs;
795 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
796 dc->physDev = NULL;
799 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
800 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
801 if (dc->hGCClipRgn) DeleteObject( dc->hGCClipRgn );
802 PATH_DestroyGdiPath(&dc->path);
804 GDI_FreeObject( hdc, dc );
805 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
806 return TRUE;
810 /***********************************************************************
811 * ResetDCW (GDI32.@)
813 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
815 DC *dc;
816 HDC ret = hdc;
818 if ((dc = DC_GetDCPtr( hdc )))
820 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
821 GDI_ReleaseObj( hdc );
823 return ret;
827 /***********************************************************************
828 * ResetDCA (GDI32.@)
830 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
832 DEVMODEW *devmodeW;
833 HDC ret;
835 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
836 else devmodeW = NULL;
838 ret = ResetDCW(hdc, devmodeW);
840 if (devmodeW) HeapFree(GetProcessHeap(), 0, devmodeW);
841 return ret;
845 /***********************************************************************
846 * GetDeviceCaps (GDI32.@)
848 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
850 DC *dc;
851 INT ret = 0;
853 if ((dc = DC_GetDCPtr( hdc )))
855 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
856 GDI_ReleaseObj( hdc );
858 return ret;
862 /***********************************************************************
863 * SetBkColor (GDI32.@)
865 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
867 COLORREF oldColor;
868 DC * dc = DC_GetDCPtr( hdc );
870 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
872 if (!dc) return CLR_INVALID;
873 oldColor = dc->backgroundColor;
874 if (dc->funcs->pSetBkColor)
876 color = dc->funcs->pSetBkColor(dc->physDev, color);
877 if (color == CLR_INVALID) /* don't change it */
879 color = oldColor;
880 oldColor = CLR_INVALID;
883 dc->backgroundColor = color;
884 GDI_ReleaseObj( hdc );
885 return oldColor;
889 /***********************************************************************
890 * SetTextColor (GDI32.@)
892 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
894 COLORREF oldColor;
895 DC * dc = DC_GetDCPtr( hdc );
897 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
899 if (!dc) return CLR_INVALID;
900 oldColor = dc->textColor;
901 if (dc->funcs->pSetTextColor)
903 color = dc->funcs->pSetTextColor(dc->physDev, color);
904 if (color == CLR_INVALID) /* don't change it */
906 color = oldColor;
907 oldColor = CLR_INVALID;
910 dc->textColor = color;
911 GDI_ReleaseObj( hdc );
912 return oldColor;
916 /***********************************************************************
917 * SetTextAlign (GDI32.@)
919 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
921 UINT prevAlign;
922 DC *dc = DC_GetDCPtr( hdc );
924 TRACE("hdc=%p align=%d\n", hdc, align);
926 if (!dc) return 0x0;
927 if (dc->funcs->pSetTextAlign)
928 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
929 else {
930 prevAlign = dc->textAlign;
931 dc->textAlign = align;
933 GDI_ReleaseObj( hdc );
934 return prevAlign;
937 /***********************************************************************
938 * GetDCOrgEx (GDI32.@)
940 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
942 DC * dc;
944 if (!lpp) return FALSE;
945 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
947 lpp->x = lpp->y = 0;
948 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
949 GDI_ReleaseObj( hDC );
950 return TRUE;
954 /***********************************************************************
955 * SetDCOrg (GDI.117)
957 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
959 DWORD prevOrg = 0;
960 HDC hdc = HDC_32( hdc16 );
961 DC *dc = DC_GetDCPtr( hdc );
962 if (!dc) return 0;
963 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
964 GDI_ReleaseObj( hdc );
965 return prevOrg;
969 /***********************************************************************
970 * SetGraphicsMode (GDI32.@)
972 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
974 INT ret = 0;
975 DC *dc = DC_GetDCPtr( hdc );
977 /* One would think that setting the graphics mode to GM_COMPATIBLE
978 * would also reset the world transformation matrix to the unity
979 * matrix. However, in Windows, this is not the case. This doesn't
980 * make a lot of sense to me, but that's the way it is.
982 if (!dc) return 0;
983 if ((mode > 0) && (mode <= GM_LAST))
985 ret = dc->GraphicsMode;
986 dc->GraphicsMode = mode;
988 GDI_ReleaseObj( hdc );
989 return ret;
993 /***********************************************************************
994 * SetArcDirection (GDI32.@)
996 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
998 DC * dc;
999 INT nOldDirection = 0;
1001 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1003 SetLastError(ERROR_INVALID_PARAMETER);
1004 return 0;
1007 if ((dc = DC_GetDCPtr( hdc )))
1009 if (dc->funcs->pSetArcDirection)
1011 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1013 nOldDirection = dc->ArcDirection;
1014 dc->ArcDirection = nDirection;
1015 GDI_ReleaseObj( hdc );
1017 return nOldDirection;
1021 /***********************************************************************
1022 * GetWorldTransform (GDI32.@)
1024 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1026 DC * dc;
1027 if (!xform) return FALSE;
1028 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1029 *xform = dc->xformWorld2Wnd;
1030 GDI_ReleaseObj( hdc );
1031 return TRUE;
1035 /***********************************************************************
1036 * GetTransform (GDI32.@)
1038 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1040 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1041 FIXME("stub: don't know what to do for code %lx\n", unknown );
1042 return FALSE;
1046 /***********************************************************************
1047 * SetWorldTransform (GDI32.@)
1049 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1051 BOOL ret = FALSE;
1052 DC *dc = DC_GetDCPtr( hdc );
1054 if (!dc) return FALSE;
1055 if (!xform) goto done;
1057 /* Check that graphics mode is GM_ADVANCED */
1058 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1060 if (dc->funcs->pSetWorldTransform)
1062 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1063 if (!ret) goto done;
1066 dc->xformWorld2Wnd = *xform;
1067 DC_UpdateXforms( dc );
1068 ret = TRUE;
1069 done:
1070 GDI_ReleaseObj( hdc );
1071 return ret;
1075 /****************************************************************************
1076 * ModifyWorldTransform [GDI32.@]
1077 * Modifies the world transformation for a device context.
1079 * PARAMS
1080 * hdc [I] Handle to device context
1081 * xform [I] XFORM structure that will be used to modify the world
1082 * transformation
1083 * iMode [I] Specifies in what way to modify the world transformation
1084 * Possible values:
1085 * MWT_IDENTITY
1086 * Resets the world transformation to the identity matrix.
1087 * The parameter xform is ignored.
1088 * MWT_LEFTMULTIPLY
1089 * Multiplies xform into the world transformation matrix from
1090 * the left.
1091 * MWT_RIGHTMULTIPLY
1092 * Multiplies xform into the world transformation matrix from
1093 * the right.
1095 * RETURNS STD
1097 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1098 DWORD iMode )
1100 BOOL ret = FALSE;
1101 DC *dc = DC_GetDCPtr( hdc );
1103 /* Check for illegal parameters */
1104 if (!dc) return FALSE;
1105 if (!xform) goto done;
1107 /* Check that graphics mode is GM_ADVANCED */
1108 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1110 if (dc->funcs->pModifyWorldTransform)
1112 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1113 if (!ret) goto done;
1116 switch (iMode)
1118 case MWT_IDENTITY:
1119 dc->xformWorld2Wnd.eM11 = 1.0f;
1120 dc->xformWorld2Wnd.eM12 = 0.0f;
1121 dc->xformWorld2Wnd.eM21 = 0.0f;
1122 dc->xformWorld2Wnd.eM22 = 1.0f;
1123 dc->xformWorld2Wnd.eDx = 0.0f;
1124 dc->xformWorld2Wnd.eDy = 0.0f;
1125 break;
1126 case MWT_LEFTMULTIPLY:
1127 CombineTransform( &dc->xformWorld2Wnd, xform,
1128 &dc->xformWorld2Wnd );
1129 break;
1130 case MWT_RIGHTMULTIPLY:
1131 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1132 xform );
1133 break;
1134 default:
1135 goto done;
1138 DC_UpdateXforms( dc );
1139 ret = TRUE;
1140 done:
1141 GDI_ReleaseObj( hdc );
1142 return ret;
1146 /****************************************************************************
1147 * CombineTransform [GDI32.@]
1148 * Combines two transformation matrices.
1150 * PARAMS
1151 * xformResult [O] Stores the result of combining the two matrices
1152 * xform1 [I] Specifies the first matrix to apply
1153 * xform2 [I] Specifies the second matrix to apply
1155 * REMARKS
1156 * The same matrix can be passed in for more than one of the parameters.
1158 * RETURNS STD
1160 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1161 const XFORM *xform2 )
1163 XFORM xformTemp;
1165 /* Check for illegal parameters */
1166 if (!xformResult || !xform1 || !xform2)
1167 return FALSE;
1169 /* Create the result in a temporary XFORM, since xformResult may be
1170 * equal to xform1 or xform2 */
1171 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1172 xform1->eM12 * xform2->eM21;
1173 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1174 xform1->eM12 * xform2->eM22;
1175 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1176 xform1->eM22 * xform2->eM21;
1177 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1178 xform1->eM22 * xform2->eM22;
1179 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1180 xform1->eDy * xform2->eM21 +
1181 xform2->eDx;
1182 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1183 xform1->eDy * xform2->eM22 +
1184 xform2->eDy;
1186 /* Copy the result to xformResult */
1187 *xformResult = xformTemp;
1189 return TRUE;
1193 /***********************************************************************
1194 * SetDCHook (GDI32.@)
1196 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1198 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1200 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1202 if (!dc) return FALSE;
1204 if (!(dc->flags & DC_SAVED))
1206 dc->dwHookData = dwHookData;
1207 dc->hookThunk = hookProc;
1209 GDI_ReleaseObj( hdc );
1210 return TRUE;
1214 /* relay function to call the 16-bit DC hook proc */
1215 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1217 WORD args[6];
1218 DWORD ret;
1219 FARPROC16 proc = NULL;
1220 HDC hdc = HDC_32( hdc16 );
1221 DC *dc = DC_GetDCPtr( hdc );
1223 if (!dc) return FALSE;
1224 proc = dc->hookProc;
1225 GDI_ReleaseObj( hdc );
1226 if (!proc) return FALSE;
1227 args[5] = hdc16;
1228 args[4] = code;
1229 args[3] = HIWORD(data);
1230 args[2] = LOWORD(data);
1231 args[1] = HIWORD(lParam);
1232 args[0] = LOWORD(lParam);
1233 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1234 return LOWORD(ret);
1237 /***********************************************************************
1238 * SetDCHook (GDI.190)
1240 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1242 HDC hdc = HDC_32( hdc16 );
1243 DC *dc = DC_GetDCPtr( hdc );
1244 if (!dc) return FALSE;
1246 dc->hookProc = hookProc;
1247 GDI_ReleaseObj( hdc );
1248 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1252 /***********************************************************************
1253 * GetDCHook (GDI.191)
1255 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1257 HDC hdc = HDC_32( hdc16 );
1258 DC *dc = DC_GetDCPtr( hdc );
1259 DWORD ret;
1261 if (!dc) return 0;
1262 *phookProc = dc->hookProc;
1263 ret = dc->dwHookData;
1264 GDI_ReleaseObj( hdc );
1265 return ret;
1269 /***********************************************************************
1270 * SetHookFlags (GDI.192)
1272 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1274 HDC hdc = HDC_32( hdc16 );
1275 DC *dc = DC_GetDCPtr( hdc );
1277 if( dc )
1279 WORD wRet = dc->flags & DC_DIRTY;
1281 /* "Undocumented Windows" info is slightly confusing.
1284 TRACE("hDC %p, flags %04x\n",hdc,flags);
1286 if( flags & DCHF_INVALIDATEVISRGN )
1287 dc->flags |= DC_DIRTY;
1288 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1289 dc->flags &= ~DC_DIRTY;
1290 GDI_ReleaseObj( hdc );
1291 return wRet;
1293 return 0;
1296 /***********************************************************************
1297 * SetICMMode (GDI32.@)
1299 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1301 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1302 if (iEnableICM == ICM_OFF) return ICM_OFF;
1303 if (iEnableICM == ICM_ON) return 0;
1304 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1305 return 0;
1308 /***********************************************************************
1309 * GetDeviceGammaRamp (GDI32.@)
1311 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1313 BOOL ret = FALSE;
1314 DC *dc = DC_GetDCPtr( hDC );
1316 if( dc )
1318 if (dc->funcs->pGetDeviceGammaRamp)
1319 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1320 GDI_ReleaseObj( hDC );
1322 return ret;
1325 /***********************************************************************
1326 * SetDeviceGammaRamp (GDI32.@)
1328 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1330 BOOL ret = FALSE;
1331 DC *dc = DC_GetDCPtr( hDC );
1333 if( dc )
1335 if (dc->funcs->pSetDeviceGammaRamp)
1336 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1337 GDI_ReleaseObj( hDC );
1339 return ret;
1342 /***********************************************************************
1343 * GetColorSpace (GDI32.@)
1345 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1347 /*FIXME Need to to whatever GetColorSpace actually does */
1348 return 0;
1351 /***********************************************************************
1352 * CreateColorSpaceA (GDI32.@)
1354 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1356 FIXME( "stub\n" );
1357 return 0;
1360 /***********************************************************************
1361 * CreateColorSpaceW (GDI32.@)
1363 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1365 FIXME( "stub\n" );
1366 return 0;
1369 /***********************************************************************
1370 * DeleteColorSpace (GDI32.@)
1372 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1374 FIXME( "stub\n" );
1376 return TRUE;
1379 /***********************************************************************
1380 * SetColorSpace (GDI32.@)
1382 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1384 FIXME( "stub\n" );
1386 return hColorSpace;
1389 /***********************************************************************
1390 * GetBoundsRect (GDI.194)
1392 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1394 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1397 /***********************************************************************
1398 * GetBoundsRect (GDI32.@)
1400 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1402 FIXME("(): stub\n");
1403 return DCB_RESET; /* bounding rectangle always empty */
1406 /***********************************************************************
1407 * SetBoundsRect (GDI.193)
1409 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1411 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1412 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1414 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1417 /***********************************************************************
1418 * SetBoundsRect (GDI32.@)
1420 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1422 FIXME("(): stub\n");
1423 return DCB_DISABLE; /* bounding rectangle always empty */
1427 /***********************************************************************
1428 * GetRelAbs (GDI32.@)
1430 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1432 INT ret = 0;
1433 DC *dc = DC_GetDCPtr( hdc );
1434 if (dc) ret = dc->relAbsMode;
1435 GDI_ReleaseObj( hdc );
1436 return ret;
1439 /***********************************************************************
1440 * GetLayout (GDI32.@)
1442 * Gets left->right or right->left text layout flags of a dc.
1443 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1446 DWORD WINAPI GetLayout(HDC hdc)
1448 FIXME("(%p): stub\n", hdc);
1449 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1450 return 0;
1453 /***********************************************************************
1454 * SetLayout (GDI32.@)
1456 * Sets left->right or right->left text layout flags of a dc.
1457 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1460 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1462 FIXME("(%p,%08lx): stub\n", hdc, layout);
1463 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1464 return 0;
1467 /***********************************************************************
1468 * GetDCBrushColor (GDI32.@)
1470 * Retrieves the current brush color for the specified device
1471 * context (DC).
1474 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1476 DC *dc;
1477 COLORREF dcBrushColor = CLR_INVALID;
1479 TRACE("hdc(%p)\n", hdc);
1481 dc = DC_GetDCPtr( hdc );
1482 if (dc)
1484 dcBrushColor = dc->dcBrushColor;
1485 GDI_ReleaseObj( hdc );
1488 return dcBrushColor;
1491 /***********************************************************************
1492 * SetDCBrushColor (GDI32.@)
1494 * Sets the current device context (DC) brush color to the specified
1495 * color value. If the device cannot represent the specified color
1496 * value, the color is set to the nearest physical color.
1499 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1501 DC *dc;
1502 COLORREF oldClr = CLR_INVALID;
1504 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1506 dc = DC_GetDCPtr( hdc );
1507 if (dc)
1509 if (dc->funcs->pSetDCBrushColor)
1510 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
1511 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
1513 /* If DC_BRUSH is selected, update driver pen color */
1514 HBRUSH hBrush = CreateSolidBrush( crColor );
1515 dc->funcs->pSelectBrush( dc->physDev, hBrush );
1516 DeleteObject( hBrush );
1519 if (crColor != CLR_INVALID)
1521 oldClr = dc->dcBrushColor;
1522 dc->dcBrushColor = crColor;
1525 GDI_ReleaseObj( hdc );
1528 return oldClr;
1531 /***********************************************************************
1532 * GetDCPenColor (GDI32.@)
1534 * Retrieves the current pen color for the specified device
1535 * context (DC).
1538 COLORREF WINAPI GetDCPenColor(HDC hdc)
1540 DC *dc;
1541 COLORREF dcPenColor = CLR_INVALID;
1543 TRACE("hdc(%p)\n", hdc);
1545 dc = DC_GetDCPtr( hdc );
1546 if (dc)
1548 dcPenColor = dc->dcPenColor;
1549 GDI_ReleaseObj( hdc );
1552 return dcPenColor;
1555 /***********************************************************************
1556 * SetDCPenColor (GDI32.@)
1558 * Sets the current device context (DC) pen color to the specified
1559 * color value. If the device cannot represent the specified color
1560 * value, the color is set to the nearest physical color.
1563 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1565 DC *dc;
1566 COLORREF oldClr = CLR_INVALID;
1568 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1570 dc = DC_GetDCPtr( hdc );
1571 if (dc)
1573 if (dc->funcs->pSetDCPenColor)
1574 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
1575 else if (dc->hPen == GetStockObject( DC_PEN ))
1577 /* If DC_PEN is selected, update the driver pen color */
1578 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
1579 HPEN hPen = CreatePenIndirect( &logpen );
1580 dc->funcs->pSelectPen( dc->physDev, hPen );
1581 DeleteObject( hPen );
1584 if (crColor != CLR_INVALID)
1586 oldClr = dc->dcPenColor;
1587 dc->dcPenColor = crColor;
1590 GDI_ReleaseObj( hdc );
1593 return oldClr;
1596 /***********************************************************************
1597 * SetVirtualResolution (GDI32.@)
1599 * Undocumented on msdn. Called when PowerPoint XP saves a file.
1601 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
1603 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
1604 return FALSE;