msw_style.c 62.4 KB
Newer Older
1
/* MS-Windows Engine (aka GTK-Wimp)
2
 *
3
 * Copyright (C) 2003, 2004 Raymond Penners <raymond@dotsphinx.com>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * Includes code adapted from redmond95 by Owen Taylor, and
 * gtk-nativewin by Evan Martin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

23 24 25 26
/*
 * Useful resources:
 *
 *  http://lxr.mozilla.org/mozilla/source/gfx/src/windows/nsNativeThemeWin.cpp
Dom Lachowicz's avatar
Dom Lachowicz committed
27
 *  http://lxr.mozilla.org/seamonkey/source/widget/src/windows/nsLookAndFeel.cpp
28 29 30
 *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/functions/drawthemebackground.asp
 */

31
#include "msw_style.h"
Raymond Penners's avatar
Raymond Penners committed
32
#include "xp_theme.h"
33 34 35 36 37 38

#include <windows.h>
#include <math.h>
#include <string.h>
#include <stdio.h>

39 40
#include "gtk/gtk.h"
#include "gtk/gtk.h"
41
/* #include <gdk/gdkwin32.h> */
42

43 44 45
#include "gdk/win32/gdkwin32.h"


46 47
/* Default values, not normally used
 */
cinamod's avatar
cinamod committed
48 49
static const GtkRequisition default_option_indicator_size = { 9, 8 };
static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
50 51 52

static GtkStyleClass *parent_class;

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
typedef enum
{
    CHECK_AA,
    CHECK_BASE,
    CHECK_BLACK,
    CHECK_DARK,
    CHECK_LIGHT,
    CHECK_MID,
    CHECK_TEXT,
    RADIO_BASE,
    RADIO_BLACK,
    RADIO_DARK,
    RADIO_LIGHT,
    RADIO_MID,
    RADIO_TEXT
68 69 70 71
} Part;

#define PART_SIZE 13

