msw_style.c 55.8 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
#include "msw_style.h"
Raymond Penners's avatar
Raymond Penners committed
24
#include "xp_theme.h"
25 26 27 28 29 30

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

31 32 33 34 35
#include "gtk/gtk.h"
#include "gtk/gtk.h"
#include "gdk/win32/gdkwin32.h"


36 37
/* Default values, not normally used
 */
cinamod's avatar
cinamod committed
38 39
static const GtkRequisition default_option_indicator_size = { 9, 8 };
static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

static GtkStyleClass *parent_class;

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
} Part;

#define PART_SIZE 13

cinamod's avatar
cinamod committed
61
static const char check_aa_bits[] = {
62 63
 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};
cinamod's avatar
cinamod committed
64
static const char check_base_bits[] = {
65 66
 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};
cinamod's avatar
cinamod committed
67
static const char check_black_bits[] = {
68 69
 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};
cinamod's avatar
cinamod committed
70
static const char check_dark_bits[] = {
71 72
 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};
cinamod's avatar
cinamod committed
73
static const char check_light_bits[] = {
74 75
 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};
cinamod's avatar
cinamod committed
76
static const char check_mid_bits[] = {
77 78
 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};
cinamod's avatar
cinamod committed
79
static const char check_text_bits[] = {
80 81
 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};
cinamod's avatar
cinamod committed
82
static const char radio_base_bits[] = {
83 84
 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};
cinamod's avatar
cinamod committed
85
static const char radio_black_bits[] = {
86 87
 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};
cinamod's avatar
cinamod committed
88
static const char radio_dark_bits[] = {
89 90
 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};
cinamod's avatar
cinamod committed
91
static const char radio_light_bits[] = {
92 93
 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};
cinamod's avatar
cinamod committed
94
static const char radio_mid_bits[] = {
95 96
 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};
cinamod's avatar
cinamod committed
97
static const char radio_text_bits[] = {
98 99 100 101
 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 {
cinamod's avatar
cinamod committed
102 103
  const char *bits;
  GdkBitmap  *bmap;
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
} 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 }
};

static gboolean
cinamod's avatar
cinamod committed
121
get_system_font(XpThemeClass klazz, XpThemeFont type, LOGFONT *out_lf)
122
{
cinamod's avatar
cinamod committed
123 124
#if 0
  /* TODO: this crashes. need to figure out why and how to fix it */
cinamod's avatar
cinamod committed
125 126 127
  if (xp_theme_get_system_font(klazz, type, out_lf))
    return TRUE;
  else
cinamod's avatar
cinamod committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
#endif
  {
	  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;
	    }
  }
cinamod's avatar
cinamod committed
148
  return FALSE;
149 150
}

cinamod's avatar
cinamod committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 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 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
/***************************** STOLEN FROM PANGO *****************************/

/*
	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
{
  guint16 format_selector;
  guint16 num_records;
  guint16 string_storage_offset;
};

struct name_record
{
  guint16 platform_id;
  guint16 encoding_id;
  guint16 language_id;
  guint16 name_id;
  guint16 string_length;
  guint16 string_offset;
};

gboolean
pango_win32_get_name_header (HDC                 hdc,
			     struct name_header *header)
{
  if (GetFontData (hdc, NAME, 0, header, sizeof (*header)) != sizeof (*header))
    return FALSE;

  header->num_records = GUINT16_FROM_BE (header->num_records);
  header->string_storage_offset = GUINT16_FROM_BE (header->string_storage_offset);

  return TRUE;
}

gboolean
pango_win32_get_name_record (HDC                 hdc,
			     gint                i,
			     struct name_record *record)
{
  if (GetFontData (hdc, NAME, 6 + i * sizeof (*record),
		   record, sizeof (*record)) != sizeof (*record))
    return FALSE;

  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);

  return TRUE;
}

static gchar *
get_family_name (LOGFONT *lfp, HDC pango_win32_hdc)
{
  HFONT hfont;
  HFONT oldhfont;

  struct name_header header;
  struct name_record record;

  gint unicode_ix = -1, mac_ix = -1, microsoft_ix = -1;
  gint name_ix;
  gchar *codeset;

  gchar *string = NULL;
  gchar *name;

  gint i, l;
  gsize nbytes;

  /* 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;

  if (i == l)
    return g_strdup (lfp->lfFaceName);

  if ((hfont = CreateFontIndirect (lfp)) == NULL)
    goto fail0;

  if ((oldhfont = SelectObject (pango_win32_hdc, hfont)) == NULL)
    goto fail1;

  if (!pango_win32_get_name_header (pango_win32_hdc, &header))
    goto fail2;

  PING (("%d name records", header.num_records));

  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;
    }

  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;
  else
    goto fail2;

  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);

  PING(("%s", name));

  SelectObject (pango_win32_hdc, oldhfont);
  DeleteObject (hfont);

  return name;

 fail2:
  g_free (string);
  SelectObject (pango_win32_hdc, oldhfont);

 fail1:
  DeleteObject (hfont);

 fail0:
  return g_locale_to_utf8 (lfp->lfFaceName, -1, NULL, NULL, NULL);
}

/***************************** STOLEN FROM PANGO *****************************/

