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