Dom Lachowicz's avatar
Dom Lachowicz committed
72
static const guint8 check_aa_bits[] = {
73 74 75 76
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
77
static const guint8 check_base_bits[] = {
78 79 80 81
    0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xfc, 0x07, 0xfc, 0x07, 0xfc, 0x07,
    0xfc, 0x07, 0xfc,
    0x07, 0xfc, 0x07, 0xfc, 0x07, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
82
static const guint8 check_black_bits[] = {
83 84 85 86
    0x00, 0x00, 0xfe, 0x0f, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00,
    0x02, 0x00, 0x02,
    0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
87
static const guint8 check_dark_bits[] = {
88 89 90 91
    0xff, 0x1f, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
    0x01, 0x00, 0x01,
    0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
92
static const guint8 check_light_bits[] = {
93 94 95 96
    0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
    0x00, 0x10, 0x00,
    0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0xfe, 0x1f
};
Dom Lachowicz's avatar
Dom Lachowicz committed
97
static const guint8 check_mid_bits[] = {
98 99 100 101
    0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08,
    0x00, 0x08, 0x00,
    0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0xfc, 0x0f, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
102
static const guint8 check_text_bits[] = {
103 104 105 106
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x88, 0x03,
    0xd8, 0x01, 0xf8,
    0x00, 0x70, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
107
static const guint8 radio_base_bits[] = {
108 109 110 111
    0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0xf8, 0x03, 0xfc, 0x07, 0xfc, 0x07,
    0xfc, 0x07, 0xfc,
    0x07, 0xfc, 0x07, 0xf8, 0x03, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
112
static const guint8 radio_black_bits[] = {
113 114 115 116
    0x00, 0x00, 0xf0, 0x01, 0x0c, 0x02, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00,
    0x02, 0x00, 0x02,
    0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
117
static const guint8 radio_dark_bits[] = {
118 119 120 121
    0xf0, 0x01, 0x0c, 0x06, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00,
    0x01, 0x00, 0x01,
    0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
122
static const guint8 radio_light_bits[] = {
123 124 125 126
    0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x10, 0x00, 0x10,
    0x00, 0x10, 0x00,
    0x10, 0x00, 0x10, 0x00, 0x08, 0x00, 0x08, 0x0c, 0x06, 0xf0, 0x01
};
Dom Lachowicz's avatar
Dom Lachowicz committed
127
static const guint8 radio_mid_bits[] = {
128 129 130 131
    0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08,
    0x00, 0x08, 0x00,
    0x08, 0x00, 0x08, 0x00, 0x04, 0x0c, 0x06, 0xf0, 0x01, 0x00, 0x00
};
Dom Lachowicz's avatar
Dom Lachowicz committed
132
static const guint8 radio_text_bits[] = {
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0xf0, 0x01,
    0xf0, 0x01, 0xf0,
    0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static struct
{
    const guint8 *bits;
    GdkBitmap *bmap;
} parts[] =
{
    {check_aa_bits, NULL},
    {check_base_bits, NULL},
    {check_black_bits, NULL},
    {check_dark_bits, NULL},
    {check_light_bits, NULL},
    {check_mid_bits, NULL},
    {check_text_bits, NULL},
    {radio_base_bits, NULL},
    {radio_black_bits, NULL},
    {radio_dark_bits, NULL},
    {radio_light_bits, NULL},
    {radio_mid_bits, NULL},
    {radio_text_bits, NULL}
157 158 159
};

static gboolean
160
get_system_font (XpThemeClass klazz, XpThemeFont type, LOGFONT * out_lf)
161
{
cinamod's avatar
cinamod committed
162
#if 0
163 164 165 166 167
    /* TODO: this causes crashes later because the font name is in UCS2, and
       the pango fns don't deal with that gracefully */
    if (xp_theme_get_system_font (klazz, type, out_lf))
	return TRUE;
    else
cinamod's avatar
cinamod committed
168
#endif
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
	{
	    NONCLIENTMETRICS ncm;

	    ncm.cbSize = sizeof (NONCLIENTMETRICS);

	    if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS,
				      sizeof (NONCLIENTMETRICS), &ncm, 0))
		{
		    if (type == XP_THEME_FONT_CAPTION)
			*out_lf = ncm.lfCaptionFont;
		    else if (type == XP_THEME_FONT_MENU)
			*out_lf = ncm.lfMenuFont;
		    else if (type == XP_THEME_FONT_STATUS)
			*out_lf = ncm.lfStatusFont;
		    else
			*out_lf = ncm.lfMessageFont;

		    return TRUE;
		}
	}
    return FALSE;
190 191
}

192
/***************************** BEGIN STOLEN FROM PANGO *****************************/
cinamod's avatar
cinamod committed
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 225 226 227 228

/*
	This code is stolen from Pango 1.4. It attempts to address the following problems:

	http://bugzilla.gnome.org/show_bug.cgi?id=135098
	http://sourceforge.net/tracker/index.php?func=detail&aid=895762&group_id=76416&atid=547655

	As Owen suggested in bug 135098, once Pango 1.6 is released, we need to get rid of this code.
*/

#define PING(printlist)

/* TrueType defines: */

#define MAKE_TT_TABLE_NAME(c1, c2, c3, c4) \
   (((guint32)c4) << 24 | ((guint32)c3) << 16 | ((guint32)c2) << 8 | ((guint32)c1))

#define CMAP (MAKE_TT_TABLE_NAME('c','m','a','p'))
#define CMAP_HEADER_SIZE 4

#define NAME (MAKE_TT_TABLE_NAME('n','a','m','e'))
#define NAME_HEADER_SIZE 6

#define ENCODING_TABLE_SIZE 8

#define APPLE_UNICODE_PLATFORM_ID 0
#define MACINTOSH_PLATFORM_ID 1
#define ISO_PLATFORM_ID 2
#define MICROSOFT_PLATFORM_ID 3

#define SYMBOL_ENCODING_ID 0
#define UNICODE_ENCODING_ID 1
#define UCS4_ENCODING_ID 10

struct name_header
{
229 230 231
    guint16 format_selector;
    guint16 num_records;
    guint16 string_storage_offset;
cinamod's avatar
cinamod committed
232 233 234 235
};

struct name_record
{
236 237 238 239 240 241
    guint16 platform_id;
    guint16 encoding_id;
    guint16 language_id;
    guint16 name_id;
    guint16 string_length;
    guint16 string_offset;
cinamod's avatar
cinamod committed
242 243
};

244
static gboolean
245
pango_win32_get_name_header (HDC hdc, struct name_header *header)
cinamod's avatar
cinamod committed
246
{
247 248 249
    if (GetFontData (hdc, NAME, 0, header, sizeof (*header)) !=
	sizeof (*header))
	return FALSE;
cinamod's avatar
cinamod committed
250

251 252 253
    header->num_records = GUINT16_FROM_BE (header->num_records);
    header->string_storage_offset =
	GUINT16_FROM_BE (header->string_storage_offset);
cinamod's avatar
cinamod committed
254

255
    return TRUE;
cinamod's avatar
cinamod committed
256 257
}

258
static gboolean
259
pango_win32_get_name_record (HDC hdc, gint i, struct name_record *record)
cinamod's avatar
cinamod committed
260
{
261 262 263
    if (GetFontData (hdc, NAME, 6 + i * sizeof (*record),
		     record, sizeof (*record)) != sizeof (*record))
	return FALSE;
cinamod's avatar
cinamod committed
264

265 266 267 268 269 270
    record->platform_id = GUINT16_FROM_BE (record->platform_id);
    record->encoding_id = GUINT16_FROM_BE (record->encoding_id);
    record->language_id = GUINT16_FROM_BE (record->language_id);
    record->name_id = GUINT16_FROM_BE (record->name_id);
    record->string_length = GUINT16_FROM_BE (record->string_length);
    record->string_offset = GUINT16_FROM_BE (record->string_offset);
cinamod's avatar
cinamod committed
271

272
    return TRUE;
cinamod's avatar
cinamod committed
273 274 275
}

static gchar *
276
get_family_name (LOGFONT * lfp, HDC pango_win32_hdc)
cinamod's avatar
cinamod committed
277
{
278 279
    HFONT hfont;
    HFONT oldhfont;
cinamod's avatar
cinamod committed
280

281 282
    struct name_header header;
    struct name_record record;
cinamod's avatar
cinamod committed
283

284 285 286
    gint unicode_ix = -1, mac_ix = -1, microsoft_ix = -1;
    gint name_ix;
    gchar *codeset;
cinamod's avatar
cinamod committed
287

288 289
    gchar *string = NULL;
    gchar *name;
cinamod's avatar
cinamod committed
290

291
    size_t i, l, nbytes;
cinamod's avatar
cinamod committed
292

293 294 295 296 297 298 299 300
    /* If lfFaceName is ASCII, assume it is the common (English) name for the 
       font. Is this valid? Do some TrueType fonts have different names in
       French, German, etc, and does the system return these if the locale is 
       set to use French, German, etc? */
    l = strlen (lfp->lfFaceName);
    for (i = 0; i < l; i++)
	if (lfp->lfFaceName[i] < ' ' || lfp->lfFaceName[i] > '~')
	    break;
cinamod's avatar
cinamod committed
301

302 303
    if (i == l)
	return g_strdup (lfp->lfFaceName);
cinamod's avatar
cinamod committed
304

305 306
    if ((hfont = CreateFontIndirect (lfp)) == NULL)
	goto fail0;
cinamod's avatar
cinamod committed
307

308 309
    if ((oldhfont = (HFONT) SelectObject (pango_win32_hdc, hfont)) == NULL)
	goto fail1;
cinamod's avatar
cinamod committed
310

311 312
    if (!pango_win32_get_name_header (pango_win32_hdc, &header))
	goto fail2;
cinamod's avatar
cinamod committed
313

314
    PING (("%d name records", header.num_records));
cinamod's avatar
cinamod committed
315

316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    for (i = 0; i < header.num_records; i++)
	{
	    if (!pango_win32_get_name_record (pango_win32_hdc, i, &record))
		goto fail2;

	    if ((record.name_id != 1 && record.name_id != 16)
		|| record.string_length <= 0)
		continue;

	    PING (("platform:%d encoding:%d language:%04x name_id:%d",
		   record.platform_id, record.encoding_id, record.language_id,
		   record.name_id));

	    if (record.platform_id == APPLE_UNICODE_PLATFORM_ID ||
		record.platform_id == ISO_PLATFORM_ID)
		unicode_ix = i;
	    else if (record.platform_id == MACINTOSH_PLATFORM_ID && record.encoding_id == 0 &&	/* Roman 
												 */
		     record.language_id == 0)	/* English */
		mac_ix = i;
	    else if (record.platform_id == MICROSOFT_PLATFORM_ID)
		if ((microsoft_ix == -1 ||
		     PRIMARYLANGID (record.language_id) == LANG_ENGLISH) &&
		    (record.encoding_id == SYMBOL_ENCODING_ID ||
		     record.encoding_id == UNICODE_ENCODING_ID ||
		     record.encoding_id == UCS4_ENCODING_ID))
		    microsoft_ix = i;
	}
cinamod's avatar
cinamod committed
344

345 346 347 348 349 350
    if (microsoft_ix >= 0)
	name_ix = microsoft_ix;
    else if (mac_ix >= 0)
	name_ix = mac_ix;
    else if (unicode_ix >= 0)
	name_ix = unicode_ix;
cinamod's avatar
cinamod committed
351
    else
352
	goto fail2;
cinamod's avatar
cinamod committed
353

354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    if (!pango_win32_get_name_record (pango_win32_hdc, name_ix, &record))
	goto fail2;

    string = g_malloc (record.string_length + 1);
    if (GetFontData (pango_win32_hdc, NAME,
		     header.string_storage_offset + record.string_offset,
		     string, record.string_length) != record.string_length)
	goto fail2;

    string[record.string_length] = '\0';

    if (name_ix == microsoft_ix)
	if (record.encoding_id == SYMBOL_ENCODING_ID ||
	    record.encoding_id == UNICODE_ENCODING_ID)
	    codeset = "UTF-16BE";
	else
	    codeset = "UCS-4BE";
    else if (name_ix == mac_ix)
	codeset = "MacRoman";
    else			/* name_ix == unicode_ix */
	codeset = "UCS-4BE";

    name =
	g_convert (string, record.string_length, "UTF-8", codeset, NULL,
		   &nbytes, NULL);
    if (name == NULL)
	goto fail2;
    g_free (string);
cinamod's avatar
cinamod committed
382

383
    PING (("%s", name));
cinamod's avatar
cinamod committed
384

385 386
    SelectObject (pango_win32_hdc, oldhfont);
    DeleteObject (hfont);
cinamod's avatar
cinamod committed
387

388
    return name;
cinamod's avatar
cinamod committed
389

390 391 392
  fail2:
    g_free (string);
    SelectObject (pango_win32_hdc, oldhfont);
cinamod's avatar
cinamod committed
393

394 395
  fail1:
    DeleteObject (hfont);
cinamod's avatar
cinamod committed
396

397 398
  fail0:
    return g_locale_to_utf8 (lfp->lfFaceName, -1, NULL, NULL, NULL);
cinamod's avatar
cinamod committed
399 400
}

401
/***************************** END STOLEN FROM PANGO *****************************/
cinamod's avatar
cinamod committed
402

cinamod's avatar
cinamod committed
403
static char *
404 405
sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char *buf,
			size_t bufsiz)
406
{
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
    HDC hDC;
    HWND hwnd;
    LOGFONT lf;
    int pt_size;
    const char *weight;
    const char *style;
    char *font;

    if (get_system_font (klazz, type, &lf))
	{
	    switch (lf.lfWeight)
		{
		case FW_THIN:
		case FW_EXTRALIGHT:
		    weight = "Ultra-Light";
		    break;

		case FW_LIGHT:
		    weight = "Light";
		    break;

		case FW_BOLD:
		    weight = "Bold";
		    break;

		case FW_SEMIBOLD:
		    weight = "Semi-Bold";
		    break;

		case FW_ULTRABOLD:
		    weight = "Ultra-Bold";
		    break;

		case FW_HEAVY:
		    weight = "Heavy";
		    break;

		default:
		    weight = "";
		    break;
		}

	    if (lf.lfItalic)
		style = "Italic";
	    else
		style = "";

	    hwnd = GetDesktopWindow ();
	    hDC = GetDC (hwnd);
	    if (hDC)
		{
		    pt_size = -MulDiv (lf.lfHeight, 72,
				       GetDeviceCaps (hDC, LOGPIXELSY));
		    ReleaseDC (hwnd, hDC);
		}
	    else
cinamod's avatar
cinamod committed
463
		pt_size = 10;
cinamod's avatar
cinamod committed
464

465 466 467 468
	    font = get_family_name (&lf, hDC);
	    g_snprintf (buf, bufsiz, "%s %s %s %d", font, style, weight,
			pt_size);
	    g_free (font);
cinamod's avatar
cinamod committed
469

470 471
	    return buf;
	}
cinamod's avatar
cinamod committed
472

473
    return NULL;
cinamod's avatar
cinamod committed
474 475
}

cinamod's avatar
cinamod committed
476 477 478 479 480
/* missing from ms's header files */
#ifndef SPI_GETMENUSHOWDELAY
#define SPI_GETMENUSHOWDELAY 106
#endif

cinamod's avatar
cinamod committed
481 482 483 484
/* I don't know the proper XP theme class for things like
   HIGHLIGHTTEXT, so we'll just define it to be "BUTTON"
   for now */
#define XP_THEME_CLASS_TEXT XP_THEME_CLASS_BUTTON
cinamod's avatar
cinamod committed
485

cinamod's avatar
cinamod committed
486
static void
cinamod's avatar
cinamod committed
487
setup_menu_settings (GtkSettings * settings)
cinamod's avatar
cinamod committed
488
{
489 490 491 492 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 522 523 524 525 526 527 528 529 530 531 532 533
    int menu_delay;
    gboolean win95 = FALSE;
    OSVERSIONINFOEX osvi;
    GObjectClass *klazz = G_OBJECT_GET_CLASS (G_OBJECT (settings));

    ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);

    if (!GetVersionEx ((OSVERSIONINFO *) & osvi))
	win95 = TRUE;		/* assume the worst */

    if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
	if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
	    win95 = TRUE;

    if (!win95)
	{
	    if (SystemParametersInfo
		(SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0))
		{
		    if (klazz)
			{
			    if (g_object_class_find_property
				(klazz, "gtk-menu-bar-popup-delay"))
				{
				    g_object_set (settings,
						  "gtk-menu-bar-popup-delay",
						  0, NULL);
				}
			    if (g_object_class_find_property
				(klazz, "gtk-menu-popup-delay"))
				{
				    g_object_set (settings,
						  "gtk-menu-popup-delay",
						  menu_delay, NULL);
				}
			    if (g_object_class_find_property
				(klazz, "gtk-menu-popdown-delay"))
				{
				    g_object_set (settings,
						  "gtk-menu-popdown-delay",
						  menu_delay, NULL);
				}
			}
		}
cinamod's avatar
cinamod committed
534 535 536
	}
}

537
void
538
msw_style_setup_system_settings (void)
cinamod's avatar
cinamod committed
539
{
540 541
    GtkSettings *settings;
    int cursor_blink_time;
cinamod's avatar
cinamod committed
542

543 544 545
    settings = gtk_settings_get_default ();
    if (!settings)
	return;
cinamod's avatar
cinamod committed
546

547 548
    cursor_blink_time = GetCaretBlinkTime ();
    g_object_set (settings, "gtk-cursor-blink", cursor_blink_time > 0, NULL);
cinamod's avatar
cinamod committed
549

550 551 552
    if (cursor_blink_time > 0)
	g_object_set (settings, "gtk-cursor-blink-time",
		      2 * cursor_blink_time, NULL);
cinamod's avatar
cinamod committed
553

554 555 556 557 558 559
    g_object_set (settings, "gtk-double-click-distance",
		  GetSystemMetrics (SM_CXDOUBLECLK), NULL);
    g_object_set (settings, "gtk-double-click-time", GetDoubleClickTime (),
		  NULL);
    g_object_set (settings, "gtk-dnd-drag-threshold",
		  GetSystemMetrics (SM_CXDRAG), NULL);
cinamod's avatar
cinamod committed
560

561
    setup_menu_settings (settings);
cinamod's avatar
cinamod committed
562

563 564 565 566
    /* 
       http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
       http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
       http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp */
cinamod's avatar
cinamod committed
567 568
}

cinamod's avatar
cinamod committed
569
static void
570
setup_system_font (GtkStyle * style)
cinamod's avatar
cinamod committed
571
{
572 573
    char buf[256], *font;	/* It's okay, lfFaceName is smaller than 32
				   chars */
cinamod's avatar
cinamod committed
574

575 576 577 578 579 580
    if ((font = sys_font_to_pango_font (XP_THEME_CLASS_TEXT,
					XP_THEME_FONT_MESSAGE,
					buf, sizeof (buf))) != NULL)
	{
	    if (style->font_desc)
		pango_font_description_free (style->font_desc);
cinamod's avatar
cinamod committed
581

582 583
	    style->font_desc = pango_font_description_from_string (font);
	}
584 585 586
}

static void
587
sys_color_to_gtk_color (XpThemeClass klazz, int id, GdkColor * pcolor)
588
{
589
    DWORD color;
cinamod's avatar
cinamod committed
590

591 592
    if (!xp_theme_get_system_color (klazz, id, &color))
	color = GetSysColor (id);
cinamod's avatar
cinamod committed
593

594 595 596 597
    pcolor->pixel = color;
    pcolor->red = (GetRValue (color) << 8) | GetRValue (color);
    pcolor->green = (GetGValue (color) << 8) | GetGValue (color);
    pcolor->blue = (GetBValue (color) << 8) | GetBValue (color);
598 599
}

cinamod's avatar
cinamod committed
600
static int
601
get_system_metric (XpThemeClass klazz, int id)
cinamod's avatar
cinamod committed
602
{
603
    int rval;
cinamod's avatar
cinamod committed
604

605 606
    if (!xp_theme_get_system_metric (klazz, id, &rval))
	rval = GetSystemMetrics (id);
cinamod's avatar
cinamod committed
607

608
    return rval;
cinamod's avatar
cinamod committed
609 610
}

611
static void
612
setup_msw_rc_style (void)
613
{
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 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 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
    char buf[1024], font_buf[256], *font_ptr;

    GdkColor menu_color;
    GdkColor menu_text_color;
    GdkColor tooltip_back;
    GdkColor tooltip_fore;
    GdkColor btn_fore;
    GdkColor btn_face;
    GdkColor progress_back;

    GdkColor fg_prelight;
    GdkColor bg_prelight;
    GdkColor base_prelight;
    GdkColor text_prelight;

    /* Prelight */
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
			    &fg_prelight);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
			    &bg_prelight);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
			    &base_prelight);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
			    &text_prelight);

    sys_color_to_gtk_color (XP_THEME_CLASS_MENU, COLOR_MENUTEXT,
			    &menu_text_color);
    sys_color_to_gtk_color (XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);

    /* tooltips */
    sys_color_to_gtk_color (XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT,
			    &tooltip_fore);
    sys_color_to_gtk_color (XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK,
			    &tooltip_back);

    /* text on push buttons. TODO: button shadows, backgrounds, and
       highlights */
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);

    /* progress bar background color */
    sys_color_to_gtk_color (XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT,
			    &progress_back);

    /* Enable coloring for menus. */
    font_ptr =
	sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,
				font_buf, sizeof (font_buf));
    g_snprintf (buf, sizeof (buf),
		"style \"msw-menu\" = \"msw-default\"\n" "{\n"
		"fg[PRELIGHT] = { %d, %d, %d }\n"
		"bg[PRELIGHT] = { %d, %d, %d }\n"
		"text[PRELIGHT] = { %d, %d, %d }\n"
		"base[PRELIGHT] = { %d, %d, %d }\n"
		"fg[NORMAL] = { %d, %d, %d }\n"
		"bg[NORMAL] = { %d, %d, %d }\n" "%s = \"%s\"\n"
		"}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
		"widget_class \"*GtkMenu\" style \"msw-menu\"\n"
		"widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
		fg_prelight.red, fg_prelight.green, fg_prelight.blue,
		bg_prelight.red, bg_prelight.green, bg_prelight.blue,
		text_prelight.red, text_prelight.green, text_prelight.blue,
		base_prelight.red, base_prelight.green, base_prelight.blue,
		menu_text_color.red, menu_text_color.green,
		menu_text_color.blue, menu_color.red, menu_color.green,
		menu_color.blue, (font_ptr ? "font_name" : "#"),
		(font_ptr ? font_ptr : " font name should go here"));
    gtk_rc_parse_string (buf);

    /* Enable coloring for menu bars. */
    g_snprintf (buf, sizeof (buf),
		"style \"msw-menu-bar\" = \"msw-menu\"\n"
		"{\n"
		"bg[NORMAL] = { %d, %d, %d }\n"
		"GtkMenuBar::shadow-type = %s\n"
		"}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
		btn_face.red, btn_face.green, btn_face.blue, "etched-in");
    gtk_rc_parse_string (buf);

    g_snprintf (buf, sizeof (buf),
		"style \"msw-toolbar\" = \"msw-default\"\n"
		"{\n"
		"GtkHandleBox::shadow-type = %s\n"
		"GtkToolbar::shadow-type = %s\n"
		"}widget_class \"*HandleBox*\" style \"msw-toolbar\"\n",
		"etched-in", "etched-in");
    gtk_rc_parse_string (buf);

    /* enable tooltip fonts */
    font_ptr =
	sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,
				font_buf, sizeof (font_buf));
    g_snprintf (buf, sizeof (buf),
		"style \"msw-tooltips-caption\" = \"msw-default\"\n"
		"{fg[NORMAL] = { %d, %d, %d }\n" "%s = \"%s\"\n"
		"}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
		tooltip_fore.red, tooltip_fore.green, tooltip_fore.blue,
		(font_ptr ? "font_name" : "#"),
		(font_ptr ? font_ptr : " font name should go here"));
    gtk_rc_parse_string (buf);

    g_snprintf (buf, sizeof (buf),
		"style \"msw-tooltips\" = \"msw-default\"\n"
		"{bg[NORMAL] = { %d, %d, %d }\n"
		"}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
		tooltip_back.red, tooltip_back.green, tooltip_back.blue);
    gtk_rc_parse_string (buf);

    /* enable font theming for status bars */
    font_ptr =
	sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,
				font_buf, sizeof (font_buf));
    g_snprintf (buf, sizeof (buf),
		"style \"msw-status\" = \"msw-default\"\n" "{%s = \"%s\"\n"
		"bg[NORMAL] = { %d, %d, %d }\n"
		"}widget_class \"*Status*\" style \"msw-status\"\n",
		(font_ptr ? "font_name" : "#"),
		(font_ptr ? font_ptr : " font name should go here"),
		btn_face.red, btn_face.green, btn_face.blue);
    gtk_rc_parse_string (buf);

    /* enable coloring for text on buttons TODO: use GetThemeMetric for the
       border and outside border */
    g_snprintf (buf, sizeof (buf),
		"style \"msw-button\" = \"msw-default\"\n"
		"{\n"
		"bg[NORMAL] = { %d, %d, %d }\n"
		"bg[PRELIGHT] = { %d, %d, %d }\n"
		"bg[INSENSITIVE] = { %d, %d, %d }\n"
		"fg[PRELIGHT] = { %d, %d, %d }\n"
		"GtkButton::default-border = { 1, 1, 1, 1 }\n"
		"GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
		"GtkButton::child-displacement-x = 1\n"
		"GtkButton::child-displacement-y = 1\n"
		"}widget_class \"*Button*\" style \"msw-button\"\n",
		btn_face.red, btn_face.green, btn_face.blue,
		btn_face.red, btn_face.green, btn_face.blue,
		btn_face.red, btn_face.green, btn_face.blue,
		btn_fore.red, btn_fore.green, btn_fore.blue);
    gtk_rc_parse_string (buf);

    /* enable coloring for progress bars */
    g_snprintf (buf, sizeof (buf),
		"style \"msw-progress\" = \"msw-default\"\n"
		"{bg[PRELIGHT] = { %d, %d, %d }\n"
		"bg[NORMAL] = { %d, %d, %d }\n"
		"}widget_class \"*Progress*\" style \"msw-progress\"\n",
		progress_back.red,
		progress_back.green,
		progress_back.blue,
		btn_face.red, btn_face.green, btn_face.blue);
    gtk_rc_parse_string (buf);

    /* scrollbar thumb width and height */
    g_snprintf (buf, sizeof (buf),
		"style \"msw-vscrollbar\" = \"msw-default\"\n"
		"{GtkRange::slider-width = %d\n"
		"GtkRange::stepper-size = %d\n"
		"GtkRange::stepper-spacing = 0\n"
		"GtkRange::trough_border = 0\n"
		"GtkScale::slider-length = %d\n"
		"GtkScrollbar::min-slider-length = 8\n"
		"}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n"
		"widget_class \"*VScale*\" style \"msw-vscrollbar\"\n",
		GetSystemMetrics (SM_CYVTHUMB),
		get_system_metric (XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL),
		11);
    gtk_rc_parse_string (buf);

    g_snprintf (buf, sizeof (buf),
		"style \"msw-hscrollbar\" = \"msw-default\"\n"
		"{GtkRange::slider-width = %d\n"
		"GtkRange::stepper-size = %d\n"
		"GtkRange::stepper-spacing = 0\n"
		"GtkRange::trough_border = 0\n"
		"GtkScale::slider-length = %d\n"
		"GtkScrollbar::min-slider-length = 8\n"
		"}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n"
		"widget_class \"*HScale*\" style \"msw-hscrollbar\"\n",
		GetSystemMetrics (SM_CXHTHUMB),
		get_system_metric (XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL),
		11);
    gtk_rc_parse_string (buf);

    /* radio/check button sizes */
    g_snprintf (buf, sizeof (buf),
		"style \"msw-checkbutton\" = \"msw-button\"\n"
		"{GtkCheckButton::indicator-size = 13\n"
		"}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
		"widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
    gtk_rc_parse_string (buf);
Raymond Penners's avatar
Raymond Penners committed
805
}
806