cinamod's avatar
cinamod committed
361
static char *
cinamod's avatar
cinamod committed
362
sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char * buf, size_t bufsiz)
363
{
cinamod's avatar
cinamod committed
364 365
  HDC hDC;
  HWND hwnd;
366
  LOGFONT lf;
cinamod's avatar
cinamod committed
367
  int pt_size;
cinamod's avatar
cinamod committed
368 369
  const char * weight;
  const char * style;
cinamod's avatar
cinamod committed
370
  char * font;
cinamod's avatar
cinamod committed
371

cinamod's avatar
cinamod committed
372
  if (get_system_font(klazz, type, &lf))
373
    {
374 375 376
      switch (lf.lfWeight) {
      case FW_THIN:
      case FW_EXTRALIGHT:
cinamod's avatar
cinamod committed
377
	weight = "Ultra-Light";
378 379 380
	break;

      case FW_LIGHT:
cinamod's avatar
cinamod committed
381
	weight = "Light";
382 383 384
	break;

      case FW_BOLD:
cinamod's avatar
cinamod committed
385 386 387 388 389
	weight = "Bold";
	break;

      case FW_SEMIBOLD:
	weight = "Semi-Bold";
390 391 392
	break;

      case FW_ULTRABOLD:
cinamod's avatar
cinamod committed
393
	weight = "Ultra-Bold";
394 395 396
	break;

      case FW_HEAVY:
cinamod's avatar
cinamod committed
397 398
	weight = "Heavy";
	break;
399 400

      default:
cinamod's avatar
cinamod committed
401
	weight = "";
402 403 404 405
	break;
      }

      if (lf.lfItalic)
cinamod's avatar
cinamod committed
406
	style="Italic";
407
      else
cinamod's avatar
cinamod committed
408
	style="";
cinamod's avatar
cinamod committed
409

cinamod's avatar
cinamod committed
410 411 412 413 414 415 416 417
	hwnd = GetDesktopWindow();
	hDC = GetDC(hwnd);
	if (hDC) {
		pt_size = -MulDiv(lf.lfHeight, 72,
	                      GetDeviceCaps(hDC,LOGPIXELSY));
		ReleaseDC(hwnd, hDC);
	} else
		pt_size = 10;
cinamod's avatar
cinamod committed
418

cinamod's avatar
cinamod committed
419 420 421
	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
422 423 424

    return buf;
   }
cinamod's avatar
cinamod committed
425

426
  return NULL;
cinamod's avatar
cinamod committed
427 428
}

cinamod's avatar
cinamod committed
429 430 431 432 433
/* missing from ms's header files */
#ifndef SPI_GETMENUSHOWDELAY
#define SPI_GETMENUSHOWDELAY 106
#endif

