gdiobj.c 39.5 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * GDI functions
 *
 * Copyright 1993 Alexandre Julliard
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
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
20

21 22
#include "config.h"

23
#include <assert.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
24
#include <stdlib.h>
25
#include <stdarg.h>
26
#include <stdio.h>
27

28
#include "windef.h"
29
#include "winbase.h"
30
#include "wingdi.h"
31
#include "winreg.h"
32
#include "winnls.h"
33
#include "winerror.h"
34
#include "winternl.h"
35

36
#include "gdi_private.h"
37
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
38

39
WINE_DEFAULT_DEBUG_CHANNEL(gdi);
40

41
#define HGDIOBJ_32(h16)   ((HGDIOBJ)(ULONG_PTR)(h16))
42

43 44
#define GDI_HEAP_SIZE 0xffe0

45 46
HMODULE gdi32_module = 0;

Alexandre Julliard's avatar
Alexandre Julliard committed
47
/***********************************************************************
48
 *          GDI stock objects
Alexandre Julliard's avatar
Alexandre Julliard committed
49 50
 */

51 52 53
static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
static const LOGBRUSH NullBrush  = { BS_NULL, 0, 0 };
Alexandre Julliard's avatar
Alexandre Julliard committed
54

55 56
static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
static const LOGBRUSH GrayBrush   = { BS_SOLID, RGB(128,128,128), 0 };
57
static const LOGBRUSH DkGrayBrush = { BS_SOLID, RGB(64,64,64), 0 };
Alexandre Julliard's avatar
Alexandre Julliard committed
58

59 60 61
static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
static const LOGPEN NullPen  = { PS_NULL,  { 0, 0 }, 0 };
Alexandre Julliard's avatar
Alexandre Julliard committed
62

63 64
static const LOGBRUSH DCBrush = { BS_SOLID, RGB(255,255,255), 0 };
static const LOGPEN DCPen     = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
65 66 67 68 69 70 71

/* reserve one extra entry for the stock default bitmap */
/* this is what Windows does too */
#define NB_STOCK_OBJECTS (STOCK_LAST+2)

static HGDIOBJ stock_objects[NB_STOCK_OBJECTS];

72
static CRITICAL_SECTION gdi_section;
73 74
static CRITICAL_SECTION_DEBUG critsect_debug =
{
75
    0, 0, &gdi_section,
76
    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
77
      0, 0, { (DWORD_PTR)(__FILE__ ": gdi_section") }
78
};
79
static CRITICAL_SECTION gdi_section = { &critsect_debug, -1, 0, 0, 0, 0 };
80

81 82 83 84 85 86 87

/****************************************************************************
 *
 *	language-independent stock fonts
 *
 */