cinamod's avatar
cinamod committed
807
static void
808
setup_system_styles (GtkStyle * style)
cinamod's avatar
cinamod committed
809
{
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
    int i;

    /* Default background */
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
			    &style->bg[GTK_STATE_NORMAL]);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
			    &style->bg[GTK_STATE_SELECTED]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
			    &style->bg[GTK_STATE_INSENSITIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
			    &style->bg[GTK_STATE_ACTIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
			    &style->bg[GTK_STATE_PRELIGHT]);

    /* Default base */
    sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOW,
			    &style->base[GTK_STATE_NORMAL]);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
			    &style->base[GTK_STATE_SELECTED]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
			    &style->base[GTK_STATE_INSENSITIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
			    &style->base[GTK_STATE_ACTIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOW,
			    &style->base[GTK_STATE_PRELIGHT]);

    /* Default text */
    sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT,
			    &style->text[GTK_STATE_NORMAL]);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
			    &style->text[GTK_STATE_SELECTED]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_GRAYTEXT,
			    &style->text[GTK_STATE_INSENSITIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT,
			    &style->text[GTK_STATE_ACTIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT,
			    &style->text[GTK_STATE_PRELIGHT]);

    /* Default foreground */
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT,
			    &style->fg[GTK_STATE_NORMAL]);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
			    &style->fg[GTK_STATE_SELECTED]);
    sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_GRAYTEXT,
			    &style->fg[GTK_STATE_INSENSITIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT,
			    &style->fg[GTK_STATE_ACTIVE]);
    sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT,
			    &style->fg[GTK_STATE_PRELIGHT]);

    for (i = 0; i < 5; i++)
	{
	    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW,
				    &style->dark[i]);
	    sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT,
				    &style->light[i]);

	    style->mid[i].red =
		(style->light[i].red + style->dark[i].red) / 2;
	    style->mid[i].green =
		(style->light[i].green + style->dark[i].green) / 2;
	    style->mid[i].blue =
		(style->light[i].blue + style->dark[i].blue) / 2;

	    style->text_aa[i].red =
		(style->text[i].red + style->base[i].red) / 2;
	    style->text_aa[i].green =
		(style->text[i].green + style->base[i].green) / 2;
	    style->text_aa[i].blue =
		(style->text[i].blue + style->base[i].blue) / 2;
	}