cinamod's avatar
cinamod committed
434 435 436 437
/* 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
438

cinamod's avatar
cinamod committed
439
static void
cinamod's avatar
cinamod committed
440
setup_menu_settings (GtkSettings * settings)
cinamod's avatar
cinamod committed
441
{
442 443 444
  int menu_delay;
  gboolean win95 = FALSE;
  OSVERSIONINFOEX osvi;
cinamod's avatar
cinamod committed
445
  GObjectClass * klazz = G_OBJECT_GET_CLASS(G_OBJECT(settings));
cinamod's avatar
cinamod committed
446

447 448
  ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
cinamod's avatar
cinamod committed
449

450 451
  if (!GetVersionEx ( (OSVERSIONINFO *) &osvi))
    win95 = TRUE; /* assume the worst */
cinamod's avatar
cinamod committed
452

453 454 455
  if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
    if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
      win95 = TRUE;
cinamod's avatar
cinamod committed
456

457 458 459 460
  if (!win95) {
    if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0)) {
      if (klazz) {
	if (g_object_class_find_property (klazz, "gtk-menu-bar-popup-delay")) {
461
	  g_object_set (settings, "gtk-menu-bar-popup-delay", 0, NULL);
462 463
	}
	if (g_object_class_find_property (klazz, "gtk-menu-popup-delay")) {
464
	  g_object_set (settings, "gtk-menu-popup-delay", menu_delay, NULL);
465 466
	}
	if (g_object_class_find_property (klazz, "gtk-menu-popdown-delay")) {
467
	  g_object_set (settings, "gtk-menu-popdown-delay", menu_delay, NULL);
cinamod's avatar
cinamod committed
468
	}
469 470 471
      }
    }
  }
cinamod's avatar
cinamod committed
472 473
}

474
void
475
msw_style_setup_system_settings (void)
cinamod's avatar
cinamod committed
476 477
{
  GtkSettings * settings;
cinamod's avatar
cinamod committed
478
  int cursor_blink_time;
cinamod's avatar
cinamod committed
479 480 481 482 483 484

  settings = gtk_settings_get_default ();
  if (!settings)
    return;

  cursor_blink_time = GetCaretBlinkTime ();
485
  g_object_set (settings, "gtk-cursor-blink", cursor_blink_time > 0, NULL);
cinamod's avatar
cinamod committed
486 487 488

  if (cursor_blink_time > 0)
  {
489 490
  	g_object_set (settings, "gtk-cursor-blink-time", 2*cursor_blink_time,
		      NULL);
cinamod's avatar
cinamod committed
491 492
  }

493 494 495
  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
496

cinamod's avatar
cinamod committed
497
  setup_menu_settings (settings);
cinamod's avatar
cinamod committed
498

cinamod's avatar
cinamod committed
499 500 501 502 503 504 505
  /*
     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
506 507 508
static void
setup_system_font(GtkStyle *style)
{
cinamod's avatar
cinamod committed
509
  char buf[256], * font; /* It's okay, lfFaceName is smaller than 32 chars */
cinamod's avatar
cinamod committed
510

Raymond Penners's avatar
Raymond Penners committed
511 512 513 514 515
  if ((font = sys_font_to_pango_font(XP_THEME_CLASS_TEXT,
                                     XP_THEME_FONT_MESSAGE,
                                     buf, sizeof (buf))) != NULL)
    {
      if (style->font_desc)
cinamod's avatar
cinamod committed
516 517
	pango_font_description_free (style->font_desc);

Raymond Penners's avatar
Raymond Penners committed
518 519
      style->font_desc = pango_font_description_from_string(font);
    }
520 521 522
}

static void
cinamod's avatar
cinamod committed
523
sys_color_to_gtk_color(XpThemeClass klazz, int id, GdkColor *pcolor)
524
{
cinamod's avatar
cinamod committed
525 526 527 528 529
  DWORD color;

  if (!xp_theme_get_system_color (klazz, id, &color))
  	color = GetSysColor(id);

Raymond Penners's avatar
Raymond Penners committed
530 531 532 533
  pcolor->pixel = color;
  pcolor->red   = (GetRValue(color) << 8) | GetRValue(color);
  pcolor->green = (GetGValue(color) << 8) | GetGValue(color);
  pcolor->blue  = (GetBValue(color) << 8) | GetBValue(color);
534 535
}

