Moved a bunch of definitions from gdi.h into a new gdi_private.h to
[wine/multimedia.git] / objects / dc.c
blobebd8e8d6af551c549359e969f71c1c8da1b1d831
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->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 * ResetDCW (GDI32.@)
818 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *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 * ResetDCA (GDI32.@)
835 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
837 DEVMODEW *devmodeW;
838 HDC ret;
840 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
841 else devmodeW = NULL;
843 ret = ResetDCW(hdc, devmodeW);
845 if (devmodeW) HeapFree(GetProcessHeap(), 0, devmodeW);
846 return ret;
850 /***********************************************************************
851 * GetDeviceCaps (GDI32.@)
853 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
855 DC *dc;
856 INT ret = 0;
858 if ((dc = DC_GetDCPtr( hdc )))
860 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
861 GDI_ReleaseObj( hdc );
863 return ret;
867 /***********************************************************************
868 * SetBkColor (GDI32.@)
870 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
872 COLORREF oldColor;
873 DC * dc = DC_GetDCPtr( hdc );
875 TRACE("hdc=%p color=0x%08lx\n", hdc, color);
877 if (!dc) return CLR_INVALID;
878 oldColor = dc->backgroundColor;
879 if (dc->funcs->pSetBkColor)
881 color = dc->funcs->pSetBkColor(dc->physDev, color);
882 if (color == CLR_INVALID) /* don't change it */
884 color = oldColor;
885 oldColor = CLR_INVALID;
888 dc->backgroundColor = color;
889 GDI_ReleaseObj( hdc );
890 return oldColor;
894 /***********************************************************************
895 * SetTextColor (GDI32.@)
897 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
899 COLORREF oldColor;
900 DC * dc = DC_GetDCPtr( hdc );
902 TRACE(" hdc=%p color=0x%08lx\n", hdc, color);
904 if (!dc) return CLR_INVALID;
905 oldColor = dc->textColor;
906 if (dc->funcs->pSetTextColor)
908 color = dc->funcs->pSetTextColor(dc->physDev, color);
909 if (color == CLR_INVALID) /* don't change it */
911 color = oldColor;
912 oldColor = CLR_INVALID;
915 dc->textColor = color;
916 GDI_ReleaseObj( hdc );
917 return oldColor;
921 /***********************************************************************
922 * SetTextAlign (GDI32.@)
924 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
926 UINT prevAlign;
927 DC *dc = DC_GetDCPtr( hdc );
929 TRACE("hdc=%p align=%d\n", hdc, align);
931 if (!dc) return 0x0;
932 if (dc->funcs->pSetTextAlign)
933 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
934 else {
935 prevAlign = dc->textAlign;
936 dc->textAlign = align;
938 GDI_ReleaseObj( hdc );
939 return prevAlign;
942 /***********************************************************************
943 * GetDCOrgEx (GDI32.@)
945 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
947 DC * dc;
949 if (!lpp) return FALSE;
950 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
952 lpp->x = lpp->y = 0;
953 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
954 GDI_ReleaseObj( hDC );
955 return TRUE;
959 /***********************************************************************
960 * SetDCOrg (GDI.117)
962 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
964 DWORD prevOrg = 0;
965 HDC hdc = HDC_32( hdc16 );
966 DC *dc = DC_GetDCPtr( hdc );
967 if (!dc) return 0;
968 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
969 GDI_ReleaseObj( hdc );
970 return prevOrg;
974 /***********************************************************************
975 * SetGraphicsMode (GDI32.@)
977 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
979 INT ret = 0;
980 DC *dc = DC_GetDCPtr( hdc );
982 /* One would think that setting the graphics mode to GM_COMPATIBLE
983 * would also reset the world transformation matrix to the unity
984 * matrix. However, in Windows, this is not the case. This doesn't
985 * make a lot of sense to me, but that's the way it is.
987 if (!dc) return 0;
988 if ((mode > 0) && (mode <= GM_LAST))
990 ret = dc->GraphicsMode;
991 dc->GraphicsMode = mode;
993 GDI_ReleaseObj( hdc );
994 return ret;
998 /***********************************************************************
999 * SetArcDirection (GDI32.@)
1001 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1003 DC * dc;
1004 INT nOldDirection = 0;
1006 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1008 SetLastError(ERROR_INVALID_PARAMETER);
1009 return 0;
1012 if ((dc = DC_GetDCPtr( hdc )))
1014 if (dc->funcs->pSetArcDirection)
1016 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1018 nOldDirection = dc->ArcDirection;
1019 dc->ArcDirection = nDirection;
1020 GDI_ReleaseObj( hdc );
1022 return nOldDirection;
1026 /***********************************************************************
1027 * GetWorldTransform (GDI32.@)
1029 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1031 DC * dc;
1032 if (!xform) return FALSE;
1033 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1034 *xform = dc->xformWorld2Wnd;
1035 GDI_ReleaseObj( hdc );
1036 return TRUE;
1040 /***********************************************************************
1041 * GetTransform (GDI32.@)
1043 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1045 if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1046 FIXME("stub: don't know what to do for code %lx\n", unknown );
1047 return FALSE;
1051 /***********************************************************************
1052 * SetWorldTransform (GDI32.@)
1054 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1056 BOOL ret = FALSE;
1057 DC *dc = DC_GetDCPtr( hdc );
1059 if (!dc) return FALSE;
1060 if (!xform) goto done;
1062 /* Check that graphics mode is GM_ADVANCED */
1063 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1065 if (dc->funcs->pSetWorldTransform)
1067 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1068 if (!ret) goto done;
1071 dc->xformWorld2Wnd = *xform;
1072 DC_UpdateXforms( dc );
1073 ret = TRUE;
1074 done:
1075 GDI_ReleaseObj( hdc );
1076 return ret;
1080 /****************************************************************************
1081 * ModifyWorldTransform [GDI32.@]
1082 * Modifies the world transformation for a device context.
1084 * PARAMS
1085 * hdc [I] Handle to device context
1086 * xform [I] XFORM structure that will be used to modify the world
1087 * transformation
1088 * iMode [I] Specifies in what way to modify the world transformation
1089 * Possible values:
1090 * MWT_IDENTITY
1091 * Resets the world transformation to the identity matrix.
1092 * The parameter xform is ignored.
1093 * MWT_LEFTMULTIPLY
1094 * Multiplies xform into the world transformation matrix from
1095 * the left.
1096 * MWT_RIGHTMULTIPLY
1097 * Multiplies xform into the world transformation matrix from
1098 * the right.
1100 * RETURNS STD
1102 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1103 DWORD iMode )
1105 BOOL ret = FALSE;
1106 DC *dc = DC_GetDCPtr( hdc );
1108 /* Check for illegal parameters */
1109 if (!dc) return FALSE;
1110 if (!xform) goto done;
1112 /* Check that graphics mode is GM_ADVANCED */
1113 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1115 if (dc->funcs->pModifyWorldTransform)
1117 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1118 if (!ret) goto done;
1121 switch (iMode)
1123 case MWT_IDENTITY:
1124 dc->xformWorld2Wnd.eM11 = 1.0f;
1125 dc->xformWorld2Wnd.eM12 = 0.0f;
1126 dc->xformWorld2Wnd.eM21 = 0.0f;
1127 dc->xformWorld2Wnd.eM22 = 1.0f;
1128 dc->xformWorld2Wnd.eDx = 0.0f;
1129 dc->xformWorld2Wnd.eDy = 0.0f;
1130 break;
1131 case MWT_LEFTMULTIPLY:
1132 CombineTransform( &dc->xformWorld2Wnd, xform,
1133 &dc->xformWorld2Wnd );
1134 break;
1135 case MWT_RIGHTMULTIPLY:
1136 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1137 xform );
1138 break;
1139 default:
1140 goto done;
1143 DC_UpdateXforms( dc );
1144 ret = TRUE;
1145 done:
1146 GDI_ReleaseObj( hdc );
1147 return ret;
1151 /****************************************************************************
1152 * CombineTransform [GDI32.@]
1153 * Combines two transformation matrices.
1155 * PARAMS
1156 * xformResult [O] Stores the result of combining the two matrices
1157 * xform1 [I] Specifies the first matrix to apply
1158 * xform2 [I] Specifies the second matrix to apply
1160 * REMARKS
1161 * The same matrix can be passed in for more than one of the parameters.
1163 * RETURNS STD
1165 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1166 const XFORM *xform2 )
1168 XFORM xformTemp;
1170 /* Check for illegal parameters */
1171 if (!xformResult || !xform1 || !xform2)
1172 return FALSE;
1174 /* Create the result in a temporary XFORM, since xformResult may be
1175 * equal to xform1 or xform2 */
1176 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1177 xform1->eM12 * xform2->eM21;
1178 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1179 xform1->eM12 * xform2->eM22;
1180 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1181 xform1->eM22 * xform2->eM21;
1182 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1183 xform1->eM22 * xform2->eM22;
1184 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1185 xform1->eDy * xform2->eM21 +
1186 xform2->eDx;
1187 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1188 xform1->eDy * xform2->eM22 +
1189 xform2->eDy;
1191 /* Copy the result to xformResult */
1192 *xformResult = xformTemp;
1194 return TRUE;
1198 /***********************************************************************
1199 * SetDCHook (GDI32.@)
1201 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1203 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1205 DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1207 if (!dc) return FALSE;
1209 if (!(dc->flags & DC_SAVED))
1211 dc->dwHookData = dwHookData;
1212 dc->hookThunk = hookProc;
1214 GDI_ReleaseObj( hdc );
1215 return TRUE;
1219 /* relay function to call the 16-bit DC hook proc */
1220 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1222 WORD args[6];
1223 DWORD ret;
1224 FARPROC16 proc = NULL;
1225 HDC hdc = HDC_32( hdc16 );
1226 DC *dc = DC_GetDCPtr( hdc );
1228 if (!dc) return FALSE;
1229 proc = dc->hookProc;
1230 GDI_ReleaseObj( hdc );
1231 if (!proc) return FALSE;
1232 args[5] = hdc16;
1233 args[4] = code;
1234 args[3] = HIWORD(data);
1235 args[2] = LOWORD(data);
1236 args[1] = HIWORD(lParam);
1237 args[0] = LOWORD(lParam);
1238 WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1239 return LOWORD(ret);
1242 /***********************************************************************
1243 * SetDCHook (GDI.190)
1245 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1247 HDC hdc = HDC_32( hdc16 );
1248 DC *dc = DC_GetDCPtr( hdc );
1249 if (!dc) return FALSE;
1251 dc->hookProc = hookProc;
1252 GDI_ReleaseObj( hdc );
1253 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1257 /***********************************************************************
1258 * GetDCHook (GDI.191)
1260 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1262 HDC hdc = HDC_32( hdc16 );
1263 DC *dc = DC_GetDCPtr( hdc );
1264 DWORD ret;
1266 if (!dc) return 0;
1267 *phookProc = dc->hookProc;
1268 ret = dc->dwHookData;
1269 GDI_ReleaseObj( hdc );
1270 return ret;
1274 /***********************************************************************
1275 * SetHookFlags (GDI.192)
1277 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1279 HDC hdc = HDC_32( hdc16 );
1280 DC *dc = DC_GetDCPtr( hdc );
1282 if( dc )
1284 WORD wRet = dc->flags & DC_DIRTY;
1286 /* "Undocumented Windows" info is slightly confusing.
1289 TRACE("hDC %p, flags %04x\n",hdc,flags);
1291 if( flags & DCHF_INVALIDATEVISRGN )
1292 dc->flags |= DC_DIRTY;
1293 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1294 dc->flags &= ~DC_DIRTY;
1295 GDI_ReleaseObj( hdc );
1296 return wRet;
1298 return 0;
1301 /***********************************************************************
1302 * SetICMMode (GDI32.@)
1304 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1306 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1307 if (iEnableICM == ICM_OFF) return ICM_OFF;
1308 if (iEnableICM == ICM_ON) return 0;
1309 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1310 return 0;
1313 /***********************************************************************
1314 * GetDeviceGammaRamp (GDI32.@)
1316 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1318 BOOL ret = FALSE;
1319 DC *dc = DC_GetDCPtr( hDC );
1321 if( dc )
1323 if (dc->funcs->pGetDeviceGammaRamp)
1324 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1325 GDI_ReleaseObj( hDC );
1327 return ret;
1330 /***********************************************************************
1331 * SetDeviceGammaRamp (GDI32.@)
1333 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1335 BOOL ret = FALSE;
1336 DC *dc = DC_GetDCPtr( hDC );
1338 if( dc )
1340 if (dc->funcs->pSetDeviceGammaRamp)
1341 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1342 GDI_ReleaseObj( hDC );
1344 return ret;
1347 /***********************************************************************
1348 * GetColorSpace (GDI32.@)
1350 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1352 /*FIXME Need to to whatever GetColorSpace actually does */
1353 return 0;
1356 /***********************************************************************
1357 * CreateColorSpaceA (GDI32.@)
1359 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1361 FIXME( "stub\n" );
1362 return 0;
1365 /***********************************************************************
1366 * CreateColorSpaceW (GDI32.@)
1368 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1370 FIXME( "stub\n" );
1371 return 0;
1374 /***********************************************************************
1375 * DeleteColorSpace (GDI32.@)
1377 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1379 FIXME( "stub\n" );
1381 return TRUE;
1384 /***********************************************************************
1385 * SetColorSpace (GDI32.@)
1387 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1389 FIXME( "stub\n" );
1391 return hColorSpace;
1394 /***********************************************************************
1395 * GetBoundsRect (GDI.194)
1397 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1399 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1402 /***********************************************************************
1403 * GetBoundsRect (GDI32.@)
1405 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1407 FIXME("(): stub\n");
1408 return DCB_RESET; /* bounding rectangle always empty */
1411 /***********************************************************************
1412 * SetBoundsRect (GDI.193)
1414 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1416 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1417 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1419 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1422 /***********************************************************************
1423 * SetBoundsRect (GDI32.@)
1425 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1427 FIXME("(): stub\n");
1428 return DCB_DISABLE; /* bounding rectangle always empty */
1432 /***********************************************************************
1433 * GetRelAbs (GDI32.@)
1435 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1437 INT ret = 0;
1438 DC *dc = DC_GetDCPtr( hdc );
1439 if (dc) ret = dc->relAbsMode;
1440 GDI_ReleaseObj( hdc );
1441 return ret;
1444 /***********************************************************************
1445 * GetLayout (GDI32.@)
1447 * Gets left->right or right->left text layout flags of a dc.
1448 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1451 DWORD WINAPI GetLayout(HDC hdc)
1453 FIXME("(%p): stub\n", hdc);
1454 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1455 return 0;
1458 /***********************************************************************
1459 * SetLayout (GDI32.@)
1461 * Sets left->right or right->left text layout flags of a dc.
1462 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1465 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1467 FIXME("(%p,%08lx): stub\n", hdc, layout);
1468 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1469 return 0;
1472 /***********************************************************************
1473 * GetDCBrushColor (GDI32.@)
1475 * Retrieves the current brush color for the specified device
1476 * context (DC).
1479 COLORREF WINAPI GetDCBrushColor(HDC hdc)
1481 DC *dc;
1482 COLORREF dcBrushColor = CLR_INVALID;
1484 TRACE("hdc(%p)\n", hdc);
1486 dc = DC_GetDCPtr( hdc );
1487 if (dc)
1489 dcBrushColor = dc->dcBrushColor;
1490 GDI_ReleaseObj( hdc );
1493 return dcBrushColor;
1496 /***********************************************************************
1497 * SetDCBrushColor (GDI32.@)
1499 * Sets the current device context (DC) brush color to the specified
1500 * color value. If the device cannot represent the specified color
1501 * value, the color is set to the nearest physical color.
1504 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1506 DC *dc;
1507 COLORREF oldClr = CLR_INVALID;
1509 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1511 dc = DC_GetDCPtr( hdc );
1512 if (dc)
1514 if (dc->funcs->pSetDCBrushColor)
1515 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
1516 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
1518 /* If DC_BRUSH is selected, update driver pen color */
1519 HBRUSH hBrush = CreateSolidBrush( crColor );
1520 dc->funcs->pSelectBrush( dc->physDev, hBrush );
1521 DeleteObject( hBrush );
1524 if (crColor != CLR_INVALID)
1526 oldClr = dc->dcBrushColor;
1527 dc->dcBrushColor = crColor;
1530 GDI_ReleaseObj( hdc );
1533 return oldClr;
1536 /***********************************************************************
1537 * GetDCPenColor (GDI32.@)
1539 * Retrieves the current pen color for the specified device
1540 * context (DC).
1543 COLORREF WINAPI GetDCPenColor(HDC hdc)
1545 DC *dc;
1546 COLORREF dcPenColor = CLR_INVALID;
1548 TRACE("hdc(%p)\n", hdc);
1550 dc = DC_GetDCPtr( hdc );
1551 if (dc)
1553 dcPenColor = dc->dcPenColor;
1554 GDI_ReleaseObj( hdc );
1557 return dcPenColor;
1560 /***********************************************************************
1561 * SetDCPenColor (GDI32.@)
1563 * Sets the current device context (DC) pen color to the specified
1564 * color value. If the device cannot represent the specified color
1565 * value, the color is set to the nearest physical color.
1568 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
1570 DC *dc;
1571 COLORREF oldClr = CLR_INVALID;
1573 TRACE("hdc(%p) crColor(%08lx)\n", hdc, crColor);
1575 dc = DC_GetDCPtr( hdc );
1576 if (dc)
1578 if (dc->funcs->pSetDCPenColor)
1579 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
1580 else if (dc->hPen == GetStockObject( DC_PEN ))
1582 /* If DC_PEN is selected, update the driver pen color */
1583 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
1584 HPEN hPen = CreatePenIndirect( &logpen );
1585 dc->funcs->pSelectPen( dc->physDev, hPen );
1586 DeleteObject( hPen );
1589 if (crColor != CLR_INVALID)
1591 oldClr = dc->dcPenColor;
1592 dc->dcPenColor = crColor;
1595 GDI_ReleaseObj( hdc );
1598 return oldClr;
1601 /***********************************************************************
1602 * SetVirtualResolution (GDI32.@)
1604 * Undocumented on msdn. Called when PowerPoint XP saves a file.
1606 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
1608 FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
1609 return FALSE;