cinamod's avatar
cinamod committed
881 882
}

Raymond Penners's avatar
Raymond Penners committed
883
static gboolean
884
sanitize_size (GdkWindow * window, gint * width, gint * height)
885
{
886 887 888 889 890 891 892 893 894 895 896 897 898
    gboolean set_bg = FALSE;

    if ((*width == -1) && (*height == -1))
	{
	    set_bg = GDK_IS_WINDOW (window);
	    gdk_drawable_get_size (window, width, height);
	}
    else if (*width == -1)
	gdk_drawable_get_size (window, width, NULL);
    else if (*height == -1)
	gdk_drawable_get_size (window, NULL, height);

    return set_bg;
899 900
}

Raymond Penners's avatar
Raymond Penners committed
901
static XpThemeElement
902
map_gtk_progress_bar_to_xp (GtkProgressBar * progress_bar, gboolean trough)
Raymond Penners's avatar
Raymond Penners committed
903
{
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
    XpThemeElement ret;

    switch (progress_bar->orientation)
	{
	case GTK_PROGRESS_LEFT_TO_RIGHT:
	case GTK_PROGRESS_RIGHT_TO_LEFT:
	    ret = trough
		? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
		: XP_THEME_ELEMENT_PROGRESS_BAR_H;
	    break;
	default:
	    ret = trough
		? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
		: XP_THEME_ELEMENT_PROGRESS_BAR_V;
	    break;
	}
    return ret;
Raymond Penners's avatar
Raymond Penners committed
921 922
}