cinamod's avatar
cinamod committed
536 537 538
static int
get_system_metric(XpThemeClass klazz, int id)
{
Raymond Penners's avatar
Raymond Penners committed
539
  int rval;
cinamod's avatar
cinamod committed
540

Raymond Penners's avatar
Raymond Penners committed
541 542
  if (!xp_theme_get_system_metric(klazz, id, &rval))
    rval = GetSystemMetrics (id);
cinamod's avatar
cinamod committed
543

Raymond Penners's avatar
Raymond Penners committed
544
  return rval;
cinamod's avatar
cinamod committed
545 546
}

547
static void
548
setup_msw_rc_style(void)
549
{
cinamod's avatar
cinamod committed
550 551 552
  /* TODO: Owen says:
  	 "If your setup_system_styles() function called gtk_rc_parse_string(), then you are just piling a new set of strings on top each time the theme changes .. the old ones won't be removed" */

cinamod's avatar
cinamod committed
553
  char buf[1024], font_buf[256], *font_ptr;
cinamod's avatar
cinamod committed
554

Raymond Penners's avatar
Raymond Penners committed
555 556
  GdkColor menu_color;
  GdkColor menu_text_color;
Raymond Penners's avatar
Raymond Penners committed
557 558 559
  GdkColor tooltip_back;
  GdkColor tooltip_fore;
  GdkColor btn_fore;
cinamod's avatar
cinamod committed
560
  GdkColor btn_face;
Raymond Penners's avatar
Raymond Penners committed
561 562
  GdkColor progress_back;

cinamod's avatar
cinamod committed
563 564 565 566 567
  GdkColor fg_prelight;
  GdkColor bg_prelight;
  GdkColor base_prelight;
  GdkColor text_prelight;

568 569
  NONCLIENTMETRICS nc;

Raymond Penners's avatar
Raymond Penners committed
570
  /* Prelight */
cinamod's avatar
cinamod committed
571 572 573 574
  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);
575

cinamod's avatar
cinamod committed
576 577
  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);
578

Raymond Penners's avatar
Raymond Penners committed
579
  /* tooltips */
cinamod's avatar
cinamod committed
580 581
  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);
Raymond Penners's avatar
Raymond Penners committed
582 583

  /* text on push buttons. TODO: button shadows, backgrounds, and highlights */
cinamod's avatar
cinamod committed
584
  sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
cinamod's avatar
cinamod committed
585
  sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
Raymond Penners's avatar
Raymond Penners committed
586 587

  /* progress bar background color */
cinamod's avatar
cinamod committed
588
  sys_color_to_gtk_color(XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT, &progress_back);
Raymond Penners's avatar
Raymond Penners committed
589 590

  /* Enable coloring for menus. */
cinamod's avatar
cinamod committed
591 592
  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),
593
	     "style \"msw-menu\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
594 595 596 597 598 599 600 601
	     "{\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"
602 603 604
	     "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
	     "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
	     "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
cinamod's avatar
cinamod committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
	     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"));
Raymond Penners's avatar
Raymond Penners committed
625
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
626

cinamod's avatar
cinamod committed
627 628
  /* Enable coloring for menu bars. */
  g_snprintf(buf, sizeof (buf),
629
	     "style \"msw-menu-bar\" = \"msw-menu\"\n"
cinamod's avatar
cinamod committed
630 631
	     "{\n"
	     "bg[NORMAL] = { %d, %d, %d }\n"
cinamod's avatar
cinamod committed
632
	     "GtkMenuBar::shadow-type = etched-in\n"
633
	     "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
cinamod's avatar
cinamod committed
634 635 636 637
	     btn_face.red,
	     btn_face.green,
	     btn_face.blue);
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
638

cinamod's avatar
cinamod committed
639
  /* enable tooltip fonts */
cinamod's avatar
cinamod committed
640 641
  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),
642
	     "style \"msw-tooltips-caption\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
643 644
	     "{fg[NORMAL] = { %d, %d, %d }\n"
	     "%s = \"%s\"\n"
645
	     "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
cinamod's avatar
cinamod committed
646 647 648 649 650
	     tooltip_fore.red,
	     tooltip_fore.green,
	     tooltip_fore.blue,
	     (font_ptr ? "font_name" : "#"),
	     (font_ptr ? font_ptr : " font name should go here"));
