Implement the Rtlp* registry functions.
[wine.git] / objects / dc.c
blobfafe60f22a330d7284d5074b26cb33bb5c77d1d7
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 "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc);
40 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
42 static const struct gdi_obj_funcs dc_funcs =
44 NULL, /* pSelectObject */
45 NULL, /* pGetObject16 */
46 NULL, /* pGetObjectA */
47 NULL, /* pGetObjectW */
48 NULL, /* pUnrealizeObject */
49 DC_DeleteObject /* pDeleteObject */
52 /***********************************************************************
53 * DC_AllocDC
55 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
57 HDC hdc;
58 DC *dc;
60 if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
62 dc->hSelf = hdc;
63 dc->funcs = funcs;
64 dc->physDev = NULL;
65 dc->saveLevel = 0;
66 dc->dwHookData = 0;
67 dc->hookProc = NULL;
68 dc->hookThunk = NULL;
69 dc->wndOrgX = 0;
70 dc->wndOrgY = 0;
71 dc->wndExtX = 1;
72 dc->wndExtY = 1;
73 dc->vportOrgX = 0;
74 dc->vportOrgY = 0;
75 dc->vportExtX = 1;
76 dc->vportExtY = 1;
77 dc->flags = 0;
78 dc->hClipRgn = 0;
79 dc->hVisRgn = 0;
80 dc->hGCClipRgn = 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->breakTotalExtra = 0;
102 dc->breakCount = 0;
103 dc->breakExtra = 0;
104 dc->breakRem = 0;
105 dc->totalExtent.left = 0;
106 dc->totalExtent.top = 0;
107 dc->totalExtent.right = 0;
108 dc->totalExtent.bottom = 0;
109 dc->bitsPerPixel = 1;
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->bitsPerPixel = dc->bitsPerPixel;
300 newdc->ROPmode = dc->ROPmode;
301 newdc->polyFillMode = dc->polyFillMode;
302 newdc->stretchBltMode = dc->stretchBltMode;
303 newdc->relAbsMode = dc->relAbsMode;
304 newdc->backgroundMode = dc->backgroundMode;
305 newdc->backgroundColor = dc->backgroundColor;
306 newdc->textColor = dc->textColor;
307 newdc->dcBrushColor = dc->dcBrushColor;
308 newdc->dcPenColor = dc->dcPenColor;
309 newdc->brushOrgX = dc->brushOrgX;
310 newdc->brushOrgY = dc->brushOrgY;
311 newdc->textAlign = dc->textAlign;
312 newdc->charExtra = dc->charExtra;
313 newdc->breakTotalExtra = dc->breakTotalExtra;
314 newdc->breakCount = dc->breakCount;
315 newdc->breakExtra = dc->breakExtra;
316 newdc->breakRem = dc->breakRem;
317 newdc->MapMode = dc->MapMode;
318 newdc->GraphicsMode = dc->GraphicsMode;
319 newdc->CursPosX = dc->CursPosX;
320 newdc->CursPosY = dc->CursPosY;
321 newdc->ArcDirection = dc->ArcDirection;
322 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
323 newdc->xformWorld2Vport = dc->xformWorld2Vport;
324 newdc->xformVport2World = dc->xformVport2World;
325 newdc->vport2WorldValid = dc->vport2WorldValid;
326 newdc->wndOrgX = dc->wndOrgX;
327 newdc->wndOrgY = dc->wndOrgY;
328 newdc->wndExtX = dc->wndExtX;
329 newdc->wndExtY = dc->wndExtY;
330 newdc->vportOrgX = dc->vportOrgX;
331 newdc->vportOrgY = dc->vportOrgY;
332 newdc->vportExtX = dc->vportExtX;
333 newdc->vportExtY = dc->vportExtY;
335 newdc->hSelf = (HDC)handle;
336 newdc->saveLevel = 0;
338 PATH_InitGdiPath( &newdc->path );
340 newdc->pAbortProc = NULL;
341 newdc->hookThunk = NULL;
342 newdc->hookProc = 0;
344 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
346 newdc->hGCClipRgn = newdc->hVisRgn = 0;
347 if (dc->hClipRgn)
349 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
350 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
352 else
353 newdc->hClipRgn = 0;
355 if(dc->gdiFont) {
356 newdc->gdiFont = dc->gdiFont;
357 } else
358 newdc->gdiFont = 0;
360 GDI_ReleaseObj( handle );
361 GDI_ReleaseObj( hdc );
362 return handle;
366 /***********************************************************************
367 * SetDCState (Not a Windows API)
369 void WINAPI SetDCState( HDC hdc, HDC hdcs )
371 DC *dc, *dcs;
373 if (!(dc = DC_GetDCUpdate( hdc ))) return;
374 if (!(dcs = DC_GetDCPtr( hdcs )))
376 GDI_ReleaseObj( hdc );
377 return;
379 if (!dcs->flags & DC_SAVED)
381 GDI_ReleaseObj( hdc );
382 GDI_ReleaseObj( hdcs );
383 return;
385 TRACE("%p %p\n", hdc, hdcs );
387 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
388 dc->hDevice = dcs->hDevice;
389 dc->totalExtent = dcs->totalExtent;
390 dc->ROPmode = dcs->ROPmode;
391 dc->polyFillMode = dcs->polyFillMode;
392 dc->stretchBltMode = dcs->stretchBltMode;
393 dc->relAbsMode = dcs->relAbsMode;
394 dc->backgroundMode = dcs->backgroundMode;
395 dc->backgroundColor = dcs->backgroundColor;
396 dc->textColor = dcs->textColor;
397 dc->dcBrushColor = dcs->dcBrushColor;
398 dc->dcPenColor = dcs->dcPenColor;
399 dc->brushOrgX = dcs->brushOrgX;
400 dc->brushOrgY = dcs->brushOrgY;
401 dc->textAlign = dcs->textAlign;
402 dc->charExtra = dcs->charExtra;
403 dc->breakTotalExtra = dcs->breakTotalExtra;
404 dc->breakCount = dcs->breakCount;
405 dc->breakExtra = dcs->breakExtra;
406 dc->breakRem = dcs->breakRem;
407 dc->MapMode = dcs->MapMode;
408 dc->GraphicsMode = dcs->GraphicsMode;
409 dc->CursPosX = dcs->CursPosX;
410 dc->CursPosY = dcs->CursPosY;
411 dc->ArcDirection = dcs->ArcDirection;
412 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
413 dc->xformWorld2Vport = dcs->xformWorld2Vport;
414 dc->xformVport2World = dcs->xformVport2World;
415 dc->vport2WorldValid = dcs->vport2WorldValid;
417 dc->wndOrgX = dcs->wndOrgX;
418 dc->wndOrgY = dcs->wndOrgY;
419 dc->wndExtX = dcs->wndExtX;
420 dc->wndExtY = dcs->wndExtY;
421 dc->vportOrgX = dcs->vportOrgX;
422 dc->vportOrgY = dcs->vportOrgY;
423 dc->vportExtX = dcs->vportExtX;
424 dc->vportExtY = dcs->vportExtY;
426 if (GDIMAGIC(dc->header.wMagic) != MEMORY_DC_MAGIC) dc->bitsPerPixel = dcs->bitsPerPixel;
428 if (dcs->hClipRgn)
430 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
431 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
433 else
435 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
436 dc->hClipRgn = 0;
438 CLIPPING_UpdateGCRegion( dc );
440 SelectObject( hdc, dcs->hBitmap );
441 SelectObject( hdc, dcs->hBrush );
442 SelectObject( hdc, dcs->hFont );
443 SelectObject( hdc, dcs->hPen );
444 SetBkColor( hdc, dcs->backgroundColor);
445 SetTextColor( hdc, dcs->textColor);
446 GDISelectPalette( hdc, dcs->hPalette, FALSE );
447 GDI_ReleaseObj( hdcs );
448 GDI_ReleaseObj( hdc );
452 /***********************************************************************
453 * GetDCState (GDI.179)
455 HDC16 WINAPI GetDCState16( HDC16 hdc )
457 return HDC_16( GetDCState( HDC_32(hdc) ));
461 /***********************************************************************
462 * SetDCState (GDI.180)
464 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
466 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
470 /***********************************************************************
471 * SaveDC (GDI32.@)
473 INT WINAPI SaveDC( HDC hdc )
475 HDC hdcs;
476 DC * dc, * dcs;
477 INT ret;
479 dc = DC_GetDCPtr( hdc );
480 if (!dc) return 0;
482 if(dc->funcs->pSaveDC)
484 ret = dc->funcs->pSaveDC( dc->physDev );
485 GDI_ReleaseObj( hdc );
486 return ret;
489 if (!(hdcs = GetDCState( hdc )))
491 GDI_ReleaseObj( hdc );
492 return 0;
494 dcs = DC_GetDCPtr( hdcs );
496 /* Copy path. The reason why path saving / restoring is in SaveDC/
497 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
498 * functions are only in Win16 (which doesn't have paths) and that
499 * SetDCState doesn't allow us to signal an error (which can happen
500 * when copying paths).
502 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
504 GDI_ReleaseObj( hdc );
505 GDI_ReleaseObj( hdcs );
506 DeleteDC( hdcs );
507 return 0;
510 dcs->header.hNext = dc->header.hNext;
511 dc->header.hNext = HDC_16(hdcs);
512 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
513 ret = ++dc->saveLevel;
514 GDI_ReleaseObj( hdcs );
515 GDI_ReleaseObj( hdc );
516 return ret;
520 /***********************************************************************
521 * RestoreDC (GDI32.@)
523 BOOL WINAPI RestoreDC( HDC hdc, INT level )
525 DC * dc, * dcs;
526 BOOL success;
528 TRACE("%p %d\n", hdc, level );
529 dc = DC_GetDCUpdate( hdc );
530 if(!dc) return FALSE;
531 if(dc->funcs->pRestoreDC)
533 success = dc->funcs->pRestoreDC( dc->physDev, level );
534 GDI_ReleaseObj( hdc );
535 return success;
538 if (level == -1) level = dc->saveLevel;
539 if ((level < 1)
540 /* This pair of checks disagrees with MSDN "Platform SDK:
541 Windows GDI" July 2000 which says all negative values
542 for level will be interpreted as an instance relative
543 to the current state. Restricting it to just -1 does
544 not satisfy this */
545 || (level > dc->saveLevel))
547 GDI_ReleaseObj( hdc );
548 return FALSE;
551 success=TRUE;
552 while (dc->saveLevel >= level)
554 HDC hdcs = HDC_32(dc->header.hNext);
555 if (!(dcs = DC_GetDCPtr( hdcs )))
557 GDI_ReleaseObj( hdc );
558 return FALSE;
560 dc->header.hNext = dcs->header.hNext;
561 if (--dc->saveLevel < level)
563 SetDCState( hdc, hdcs );
564 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
565 /* FIXME: This might not be quite right, since we're
566 * returning FALSE but still destroying the saved DC state */
567 success=FALSE;
569 GDI_ReleaseObj( hdcs );
570 GDI_ReleaseObj( hdc );
571 DeleteDC( hdcs );
572 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
574 GDI_ReleaseObj( hdc );
575 return success;
579 /***********************************************************************
580 * CreateDCW (GDI32.@)
582 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
583 const DEVMODEW *initData )
585 HDC hdc;
586 DC * dc;
587 const DC_FUNCTIONS *funcs;
588 WCHAR buf[300];
590 GDI_CheckNotLock();
592 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
594 if (!driver) return 0;
595 strcpyW(buf, driver);
598 if (!(funcs = DRIVER_load_driver( buf )))
600 ERR( "no driver found for %s\n", debugstr_w(buf) );
601 return 0;
603 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
605 DRIVER_release_driver( funcs );
606 return 0;
609 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
611 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
612 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
614 if (dc->funcs->pCreateDC &&
615 !dc->funcs->pCreateDC( dc, &dc->physDev, buf, device, output, initData ))
617 WARN("creation aborted by device\n" );
618 GDI_FreeObject( dc->hSelf, dc );
619 DRIVER_release_driver( funcs );
620 return 0;
623 dc->totalExtent.left = 0;
624 dc->totalExtent.top = 0;
625 dc->totalExtent.right = GetDeviceCaps( dc->hSelf, HORZRES );
626 dc->totalExtent.bottom = GetDeviceCaps( dc->hSelf, VERTRES );
627 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
629 DC_InitDC( dc );
630 hdc = dc->hSelf;
631 GDI_ReleaseObj( hdc );
632 return hdc;
636 /***********************************************************************
637 * CreateDCA (GDI32.@)
639 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
640 const DEVMODEA *initData )
642 UNICODE_STRING driverW, deviceW, outputW;
643 DEVMODEW *initDataW;
644 HDC ret;
646 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
647 else driverW.Buffer = NULL;
649 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
650 else deviceW.Buffer = NULL;
652 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
653 else outputW.Buffer = NULL;
655 if (initData) initDataW = GdiConvertToDevmodeW(initData);
656 else initDataW = NULL;
658 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
660 RtlFreeUnicodeString(&driverW);
661 RtlFreeUnicodeString(&deviceW);
662 RtlFreeUnicodeString(&outputW);
663 if (initDataW) HeapFree(GetProcessHeap(), 0, initDataW);
664 return ret;
668 /***********************************************************************
669 * CreateICA (GDI32.@)
671 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
672 const DEVMODEA* initData )
674 /* Nothing special yet for ICs */
675 return CreateDCA( driver, device, output, initData );
679 /***********************************************************************
680 * CreateICW (GDI32.@)
682 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
683 const DEVMODEW* initData )
685 /* Nothing special yet for ICs */
686 return CreateDCW( driver, device, output, initData );
690 /***********************************************************************
691 * CreateCompatibleDC (GDI32.@)
693 HDC WINAPI CreateCompatibleDC( HDC hdc )
695 DC *dc, *origDC;
696 const DC_FUNCTIONS *funcs;
697 PHYSDEV physDev;
699 GDI_CheckNotLock();
701 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
703 funcs = origDC->funcs;
704 physDev = origDC->physDev;
705 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
706 funcs = DRIVER_get_driver( funcs );
708 else
710 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
711 funcs = DRIVER_load_driver( displayW );
712 physDev = NULL;
715 if (!funcs) return 0;
717 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
719 DRIVER_release_driver( funcs );
720 return 0;
723 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
725 dc->bitsPerPixel = 1;
726 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
728 /* Copy the driver-specific physical device info into
729 * the new DC. The driver may use this read-only info
730 * while creating the compatible DC below. */
731 dc->physDev = physDev;
733 if (dc->funcs->pCreateDC &&
734 !dc->funcs->pCreateDC( dc, &dc->physDev, NULL, NULL, NULL, NULL ))
736 WARN("creation aborted by device\n");
737 GDI_FreeObject( dc->hSelf, dc );
738 DRIVER_release_driver( funcs );
739 return 0;
742 dc->totalExtent.left = 0;
743 dc->totalExtent.top = 0;
744 dc->totalExtent.right = 1; /* default bitmap is 1x1 */
745 dc->totalExtent.bottom = 1;
746 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
748 DC_InitDC( dc );
749 GDI_ReleaseObj( dc->hSelf );
750 return dc->hSelf;
754 /***********************************************************************
755 * DeleteDC (GDI32.@)
757 BOOL WINAPI DeleteDC( HDC hdc )
759 const DC_FUNCTIONS *funcs = NULL;
760 DC * dc;
762 TRACE("%p\n", hdc );
764 GDI_CheckNotLock();
766 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
768 /* Call hook procedure to check whether is it OK to delete this DC */
769 if (dc->hookThunk)
771 DCHOOKPROC proc = dc->hookThunk;
772 DWORD data = dc->dwHookData;
773 GDI_ReleaseObj( hdc );
774 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
775 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
778 while (dc->saveLevel)
780 DC * dcs;
781 HDC hdcs = HDC_32(dc->header.hNext);
782 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
783 dc->header.hNext = dcs->header.hNext;
784 dc->saveLevel--;
785 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
786 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
787 if (dcs->hGCClipRgn) DeleteObject( dcs->hGCClipRgn );
788 PATH_DestroyGdiPath(&dcs->path);
789 GDI_FreeObject( hdcs, dcs );
792 if (!(dc->flags & DC_SAVED))
794 SelectObject( hdc, GetStockObject(BLACK_PEN) );
795 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
796 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
797 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
798 funcs = dc->funcs;
799 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
800 dc->physDev = NULL;
803 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
804 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
805 if (dc->hGCClipRgn) DeleteObject( dc->hGCClipRgn );
806 PATH_DestroyGdiPath(&dc->path);
808 GDI_FreeObject( hdc, dc );
809 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
810 return TRUE;
814 /***********************************************************************
815 * ResetDCA (GDI32.@)
817 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
819 DC *dc;
820 HDC ret = hdc;
822 if ((dc = DC_GetDCPtr( hdc )))
824 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
825 GDI_ReleaseObj( hdc );
827 return ret;
831 /***********************************************************************
832 * ResetDCW (GDI32.@)
834 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
836 return ResetDCA(hdc, (const DEVMODEA*)devmode); /* FIXME */
840 /***********************************************************************
841 * GetDeviceCaps (GDI32.@)
843 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
845 DC *dc;
846 INT ret = 0;
848 if ((dc = DC_GetDCPtr( hdc )))
850 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
851 GDI_ReleaseObj( hdc );
853 return ret;
857 /***********************************************************************
858 * SetBkColor (GDI32.@)
860 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
862 COLORREF oldColor;
863 DC * dc = DC_GetDCPtr( hdc );
865 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
867 if (!dc) return CLR_INVALID;
868 oldColor = dc->backgroundColor;
869 if (dc->funcs->pSetBkColor)
871 color = dc->funcs->pSetBkColor(dc->physDev, color);
872 if (color == CLR_INVALID) /* don't change it */
874 color = oldColor;
875 oldColor = CLR_INVALID;
878 dc->backgroundColor = color;
879 GDI_ReleaseObj( hdc );
880 return oldColor;
884 /***********************************************************************
885 * SetTextColor (GDI32.@)
887 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
889 COLORREF oldColor;
890 DC * dc = DC_GetDCPtr( hdc );
892 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
894 if (!dc) return CLR_INVALID;
895 oldColor = dc->textColor;
896 if (dc->funcs->pSetTextColor)
898 color = dc->funcs->pSetTextColor(dc->physDev, color);
899 if (color == CLR_INVALID) /* don't change it */
901 color = oldColor;
902 oldColor = CLR_INVALID;
905 dc->textColor = color;
906 GDI_ReleaseObj( hdc );
907 return oldColor;
911 /***********************************************************************
912 * SetTextAlign (GDI32.@)
914 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
916 UINT prevAlign;
917 DC *dc = DC_GetDCPtr( hdc );
919 TRACE("hdc=%p align=%d\n", hdc, align);
921 if (!dc) return 0x0;
922 if (dc->funcs->pSetTextAlign)
923 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
924 else {
925 prevAlign = dc->textAlign;
926 dc->textAlign = align;
928 GDI_ReleaseObj( hdc );
929 return prevAlign;
932 /***********************************************************************
933 * GetDCOrgEx (GDI32.@)
935 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
937 DC * dc;
939 if (!lpp) return FALSE;
940 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
942 lpp->x = lpp->y = 0;
943 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
944 GDI_ReleaseObj( hDC );
945 return TRUE;
949 /***********************************************************************
950 * SetDCOrg (GDI.117)
952 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
954 DWORD prevOrg = 0;
955 HDC hdc = HDC_32( hdc16 );
956 DC *dc = DC_GetDCPtr( hdc );
957 if (!dc) return 0;
958 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
959 GDI_ReleaseObj( hdc );
960 return prevOrg;
964 /***********************************************************************
965 * SetGraphicsMode (GDI32.@)
967 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
969 INT ret = 0;
970 DC *dc = DC_GetDCPtr( hdc );
972 /* One would think that setting the graphics mode to GM_COMPATIBLE
973 * would also reset the world transformation matrix to the unity
974 * matrix. However, in Windows, this is not the case. This doesn't
975 * make a lot of sense to me, but that's the way it is.
977 if (!dc) return 0;
978 if ((mode > 0) && (mode <= GM_LAST))
980 ret = dc->GraphicsMode;
981 dc->GraphicsMode = mode;
983 GDI_ReleaseObj( hdc );
984 return ret;
988 /***********************************************************************
989 * SetArcDirection (GDI32.@)
991 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
993 DC * dc;
994 INT nOldDirection = 0;
996 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
998 SetLastError(ERROR_INVALID_PARAMETER);
999 return 0;
1002 if ((dc = DC_GetDCPtr( hdc )))
1004 if (dc->funcs->pSetArcDirection)
1006 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1008 nOldDirection = dc->ArcDirection;
1009 dc->ArcDirection = nDirection;
1010 GDI_ReleaseObj( hdc );
1012 return nOldDirection;
1016 /***********************************************************************
1017 * GetWorldTransform (GDI32.@)
1019 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1021 DC * dc;
1022 if (!xform) return FALSE;
1023 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1024 *xform = dc->xformWorld2Wnd;
1025 GDI_ReleaseObj( hdc );
1026 return TRUE;
1030 /***********************************************************************
1031 * GetTransform (GDI32.@)
1033 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1035 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1036 ERR("stub: don't know what to do for code %lx\n", unknown );
1037 return FALSE;
1041 /***********************************************************************
1042 * SetWorldTransform (GDI32.@)
1044 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1046 BOOL ret = FALSE;
1047 DC *dc = DC_GetDCPtr( hdc );
1049 if (!dc) return FALSE;
1050 if (!xform) goto done;
1052 /* Check that graphics mode is GM_ADVANCED */
1053 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1055 if (dc->funcs->pSetWorldTransform)
1057 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1058 if (!ret) goto done;
1061 dc->xformWorld2Wnd = *xform;
1062 DC_UpdateXforms( dc );
1063 ret = TRUE;
1064 done:
1065 GDI_ReleaseObj( hdc );
1066 return ret;
1070 /****************************************************************************
1071 * ModifyWorldTransform [GDI32.@]
1072 * Modifies the world transformation for a device context.
1074 * PARAMS
1075 * hdc [I] Handle to device context
1076 * xform [I] XFORM structure that will be used to modify the world
1077 * transformation
1078 * iMode [I] Specifies in what way to modify the world transformation
1079 * Possible values:
1080 * MWT_IDENTITY
1081 * Resets the world transformation to the identity matrix.
1082 * The parameter xform is ignored.
1083 * MWT_LEFTMULTIPLY
1084 * Multiplies xform into the world transformation matrix from
1085 * the left.
1086 * MWT_RIGHTMULTIPLY
1087 * Multiplies xform into the world transformation matrix from
1088 * the right.
1090 * RETURNS STD
1092 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1093 DWORD iMode )
1095 BOOL ret = FALSE;
1096 DC *dc = DC_GetDCPtr( hdc );
1098 /* Check for illegal parameters */
1099 if (!dc) return FALSE;
1100 if (!xform) goto done;
1102 /* Check that graphics mode is GM_ADVANCED */
1103 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1105 if (dc->funcs->pModifyWorldTransform)
1107 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1108 if (!ret) goto done;
1111 switch (iMode)
1113 case MWT_IDENTITY:
1114 dc->xformWorld2Wnd.eM11 = 1.0f;
1115 dc->xformWorld2Wnd.eM12 = 0.0f;
1116 dc->xformWorld2Wnd.eM21 = 0.0f;
1117 dc->xformWorld2Wnd.eM22 = 1.0f;
1118 dc->xformWorld2Wnd.eDx = 0.0f;
1119 dc->xformWorld2Wnd.eDy = 0.0f;
1120 break;
1121 case MWT_LEFTMULTIPLY:
1122 CombineTransform( &dc->xformWorld2Wnd, xform,
1123 &dc->xformWorld2Wnd );
1124 break;
1125 case MWT_RIGHTMULTIPLY:
1126 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1127 xform );
1128 break;
1129 default:
1130 goto done;
1133 DC_UpdateXforms( dc );
1134 ret = TRUE;
1135 done:
1136 GDI_ReleaseObj( hdc );
1137 return ret;
1141 /****************************************************************************
1142 * CombineTransform [GDI32.@]
1143 * Combines two transformation matrices.
1145 * PARAMS
1146 * xformResult [O] Stores the result of combining the two matrices
1147 * xform1 [I] Specifies the first matrix to apply
1148 * xform2 [I] Specifies the second matrix to apply
1150 * REMARKS
1151 * The same matrix can be passed in for more than one of the parameters.
1153 * RETURNS STD
1155 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1156 const XFORM *xform2 )
1158 XFORM xformTemp;
1160 /* Check for illegal parameters */
1161 if (!xformResult || !xform1 || !xform2)
1162 return FALSE;
1164 /* Create the result in a temporary XFORM, since xformResult may be
1165 * equal to xform1 or xform2 */
1166 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1167 xform1->eM12 * xform2->eM21;
1168 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1169 xform1->eM12 * xform2->eM22;
1170 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1171 xform1->eM22 * xform2->eM21;
1172 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1173 xform1->eM22 * xform2->eM22;
1174 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1175 xform1->eDy * xform2->eM21 +
1176 xform2->eDx;
1177 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1178 xform1->eDy * xform2->eM22 +
1179 xform2->eDy;
1181 /* Copy the result to xformResult */
1182 *xformResult = xformTemp;
1184 return TRUE;
1188 /***********************************************************************
1189 * SetDCHook (GDI32.@)
1191 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1193 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1195 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1197 if (!dc) return FALSE;
1199 if (!(dc->flags & DC_SAVED))
1201 dc->dwHookData = dwHookData;
1202 dc->hookThunk = hookProc;
1204 GDI_ReleaseObj( hdc );
1205 return TRUE;
1209 /* relay function to call the 16-bit DC hook proc */
1210 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1212 WORD args[6];
1213 DWORD ret;
1214 FARPROC16 proc = NULL;
1215 HDC hdc = HDC_32( hdc16 );
1216 DC *dc = DC_GetDCPtr( hdc );
1218 if (!dc) return FALSE;
1219 proc = dc->hookProc;
1220 GDI_ReleaseObj( hdc );
1221 if (!proc) return FALSE;
1222 args[5] = hdc16;
1223 args[4] = code;
1224 args[3] = HIWORD(data);
1225 args[2] = LOWORD(data);
1226 args[1] = HIWORD(lParam);
1227 args[0] = LOWORD(lParam);
1228 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1229 return LOWORD(ret);
1232 /***********************************************************************
1233 * SetDCHook (GDI.190)
1235 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1237 HDC hdc = HDC_32( hdc16 );
1238 DC *dc = DC_GetDCPtr( hdc );
1239 if (!dc) return FALSE;
1241 dc->hookProc = hookProc;
1242 GDI_ReleaseObj( hdc );
1243 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1247 /***********************************************************************
1248 * GetDCHook (GDI.191)
1250 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1252 HDC hdc = HDC_32( hdc16 );
1253 DC *dc = DC_GetDCPtr( hdc );
1254 DWORD ret;
1256 if (!dc) return 0;
1257 *phookProc = dc->hookProc;
1258 ret = dc->dwHookData;
1259 GDI_ReleaseObj( hdc );
1260 return ret;
1264 /***********************************************************************
1265 * SetHookFlags (GDI.192)
1267 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1269 HDC hdc = HDC_32( hdc16 );
1270 DC *dc = DC_GetDCPtr( hdc );
1272 if( dc )
1274 WORD wRet = dc->flags & DC_DIRTY;
1276 /* "Undocumented Windows" info is slightly confusing.
1279 TRACE("hDC %p, flags %04x\n",hdc,flags);
1281 if( flags & DCHF_INVALIDATEVISRGN )
1282 dc->flags |= DC_DIRTY;
1283 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1284 dc->flags &= ~DC_DIRTY;
1285 GDI_ReleaseObj( hdc );
1286 return wRet;
1288 return 0;
1291 /***********************************************************************
1292 * SetICMMode (GDI32.@)
1294 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1296 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1297 if (iEnableICM == ICM_OFF) return ICM_OFF;
1298 if (iEnableICM == ICM_ON) return 0;
1299 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1300 return 0;
1303 /***********************************************************************
1304 * GetDeviceGammaRamp (GDI32.@)
1306 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1308 BOOL ret = FALSE;
1309 DC *dc = DC_GetDCPtr( hDC );
1311 if( dc )
1313 if (dc->funcs->pGetDeviceGammaRamp)
1314 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1315 GDI_ReleaseObj( hDC );
1317 return ret;
1320 /***********************************************************************
1321 * SetDeviceGammaRamp (GDI32.@)
1323 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1325 BOOL ret = FALSE;
1326 DC *dc = DC_GetDCPtr( hDC );
1328 if( dc )
1330 if (dc->funcs->pSetDeviceGammaRamp)
1331 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1332 GDI_ReleaseObj( hDC );
1334 return ret;
1337 /***********************************************************************
1338 * GetColorSpace (GDI32.@)
1340 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1342 /*FIXME Need to to whatever GetColorSpace actually does */
1343 return 0;
1346 /***********************************************************************
1347 * CreateColorSpaceA (GDI32.@)
1349 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1351 FIXME( "stub\n" );
1352 return 0;
1355 /***********************************************************************
1356 * CreateColorSpaceW (GDI32.@)
1358 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1360 FIXME( "stub\n" );
1361 return 0;
1364 /***********************************************************************
1365 * DeleteColorSpace (GDI32.@)
1367 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1369 FIXME( "stub\n" );
1371 return TRUE;
1374 /***********************************************************************
1375 * SetColorSpace (GDI32.@)
1377 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1379 FIXME( "stub\n" );
1381 return hColorSpace;
1384 /***********************************************************************
1385 * GetBoundsRect (GDI.194)
1387 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1389 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1392 /***********************************************************************
1393 * GetBoundsRect (GDI32.@)
1395 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1397 FIXME("(): stub\n");
1398 return DCB_RESET; /* bounding rectangle always empty */
1401 /***********************************************************************
1402 * SetBoundsRect (GDI.193)
1404 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1406 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1407 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1409 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1412 /***********************************************************************
1413 * SetBoundsRect (GDI32.@)
1415 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1417 FIXME("(): stub\n");
1418 return DCB_DISABLE; /* bounding rectangle always empty */
1422 /***********************************************************************
1423 * GetRelAbs (GDI32.@)
1425 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1427 INT ret = 0;
1428 DC *dc = DC_GetDCPtr( hdc );
1429 if (dc) ret = dc->relAbsMode;
1430 GDI_ReleaseObj( hdc );
1431 return ret;
1434 /***********************************************************************
1435 * GetLayout (GDI32.@)
1437 * Gets left->right or right->left text layout flags of a dc.
1438 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1441 DWORD WINAPI GetLayout(HDC hdc)
1443 FIXME("(%p): stub\n", hdc);
1444 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1445 return 0;
1448 /***********************************************************************
1449 * SetLayout (GDI32.@)
1451 * Sets left->right or right->left text layout flags of a dc.
1452 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1455 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1457 FIXME("(%p,%08lx): stub\n", hdc, layout);
1458 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1459 return 0;
1462 /***********************************************************************
1463 * GetDCBrushColor (GDI32.@)
1465 * Retrieves the current brush color for the specified device
1466 * context (DC).
1469 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1471 DC *dc;
1472 COLORREF dcBrushColor = CLR_INVALID;
1474 TRACE("hdc(%p)\n", hdc);
1476 dc = DC_GetDCPtr( hdc );
1477 if (dc)
1479 dcBrushColor = dc->dcBrushColor;
1480 GDI_ReleaseObj( hdc );
1483 return dcBrushColor;
1486 /***********************************************************************
1487 * SetDCBrushColor (GDI32.@)
1489 * Sets the current device context (DC) brush color to the specified
1490 * color value. If the device cannot represent the specified color
1491 * value, the color is set to the nearest physical color.
1494 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1496 DC *dc;
1497 COLORREF oldClr = CLR_INVALID;
1499 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1501 dc = DC_GetDCPtr( hdc );
1502 if (dc)
1504 if (dc->funcs->pSetDCBrushColor)
1505 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
1506 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
1508 /* If DC_BRUSH is selected, update driver pen color */
1509 HBRUSH hBrush = CreateSolidBrush( crColor );
1510 dc->funcs->pSelectBrush( dc->physDev, hBrush );
1511 DeleteObject( hBrush );
1514 if (crColor != CLR_INVALID)
1516 oldClr = dc->dcBrushColor;
1517 dc->dcBrushColor = crColor;
1520 GDI_ReleaseObj( hdc );
1523 return oldClr;
1526 /***********************************************************************
1527 * GetDCPenColor (GDI32.@)
1529 * Retrieves the current pen color for the specified device
1530 * context (DC).
1533 COLORREF WINAPI GetDCPenColor(HDC hdc)
1535 DC *dc;
1536 COLORREF dcPenColor = CLR_INVALID;
1538 TRACE("hdc(%p)\n", hdc);
1540 dc = DC_GetDCPtr( hdc );
1541 if (dc)
1543 dcPenColor = dc->dcPenColor;
1544 GDI_ReleaseObj( hdc );
1547 return dcPenColor;
1550 /***********************************************************************
1551 * SetDCPenColor (GDI32.@)
1553 * Sets the current device context (DC) pen color to the specified
1554 * color value. If the device cannot represent the specified color
1555 * value, the color is set to the nearest physical color.
1558 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1560 DC *dc;
1561 COLORREF oldClr = CLR_INVALID;
1563 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1565 dc = DC_GetDCPtr( hdc );
1566 if (dc)
1568 if (dc->funcs->pSetDCPenColor)
1569 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
1570 else if (dc->hPen == GetStockObject( DC_PEN ))
1572 /* If DC_PEN is selected, update the driver pen color */
1573 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
1574 HPEN hPen = CreatePenIndirect( &logpen );
1575 dc->funcs->pSelectPen( dc->physDev, hPen );
1576 DeleteObject( hPen );
1579 if (crColor != CLR_INVALID)
1581 oldClr = dc->dcPenColor;
1582 dc->dcPenColor = crColor;
1585 GDI_ReleaseObj( hdc );
1588 return oldClr;
1591 /***********************************************************************
1592 * SetVirtualResolution (GDI32.@)
1594 * Undocumented on msdn. Called when PowerPoint XP saves a file.
1596 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
1598 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
1599 return FALSE;