923
static void
924 925
draw_part (GdkDrawable * drawable,
	   GdkGC * gc, GdkRectangle * area, gint x, gint y, Part part)
926
{
927 928
    if (area)
	gdk_gc_set_clip_rectangle (gc, area);
Raymond Penners's avatar
Raymond Penners committed
929

930 931 932 933
    if (!parts[part].bmap)
	parts[part].bmap = gdk_bitmap_create_from_data (drawable,
							parts[part].bits,
							PART_SIZE, PART_SIZE);
934

935 936 937
    gdk_gc_set_ts_origin (gc, x, y);
    gdk_gc_set_stipple (gc, parts[part].bmap);
    gdk_gc_set_fill (gc, GDK_STIPPLED);
938

939
    gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
940

941
    gdk_gc_set_fill (gc, GDK_SOLID);
942

943 944
    if (area)
	gdk_gc_set_clip_rectangle (gc, NULL);
945 946 947
}

static void
948 949 950 951 952 953 954
draw_check (GtkStyle * style,
	    GdkWindow * window,
	    GtkStateType state,
	    GtkShadowType shadow,
	    GdkRectangle * area,
	    GtkWidget * widget,
	    const gchar * detail, gint x, gint y, gint width, gint height)
955
{
956 957
    x -= (1 + PART_SIZE - width) / 2;
    y -= (1 + PART_SIZE - height) / 2;
Raymond Penners's avatar
Raymond Penners committed
958

959
    if (detail && strcmp (detail, "check") == 0)	/* Menu item */
960
	{
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
	    if (shadow == GTK_SHADOW_IN)
		{
		    draw_part (window, style->black_gc, area, x, y,
			       CHECK_TEXT);
		    draw_part (window, style->dark_gc[state], area, x, y,
			       CHECK_AA);
		}
	}
    else
	{
	    if (!xp_theme_draw (window, shadow == GTK_SHADOW_IN
				? XP_THEME_ELEMENT_PRESSED_CHECKBOX
				: XP_THEME_ELEMENT_CHECKBOX,
				style, x, y, width, height, state, area))
		{
		    draw_part (window, style->black_gc, area, x, y,
			       CHECK_BLACK);
		    draw_part (window, style->dark_gc[state], area, x, y,
			       CHECK_DARK);
		    draw_part (window, style->mid_gc[state], area, x, y,
			       CHECK_MID);
		    draw_part (window, style->light_gc[state], area, x, y,
			       CHECK_LIGHT);
		    draw_part (window, style->base_gc[state], area, x, y,
			       CHECK_BASE);

		    if (shadow == GTK_SHADOW_IN)
			{
			    draw_part (window, style->text_gc[state], area, x,
				       y, CHECK_TEXT);
			    draw_part (window, style->text_aa_gc[state], area,
				       x, y, CHECK_AA);
			}
		}
995 996 997 998
	}
}