cinamod's avatar
cinamod committed
651
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
652

cinamod's avatar
cinamod committed
653
  g_snprintf(buf, sizeof (buf),
654
	     "style \"msw-tooltips\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
655
	     "{bg[NORMAL] = { %d, %d, %d }\n"
656
	     "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
cinamod's avatar
cinamod committed
657 658 659
	     tooltip_back.red,
	     tooltip_back.green,
	     tooltip_back.blue);
Raymond Penners's avatar
Raymond Penners committed
660
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
661

cinamod's avatar
cinamod committed
662
  /* enable font theming for status bars */
cinamod's avatar
cinamod committed
663 664
  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),
665
	     "style \"msw-status\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
666 667
	     "{%s = \"%s\"\n"
	     "bg[NORMAL] = { %d, %d, %d }\n"
668
	     "}widget_class \"*Status*\" style \"msw-status\"\n",
cinamod's avatar
cinamod committed
669 670 671
	     (font_ptr ? "font_name" : "#"),
	     (font_ptr ? font_ptr : " font name should go here"),
	     btn_face.red, btn_face.green, btn_face.blue);
cinamod's avatar
cinamod committed
672
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
673

Raymond Penners's avatar
Raymond Penners committed
674 675
  /* enable coloring for text on buttons
     TODO: use GetThemeMetric for the border and outside border */
cinamod's avatar
cinamod committed
676
  g_snprintf(buf, sizeof (buf),
677
	     "style \"msw-button\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
678 679 680 681 682 683 684 685 686
	     "{\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"
687
	     "}widget_class \"*Button*\" style \"msw-button\"\n",
cinamod's avatar
cinamod committed
688 689 690 691 692
	     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
	     );
Raymond Penners's avatar
Raymond Penners committed
693
  gtk_rc_parse_string(buf);
694

Raymond Penners's avatar
Raymond Penners committed
695
  /* enable coloring for progress bars */
cinamod's avatar
cinamod committed
696
  g_snprintf(buf, sizeof (buf),
697
	     "style \"msw-progress\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
698 699
	     "{bg[PRELIGHT] = { %d, %d, %d }\n"
	     "bg[NORMAL] = { %d, %d, %d }\n"
700
	     "}widget_class \"*Progress*\" style \"msw-progress\"\n",
cinamod's avatar
cinamod committed
701 702 703 704
	     progress_back.red,
	     progress_back.green,
	     progress_back.blue,
	     btn_face.red, btn_face.green, btn_face.blue);
Raymond Penners's avatar
Raymond Penners committed
705
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
706

707
  /* scrollbar thumb width and height */
cinamod's avatar
cinamod committed
708
  g_snprintf(buf, sizeof (buf),
709
	     "style \"msw-vscrollbar\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
710 711 712 713
	     "{GtkRange::slider-width = %d\n"
	     "GtkRange::stepper-size = %d\n"
	     "GtkRange::stepper-spacing = 0\n"
	     "GtkRange::trough_border = 0\n"
714
	     "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n",
cinamod's avatar
cinamod committed
715 716
	     GetSystemMetrics(SM_CYVTHUMB),
	     get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL));
717
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
718

cinamod's avatar
cinamod committed
719
  g_snprintf(buf, sizeof (buf),
720
	     "style \"msw-hscrollbar\" = \"msw-default\"\n"
cinamod's avatar
cinamod committed
721 722 723 724
	     "{GtkRange::slider-width = %d\n"
	     "GtkRange::stepper-size = %d\n"
	     "GtkRange::stepper-spacing = 0\n"
	     "GtkRange::trough_border = 0\n"
725
	     "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n",
cinamod's avatar
cinamod committed
726 727
	     GetSystemMetrics(SM_CXHTHUMB),
	     get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL));
728
  gtk_rc_parse_string(buf);
cinamod's avatar
cinamod committed
729

730
  /* radio/check button sizes */
