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