static void
999 1000 1001 1002 1003 1004 1005
draw_expander (GtkStyle * style,
	       GdkWindow * window,
	       GtkStateType state,
	       GdkRectangle * area,
	       GtkWidget * widget,
	       const gchar * detail,
	       gint x, gint y, GtkExpanderStyle expander_style)
1006
{
1007 1008 1009 1010 1011 1012 1013 1014
    gint expander_size;
    gint expander_semi_size;
    GdkColor color;
    GdkGCValues values;
    gboolean success;
    XpThemeElement xp_expander;

    gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
1015

1016 1017 1018 1019 1020 1021
    switch (expander_style)
	{
	case GTK_EXPANDER_COLLAPSED:
	case GTK_EXPANDER_SEMI_COLLAPSED:
	    xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
	    break;
1022
	default:
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
	    xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
	    break;
	}

    if ((expander_size % 2) == 0)
	expander_size--;

    if (expander_size > 2)
	expander_size -= 2;

    if (area)
	gdk_gc_set_clip_rectangle (style->fg_gc[state], area);

    expander_semi_size = expander_size / 2;
    x -= expander_semi_size;
    y -= expander_semi_size;

    gdk_gc_get_values (style->fg_gc[state], &values);

    if (!xp_theme_draw (window, xp_expander, style,
			x, y, expander_size, expander_size, state, area))
	{
	    /* RGB values to emulate Windows Classic style */
	    color.red = color.green = color.blue = 128 << 8;
cinamod's avatar
cinamod committed
1047

1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
	    success = gdk_colormap_alloc_color
		(gtk_widget_get_default_colormap (), &color, FALSE, TRUE);

	    if (success)
		gdk_gc_set_foreground (style->fg_gc[state], &color);

	    gdk_draw_rectangle
		(window, style->fg_gc[state], FALSE, x, y,
		 expander_size - 1, expander_size - 1);

	    gdk_draw_line
		(window, style->fg_gc[state], x + 2, y + expander_semi_size,
		 x + expander_size - 2, y + expander_semi_size);

	    switch (expander_style)
		{
		case GTK_EXPANDER_COLLAPSED:
		case GTK_EXPANDER_SEMI_COLLAPSED:
		    gdk_draw_line
			(window, style->fg_gc[state], x + expander_semi_size,
			 y + 2, x + expander_semi_size,
			 y + expander_size - 2);
		    break;

		default:
		    break;
		}

	    if (success)
		gdk_gc_set_foreground (style->fg_gc[state],
				       &values.foreground);
	}
1080

1081 1082
    if (area)
	gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
1083 1084 1085
}