cinamod's avatar
cinamod committed
731
  g_snprintf(buf, sizeof (buf),
732
	     "style \"msw-checkbutton\" = \"msw-button\"\n"
cinamod's avatar
cinamod committed
733
	     "{GtkCheckButton::indicator-size = 13\n"
734 735
	     "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
	     "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
736
  gtk_rc_parse_string(buf);
Raymond Penners's avatar
Raymond Penners committed
737
}
738

cinamod's avatar
cinamod committed
739 740 741 742 743 744
static void
setup_system_styles(GtkStyle *style)
{
  int i;

  /* Default background */
cinamod's avatar
cinamod committed
745
  sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNFACE,   &style->bg[GTK_STATE_NORMAL]);
cinamod's avatar
cinamod committed
746
  sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
cinamod's avatar
cinamod committed
747 748 749
  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]);
cinamod's avatar
cinamod committed
750 751

  /* Default base */
cinamod's avatar
cinamod committed
752
  sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOW,    &style->base[GTK_STATE_NORMAL]);
cinamod's avatar
cinamod committed
753
  sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
cinamod's avatar
cinamod committed
754 755 756
  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]);
cinamod's avatar
cinamod committed
757 758

  /* Default text */
cinamod's avatar
cinamod committed
759
  sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOWTEXT,    &style->text[GTK_STATE_NORMAL]);
cinamod's avatar
cinamod committed
760
  sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
cinamod's avatar
cinamod committed
761 762 763 764 765 766
  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 forgeground */
  sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNTEXT,       &style->fg[GTK_STATE_NORMAL]);
cinamod's avatar
cinamod committed
767 768
  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]);
cinamod's avatar
cinamod committed
769
  sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNTEXT,       &style->fg[GTK_STATE_ACTIVE]);
cinamod's avatar
cinamod committed
770
  sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOWTEXT,    &style->fg[GTK_STATE_PRELIGHT]);
cinamod's avatar
cinamod committed
771 772 773

  for (i = 0; i < 5; i++)
    {
cinamod's avatar
cinamod committed
774 775
      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]);
cinamod's avatar
cinamod committed
776 777 778 779 780 781 782 783 784 785 786

      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;
    }
}

Raymond Penners's avatar
Raymond Penners committed
787
static gboolean
788 789 790 791 792 793 794 795 796
sanitize_size (GdkWindow *window,
	       gint      *width,
	       gint      *height)
{
  gboolean set_bg = FALSE;

  if ((*width == -1) && (*height == -1))
    {
      set_bg = GDK_IS_WINDOW (window);
797
      gdk_drawable_get_size (window, width, height);
798 799
    }
  else if (*width == -1)
800
    gdk_drawable_get_size (window, width, NULL);
801
  else if (*height == -1)
802
    gdk_drawable_get_size (window, NULL, height);
803 804 805 806

  return set_bg;
}

Raymond Penners's avatar
Raymond Penners committed
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
static XpThemeElement
map_gtk_progress_bar_to_xp(GtkProgressBar *progress_bar, gboolean trough)
{
  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;
}

828 829 830 831 832 833 834 835 836 837
static void
draw_part (GdkDrawable  *drawable,
	   GdkGC        *gc,
	   GdkRectangle *area,
	   gint          x,
	   gint          y,
	   Part          part)
{
  if (area)
    gdk_gc_set_clip_rectangle (gc, area);
Raymond Penners's avatar
Raymond Penners committed
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
  if (!parts[part].bmap)
      parts[part].bmap = gdk_bitmap_create_from_data (drawable,
						      parts[part].bits,
						      PART_SIZE, PART_SIZE);

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

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

  gdk_gc_set_fill (gc, GDK_SOLID);

  if (area)
    gdk_gc_set_clip_rectangle (gc, NULL);
}

static void
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)
{
  x -= (1 + PART_SIZE - width) / 2;
  y -= (1 + PART_SIZE - height) / 2;
Raymond Penners's avatar
Raymond Penners committed
871

872 873 874 875 876 877 878 879 880 881
  if (detail && strcmp (detail, "check") == 0)	/* Menu item */
    {
      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
    {
cinamod's avatar
cinamod committed
882 883 884 885
      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))
886 887 888 889 890 891
        {
          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);
Raymond Penners's avatar
Raymond Penners committed
892

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
          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);
            }
        }
    }
}

