dc.c 58.6 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * GDI Device Context functions
 *
 * Copyright 1993 Alexandre Julliard
Alexandre Julliard's avatar
Alexandre Julliard committed
5
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

21 22
#include "config.h"

23
#include <assert.h>
24
#include <stdarg.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
25
#include <stdlib.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
26
#include <string.h>
27
#include "windef.h"
28
#include "winbase.h"
29
#include "wingdi.h"
30
#include "winreg.h"
31
#include "winternl.h"
32 33
#include "winerror.h"
#include "wownt32.h"
34
#include "gdi_private.h"
35
#include "wine/unicode.h"
36
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
37

38
WINE_DEFAULT_DEBUG_CHANNEL(dc);
39

40 41
static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };

42 43 44 45 46 47 48 49 50 51 52 53
static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );

static const struct gdi_obj_funcs dc_funcs =
{
    NULL,             /* pSelectObject */
    NULL,             /* pGetObject16 */
    NULL,             /* pGetObjectA */
    NULL,             /* pGetObjectW */
    NULL,             /* pUnrealizeObject */
    DC_DeleteObject   /* pDeleteObject */
};

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

static inline DC *get_dc_obj( HDC hdc )
{
    DC *dc = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
    if (!dc) return NULL;

    if ((GDIMAGIC(dc->header.wMagic) != DC_MAGIC) &&
        (GDIMAGIC(dc->header.wMagic) != MEMORY_DC_MAGIC) &&
        (GDIMAGIC(dc->header.wMagic) != METAFILE_DC_MAGIC) &&
        (GDIMAGIC(dc->header.wMagic) != ENHMETAFILE_DC_MAGIC))
    {
        GDI_ReleaseObj( hdc );
        SetLastError( ERROR_INVALID_HANDLE );
        dc = NULL;
    }
    return dc;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
73
/***********************************************************************
74
 *           alloc_dc_ptr
Alexandre Julliard's avatar
Alexandre Julliard committed
75
 */
76
DC *alloc_dc_ptr( const DC_FUNCTIONS *funcs, WORD magic )
Alexandre Julliard's avatar
Alexandre Julliard committed
77
{
78
    HDC hdc;
Alexandre Julliard's avatar
Alexandre Julliard committed
79 80
    DC *dc;

81
    if (!(dc = GDI_AllocObject( sizeof(*dc), magic, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
82 83 84 85

    dc->hSelf               = hdc;
    dc->funcs               = funcs;
    dc->physDev             = NULL;
86 87 88
    dc->thread              = GetCurrentThreadId();
    dc->refcount            = 1;
    dc->dirty               = 0;
89
    dc->saveLevel           = 0;
90
    dc->saved_dc            = 0;
91 92 93 94 95 96 97 98 99 100 101
    dc->dwHookData          = 0;
    dc->hookProc            = NULL;
    dc->hookThunk           = NULL;
    dc->wndOrgX             = 0;
    dc->wndOrgY             = 0;
    dc->wndExtX             = 1;
    dc->wndExtY             = 1;
    dc->vportOrgX           = 0;
    dc->vportOrgY           = 0;
    dc->vportExtX           = 1;
    dc->vportExtY           = 1;
102
    dc->miterLimit          = 10.0f; /* 10.0 is the default, from MSDN */
103
    dc->flags               = 0;
104
    dc->layout              = 0;
105
    dc->hClipRgn            = 0;
106 107
    dc->hMetaRgn            = 0;
    dc->hMetaClipRgn        = 0;
108 109 110 111 112 113 114
    dc->hVisRgn             = 0;
    dc->hPen                = GetStockObject( BLACK_PEN );
    dc->hBrush              = GetStockObject( WHITE_BRUSH );
    dc->hFont               = GetStockObject( SYSTEM_FONT );
    dc->hBitmap             = 0;
    dc->hDevice             = 0;
    dc->hPalette            = GetStockObject( DEFAULT_PALETTE );
115
    dc->gdiFont             = 0;
116 117 118 119 120 121
    dc->ROPmode             = R2_COPYPEN;
    dc->polyFillMode        = ALTERNATE;
    dc->stretchBltMode      = BLACKONWHITE;
    dc->relAbsMode          = ABSOLUTE;
    dc->backgroundMode      = OPAQUE;
    dc->backgroundColor     = RGB( 255, 255, 255 );
122 123
    dc->dcBrushColor        = RGB( 255, 255, 255 );
    dc->dcPenColor          = RGB( 0, 0, 0 );
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    dc->textColor           = RGB( 0, 0, 0 );
    dc->brushOrgX           = 0;
    dc->brushOrgY           = 0;
    dc->textAlign           = TA_LEFT | TA_TOP | TA_NOUPDATECP;
    dc->charExtra           = 0;
    dc->breakExtra          = 0;
    dc->breakRem            = 0;
    dc->MapMode             = MM_TEXT;
    dc->GraphicsMode        = GM_COMPATIBLE;
    dc->pAbortProc          = NULL;
    dc->CursPosX            = 0;
    dc->CursPosY            = 0;
    dc->ArcDirection        = AD_COUNTERCLOCKWISE;
    dc->xformWorld2Wnd.eM11 = 1.0f;
    dc->xformWorld2Wnd.eM12 = 0.0f;
    dc->xformWorld2Wnd.eM21 = 0.0f;
    dc->xformWorld2Wnd.eM22 = 1.0f;
    dc->xformWorld2Wnd.eDx  = 0.0f;
    dc->xformWorld2Wnd.eDy  = 0.0f;
    dc->xformWorld2Vport    = dc->xformWorld2Wnd;
    dc->xformVport2World    = dc->xformWorld2Wnd;
    dc->vport2WorldValid    = TRUE;
146 147 148 149
    dc->BoundsRect.left     = 0;
    dc->BoundsRect.top      = 0;
    dc->BoundsRect.right    = 0;
    dc->BoundsRect.bottom   = 0;
150
    dc->saved_visrgn        = NULL;
151
    PATH_InitGdiPath(&dc->path);
152
    GDI_ReleaseObj( dc->hSelf );
Alexandre Julliard's avatar
Alexandre Julliard committed
153 154 155 156
    return dc;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
157

158
/***********************************************************************
159
 *           free_dc_ptr
160
 */
161
BOOL free_dc_ptr( DC *dc )
162
{
163
    assert( dc->refcount == 1 );
164 165
    /* grab the gdi lock again */
    if (!GDI_GetObjPtr( dc->hSelf, MAGIC_DONTCARE )) return FALSE;  /* shouldn't happen */
166 167 168 169
    return GDI_FreeObject( dc->hSelf, dc );
}


170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/***********************************************************************
 *           get_dc_ptr
 *
 * Retrieve a DC pointer but release the GDI lock.
 */
DC *get_dc_ptr( HDC hdc )
{
    DC *dc = get_dc_obj( hdc );
    if (!dc) return NULL;

    if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
    {
        dc->thread = GetCurrentThreadId();
    }
    else if (dc->thread != GetCurrentThreadId())
    {
        WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
        GDI_ReleaseObj( hdc );
        return NULL;
    }
    else InterlockedIncrement( &dc->refcount );

    GDI_ReleaseObj( hdc );
    return dc;
}


/***********************************************************************
 *           release_dc_ptr
 */
void release_dc_ptr( DC *dc )
{
    LONG ref;

    dc->thread = 0;
    ref = InterlockedDecrement( &dc->refcount );
    assert( ref >= 0 );
    if (ref) dc->thread = GetCurrentThreadId();  /* we still own it */
}


/***********************************************************************
 *           update_dc
 *
 * Make sure the DC vis region is up to date.
 * This function may call up to USER so the GDI lock should _not_
 * be held when calling it.
 */
void update_dc( DC *dc )
{
    if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookThunk)
        dc->hookThunk( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
}


225 226 227 228 229
/***********************************************************************
 *           DC_DeleteObject
 */
static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
{
230
    GDI_ReleaseObj( handle );
231 232 233 234
    return DeleteDC( handle );
}


Alexandre Julliard's avatar
Alexandre Julliard committed
235
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
236
 *           DC_InitDC
Alexandre Julliard's avatar
Alexandre Julliard committed
237
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
238
 * Setup device-specific DC values for a newly created DC.
Alexandre Julliard's avatar
Alexandre Julliard committed
239
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
240
void DC_InitDC( DC* dc )
Alexandre Julliard's avatar
Alexandre Julliard committed
241
{
242
    if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
243 244 245 246 247
    SetTextColor( dc->hSelf, dc->textColor );
    SetBkColor( dc->hSelf, dc->backgroundColor );
    SelectObject( dc->hSelf, dc->hPen );
    SelectObject( dc->hSelf, dc->hBrush );
    SelectObject( dc->hSelf, dc->hFont );
Alexandre Julliard's avatar
Alexandre Julliard committed
248
    CLIPPING_UpdateGCRegion( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
249 250 251
}


Alexandre Julliard's avatar
Alexandre Julliard committed
252 253 254 255 256 257 258
/***********************************************************************
 *           DC_InvertXform
 *
 * Computes the inverse of the transformation xformSrc and stores it to
 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
 * is singular.
 */
259
static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
Alexandre Julliard's avatar
Alexandre Julliard committed
260 261
{
    FLOAT determinant;
262

Alexandre Julliard's avatar
Alexandre Julliard committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
    determinant = xformSrc->eM11*xformSrc->eM22 -
        xformSrc->eM12*xformSrc->eM21;
    if (determinant > -1e-12 && determinant < 1e-12)
        return FALSE;

    xformDest->eM11 =  xformSrc->eM22 / determinant;
    xformDest->eM12 = -xformSrc->eM12 / determinant;
    xformDest->eM21 = -xformSrc->eM21 / determinant;
    xformDest->eM22 =  xformSrc->eM11 / determinant;
    xformDest->eDx  = -xformSrc->eDx * xformDest->eM11 -
                       xformSrc->eDy * xformDest->eM21;
    xformDest->eDy  = -xformSrc->eDx * xformDest->eM12 -
                       xformSrc->eDy * xformDest->eM22;

    return TRUE;
}


/***********************************************************************
 *           DC_UpdateXforms
 *
 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
 * fields of the specified DC by creating a transformation that
 * represents the current mapping mode and combining it with the DC's
 * world transform. This function should be called whenever the
 * parameters associated with the mapping mode (window and viewport
 * extents and origins) or the world transform change.
 */
void DC_UpdateXforms( DC *dc )
{
293
    XFORM xformWnd2Vport, oldworld2vport;
Alexandre Julliard's avatar
Alexandre Julliard committed
294
    FLOAT scaleX, scaleY;
295

Alexandre Julliard's avatar
Alexandre Julliard committed
296 297 298 299 300 301 302 303 304 305 306 307
    /* Construct a transformation to do the window-to-viewport conversion */
    scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
    scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
    xformWnd2Vport.eM11 = scaleX;
    xformWnd2Vport.eM12 = 0.0;
    xformWnd2Vport.eM21 = 0.0;
    xformWnd2Vport.eM22 = scaleY;
    xformWnd2Vport.eDx  = (FLOAT)dc->vportOrgX -
        scaleX * (FLOAT)dc->wndOrgX;
    xformWnd2Vport.eDy  = (FLOAT)dc->vportOrgY -
        scaleY * (FLOAT)dc->wndOrgY;

308
    oldworld2vport = dc->xformWorld2Vport;
Alexandre Julliard's avatar
Alexandre Julliard committed
309
    /* Combine with the world transformation */
310
    CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
Alexandre Julliard's avatar
Alexandre Julliard committed
311 312 313
        &xformWnd2Vport );

    /* Create inverse of world-to-viewport transformation */
314 315
    dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
        &dc->xformVport2World );
316

317
    /* Reselect the font and pen back into the dc so that the size
318
       gets updated. */
319
    if(memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)))
320
    {
321
        SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
322 323
        SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
324 325 326
}


Alexandre Julliard's avatar
Alexandre Julliard committed
327
/***********************************************************************
328
 *           GetDCState   (Not a Windows API)
Alexandre Julliard's avatar
Alexandre Julliard committed
329
 */
330
HDC WINAPI GetDCState( HDC hdc )
Alexandre Julliard's avatar
Alexandre Julliard committed
331 332
{
    DC * newdc, * dc;
333
    HGDIOBJ handle;
334

335
    if (!(dc = get_dc_ptr( hdc ))) return 0;
336
    if (!(newdc = GDI_AllocObject( sizeof(DC), GDIMAGIC(dc->header.wMagic), &handle, &dc_funcs )))
Alexandre Julliard's avatar
Alexandre Julliard committed
337
    {
338
      release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
339 340
      return 0;
    }
341
    TRACE("(%p): returning %p\n", hdc, handle );
Alexandre Julliard's avatar
Alexandre Julliard committed
342

343
    newdc->flags            = dc->flags | DC_SAVED;
344
    newdc->layout           = dc->layout;
345 346 347 348
    newdc->hPen             = dc->hPen;
    newdc->hBrush           = dc->hBrush;
    newdc->hFont            = dc->hFont;
    newdc->hBitmap          = dc->hBitmap;
349
    newdc->hDevice          = dc->hDevice;
350
    newdc->hPalette         = dc->hPalette;
351 352 353 354 355 356 357
    newdc->ROPmode          = dc->ROPmode;
    newdc->polyFillMode     = dc->polyFillMode;
    newdc->stretchBltMode   = dc->stretchBltMode;
    newdc->relAbsMode       = dc->relAbsMode;
    newdc->backgroundMode   = dc->backgroundMode;
    newdc->backgroundColor  = dc->backgroundColor;
    newdc->textColor        = dc->textColor;
358 359
    newdc->dcBrushColor     = dc->dcBrushColor;
    newdc->dcPenColor       = dc->dcPenColor;
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    newdc->brushOrgX        = dc->brushOrgX;
    newdc->brushOrgY        = dc->brushOrgY;
    newdc->textAlign        = dc->textAlign;
    newdc->charExtra        = dc->charExtra;
    newdc->breakExtra       = dc->breakExtra;
    newdc->breakRem         = dc->breakRem;
    newdc->MapMode          = dc->MapMode;
    newdc->GraphicsMode     = dc->GraphicsMode;
    newdc->CursPosX         = dc->CursPosX;
    newdc->CursPosY         = dc->CursPosY;
    newdc->ArcDirection     = dc->ArcDirection;
    newdc->xformWorld2Wnd   = dc->xformWorld2Wnd;
    newdc->xformWorld2Vport = dc->xformWorld2Vport;
    newdc->xformVport2World = dc->xformVport2World;
    newdc->vport2WorldValid = dc->vport2WorldValid;
    newdc->wndOrgX          = dc->wndOrgX;
    newdc->wndOrgY          = dc->wndOrgY;
    newdc->wndExtX          = dc->wndExtX;
    newdc->wndExtY          = dc->wndExtY;
    newdc->vportOrgX        = dc->vportOrgX;
    newdc->vportOrgY        = dc->vportOrgY;
    newdc->vportExtX        = dc->vportExtX;
    newdc->vportExtY        = dc->vportExtY;
383
    newdc->BoundsRect       = dc->BoundsRect;
Alexandre Julliard's avatar
Alexandre Julliard committed
384

385
    newdc->hSelf = (HDC)handle;
386 387
    newdc->thread    = GetCurrentThreadId();
    newdc->refcount  = 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
388
    newdc->saveLevel = 0;
389
    newdc->saved_dc  = 0;
390
    GDI_ReleaseObj( handle );
Alexandre Julliard's avatar
Alexandre Julliard committed
391

392
    PATH_InitGdiPath( &newdc->path );
393

394
    newdc->pAbortProc = NULL;
395
    newdc->hookThunk  = NULL;
396
    newdc->hookProc   = 0;
397
    newdc->saved_visrgn = NULL;
398

Alexandre Julliard's avatar
Alexandre Julliard committed
399 400
    /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */

401 402 403 404
    newdc->hVisRgn      = 0;
    newdc->hClipRgn     = 0;
    newdc->hMetaRgn     = 0;
    newdc->hMetaClipRgn = 0;
405
    if (dc->hClipRgn)
Alexandre Julliard's avatar
Alexandre Julliard committed
406
    {
407 408
        newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
        CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
Alexandre Julliard's avatar
Alexandre Julliard committed
409
    }
410 411 412 413 414 415
    if (dc->hMetaRgn)
    {
        newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
        CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
    }
    /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
416 417 418 419 420 421

    if(dc->gdiFont) {
	newdc->gdiFont = dc->gdiFont;
    } else
        newdc->gdiFont = 0;

422 423
    release_dc_ptr( newdc );
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
424 425 426 427 428
    return handle;
}


/***********************************************************************
429
 *           SetDCState   (Not a Windows API)
Alexandre Julliard's avatar
Alexandre Julliard committed
430
 */
431
void WINAPI SetDCState( HDC hdc, HDC hdcs )
Alexandre Julliard's avatar
Alexandre Julliard committed
432
{
Alexandre Julliard's avatar
Alexandre Julliard committed
433
    DC *dc, *dcs;
434

435 436
    if (!(dc = get_dc_ptr( hdc ))) return;
    if (!(dcs = get_dc_ptr( hdcs )))
Alexandre Julliard's avatar
Alexandre Julliard committed
437
    {
438 439
        release_dc_ptr( dc );
        return;
Alexandre Julliard's avatar
Alexandre Julliard committed
440
    }
Andrew Talbot's avatar
Andrew Talbot committed
441
    if (!(dcs->flags & DC_SAVED))
Alexandre Julliard's avatar
Alexandre Julliard committed
442
    {
443 444 445
        release_dc_ptr( dc );
        release_dc_ptr( dcs );
        return;
Alexandre Julliard's avatar
Alexandre Julliard committed
446
    }
447
    TRACE("%p %p\n", hdc, hdcs );
Alexandre Julliard's avatar
Alexandre Julliard committed
448

449
    update_dc( dc );
450
    dc->flags            = dcs->flags & ~DC_SAVED;
451
    dc->layout           = dcs->layout;
452 453 454 455 456 457 458 459
    dc->hDevice          = dcs->hDevice;
    dc->ROPmode          = dcs->ROPmode;
    dc->polyFillMode     = dcs->polyFillMode;
    dc->stretchBltMode   = dcs->stretchBltMode;
    dc->relAbsMode       = dcs->relAbsMode;
    dc->backgroundMode   = dcs->backgroundMode;
    dc->backgroundColor  = dcs->backgroundColor;
    dc->textColor        = dcs->textColor;
460 461
    dc->dcBrushColor     = dcs->dcBrushColor;
    dc->dcPenColor       = dcs->dcPenColor;
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
    dc->brushOrgX        = dcs->brushOrgX;
    dc->brushOrgY        = dcs->brushOrgY;
    dc->textAlign        = dcs->textAlign;
    dc->charExtra        = dcs->charExtra;
    dc->breakExtra       = dcs->breakExtra;
    dc->breakRem         = dcs->breakRem;
    dc->MapMode          = dcs->MapMode;
    dc->GraphicsMode     = dcs->GraphicsMode;
    dc->CursPosX         = dcs->CursPosX;
    dc->CursPosY         = dcs->CursPosY;
    dc->ArcDirection     = dcs->ArcDirection;
    dc->xformWorld2Wnd   = dcs->xformWorld2Wnd;
    dc->xformWorld2Vport = dcs->xformWorld2Vport;
    dc->xformVport2World = dcs->xformVport2World;
    dc->vport2WorldValid = dcs->vport2WorldValid;
477
    dc->BoundsRect       = dcs->BoundsRect;
478 479 480 481 482 483 484 485 486 487 488

    dc->wndOrgX          = dcs->wndOrgX;
    dc->wndOrgY          = dcs->wndOrgY;
    dc->wndExtX          = dcs->wndExtX;
    dc->wndExtY          = dcs->wndExtY;
    dc->vportOrgX        = dcs->vportOrgX;
    dc->vportOrgY        = dcs->vportOrgY;
    dc->vportExtX        = dcs->vportExtX;
    dc->vportExtY        = dcs->vportExtY;

    if (dcs->hClipRgn)
489
    {
490 491
        if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
        CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
492 493
    }
    else
494
    {
495
        if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
496
        dc->hClipRgn = 0;
497
    }
498 499 500 501 502 503 504 505 506 507
    if (dcs->hMetaRgn)
    {
        if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
        CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
    }
    else
    {
        if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
        dc->hMetaRgn = 0;
    }
508
    CLIPPING_UpdateGCRegion( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
509

510 511 512 513 514 515
    SelectObject( hdc, dcs->hBitmap );
    SelectObject( hdc, dcs->hBrush );
    SelectObject( hdc, dcs->hFont );
    SelectObject( hdc, dcs->hPen );
    SetBkColor( hdc, dcs->backgroundColor);
    SetTextColor( hdc, dcs->textColor);
516
    GDISelectPalette( hdc, dcs->hPalette, FALSE );
517 518
    release_dc_ptr( dc );
    release_dc_ptr( dcs );
Alexandre Julliard's avatar
Alexandre Julliard committed
519 520 521
}


522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
/***********************************************************************
 *           GetDCState   (GDI.179)
 */
HDC16 WINAPI GetDCState16( HDC16 hdc )
{
    return HDC_16( GetDCState( HDC_32(hdc) ));
}


/***********************************************************************
 *           SetDCState   (GDI.180)
 */
void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
{
    SetDCState( HDC_32(hdc), HDC_32(hdcs) );
}


Alexandre Julliard's avatar
Alexandre Julliard committed
540
/***********************************************************************
541
 *           SaveDC    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
542
 */
543
INT WINAPI SaveDC( HDC hdc )
Alexandre Julliard's avatar
Alexandre Julliard committed
544
{
545
    HDC hdcs;
Alexandre Julliard's avatar
Alexandre Julliard committed
546
    DC * dc, * dcs;
547
    INT ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
548

549
    dc = get_dc_ptr( hdc );
550 551 552
    if (!dc) return 0;

    if(dc->funcs->pSaveDC)
553
    {
554
        ret = dc->funcs->pSaveDC( dc->physDev );
555 556
        if(ret)
            ret = ++dc->saveLevel;
557
        release_dc_ptr( dc );
558 559
        return ret;
    }
560

561
    if (!(hdcs = GetDCState( hdc )))
Alexandre Julliard's avatar
Alexandre Julliard committed
562
    {
563 564
        release_dc_ptr( dc );
        return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
565
    }
566
    dcs = get_dc_ptr( hdcs );
Alexandre Julliard's avatar
Alexandre Julliard committed
567 568 569 570 571 572 573

    /* Copy path. The reason why path saving / restoring is in SaveDC/
     * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
     * functions are only in Win16 (which doesn't have paths) and that
     * SetDCState doesn't allow us to signal an error (which can happen
     * when copying paths).
     */
574
    if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
Alexandre Julliard's avatar
Alexandre Julliard committed
575
    {
576 577
        release_dc_ptr( dc );
        release_dc_ptr( dcs );
578
	DeleteDC( hdcs );
Alexandre Julliard's avatar
Alexandre Julliard committed
579 580
	return 0;
    }
581

582 583
    dcs->saved_dc = dc->saved_dc;
    dc->saved_dc = hdcs;
584
    TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
Alexandre Julliard's avatar
Alexandre Julliard committed
585
    ret = ++dc->saveLevel;
586 587
    release_dc_ptr( dcs );
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
588
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
589 590 591
}


Alexandre Julliard's avatar
Alexandre Julliard committed
592
/***********************************************************************
593
 *           RestoreDC    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
594
 */
595
BOOL WINAPI RestoreDC( HDC hdc, INT level )
Alexandre Julliard's avatar
Alexandre Julliard committed
596 597
{
    DC * dc, * dcs;
598
    BOOL success;
Alexandre Julliard's avatar
Alexandre Julliard committed
599

600
    TRACE("%p %d\n", hdc, level );
601
    if (!(dc = get_dc_ptr( hdc ))) return FALSE;
602 603

    if(abs(level) > dc->saveLevel || level == 0)
604
    {
605
        release_dc_ptr( dc );
606
        return FALSE;
607
    }
608 609 610

    update_dc( dc );

611
    if(dc->funcs->pRestoreDC)
Alexandre Julliard's avatar
Alexandre Julliard committed
612
    {
613 614 615 616
        success = dc->funcs->pRestoreDC( dc->physDev, level );
        if(level < 0) level = dc->saveLevel + level + 1;
        if(success)
            dc->saveLevel = level - 1;
617
        release_dc_ptr( dc );
618
        return success;
Alexandre Julliard's avatar
Alexandre Julliard committed
619
    }
620

621
    if (level < 0) level = dc->saveLevel + level + 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
622
    success=TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
623
    while (dc->saveLevel >= level)
Alexandre Julliard's avatar
Alexandre Julliard committed
624
    {
625
        HDC hdcs = dc->saved_dc;
626
	if (!(dcs = get_dc_ptr( hdcs )))
Alexandre Julliard's avatar
Alexandre Julliard committed
627
	{
628 629
            success = FALSE;
            break;
630
	}
631 632
        dc->saved_dc = dcs->saved_dc;
        dcs->saved_dc = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
633 634
	if (--dc->saveLevel < level)
	{
635
	    SetDCState( hdc, hdcs );
636
            if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
Alexandre Julliard's avatar
Alexandre Julliard committed
637 638 639 640
		/* FIXME: This might not be quite right, since we're
		 * returning FALSE but still destroying the saved DC state */
	        success=FALSE;
	}
641
        release_dc_ptr( dcs );
642
	DeleteDC( hdcs );
Alexandre Julliard's avatar
Alexandre Julliard committed
643
    }
644
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
645
    return success;
Alexandre Julliard's avatar
Alexandre Julliard committed
646 647 648
}


649
/***********************************************************************
650
 *           CreateDCW    (GDI32.@)
651
 */
652 653
HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
                      const DEVMODEW *initData )
Alexandre Julliard's avatar
Alexandre Julliard committed
654
{
655
    HDC hdc;
Alexandre Julliard's avatar
Alexandre Julliard committed
656
    DC * dc;
Alexandre Julliard's avatar
Alexandre Julliard committed
657
    const DC_FUNCTIONS *funcs;
658
    WCHAR buf[300];
Alexandre Julliard's avatar
Alexandre Julliard committed
659

660 661
    GDI_CheckNotLock();

662
    if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
663
    {
664 665 666 667 668
        if (!driver)
        {
            ERR( "no device found for %s\n", debugstr_w(device) );
            return 0;
        }
669
        strcpyW(buf, driver);
670
    }
671

672 673
    if (!(funcs = DRIVER_load_driver( buf )))
    {
674
        ERR( "no driver found for %s\n", debugstr_w(buf) );
675 676
        return 0;
    }
677
    if (!(dc = alloc_dc_ptr( funcs, DC_MAGIC ))) goto error;
678
    hdc = dc->hSelf;
679

680
    dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
681
    if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
Alexandre Julliard's avatar
Alexandre Julliard committed
682

683
    TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
684
          debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
Alexandre Julliard's avatar
Alexandre Julliard committed
685 686

    if (dc->funcs->pCreateDC &&
687
        !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
Alexandre Julliard's avatar
Alexandre Julliard committed
688
    {
689
        WARN("creation aborted by device\n" );
690
        goto error;
Alexandre Julliard's avatar
Alexandre Julliard committed
691
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
692

693 694
    SetRectRgn( dc->hVisRgn, 0, 0,
                GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
695

Alexandre Julliard's avatar
Alexandre Julliard committed
696
    DC_InitDC( dc );
697
    release_dc_ptr( dc );
698
    return hdc;
699 700 701

error:
    if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
702
    if (dc) free_dc_ptr( dc );
703 704
    DRIVER_release_driver( funcs );
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
705 706 707
}


Alexandre Julliard's avatar
Alexandre Julliard committed
708
/***********************************************************************
709
 *           CreateDCA    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
710
 */
711 712
HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
                      const DEVMODEA *initData )
713
{
714
    UNICODE_STRING driverW, deviceW, outputW;
715
    DEVMODEW *initDataW;
716 717 718 719 720 721 722 723 724 725 726
    HDC ret;

    if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
    else driverW.Buffer = NULL;

    if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
    else deviceW.Buffer = NULL;

    if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
    else outputW.Buffer = NULL;

727 728 729 730 731 732 733
    initDataW = NULL;
    if (initData)
    {
        /* don't convert initData for DISPLAY driver, it's not used */
        if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
            initDataW = GdiConvertToDevmodeW(initData);
    }
734

735
    ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
736 737 738 739

    RtlFreeUnicodeString(&driverW);
    RtlFreeUnicodeString(&deviceW);
    RtlFreeUnicodeString(&outputW);
740
    HeapFree(GetProcessHeap(), 0, initDataW);
741
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
742 743 744
}


Alexandre Julliard's avatar
Alexandre Julliard committed
745
/***********************************************************************
746
 *           CreateICA    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
747
 */
748 749
HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
                          const DEVMODEA* initData )
Alexandre Julliard's avatar
Alexandre Julliard committed
750 751
{
      /* Nothing special yet for ICs */
752
    return CreateDCA( driver, device, output, initData );
Alexandre Julliard's avatar
Alexandre Julliard committed
753 754 755 756
}


/***********************************************************************
757
 *           CreateICW    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
758
 */
759 760
HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
                          const DEVMODEW* initData )
Alexandre Julliard's avatar
Alexandre Julliard committed
761 762
{
      /* Nothing special yet for ICs */
763
    return CreateDCW( driver, device, output, initData );
Alexandre Julliard's avatar
Alexandre Julliard committed
764 765 766 767
}


/***********************************************************************
768
 *           CreateCompatibleDC   (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
769
 */
770
HDC WINAPI CreateCompatibleDC( HDC hdc )
Alexandre Julliard's avatar
Alexandre Julliard committed
771
{
Alexandre Julliard's avatar
Alexandre Julliard committed
772
    DC *dc, *origDC;
773
    HDC ret;
774 775
    const DC_FUNCTIONS *funcs = NULL;
    PHYSDEV physDev = NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
776

777
    GDI_CheckNotLock();
778

779
    if ((origDC = get_dc_ptr( hdc )))
780
    {
781 782 783 784 785
        if (GetObjectType( hdc ) == OBJ_DC)
        {
            funcs = origDC->funcs;
            physDev = origDC->physDev;
        }
786
        release_dc_ptr( origDC );
787
        if (funcs) funcs = DRIVER_get_driver( funcs );
788
    }
789

790
    if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
791

792
    if (!(dc = alloc_dc_ptr( funcs, MEMORY_DC_MAGIC ))) goto error;
Alexandre Julliard's avatar
Alexandre Julliard committed
793

794
    TRACE("(%p): returning %p\n", hdc, dc->hSelf );
Alexandre Julliard's avatar
Alexandre Julliard committed
795

796
    dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
797
    if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;   /* default bitmap is 1x1 */
Alexandre Julliard's avatar
Alexandre Julliard committed
798

799 800 801
    /* Copy the driver-specific physical device info into
     * the new DC. The driver may use this read-only info
     * while creating the compatible DC below. */
802
    dc->physDev = physDev;
803
    ret = dc->hSelf;
804

Alexandre Julliard's avatar
Alexandre Julliard committed
805
    if (dc->funcs->pCreateDC &&
806
        !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
Alexandre Julliard's avatar
Alexandre Julliard committed
807
    {
808
        WARN("creation aborted by device\n");
809
        goto error;
Alexandre Julliard's avatar
Alexandre Julliard committed
810
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
811

Alexandre Julliard's avatar
Alexandre Julliard committed
812
    DC_InitDC( dc );
813
    release_dc_ptr( dc );
814
    return ret;
815 816 817

error:
    if (dc && dc->hVisRgn) DeleteObject( dc->hVisRgn );
818
    if (dc) free_dc_ptr( dc );
819 820
    DRIVER_release_driver( funcs );
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
821 822 823
}


Alexandre Julliard's avatar
Alexandre Julliard committed
824
/***********************************************************************
825
 *           DeleteDC    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
826
 */
827
BOOL WINAPI DeleteDC( HDC hdc )
Alexandre Julliard's avatar
Alexandre Julliard committed
828
{
829 830
    const DC_FUNCTIONS *funcs = NULL;
    DC * dc;
Alexandre Julliard's avatar
Alexandre Julliard committed
831

832
    TRACE("%p\n", hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
833

834 835
    GDI_CheckNotLock();

836
    if (!(dc = get_dc_ptr( hdc ))) return FALSE;
837 838 839
    if (dc->refcount != 1)
    {
        FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
840
        release_dc_ptr( dc );
841 842
        return FALSE;
    }
843

844
    /* Call hook procedure to check whether is it OK to delete this DC */
845
    if (dc->hookThunk && !dc->hookThunk( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
846
    {
847 848
        release_dc_ptr( dc );
        return FALSE;
849 850
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
851 852
    while (dc->saveLevel)
    {
853 854
        DC * dcs;
        HDC hdcs = dc->saved_dc;
855
        if (!(dcs = get_dc_ptr( hdcs ))) break;
856 857
        dc->saved_dc = dcs->saved_dc;
        dc->saveLevel--;
858
        if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
859 860
        if (dcs->hMetaRgn) DeleteObject( dcs->hMetaRgn );
        if (dcs->hMetaClipRgn) DeleteObject( dcs->hMetaClipRgn );
861 862
        if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
        PATH_DestroyGdiPath(&dcs->path);
863
        free_dc_ptr( dcs );
Alexandre Julliard's avatar
Alexandre Julliard committed
864
    }
865

866
    if (!(dc->flags & DC_SAVED))
Alexandre Julliard's avatar
Alexandre Julliard committed
867
    {
868 869 870
	SelectObject( hdc, GetStockObject(BLACK_PEN) );
	SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
	SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
871
        SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
872
        funcs = dc->funcs;
873
        if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
874
        dc->physDev = NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
875
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
876

877 878 879 880 881 882 883
    while (dc->saved_visrgn)
    {
        struct saved_visrgn *next = dc->saved_visrgn->next;
        DeleteObject( dc->saved_visrgn->hrgn );
        HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
        dc->saved_visrgn = next;
    }
884
    if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
885 886
    if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
    if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
887 888
    if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
    PATH_DestroyGdiPath(&dc->path);
889

890
    free_dc_ptr( dc );
891 892
    if (funcs) DRIVER_release_driver( funcs );  /* do that after releasing the GDI lock */
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
893 894 895
}


Alexandre Julliard's avatar
Alexandre Julliard committed
896
/***********************************************************************
897
 *           ResetDCW    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
898
 */
899
HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
Alexandre Julliard's avatar
Alexandre Julliard committed
900
{
901 902 903
    DC *dc;
    HDC ret = hdc;

904
    if ((dc = get_dc_ptr( hdc )))
905 906
    {
        if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
907
        release_dc_ptr( dc );
908 909
    }
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
910 911 912 913
}


/***********************************************************************
914
 *           ResetDCA    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
915
 */
916
HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
Alexandre Julliard's avatar
Alexandre Julliard committed
917
{
918 919 920 921 922 923 924 925
    DEVMODEW *devmodeW;
    HDC ret;

    if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
    else devmodeW = NULL;

    ret = ResetDCW(hdc, devmodeW);

926
    HeapFree(GetProcessHeap(), 0, devmodeW);
927
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
928 929 930
}


Alexandre Julliard's avatar
Alexandre Julliard committed
931
/***********************************************************************
932
 *           GetDeviceCaps    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
933
 */
934
INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
Alexandre Julliard's avatar
Alexandre Julliard committed
935
{
936
    DC *dc;
937
    INT ret = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
938

939
    if ((dc = get_dc_ptr( hdc )))
940
    {
941
        if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
942 943 944 945 946 947 948 949 950 951 952 953 954 955
        else switch(cap)  /* return meaningful values for some entries */
        {
        case HORZRES:     ret = 640; break;
        case VERTRES:     ret = 480; break;
        case BITSPIXEL:   ret = 1; break;
        case PLANES:      ret = 1; break;
        case NUMCOLORS:   ret = 2; break;
        case ASPECTX:     ret = 36; break;
        case ASPECTY:     ret = 36; break;
        case ASPECTXY:    ret = 51; break;
        case LOGPIXELSX:  ret = 72; break;
        case LOGPIXELSY:  ret = 72; break;
        case SIZEPALETTE: ret = 2; break;
        }
956
        release_dc_ptr( dc );
957
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
958
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
959 960 961
}


962 963 964 965 966 967
/***********************************************************************
 *		GetBkColor (GDI32.@)
 */
COLORREF WINAPI GetBkColor( HDC hdc )
{
    COLORREF ret = 0;
968
    DC * dc = get_dc_ptr( hdc );
969 970 971
    if (dc)
    {
        ret = dc->backgroundColor;
972
        release_dc_ptr( dc );
973 974 975 976 977
    }
    return ret;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
978
/***********************************************************************
979
 *           SetBkColor    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
980
 */
981
COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
Alexandre Julliard's avatar
Alexandre Julliard committed
982 983
{
    COLORREF oldColor;
984
    DC * dc = get_dc_ptr( hdc );
985

986
    TRACE("hdc=%p color=0x%08x\n", hdc, color);
987

988 989
    if (!dc) return CLR_INVALID;
    oldColor = dc->backgroundColor;
Alexandre Julliard's avatar
Alexandre Julliard committed
990
    if (dc->funcs->pSetBkColor)
991 992 993 994 995 996 997
    {
        color = dc->funcs->pSetBkColor(dc->physDev, color);
        if (color == CLR_INVALID)  /* don't change it */
        {
            color = oldColor;
            oldColor = CLR_INVALID;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
998
    }
999
    dc->backgroundColor = color;
1000
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1001 1002 1003 1004
    return oldColor;
}


1005 1006 1007 1008 1009 1010
/***********************************************************************
 *		GetTextColor (GDI32.@)
 */
COLORREF WINAPI GetTextColor( HDC hdc )
{
    COLORREF ret = 0;
1011
    DC * dc = get_dc_ptr( hdc );
1012 1013 1014
    if (dc)
    {
        ret = dc->textColor;
1015
        release_dc_ptr( dc );
1016 1017 1018 1019 1020
    }
    return ret;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1021
/***********************************************************************
1022
 *           SetTextColor    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1023
 */
1024
COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
Alexandre Julliard's avatar
Alexandre Julliard committed
1025 1026
{
    COLORREF oldColor;
1027
    DC * dc = get_dc_ptr( hdc );
1028

1029
    TRACE(" hdc=%p color=0x%08x\n", hdc, color);
1030

1031 1032
    if (!dc) return CLR_INVALID;
    oldColor = dc->textColor;
Alexandre Julliard's avatar
Alexandre Julliard committed
1033
    if (dc->funcs->pSetTextColor)
1034 1035 1036 1037 1038 1039 1040
    {
        color = dc->funcs->pSetTextColor(dc->physDev, color);
        if (color == CLR_INVALID)  /* don't change it */
        {
            color = oldColor;
            oldColor = CLR_INVALID;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
1041
    }
1042
    dc->textColor = color;
1043
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1044 1045 1046
    return oldColor;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1047

1048 1049 1050 1051 1052 1053
/***********************************************************************
 *		GetTextAlign (GDI32.@)
 */
UINT WINAPI GetTextAlign( HDC hdc )
{
    UINT ret = 0;
1054
    DC * dc = get_dc_ptr( hdc );
1055 1056 1057
    if (dc)
    {
        ret = dc->textAlign;
1058
        release_dc_ptr( dc );
1059 1060 1061 1062 1063
    }
    return ret;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1064
/***********************************************************************
1065
 *           SetTextAlign    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1066
 */
1067
UINT WINAPI SetTextAlign( HDC hdc, UINT align )
Alexandre Julliard's avatar
Alexandre Julliard committed
1068
{
1069
    UINT ret;
1070
    DC *dc = get_dc_ptr( hdc );
1071 1072 1073

    TRACE("hdc=%p align=%d\n", hdc, align);

1074
    if (!dc) return 0x0;
1075
    ret = dc->textAlign;
1076
    if (dc->funcs->pSetTextAlign)
1077 1078 1079
        if (!dc->funcs->pSetTextAlign(dc->physDev, align))
            ret = GDI_ERROR;
    if (ret != GDI_ERROR)
1080
	dc->textAlign = align;
1081
    release_dc_ptr( dc );
1082
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1083 1084
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1085
/***********************************************************************
1086
 *           GetDCOrgEx  (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1087
 */
1088
BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
Alexandre Julliard's avatar
Alexandre Julliard committed
1089
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1090
    DC * dc;
1091

Alexandre Julliard's avatar
Alexandre Julliard committed
1092
    if (!lpp) return FALSE;
1093
    if (!(dc = get_dc_ptr( hDC ))) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1094

1095
    lpp->x = lpp->y = 0;
1096
    if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1097
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1098 1099 1100 1101
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1102
/***********************************************************************
1103
 *           SetDCOrg   (GDI.117)
Alexandre Julliard's avatar
Alexandre Julliard committed
1104
 */
1105
DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
Alexandre Julliard's avatar
Alexandre Julliard committed
1106
{
1107
    DWORD prevOrg = 0;
1108
    HDC hdc = HDC_32( hdc16 );
1109
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1110
    if (!dc) return 0;
1111
    if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
1112
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1113 1114
    return prevOrg;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1115 1116


1117 1118 1119 1120 1121 1122
/***********************************************************************
 *		GetGraphicsMode (GDI32.@)
 */
INT WINAPI GetGraphicsMode( HDC hdc )
{
    INT ret = 0;
1123
    DC * dc = get_dc_ptr( hdc );
1124 1125 1126
    if (dc)
    {
        ret = dc->GraphicsMode;
1127
        release_dc_ptr( dc );
1128 1129 1130 1131 1132
    }
    return ret;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1133
/***********************************************************************
1134
 *           SetGraphicsMode    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1135
 */
1136
INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
Alexandre Julliard's avatar
Alexandre Julliard committed
1137
{
1138
    INT ret = 0;
1139
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1140 1141 1142 1143 1144 1145

    /* One would think that setting the graphics mode to GM_COMPATIBLE
     * would also reset the world transformation matrix to the unity
     * matrix. However, in Windows, this is not the case. This doesn't
     * make a lot of sense to me, but that's the way it is.
     */
Alexandre Julliard's avatar
Alexandre Julliard committed
1146
    if (!dc) return 0;
1147
    if ((mode > 0) && (mode <= GM_LAST))
1148
    {
1149 1150 1151
        ret = dc->GraphicsMode;
        dc->GraphicsMode = mode;
    }
1152
    release_dc_ptr( dc );
1153
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1154 1155 1156
}


1157 1158 1159 1160 1161 1162
/***********************************************************************
 *		GetArcDirection (GDI32.@)
 */
INT WINAPI GetArcDirection( HDC hdc )
{
    INT ret = 0;
1163
    DC * dc = get_dc_ptr( hdc );
1164 1165 1166
    if (dc)
    {
        ret = dc->ArcDirection;
1167
        release_dc_ptr( dc );
1168 1169 1170 1171 1172
    }
    return ret;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1173
/***********************************************************************
1174
 *           SetArcDirection    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1175
 */
1176
INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
Alexandre Julliard's avatar
Alexandre Julliard committed
1177
{
1178 1179
    DC * dc;
    INT nOldDirection = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1180 1181 1182 1183 1184 1185 1186

    if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
	return 0;
    }

1187
    if ((dc = get_dc_ptr( hdc )))
1188
    {
1189 1190 1191 1192
        if (dc->funcs->pSetArcDirection)
        {
            dc->funcs->pSetArcDirection(dc->physDev, nDirection);
        }
1193 1194
        nOldDirection = dc->ArcDirection;
        dc->ArcDirection = nDirection;
1195
        release_dc_ptr( dc );
1196
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1197 1198 1199 1200
    return nOldDirection;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1201
/***********************************************************************
1202
 *           GetWorldTransform    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1203
 */
1204
BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
Alexandre Julliard's avatar
Alexandre Julliard committed
1205
{
1206 1207
    DC * dc;
    if (!xform) return FALSE;
1208
    if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1209
    *xform = dc->xformWorld2Wnd;
1210
    release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1211 1212 1213 1214
    return TRUE;
}


1215 1216 1217 1218 1219 1220
/***********************************************************************
 *           GetTransform    (GDI32.@)
 */
BOOL WINAPI GetTransform( HDC hdc, DWORD unknown, LPXFORM xform )
{
    if (unknown == 0x0203) return GetWorldTransform( hdc, xform );
1221
    FIXME("stub: don't know what to do for code %x\n", unknown );
1222 1223 1224 1225
    return FALSE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1226
/***********************************************************************
1227
 *           SetWorldTransform    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1228
 */
1229
BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
Alexandre Julliard's avatar
Alexandre Julliard committed
1230
{
1231
    BOOL ret = FALSE;
1232
    DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
1233

1234
    if (!dc) return FALSE;
1235
    if (!xform) goto done;
1236

Alexandre Julliard's avatar
Alexandre Julliard committed
1237
    /* Check that graphics mode is GM_ADVANCED */
1238
    if (dc->GraphicsMode!=GM_ADVANCED) goto done;
Alexandre Julliard's avatar
Alexandre Julliard committed
1239

1240 1241 1242 1243 1244 1245
    if (dc->funcs->pSetWorldTransform)
    {
        ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
        if (!ret) goto done;
    }

1246
    dc->xformWorld2Wnd = *xform;
Alexandre Julliard's avatar
Alexandre Julliard committed
1247
    DC_UpdateXforms( dc );
1248 1249
    ret = TRUE;
 done:
1250
    release_dc_ptr( dc );
1251
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1252 1253 1254 1255
}


/****************************************************************************
1256
 * ModifyWorldTransform [GDI32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
 * Modifies the world transformation for a device context.
 *
 * PARAMS
 *    hdc   [I] Handle to device context
 *    xform [I] XFORM structure that will be used to modify the world
 *              transformation
 *    iMode [I] Specifies in what way to modify the world transformation
 *              Possible values:
 *              MWT_IDENTITY
 *                 Resets the world transformation to the identity matrix.
 *                 The parameter xform is ignored.
 *              MWT_LEFTMULTIPLY
 *                 Multiplies xform into the world transformation matrix from
 *                 the left.
 *              MWT_RIGHTMULTIPLY
 *                 Multiplies xform into the world transformation matrix from
 *                 the right.
 *
Jon Griffiths's avatar
Jon Griffiths committed
1275 1276 1277
 * RETURNS
 *  Success: TRUE.
 *  Failure: FALSE. Use GetLastError() to determine the cause.
Alexandre Julliard's avatar
Alexandre Julliard committed
1278
 */
1279
BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
Alexandre Julliard's avatar
Alexandre Julliard committed
1280 1281
    DWORD iMode )
{
1282
    BOOL ret = FALSE;
1283
    DC *dc = get_dc_ptr( hdc );
1284

Alexandre Julliard's avatar
Alexandre Julliard committed
1285
    /* Check for illegal parameters */
1286
    if (!dc) return FALSE;
1287
    if (!xform && iMode != MWT_IDENTITY) goto done;
1288

Alexandre Julliard's avatar
Alexandre Julliard committed
1289
    /* Check that graphics mode is GM_ADVANCED */
1290 1291
    if (dc->GraphicsMode!=GM_ADVANCED) goto done;

1292 1293 1294 1295 1296 1297
    if (dc->funcs->pModifyWorldTransform)
    {
        ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
        if (!ret) goto done;
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
1298 1299 1300
    switch (iMode)
    {
        case MWT_IDENTITY:
1301 1302 1303 1304 1305 1306
	    dc->xformWorld2Wnd.eM11 = 1.0f;
	    dc->xformWorld2Wnd.eM12 = 0.0f;
	    dc->xformWorld2Wnd.eM21 = 0.0f;
	    dc->xformWorld2Wnd.eM22 = 1.0f;
	    dc->xformWorld2Wnd.eDx  = 0.0f;
	    dc->xformWorld2Wnd.eDy  = 0.0f;
Alexandre Julliard's avatar
Alexandre Julliard committed
1307 1308
	    break;
        case MWT_LEFTMULTIPLY:
1309 1310
	    CombineTransform( &dc->xformWorld2Wnd, xform,
	        &dc->xformWorld2Wnd );
Alexandre Julliard's avatar
Alexandre Julliard committed
1311 1312
	    break;
	case MWT_RIGHTMULTIPLY:
1313
	    CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
Alexandre Julliard's avatar
Alexandre Julliard committed
1314 1315 1316
	        xform );
	    break;
        default:
1317
            goto done;
Alexandre Julliard's avatar
Alexandre Julliard committed
1318 1319 1320
    }

    DC_UpdateXforms( dc );
1321 1322
    ret = TRUE;
 done:
1323
    release_dc_ptr( dc );
1324
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1325 1326 1327 1328
}


/****************************************************************************
1329
 * CombineTransform [GDI32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
 * Combines two transformation matrices.
 *
 * PARAMS
 *    xformResult [O] Stores the result of combining the two matrices
 *    xform1      [I] Specifies the first matrix to apply
 *    xform2      [I] Specifies the second matrix to apply
 *
 * REMARKS
 *    The same matrix can be passed in for more than one of the parameters.
 *
Jon Griffiths's avatar
Jon Griffiths committed
1340 1341 1342
 * RETURNS
 *  Success: TRUE.
 *  Failure: FALSE. Use GetLastError() to determine the cause.
Alexandre Julliard's avatar
Alexandre Julliard committed
1343
 */
1344
BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
Alexandre Julliard's avatar
Alexandre Julliard committed
1345 1346 1347
    const XFORM *xform2 )
{
    XFORM xformTemp;
1348

Alexandre Julliard's avatar
Alexandre Julliard committed
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
    /* Check for illegal parameters */
    if (!xformResult || !xform1 || !xform2)
        return FALSE;

    /* Create the result in a temporary XFORM, since xformResult may be
     * equal to xform1 or xform2 */
    xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
                     xform1->eM12 * xform2->eM21;
    xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
                     xform1->eM12 * xform2->eM22;
    xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
                     xform1->eM22 * xform2->eM21;
    xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
                     xform1->eM22 * xform2->eM22;
    xformTemp.eDx  = xform1->eDx  * xform2->eM11 +
                     xform1->eDy  * xform2->eM21 +
                     xform2->eDx;
    xformTemp.eDy  = xform1->eDx  * xform2->eM12 +
                     xform1->eDy  * xform2->eM22 +
                     xform2->eDy;

    /* Copy the result to xformResult */
    *xformResult = xformTemp;

Alexandre Julliard's avatar
Alexandre Julliard committed
1373
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1374 1375 1376
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1377
/***********************************************************************
1378 1379 1380
 *           SetDCHook   (GDI32.@)
 *
 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
Alexandre Julliard's avatar
Alexandre Julliard committed
1381
 */
1382
BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1383
{
1384
    DC *dc = get_dc_ptr( hdc );
1385

1386
    if (!dc) return FALSE;
1387 1388 1389 1390 1391 1392

    if (!(dc->flags & DC_SAVED))
    {
        dc->dwHookData = dwHookData;
        dc->hookThunk = hookProc;
    }
1393
    release_dc_ptr( dc );
1394 1395
    return TRUE;
}
1396 1397


1398
/* relay function to call the 16-bit DC hook proc */
1399
static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
Alexandre Julliard's avatar
Alexandre Julliard committed
1400
{
1401
    WORD args[6];
1402 1403
    DWORD ret = 0;
    DC *dc = get_dc_ptr( hdc );
1404

1405
    if (!dc) return FALSE;
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
    if (dc->hookProc)
    {
        args[5] = HDC_16(hdc);
        args[4] = code;
        args[3] = HIWORD(data);
        args[2] = LOWORD(data);
        args[1] = HIWORD(lParam);
        args[0] = LOWORD(lParam);
        WOWCallback16Ex( (DWORD)dc->hookProc, WCB16_PASCAL, sizeof(args), args, &ret );
    }
    release_dc_ptr( dc );
1417
    return LOWORD(ret);
1418
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1419

1420 1421 1422
/***********************************************************************
 *           SetDCHook   (GDI.190)
 */
1423
BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1424
{
1425
    DC *dc = get_dc_ptr( HDC_32(hdc16) );
Alexandre Julliard's avatar
Alexandre Julliard committed
1426

1427 1428 1429 1430 1431 1432 1433 1434 1435
    if (!dc) return FALSE;
    if (!(dc->flags & DC_SAVED))
    {
        dc->dwHookData = dwHookData;
        dc->hookThunk = call_dc_hook16;
        dc->hookProc = hookProc;
    }
    release_dc_ptr( dc );
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1436 1437 1438 1439 1440 1441
}


/***********************************************************************
 *           GetDCHook   (GDI.191)
 */
1442
DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
Alexandre Julliard's avatar
Alexandre Julliard committed
1443
{
1444
    HDC hdc = HDC_32( hdc16 );
1445
    DC *dc = get_dc_ptr( hdc );
1446 1447
    DWORD ret;

Alexandre Julliard's avatar
Alexandre Julliard committed
1448 1449
    if (!dc) return 0;
    *phookProc = dc->hookProc;
1450
    ret = dc->dwHookData;
1451
    release_dc_ptr( dc );
1452
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1453 1454 1455 1456
}


/***********************************************************************
1457
 *           SetHookFlags   (GDI.192)
Alexandre Julliard's avatar
Alexandre Julliard committed
1458
 */
1459
WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
Alexandre Julliard's avatar
Alexandre Julliard committed
1460
{
1461
    HDC hdc = HDC_32( hdc16 );
1462 1463
    DC *dc = get_dc_obj( hdc );  /* not get_dc_ptr, this needs to work from any thread */
    LONG ret = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1464

1465
    if (!dc) return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1466

1467
    /* "Undocumented Windows" info is slightly confusing. */
Alexandre Julliard's avatar
Alexandre Julliard committed
1468

1469
    TRACE("hDC %p, flags %04x\n",hdc,flags);
Alexandre Julliard's avatar
Alexandre Julliard committed
1470

1471 1472 1473 1474 1475 1476 1477
    if (flags & DCHF_INVALIDATEVISRGN)
        ret = InterlockedExchange( &dc->dirty, 1 );
    else if (flags & DCHF_VALIDATEVISRGN || !flags)
        ret = InterlockedExchange( &dc->dirty, 0 );

    GDI_ReleaseObj( dc );
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1478 1479
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1480
/***********************************************************************
1481
 *           SetICMMode    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1482
 */
1483
INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
Alexandre Julliard's avatar
Alexandre Julliard committed
1484 1485 1486 1487 1488 1489 1490 1491
{
/*FIXME  Asuming that ICM is always off, and cannot be turned on */
    if (iEnableICM == ICM_OFF) return ICM_OFF;
    if (iEnableICM == ICM_ON) return 0;
    if (iEnableICM == ICM_QUERY) return ICM_OFF;
    return 0;
}

1492
/***********************************************************************
1493
 *           GetDeviceGammaRamp    (GDI32.@)
1494
 */
1495 1496 1497
BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
{
    BOOL ret = FALSE;
1498
    DC *dc = get_dc_ptr( hDC );
1499 1500 1501 1502

    if( dc )
    {
	if (dc->funcs->pGetDeviceGammaRamp)
1503
	    ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1504
	release_dc_ptr( dc );
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
    }
    return ret;
}

/***********************************************************************
 *           SetDeviceGammaRamp    (GDI32.@)
 */
BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
{
    BOOL ret = FALSE;
1515
    DC *dc = get_dc_ptr( hDC );
1516 1517 1518 1519

    if( dc )
    {
	if (dc->funcs->pSetDeviceGammaRamp)
1520
	    ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1521
	release_dc_ptr( dc );
1522 1523
    }
    return ret;
1524
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1525 1526

/***********************************************************************
1527
 *           GetColorSpace    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1528
 */
1529
HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
1530 1531 1532 1533
{
/*FIXME    Need to to whatever GetColorSpace actually does */
    return 0;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1534

1535
/***********************************************************************
1536
 *           CreateColorSpaceA    (GDI32.@)
1537 1538 1539 1540
 */
HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
{
  FIXME( "stub\n" );
1541
  return 0;
1542 1543 1544
}

/***********************************************************************
1545
 *           CreateColorSpaceW    (GDI32.@)
1546 1547 1548 1549 1550 1551 1552 1553
 */
HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
{
  FIXME( "stub\n" );
  return 0;
}

/***********************************************************************
1554
 *           DeleteColorSpace     (GDI32.@)
1555 1556 1557 1558
 */
BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
{
  FIXME( "stub\n" );
1559

1560
  return TRUE;
1561 1562 1563
}

/***********************************************************************
1564
 *           SetColorSpace     (GDI32.@)
1565 1566 1567 1568 1569 1570 1571 1572
 */
HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
{
  FIXME( "stub\n" );

  return hColorSpace;
}

1573
/***********************************************************************
1574
 *           GetBoundsRect    (GDI32.@)
1575
 */
1576
UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1577
{
1578
    UINT ret;
1579
    DC *dc = get_dc_ptr( hdc );
1580

1581 1582 1583 1584 1585
    if ( !dc ) return 0;

    if (rect) *rect = dc->BoundsRect;

    ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1586

1587 1588 1589 1590 1591 1592 1593 1594
    if (flags & DCB_RESET)
    {
        dc->BoundsRect.left   = 0;
        dc->BoundsRect.top    = 0;
        dc->BoundsRect.right  = 0;
        dc->BoundsRect.bottom = 0;
        dc->flags &= ~DC_BOUNDS_SET;
    }
1595
    release_dc_ptr( dc );
1596
    return ret;
1597 1598
}

1599

1600
/***********************************************************************
1601
 *           SetBoundsRect    (GDI32.@)
1602
 */
1603
UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1604
{
1605 1606 1607 1608
    UINT ret;
    DC *dc;

    if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1609
    if (!(dc = get_dc_ptr( hdc ))) return 0;
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641

    ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
          ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);

    if (flags & DCB_RESET)
    {
        dc->BoundsRect.left   = 0;
        dc->BoundsRect.top    = 0;
        dc->BoundsRect.right  = 0;
        dc->BoundsRect.bottom = 0;
        dc->flags &= ~DC_BOUNDS_SET;
    }

    if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
    {
        if (dc->flags & DC_BOUNDS_SET)
        {
            dc->BoundsRect.left   = min( dc->BoundsRect.left, rect->left );
            dc->BoundsRect.top    = min( dc->BoundsRect.top, rect->top );
            dc->BoundsRect.right  = max( dc->BoundsRect.right, rect->right );
            dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
        }
        else
        {
            dc->BoundsRect = *rect;
            dc->flags |= DC_BOUNDS_SET;
        }
    }

    if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
    if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;

1642
    release_dc_ptr( dc );
1643
    return ret;
1644 1645
}

1646 1647

/***********************************************************************
1648
 *		GetRelAbs		(GDI32.@)
1649 1650 1651
 */
INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
{
1652
    INT ret = 0;
1653
    DC *dc = get_dc_ptr( hdc );
1654 1655 1656
    if (dc)
    {
        ret = dc->relAbsMode;
1657
        release_dc_ptr( dc );
1658
    }
1659
    return ret;
1660 1661
}

1662 1663 1664 1665 1666 1667 1668 1669 1670



/***********************************************************************
 *		GetBkMode (GDI32.@)
 */
INT WINAPI GetBkMode( HDC hdc )
{
    INT ret = 0;
1671
    DC * dc = get_dc_ptr( hdc );
1672 1673 1674
    if (dc)
    {
        ret = dc->backgroundMode;
1675
        release_dc_ptr( dc );
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
    }
    return ret;
}


/***********************************************************************
 *		SetBkMode (GDI32.@)
 */
INT WINAPI SetBkMode( HDC hdc, INT mode )
{
    INT ret;
    DC *dc;
    if ((mode <= 0) || (mode > BKMODE_LAST))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }
1693
    if (!(dc = get_dc_ptr( hdc ))) return 0;
1694 1695

    ret = dc->backgroundMode;
1696
    if (dc->funcs->pSetBkMode)
1697 1698 1699
        if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
            ret = 0;
    if (ret)
1700
        dc->backgroundMode = mode;
1701
    release_dc_ptr( dc );
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
    return ret;
}


/***********************************************************************
 *		GetROP2 (GDI32.@)
 */
INT WINAPI GetROP2( HDC hdc )
{
    INT ret = 0;
1712
    DC * dc = get_dc_ptr( hdc );
1713 1714 1715
    if (dc)
    {
        ret = dc->ROPmode;
1716
        release_dc_ptr( dc );
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
    }
    return ret;
}


/***********************************************************************
 *		SetROP2 (GDI32.@)
 */
INT WINAPI SetROP2( HDC hdc, INT mode )
{
    INT ret;
    DC *dc;
    if ((mode < R2_BLACK) || (mode > R2_WHITE))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }
1734
    if (!(dc = get_dc_ptr( hdc ))) return 0;
1735
    ret = dc->ROPmode;
1736
    if (dc->funcs->pSetROP2)
1737 1738 1739
        if (!dc->funcs->pSetROP2( dc->physDev, mode ))
            ret = 0;
    if (ret)
1740
        dc->ROPmode = mode;
1741
    release_dc_ptr( dc );
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
    return ret;
}


/***********************************************************************
 *		SetRelAbs (GDI32.@)
 */
INT WINAPI SetRelAbs( HDC hdc, INT mode )
{
    INT ret;
    DC *dc;
    if ((mode != ABSOLUTE) && (mode != RELATIVE))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }
1758
    if (!(dc = get_dc_ptr( hdc ))) return 0;
1759 1760 1761 1762 1763 1764 1765
    if (dc->funcs->pSetRelAbs)
        ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
    else
    {
        ret = dc->relAbsMode;
        dc->relAbsMode = mode;
    }
1766
    release_dc_ptr( dc );
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
    return ret;
}


/***********************************************************************
 *		GetPolyFillMode (GDI32.@)
 */
INT WINAPI GetPolyFillMode( HDC hdc )
{
    INT ret = 0;
1777
    DC * dc = get_dc_ptr( hdc );
1778 1779 1780
    if (dc)
    {
        ret = dc->polyFillMode;
1781
        release_dc_ptr( dc );
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
    }
    return ret;
}


/***********************************************************************
 *		SetPolyFillMode (GDI32.@)
 */
INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
{
    INT ret;
    DC *dc;
    if ((mode <= 0) || (mode > POLYFILL_LAST))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }
1799
    if (!(dc = get_dc_ptr( hdc ))) return 0;
1800
    ret = dc->polyFillMode;
1801
    if (dc->funcs->pSetPolyFillMode)
1802 1803 1804
        if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
            ret = 0;
    if (ret)
1805
        dc->polyFillMode = mode;
1806
    release_dc_ptr( dc );
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816
    return ret;
}


/***********************************************************************
 *		GetStretchBltMode (GDI32.@)
 */
INT WINAPI GetStretchBltMode( HDC hdc )
{
    INT ret = 0;
1817
    DC * dc = get_dc_ptr( hdc );
1818 1819 1820
    if (dc)
    {
        ret = dc->stretchBltMode;
1821
        release_dc_ptr( dc );
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
    }
    return ret;
}


/***********************************************************************
 *		SetStretchBltMode (GDI32.@)
 */
INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
{
    INT ret;
    DC *dc;
    if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }
1839
    if (!(dc = get_dc_ptr( hdc ))) return 0;
1840
    ret = dc->stretchBltMode;
1841
    if (dc->funcs->pSetStretchBltMode)
1842 1843 1844
        if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
            ret = 0;
    if (ret)
1845
        dc->stretchBltMode = mode;
1846
    release_dc_ptr( dc );
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856
    return ret;
}


/***********************************************************************
 *		GetMapMode (GDI32.@)
 */
INT WINAPI GetMapMode( HDC hdc )
{
    INT ret = 0;
1857
    DC * dc = get_dc_ptr( hdc );
1858 1859 1860
    if (dc)
    {
        ret = dc->MapMode;
1861
        release_dc_ptr( dc );
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
    }
    return ret;
}


/***********************************************************************
 *		GetBrushOrgEx (GDI32.@)
 */
BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
{
1872
    DC * dc = get_dc_ptr( hdc );
1873 1874 1875
    if (!dc) return FALSE;
    pt->x = dc->brushOrgX;
    pt->y = dc->brushOrgY;
1876
    release_dc_ptr( dc );
1877 1878 1879 1880 1881 1882 1883 1884 1885
    return TRUE;
}


/***********************************************************************
 *		GetCurrentPositionEx (GDI32.@)
 */
BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
{
1886
    DC * dc = get_dc_ptr( hdc );
1887 1888 1889
    if (!dc) return FALSE;
    pt->x = dc->CursPosX;
    pt->y = dc->CursPosY;
1890
    release_dc_ptr( dc );
1891 1892 1893 1894 1895 1896 1897 1898 1899
    return TRUE;
}


/***********************************************************************
 *		GetViewportExtEx (GDI32.@)
 */
BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
{
1900
    DC * dc = get_dc_ptr( hdc );
1901 1902 1903
    if (!dc) return FALSE;
    size->cx = dc->vportExtX;
    size->cy = dc->vportExtY;
1904
    release_dc_ptr( dc );
1905 1906 1907 1908 1909 1910 1911 1912 1913
    return TRUE;
}


/***********************************************************************
 *		GetViewportOrgEx (GDI32.@)
 */
BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
{
1914
    DC * dc = get_dc_ptr( hdc );
1915 1916 1917
    if (!dc) return FALSE;
    pt->x = dc->vportOrgX;
    pt->y = dc->vportOrgY;
1918
    release_dc_ptr( dc );
1919 1920 1921 1922 1923 1924 1925 1926 1927
    return TRUE;
}


/***********************************************************************
 *		GetWindowExtEx (GDI32.@)
 */
BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
{
1928
    DC * dc = get_dc_ptr( hdc );
1929 1930 1931
    if (!dc) return FALSE;
    size->cx = dc->wndExtX;
    size->cy = dc->wndExtY;
1932
    release_dc_ptr( dc );
1933 1934 1935 1936 1937 1938 1939 1940 1941
    return TRUE;
}


/***********************************************************************
 *		GetWindowOrgEx (GDI32.@)
 */
BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
{
1942
    DC * dc = get_dc_ptr( hdc );
1943 1944 1945
    if (!dc) return FALSE;
    pt->x = dc->wndOrgX;
    pt->y = dc->wndOrgY;
1946
    release_dc_ptr( dc );
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
    return TRUE;
}


/***********************************************************************
 *		InquireVisRgn   (GDI.131)
 */
HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
{
    HRGN16 ret = 0;
1957
    DC * dc = get_dc_ptr( HDC_32(hdc) );
1958 1959 1960
    if (dc)
    {
        ret = HRGN_16(dc->hVisRgn);
1961
        release_dc_ptr( dc );
1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972
    }
    return ret;
}


/***********************************************************************
 *		GetClipRgn (GDI.173)
 */
HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
{
    HRGN16 ret = 0;
1973
    DC * dc = get_dc_ptr( HDC_32(hdc) );
1974 1975 1976
    if (dc)
    {
        ret = HRGN_16(dc->hClipRgn);
1977
        release_dc_ptr( dc );
1978 1979 1980 1981 1982
    }
    return ret;
}


1983
/***********************************************************************
1984
 *           GetLayout    (GDI32.@)
1985 1986 1987 1988 1989 1990
 *
 * Gets left->right or right->left text layout flags of a dc.
 *
 */
DWORD WINAPI GetLayout(HDC hdc)
{
1991 1992
    DWORD layout = GDI_ERROR;

1993
    DC * dc = get_dc_ptr( hdc );
1994 1995 1996
    if (dc)
    {
        layout = dc->layout;
1997
        release_dc_ptr( dc );
1998 1999
    }

2000
    TRACE("hdc : %p, layout : %08x\n", hdc, layout);
2001 2002

    return layout;
2003 2004 2005
}

/***********************************************************************
2006
 *           SetLayout    (GDI32.@)
2007 2008 2009 2010 2011 2012
 *
 * Sets left->right or right->left text layout flags of a dc.
 *
 */
DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
{
2013 2014
    DWORD oldlayout = GDI_ERROR;

2015
    DC * dc = get_dc_ptr( hdc );
2016 2017 2018 2019
    if (dc)
    {
        oldlayout = dc->layout;
        dc->layout = layout;
2020
        release_dc_ptr( dc );
2021 2022
    }

2023
    TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
2024 2025

    return oldlayout;
2026
}
2027

2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041
/***********************************************************************
 *           GetDCBrushColor    (GDI32.@)
 *
 * Retrieves the current brush color for the specified device
 * context (DC).
 *
 */
COLORREF WINAPI GetDCBrushColor(HDC hdc)
{
    DC *dc;
    COLORREF dcBrushColor = CLR_INVALID;

    TRACE("hdc(%p)\n", hdc);

2042
    dc = get_dc_ptr( hdc );
2043 2044 2045
    if (dc)
    {
        dcBrushColor = dc->dcBrushColor;
2046
	release_dc_ptr( dc );
2047 2048 2049 2050 2051
    }

    return dcBrushColor;
}

2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
/***********************************************************************
 *           SetDCBrushColor    (GDI32.@)
 *
 * Sets the current device context (DC) brush color to the specified
 * color value. If the device cannot represent the specified color
 * value, the color is set to the nearest physical color.
 *
 */
COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
{
2062 2063 2064
    DC *dc;
    COLORREF oldClr = CLR_INVALID;

2065
    TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2066

2067
    dc = get_dc_ptr( hdc );
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085
    if (dc)
    {
        if (dc->funcs->pSetDCBrushColor)
            crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
        else if (dc->hBrush == GetStockObject( DC_BRUSH ))
        {
            /* If DC_BRUSH is selected, update driver pen color */
            HBRUSH hBrush = CreateSolidBrush( crColor );
            dc->funcs->pSelectBrush( dc->physDev, hBrush );
	    DeleteObject( hBrush );
	}

        if (crColor != CLR_INVALID)
        {
            oldClr = dc->dcBrushColor;
            dc->dcBrushColor = crColor;
        }

2086
        release_dc_ptr( dc );
2087 2088 2089 2090 2091
    }

    return oldClr;
}

2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105
/***********************************************************************
 *           GetDCPenColor    (GDI32.@)
 *
 * Retrieves the current pen color for the specified device
 * context (DC).
 *
 */
COLORREF WINAPI GetDCPenColor(HDC hdc)
{
    DC *dc;
    COLORREF dcPenColor = CLR_INVALID;

    TRACE("hdc(%p)\n", hdc);

2106
    dc = get_dc_ptr( hdc );
2107 2108 2109
    if (dc)
    {
        dcPenColor = dc->dcPenColor;
2110
	release_dc_ptr( dc );
2111 2112 2113 2114 2115
    }

    return dcPenColor;
}

2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
/***********************************************************************
 *           SetDCPenColor    (GDI32.@)
 *
 * Sets the current device context (DC) pen color to the specified
 * color value. If the device cannot represent the specified color
 * value, the color is set to the nearest physical color.
 *
 */
COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
{
    DC *dc;
    COLORREF oldClr = CLR_INVALID;

2129
    TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2130

2131
    dc = get_dc_ptr( hdc );
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150
    if (dc)
    {
        if (dc->funcs->pSetDCPenColor)
            crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
        else if (dc->hPen == GetStockObject( DC_PEN ))
        {
            /* If DC_PEN is selected, update the driver pen color */
            LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
            HPEN hPen = CreatePenIndirect( &logpen );
            dc->funcs->pSelectPen( dc->physDev, hPen );
	    DeleteObject( hPen );
	}

        if (crColor != CLR_INVALID)
        {
            oldClr = dc->dcPenColor;
            dc->dcPenColor = crColor;
        }

2151
        release_dc_ptr( dc );
2152 2153 2154
    }

    return oldClr;
2155
}
2156

2157 2158 2159 2160 2161 2162 2163 2164 2165
/***********************************************************************
 *           CancelDC    (GDI32.@)
 */
BOOL WINAPI CancelDC(HDC hdc)
{
    FIXME("stub\n");
    return TRUE;
}

2166 2167 2168
/***********************************************************************
 *           SetVirtualResolution   (GDI32.@)
 *
2169
 * Undocumented on msdn.  Called when PowerPoint XP saves a file.
2170 2171 2172
 */
DWORD WINAPI SetVirtualResolution(HDC hdc, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5)
{
2173
    FIXME("(%p %08x %08x %08x %08x): stub!\n", hdc, dw2, dw3, dw4, dw5);
2174 2175
    return FALSE;
}
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188

/*******************************************************************
 *      GetMiterLimit [GDI32.@]
 *
 *
 */
BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
{
    BOOL bRet = FALSE;
    DC *dc;

    TRACE("(%p,%p)\n", hdc, peLimit);

2189
    dc = get_dc_ptr( hdc );
2190 2191 2192 2193 2194
    if (dc)
    {
        if (peLimit)
            *peLimit = dc->miterLimit;

2195
        release_dc_ptr( dc );
2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212
        bRet = TRUE;
    }
    return bRet;
}

/*******************************************************************
 *      SetMiterLimit [GDI32.@]
 *
 *
 */
BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
{
    BOOL bRet = FALSE;
    DC *dc;

    TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);

2213
    dc = get_dc_ptr( hdc );
2214 2215 2216 2217 2218
    if (dc)
    {
        if (peOldLimit)
            *peOldLimit = dc->miterLimit;
        dc->miterLimit = eNewLimit;
2219
        release_dc_ptr( dc );
2220 2221 2222 2223
        bRet = TRUE;
    }
    return bRet;
}
2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257

/*******************************************************************
 *      GdiIsMetaPrintDC [GDI32.@]
 */
BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
{
    FIXME("%p\n", hdc);
    return FALSE;
}

/*******************************************************************
 *      GdiIsMetaFileDC [GDI32.@]
 */
BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
{
    TRACE("%p\n", hdc);

    switch( GetObjectType( hdc ) )
    {
    case OBJ_METADC:
    case OBJ_ENHMETADC:
        return TRUE;
    }
    return FALSE;
}

/*******************************************************************
 *      GdiIsPlayMetafileDC [GDI32.@]
 */
BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)
{
    FIXME("%p\n", hdc);
    return FALSE;
}