static void
1086 1087 1088 1089 1090 1091 1092
draw_option (GtkStyle * style,
	     GdkWindow * window,
	     GtkStateType state,
	     GtkShadowType shadow,
	     GdkRectangle * area,
	     GtkWidget * widget,
	     const gchar * detail, gint x, gint y, gint width, gint height)
1093
{
1094 1095 1096 1097
    x -= (1 + PART_SIZE - width) / 2;
    y -= (1 + PART_SIZE - height) / 2;

    if (detail && strcmp (detail, "option") == 0)	/* Menu item */
1098
	{
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
	    if (shadow == GTK_SHADOW_IN)
		draw_part (window, style->fg_gc[state], area, x, y,
			   RADIO_TEXT);
	}
    else
	{
	    if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
			       ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
			       : XP_THEME_ELEMENT_RADIO_BUTTON,
			       style, x, y, width, height, state, area))
		{
		}
	    else
		{
		    draw_part (window, style->black_gc, area, x, y,
			       RADIO_BLACK);
		    draw_part (window, style->dark_gc[state], area, x, y,
			       RADIO_DARK);
		    draw_part (window, style->mid_gc[state], area, x, y,
			       RADIO_MID);
		    draw_part (window, style->light_gc[state], area, x, y,
			       RADIO_LIGHT);
		    draw_part (window, style->base_gc[state], area, x, y,
			       RADIO_BASE);

		    if (shadow == GTK_SHADOW_IN)
			draw_part (window, style->text_gc[state], area, x, y,
				   RADIO_TEXT);
		}