static void
draw_expander(GtkStyle      *style,
	      GdkWindow     *window,
	      GtkStateType   state,
	      GdkRectangle  *area,
	      GtkWidget     *widget,
	      const gchar   *detail,
	      gint           x,
	      gint           y,
	      GtkExpanderStyle expander_style)
{
  gint expander_size;
  gint expander_semi_size;
  GdkColor color;
  GdkGCValues values;
  gboolean success;
Raymond Penners's avatar
Raymond Penners committed
918
  XpThemeElement xp_expander;
919 920 921

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

Raymond Penners's avatar
Raymond Penners committed
922 923 924 925 926 927 928 929 930 931
  switch (expander_style)
    {
    case GTK_EXPANDER_COLLAPSED:
    case GTK_EXPANDER_SEMI_COLLAPSED:
      xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
      break;
    default:
      xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
      break;
    }
Raymond Penners's avatar
Raymond Penners committed
932

Raymond Penners's avatar
Raymond Penners committed
933 934
  if ((expander_size % 2) == 0)
    expander_size--;
935 936 937

  if (expander_size > 2)
    expander_size -= 2;
cinamod's avatar
cinamod committed
938

939 940 941 942 943 944 945 946 947
  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);

Raymond Penners's avatar
0.4.3  
Raymond Penners committed
948 949 950
  if (! xp_theme_draw(window, xp_expander, style,
                      x, y,
                      expander_size, expander_size, state, area))
Raymond Penners's avatar
Raymond Penners committed
951
    {
Raymond Penners's avatar
0.4.3  
Raymond Penners committed
952 953
      /* RGB values to emulate Windows Classic style */
      color.red = color.green = color.blue = 128 << 8;
954

Raymond Penners's avatar
0.4.3  
Raymond Penners committed
955 956
      success = gdk_colormap_alloc_color
        (gtk_widget_get_default_colormap (), &color, FALSE, TRUE);
957

Raymond Penners's avatar
0.4.3  
Raymond Penners committed
958 959
      if (success)
        gdk_gc_set_foreground (style->fg_gc[state], &color);
960

Raymond Penners's avatar
0.4.3  
Raymond Penners committed
961 962 963
      gdk_draw_rectangle
        (window, style->fg_gc[state], FALSE, x, y,
         expander_size - 1, expander_size - 1);
Raymond Penners's avatar
Raymond Penners committed
964

965
      gdk_draw_line
Raymond Penners's avatar
0.4.3  
Raymond Penners committed
966 967 968 969 970 971 972 973 974 975 976 977
        (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;
        }
cinamod's avatar
cinamod committed
978 979 980

      if (success)
        gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
    }

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

static void
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)
{
  x -= (1 + PART_SIZE - width) / 2;
  y -= (1 + PART_SIZE - height) / 2;
Raymond Penners's avatar
Raymond Penners committed
1002

1003 1004 1005 1006 1007 1008 1009
  if (detail && strcmp (detail, "option") == 0)	/* Menu item */
    {
      if (shadow == GTK_SHADOW_IN)
	draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
    }
  else
    {
1010 1011 1012 1013
      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))
1014 1015 1016 1017 1018 1019 1020 1021 1022
        {
        }
      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);
Raymond Penners's avatar
Raymond Penners committed
1023

1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
	  if (shadow == GTK_SHADOW_IN)
	    draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
	}
    }
}

static void
draw_varrow (GdkWindow     *window,
	     GdkGC         *gc,
	     GtkShadowType  shadow_type,
	     GdkRectangle  *area,
	     GtkArrowType   arrow_type,
	     gint           x,
	     gint           y,
	     gint           width,
	     gint           height)
{
  gint steps, extra;
  gint y_start, y_increment;
  gint i;

  if (area)
    gdk_gc_set_clip_rectangle (gc, area);
Raymond Penners's avatar
Raymond Penners committed
1047

1048
  width = width + width % 2 - 1;	/* Force odd */
Raymond Penners's avatar
Raymond Penners committed
1049

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
  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);
    }
Raymond Penners's avatar
Raymond Penners committed
1071

1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089