]> Pileus Git - ~andy/gtk/blob - modules/engines/ms-windows/msw_style.c
draw XP status bar grip, toolbar grip properly
[~andy/gtk] / modules / engines / ms-windows / msw_style.c
1 /* MS-Windows Engine (aka GTK-Wimp)
2  *
3  * Copyright (C) 2003, 2004 Raymond Penners <raymond@dotsphinx.com>
4  * Includes code adapted from redmond95 by Owen Taylor, and
5  * gtk-nativewin by Evan Martin
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "msw_style.h"
24 #include "xp_theme.h"
25
26 #include <windows.h>
27 #include <math.h>
28 #include <string.h>
29 #include <stdio.h>
30
31 #include "gtk/gtk.h"
32 #include "gtk/gtk.h"
33 #include "gdk/win32/gdkwin32.h"
34
35
36 /* Default values, not normally used
37  */
38 static const GtkRequisition default_option_indicator_size = { 9, 8 };
39 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
40
41 static GtkStyleClass *parent_class;
42
43 typedef enum {
44   CHECK_AA,
45   CHECK_BASE,
46   CHECK_BLACK,
47   CHECK_DARK,
48   CHECK_LIGHT,
49   CHECK_MID,
50   CHECK_TEXT,
51   RADIO_BASE,
52   RADIO_BLACK,
53   RADIO_DARK,
54   RADIO_LIGHT,
55   RADIO_MID,
56   RADIO_TEXT
57 } Part;
58
59 #define PART_SIZE 13
60
61 static const char check_aa_bits[] = {
62  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
63  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
64 static const char check_base_bits[] = {
65  0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
66  0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
67 static const char check_black_bits[] = {
68  0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
69  0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
70 static const char check_dark_bits[] = {
71  0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
72  0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
73 static const char check_light_bits[] = {
74  0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
75  0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
76 static const char check_mid_bits[] = {
77  0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
78  0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
79 static const char check_text_bits[] = {
80  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x88,0x03,0xd8,0x01,0xf8,
81  0x00,0x70,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
82 static const char radio_base_bits[] = {
83  0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
84  0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
85 static const char radio_black_bits[] = {
86  0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
87  0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
88 static const char radio_dark_bits[] = {
89  0xf0,0x01,0x0c,0x06,0x02,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
90  0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
91 static const char radio_light_bits[] = {
92  0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
93  0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x0c,0x06,0xf0,0x01};
94 static const char radio_mid_bits[] = {
95  0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
96  0x08,0x00,0x08,0x00,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00};
97 static const char radio_text_bits[] = {
98  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
99  0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
100
101 static struct {
102   const char *bits;
103   GdkBitmap  *bmap;
104 } parts[] = {
105   { check_aa_bits, NULL },
106   { check_base_bits, NULL },
107   { check_black_bits, NULL },
108   { check_dark_bits, NULL },
109   { check_light_bits, NULL },
110   { check_mid_bits, NULL },
111   { check_text_bits, NULL },
112   { radio_base_bits, NULL },
113   { radio_black_bits, NULL },
114   { radio_dark_bits, NULL },
115   { radio_light_bits, NULL },
116   { radio_mid_bits, NULL },
117   { radio_text_bits, NULL }
118 };
119
120 static gboolean
121 get_system_font(XpThemeClass klazz, XpThemeFont type, LOGFONT *out_lf)
122 {
123 #if 0
124   /* TODO: this crashes. need to figure out why and how to fix it */
125   if (xp_theme_get_system_font(klazz, type, out_lf))
126     return TRUE;
127   else
128 #endif
129   {
130           NONCLIENTMETRICS ncm;
131           ncm.cbSize = sizeof(NONCLIENTMETRICS);
132
133           if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
134                                    sizeof(NONCLIENTMETRICS), &ncm, 0))
135             {
136               if (type == XP_THEME_FONT_CAPTION)
137                 *out_lf = ncm.lfCaptionFont;
138               else if (type == XP_THEME_FONT_MENU)
139                 *out_lf = ncm.lfMenuFont;
140               else if (type == XP_THEME_FONT_STATUS)
141                 *out_lf = ncm.lfStatusFont;
142               else
143                 *out_lf = ncm.lfMessageFont;
144
145               return TRUE;
146             }
147   }
148   return FALSE;
149 }
150
151 /***************************** STOLEN FROM PANGO *****************************/
152
153 /*
154         This code is stolen from Pango 1.4. It attempts to address the following problems:
155
156         http://bugzilla.gnome.org/show_bug.cgi?id=135098
157         http://sourceforge.net/tracker/index.php?func=detail&aid=895762&group_id=76416&atid=547655
158
159         As Owen suggested in bug 135098, once Pango 1.6 is released, we need to get rid of this code.
160 */
161
162 #define PING(printlist)
163
164 /* TrueType defines: */
165
166 #define MAKE_TT_TABLE_NAME(c1, c2, c3, c4) \
167    (((guint32)c4) << 24 | ((guint32)c3) << 16 | ((guint32)c2) << 8 | ((guint32)c1))
168
169 #define CMAP (MAKE_TT_TABLE_NAME('c','m','a','p'))
170 #define CMAP_HEADER_SIZE 4
171
172 #define NAME (MAKE_TT_TABLE_NAME('n','a','m','e'))
173 #define NAME_HEADER_SIZE 6
174
175 #define ENCODING_TABLE_SIZE 8
176
177 #define APPLE_UNICODE_PLATFORM_ID 0
178 #define MACINTOSH_PLATFORM_ID 1
179 #define ISO_PLATFORM_ID 2
180 #define MICROSOFT_PLATFORM_ID 3
181
182 #define SYMBOL_ENCODING_ID 0
183 #define UNICODE_ENCODING_ID 1
184 #define UCS4_ENCODING_ID 10
185
186 struct name_header
187 {
188   guint16 format_selector;
189   guint16 num_records;
190   guint16 string_storage_offset;
191 };
192
193 struct name_record
194 {
195   guint16 platform_id;
196   guint16 encoding_id;
197   guint16 language_id;
198   guint16 name_id;
199   guint16 string_length;
200   guint16 string_offset;
201 };
202
203 gboolean
204 pango_win32_get_name_header (HDC                 hdc,
205                              struct name_header *header)
206 {
207   if (GetFontData (hdc, NAME, 0, header, sizeof (*header)) != sizeof (*header))
208     return FALSE;
209
210   header->num_records = GUINT16_FROM_BE (header->num_records);
211   header->string_storage_offset = GUINT16_FROM_BE (header->string_storage_offset);
212
213   return TRUE;
214 }
215
216 gboolean
217 pango_win32_get_name_record (HDC                 hdc,
218                              gint                i,
219                              struct name_record *record)
220 {
221   if (GetFontData (hdc, NAME, 6 + i * sizeof (*record),
222                    record, sizeof (*record)) != sizeof (*record))
223     return FALSE;
224
225   record->platform_id = GUINT16_FROM_BE (record->platform_id);
226   record->encoding_id = GUINT16_FROM_BE (record->encoding_id);
227   record->language_id = GUINT16_FROM_BE (record->language_id);
228   record->name_id = GUINT16_FROM_BE (record->name_id);
229   record->string_length = GUINT16_FROM_BE (record->string_length);
230   record->string_offset = GUINT16_FROM_BE (record->string_offset);
231
232   return TRUE;
233 }
234
235 static gchar *
236 get_family_name (LOGFONT *lfp, HDC pango_win32_hdc)
237 {
238   HFONT hfont;
239   HFONT oldhfont;
240
241   struct name_header header;
242   struct name_record record;
243
244   gint unicode_ix = -1, mac_ix = -1, microsoft_ix = -1;
245   gint name_ix;
246   gchar *codeset;
247
248   gchar *string = NULL;
249   gchar *name;
250
251   gint i, l;
252   gsize nbytes;
253
254   /* If lfFaceName is ASCII, assume it is the common (English) name
255    * for the font. Is this valid? Do some TrueType fonts have
256    * different names in French, German, etc, and does the system
257    * return these if the locale is set to use French, German, etc?
258    */
259   l = strlen (lfp->lfFaceName);
260   for (i = 0; i < l; i++)
261     if (lfp->lfFaceName[i] < ' ' || lfp->lfFaceName[i] > '~')
262       break;
263
264   if (i == l)
265     return g_strdup (lfp->lfFaceName);
266
267   if ((hfont = CreateFontIndirect (lfp)) == NULL)
268     goto fail0;
269
270   if ((oldhfont = SelectObject (pango_win32_hdc, hfont)) == NULL)
271     goto fail1;
272
273   if (!pango_win32_get_name_header (pango_win32_hdc, &header))
274     goto fail2;
275
276   PING (("%d name records", header.num_records));
277
278   for (i = 0; i < header.num_records; i++)
279     {
280       if (!pango_win32_get_name_record (pango_win32_hdc, i, &record))
281         goto fail2;
282
283       if ((record.name_id != 1 && record.name_id != 16) || record.string_length <= 0)
284         continue;
285
286       PING(("platform:%d encoding:%d language:%04x name_id:%d",
287             record.platform_id, record.encoding_id, record.language_id, record.name_id));
288
289       if (record.platform_id == APPLE_UNICODE_PLATFORM_ID ||
290           record.platform_id == ISO_PLATFORM_ID)
291         unicode_ix = i;
292       else if (record.platform_id == MACINTOSH_PLATFORM_ID &&
293                record.encoding_id == 0 && /* Roman */
294                record.language_id == 0) /* English */
295         mac_ix = i;
296       else if (record.platform_id == MICROSOFT_PLATFORM_ID)
297         if ((microsoft_ix == -1 ||
298              PRIMARYLANGID (record.language_id) == LANG_ENGLISH) &&
299             (record.encoding_id == SYMBOL_ENCODING_ID ||
300              record.encoding_id == UNICODE_ENCODING_ID ||
301              record.encoding_id == UCS4_ENCODING_ID))
302           microsoft_ix = i;
303     }
304
305   if (microsoft_ix >= 0)
306     name_ix = microsoft_ix;
307   else if (mac_ix >= 0)
308     name_ix = mac_ix;
309   else if (unicode_ix >= 0)
310     name_ix = unicode_ix;
311   else
312     goto fail2;
313
314   if (!pango_win32_get_name_record (pango_win32_hdc, name_ix, &record))
315     goto fail2;
316
317   string = g_malloc (record.string_length + 1);
318   if (GetFontData (pango_win32_hdc, NAME,
319                    header.string_storage_offset + record.string_offset,
320                    string, record.string_length) != record.string_length)
321     goto fail2;
322
323   string[record.string_length] = '\0';
324
325   if (name_ix == microsoft_ix)
326     if (record.encoding_id == SYMBOL_ENCODING_ID ||
327         record.encoding_id == UNICODE_ENCODING_ID)
328       codeset = "UTF-16BE";
329     else
330       codeset = "UCS-4BE";
331   else if (name_ix == mac_ix)
332     codeset = "MacRoman";
333   else /* name_ix == unicode_ix */
334     codeset = "UCS-4BE";
335
336   name = g_convert (string, record.string_length, "UTF-8", codeset, NULL, &nbytes, NULL);
337   if (name == NULL)
338     goto fail2;
339   g_free (string);
340
341   PING(("%s", name));
342
343   SelectObject (pango_win32_hdc, oldhfont);
344   DeleteObject (hfont);
345
346   return name;
347
348  fail2:
349   g_free (string);
350   SelectObject (pango_win32_hdc, oldhfont);
351
352  fail1:
353   DeleteObject (hfont);
354
355  fail0:
356   return g_locale_to_utf8 (lfp->lfFaceName, -1, NULL, NULL, NULL);
357 }
358
359 /***************************** STOLEN FROM PANGO *****************************/
360
361 static char *
362 sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char * buf, size_t bufsiz)
363 {
364   HDC hDC;
365   HWND hwnd;
366   LOGFONT lf;
367   int pt_size;
368   const char * weight;
369   const char * style;
370   char * font;
371
372   if (get_system_font(klazz, type, &lf))
373     {
374       switch (lf.lfWeight) {
375       case FW_THIN:
376       case FW_EXTRALIGHT:
377         weight = "Ultra-Light";
378         break;
379
380       case FW_LIGHT:
381         weight = "Light";
382         break;
383
384       case FW_BOLD:
385         weight = "Bold";
386         break;
387
388       case FW_SEMIBOLD:
389         weight = "Semi-Bold";
390         break;
391
392       case FW_ULTRABOLD:
393         weight = "Ultra-Bold";
394         break;
395
396       case FW_HEAVY:
397         weight = "Heavy";
398         break;
399
400       default:
401         weight = "";
402         break;
403       }
404
405       if (lf.lfItalic)
406         style="Italic";
407       else
408         style="";
409
410         hwnd = GetDesktopWindow();
411         hDC = GetDC(hwnd);
412         if (hDC) {
413                 pt_size = -MulDiv(lf.lfHeight, 72,
414                               GetDeviceCaps(hDC,LOGPIXELSY));
415                 ReleaseDC(hwnd, hDC);
416         } else
417                 pt_size = 10;
418
419         font = get_family_name(&lf, hDC);
420     g_snprintf(buf, bufsiz, "%s %s %s %d", font, style, weight, pt_size);
421         g_free(font);
422
423     return buf;
424    }
425
426   return NULL;
427 }
428
429 /* missing from ms's header files */
430 #ifndef SPI_GETMENUSHOWDELAY
431 #define SPI_GETMENUSHOWDELAY 106
432 #endif
433
434 /* I don't know the proper XP theme class for things like
435    HIGHLIGHTTEXT, so we'll just define it to be "BUTTON"
436    for now */
437 #define XP_THEME_CLASS_TEXT XP_THEME_CLASS_BUTTON
438
439 static void
440 setup_menu_settings (GtkSettings * settings)
441 {
442   int menu_delay;
443   gboolean win95 = FALSE;
444   OSVERSIONINFOEX osvi;
445   GObjectClass * klazz = G_OBJECT_GET_CLASS(G_OBJECT(settings));
446
447   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
448   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
449
450   if (!GetVersionEx ( (OSVERSIONINFO *) &osvi))
451     win95 = TRUE; /* assume the worst */
452
453   if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
454     if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
455       win95 = TRUE;
456
457   if (!win95) {
458     if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0)) {
459       if (klazz) {
460         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);
468         }
469       }
470     }
471   }
472 }
473
474 void
475 msw_style_setup_system_settings (void)
476 {
477   GtkSettings * settings;
478   int cursor_blink_time;
479
480   settings = gtk_settings_get_default ();
481   if (!settings)
482     return;
483
484   cursor_blink_time = GetCaretBlinkTime ();
485   g_object_set (settings, "gtk-cursor-blink", cursor_blink_time > 0, NULL);
486
487   if (cursor_blink_time > 0)
488   {
489         g_object_set (settings, "gtk-cursor-blink-time", 2*cursor_blink_time,
490                       NULL);
491   }
492
493   g_object_set (settings, "gtk-double-click-time", GetDoubleClickTime(), NULL);
494   g_object_set (settings, "gtk-dnd-drag-threshold", GetSystemMetrics(SM_CXDRAG),
495                 NULL);
496
497   setup_menu_settings (settings);
498
499   /*
500      http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
501      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
502      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp
503   */
504 }
505
506 static void
507 setup_system_font(GtkStyle *style)
508 {
509   char buf[256], * font; /* It's okay, lfFaceName is smaller than 32 chars */
510
511   if ((font = sys_font_to_pango_font(XP_THEME_CLASS_TEXT,
512                                      XP_THEME_FONT_MESSAGE,
513                                      buf, sizeof (buf))) != NULL)
514     {
515       if (style->font_desc)
516         pango_font_description_free (style->font_desc);
517
518       style->font_desc = pango_font_description_from_string(font);
519     }
520 }
521
522 static void
523 sys_color_to_gtk_color(XpThemeClass klazz, int id, GdkColor *pcolor)
524 {
525   DWORD color;
526
527   if (!xp_theme_get_system_color (klazz, id, &color))
528         color = GetSysColor(id);
529
530   pcolor->pixel = color;
531   pcolor->red   = (GetRValue(color) << 8) | GetRValue(color);
532   pcolor->green = (GetGValue(color) << 8) | GetGValue(color);
533   pcolor->blue  = (GetBValue(color) << 8) | GetBValue(color);
534 }
535
536 static int
537 get_system_metric(XpThemeClass klazz, int id)
538 {
539   int rval;
540
541   if (!xp_theme_get_system_metric(klazz, id, &rval))
542     rval = GetSystemMetrics (id);
543
544   return rval;
545 }
546
547 static void
548 setup_msw_rc_style(void)
549 {
550   /* TODO: Owen says:
551          "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" */
552
553   char buf[1024], font_buf[256], *font_ptr;
554
555   GdkColor menu_color;
556   GdkColor menu_text_color;
557   GdkColor tooltip_back;
558   GdkColor tooltip_fore;
559   GdkColor btn_fore;
560   GdkColor btn_face;
561   GdkColor progress_back;
562
563   GdkColor fg_prelight;
564   GdkColor bg_prelight;
565   GdkColor base_prelight;
566   GdkColor text_prelight;
567
568   NONCLIENTMETRICS nc;
569
570   /* Prelight */
571   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &fg_prelight);
572   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
573   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &base_prelight);
574   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &text_prelight);
575
576   sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENUTEXT, &menu_text_color);
577   sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);
578
579   /* tooltips */
580   sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT, &tooltip_fore);
581   sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK, &tooltip_back);
582
583   /* text on push buttons. TODO: button shadows, backgrounds, and highlights */
584   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
585   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
586
587   /* progress bar background color */
588   sys_color_to_gtk_color(XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT, &progress_back);
589
590   /* Enable coloring for menus. */
591   font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,font_buf, sizeof (font_buf));
592   g_snprintf(buf, sizeof (buf),
593              "style \"msw-menu\" = \"msw-default\"\n"
594              "{\n"
595              "fg[PRELIGHT] = { %d, %d, %d }\n"
596              "bg[PRELIGHT] = { %d, %d, %d }\n"
597              "text[PRELIGHT] = { %d, %d, %d }\n"
598              "base[PRELIGHT] = { %d, %d, %d }\n"
599              "fg[NORMAL] = { %d, %d, %d }\n"
600              "bg[NORMAL] = { %d, %d, %d }\n"
601              "%s = \"%s\"\n"
602              "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
603              "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
604              "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
605              fg_prelight.red,
606              fg_prelight.green,
607              fg_prelight.blue,
608              bg_prelight.red,
609              bg_prelight.green,
610              bg_prelight.blue,
611              text_prelight.red,
612              text_prelight.green,
613              text_prelight.blue,
614              base_prelight.red,
615              base_prelight.green,
616              base_prelight.blue,
617              menu_text_color.red,
618              menu_text_color.green,
619              menu_text_color.blue,
620              menu_color.red,
621              menu_color.green,
622              menu_color.blue,
623              (font_ptr ? "font_name" : "#"),
624              (font_ptr ? font_ptr : " font name should go here"));
625   gtk_rc_parse_string(buf);
626
627   /* Enable coloring for menu bars. */
628   g_snprintf(buf, sizeof (buf),
629              "style \"msw-menu-bar\" = \"msw-menu\"\n"
630              "{\n"
631              "bg[NORMAL] = { %d, %d, %d }\n"
632              "GtkMenuBar::shadow-type = etched-in\n"
633              "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
634              btn_face.red,
635              btn_face.green,
636              btn_face.blue);
637   gtk_rc_parse_string(buf);
638
639   /* enable tooltip fonts */
640   font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
641   g_snprintf(buf, sizeof (buf),
642              "style \"msw-tooltips-caption\" = \"msw-default\"\n"
643              "{fg[NORMAL] = { %d, %d, %d }\n"
644              "%s = \"%s\"\n"
645              "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
646              tooltip_fore.red,
647              tooltip_fore.green,
648              tooltip_fore.blue,
649              (font_ptr ? "font_name" : "#"),
650              (font_ptr ? font_ptr : " font name should go here"));
651   gtk_rc_parse_string(buf);
652
653   g_snprintf(buf, sizeof (buf),
654              "style \"msw-tooltips\" = \"msw-default\"\n"
655              "{bg[NORMAL] = { %d, %d, %d }\n"
656              "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
657              tooltip_back.red,
658              tooltip_back.green,
659              tooltip_back.blue);
660   gtk_rc_parse_string(buf);
661
662   /* enable font theming for status bars */
663   font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
664   g_snprintf(buf, sizeof (buf),
665              "style \"msw-status\" = \"msw-default\"\n"
666              "{%s = \"%s\"\n"
667              "bg[NORMAL] = { %d, %d, %d }\n"
668              "}widget_class \"*Status*\" style \"msw-status\"\n",
669              (font_ptr ? "font_name" : "#"),
670              (font_ptr ? font_ptr : " font name should go here"),
671              btn_face.red, btn_face.green, btn_face.blue);
672   gtk_rc_parse_string(buf);
673
674   /* enable coloring for text on buttons
675      TODO: use GetThemeMetric for the border and outside border */
676   g_snprintf(buf, sizeof (buf),
677              "style \"msw-button\" = \"msw-default\"\n"
678              "{\n"
679              "bg[NORMAL] = { %d, %d, %d }\n"
680              "bg[PRELIGHT] = { %d, %d, %d }\n"
681              "bg[INSENSITIVE] = { %d, %d, %d }\n"
682              "fg[PRELIGHT] = { %d, %d, %d }\n"
683              "GtkButton::default-border = { 1, 1, 1, 1 }\n"
684              "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
685              "GtkButton::child-displacement-x = 1\n"
686              "GtkButton::child-displacement-y = 1\n"
687              "}widget_class \"*Button*\" style \"msw-button\"\n",
688              btn_face.red, btn_face.green, btn_face.blue,
689              btn_face.red, btn_face.green, btn_face.blue,
690              btn_face.red, btn_face.green, btn_face.blue,
691              btn_fore.red, btn_fore.green, btn_fore.blue
692              );
693   gtk_rc_parse_string(buf);
694
695   /* enable coloring for progress bars */
696   g_snprintf(buf, sizeof (buf),
697              "style \"msw-progress\" = \"msw-default\"\n"
698              "{bg[PRELIGHT] = { %d, %d, %d }\n"
699              "bg[NORMAL] = { %d, %d, %d }\n"
700              "}widget_class \"*Progress*\" style \"msw-progress\"\n",
701              progress_back.red,
702              progress_back.green,
703              progress_back.blue,
704              btn_face.red, btn_face.green, btn_face.blue);
705   gtk_rc_parse_string(buf);
706
707   /* scrollbar thumb width and height */
708   g_snprintf(buf, sizeof (buf),
709              "style \"msw-vscrollbar\" = \"msw-default\"\n"
710              "{GtkRange::slider-width = %d\n"
711              "GtkRange::stepper-size = %d\n"
712              "GtkRange::stepper-spacing = 0\n"
713              "GtkRange::trough_border = 0\n"
714              "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n",
715              GetSystemMetrics(SM_CYVTHUMB),
716              get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL));
717   gtk_rc_parse_string(buf);
718
719   g_snprintf(buf, sizeof (buf),
720              "style \"msw-hscrollbar\" = \"msw-default\"\n"
721              "{GtkRange::slider-width = %d\n"
722              "GtkRange::stepper-size = %d\n"
723              "GtkRange::stepper-spacing = 0\n"
724              "GtkRange::trough_border = 0\n"
725              "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n",
726              GetSystemMetrics(SM_CXHTHUMB),
727              get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL));
728   gtk_rc_parse_string(buf);
729
730   /* radio/check button sizes */
731   g_snprintf(buf, sizeof (buf),
732              "style \"msw-checkbutton\" = \"msw-button\"\n"
733              "{GtkCheckButton::indicator-size = 13\n"
734              "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
735              "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
736   gtk_rc_parse_string(buf);
737 }
738
739 static void
740 setup_system_styles(GtkStyle *style)
741 {
742   int i;
743
744   /* Default background */
745   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNFACE,   &style->bg[GTK_STATE_NORMAL]);
746   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
747   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNFACE,   &style->bg[GTK_STATE_INSENSITIVE]);
748   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNFACE,   &style->bg[GTK_STATE_ACTIVE]);
749   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNFACE,   &style->bg[GTK_STATE_PRELIGHT]);
750
751   /* Default base */
752   sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOW,    &style->base[GTK_STATE_NORMAL]);
753   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
754   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNFACE,   &style->base[GTK_STATE_INSENSITIVE]);
755   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNFACE,   &style->base[GTK_STATE_ACTIVE]);
756   sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOW,    &style->base[GTK_STATE_PRELIGHT]);
757
758   /* Default text */
759   sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOWTEXT,    &style->text[GTK_STATE_NORMAL]);
760   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
761   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_GRAYTEXT,      &style->text[GTK_STATE_INSENSITIVE]);
762   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNTEXT,       &style->text[GTK_STATE_ACTIVE]);
763   sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOWTEXT,    &style->text[GTK_STATE_PRELIGHT]);
764
765   /* Default forgeground */
766   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNTEXT,       &style->fg[GTK_STATE_NORMAL]);
767   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
768   sys_color_to_gtk_color(XP_THEME_CLASS_TEXT,    COLOR_GRAYTEXT,      &style->fg[GTK_STATE_INSENSITIVE]);
769   sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON,  COLOR_BTNTEXT,       &style->fg[GTK_STATE_ACTIVE]);
770   sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW,  COLOR_WINDOWTEXT,    &style->fg[GTK_STATE_PRELIGHT]);
771
772   for (i = 0; i < 5; i++)
773     {
774       sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW, &style->dark[i]);
775       sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT, &style->light[i]);
776
777       style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
778       style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
779       style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
780
781       style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
782       style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
783       style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
784     }
785 }
786
787 static gboolean
788 sanitize_size (GdkWindow *window,
789                gint      *width,
790                gint      *height)
791 {
792   gboolean set_bg = FALSE;
793
794   if ((*width == -1) && (*height == -1))
795     {
796       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   return set_bg;
805 }
806
807 static XpThemeElement
808 map_gtk_progress_bar_to_xp(GtkProgressBar *progress_bar, gboolean trough)
809 {
810   XpThemeElement ret;
811   switch (progress_bar->orientation)
812     {
813     case GTK_PROGRESS_LEFT_TO_RIGHT:
814     case GTK_PROGRESS_RIGHT_TO_LEFT:
815       ret = trough
816         ? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
817         : XP_THEME_ELEMENT_PROGRESS_BAR_H;
818       break;
819     default:
820       ret = trough
821         ? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
822         : XP_THEME_ELEMENT_PROGRESS_BAR_V;
823       break;
824     }
825   return ret;
826 }
827
828 static void
829 draw_part (GdkDrawable  *drawable,
830            GdkGC        *gc,
831            GdkRectangle *area,
832            gint          x,
833            gint          y,
834            Part          part)
835 {
836   if (area)
837     gdk_gc_set_clip_rectangle (gc, area);
838
839   if (!parts[part].bmap)
840       parts[part].bmap = gdk_bitmap_create_from_data (drawable,
841                                                       parts[part].bits,
842                                                       PART_SIZE, PART_SIZE);
843
844   gdk_gc_set_ts_origin (gc, x, y);
845   gdk_gc_set_stipple (gc, parts[part].bmap);
846   gdk_gc_set_fill (gc, GDK_STIPPLED);
847
848   gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
849
850   gdk_gc_set_fill (gc, GDK_SOLID);
851
852   if (area)
853     gdk_gc_set_clip_rectangle (gc, NULL);
854 }
855
856 static void
857 draw_check(GtkStyle      *style,
858            GdkWindow     *window,
859            GtkStateType   state,
860            GtkShadowType  shadow,
861            GdkRectangle  *area,
862            GtkWidget     *widget,
863            const gchar   *detail,
864            gint           x,
865            gint           y,
866            gint           width,
867            gint           height)
868 {
869   x -= (1 + PART_SIZE - width) / 2;
870   y -= (1 + PART_SIZE - height) / 2;
871
872   if (detail && strcmp (detail, "check") == 0)  /* Menu item */
873     {
874       if (shadow == GTK_SHADOW_IN)
875         {
876           draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
877           draw_part (window, style->dark_gc[state], area, x, y, CHECK_AA);
878         }
879     }
880   else
881     {
882       if (!xp_theme_draw(window, shadow == GTK_SHADOW_IN
883                          ? XP_THEME_ELEMENT_PRESSED_CHECKBOX
884                          : XP_THEME_ELEMENT_CHECKBOX,
885                          style, x, y, width, height, state, area))
886         {
887           draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
888           draw_part (window, style->dark_gc[state], area, x, y, CHECK_DARK);
889           draw_part (window, style->mid_gc[state], area, x, y, CHECK_MID);
890           draw_part (window, style->light_gc[state], area, x, y, CHECK_LIGHT);
891           draw_part (window, style->base_gc[state], area, x, y, CHECK_BASE);
892
893           if (shadow == GTK_SHADOW_IN)
894             {
895               draw_part (window, style->text_gc[state], area, x, y, CHECK_TEXT);
896               draw_part (window, style->text_aa_gc[state], area, x, y, CHECK_AA);
897             }
898         }
899     }
900 }
901
902 static void
903 draw_expander(GtkStyle      *style,
904               GdkWindow     *window,
905               GtkStateType   state,
906               GdkRectangle  *area,
907               GtkWidget     *widget,
908               const gchar   *detail,
909               gint           x,
910               gint           y,
911               GtkExpanderStyle expander_style)
912 {
913   gint expander_size;
914   gint expander_semi_size;
915   GdkColor color;
916   GdkGCValues values;
917   gboolean success;
918   XpThemeElement xp_expander;
919
920   gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
921
922   switch (expander_style)
923     {
924     case GTK_EXPANDER_COLLAPSED:
925     case GTK_EXPANDER_SEMI_COLLAPSED:
926       xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
927       break;
928     default:
929       xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
930       break;
931     }
932
933   if ((expander_size % 2) == 0)
934     expander_size--;
935
936   if (expander_size > 2)
937     expander_size -= 2;
938
939   if (area)
940     gdk_gc_set_clip_rectangle (style->fg_gc[state], area);
941
942   expander_semi_size = expander_size / 2;
943   x -= expander_semi_size;
944   y -= expander_semi_size;
945
946   gdk_gc_get_values (style->fg_gc[state], &values);
947
948   if (! xp_theme_draw(window, xp_expander, style,
949                       x, y,
950                       expander_size, expander_size, state, area))
951     {
952       /* RGB values to emulate Windows Classic style */
953       color.red = color.green = color.blue = 128 << 8;
954
955       success = gdk_colormap_alloc_color
956         (gtk_widget_get_default_colormap (), &color, FALSE, TRUE);
957
958       if (success)
959         gdk_gc_set_foreground (style->fg_gc[state], &color);
960
961       gdk_draw_rectangle
962         (window, style->fg_gc[state], FALSE, x, y,
963          expander_size - 1, expander_size - 1);
964
965       gdk_draw_line
966         (window, style->fg_gc[state], x + 2, y + expander_semi_size,
967          x + expander_size - 2, y + expander_semi_size);
968
969       switch (expander_style)
970         {
971         case GTK_EXPANDER_COLLAPSED:
972         case GTK_EXPANDER_SEMI_COLLAPSED:
973           gdk_draw_line
974             (window, style->fg_gc[state], x + expander_semi_size, y + 2,
975              x + expander_semi_size, y + expander_size - 2);
976           break;
977         }
978
979       if (success)
980         gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
981     }
982
983   if (area)
984     gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
985 }
986
987 static void
988 draw_option(GtkStyle      *style,
989             GdkWindow     *window,
990             GtkStateType   state,
991             GtkShadowType  shadow,
992             GdkRectangle  *area,
993             GtkWidget     *widget,
994             const gchar   *detail,
995             gint           x,
996             gint           y,
997             gint           width,
998             gint           height)
999 {
1000   x -= (1 + PART_SIZE - width) / 2;
1001   y -= (1 + PART_SIZE - height) / 2;
1002
1003   if (detail && strcmp (detail, "option") == 0) /* Menu item */
1004     {
1005       if (shadow == GTK_SHADOW_IN)
1006         draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
1007     }
1008   else
1009     {
1010       if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1011                         ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1012                         : XP_THEME_ELEMENT_RADIO_BUTTON,
1013                         style, x, y, width, height, state, area))
1014         {
1015         }
1016       else
1017         {
1018           draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
1019           draw_part (window, style->dark_gc[state], area, x, y, RADIO_DARK);
1020           draw_part (window, style->mid_gc[state], area, x, y, RADIO_MID);
1021           draw_part (window, style->light_gc[state], area, x, y, RADIO_LIGHT);
1022           draw_part (window, style->base_gc[state], area, x, y, RADIO_BASE);
1023
1024           if (shadow == GTK_SHADOW_IN)
1025             draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
1026         }
1027     }
1028 }
1029
1030 static void
1031 draw_varrow (GdkWindow     *window,
1032              GdkGC         *gc,
1033              GtkShadowType  shadow_type,
1034              GdkRectangle  *area,
1035              GtkArrowType   arrow_type,
1036              gint           x,
1037              gint           y,
1038              gint           width,
1039              gint           height)
1040 {
1041   gint steps, extra;
1042   gint y_start, y_increment;
1043   gint i;
1044
1045   if (area)
1046     gdk_gc_set_clip_rectangle (gc, area);
1047
1048   width = width + width % 2 - 1;        /* Force odd */
1049
1050   steps = 1 + width / 2;
1051
1052   extra = height - steps;
1053
1054   if (arrow_type == GTK_ARROW_DOWN)
1055     {
1056       y_start = y;
1057       y_increment = 1;
1058     }
1059   else
1060     {
1061       y_start = y + height - 1;
1062       y_increment = -1;
1063     }
1064
1065   for (i = extra; i < height; i++)
1066     {
1067       gdk_draw_line (window, gc,
1068                      x + (i - extra),              y_start + i * y_increment,
1069                      x + width - (i - extra) - 1,  y_start + i * y_increment);
1070     }
1071
1072   if (area)
1073     gdk_gc_set_clip_rectangle (gc, NULL);
1074 }
1075
1076 static void
1077 draw_harrow (GdkWindow     *window,
1078              GdkGC         *gc,
1079              GtkShadowType  shadow_type,
1080              GdkRectangle  *area,
1081              GtkArrowType   arrow_type,
1082              gint           x,
1083              gint           y,
1084              gint           width,
1085              gint           height)
1086 {
1087   gint steps, extra;
1088   gint x_start, x_increment;
1089   gint i;
1090
1091   if (area)
1092     gdk_gc_set_clip_rectangle (gc, area);
1093
1094   height = height + height % 2 - 1;     /* Force odd */
1095
1096   steps = 1 + height / 2;
1097
1098   extra = width - steps;
1099
1100   if (arrow_type == GTK_ARROW_RIGHT)
1101     {
1102       x_start = x;
1103       x_increment = 1;
1104     }
1105   else
1106     {
1107       x_start = x + width - 1;
1108       x_increment = -1;
1109     }
1110
1111   for (i = extra; i < width; i++)
1112     {
1113       gdk_draw_line (window, gc,
1114                      x_start + i * x_increment, y + (i - extra),
1115                      x_start + i * x_increment, y + height - (i - extra) - 1);
1116     }
1117
1118
1119   if (area)
1120     gdk_gc_set_clip_rectangle (gc, NULL);
1121 }
1122
1123 /* This function makes up for some brokeness in gtkrange.c
1124  * where we never get the full arrow of the stepper button
1125  * and the type of button in a single drawing function.
1126  *
1127  * It doesn't work correctly when the scrollbar is squished
1128  * to the point we don't have room for full-sized steppers.
1129  */
1130 static void
1131 reverse_engineer_stepper_box (GtkWidget    *range,
1132                               GtkArrowType  arrow_type,
1133                               gint         *x,
1134                               gint         *y,
1135                               gint         *width,
1136                               gint         *height)
1137 {
1138   gint slider_width = 14, stepper_size = 14;
1139   gint box_width;
1140   gint box_height;
1141
1142   if (range)
1143     {
1144       gtk_widget_style_get (range,
1145                             "slider_width", &slider_width,
1146                             "stepper_size", &stepper_size,
1147                             NULL);
1148     }
1149
1150   if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1151     {
1152       box_width = slider_width;
1153       box_height = stepper_size;
1154     }
1155   else
1156     {
1157       box_width = stepper_size;
1158       box_height = slider_width;
1159     }
1160
1161   *x = *x - (box_width - *width) / 2;
1162   *y = *y - (box_height - *height) / 2;
1163   *width = box_width;
1164   *height = box_height;
1165 }
1166
1167 static void
1168 draw_arrow (GtkStyle      *style,
1169             GdkWindow     *window,
1170             GtkStateType   state,
1171             GtkShadowType  shadow,
1172             GdkRectangle  *area,
1173             GtkWidget     *widget,
1174             const gchar   *detail,
1175             GtkArrowType   arrow_type,
1176             gboolean       fill,
1177             gint           x,
1178             gint           y,
1179             gint           width,
1180             gint           height)
1181 {
1182   const gchar * name;
1183
1184   name = gtk_widget_get_name (widget);
1185
1186   sanitize_size (window, &width, &height);
1187
1188   if (detail && strcmp (detail, "spinbutton") == 0)
1189     {
1190       if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1191         {
1192           return;
1193         }
1194       else
1195         {
1196           x += (width - 7) / 2;
1197
1198           if (arrow_type == GTK_ARROW_UP)
1199             y += (height - 4) / 2;
1200           else
1201             y += (1 + height - 4) / 2;
1202           draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1203                        x, y, 7, 4);
1204         }
1205     }
1206   else if (detail && (!strcmp (detail, "vscrollbar")
1207                       || !strcmp (detail, "hscrollbar")))
1208     {
1209       gboolean is_disabled = FALSE;
1210       GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1211       gint box_x = x;
1212       gint box_y = y;
1213       gint box_width = width;
1214       gint box_height = height;
1215       XpThemeElement xp_arrow;
1216       reverse_engineer_stepper_box (widget, arrow_type,
1217                                     &box_x, &box_y, &box_width, &box_height);
1218
1219       if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1220         is_disabled = TRUE;
1221
1222       switch (arrow_type)
1223         {
1224         case GTK_ARROW_UP:
1225           xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1226           break;
1227         case GTK_ARROW_DOWN:
1228           xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1229           break;
1230         case GTK_ARROW_LEFT:
1231           xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1232           break;
1233         default:
1234           xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1235           break;
1236         }
1237       if (xp_theme_draw(window, xp_arrow, style, box_x, box_y, box_width, box_height, state, area))
1238         {
1239         }
1240       else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1241         {
1242           x += (width - 7) / 2;
1243           y += (height - 5) / 2;
1244
1245           draw_varrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1246                        x, y, 7, 5);
1247         }
1248       else
1249         {
1250           y += (height - 7) / 2;
1251           x += (width - 5) / 2;
1252
1253           draw_harrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1254                        x, y, 5, 7);
1255         }
1256     }
1257   else
1258     {
1259       /* draw the toolbar chevrons - waiting for GTK 2.4 */
1260           if (name && !strcmp (name, "gtk-toolbar-arrow"))
1261           {
1262                   if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1263                                 return;
1264           }
1265
1266       if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1267         {
1268           x += (width - 7) / 2;
1269           y += (height - 5) / 2;
1270
1271           draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1272                        x, y, 7, 5);
1273         }
1274       else
1275         {
1276           x += (width - 5) / 2;
1277           y += (height - 7) / 2;
1278
1279           draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1280                        x, y, 5, 7);
1281         }
1282     }
1283 }
1284
1285 static void
1286 option_menu_get_props (GtkWidget      *widget,
1287                        GtkRequisition *indicator_size,
1288                        GtkBorder      *indicator_spacing)
1289 {
1290   GtkRequisition *tmp_size = NULL;
1291   GtkBorder *tmp_spacing = NULL;
1292
1293   if (widget)
1294     gtk_widget_style_get (widget,
1295                           "indicator_size", &tmp_size,
1296                           "indicator_spacing", &tmp_spacing,
1297                           NULL);
1298
1299   if (tmp_size)
1300     {
1301       *indicator_size = *tmp_size;
1302       g_free (tmp_size);
1303     }
1304   else
1305     *indicator_size = default_option_indicator_size;
1306
1307   if (tmp_spacing)
1308     {
1309       *indicator_spacing = *tmp_spacing;
1310       g_free (tmp_spacing);
1311     }
1312   else
1313     *indicator_spacing = default_option_indicator_spacing;
1314 }
1315
1316 static gboolean is_toolbar_child(GtkWidget * wid)
1317 {
1318         while(wid)
1319         {
1320                 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1321                         return TRUE;
1322                 else
1323                         wid = wid->parent;
1324         }
1325
1326         return FALSE;
1327 }
1328
1329 static void
1330 draw_box (GtkStyle      *style,
1331           GdkWindow     *window,
1332           GtkStateType   state_type,
1333           GtkShadowType  shadow_type,
1334           GdkRectangle  *area,
1335           GtkWidget     *widget,
1336           const gchar   *detail,
1337           gint           x,
1338           gint           y,
1339           gint           width,
1340           gint           height)
1341 {
1342   if (detail &&
1343       (!strcmp (detail, "button") ||
1344        !strcmp (detail, "buttondefault")))
1345     {
1346       if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1347         {
1348           if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1349                             width, height, state_type, area))
1350             return;
1351         }
1352       else if (is_toolbar_child (widget->parent))
1353       {
1354                     if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1355                                               width, height, state_type, area))
1356                 return;
1357           }
1358       else
1359         {
1360           gboolean is_default = !strcmp (detail, "buttondefault");
1361           if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1362                             : XP_THEME_ELEMENT_BUTTON, style, x, y,
1363                             width, height, state_type, area))
1364             return;
1365         }
1366     }
1367   else if (detail && !strcmp (detail, "spinbutton"))
1368     {
1369       if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1370         {
1371           return;
1372         }
1373     }
1374   else if (detail && (!strcmp (detail, "spinbutton_up")
1375                       || !strcmp (detail, "spinbutton_down")))
1376     {
1377       if (xp_theme_draw(window,
1378                         (! strcmp (detail, "spinbutton_up"))
1379                         ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1380                         : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1381                         style, x, y, width, height, state_type, area))
1382         {
1383           return;
1384         }
1385     }
1386
1387   else if (detail && !strcmp (detail, "slider"))
1388     {
1389       if (GTK_IS_SCROLLBAR(widget))
1390         {
1391           GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1392           gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1393           if (xp_theme_draw(window,
1394                             is_v
1395                             ? XP_THEME_ELEMENT_SCROLLBAR_V
1396                             : XP_THEME_ELEMENT_SCROLLBAR_H,
1397                             style, x, y, width, height, state_type, area))
1398             {
1399               XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1400
1401               /* Do not display grippers on tiny scroll bars, the limit imposed
1402                  is rather arbitrary, perhaps we can fetch the gripper geometry
1403                  from somewhere and use that... */
1404               if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1405                   || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1406                 {
1407                   return;
1408                 }
1409
1410               xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1411               return;
1412             }
1413           else
1414           {
1415             if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1416               return;
1417           }
1418         }
1419     }
1420   else if (detail && !strcmp (detail, "bar"))
1421     {
1422       if (widget && GTK_IS_PROGRESS_BAR (widget))
1423         {
1424           GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1425           XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1426           if (xp_theme_draw (window, xp_progress_bar,
1427                              style, x, y, width, height, state_type, area))
1428             {
1429               return;
1430             }
1431         }
1432     }
1433   else if (detail && strcmp (detail, "menuitem") == 0) {
1434     shadow_type = GTK_SHADOW_NONE;
1435       if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1436         {
1437                 return;
1438         }
1439   }
1440   else if (detail && !strcmp (detail, "trough"))
1441     {
1442       if (widget && GTK_IS_PROGRESS_BAR (widget))
1443         {
1444           GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1445           XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1446           if (xp_theme_draw (window, xp_progress_bar,
1447                              style, x, y, width, height, state_type, area))
1448             {
1449               return;
1450             }
1451           else
1452             {
1453               /* Blank in classic Windows */
1454             }
1455         }
1456       else if (widget && GTK_IS_SCROLLBAR(widget))
1457         {
1458           gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1459
1460           if (GTK_IS_RANGE(widget)
1461               && xp_theme_draw(window,
1462                                is_vertical
1463                                ? XP_THEME_ELEMENT_TROUGH_V
1464                                : XP_THEME_ELEMENT_TROUGH_H,
1465                                style,
1466                                x, y, width, height, state_type, area))
1467             {
1468               return;
1469             }
1470           else
1471             {
1472               GdkGCValues gc_values;
1473               GdkGC *gc;
1474               GdkPixmap *pixmap;
1475
1476               sanitize_size (window, &width, &height);
1477
1478               pixmap = gdk_pixmap_new (window, 2, 2, -1);
1479
1480               gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1481               gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1482               gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1483               gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1484
1485               gc_values.fill = GDK_TILED;
1486               gc_values.tile = pixmap;
1487               gc_values.ts_x_origin = x;
1488               gc_values.ts_y_origin = y;
1489               gc = gdk_gc_new_with_values (window, &gc_values,
1490                                            GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1491
1492               if (area)
1493                 gdk_gc_set_clip_rectangle (gc, area);
1494
1495               gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1496
1497               gdk_gc_unref (gc);
1498               gdk_drawable_unref (pixmap);
1499
1500               return;
1501             }
1502         }
1503       else if (widget && GTK_IS_SCALE(widget))
1504         {
1505           gboolean is_vertical = GTK_IS_VSCALE(widget);
1506
1507           parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1508                                   widget, detail, x, y, width, height);
1509
1510           if(is_vertical)
1511             parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1512           else
1513             parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1514
1515           return;
1516         }
1517     }
1518   else if (detail && strcmp (detail, "optionmenu") == 0)
1519     {
1520       if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1521                         style, x, y, width, height, state_type, area))
1522         {
1523           return;
1524         }
1525     }
1526   else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1527   {
1528        GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1529           if (shadow_type == GTK_SHADOW_IN)
1530                 shadow_type = GTK_SHADOW_ETCHED_IN;
1531        if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1532            shadow_type = GTK_SHADOW_OUT;
1533   }
1534   else
1535   {
1536          const gchar * name = gtk_widget_get_name (widget);
1537
1538           if (name && !strcmp (name, "gtk-tooltips")) {
1539          if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1540            {
1541                         return;
1542             }
1543                 }
1544   }
1545
1546   parent_class->draw_box (style, window, state_type, shadow_type, area,
1547                           widget, detail, x, y, width, height);
1548
1549   if (detail && strcmp (detail, "optionmenu") == 0)
1550     {
1551       GtkRequisition indicator_size;
1552       GtkBorder indicator_spacing;
1553       gint vline_x;
1554
1555       option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1556
1557       sanitize_size (window, &width, &height);
1558
1559       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1560         vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1561       else
1562         vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1563
1564       parent_class->draw_vline (style, window, state_type, area, widget,
1565                                 detail,
1566                                 y + style->ythickness + 1,
1567                                 y + height - style->ythickness - 3,
1568                                 vline_x);
1569     }
1570 }
1571
1572 static void
1573 draw_tab (GtkStyle      *style,
1574           GdkWindow     *window,
1575           GtkStateType   state,
1576           GtkShadowType  shadow,
1577           GdkRectangle  *area,
1578           GtkWidget     *widget,
1579           const gchar   *detail,
1580           gint           x,
1581           gint           y,
1582           gint           width,
1583           gint           height)
1584 {
1585   GtkRequisition indicator_size;
1586   GtkBorder indicator_spacing;
1587
1588   gint arrow_height;
1589
1590   g_return_if_fail (style != NULL);
1591   g_return_if_fail (window != NULL);
1592
1593   if (detail && ! strcmp (detail, "optionmenutab"))
1594     {
1595       if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1596                         style, x-5, widget->allocation.y+1,
1597                         width+10, widget->allocation.height-2, state, area))
1598         {
1599           return;
1600         }
1601     }
1602
1603   if (widget)
1604     gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1605
1606   option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1607
1608   x += (width - indicator_size.width) / 2;
1609   arrow_height = (indicator_size.width + 1) / 2;
1610
1611   y += (height - arrow_height) / 2;
1612
1613   draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1614                x, y, indicator_size.width, arrow_height);
1615 }
1616
1617 /* this is an undefined magic value that, according to the mozilla folks,
1618    worked for all the various themes that they tried */
1619 #define XP_EDGE_SIZE 2
1620
1621 static void
1622 draw_extension(GtkStyle *style,
1623                GdkWindow *window,
1624                GtkStateType state_type,
1625                GtkShadowType shadow_type,
1626                GdkRectangle *area,
1627                GtkWidget *widget,
1628                const gchar *detail,
1629                gint x,
1630                gint y,
1631                gint width,
1632                gint height,
1633                GtkPositionType gap_side)
1634 {
1635   if (detail && !strcmp(detail, "tab"))
1636     {
1637       GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1638       GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1639
1640       if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1641           height += XP_EDGE_SIZE;
1642
1643 #if 0
1644       /* FIXME: pos != TOP to be implemented */
1645       else if (pos_type == GTK_POS_BOTTOM)
1646         y -= XP_EDGE_SIZE;
1647       else if (pos_type == GTK_POS_RIGHT)
1648         width += XP_EDGE_SIZE;
1649       else if (pos_type == GTK_POS_LEFT)
1650         height -= XP_EDGE_SIZE;
1651 #endif
1652
1653       if (pos_type == GTK_POS_TOP
1654           && xp_theme_draw
1655           (window, gtk_notebook_get_current_page(notebook)==0
1656            ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1657            : XP_THEME_ELEMENT_TAB_ITEM,
1658            style, x, y, width, height, state_type, area))
1659         {
1660           return;
1661         }
1662     }
1663   parent_class->draw_extension
1664     (style, window, state_type, shadow_type, area, widget, detail,
1665          x, y, width, height, gap_side);
1666 }
1667
1668 static void
1669 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1670               GtkShadowType shadow_type, GdkRectangle *area,
1671               GtkWidget *widget, const gchar *detail, gint x,
1672               gint y, gint width, gint height, GtkPositionType gap_side,
1673               gint gap_x, gint gap_width)
1674 {
1675   if (detail && !strcmp(detail, "notebook"))
1676     {
1677       GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1678
1679       /* FIXME: pos != TOP to be implemented */
1680       if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style,  x, y, width, height,
1681                         state_type, area))
1682         {
1683           return;
1684         }
1685     }
1686   parent_class->draw_box_gap(style, window, state_type, shadow_type,
1687                              area, widget, detail, x, y, width, height,
1688                              gap_side, gap_x, gap_width);
1689 }
1690
1691 static void
1692 draw_flat_box (GtkStyle *style, GdkWindow *window,
1693                GtkStateType state_type, GtkShadowType shadow_type,
1694                GdkRectangle *area, GtkWidget *widget,
1695                const gchar *detail, gint x, gint y,
1696                gint width, gint height)
1697 {
1698   if (detail && ! strcmp (detail, "checkbutton"))
1699     {
1700       if (state_type == GTK_STATE_PRELIGHT)
1701         {
1702           return;
1703         }
1704     }
1705
1706   parent_class->draw_flat_box(style, window, state_type, shadow_type,
1707                               area, widget, detail, x, y, width, height);
1708 }
1709
1710 static void
1711 draw_shadow (GtkStyle      *style,
1712              GdkWindow     *window,
1713              GtkStateType   state_type,
1714              GtkShadowType  shadow_type,
1715              GdkRectangle  *area,
1716              GtkWidget     *widget,
1717              const gchar   *detail,
1718              gint           x,
1719              gint           y,
1720              gint           width,
1721              gint           height)
1722 {
1723   if(detail && ! strcmp(detail, "entry"))
1724     {
1725       if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1726                         x, y, width, height, state_type, area))
1727         {
1728           return;
1729         }
1730     }
1731   parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1732                              detail, x, y, width, height);
1733 }
1734
1735 static void
1736 draw_hline (GtkStyle            *style,
1737             GdkWindow           *window,
1738             GtkStateType         state_type,
1739             GdkRectangle        *area,
1740             GtkWidget           *widget,
1741             const gchar         *detail,
1742             gint                 x1,
1743             gint                 x2,
1744             gint                 y)
1745 {
1746
1747   if (detail && !strcmp(detail, "menuitem")) {
1748           if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1749                         x1, y, x2, style->ythickness, state_type, area)) {
1750                         return;
1751           }
1752   }
1753
1754   parent_class->draw_hline (style, window, state_type, area, widget,
1755                             detail, x1, x2, y);
1756 }
1757
1758 static void
1759 draw_vline (GtkStyle            *style,
1760             GdkWindow           *window,
1761             GtkStateType         state_type,
1762             GdkRectangle        *area,
1763             GtkWidget           *widget,
1764             const gchar         *detail,
1765             gint                 y1,
1766             gint                 y2,
1767             gint                 x)
1768 {
1769   parent_class->draw_vline (style, window, state_type, area, widget,
1770                             detail, y1, y2, x);
1771 }
1772
1773 static void
1774 draw_resize_grip (GtkStyle      *style,
1775                        GdkWindow     *window,
1776                        GtkStateType   state_type,
1777                        GdkRectangle  *area,
1778                        GtkWidget     *widget,
1779                        const gchar   *detail,
1780                        GdkWindowEdge  edge,
1781                        gint           x,
1782                        gint           y,
1783                        gint           width,
1784                        gint           height)
1785 {
1786         if (detail && !strcmp(detail, "statusbar")) {
1787                 if (xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1788                            state_type, area))
1789                         return;
1790         }
1791
1792         parent_class->draw_resize_grip (style, window, state_type, area,
1793                                                                         widget, detail, edge, x, y, width, height);
1794 }
1795
1796 static void
1797 draw_handle (GtkStyle        *style,
1798              GdkWindow       *window,
1799              GtkStateType     state_type,
1800              GtkShadowType    shadow_type,
1801              GdkRectangle    *area,
1802              GtkWidget       *widget,
1803              const gchar     *detail,
1804              gint             x,
1805              gint             y,
1806              gint             width,
1807              gint             height,
1808              GtkOrientation   orientation)
1809 {
1810   if (is_toolbar_child (widget))
1811     {
1812       XpThemeElement hndl;
1813
1814       sanitize_size (window, &width, &height);
1815
1816       if (orientation == GTK_ORIENTATION_VERTICAL)
1817         hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1818       else
1819         hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1820
1821       if (xp_theme_draw (window, hndl, style, x, y, width, height,
1822                          state_type, area))
1823         {
1824           return;
1825         }
1826
1827       /* grippers are just flat boxes when they're not a toolbar */
1828       parent_class->draw_box (style, window, state_type, shadow_type,
1829                               area, widget, detail, x, y, width, height);
1830     }
1831   else if (!GTK_IS_PANED (widget))
1832     {
1833       /* TODO: Draw handle boxes as double lines: || */
1834       parent_class->draw_handle (style, window, state_type, shadow_type,
1835                                  area, widget, detail, x, y, width, height,
1836                                  orientation);
1837     }
1838 }
1839
1840 static void
1841 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
1842 {
1843   setup_system_font (style);
1844   setup_menu_settings (gtk_settings_get_default ());
1845   setup_system_styles (style);
1846   parent_class->init_from_rc(style, rc_style);
1847 }
1848
1849 static void
1850 msw_style_class_init (MswStyleClass *klass)
1851 {
1852   GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1853
1854   parent_class = g_type_class_peek_parent (klass);
1855
1856   style_class->init_from_rc = msw_style_init_from_rc;
1857   style_class->draw_arrow = draw_arrow;
1858   style_class->draw_box = draw_box;
1859   style_class->draw_check = draw_check;
1860   style_class->draw_option = draw_option;
1861   style_class->draw_tab = draw_tab;
1862   style_class->draw_flat_box = draw_flat_box;
1863   style_class->draw_expander = draw_expander;
1864   style_class->draw_extension = draw_extension;
1865   style_class->draw_box_gap = draw_box_gap;
1866   style_class->draw_shadow = draw_shadow;
1867   style_class->draw_hline = draw_hline;
1868   style_class->draw_vline = draw_vline;
1869   style_class->draw_handle = draw_handle;
1870   style_class->draw_resize_grip = draw_resize_grip;
1871 }
1872
1873 GType msw_type_style = 0;
1874
1875 void
1876 msw_style_register_type (GTypeModule *module)
1877 {
1878   static const GTypeInfo object_info =
1879   {
1880     sizeof (MswStyleClass),
1881     (GBaseInitFunc) NULL,
1882     (GBaseFinalizeFunc) NULL,
1883     (GClassInitFunc) msw_style_class_init,
1884     NULL,           /* class_finalize */
1885     NULL,           /* class_data */
1886     sizeof (MswStyle),
1887     0,              /* n_preallocs */
1888     (GInstanceInitFunc) NULL,
1889   };
1890
1891   msw_type_style = g_type_module_register_type (module,
1892                                                    GTK_TYPE_STYLE,
1893                                                    "MswStyle",
1894                                                    &object_info, 0);
1895 }
1896
1897 void
1898 msw_style_init (void)
1899 {
1900   xp_theme_init ();
1901   msw_style_setup_system_settings ();
1902   setup_msw_rc_style ();
1903 }