- moved the remaining of int21 calls to dlls/winedos
[wine.git] / objects / dc.c
blob18668459c48be9adc466f6a35f47ad5d9aff012b
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 "heap.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->bitsPerPixel = 1;
111 dc->MapMode = MM_TEXT;
112 dc->GraphicsMode = GM_COMPATIBLE;
113 dc->pAbortProc = NULL;
114 dc->CursPosX = 0;
115 dc->CursPosY = 0;
116 dc->ArcDirection = AD_COUNTERCLOCKWISE;
117 dc->xformWorld2Wnd.eM11 = 1.0f;
118 dc->xformWorld2Wnd.eM12 = 0.0f;
119 dc->xformWorld2Wnd.eM21 = 0.0f;
120 dc->xformWorld2Wnd.eM22 = 1.0f;
121 dc->xformWorld2Wnd.eDx = 0.0f;
122 dc->xformWorld2Wnd.eDy = 0.0f;
123 dc->xformWorld2Vport = dc->xformWorld2Wnd;
124 dc->xformVport2World = dc->xformWorld2Wnd;
125 dc->vport2WorldValid = TRUE;
126 PATH_InitGdiPath(&dc->path);
127 return dc;
132 /***********************************************************************
133 * DC_GetDCPtr
135 DC *DC_GetDCPtr( HDC hdc )
137 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
138 if (!ptr) return NULL;
139 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
140 (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
141 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
142 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
143 return (DC *)ptr;
144 GDI_ReleaseObj( hdc );
145 SetLastError( ERROR_INVALID_HANDLE );
146 return NULL;
149 /***********************************************************************
150 * DC_GetDCUpdate
152 * Retrieve a DC ptr while making sure the visRgn is updated.
153 * This function may call up to USER so the GDI lock should _not_
154 * be held when calling it.
156 DC *DC_GetDCUpdate( HDC hdc )
158 DC *dc = DC_GetDCPtr( hdc );
159 if (!dc) return NULL;
160 while (dc->flags & DC_DIRTY)
162 DCHOOKPROC proc = dc->hookThunk;
163 dc->flags &= ~DC_DIRTY;
164 if (proc)
166 DWORD data = dc->dwHookData;
167 GDI_ReleaseObj( hdc );
168 proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
169 if (!(dc = DC_GetDCPtr( hdc ))) break;
170 /* otherwise restart the loop in case it became dirty again in the meantime */
173 return dc;
177 /***********************************************************************
178 * DC_DeleteObject
180 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
182 GDI_ReleaseObj( handle );
183 return DeleteDC( handle );
187 /***********************************************************************
188 * DC_InitDC
190 * Setup device-specific DC values for a newly created DC.
192 void DC_InitDC( DC* dc )
194 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
195 SetTextColor( dc->hSelf, dc->textColor );
196 SetBkColor( dc->hSelf, dc->backgroundColor );
197 SelectObject( dc->hSelf, dc->hPen );
198 SelectObject( dc->hSelf, dc->hBrush );
199 SelectObject( dc->hSelf, dc->hFont );
200 CLIPPING_UpdateGCRegion( dc );
204 /***********************************************************************
205 * DC_InvertXform
207 * Computes the inverse of the transformation xformSrc and stores it to
208 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
209 * is singular.
211 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
213 FLOAT determinant;
215 determinant = xformSrc->eM11*xformSrc->eM22 -
216 xformSrc->eM12*xformSrc->eM21;
217 if (determinant > -1e-12 && determinant < 1e-12)
218 return FALSE;
220 xformDest->eM11 = xformSrc->eM22 / determinant;
221 xformDest->eM12 = -xformSrc->eM12 / determinant;
222 xformDest->eM21 = -xformSrc->eM21 / determinant;
223 xformDest->eM22 = xformSrc->eM11 / determinant;
224 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
225 xformSrc->eDy * xformDest->eM21;
226 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
227 xformSrc->eDy * xformDest->eM22;
229 return TRUE;
233 /***********************************************************************
234 * DC_UpdateXforms
236 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
237 * fields of the specified DC by creating a transformation that
238 * represents the current mapping mode and combining it with the DC's
239 * world transform. This function should be called whenever the
240 * parameters associated with the mapping mode (window and viewport
241 * extents and origins) or the world transform change.
243 void DC_UpdateXforms( DC *dc )
245 XFORM xformWnd2Vport, oldworld2vport;
246 FLOAT scaleX, scaleY;
248 /* Construct a transformation to do the window-to-viewport conversion */
249 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
250 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
251 xformWnd2Vport.eM11 = scaleX;
252 xformWnd2Vport.eM12 = 0.0;
253 xformWnd2Vport.eM21 = 0.0;
254 xformWnd2Vport.eM22 = scaleY;
255 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
256 scaleX * (FLOAT)dc->wndOrgX;
257 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
258 scaleY * (FLOAT)dc->wndOrgY;
260 oldworld2vport = dc->xformWorld2Vport;
261 /* Combine with the world transformation */
262 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
263 &xformWnd2Vport );
265 /* Create inverse of world-to-viewport transformation */
266 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
267 &dc->xformVport2World );
269 /* Reselect the font back into the dc so that the font size
270 gets updated. */
271 if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
272 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
276 /***********************************************************************
277 * GetDCState (Not a Windows API)
279 HDC WINAPI GetDCState( HDC hdc )
281 DC * newdc, * dc;
282 HGDIOBJ handle;
284 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
285 if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
287 GDI_ReleaseObj( hdc );
288 return 0;
290 TRACE("(%p): returning %p\n", hdc, handle );
292 newdc->flags = dc->flags | DC_SAVED;
293 newdc->hPen = dc->hPen;
294 newdc->hBrush = dc->hBrush;
295 newdc->hFont = dc->hFont;
296 newdc->hBitmap = dc->hBitmap;
297 newdc->hDevice = dc->hDevice;
298 newdc->hPalette = dc->hPalette;
299 newdc->totalExtent = dc->totalExtent;
300 newdc->bitsPerPixel = dc->bitsPerPixel;
301 newdc->ROPmode = dc->ROPmode;
302 newdc->polyFillMode = dc->polyFillMode;
303 newdc->stretchBltMode = dc->stretchBltMode;
304 newdc->relAbsMode = dc->relAbsMode;
305 newdc->backgroundMode = dc->backgroundMode;
306 newdc->backgroundColor = dc->backgroundColor;
307 newdc->textColor = dc->textColor;
308 newdc->dcBrushColor = dc->dcBrushColor;
309 newdc->dcPenColor = dc->dcPenColor;
310 newdc->brushOrgX = dc->brushOrgX;
311 newdc->brushOrgY = dc->brushOrgY;
312 newdc->textAlign = dc->textAlign;
313 newdc->charExtra = dc->charExtra;
314 newdc->breakTotalExtra = dc->breakTotalExtra;
315 newdc->breakCount = dc->breakCount;
316 newdc->breakExtra = dc->breakExtra;
317 newdc->breakRem = dc->breakRem;
318 newdc->MapMode = dc->MapMode;
319 newdc->GraphicsMode = dc->GraphicsMode;
320 newdc->CursPosX = dc->CursPosX;
321 newdc->CursPosY = dc->CursPosY;
322 newdc->ArcDirection = dc->ArcDirection;
323 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
324 newdc->xformWorld2Vport = dc->xformWorld2Vport;
325 newdc->xformVport2World = dc->xformVport2World;
326 newdc->vport2WorldValid = dc->vport2WorldValid;
327 newdc->wndOrgX = dc->wndOrgX;
328 newdc->wndOrgY = dc->wndOrgY;
329 newdc->wndExtX = dc->wndExtX;
330 newdc->wndExtY = dc->wndExtY;
331 newdc->vportOrgX = dc->vportOrgX;
332 newdc->vportOrgY = dc->vportOrgY;
333 newdc->vportExtX = dc->vportExtX;
334 newdc->vportExtY = dc->vportExtY;
336 newdc->hSelf = (HDC)handle;
337 newdc->saveLevel = 0;
339 PATH_InitGdiPath( &newdc->path );
341 newdc->pAbortProc = NULL;
342 newdc->hookThunk = NULL;
343 newdc->hookProc = 0;
345 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
347 newdc->hGCClipRgn = newdc->hVisRgn = 0;
348 if (dc->hClipRgn)
350 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
351 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
353 else
354 newdc->hClipRgn = 0;
356 if(dc->gdiFont) {
357 newdc->gdiFont = dc->gdiFont;
358 } else
359 newdc->gdiFont = 0;
361 GDI_ReleaseObj( handle );
362 GDI_ReleaseObj( hdc );
363 return handle;
367 /***********************************************************************
368 * SetDCState (Not a Windows API)
370 void WINAPI SetDCState( HDC hdc, HDC hdcs )
372 DC *dc, *dcs;
374 if (!(dc = DC_GetDCUpdate( hdc ))) return;
375 if (!(dcs = DC_GetDCPtr( hdcs )))
377 GDI_ReleaseObj( hdc );
378 return;
380 if (!dcs->flags & DC_SAVED)
382 GDI_ReleaseObj( hdc );
383 GDI_ReleaseObj( hdcs );
384 return;
386 TRACE("%p %p\n", hdc, hdcs );
388 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
389 dc->hDevice = dcs->hDevice;
390 dc->totalExtent = dcs->totalExtent;
391 dc->ROPmode = dcs->ROPmode;
392 dc->polyFillMode = dcs->polyFillMode;
393 dc->stretchBltMode = dcs->stretchBltMode;
394 dc->relAbsMode = dcs->relAbsMode;
395 dc->backgroundMode = dcs->backgroundMode;
396 dc->backgroundColor = dcs->backgroundColor;
397 dc->textColor = dcs->textColor;
398 dc->dcBrushColor = dcs->dcBrushColor;
399 dc->dcPenColor = dcs->dcPenColor;
400 dc->brushOrgX = dcs->brushOrgX;
401 dc->brushOrgY = dcs->brushOrgY;
402 dc->textAlign = dcs->textAlign;
403 dc->charExtra = dcs->charExtra;
404 dc->breakTotalExtra = dcs->breakTotalExtra;
405 dc->breakCount = dcs->breakCount;
406 dc->breakExtra = dcs->breakExtra;
407 dc->breakRem = dcs->breakRem;
408 dc->MapMode = dcs->MapMode;
409 dc->GraphicsMode = dcs->GraphicsMode;
410 dc->CursPosX = dcs->CursPosX;
411 dc->CursPosY = dcs->CursPosY;
412 dc->ArcDirection = dcs->ArcDirection;
413 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
414 dc->xformWorld2Vport = dcs->xformWorld2Vport;
415 dc->xformVport2World = dcs->xformVport2World;
416 dc->vport2WorldValid = dcs->vport2WorldValid;
418 dc->wndOrgX = dcs->wndOrgX;
419 dc->wndOrgY = dcs->wndOrgY;
420 dc->wndExtX = dcs->wndExtX;
421 dc->wndExtY = dcs->wndExtY;
422 dc->vportOrgX = dcs->vportOrgX;
423 dc->vportOrgY = dcs->vportOrgY;
424 dc->vportExtX = dcs->vportExtX;
425 dc->vportExtY = dcs->vportExtY;
427 if (GDIMAGIC(dc->header.wMagic) != MEMORY_DC_MAGIC) dc->bitsPerPixel = dcs->bitsPerPixel;
429 if (dcs->hClipRgn)
431 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
432 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
434 else
436 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
437 dc->hClipRgn = 0;
439 CLIPPING_UpdateGCRegion( dc );
441 SelectObject( hdc, dcs->hBitmap );
442 SelectObject( hdc, dcs->hBrush );
443 SelectObject( hdc, dcs->hFont );
444 SelectObject( hdc, dcs->hPen );
445 SetBkColor( hdc, dcs->backgroundColor);
446 SetTextColor( hdc, dcs->textColor);
447 GDISelectPalette( hdc, dcs->hPalette, FALSE );
448 GDI_ReleaseObj( hdcs );
449 GDI_ReleaseObj( hdc );
453 /***********************************************************************
454 * GetDCState (GDI.179)
456 HDC16 WINAPI GetDCState16( HDC16 hdc )
458 return HDC_16( GetDCState( HDC_32(hdc) ));
462 /***********************************************************************
463 * SetDCState (GDI.180)
465 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
467 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
471 /***********************************************************************
472 * SaveDC (GDI32.@)
474 INT WINAPI SaveDC( HDC hdc )
476 HDC hdcs;
477 DC * dc, * dcs;
478 INT ret;
480 dc = DC_GetDCPtr( hdc );
481 if (!dc) return 0;
483 if(dc->funcs->pSaveDC)
485 ret = dc->funcs->pSaveDC( dc->physDev );
486 GDI_ReleaseObj( hdc );
487 return ret;
490 if (!(hdcs = GetDCState( hdc )))
492 GDI_ReleaseObj( hdc );
493 return 0;
495 dcs = DC_GetDCPtr( hdcs );
497 /* Copy path. The reason why path saving / restoring is in SaveDC/
498 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
499 * functions are only in Win16 (which doesn't have paths) and that
500 * SetDCState doesn't allow us to signal an error (which can happen
501 * when copying paths).
503 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
505 GDI_ReleaseObj( hdc );
506 GDI_ReleaseObj( hdcs );
507 DeleteDC( hdcs );
508 return 0;
511 dcs->header.hNext = dc->header.hNext;
512 dc->header.hNext = HDC_16(hdcs);
513 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
514 ret = ++dc->saveLevel;
515 GDI_ReleaseObj( hdcs );
516 GDI_ReleaseObj( hdc );
517 return ret;
521 /***********************************************************************
522 * RestoreDC (GDI32.@)
524 BOOL WINAPI RestoreDC( HDC hdc, INT level )
526 DC * dc, * dcs;
527 BOOL success;
529 TRACE("%p %d\n", hdc, level );
530 dc = DC_GetDCUpdate( hdc );
531 if(!dc) return FALSE;
532 if(dc->funcs->pRestoreDC)
534 success = dc->funcs->pRestoreDC( dc->physDev, level );
535 GDI_ReleaseObj( hdc );
536 return success;
539 if (level == -1) level = dc->saveLevel;
540 if ((level < 1)
541 /* This pair of checks disagrees with MSDN "Platform SDK:
542 Windows GDI" July 2000 which says all negative values
543 for level will be interpreted as an instance relative
544 to the current state. Restricting it to just -1 does
545 not satisfy this */
546 || (level > dc->saveLevel))
548 GDI_ReleaseObj( hdc );
549 return FALSE;
552 success=TRUE;
553 while (dc->saveLevel >= level)
555 HDC hdcs = HDC_32(dc->header.hNext);
556 if (!(dcs = DC_GetDCPtr( hdcs )))
558 GDI_ReleaseObj( hdc );
559 return FALSE;
561 dc->header.hNext = dcs->header.hNext;
562 if (--dc->saveLevel < level)
564 SetDCState( hdc, hdcs );
565 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
566 /* FIXME: This might not be quite right, since we're
567 * returning FALSE but still destroying the saved DC state */
568 success=FALSE;
570 GDI_ReleaseObj( hdcs );
571 GDI_ReleaseObj( hdc );
572 DeleteDC( hdcs );
573 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
575 GDI_ReleaseObj( hdc );
576 return success;
580 /***********************************************************************
581 * CreateDCW (GDI32.@)
583 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
584 const DEVMODEW *initData )
586 HDC hdc;
587 DC * dc;
588 const DC_FUNCTIONS *funcs;
589 WCHAR buf[300];
591 GDI_CheckNotLock();
593 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
595 if (!driver) return 0;
596 strcpyW(buf, driver);
599 if (!(funcs = DRIVER_load_driver( buf )))
601 ERR( "no driver found for %s\n", debugstr_w(buf) );
602 return 0;
604 if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
606 DRIVER_release_driver( funcs );
607 return 0;
610 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
612 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
613 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
615 if (dc->funcs->pCreateDC &&
616 !dc->funcs->pCreateDC( dc, &dc->physDev, buf, device, output, initData ))
618 WARN("creation aborted by device\n" );
619 GDI_FreeObject( dc->hSelf, dc );
620 DRIVER_release_driver( funcs );
621 return 0;
624 dc->totalExtent.left = 0;
625 dc->totalExtent.top = 0;
626 dc->totalExtent.right = GetDeviceCaps( dc->hSelf, HORZRES );
627 dc->totalExtent.bottom = GetDeviceCaps( dc->hSelf, VERTRES );
628 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
630 DC_InitDC( dc );
631 hdc = dc->hSelf;
632 GDI_ReleaseObj( hdc );
633 return hdc;
637 /***********************************************************************
638 * CreateDCA (GDI32.@)
640 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
641 const DEVMODEA *initData )
643 UNICODE_STRING driverW, deviceW, outputW;
644 DEVMODEW *initDataW;
645 HDC ret;
647 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
648 else driverW.Buffer = NULL;
650 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
651 else deviceW.Buffer = NULL;
653 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
654 else outputW.Buffer = NULL;
656 if (initData) initDataW = GdiConvertToDevmodeW(initData);
657 else initDataW = NULL;
659 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
661 RtlFreeUnicodeString(&driverW);
662 RtlFreeUnicodeString(&deviceW);
663 RtlFreeUnicodeString(&outputW);
664 if (initDataW) HeapFree(GetProcessHeap(), 0, initDataW);
665 return ret;
669 /***********************************************************************
670 * CreateICA (GDI32.@)
672 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
673 const DEVMODEA* initData )
675 /* Nothing special yet for ICs */
676 return CreateDCA( driver, device, output, initData );
680 /***********************************************************************
681 * CreateICW (GDI32.@)
683 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
684 const DEVMODEW* initData )
686 /* Nothing special yet for ICs */
687 return CreateDCW( driver, device, output, initData );
691 /***********************************************************************
692 * CreateCompatibleDC (GDI32.@)
694 HDC WINAPI CreateCompatibleDC( HDC hdc )
696 DC *dc, *origDC;
697 const DC_FUNCTIONS *funcs;
698 PHYSDEV physDev;
700 GDI_CheckNotLock();
702 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
704 funcs = origDC->funcs;
705 physDev = origDC->physDev;
706 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
707 funcs = DRIVER_get_driver( funcs );
709 else
711 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
712 funcs = DRIVER_load_driver( displayW );
713 physDev = NULL;
716 if (!funcs) return 0;
718 if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
720 DRIVER_release_driver( funcs );
721 return 0;
724 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
726 dc->bitsPerPixel = 1;
727 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
729 /* Copy the driver-specific physical device info into
730 * the new DC. The driver may use this read-only info
731 * while creating the compatible DC below. */
732 dc->physDev = physDev;
734 if (dc->funcs->pCreateDC &&
735 !dc->funcs->pCreateDC( dc, &dc->physDev, NULL, NULL, NULL, NULL ))
737 WARN("creation aborted by device\n");
738 GDI_FreeObject( dc->hSelf, dc );
739 DRIVER_release_driver( funcs );
740 return 0;
743 dc->totalExtent.left = 0;
744 dc->totalExtent.top = 0;
745 dc->totalExtent.right = 1; /* default bitmap is 1x1 */
746 dc->totalExtent.bottom = 1;
747 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
749 DC_InitDC( dc );
750 GDI_ReleaseObj( dc->hSelf );
751 return dc->hSelf;
755 /***********************************************************************
756 * DeleteDC (GDI32.@)
758 BOOL WINAPI DeleteDC( HDC hdc )
760 const DC_FUNCTIONS *funcs = NULL;
761 DC * dc;
763 TRACE("%p\n", hdc );
765 GDI_CheckNotLock();
767 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
769 /* Call hook procedure to check whether is it OK to delete this DC */
770 if (dc->hookThunk)
772 DCHOOKPROC proc = dc->hookThunk;
773 DWORD data = dc->dwHookData;
774 GDI_ReleaseObj( hdc );
775 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
776 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
779 while (dc->saveLevel)
781 DC * dcs;
782 HDC hdcs = HDC_32(dc->header.hNext);
783 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
784 dc->header.hNext = dcs->header.hNext;
785 dc->saveLevel--;
786 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
787 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
788 if (dcs->hGCClipRgn) DeleteObject( dcs->hGCClipRgn );
789 PATH_DestroyGdiPath(&dcs->path);
790 GDI_FreeObject( hdcs, dcs );
793 if (!(dc->flags & DC_SAVED))
795 SelectObject( hdc, GetStockObject(BLACK_PEN) );
796 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
797 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
798 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
799 funcs = dc->funcs;
800 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
801 dc->physDev = NULL;
804 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
805 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
806 if (dc->hGCClipRgn) DeleteObject( dc->hGCClipRgn );
807 PATH_DestroyGdiPath(&dc->path);
809 GDI_FreeObject( hdc, dc );
810 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
811 return TRUE;
815 /***********************************************************************
816 * ResetDCA (GDI32.@)
818 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
820 DC *dc;
821 HDC ret = hdc;
823 if ((dc = DC_GetDCPtr( hdc )))
825 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
826 GDI_ReleaseObj( hdc );
828 return ret;
832 /***********************************************************************
833 * ResetDCW (GDI32.@)
835 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
837 return ResetDCA(hdc, (const DEVMODEA*)devmode); /* FIXME */
841 /***********************************************************************
842 * GetDeviceCaps (GDI32.@)
844 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
846 DC *dc;
847 INT ret = 0;
849 if ((dc = DC_GetDCPtr( hdc )))
851 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
852 GDI_ReleaseObj( hdc );
854 return ret;
858 /***********************************************************************
859 * SetBkColor (GDI32.@)
861 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
863 COLORREF oldColor;
864 DC * dc = DC_GetDCPtr( hdc );
866 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
868 if (!dc) return CLR_INVALID;
869 oldColor = dc->backgroundColor;
870 if (dc->funcs->pSetBkColor)
872 color = dc->funcs->pSetBkColor(dc->physDev, color);
873 if (color == CLR_INVALID) /* don't change it */
875 color = oldColor;
876 oldColor = CLR_INVALID;
879 dc->backgroundColor = color;
880 GDI_ReleaseObj( hdc );
881 return oldColor;
885 /***********************************************************************
886 * SetTextColor (GDI32.@)
888 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
890 COLORREF oldColor;
891 DC * dc = DC_GetDCPtr( hdc );
893 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
895 if (!dc) return CLR_INVALID;
896 oldColor = dc->textColor;
897 if (dc->funcs->pSetTextColor)
899 color = dc->funcs->pSetTextColor(dc->physDev, color);
900 if (color == CLR_INVALID) /* don't change it */
902 color = oldColor;
903 oldColor = CLR_INVALID;
906 dc->textColor = color;
907 GDI_ReleaseObj( hdc );
908 return oldColor;
912 /***********************************************************************
913 * SetTextAlign (GDI32.@)
915 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
917 UINT prevAlign;
918 DC *dc = DC_GetDCPtr( hdc );
920 TRACE("hdc=%p align=%d\n", hdc, align);
922 if (!dc) return 0x0;
923 if (dc->funcs->pSetTextAlign)
924 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
925 else {
926 prevAlign = dc->textAlign;
927 dc->textAlign = align;
929 GDI_ReleaseObj( hdc );
930 return prevAlign;
933 /***********************************************************************
934 * GetDCOrgEx (GDI32.@)
936 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
938 DC * dc;
940 if (!lpp) return FALSE;
941 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
943 lpp->x = lpp->y = 0;
944 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
945 GDI_ReleaseObj( hDC );
946 return TRUE;
950 /***********************************************************************
951 * SetDCOrg (GDI.117)
953 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
955 DWORD prevOrg = 0;
956 HDC hdc = HDC_32( hdc16 );
957 DC *dc = DC_GetDCPtr( hdc );
958 if (!dc) return 0;
959 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
960 GDI_ReleaseObj( hdc );
961 return prevOrg;
965 /***********************************************************************
966 * SetGraphicsMode (GDI32.@)
968 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
970 INT ret = 0;
971 DC *dc = DC_GetDCPtr( hdc );
973 /* One would think that setting the graphics mode to GM_COMPATIBLE
974 * would also reset the world transformation matrix to the unity
975 * matrix. However, in Windows, this is not the case. This doesn't
976 * make a lot of sense to me, but that's the way it is.
978 if (!dc) return 0;
979 if ((mode > 0) && (mode <= GM_LAST))
981 ret = dc->GraphicsMode;
982 dc->GraphicsMode = mode;
984 GDI_ReleaseObj( hdc );
985 return ret;
989 /***********************************************************************
990 * SetArcDirection (GDI32.@)
992 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
994 DC * dc;
995 INT nOldDirection = 0;
997 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
999 SetLastError(ERROR_INVALID_PARAMETER);
1000 return 0;
1003 if ((dc = DC_GetDCPtr( hdc )))
1005 if (dc->funcs->pSetArcDirection)
1007 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1009 nOldDirection = dc->ArcDirection;
1010 dc->ArcDirection = nDirection;
1011 GDI_ReleaseObj( hdc );
1013 return nOldDirection;
1017 /***********************************************************************
1018 * GetWorldTransform (GDI32.@)
1020 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1022 DC * dc;
1023 if (!xform) return FALSE;
1024 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1025 *xform = dc->xformWorld2Wnd;
1026 GDI_ReleaseObj( hdc );
1027 return TRUE;
1031 /***********************************************************************
1032 * GetTransform (GDI32.@)
1034 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1036 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1037 ERR("stub: don't know what to do for code %lx\n", unknown );
1038 return FALSE;
1042 /***********************************************************************
1043 * SetWorldTransform (GDI32.@)
1045 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1047 BOOL ret = FALSE;
1048 DC *dc = DC_GetDCPtr( hdc );
1050 if (!dc) return FALSE;
1051 if (!xform) goto done;
1053 /* Check that graphics mode is GM_ADVANCED */
1054 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1056 if (dc->funcs->pSetWorldTransform)
1058 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1059 if (!ret) goto done;
1062 dc->xformWorld2Wnd = *xform;
1063 DC_UpdateXforms( dc );
1064 ret = TRUE;
1065 done:
1066 GDI_ReleaseObj( hdc );
1067 return ret;
1071 /****************************************************************************
1072 * ModifyWorldTransform [GDI32.@]
1073 * Modifies the world transformation for a device context.
1075 * PARAMS
1076 * hdc [I] Handle to device context
1077 * xform [I] XFORM structure that will be used to modify the world
1078 * transformation
1079 * iMode [I] Specifies in what way to modify the world transformation
1080 * Possible values:
1081 * MWT_IDENTITY
1082 * Resets the world transformation to the identity matrix.
1083 * The parameter xform is ignored.
1084 * MWT_LEFTMULTIPLY
1085 * Multiplies xform into the world transformation matrix from
1086 * the left.
1087 * MWT_RIGHTMULTIPLY
1088 * Multiplies xform into the world transformation matrix from
1089 * the right.
1091 * RETURNS STD
1093 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1094 DWORD iMode )
1096 BOOL ret = FALSE;
1097 DC *dc = DC_GetDCPtr( hdc );
1099 /* Check for illegal parameters */
1100 if (!dc) return FALSE;
1101 if (!xform) goto done;
1103 /* Check that graphics mode is GM_ADVANCED */
1104 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1106 if (dc->funcs->pModifyWorldTransform)
1108 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1109 if (!ret) goto done;
1112 switch (iMode)
1114 case MWT_IDENTITY:
1115 dc->xformWorld2Wnd.eM11 = 1.0f;
1116 dc->xformWorld2Wnd.eM12 = 0.0f;
1117 dc->xformWorld2Wnd.eM21 = 0.0f;
1118 dc->xformWorld2Wnd.eM22 = 1.0f;
1119 dc->xformWorld2Wnd.eDx = 0.0f;
1120 dc->xformWorld2Wnd.eDy = 0.0f;
1121 break;
1122 case MWT_LEFTMULTIPLY:
1123 CombineTransform( &dc->xformWorld2Wnd, xform,
1124 &dc->xformWorld2Wnd );
1125 break;
1126 case MWT_RIGHTMULTIPLY:
1127 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1128 xform );
1129 break;
1130 default:
1131 goto done;
1134 DC_UpdateXforms( dc );
1135 ret = TRUE;
1136 done:
1137 GDI_ReleaseObj( hdc );
1138 return ret;
1142 /****************************************************************************
1143 * CombineTransform [GDI32.@]
1144 * Combines two transformation matrices.
1146 * PARAMS
1147 * xformResult [O] Stores the result of combining the two matrices
1148 * xform1 [I] Specifies the first matrix to apply
1149 * xform2 [I] Specifies the second matrix to apply
1151 * REMARKS
1152 * The same matrix can be passed in for more than one of the parameters.
1154 * RETURNS STD
1156 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1157 const XFORM *xform2 )
1159 XFORM xformTemp;
1161 /* Check for illegal parameters */
1162 if (!xformResult || !xform1 || !xform2)
1163 return FALSE;
1165 /* Create the result in a temporary XFORM, since xformResult may be
1166 * equal to xform1 or xform2 */
1167 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1168 xform1->eM12 * xform2->eM21;
1169 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1170 xform1->eM12 * xform2->eM22;
1171 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1172 xform1->eM22 * xform2->eM21;
1173 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1174 xform1->eM22 * xform2->eM22;
1175 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1176 xform1->eDy * xform2->eM21 +
1177 xform2->eDx;
1178 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1179 xform1->eDy * xform2->eM22 +
1180 xform2->eDy;
1182 /* Copy the result to xformResult */
1183 *xformResult = xformTemp;
1185 return TRUE;
1189 /***********************************************************************
1190 * SetDCHook (GDI32.@)
1192 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1194 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1196 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1198 if (!dc) return FALSE;
1200 if (!(dc->flags & DC_SAVED))
1202 dc->dwHookData = dwHookData;
1203 dc->hookThunk = hookProc;
1205 GDI_ReleaseObj( hdc );
1206 return TRUE;
1210 /* relay function to call the 16-bit DC hook proc */
1211 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1213 WORD args[6];
1214 DWORD ret;
1215 FARPROC16 proc = NULL;
1216 HDC hdc = HDC_32( hdc16 );
1217 DC *dc = DC_GetDCPtr( hdc );
1219 if (!dc) return FALSE;
1220 proc = dc->hookProc;
1221 GDI_ReleaseObj( hdc );
1222 if (!proc) return FALSE;
1223 args[5] = hdc16;
1224 args[4] = code;
1225 args[3] = HIWORD(data);
1226 args[2] = LOWORD(data);
1227 args[1] = HIWORD(lParam);
1228 args[0] = LOWORD(lParam);
1229 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1230 return LOWORD(ret);
1233 /***********************************************************************
1234 * SetDCHook (GDI.190)
1236 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1238 HDC hdc = HDC_32( hdc16 );
1239 DC *dc = DC_GetDCPtr( hdc );
1240 if (!dc) return FALSE;
1242 dc->hookProc = hookProc;
1243 GDI_ReleaseObj( hdc );
1244 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1248 /***********************************************************************
1249 * GetDCHook (GDI.191)
1251 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1253 HDC hdc = HDC_32( hdc16 );
1254 DC *dc = DC_GetDCPtr( hdc );
1255 DWORD ret;
1257 if (!dc) return 0;
1258 *phookProc = dc->hookProc;
1259 ret = dc->dwHookData;
1260 GDI_ReleaseObj( hdc );
1261 return ret;
1265 /***********************************************************************
1266 * SetHookFlags (GDI.192)
1268 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1270 HDC hdc = HDC_32( hdc16 );
1271 DC *dc = DC_GetDCPtr( hdc );
1273 if( dc )
1275 WORD wRet = dc->flags & DC_DIRTY;
1277 /* "Undocumented Windows" info is slightly confusing.
1280 TRACE("hDC %p, flags %04x\n",hdc,flags);
1282 if( flags & DCHF_INVALIDATEVISRGN )
1283 dc->flags |= DC_DIRTY;
1284 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1285 dc->flags &= ~DC_DIRTY;
1286 GDI_ReleaseObj( hdc );
1287 return wRet;
1289 return 0;
1292 /***********************************************************************
1293 * SetICMMode (GDI32.@)
1295 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1297 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1298 if (iEnableICM == ICM_OFF) return ICM_OFF;
1299 if (iEnableICM == ICM_ON) return 0;
1300 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1301 return 0;
1304 /***********************************************************************
1305 * GetDeviceGammaRamp (GDI32.@)
1307 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1309 BOOL ret = FALSE;
1310 DC *dc = DC_GetDCPtr( hDC );
1312 if( dc )
1314 if (dc->funcs->pGetDeviceGammaRamp)
1315 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1316 GDI_ReleaseObj( hDC );
1318 return ret;
1321 /***********************************************************************
1322 * SetDeviceGammaRamp (GDI32.@)
1324 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1326 BOOL ret = FALSE;
1327 DC *dc = DC_GetDCPtr( hDC );
1329 if( dc )
1331 if (dc->funcs->pSetDeviceGammaRamp)
1332 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1333 GDI_ReleaseObj( hDC );
1335 return ret;
1338 /***********************************************************************
1339 * GetColorSpace (GDI32.@)
1341 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1343 /*FIXME Need to to whatever GetColorSpace actually does */
1344 return 0;
1347 /***********************************************************************
1348 * CreateColorSpaceA (GDI32.@)
1350 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1352 FIXME( "stub\n" );
1353 return 0;
1356 /***********************************************************************
1357 * CreateColorSpaceW (GDI32.@)
1359 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1361 FIXME( "stub\n" );
1362 return 0;
1365 /***********************************************************************
1366 * DeleteColorSpace (GDI32.@)
1368 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1370 FIXME( "stub\n" );
1372 return TRUE;
1375 /***********************************************************************
1376 * SetColorSpace (GDI32.@)
1378 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1380 FIXME( "stub\n" );
1382 return hColorSpace;
1385 /***********************************************************************
1386 * GetBoundsRect (GDI.194)
1388 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1390 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1393 /***********************************************************************
1394 * GetBoundsRect (GDI32.@)
1396 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1398 FIXME("(): stub\n");
1399 return DCB_RESET; /* bounding rectangle always empty */
1402 /***********************************************************************
1403 * SetBoundsRect (GDI.193)
1405 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1407 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1408 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1410 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1413 /***********************************************************************
1414 * SetBoundsRect (GDI32.@)
1416 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1418 FIXME("(): stub\n");
1419 return DCB_DISABLE; /* bounding rectangle always empty */
1423 /***********************************************************************
1424 * GetRelAbs (GDI32.@)
1426 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1428 INT ret = 0;
1429 DC *dc = DC_GetDCPtr( hdc );
1430 if (dc) ret = dc->relAbsMode;
1431 GDI_ReleaseObj( hdc );
1432 return ret;
1435 /***********************************************************************
1436 * GetLayout (GDI32.@)
1438 * Gets left->right or right->left text layout flags of a dc.
1439 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1442 DWORD WINAPI GetLayout(HDC hdc)
1444 FIXME("(%p): stub\n", hdc);
1445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1446 return 0;
1449 /***********************************************************************
1450 * SetLayout (GDI32.@)
1452 * Sets left->right or right->left text layout flags of a dc.
1453 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1456 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1458 FIXME("(%p,%08lx): stub\n", hdc, layout);
1459 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1460 return 0;
1463 /***********************************************************************
1464 * GetDCBrushColor (GDI32.@)
1466 * Retrieves the current brush color for the specified device
1467 * context (DC).
1470 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1472 DC *dc;
1473 COLORREF dcBrushColor = CLR_INVALID;
1475 TRACE("hdc(%p)\n", hdc);
1477 dc = DC_GetDCPtr( hdc );
1478 if (dc)
1480 dcBrushColor = dc->dcBrushColor;
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;
1546 return dcPenColor;
1549 /***********************************************************************
1550 * SetDCPenColor (GDI32.@)
1552 * Sets the current device context (DC) pen color to the specified
1553 * color value. If the device cannot represent the specified color
1554 * value, the color is set to the nearest physical color.
1557 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1559 DC *dc;
1560 COLORREF oldClr = CLR_INVALID;
1562 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1564 dc = DC_GetDCPtr( hdc );
1565 if (dc)
1567 if (dc->funcs->pSetDCPenColor)
1568 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
1569 else if (dc->hPen == GetStockObject( DC_PEN ))
1571 /* If DC_PEN is selected, update the driver pen color */
1572 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
1573 HPEN hPen = CreatePenIndirect( &logpen );
1574 dc->funcs->pSelectPen( dc->physDev, hPen );
1575 DeleteObject( hPen );
1578 if (crColor != CLR_INVALID)
1580 oldClr = dc->dcPenColor;
1581 dc->dcPenColor = crColor;
1584 GDI_ReleaseObj( hdc );
1587 return oldClr;
1590 /***********************************************************************
1591 * SetVirtualResolution (GDI32.@)
1593 * Undocumented on msdn. Called when PowerPoint XP saves a file.
1595 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
1597 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
1598 return FALSE;