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