Fix strncpyWtoA to actually act as advertised (and not overflow the
[wine] / objects / dc.c
1 /*
2  * GDI Device Context functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
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"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(dc);
40
41 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
42
43 static const struct gdi_obj_funcs dc_funcs =
44 {
45     NULL,             /* pSelectObject */
46     NULL,             /* pGetObject16 */
47     NULL,             /* pGetObjectA */
48     NULL,             /* pGetObjectW */
49     NULL,             /* pUnrealizeObject */
50     DC_DeleteObject   /* pDeleteObject */
51 };
52
53 /***********************************************************************
54  *           DC_AllocDC
55  */
56 DC *DC_AllocDC( const DC_FUNCTIONS *funcs, WORD magic )
57 {
58     HDC hdc;
59     DC *dc;
60
61     if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
62
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->textColor           = RGB( 0, 0, 0 );
96     dc->brushOrgX           = 0;
97     dc->brushOrgY           = 0;
98     dc->textAlign           = TA_LEFT | TA_TOP | TA_NOUPDATECP;
99     dc->charExtra           = 0;
100     dc->breakTotalExtra     = 0;
101     dc->breakCount          = 0;
102     dc->breakExtra          = 0;
103     dc->breakRem            = 0;
104     dc->totalExtent.left    = 0;
105     dc->totalExtent.top     = 0;
106     dc->totalExtent.right   = 0;
107     dc->totalExtent.bottom  = 0;
108     dc->bitsPerPixel        = 1;
109     dc->MapMode             = MM_TEXT;
110     dc->GraphicsMode        = GM_COMPATIBLE;
111     dc->pAbortProc          = NULL;
112     dc->CursPosX            = 0;
113     dc->CursPosY            = 0;
114     dc->ArcDirection        = AD_COUNTERCLOCKWISE;
115     dc->xformWorld2Wnd.eM11 = 1.0f;
116     dc->xformWorld2Wnd.eM12 = 0.0f;
117     dc->xformWorld2Wnd.eM21 = 0.0f;
118     dc->xformWorld2Wnd.eM22 = 1.0f;
119     dc->xformWorld2Wnd.eDx  = 0.0f;
120     dc->xformWorld2Wnd.eDy  = 0.0f;
121     dc->xformWorld2Vport    = dc->xformWorld2Wnd;
122     dc->xformVport2World    = dc->xformWorld2Wnd;
123     dc->vport2WorldValid    = TRUE;
124     PATH_InitGdiPath(&dc->path);
125     return dc;
126 }
127
128
129
130 /***********************************************************************
131  *           DC_GetDCPtr
132  */
133 DC *DC_GetDCPtr( HDC hdc )
134 {
135     GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
136     if (!ptr) return NULL;
137     if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
138         (GDIMAGIC(ptr->wMagic) == MEMORY_DC_MAGIC) ||
139         (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
140         (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
141         return (DC *)ptr;
142     GDI_ReleaseObj( hdc );
143     SetLastError( ERROR_INVALID_HANDLE );
144     return NULL;
145 }
146
147 /***********************************************************************
148  *           DC_GetDCUpdate
149  *
150  * Retrieve a DC ptr while making sure the visRgn is updated.
151  * This function may call up to USER so the GDI lock should _not_
152  * be held when calling it.
153  */
154 DC *DC_GetDCUpdate( HDC hdc )
155 {
156     DC *dc = DC_GetDCPtr( hdc );
157     if (!dc) return NULL;
158     while (dc->flags & DC_DIRTY)
159     {
160         DCHOOKPROC proc = dc->hookThunk;
161         dc->flags &= ~DC_DIRTY;
162         if (proc)
163         {
164             DWORD data = dc->dwHookData;
165             GDI_ReleaseObj( hdc );
166             proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
167             if (!(dc = DC_GetDCPtr( hdc ))) break;
168             /* otherwise restart the loop in case it became dirty again in the meantime */
169         }
170     }
171     return dc;
172 }
173
174
175 /***********************************************************************
176  *           DC_DeleteObject
177  */
178 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
179 {
180     GDI_ReleaseObj( handle );
181     return DeleteDC( handle );
182 }
183
184
185 /***********************************************************************
186  *           DC_InitDC
187  *
188  * Setup device-specific DC values for a newly created DC.
189  */
190 void DC_InitDC( DC* dc )
191 {
192     if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
193     SetTextColor( dc->hSelf, dc->textColor );
194     SetBkColor( dc->hSelf, dc->backgroundColor );
195     SelectObject( dc->hSelf, dc->hPen );
196     SelectObject( dc->hSelf, dc->hBrush );
197     SelectObject( dc->hSelf, dc->hFont );
198     CLIPPING_UpdateGCRegion( dc );
199 }
200
201
202 /***********************************************************************
203  *           DC_InvertXform
204  *
205  * Computes the inverse of the transformation xformSrc and stores it to
206  * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
207  * is singular.
208  */
209 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
210 {
211     FLOAT determinant;
212
213     determinant = xformSrc->eM11*xformSrc->eM22 -
214         xformSrc->eM12*xformSrc->eM21;
215     if (determinant > -1e-12 && determinant < 1e-12)
216         return FALSE;
217
218     xformDest->eM11 =  xformSrc->eM22 / determinant;
219     xformDest->eM12 = -xformSrc->eM12 / determinant;
220     xformDest->eM21 = -xformSrc->eM21 / determinant;
221     xformDest->eM22 =  xformSrc->eM11 / determinant;
222     xformDest->eDx  = -xformSrc->eDx * xformDest->eM11 -
223                        xformSrc->eDy * xformDest->eM21;
224     xformDest->eDy  = -xformSrc->eDx * xformDest->eM12 -
225                        xformSrc->eDy * xformDest->eM22;
226
227     return TRUE;
228 }
229
230
231 /***********************************************************************
232  *           DC_UpdateXforms
233  *
234  * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
235  * fields of the specified DC by creating a transformation that
236  * represents the current mapping mode and combining it with the DC's
237  * world transform. This function should be called whenever the
238  * parameters associated with the mapping mode (window and viewport
239  * extents and origins) or the world transform change.
240  */
241 void DC_UpdateXforms( DC *dc )
242 {
243     XFORM xformWnd2Vport;
244     FLOAT scaleX, scaleY;
245
246     /* Construct a transformation to do the window-to-viewport conversion */
247     scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
248     scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
249     xformWnd2Vport.eM11 = scaleX;
250     xformWnd2Vport.eM12 = 0.0;
251     xformWnd2Vport.eM21 = 0.0;
252     xformWnd2Vport.eM22 = scaleY;
253     xformWnd2Vport.eDx  = (FLOAT)dc->vportOrgX -
254         scaleX * (FLOAT)dc->wndOrgX;
255     xformWnd2Vport.eDy  = (FLOAT)dc->vportOrgY -
256         scaleY * (FLOAT)dc->wndOrgY;
257
258     /* Combine with the world transformation */
259     CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
260         &xformWnd2Vport );
261
262     /* Create inverse of world-to-viewport transformation */
263     dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
264         &dc->xformVport2World );
265
266     /* Reselect the font back into the dc so that the font size
267        gets updated. */
268     SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
269 }
270
271
272 /***********************************************************************
273  *           GetDCState   (Not a Windows API)
274  */
275 HDC WINAPI GetDCState( HDC hdc )
276 {
277     DC * newdc, * dc;
278     HGDIOBJ handle;
279
280     if (!(dc = DC_GetDCPtr( hdc ))) return 0;
281     if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
282     {
283       GDI_ReleaseObj( hdc );
284       return 0;
285     }
286     TRACE("(%p): returning %p\n", hdc, handle );
287
288     newdc->flags            = dc->flags | DC_SAVED;
289     newdc->hPen             = dc->hPen;
290     newdc->hBrush           = dc->hBrush;
291     newdc->hFont            = dc->hFont;
292     newdc->hBitmap          = dc->hBitmap;
293     newdc->hDevice          = dc->hDevice;
294     newdc->hPalette         = dc->hPalette;
295     newdc->totalExtent      = dc->totalExtent;
296     newdc->bitsPerPixel     = dc->bitsPerPixel;
297     newdc->ROPmode          = dc->ROPmode;
298     newdc->polyFillMode     = dc->polyFillMode;
299     newdc->stretchBltMode   = dc->stretchBltMode;
300     newdc->relAbsMode       = dc->relAbsMode;
301     newdc->backgroundMode   = dc->backgroundMode;
302     newdc->backgroundColor  = dc->backgroundColor;
303     newdc->textColor        = dc->textColor;
304     newdc->brushOrgX        = dc->brushOrgX;
305     newdc->brushOrgY        = dc->brushOrgY;
306     newdc->textAlign        = dc->textAlign;
307     newdc->charExtra        = dc->charExtra;
308     newdc->breakTotalExtra  = dc->breakTotalExtra;
309     newdc->breakCount       = dc->breakCount;
310     newdc->breakExtra       = dc->breakExtra;
311     newdc->breakRem         = dc->breakRem;
312     newdc->MapMode          = dc->MapMode;
313     newdc->GraphicsMode     = dc->GraphicsMode;
314     newdc->CursPosX         = dc->CursPosX;
315     newdc->CursPosY         = dc->CursPosY;
316     newdc->ArcDirection     = dc->ArcDirection;
317     newdc->xformWorld2Wnd   = dc->xformWorld2Wnd;
318     newdc->xformWorld2Vport = dc->xformWorld2Vport;
319     newdc->xformVport2World = dc->xformVport2World;
320     newdc->vport2WorldValid = dc->vport2WorldValid;
321     newdc->wndOrgX          = dc->wndOrgX;
322     newdc->wndOrgY          = dc->wndOrgY;
323     newdc->wndExtX          = dc->wndExtX;
324     newdc->wndExtY          = dc->wndExtY;
325     newdc->vportOrgX        = dc->vportOrgX;
326     newdc->vportOrgY        = dc->vportOrgY;
327     newdc->vportExtX        = dc->vportExtX;
328     newdc->vportExtY        = dc->vportExtY;
329
330     newdc->hSelf = (HDC)handle;
331     newdc->saveLevel = 0;
332
333     PATH_InitGdiPath( &newdc->path );
334
335     newdc->pAbortProc = NULL;
336     newdc->hookThunk  = NULL;
337     newdc->hookProc   = 0;
338
339     /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
340
341     newdc->hGCClipRgn = newdc->hVisRgn = 0;
342     if (dc->hClipRgn)
343     {
344         newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
345         CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
346     }
347     else
348         newdc->hClipRgn = 0;
349
350     if(dc->gdiFont) {
351         newdc->gdiFont = dc->gdiFont;
352     } else
353         newdc->gdiFont = 0;
354
355     GDI_ReleaseObj( handle );
356     GDI_ReleaseObj( hdc );
357     return handle;
358 }
359
360
361 /***********************************************************************
362  *           SetDCState   (Not a Windows API)
363  */
364 void WINAPI SetDCState( HDC hdc, HDC hdcs )
365 {
366     DC *dc, *dcs;
367
368     if (!(dc = DC_GetDCUpdate( hdc ))) return;
369     if (!(dcs = DC_GetDCPtr( hdcs )))
370     {
371       GDI_ReleaseObj( hdc );
372       return;
373     }
374     if (!dcs->flags & DC_SAVED)
375     {
376       GDI_ReleaseObj( hdc );
377       GDI_ReleaseObj( hdcs );
378       return;
379     }
380     TRACE("%p %p\n", hdc, hdcs );
381
382     dc->flags            = dcs->flags & ~(DC_SAVED | DC_DIRTY);
383     dc->hDevice          = dcs->hDevice;
384     dc->totalExtent      = dcs->totalExtent;
385     dc->ROPmode          = dcs->ROPmode;
386     dc->polyFillMode     = dcs->polyFillMode;
387     dc->stretchBltMode   = dcs->stretchBltMode;
388     dc->relAbsMode       = dcs->relAbsMode;
389     dc->backgroundMode   = dcs->backgroundMode;
390     dc->backgroundColor  = dcs->backgroundColor;
391     dc->textColor        = dcs->textColor;
392     dc->brushOrgX        = dcs->brushOrgX;
393     dc->brushOrgY        = dcs->brushOrgY;
394     dc->textAlign        = dcs->textAlign;
395     dc->charExtra        = dcs->charExtra;
396     dc->breakTotalExtra  = dcs->breakTotalExtra;
397     dc->breakCount       = dcs->breakCount;
398     dc->breakExtra       = dcs->breakExtra;
399     dc->breakRem         = dcs->breakRem;
400     dc->MapMode          = dcs->MapMode;
401     dc->GraphicsMode     = dcs->GraphicsMode;
402     dc->CursPosX         = dcs->CursPosX;
403     dc->CursPosY         = dcs->CursPosY;
404     dc->ArcDirection     = dcs->ArcDirection;
405     dc->xformWorld2Wnd   = dcs->xformWorld2Wnd;
406     dc->xformWorld2Vport = dcs->xformWorld2Vport;
407     dc->xformVport2World = dcs->xformVport2World;
408     dc->vport2WorldValid = dcs->vport2WorldValid;
409
410     dc->wndOrgX          = dcs->wndOrgX;
411     dc->wndOrgY          = dcs->wndOrgY;
412     dc->wndExtX          = dcs->wndExtX;
413     dc->wndExtY          = dcs->wndExtY;
414     dc->vportOrgX        = dcs->vportOrgX;
415     dc->vportOrgY        = dcs->vportOrgY;
416     dc->vportExtX        = dcs->vportExtX;
417     dc->vportExtY        = dcs->vportExtY;
418
419     if (GDIMAGIC(dc->header.wMagic) != MEMORY_DC_MAGIC) dc->bitsPerPixel = dcs->bitsPerPixel;
420
421     if (dcs->hClipRgn)
422     {
423         if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
424         CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
425     }
426     else
427     {
428         if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
429         dc->hClipRgn = 0;
430     }
431     CLIPPING_UpdateGCRegion( dc );
432
433     SelectObject( hdc, dcs->hBitmap );
434     SelectObject( hdc, dcs->hBrush );
435     SelectObject( hdc, dcs->hFont );
436     SelectObject( hdc, dcs->hPen );
437     SetBkColor( hdc, dcs->backgroundColor);
438     SetTextColor( hdc, dcs->textColor);
439     GDISelectPalette( hdc, dcs->hPalette, FALSE );
440     GDI_ReleaseObj( hdcs );
441     GDI_ReleaseObj( hdc );
442 }
443
444
445 /***********************************************************************
446  *           GetDCState   (GDI.179)
447  */
448 HDC16 WINAPI GetDCState16( HDC16 hdc )
449 {
450     return HDC_16( GetDCState( HDC_32(hdc) ));
451 }
452
453
454 /***********************************************************************
455  *           SetDCState   (GDI.180)
456  */
457 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
458 {
459     SetDCState( HDC_32(hdc), HDC_32(hdcs) );
460 }
461
462
463 /***********************************************************************
464  *           SaveDC    (GDI32.@)
465  */
466 INT WINAPI SaveDC( HDC hdc )
467 {
468     HDC hdcs;
469     DC * dc, * dcs;
470     INT ret;
471
472     dc = DC_GetDCPtr( hdc );
473     if (!dc) return 0;
474
475     if(dc->funcs->pSaveDC)
476     {
477         ret = dc->funcs->pSaveDC( dc->physDev );
478         GDI_ReleaseObj( hdc );
479         return ret;
480     }
481
482     if (!(hdcs = GetDCState( hdc )))
483     {
484       GDI_ReleaseObj( hdc );
485       return 0;
486     }
487     dcs = DC_GetDCPtr( hdcs );
488
489     /* Copy path. The reason why path saving / restoring is in SaveDC/
490      * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
491      * functions are only in Win16 (which doesn't have paths) and that
492      * SetDCState doesn't allow us to signal an error (which can happen
493      * when copying paths).
494      */
495     if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
496     {
497         GDI_ReleaseObj( hdc );
498         GDI_ReleaseObj( hdcs );
499         DeleteDC( hdcs );
500         return 0;
501     }
502
503     dcs->header.hNext = dc->header.hNext;
504     dc->header.hNext = HDC_16(hdcs);
505     TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
506     ret = ++dc->saveLevel;
507     GDI_ReleaseObj( hdcs );
508     GDI_ReleaseObj( hdc );
509     return ret;
510 }
511
512
513 /***********************************************************************
514  *           RestoreDC    (GDI32.@)
515  */
516 BOOL WINAPI RestoreDC( HDC hdc, INT level )
517 {
518     DC * dc, * dcs;
519     BOOL success;
520
521     TRACE("%p %d\n", hdc, level );
522     dc = DC_GetDCUpdate( hdc );
523     if(!dc) return FALSE;
524     if(dc->funcs->pRestoreDC)
525     {
526         success = dc->funcs->pRestoreDC( dc->physDev, level );
527         GDI_ReleaseObj( hdc );
528         return success;
529     }
530
531     if (level == -1) level = dc->saveLevel;
532     if ((level < 1)
533             /* This pair of checks disagrees with MSDN "Platform SDK:
534                Windows GDI" July 2000 which says all negative values
535                for level will be interpreted as an instance relative
536                to the current state.  Restricting it to just -1 does
537                not satisfy this */
538         || (level > dc->saveLevel))
539     {
540         GDI_ReleaseObj( hdc );
541         return FALSE;
542     }
543
544     success=TRUE;
545     while (dc->saveLevel >= level)
546     {
547         HDC hdcs = HDC_32(dc->header.hNext);
548         if (!(dcs = DC_GetDCPtr( hdcs )))
549         {
550           GDI_ReleaseObj( hdc );
551           return FALSE;
552         }
553         dc->header.hNext = dcs->header.hNext;
554         if (--dc->saveLevel < level)
555         {
556             SetDCState( hdc, hdcs );
557             if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
558                 /* FIXME: This might not be quite right, since we're
559                  * returning FALSE but still destroying the saved DC state */
560                 success=FALSE;
561         }
562         GDI_ReleaseObj( hdcs );
563         GDI_ReleaseObj( hdc );
564         DeleteDC( hdcs );
565         if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
566     }
567     GDI_ReleaseObj( hdc );
568     return success;
569 }
570
571
572 /***********************************************************************
573  *           CreateDCW    (GDI32.@)
574  */
575 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
576                       const DEVMODEW *initData )
577 {
578     HDC hdc;
579     DC * dc;
580     const DC_FUNCTIONS *funcs;
581     WCHAR buf[300];
582
583     GDI_CheckNotLock();
584
585     if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
586     {
587         if (!driver) return 0;
588         strcpyW(buf, driver);
589     }
590
591     if (!(funcs = DRIVER_load_driver( buf )))
592     {
593         ERR( "no driver found for %s\n", debugstr_w(buf) );
594         return 0;
595     }
596     if (!(dc = DC_AllocDC( funcs, DC_MAGIC )))
597     {
598         DRIVER_release_driver( funcs );
599         return 0;
600     }
601
602     dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
603
604     TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
605           debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
606
607     if (dc->funcs->pCreateDC &&
608         !dc->funcs->pCreateDC( dc, &dc->physDev, buf, device, output, initData ))
609     {
610         WARN("creation aborted by device\n" );
611         GDI_FreeObject( dc->hSelf, dc );
612         DRIVER_release_driver( funcs );
613         return 0;
614     }
615
616     dc->totalExtent.left   = 0;
617     dc->totalExtent.top    = 0;
618     dc->totalExtent.right  = GetDeviceCaps( dc->hSelf, HORZRES );
619     dc->totalExtent.bottom = GetDeviceCaps( dc->hSelf, VERTRES );
620     dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
621
622     DC_InitDC( dc );
623     hdc = dc->hSelf;
624     GDI_ReleaseObj( hdc );
625     return hdc;
626 }
627
628
629 /***********************************************************************
630  *           CreateDCA    (GDI32.@)
631  */
632 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
633                       const DEVMODEA *initData )
634 {
635     UNICODE_STRING driverW, deviceW, outputW;
636     DEVMODEW *initDataW;
637     HDC ret;
638
639     if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
640     else driverW.Buffer = NULL;
641
642     if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
643     else deviceW.Buffer = NULL;
644
645     if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
646     else outputW.Buffer = NULL;
647
648     if (initData) initDataW = GdiConvertToDevmodeW(initData);
649     else initDataW = NULL;
650
651     ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
652
653     RtlFreeUnicodeString(&driverW);
654     RtlFreeUnicodeString(&deviceW);
655     RtlFreeUnicodeString(&outputW);
656     if (initDataW) HeapFree(GetProcessHeap(), 0, initDataW);
657     return ret;
658 }
659
660
661 /***********************************************************************
662  *           CreateICA    (GDI32.@)
663  */
664 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
665                           const DEVMODEA* initData )
666 {
667       /* Nothing special yet for ICs */
668     return CreateDCA( driver, device, output, initData );
669 }
670
671
672 /***********************************************************************
673  *           CreateICW    (GDI32.@)
674  */
675 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
676                           const DEVMODEW* initData )
677 {
678       /* Nothing special yet for ICs */
679     return CreateDCW( driver, device, output, initData );
680 }
681
682
683 /***********************************************************************
684  *           CreateCompatibleDC   (GDI32.@)
685  */
686 HDC WINAPI CreateCompatibleDC( HDC hdc )
687 {
688     DC *dc, *origDC;
689     const DC_FUNCTIONS *funcs;
690     PHYSDEV physDev;
691
692     GDI_CheckNotLock();
693
694     if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
695     {
696         funcs = origDC->funcs;
697         physDev = origDC->physDev;
698         GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
699         funcs = DRIVER_get_driver( funcs );
700     }
701     else
702     {
703         static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
704         funcs = DRIVER_load_driver( displayW );
705         physDev = NULL;
706     }
707
708     if (!funcs) return 0;
709
710     if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC )))
711     {
712         DRIVER_release_driver( funcs );
713         return 0;
714     }
715
716     TRACE("(%p): returning %p\n", hdc, dc->hSelf );
717
718     dc->bitsPerPixel = 1;
719     dc->hBitmap      = GetStockObject( DEFAULT_BITMAP );
720
721     /* Copy the driver-specific physical device info into
722      * the new DC. The driver may use this read-only info
723      * while creating the compatible DC below. */
724     dc->physDev = physDev;
725
726     if (dc->funcs->pCreateDC &&
727         !dc->funcs->pCreateDC( dc, &dc->physDev, NULL, NULL, NULL, NULL ))
728     {
729         WARN("creation aborted by device\n");
730         GDI_FreeObject( dc->hSelf, dc );
731         DRIVER_release_driver( funcs );
732         return 0;
733     }
734
735     dc->totalExtent.left   = 0;
736     dc->totalExtent.top    = 0;
737     dc->totalExtent.right  = 1;  /* default bitmap is 1x1 */
738     dc->totalExtent.bottom = 1;
739     dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
740
741     DC_InitDC( dc );
742     GDI_ReleaseObj( dc->hSelf );
743     return dc->hSelf;
744 }
745
746
747 /***********************************************************************
748  *           DeleteDC    (GDI32.@)
749  */
750 BOOL WINAPI DeleteDC( HDC hdc )
751 {
752     const DC_FUNCTIONS *funcs = NULL;
753     DC * dc;
754
755     TRACE("%p\n", hdc );
756
757     GDI_CheckNotLock();
758
759     if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
760
761     /* Call hook procedure to check whether is it OK to delete this DC */
762     if (dc->hookThunk)
763     {
764         DCHOOKPROC proc = dc->hookThunk;
765         DWORD data = dc->dwHookData;
766         GDI_ReleaseObj( hdc );
767         if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
768         if (!(dc = DC_GetDCPtr( hdc ))) return TRUE;  /* deleted by the hook */
769     }
770
771     while (dc->saveLevel)
772     {
773         DC * dcs;
774         HDC hdcs = HDC_32(dc->header.hNext);
775         if (!(dcs = DC_GetDCPtr( hdcs ))) break;
776         dc->header.hNext = dcs->header.hNext;
777         dc->saveLevel--;
778         if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
779         if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
780         if (dcs->hGCClipRgn) DeleteObject( dcs->hGCClipRgn );
781         PATH_DestroyGdiPath(&dcs->path);
782         GDI_FreeObject( hdcs, dcs );
783     }
784
785     if (!(dc->flags & DC_SAVED))
786     {
787         SelectObject( hdc, GetStockObject(BLACK_PEN) );
788         SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
789         SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
790         SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
791         funcs = dc->funcs;
792         if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
793         dc->physDev = NULL;
794     }
795
796     if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
797     if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
798     if (dc->hGCClipRgn) DeleteObject( dc->hGCClipRgn );
799     PATH_DestroyGdiPath(&dc->path);
800
801     GDI_FreeObject( hdc, dc );
802     if (funcs) DRIVER_release_driver( funcs );  /* do that after releasing the GDI lock */
803     return TRUE;
804 }
805
806
807 /***********************************************************************
808  *           ResetDCA    (GDI32.@)
809  */
810 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
811 {
812     DC *dc;
813     HDC ret = hdc;
814
815     if ((dc = DC_GetDCPtr( hdc )))
816     {
817         if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
818         GDI_ReleaseObj( hdc );
819     }
820     return ret;
821 }
822
823
824 /***********************************************************************
825  *           ResetDCW    (GDI32.@)
826  */
827 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
828 {
829     return ResetDCA(hdc, (const DEVMODEA*)devmode); /* FIXME */
830 }
831
832
833 /***********************************************************************
834  *           GetDeviceCaps    (GDI32.@)
835  */
836 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
837 {
838     DC *dc;
839     INT ret = 0;
840
841     if ((dc = DC_GetDCPtr( hdc )))
842     {
843         if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
844         GDI_ReleaseObj( hdc );
845     }
846     return ret;
847 }
848
849
850 /***********************************************************************
851  *           SetBkColor    (GDI32.@)
852  */
853 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
854 {
855     COLORREF oldColor;
856     DC * dc = DC_GetDCPtr( hdc );
857
858     if (!dc) return CLR_INVALID;
859     oldColor = dc->backgroundColor;
860     if (dc->funcs->pSetBkColor)
861     {
862         color = dc->funcs->pSetBkColor(dc->physDev, color);
863         if (color == CLR_INVALID)  /* don't change it */
864         {
865             color = oldColor;
866             oldColor = CLR_INVALID;
867         }
868     }
869     dc->backgroundColor = color;
870     GDI_ReleaseObj( hdc );
871     return oldColor;
872 }
873
874
875 /***********************************************************************
876  *           SetTextColor    (GDI32.@)
877  */
878 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
879 {
880     COLORREF oldColor;
881     DC * dc = DC_GetDCPtr( hdc );
882
883     if (!dc) return CLR_INVALID;
884     oldColor = dc->textColor;
885     if (dc->funcs->pSetTextColor)
886     {
887         color = dc->funcs->pSetTextColor(dc->physDev, color);
888         if (color == CLR_INVALID)  /* don't change it */
889         {
890             color = oldColor;
891             oldColor = CLR_INVALID;
892         }
893     }
894     dc->textColor = color;
895     GDI_ReleaseObj( hdc );
896     return oldColor;
897 }
898
899
900 /***********************************************************************
901  *           SetTextAlign    (GDI32.@)
902  */
903 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
904 {
905     UINT prevAlign;
906     DC *dc = DC_GetDCPtr( hdc );
907     if (!dc) return 0x0;
908     if (dc->funcs->pSetTextAlign)
909         prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
910     else {
911         prevAlign = dc->textAlign;
912         dc->textAlign = align;
913     }
914     GDI_ReleaseObj( hdc );
915     return prevAlign;
916 }
917
918 /***********************************************************************
919  *           GetDCOrgEx  (GDI32.@)
920  */
921 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
922 {
923     DC * dc;
924
925     if (!lpp) return FALSE;
926     if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
927
928     lpp->x = lpp->y = 0;
929     if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
930     GDI_ReleaseObj( hDC );
931     return TRUE;
932 }
933
934
935 /***********************************************************************
936  *           SetDCOrg   (GDI.117)
937  */
938 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
939 {
940     DWORD prevOrg = 0;
941     HDC hdc = HDC_32( hdc16 );
942     DC *dc = DC_GetDCPtr( hdc );
943     if (!dc) return 0;
944     if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
945     GDI_ReleaseObj( hdc );
946     return prevOrg;
947 }
948
949
950 /***********************************************************************
951  *           SetGraphicsMode    (GDI32.@)
952  */
953 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
954 {
955     INT ret = 0;
956     DC *dc = DC_GetDCPtr( hdc );
957
958     /* One would think that setting the graphics mode to GM_COMPATIBLE
959      * would also reset the world transformation matrix to the unity
960      * matrix. However, in Windows, this is not the case. This doesn't
961      * make a lot of sense to me, but that's the way it is.
962      */
963     if (!dc) return 0;
964     if ((mode > 0) && (mode <= GM_LAST))
965     {
966         ret = dc->GraphicsMode;
967         dc->GraphicsMode = mode;
968     }
969     GDI_ReleaseObj( hdc );
970     return ret;
971 }
972
973
974 /***********************************************************************
975  *           SetArcDirection    (GDI32.@)
976  */
977 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
978 {
979     DC * dc;
980     INT nOldDirection = 0;
981
982     if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
983     {
984         SetLastError(ERROR_INVALID_PARAMETER);
985         return 0;
986     }
987
988     if ((dc = DC_GetDCPtr( hdc )))
989     {
990         nOldDirection = dc->ArcDirection;
991         dc->ArcDirection = nDirection;
992         GDI_ReleaseObj( hdc );
993     }
994     return nOldDirection;
995 }
996
997
998 /***********************************************************************
999  *           GetWorldTransform    (GDI32.@)
1000  */
1001 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1002 {
1003     DC * dc;
1004     if (!xform) return FALSE;
1005     if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1006     *xform = dc->xformWorld2Wnd;
1007     GDI_ReleaseObj( hdc );
1008     return TRUE;
1009 }
1010
1011
1012 /***********************************************************************
1013  *           GetTransform    (GDI32.@)
1014  */
1015 BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
1016 {
1017     if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1018     ERR("stub: don't know what to do for code %lx\n", unknown );
1019     return FALSE;
1020 }
1021
1022
1023 /***********************************************************************
1024  *           SetWorldTransform    (GDI32.@)
1025  */
1026 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1027 {
1028     BOOL ret = FALSE;
1029     DC *dc = DC_GetDCPtr( hdc );
1030
1031     if (!dc) return FALSE;
1032     if (!xform) goto done;
1033
1034     /* Check that graphics mode is GM_ADVANCED */
1035     if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1036
1037     if (dc->funcs->pSetWorldTransform)
1038     {
1039         ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1040         if (!ret) goto done;
1041     }
1042
1043     dc->xformWorld2Wnd = *xform;
1044     DC_UpdateXforms( dc );
1045     ret = TRUE;
1046  done:
1047     GDI_ReleaseObj( hdc );
1048     return ret;
1049 }
1050
1051
1052 /****************************************************************************
1053  * ModifyWorldTransform [GDI32.@]
1054  * Modifies the world transformation for a device context.
1055  *
1056  * PARAMS
1057  *    hdc   [I] Handle to device context
1058  *    xform [I] XFORM structure that will be used to modify the world
1059  *              transformation
1060  *    iMode [I] Specifies in what way to modify the world transformation
1061  *              Possible values:
1062  *              MWT_IDENTITY
1063  *                 Resets the world transformation to the identity matrix.
1064  *                 The parameter xform is ignored.
1065  *              MWT_LEFTMULTIPLY
1066  *                 Multiplies xform into the world transformation matrix from
1067  *                 the left.
1068  *              MWT_RIGHTMULTIPLY
1069  *                 Multiplies xform into the world transformation matrix from
1070  *                 the right.
1071  *
1072  * RETURNS STD
1073  */
1074 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1075     DWORD iMode )
1076 {
1077     BOOL ret = FALSE;
1078     DC *dc = DC_GetDCPtr( hdc );
1079
1080     /* Check for illegal parameters */
1081     if (!dc) return FALSE;
1082     if (!xform) goto done;
1083
1084     /* Check that graphics mode is GM_ADVANCED */
1085     if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1086
1087     if (dc->funcs->pModifyWorldTransform)
1088     {
1089         ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1090         if (!ret) goto done;
1091     }
1092
1093     switch (iMode)
1094     {
1095         case MWT_IDENTITY:
1096             dc->xformWorld2Wnd.eM11 = 1.0f;
1097             dc->xformWorld2Wnd.eM12 = 0.0f;
1098             dc->xformWorld2Wnd.eM21 = 0.0f;
1099             dc->xformWorld2Wnd.eM22 = 1.0f;
1100             dc->xformWorld2Wnd.eDx  = 0.0f;
1101             dc->xformWorld2Wnd.eDy  = 0.0f;
1102             break;
1103         case MWT_LEFTMULTIPLY:
1104             CombineTransform( &dc->xformWorld2Wnd, xform,
1105                 &dc->xformWorld2Wnd );
1106             break;
1107         case MWT_RIGHTMULTIPLY:
1108             CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1109                 xform );
1110             break;
1111         default:
1112             goto done;
1113     }
1114
1115     DC_UpdateXforms( dc );
1116     ret = TRUE;
1117  done:
1118     GDI_ReleaseObj( hdc );
1119     return ret;
1120 }
1121
1122
1123 /****************************************************************************
1124  * CombineTransform [GDI32.@]
1125  * Combines two transformation matrices.
1126  *
1127  * PARAMS
1128  *    xformResult [O] Stores the result of combining the two matrices
1129  *    xform1      [I] Specifies the first matrix to apply
1130  *    xform2      [I] Specifies the second matrix to apply
1131  *
1132  * REMARKS
1133  *    The same matrix can be passed in for more than one of the parameters.
1134  *
1135  * RETURNS STD
1136  */
1137 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1138     const XFORM *xform2 )
1139 {
1140     XFORM xformTemp;
1141
1142     /* Check for illegal parameters */
1143     if (!xformResult || !xform1 || !xform2)
1144         return FALSE;
1145
1146     /* Create the result in a temporary XFORM, since xformResult may be
1147      * equal to xform1 or xform2 */
1148     xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1149                      xform1->eM12 * xform2->eM21;
1150     xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1151                      xform1->eM12 * xform2->eM22;
1152     xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1153                      xform1->eM22 * xform2->eM21;
1154     xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1155                      xform1->eM22 * xform2->eM22;
1156     xformTemp.eDx  = xform1->eDx  * xform2->eM11 +
1157                      xform1->eDy  * xform2->eM21 +
1158                      xform2->eDx;
1159     xformTemp.eDy  = xform1->eDx  * xform2->eM12 +
1160                      xform1->eDy  * xform2->eM22 +
1161                      xform2->eDy;
1162
1163     /* Copy the result to xformResult */
1164     *xformResult = xformTemp;
1165
1166     return TRUE;
1167 }
1168
1169
1170 /***********************************************************************
1171  *           SetDCHook   (GDI32.@)
1172  *
1173  * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1174  */
1175 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1176 {
1177     DC *dc = GDI_GetObjPtr( hdc, DC_MAGIC );
1178
1179     if (!dc) return FALSE;
1180
1181     if (!(dc->flags & DC_SAVED))
1182     {
1183         dc->dwHookData = dwHookData;
1184         dc->hookThunk = hookProc;
1185     }
1186     GDI_ReleaseObj( hdc );
1187     return TRUE;
1188 }
1189
1190
1191 /* relay function to call the 16-bit DC hook proc */
1192 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1193 {
1194     WORD args[6];
1195     DWORD ret;
1196     FARPROC16 proc = NULL;
1197     HDC hdc = HDC_32( hdc16 );
1198     DC *dc = DC_GetDCPtr( hdc );
1199
1200     if (!dc) return FALSE;
1201     proc = dc->hookProc;
1202     GDI_ReleaseObj( hdc );
1203     if (!proc) return FALSE;
1204     args[5] = hdc16;
1205     args[4] = code;
1206     args[3] = HIWORD(data);
1207     args[2] = LOWORD(data);
1208     args[1] = HIWORD(lParam);
1209     args[0] = LOWORD(lParam);
1210     WOWCallback16Ex( (DWORD)proc, WCB16_PASCAL, sizeof(args), args, &ret );
1211     return LOWORD(ret);
1212 }
1213
1214 /***********************************************************************
1215  *           SetDCHook   (GDI.190)
1216  */
1217 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1218 {
1219     HDC hdc = HDC_32( hdc16 );
1220     DC *dc = DC_GetDCPtr( hdc );
1221     if (!dc) return FALSE;
1222
1223     dc->hookProc = hookProc;
1224     GDI_ReleaseObj( hdc );
1225     return SetDCHook( hdc, call_dc_hook16, dwHookData );
1226 }
1227
1228
1229 /***********************************************************************
1230  *           GetDCHook   (GDI.191)
1231  */
1232 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1233 {
1234     HDC hdc = HDC_32( hdc16 );
1235     DC *dc = DC_GetDCPtr( hdc );
1236     DWORD ret;
1237
1238     if (!dc) return 0;
1239     *phookProc = dc->hookProc;
1240     ret = dc->dwHookData;
1241     GDI_ReleaseObj( hdc );
1242     return ret;
1243 }
1244
1245
1246 /***********************************************************************
1247  *           SetHookFlags   (GDI.192)
1248  */
1249 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1250 {
1251     HDC hdc = HDC_32( hdc16 );
1252     DC *dc = DC_GetDCPtr( hdc );
1253
1254     if( dc )
1255     {
1256         WORD wRet = dc->flags & DC_DIRTY;
1257
1258         /* "Undocumented Windows" info is slightly confusing.
1259          */
1260
1261         TRACE("hDC %p, flags %04x\n",hdc,flags);
1262
1263         if( flags & DCHF_INVALIDATEVISRGN )
1264             dc->flags |= DC_DIRTY;
1265         else if( flags & DCHF_VALIDATEVISRGN || !flags )
1266             dc->flags &= ~DC_DIRTY;
1267         GDI_ReleaseObj( hdc );
1268         return wRet;
1269     }
1270     return 0;
1271 }
1272
1273 /***********************************************************************
1274  *           SetICMMode    (GDI32.@)
1275  */
1276 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1277 {
1278 /*FIXME  Asuming that ICM is always off, and cannot be turned on */
1279     if (iEnableICM == ICM_OFF) return ICM_OFF;
1280     if (iEnableICM == ICM_ON) return 0;
1281     if (iEnableICM == ICM_QUERY) return ICM_OFF;
1282     return 0;
1283 }
1284
1285 /***********************************************************************
1286  *           GetDeviceGammaRamp    (GDI32.@)
1287  */
1288 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1289 {
1290     BOOL ret = FALSE;
1291     DC *dc = DC_GetDCPtr( hDC );
1292
1293     if( dc )
1294     {
1295         if (dc->funcs->pGetDeviceGammaRamp)
1296             ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1297         GDI_ReleaseObj( hDC );
1298     }
1299     return ret;
1300 }
1301
1302 /***********************************************************************
1303  *           SetDeviceGammaRamp    (GDI32.@)
1304  */
1305 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1306 {
1307     BOOL ret = FALSE;
1308     DC *dc = DC_GetDCPtr( hDC );
1309
1310     if( dc )
1311     {
1312         if (dc->funcs->pSetDeviceGammaRamp)
1313             ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1314         GDI_ReleaseObj( hDC );
1315     }
1316     return ret;
1317 }
1318
1319 /***********************************************************************
1320  *           GetColorSpace    (GDI32.@)
1321  */
1322 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1323 {
1324 /*FIXME    Need to to whatever GetColorSpace actually does */
1325     return 0;
1326 }
1327
1328 /***********************************************************************
1329  *           CreateColorSpaceA    (GDI32.@)
1330  */
1331 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1332 {
1333   FIXME( "stub\n" );
1334   return 0;
1335 }
1336
1337 /***********************************************************************
1338  *           CreateColorSpaceW    (GDI32.@)
1339  */
1340 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1341 {
1342   FIXME( "stub\n" );
1343   return 0;
1344 }
1345
1346 /***********************************************************************
1347  *           DeleteColorSpace     (GDI32.@)
1348  */
1349 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1350 {
1351   FIXME( "stub\n" );
1352
1353   return TRUE;
1354 }
1355
1356 /***********************************************************************
1357  *           SetColorSpace     (GDI32.@)
1358  */
1359 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1360 {
1361   FIXME( "stub\n" );
1362
1363   return hColorSpace;
1364 }
1365
1366 /***********************************************************************
1367  *           GetBoundsRect    (GDI.194)
1368  */
1369 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1370 {
1371     return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1372 }
1373
1374 /***********************************************************************
1375  *           GetBoundsRect    (GDI32.@)
1376  */
1377 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1378 {
1379     FIXME("(): stub\n");
1380     return DCB_RESET;   /* bounding rectangle always empty */
1381 }
1382
1383 /***********************************************************************
1384  *           SetBoundsRect    (GDI.193)
1385  */
1386 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1387 {
1388     if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1389         FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1390
1391     return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1392 }
1393
1394 /***********************************************************************
1395  *           SetBoundsRect    (GDI32.@)
1396  */
1397 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1398 {
1399     FIXME("(): stub\n");
1400     return DCB_DISABLE;   /* bounding rectangle always empty */
1401 }
1402
1403
1404 /***********************************************************************
1405  *              GetRelAbs               (GDI32.@)
1406  */
1407 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1408 {
1409     INT ret = 0;
1410     DC *dc = DC_GetDCPtr( hdc );
1411     if (dc) ret = dc->relAbsMode;
1412     GDI_ReleaseObj( hdc );
1413     return ret;
1414 }
1415
1416 /***********************************************************************
1417  *           GetLayout    (GDI32.@)
1418  *
1419  * Gets left->right or right->left text layout flags of a dc.
1420  * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1421  *
1422  */
1423 DWORD WINAPI GetLayout(HDC hdc)
1424 {
1425     FIXME("(%p): stub\n", hdc);
1426     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1427     return 0;
1428 }
1429
1430 /***********************************************************************
1431  *           SetLayout    (GDI32.@)
1432  *
1433  * Sets left->right or right->left text layout flags of a dc.
1434  * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1435  *
1436  */
1437 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1438 {
1439     FIXME("(%p,%08lx): stub\n", hdc, layout);
1440     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1441     return 0;
1442 }
1443
1444 /***********************************************************************
1445  *           SetDCBrushColor    (GDI32.@)
1446  *
1447  * Sets the current device context (DC) brush color to the specified
1448  * color value. If the device cannot represent the specified color
1449  * value, the color is set to the nearest physical color.
1450  *
1451  */
1452 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1453 {
1454     FIXME("(%p, %08lx): stub\n", hdc, crColor);
1455     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1456     return CLR_INVALID;
1457 }
1458
1459 /***********************************************************************
1460  *           SetVirtualResolution   (GDI32.@)
1461  *
1462  * Undocumented on msdn.  Called when PowerPoint XP saves a file.
1463  */
1464 DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
1465 {
1466     FIXME("(%p %08lx %08lx %08lx %08lx): stub!\n", hdc, dw2, dw3, dw4, dw5);
1467     return FALSE;
1468 }