1128 1129 1130 1131
	}
}

static void
1132 1133 1134 1135 1136
draw_varrow (GdkWindow * window,
	     GdkGC * gc,
	     GtkShadowType shadow_type,
	     GdkRectangle * area,
	     GtkArrowType arrow_type, gint x, gint y, gint width, gint height)
1137
{
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
    gint steps, extra;
    gint y_start, y_increment;
    gint i;

    if (area)
	gdk_gc_set_clip_rectangle (gc, area);

    width = width + width % 2 - 1;	/* Force odd */
    steps = 1 + width / 2;
    extra = height - steps;

    if (arrow_type == GTK_ARROW_DOWN)
	{
	    y_start = y;
	    y_increment = 1;
	}
    else
	{
	    y_start = y + height - 1;
	    y_increment = -1;
	}

    for (i = extra; i < height; i++)
	{
	    gdk_draw_line (window, gc,
			   x + (i - extra), y_start + i * y_increment,
			   x + width - (i - extra) - 1,
			   y_start + i * y_increment);
	}

    if (area)
	gdk_gc_set_clip_rectangle (gc, NULL);
1170 1171 1172
}

static void
1173 1174 1175 1176 1177
draw_harrow (GdkWindow * window,
	     GdkGC * gc,
	     GtkShadowType shadow_type,
	     GdkRectangle * area,
	     GtkArrowType arrow_type, gint x, gint y, gint width, gint height)
1178
{
1179 1180 1181
    gint steps, extra;
    gint x_start, x_increment;
    gint i;
Raymond Penners's avatar
Raymond Penners committed
1182

1183 1184
    if (area)
	gdk_gc_set_clip_rectangle (gc, area);
Raymond Penners's avatar
Raymond Penners committed
1185

1186 1187 1188
    height = height + height % 2 - 1;	/* Force odd */
    steps = 1 + height / 2;
    extra = width - steps;
1189

1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
    if (arrow_type == GTK_ARROW_RIGHT)
	{
	    x_start = x;
	    x_increment = 1;
	}
    else
	{
	    x_start = x + width - 1;
	    x_increment = -1;
	}
1200

1201 1202 1203 1204 1205 1206 1207
    for (i = extra; i < width; i++)
	{
	    gdk_draw_line (window, gc,
			   x_start + i * x_increment, y + (i - extra),
			   x_start + i * x_increment,
			   y + height - (i - extra) - 1);
	}
Raymond Penners's avatar
Raymond Penners committed
1208

1209

1210 1211
    if (area)
	gdk_gc_set_clip_rectangle (gc, NULL);
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
}

/* This function makes up for some brokeness in gtkrange.c
 * where we never get the full arrow of the stepper button
 * and the type of button in a single drawing function.
 *
 * It doesn't work correctly when the scrollbar is squished
 * to the point we don't have room for full-sized steppers.
 */
static void
1222 1223 1224
reverse_engineer_stepper_box (GtkWidget * range,
			      GtkArrowType arrow_type