88 89 90
static const LOGFONTW OEMFixedFont =
{ 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
  0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
Alexandre Julliard's avatar
Alexandre Julliard committed
91

92 93
static const LOGFONTW AnsiFixedFont =
{ 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
94 95
  0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
  {'C','o','u','r','i','e','r','\0'} };
Alexandre Julliard's avatar
Alexandre Julliard committed
96

97 98 99 100
static const LOGFONTW AnsiVarFont =
{ 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
  0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
  {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
Alexandre Julliard's avatar
Alexandre Julliard committed
101

102 103 104 105 106 107 108 109 110 111 112
/******************************************************************************
 *
 *      language-dependent stock fonts
 *
 *      'ANSI' charset and 'DEFAULT' charset is not same.
 *      The chars in CP_ACP should be drawn with 'DEFAULT' charset.
 *      'ANSI' charset seems to be identical with ISO-8859-1.
 *      'DEFAULT' charset is a language-dependent charset.
 *
 *      'System' font seems to be an alias for language-dependent font.
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
113

114
/*
Vitaly Lipatov's avatar
Vitaly Lipatov committed
115 116 117
 * language-dependent stock fonts for all known charsets
 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
 * CharsetBindingInfo (dlls/x11drv/xfont.c),
118 119 120 121 122 123 124 125
 * and modify entries for your language if needed.
 */
struct DefaultFontInfo
{
        UINT            charset;
        LOGFONTW        SystemFont;
        LOGFONTW        DeviceDefaultFont;
        LOGFONTW        SystemFixedFont;
126
        LOGFONTW        DefaultGuiFont; /* Note for this font the lfHeight member should be the point size */
127 128 129 130 131 132
};

static const struct DefaultFontInfo default_fonts[] =
{
    {   ANSI_CHARSET,
        { /* System */
133
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
134 135 136 137 138 139 140 141 142 143 144 145 146 147
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
148
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
149
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
150
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
151 152 153 154
        },
    },
    {   EASTEUROPE_CHARSET,
        { /* System */
155
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
156 157 158 159 160 161 162 163 164 165 166 167 168 169
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
170
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
171
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
172
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
173 174 175 176
        },
    },
    {   RUSSIAN_CHARSET,
        { /* System */
177
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
178 179 180 181 182 183 184 185 186 187 188 189 190 191
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
192
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
193
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
194
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
195 196 197 198
        },
    },
    {   GREEK_CHARSET,
        { /* System */
199
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
200 201 202 203 204 205 206 207 208 209 210 211 212 213
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
214
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
215
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
216
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
217 218 219 220
        },
    },
    {   TURKISH_CHARSET,
        { /* System */
221
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
222 223 224 225 226 227 228 229 230 231 232 233 234 235
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
236
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
237
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
238
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
239 240 241 242
        },
    },
    {   HEBREW_CHARSET,
        { /* System */
243
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
244 245 246 247 248 249 250 251 252 253 254 255 256 257
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
258
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
259
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
260
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
261 262 263 264
        },
    },
    {   ARABIC_CHARSET,
        { /* System */
265
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
266 267 268 269 270 271 272 273 274 275 276 277 278 279
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
280
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
281
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
282
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
283 284 285 286
        },
    },
    {   BALTIC_CHARSET,
        { /* System */
287
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
288 289 290 291 292 293 294 295 296 297 298 299 300 301
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
302
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
303
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
304
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
305 306 307 308
        },
    },
    {   THAI_CHARSET,
        { /* System */
309
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
310 311 312 313 314 315 316 317 318 319 320 321 322 323
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
324
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
325
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
326
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
327 328 329 330
        },
    },
    {   SHIFTJIS_CHARSET,
        { /* System */
331
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
332 333 334 335 336 337 338 339 340 341 342 343 344 345
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
346
           9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
347
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
348
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
349 350 351 352
        },
    },
    {   GB2312_CHARSET,
        { /* System */
353
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
354 355 356 357 358 359 360 361 362 363 364 365 366 367
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
368
           9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
369
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
370
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
371 372 373 374
        },
    },
    {   HANGEUL_CHARSET,
        { /* System */
375
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
376 377 378 379 380 381 382 383 384 385 386 387 388 389
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
390
           9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
391
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
392
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
393 394 395 396
        },
    },
    {   CHINESEBIG5_CHARSET,
        { /* System */
397
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
398 399 400 401 402 403 404 405 406 407 408 409 410 411
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
412
           9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
413
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
414
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
415 416 417 418
        },
    },
    {   JOHAB_CHARSET,
        { /* System */
419
          16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
420 421 422 423 424 425 426 427 428 429 430 431 432 433
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'S','y','s','t','e','m','\0'}
        },
        { /* Device Default */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
           {'\0'}
        },
        { /* System Fixed */
          16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
           0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
           {'\0'}
        },
        { /* DefaultGuiFont */
434
           8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
435
           0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
436
           {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
437 438 439
        },
    },
};
Alexandre Julliard's avatar
Alexandre Julliard committed
440

Alexandre Julliard's avatar
Alexandre Julliard committed
441

442 443 444 445 446 447 448
/*************************************************************************
 * __wine_make_gdi_object_system    (GDI32.@)
 *
 * USER has to tell GDI that its system brushes and pens are non-deletable.
 * For a description of the GDI object magics and their flags,
 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
 */
449
void CDECL __wine_make_gdi_object_system( HGDIOBJ handle, BOOL set)
450
{
451 452
    GDIOBJHDR *ptr = GDI_GetObjPtr( handle, 0 );
    ptr->system = !!set;
453 454 455
    GDI_ReleaseObj( handle );
}

456 457 458 459 460
/******************************************************************************
 *      get_default_fonts
 */
static const struct DefaultFontInfo* get_default_fonts(UINT charset)
{
461
        unsigned int n;
Alexandre Julliard's avatar
Alexandre Julliard committed
462

463 464 465 466 467
        for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
        {
                if ( default_fonts[n].charset == charset )
                        return &default_fonts[n];
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
468

469 470 471
        FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
        return &default_fonts[0];
}
472

473

474 475 476 477 478 479
/******************************************************************************
 *      get_default_charset    (internal)
 *
 * get the language-dependent charset that can handle CP_ACP correctly.
 */
static UINT get_default_charset( void )
480
{
481 482 483 484 485
    CHARSETINFO     csi;
    UINT    uACP;

    uACP = GetACP();
    csi.ciCharset = ANSI_CHARSET;
486
    if ( !TranslateCharsetInfo( ULongToPtr(uACP), &csi, TCI_SRCCODEPAGE ) )
487 488 489 490 491 492
    {
        FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
        return ANSI_CHARSET;
    }

    return csi.ciCharset;
493
}
494

495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'};

/******************************************************************************
 *      get_dpi   (internal)
 *
 * get the dpi from the registry
 */
static DWORD get_dpi( void )
{
    DWORD dpi = 96;
    HKEY hkey;

    if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
    {
        DWORD type, size, new_dpi;

        size = sizeof(new_dpi);
        if(RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, &size) == ERROR_SUCCESS)
        {
            if(type == REG_DWORD && new_dpi != 0)
                dpi = new_dpi;
        }
        RegCloseKey(hkey);
    }
    return dpi;
}
522

523

524
/***********************************************************************
525
 *           GDI_inc_ref_count
526 527 528
 *
 * Increment the reference count of a GDI object.
 */
529
HGDIOBJ GDI_inc_ref_count( HGDIOBJ handle )
530
{
531 532
    GDIOBJHDR *header;

533
    if ((header = GDI_GetObjPtr( handle, 0 )))
534
    {
535
        header->selcount++;
536 537
        GDI_ReleaseObj( handle );
    }
538 539 540
    else handle = 0;

    return handle;
541 542 543 544
}


/***********************************************************************
545
 *           GDI_dec_ref_count
546 547 548
 *
 * Decrement the reference count of a GDI object.
 */
549
BOOL GDI_dec_ref_count( HGDIOBJ handle )
550 551 552
{
    GDIOBJHDR *header;

553
    if ((header = GDI_GetObjPtr( handle, 0 )))
554
    {
555 556
        assert( header->selcount );
        if (!--header->selcount && header->deleted)
557 558
        {
            /* handle delayed DeleteObject*/
559
            header->deleted = 0;
560
            GDI_ReleaseObj( handle );
561
            TRACE( "executing delayed DeleteObject for %p\n", handle );
562 563
            DeleteObject( handle );
        }
564
        else GDI_ReleaseObj( handle );
565
    }
566
    return header != NULL;
567 568 569
}


Alexandre Julliard's avatar
Alexandre Julliard committed
570
/***********************************************************************
571
 *           DllMain
Alexandre Julliard's avatar
Alexandre Julliard committed
572
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
573
 * GDI initialization.
Alexandre Julliard's avatar
Alexandre Julliard committed
574
 */
575
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
Alexandre Julliard's avatar
Alexandre Julliard committed
576
{
577
    LOGFONTW default_gui_font;
578
    const struct DefaultFontInfo* deffonts;
579 580
    int i;

581 582
    if (reason != DLL_PROCESS_ATTACH) return TRUE;

583
    gdi32_module = inst;
584
    DisableThreadLibraryCalls( inst );
585 586
    WineEngInit();

587 588 589 590 591 592 593 594 595 596 597 598 599 600
    /* create stock objects */
    stock_objects[WHITE_BRUSH]  = CreateBrushIndirect( &WhiteBrush );
    stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
    stock_objects[GRAY_BRUSH]   = CreateBrushIndirect( &GrayBrush );
    stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
    stock_objects[BLACK_BRUSH]  = CreateBrushIndirect( &BlackBrush );
    stock_objects[NULL_BRUSH]   = CreateBrushIndirect( &NullBrush );

    stock_objects[WHITE_PEN]    = CreatePenIndirect( &WhitePen );
    stock_objects[BLACK_PEN]    = CreatePenIndirect( &BlackPen );
    stock_objects[NULL_PEN]     = CreatePenIndirect( &NullPen );

    stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
    stock_objects[DEFAULT_BITMAP]  = CreateBitmap( 1, 1, 1, 1, NULL );
Alexandre Julliard's avatar
Alexandre Julliard committed
601

602
    /* language-independent stock fonts */
603 604 605
    stock_objects[OEM_FIXED_FONT]      = CreateFontIndirectW( &OEMFixedFont );
    stock_objects[ANSI_FIXED_FONT]     = CreateFontIndirectW( &AnsiFixedFont );
    stock_objects[ANSI_VAR_FONT]       = CreateFontIndirectW( &AnsiVarFont );
606 607 608

    /* language-dependent stock fonts */
    deffonts = get_default_fonts(get_default_charset());
609 610 611
    stock_objects[SYSTEM_FONT]         = CreateFontIndirectW( &deffonts->SystemFont );
    stock_objects[DEVICE_DEFAULT_FONT] = CreateFontIndirectW( &deffonts->DeviceDefaultFont );
    stock_objects[SYSTEM_FIXED_FONT]   = CreateFontIndirectW( &deffonts->SystemFixedFont );
612 613 614

    /* For the default gui font, we use the lfHeight member in deffonts as a place-holder
       for the point size so we must convert this into a true height */
615
    default_gui_font = deffonts->DefaultGuiFont;
616
    default_gui_font.lfHeight = -MulDiv(default_gui_font.lfHeight, get_dpi(), 72);
617
    stock_objects[DEFAULT_GUI_FONT]    = CreateFontIndirectW( &default_gui_font );
Alexandre Julliard's avatar
Alexandre Julliard committed
618

619 620
    stock_objects[DC_BRUSH]     = CreateBrushIndirect( &DCBrush );
    stock_objects[DC_PEN]       = CreatePenIndirect( &DCPen );
Alexandre Julliard's avatar
Alexandre Julliard committed
621

622 623 624 625 626 627 628 629 630
    /* clear the NOSYSTEM bit on all stock objects*/
    for (i = 0; i < NB_STOCK_OBJECTS; i++)
    {
        if (!stock_objects[i])
        {
            if (i == 9) continue;  /* there's no stock object 9 */
            ERR( "could not create stock object %d\n", i );
            return FALSE;
        }
631
        __wine_make_gdi_object_system( stock_objects[i], TRUE );
632 633
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
634
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
635 636
}

637
#define FIRST_LARGE_HANDLE 16
638
#define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
639 640
static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
static int next_large_handle;
641
static LONG debug_count;
642

643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
static const char *gdi_obj_type( unsigned type )
{
    switch ( type )
    {
        case OBJ_PEN: return "OBJ_PEN";
        case OBJ_BRUSH: return "OBJ_BRUSH";
        case OBJ_DC: return "OBJ_DC";
        case OBJ_METADC: return "OBJ_METADC";
        case OBJ_PAL: return "OBJ_PAL";
        case OBJ_FONT: return "OBJ_FONT";
        case OBJ_BITMAP: return "OBJ_BITMAP";
        case OBJ_REGION: return "OBJ_REGION";
        case OBJ_METAFILE: return "OBJ_METAFILE";
        case OBJ_MEMDC: return "OBJ_MEMDC";
        case OBJ_EXTPEN: return "OBJ_EXTPEN";
        case OBJ_ENHMETADC: return "OBJ_ENHMETADC";
        case OBJ_ENHMETAFILE: return "OBJ_ENHMETAFILE";
        case OBJ_COLORSPACE: return "OBJ_COLORSPACE";
        default: return "UNKNOWN";
    }
}

static void dump_gdi_objects( void )
{
    int i;

    TRACE( "%u objects:\n", MAX_LARGE_HANDLES );

    EnterCriticalSection( &gdi_section );
    for (i = 0; i < MAX_LARGE_HANDLES; i++)
    {
        if (!large_handles[i])
        {
            TRACE( "index %d handle %p FREE\n", i, (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2) );
            continue;
        }
        TRACE( "handle %p obj %p type %s selcount %u deleted %u\n",
               (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2),
               large_handles[i], gdi_obj_type( large_handles[i]->type ),
               large_handles[i]->selcount, large_handles[i]->deleted );
    }
    LeaveCriticalSection( &gdi_section );
}

687
/***********************************************************************
688
 *           alloc_gdi_handle
689
 *
690
 * Allocate a GDI handle for an object, which must have been allocated on the process heap.
691
 */
692
HGDIOBJ alloc_gdi_handle( GDIOBJHDR *obj, WORD type, const struct gdi_obj_funcs *funcs )
693 694 695
{
    int i;

696
    /* initialize the object header */
697 698 699 700 701 702
    obj->type     = type;
    obj->system   = 0;
    obj->deleted  = 0;
    obj->selcount = 0;
    obj->funcs    = funcs;
    obj->hdcs     = NULL;
703

704
    EnterCriticalSection( &gdi_section );
705 706 707 708
    for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
        if (!large_handles[i]) goto found;
    for (i = 0; i <= next_large_handle; i++)
        if (!large_handles[i]) goto found;
709
    LeaveCriticalSection( &gdi_section );
710 711 712

    ERR( "out of GDI object handles, expect a crash\n" );
    if (TRACE_ON(gdi)) dump_gdi_objects();
713
    return 0;
714

715 716 717
 found:
    large_handles[i] = obj;
    next_large_handle = i;
718
    LeaveCriticalSection( &gdi_section );
719 720 721
    TRACE( "allocated %s %p %u/%u\n",
           gdi_obj_type(type), (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2),
           InterlockedIncrement( &debug_count ), MAX_LARGE_HANDLES );
722
    return (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
Alexandre Julliard's avatar
Alexandre Julliard committed
723 724 725
}


726
/***********************************************************************
727 728 729
 *           free_gdi_handle
 *
 * Free a GDI handle and return a pointer to the object.
730
 */
731
void *free_gdi_handle( HGDIOBJ handle )
732
{
733
    GDIOBJHDR *object = NULL;
734
    int i;
735

736
    i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
737
    if (i >= 0 && i < MAX_LARGE_HANDLES)
738
    {
739
        EnterCriticalSection( &gdi_section );
740
        object = large_handles[i];
741
        large_handles[i] = NULL;
742
        LeaveCriticalSection( &gdi_section );
743
    }
744 745
    if (object)
    {
746 747
        TRACE( "freed %s %p %u/%u\n", gdi_obj_type( object->type ), handle,
               InterlockedDecrement( &debug_count ) + 1, MAX_LARGE_HANDLES );
748 749 750 751
        object->type  = 0;  /* mark it as invalid */
        object->funcs = NULL;
    }
    return object;
Alexandre Julliard's avatar
Alexandre Julliard committed
752 753
}

754

Alexandre Julliard's avatar
Alexandre Julliard committed
755 756 757 758 759
/***********************************************************************
 *           GDI_GetObjPtr
 *
 * Return a pointer to the GDI object associated to the handle.
 * Return NULL if the object has the wrong magic number.
760
 * The object must be released with GDI_ReleaseObj.
Alexandre Julliard's avatar
Alexandre Julliard committed
761
 */
762
void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
Alexandre Julliard's avatar
Alexandre Julliard committed
763
{
764
    GDIOBJHDR *ptr = NULL;
765
    int i;
766

767
    EnterCriticalSection( &gdi_section );
Alexandre Julliard's avatar
Alexandre Julliard committed
768

769 770
    i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
    if (i >= 0 && i < MAX_LARGE_HANDLES)
Alexandre Julliard's avatar
Alexandre Julliard committed
771
    {
772
        ptr = large_handles[i];
773
        if (ptr && type && ptr->type != type) ptr = NULL;
774
    }
775 776 777

    if (!ptr)
    {
778
        LeaveCriticalSection( &gdi_section );
779
        WARN( "Invalid handle %p\n", handle );
780 781
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
782 783 784 785
    return ptr;
}


786 787 788 789 790 791
/***********************************************************************
 *           GDI_ReleaseObj
 *
 */
void GDI_ReleaseObj( HGDIOBJ handle )
{
792
    LeaveCriticalSection( &gdi_section );
793 794 795
}


796 797 798 799 800
/***********************************************************************
 *           GDI_CheckNotLock
 */
void GDI_CheckNotLock(void)
{
801 802 803 804 805
    if (gdi_section.OwningThread == ULongToHandle(GetCurrentThreadId()) && gdi_section.RecursionCount)
    {
        ERR( "BUG: holding GDI lock\n" );
        DebugBreak();
    }
806 807 808
}


Alexandre Julliard's avatar
Alexandre Julliard committed
809
/***********************************************************************
810
 *           DeleteObject    (GDI32.@)
811 812 813 814 815 816 817 818 819 820 821
 *
 * Delete a Gdi object.
 *
 * PARAMS
 *  obj [I] Gdi object to delete
 *
 * RETURNS
 *  Success: TRUE. If obj was not returned from GetStockObject(), any resources
 *           it consumed are released.
 *  Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
 *           into a DC.
Alexandre Julliard's avatar
Alexandre Julliard committed
822
 */
823
BOOL WINAPI DeleteObject( HGDIOBJ obj )
Alexandre Julliard's avatar
Alexandre Julliard committed
824 825 826
{
      /* Check if object is valid */

827
    struct hdc_list *hdcs_head;
828
    const struct gdi_obj_funcs *funcs;
Alexandre Julliard's avatar
Alexandre Julliard committed
829
    GDIOBJHDR * header;
830

Alexandre Julliard's avatar
Alexandre Julliard committed
831
    if (HIWORD(obj)) return FALSE;
832

833
    if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
834

835
    if (header->system)
836
    {
837
	TRACE("Preserving system object %p\n", obj);
838 839 840
        GDI_ReleaseObj( obj );
	return TRUE;
    }
841

842
    while ((hdcs_head = header->hdcs) != NULL)
843
    {
844 845 846 847
        DC *dc = get_dc_ptr(hdcs_head->hdc);

        header->hdcs = hdcs_head->next;
        TRACE("hdc %p has interest in %p\n", hdcs_head->hdc, obj);
848 849 850

        if(dc)
        {
851 852 853 854
            PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeleteObject );
            GDI_ReleaseObj( obj );  /* release the GDI lock */
            physdev->funcs->pDeleteObject( physdev, obj );
            header = GDI_GetObjPtr( obj, 0 );  /* and grab it again */
855
            release_dc_ptr( dc );
856
        }
857 858
        HeapFree(GetProcessHeap(), 0, hdcs_head);
        if (!header) return FALSE;
859 860
    }

861
    if (header->selcount)
862
    {
863 864
        TRACE("delayed for %p because object in use, count %u\n", obj, header->selcount );
        header->deleted = 1;  /* mark for delete */
865 866 867 868
        GDI_ReleaseObj( obj );
        return TRUE;
    }

869
    TRACE("%p\n", obj );
Alexandre Julliard's avatar
Alexandre Julliard committed
870 871 872

      /* Delete object */

873
    funcs = header->funcs;
874
    GDI_ReleaseObj( obj );
875 876 877 878
    if (funcs && funcs->pDeleteObject)
        return funcs->pDeleteObject( obj );
    else
        return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
879 880
}

881 882 883 884 885 886 887 888 889 890 891 892
/***********************************************************************
 *           GDI_hdc_using_object
 *
 * Call this if the dc requires DeleteObject notification
 */
BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc)
{
    GDIOBJHDR * header;
    struct hdc_list **pphdc;

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

893
    if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
894

895
    if (header->system)
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
    {
        GDI_ReleaseObj(obj);
        return FALSE;
    }

    for(pphdc = &header->hdcs; *pphdc; pphdc = &(*pphdc)->next)
        if((*pphdc)->hdc == hdc)
            break;

    if(!*pphdc) {
        *pphdc = HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc));
        (*pphdc)->hdc = hdc;
        (*pphdc)->next = NULL;
    }

    GDI_ReleaseObj(obj);
    return TRUE;
}

/***********************************************************************
 *           GDI_hdc_not_using_object
 *
 */
BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc)
{
    GDIOBJHDR * header;
    struct hdc_list *phdc, **prev;

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

926
    if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
927

928
    if (header->system)
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
    {
        GDI_ReleaseObj(obj);
        return FALSE;
    }

    phdc = header->hdcs;
    prev = &header->hdcs;

    while(phdc) {
        if(phdc->hdc == hdc) {
            *prev = phdc->next;
            HeapFree(GetProcessHeap(), 0, phdc);
            phdc = *prev;
        } else {
            prev = &phdc->next;
            phdc = phdc->next;
        }
    }

    GDI_ReleaseObj(obj);
    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
951 952

/***********************************************************************
953
 *           GetStockObject    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
954
 */
955
HGDIOBJ WINAPI GetStockObject( INT obj )
Alexandre Julliard's avatar
Alexandre Julliard committed
956
{
957
    HGDIOBJ ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
958
    if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
959
    ret = stock_objects[obj];
960
    TRACE("returning %p\n", ret );
961
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
962 963 964
}


Alexandre Julliard's avatar
Alexandre Julliard committed
965
/***********************************************************************
966
 *           GetObjectA    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
967
 */
968
INT WINAPI GetObjectA( HGDIOBJ handle, INT count, LPVOID buffer )
Alexandre Julliard's avatar
Alexandre Julliard committed
969
{
970
    const struct gdi_obj_funcs *funcs;
971
    GDIOBJHDR * ptr;
972
    INT result = 0;
973

974
    TRACE("%p %d %p\n", handle, count, buffer );
Alexandre Julliard's avatar
Alexandre Julliard committed
975

976
    if (!(ptr = GDI_GetObjPtr( handle, 0 ))) return 0;
977 978
    funcs = ptr->funcs;
    GDI_ReleaseObj( handle );
979

980
    if (funcs && funcs->pGetObjectA)
981 982 983 984 985 986
    {
        if (buffer && ((ULONG_PTR)buffer >> 16) == 0) /* catch apps getting argument order wrong */
            SetLastError( ERROR_NOACCESS );
        else
            result = funcs->pGetObjectA( handle, count, buffer );
    }
987 988
    else
        SetLastError( ERROR_INVALID_HANDLE );
989

Alexandre Julliard's avatar
Alexandre Julliard committed
990
    return result;
Alexandre Julliard's avatar
Alexandre Julliard committed
991
}
992

993
/***********************************************************************
994
 *           GetObjectW    (GDI32.@)
995
 */
996
INT WINAPI GetObjectW( HGDIOBJ handle, INT count, LPVOID buffer )
997
{
998
    const struct gdi_obj_funcs *funcs;
999
    GDIOBJHDR * ptr;
1000
    INT result = 0;
1001
    TRACE("%p %d %p\n", handle, count, buffer );
1002

1003
    if (!(ptr = GDI_GetObjPtr( handle, 0 ))) return 0;
1004 1005
    funcs = ptr->funcs;
    GDI_ReleaseObj( handle );
1006

1007
    if (funcs && funcs->pGetObjectW)
1008 1009 1010 1011 1012 1013
    {
        if (buffer && ((ULONG_PTR)buffer >> 16) == 0) /* catch apps getting argument order wrong */
            SetLastError( ERROR_NOACCESS );
        else
            result = funcs->pGetObjectW( handle, count, buffer );
    }
1014 1015 1016
    else
        SetLastError( ERROR_INVALID_HANDLE );

1017 1018
    return result;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1019

Alexandre Julliard's avatar
Alexandre Julliard committed
1020
/***********************************************************************
1021
 *           GetObjectType    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1022
 */
1023
DWORD WINAPI GetObjectType( HGDIOBJ handle )
Alexandre Julliard's avatar
Alexandre Julliard committed
1024
{
1025
    GDIOBJHDR * ptr;
1026
    DWORD result;
Alexandre Julliard's avatar
Alexandre Julliard committed
1027

1028
    if (!(ptr = GDI_GetObjPtr( handle, 0 )))
1029 1030 1031 1032
    {
        SetLastError( ERROR_INVALID_HANDLE );
        return 0;
    }
1033
    result = ptr->type;
1034
    GDI_ReleaseObj( handle );
1035
    TRACE("%p -> %u\n", handle, result );
Alexandre Julliard's avatar
Alexandre Julliard committed
1036 1037
    return result;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1038

Alexandre Julliard's avatar
Alexandre Julliard committed
1039
/***********************************************************************
1040
 *           GetCurrentObject    	(GDI32.@)
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
 *
 * Get the currently selected object of a given type in a device context.
 *
 * PARAMS
 *  hdc  [I] Device context to get the current object from
 *  type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
 *
 * RETURNS
 *  Success: The current object of the given type selected in hdc.
 *  Failure: A NULL handle.
 *
 * NOTES
 * - only the following object types are supported:
 *| OBJ_PEN
 *| OBJ_BRUSH
 *| OBJ_PAL
 *| OBJ_FONT
 *| OBJ_BITMAP
Alexandre Julliard's avatar
Alexandre Julliard committed
1059
 */
1060
HGDIOBJ WINAPI GetCurrentObject(HDC hdc,UINT type)
Alexandre Julliard's avatar
Alexandre Julliard committed
1061
{
1062
    HGDIOBJ ret = 0;
1063 1064 1065
    DC * dc = get_dc_ptr( hdc );

    if (!dc) return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1066 1067

    switch (type) {
1068
	case OBJ_EXTPEN: /* fall through */
1069 1070 1071 1072 1073
	case OBJ_PEN:	 ret = dc->hPen; break;
	case OBJ_BRUSH:	 ret = dc->hBrush; break;
	case OBJ_PAL:	 ret = dc->hPalette; break;
	case OBJ_FONT:	 ret = dc->hFont; break;
	case OBJ_BITMAP: ret = dc->hBitmap; break;
1074 1075 1076

	/* tests show that OBJ_REGION is explicitly ignored */
	case OBJ_REGION: break;
1077 1078 1079
        default:
            /* the SDK only mentions those above */
            FIXME("(%p,%d): unknown type.\n",hdc,type);
1080
	    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1081
    }
1082
    release_dc_ptr( dc );
1083
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1084
}
1085 1086


Alexandre Julliard's avatar
Alexandre Julliard committed
1087
/***********************************************************************
1088
 *           SelectObject    (GDI32.@)
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
 *
 * Select a Gdi object into a device context.
 *
 * PARAMS
 *  hdc  [I] Device context to associate the object with
 *  hObj [I] Gdi object to associate with hdc
 *
 * RETURNS
 *  Success: A non-NULL handle representing the previously selected object of
 *           the same type as hObj.
 *  Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
 *           if hObj is not a valid object handle, no last error is set. In either
 *           case, hdc is unaffected by the call.
Alexandre Julliard's avatar
Alexandre Julliard committed
1102
 */
1103
HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj )
Alexandre Julliard's avatar
Alexandre Julliard committed
1104
{
1105
    HGDIOBJ ret = 0;
1106
    GDIOBJHDR *header;
1107

1108
    TRACE( "(%p,%p)\n", hdc, hObj );
1109

1110
    header = GDI_GetObjPtr( hObj, 0 );
1111
    if (header)
1112
    {
1113 1114 1115
        const struct gdi_obj_funcs *funcs = header->funcs;
        GDI_ReleaseObj( hObj );
        if (funcs && funcs->pSelectObject) ret = funcs->pSelectObject( hObj, hdc );
1116
    }
1117
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1118 1119 1120
}


Alexandre Julliard's avatar
Alexandre Julliard committed
1121
/***********************************************************************
1122
 *           UnrealizeObject    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1123
 */
1124
BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
Alexandre Julliard's avatar
Alexandre Julliard committed
1125
{
1126
    BOOL result = FALSE;
1127
    GDIOBJHDR * header = GDI_GetObjPtr( obj, 0 );
Alexandre Julliard's avatar
Alexandre Julliard committed
1128

1129 1130 1131
    if (header)
    {
        const struct gdi_obj_funcs *funcs = header->funcs;
Alexandre Julliard's avatar
Alexandre Julliard committed
1132

1133 1134 1135 1136 1137 1138
        GDI_ReleaseObj( obj );
        if (funcs && funcs->pUnrealizeObject)
            result = header->funcs->pUnrealizeObject( obj );
        else
            result = TRUE;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1139
    return result;
Alexandre Julliard's avatar
Alexandre Julliard committed
1140
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1141 1142


Andreas Mohr's avatar
Andreas Mohr committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
/* Solid colors to enumerate */
static const COLORREF solid_colors[] =
{ RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
};
1154

Alexandre Julliard's avatar
Alexandre Julliard committed
1155 1156

/***********************************************************************
1157
 *           EnumObjects    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1158
 */
1159 1160
INT WINAPI EnumObjects( HDC hdc, INT nObjType,
                            GOBJENUMPROC lpEnumFunc, LPARAM lParam )
Alexandre Julliard's avatar
Alexandre Julliard committed
1161
{
1162 1163
    UINT i;
    INT retval = 0;
1164 1165
    LOGPEN pen;
    LOGBRUSH brush;
Alexandre Julliard's avatar
Alexandre Julliard committed
1166

1167
    TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
Alexandre Julliard's avatar
Alexandre Julliard committed
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
    switch(nObjType)
    {
    case OBJ_PEN:
        /* Enumerate solid pens */
        for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
        {
            pen.lopnStyle   = PS_SOLID;
            pen.lopnWidth.x = 1;
            pen.lopnWidth.y = 0;
            pen.lopnColor   = solid_colors[i];
            retval = lpEnumFunc( &pen, lParam );
1179
            TRACE("solid pen %08x, ret=%d\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
                         solid_colors[i], retval);
            if (!retval) break;
        }
        break;

    case OBJ_BRUSH:
        /* Enumerate solid brushes */
        for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
        {
            brush.lbStyle = BS_SOLID;
            brush.lbColor = solid_colors[i];
            brush.lbHatch = 0;
            retval = lpEnumFunc( &brush, lParam );
1193
            TRACE("solid brush %08x, ret=%d\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
                         solid_colors[i], retval);
            if (!retval) break;
        }

        /* Now enumerate hatched brushes */
        if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
        {
            brush.lbStyle = BS_HATCHED;
            brush.lbColor = RGB(0,0,0);
            brush.lbHatch = i;
            retval = lpEnumFunc( &brush, lParam );
1205
            TRACE("hatched brush %d, ret=%d\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
1206 1207 1208 1209 1210 1211 1212
                         i, retval);
            if (!retval) break;
        }
        break;

    default:
        /* FIXME: implement Win32 types */
1213
        WARN("(%d): Invalid type\n", nObjType );
Alexandre Julliard's avatar
Alexandre Julliard committed
1214 1215 1216
        break;
    }
    return retval;
Alexandre Julliard's avatar
Alexandre Julliard committed
1217
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1218

Alexandre Julliard's avatar
Alexandre Julliard committed
1219

Alexandre Julliard's avatar
Alexandre Julliard committed
1220
/***********************************************************************
1221
 *           SetObjectOwner    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1222
 */
1223
void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
Alexandre Julliard's avatar
Alexandre Julliard committed
1224 1225 1226 1227
{
    /* Nothing to do */
}

1228 1229 1230 1231 1232 1233 1234 1235
/***********************************************************************
 *           GdiInitializeLanguagePack    (GDI32.@)
 */
DWORD WINAPI GdiInitializeLanguagePack( DWORD arg )
{
    FIXME("stub\n");
    return 0;
}
1236

Alexandre Julliard's avatar
Alexandre Julliard committed
1237
/***********************************************************************
1238
 *           GdiFlush    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1239
 */
1240
BOOL WINAPI GdiFlush(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
1241 1242 1243 1244
{
    return TRUE;  /* FIXME */
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1245 1246

/***********************************************************************
1247
 *           GdiGetBatchLimit    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1248 1249 1250 1251 1252 1253 1254 1255
 */
DWORD WINAPI GdiGetBatchLimit(void)
{
    return 1;  /* FIXME */
}


/***********************************************************************
1256
 *           GdiSetBatchLimit    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1257 1258 1259 1260 1261 1262 1263
 */
DWORD WINAPI GdiSetBatchLimit( DWORD limit )
{
    return 1; /* FIXME */
}


1264
/*******************************************************************
1265
 *      GetColorAdjustment [GDI32.@]
1266 1267 1268
 *
 *
 */
1269
BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1270
{
1271
        FIXME("stub\n");
1272 1273 1274 1275
        return 0;
}

/*******************************************************************
1276
 *      GdiComment [GDI32.@]
1277 1278 1279
 *
 *
 */
1280
BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1281
{
1282
    DC *dc = get_dc_ptr(hdc);
1283
    BOOL ret = FALSE;
1284

1285 1286
    if(dc)
    {
1287 1288
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGdiComment );
        ret = physdev->funcs->pGdiComment( physdev, cbSize, lpData );
1289
        release_dc_ptr( dc );
1290 1291
    }
    return ret;
1292
}
1293

1294
/*******************************************************************
1295
 *      SetColorAdjustment [GDI32.@]
1296 1297 1298
 *
 *
 */
1299
BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1300
{
1301
        FIXME("stub\n");
1302 1303
        return 0;
}