]> Pileus Git - ~andy/gtk/blob - modules/engines/ms-windows/msw_style.c
xp theme combo box arrows on toolbars
[~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 XpThemeElement to_xp_arrow(GtkArrowType   arrow_type)
1168 {
1169         XpThemeElement xp_arrow;
1170
1171         switch (arrow_type)
1172         {
1173                 case GTK_ARROW_UP:
1174                         xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1175                         break;
1176                 case GTK_ARROW_DOWN:
1177                         xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1178                         break;
1179                 case GTK_ARROW_LEFT:
1180                         xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1181                         break;
1182                 default:
1183                         xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1184                         break;
1185         }
1186
1187         return xp_arrow;
1188 }
1189
1190 static void
1191 draw_arrow (GtkStyle      *style,
1192             GdkWindow     *window,
1193             GtkStateType   state,
1194             GtkShadowType  shadow,
1195             GdkRectangle  *area,
1196             GtkWidget     *widget,
1197             const gchar   *detail,
1198             GtkArrowType   arrow_type,
1199             gboolean       fill,
1200             gint           x,
1201             gint           y,
1202             gint           width,
1203             gint           height)
1204 {
1205   const gchar * name;
1206
1207   name = gtk_widget_get_name (widget);
1208
1209   sanitize_size (window, &width, &height);
1210
1211   if (detail && strcmp (detail, "spinbutton") == 0)
1212     {
1213       if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1214         {
1215           return;
1216         }
1217       else
1218         {
1219           x += (width - 7) / 2;
1220
1221           if (arrow_type == GTK_ARROW_UP)
1222             y += (height - 4) / 2;
1223           else
1224             y += (1 + height - 4) / 2;
1225           draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1226                        x, y, 7, 4);
1227         }
1228     }
1229   else if (detail && (!strcmp (detail, "vscrollbar")
1230                       || !strcmp (detail, "hscrollbar")))
1231     {
1232       gboolean is_disabled = FALSE;
1233       GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1234       gint box_x = x;
1235       gint box_y = y;
1236       gint box_width = width;
1237       gint box_height = height;
1238
1239       reverse_engineer_stepper_box (widget, arrow_type,
1240                                     &box_x, &box_y, &box_width, &box_height);
1241
1242       if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1243         is_disabled = TRUE;
1244
1245       if (xp_theme_draw(window, to_xp_arrow(arrow_type), style, box_x, box_y, box_width, box_height, state, area))
1246         {
1247         }
1248       else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1249         {
1250           x += (width - 7) / 2;
1251           y += (height - 5) / 2;
1252
1253           draw_varrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1254                        x, y, 7, 5);
1255         }
1256       else
1257         {
1258           y += (height - 7) / 2;
1259           x += (width - 5) / 2;
1260
1261           draw_harrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1262                        x, y, 5, 7);
1263         }
1264     }
1265   else
1266     {
1267       /* draw the toolbar chevrons - waiting for GTK 2.4 */
1268           if (name && !strcmp (name, "gtk-toolbar-arrow"))
1269           {
1270                   if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1271                                 return;
1272           }
1273           /* probably a gtk combo box on a toolbar */
1274           else if (widget->parent && GTK_IS_BUTTON (widget->parent))
1275                 {
1276                         if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON, style, x-3, widget->allocation.y+1,
1277                         width+5, widget->allocation.height-4, state, area))
1278                                 return;
1279                 }
1280
1281       if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1282         {
1283           x += (width - 7) / 2;
1284           y += (height - 5) / 2;
1285
1286           draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1287                        x, y, 7, 5);
1288         }
1289       else
1290         {
1291           x += (width - 5) / 2;
1292           y += (height - 7) / 2;
1293
1294           draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1295                        x, y, 5, 7);
1296         }
1297     }
1298 }
1299
1300 static void
1301 option_menu_get_props (GtkWidget      *widget,
1302                        GtkRequisition *indicator_size,
1303                        GtkBorder      *indicator_spacing)
1304 {
1305   GtkRequisition *tmp_size = NULL;
1306   GtkBorder *tmp_spacing = NULL;
1307
1308   if (widget)
1309     gtk_widget_style_get (widget,
1310                           "indicator_size", &tmp_size,
1311                           "indicator_spacing", &tmp_spacing,
1312                           NULL);
1313
1314   if (tmp_size)
1315     {
1316       *indicator_size = *tmp_size;
1317       g_free (tmp_size);
1318     }
1319   else
1320     *indicator_size = default_option_indicator_size;
1321
1322   if (tmp_spacing)
1323     {
1324       *indicator_spacing = *tmp_spacing;
1325       g_free (tmp_spacing);
1326     }
1327   else
1328     *indicator_spacing = default_option_indicator_spacing;
1329 }
1330
1331 static gboolean is_toolbar_child(GtkWidget * wid)
1332 {
1333         while(wid)
1334         {
1335                 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1336                         return TRUE;
1337                 else
1338                         wid = wid->parent;
1339         }
1340
1341         return FALSE;
1342 }
1343
1344 static void
1345 draw_box (GtkStyle      *style,
1346           GdkWindow     *window,
1347           GtkStateType   state_type,
1348           GtkShadowType  shadow_type,
1349           GdkRectangle  *area,
1350           GtkWidget     *widget,
1351           const gchar   *detail,
1352           gint           x,
1353           gint           y,
1354           gint           width,
1355           gint           height)
1356 {
1357   if (detail &&
1358       (!strcmp (detail, "button") ||
1359        !strcmp (detail, "buttondefault")))
1360     {
1361       if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1362         {
1363           if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1364                             width, height, state_type, area))
1365             return;
1366         }
1367       else if (is_toolbar_child (widget->parent))
1368       {
1369                     if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1370                                               width, height, state_type, area))
1371                 return;
1372           }
1373       else
1374         {
1375           gboolean is_default = !strcmp (detail, "buttondefault");
1376           if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1377                             : XP_THEME_ELEMENT_BUTTON, style, x, y,
1378                             width, height, state_type, area))
1379             return;
1380         }
1381     }
1382   else if (detail && !strcmp (detail, "spinbutton"))
1383     {
1384       if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1385         {
1386           return;
1387         }
1388     }
1389   else if (detail && (!strcmp (detail, "spinbutton_up")
1390                       || !strcmp (detail, "spinbutton_down")))
1391     {
1392       if (xp_theme_draw(window,
1393                         (! strcmp (detail, "spinbutton_up"))
1394                         ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1395                         : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1396                         style, x, y, width, height, state_type, area))
1397         {
1398           return;
1399         }
1400     }
1401
1402   else if (detail && !strcmp (detail, "slider"))
1403     {
1404       if (GTK_IS_SCROLLBAR(widget))
1405         {
1406           GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1407           gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1408           if (xp_theme_draw(window,
1409                             is_v
1410                             ? XP_THEME_ELEMENT_SCROLLBAR_V
1411                             : XP_THEME_ELEMENT_SCROLLBAR_H,
1412                             style, x, y, width, height, state_type, area))
1413             {
1414               XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1415
1416               /* Do not display grippers on tiny scroll bars, the limit imposed
1417                  is rather arbitrary, perhaps we can fetch the gripper geometry
1418                  from somewhere and use that... */
1419               if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1420                   || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1421                 {
1422                   return;
1423                 }
1424
1425               xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1426               return;
1427             }
1428           else
1429           {
1430             if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1431               return;
1432           }
1433         }
1434     }
1435   else if (detail && !strcmp (detail, "bar"))
1436     {
1437       if (widget && GTK_IS_PROGRESS_BAR (widget))
1438         {
1439           GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1440           XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1441           if (xp_theme_draw (window, xp_progress_bar,
1442                              style, x, y, width, height, state_type, area))
1443             {
1444               return;
1445             }
1446         }
1447     }
1448   else if (detail && strcmp (detail, "menuitem") == 0) {
1449     shadow_type = GTK_SHADOW_NONE;
1450       if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1451         {
1452                 return;
1453         }
1454   }
1455   else if (detail && !strcmp (detail, "trough"))
1456     {
1457       if (widget && GTK_IS_PROGRESS_BAR (widget))
1458         {
1459           GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1460           XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1461           if (xp_theme_draw (window, xp_progress_bar,
1462                              style, x, y, width, height, state_type, area))
1463             {
1464               return;
1465             }
1466           else
1467             {
1468               /* Blank in classic Windows */
1469             }
1470         }
1471       else if (widget && GTK_IS_SCROLLBAR(widget))
1472         {
1473           gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1474
1475           if (GTK_IS_RANGE(widget)
1476               && xp_theme_draw(window,
1477                                is_vertical
1478                                ? XP_THEME_ELEMENT_TROUGH_V
1479                                : XP_THEME_ELEMENT_TROUGH_H,
1480                                style,
1481                                x, y, width, height, state_type, area))
1482             {
1483               return;
1484             }
1485           else
1486             {
1487               GdkGCValues gc_values;
1488               GdkGC *gc;
1489               GdkPixmap *pixmap;
1490
1491               sanitize_size (window, &width, &height);
1492
1493               pixmap = gdk_pixmap_new (window, 2, 2, -1);
1494
1495               gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1496               gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1497               gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1498               gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1499
1500               gc_values.fill = GDK_TILED;
1501               gc_values.tile = pixmap;
1502               gc_values.ts_x_origin = x;
1503               gc_values.ts_y_origin = y;
1504               gc = gdk_gc_new_with_values (window, &gc_values,
1505                                            GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1506
1507               if (area)
1508                 gdk_gc_set_clip_rectangle (gc, area);
1509
1510               gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1511
1512               gdk_gc_unref (gc);
1513               gdk_drawable_unref (pixmap);
1514
1515               return;
1516             }
1517         }
1518       else if (widget && GTK_IS_SCALE(widget))
1519         {
1520           gboolean is_vertical = GTK_IS_VSCALE(widget);
1521
1522           parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1523                                   widget, detail, x, y, width, height);
1524
1525           if(is_vertical)
1526             parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1527           else
1528             parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1529
1530           return;
1531         }
1532     }
1533   else if (detail && strcmp (detail, "optionmenu") == 0)
1534     {
1535       if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1536                         style, x, y, width, height, state_type, area))
1537         {
1538           return;
1539         }
1540     }
1541   else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1542   {
1543        GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1544           if (shadow_type == GTK_SHADOW_IN)
1545                 shadow_type = GTK_SHADOW_ETCHED_IN;
1546        if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1547            shadow_type = GTK_SHADOW_OUT;
1548   }
1549   else
1550   {
1551          const gchar * name = gtk_widget_get_name (widget);
1552
1553           if (name && !strcmp (name, "gtk-tooltips")) {
1554          if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1555            {
1556                         return;
1557             }
1558                 }
1559   }
1560
1561   parent_class->draw_box (style, window, state_type, shadow_type, area,
1562                           widget, detail, x, y, width, height);
1563
1564   if (detail && strcmp (detail, "optionmenu") == 0)
1565     {
1566       GtkRequisition indicator_size;
1567       GtkBorder indicator_spacing;
1568       gint vline_x;
1569
1570       option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1571
1572       sanitize_size (window, &width, &height);
1573
1574       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1575         vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1576       else
1577         vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1578
1579       parent_class->draw_vline (style, window, state_type, area, widget,
1580                                 detail,
1581                                 y + style->ythickness + 1,
1582                                 y + height - style->ythickness - 3,
1583                                 vline_x);
1584     }
1585 }
1586
1587 static void
1588 draw_tab (GtkStyle      *style,
1589           GdkWindow     *window,
1590           GtkStateType   state,
1591           GtkShadowType  shadow,
1592           GdkRectangle  *area,
1593           GtkWidget     *widget,
1594           const gchar   *detail,
1595           gint           x,
1596           gint           y,
1597           gint           width,
1598           gint           height)
1599 {
1600   GtkRequisition indicator_size;
1601   GtkBorder indicator_spacing;
1602
1603   gint arrow_height;
1604
1605   g_return_if_fail (style != NULL);
1606   g_return_if_fail (window != NULL);
1607
1608   if (detail && ! strcmp (detail, "optionmenutab"))
1609     {
1610       if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1611                         style, x-5, widget->allocation.y+1,
1612                         width+10, widget->allocation.height-2, state, area))
1613         {
1614           return;
1615         }
1616     }
1617
1618   if (widget)
1619     gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1620
1621   option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1622
1623   x += (width - indicator_size.width) / 2;
1624   arrow_height = (indicator_size.width + 1) / 2;
1625
1626   y += (height - arrow_height) / 2;
1627
1628   draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1629                x, y, indicator_size.width, arrow_height);
1630 }
1631
1632 /* this is an undefined magic value that, according to the mozilla folks,
1633    worked for all the various themes that they tried */
1634 #define XP_EDGE_SIZE 2
1635
1636 static void
1637 draw_extension(GtkStyle *style,
1638                GdkWindow *window,
1639                GtkStateType state_type,
1640                GtkShadowType shadow_type,
1641                GdkRectangle *area,
1642                GtkWidget *widget,
1643                const gchar *detail,
1644                gint x,
1645                gint y,
1646                gint width,
1647                gint height,
1648                GtkPositionType gap_side)
1649 {
1650   if (detail && !strcmp(detail, "tab"))
1651     {
1652       GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1653       GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1654
1655       if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1656           height += XP_EDGE_SIZE;
1657
1658 #if 0
1659       /* FIXME: pos != TOP to be implemented */
1660       else if (pos_type == GTK_POS_BOTTOM)
1661         y -= XP_EDGE_SIZE;
1662       else if (pos_type == GTK_POS_RIGHT)
1663         width += XP_EDGE_SIZE;
1664       else if (pos_type == GTK_POS_LEFT)
1665         height -= XP_EDGE_SIZE;
1666 #endif
1667
1668       if (pos_type == GTK_POS_TOP
1669           && xp_theme_draw
1670           (window, gtk_notebook_get_current_page(notebook)==0
1671            ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1672            : XP_THEME_ELEMENT_TAB_ITEM,
1673            style, x, y, width, height, state_type, area))
1674         {
1675           return;
1676         }
1677     }
1678   parent_class->draw_extension
1679     (style, window, state_type, shadow_type, area, widget, detail,
1680          x, y, width, height, gap_side);
1681 }
1682
1683 static void
1684 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1685               GtkShadowType shadow_type, GdkRectangle *area,
1686               GtkWidget *widget, const gchar *detail, gint x,
1687               gint y, gint width, gint height, GtkPositionType gap_side,
1688               gint gap_x, gint gap_width)
1689 {
1690   if (detail && !strcmp(detail, "notebook"))
1691     {
1692       GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1693
1694       /* FIXME: pos != TOP to be implemented */
1695       if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style,  x, y, width, height,
1696                         state_type, area))
1697         {
1698           return;
1699         }
1700     }
1701   parent_class->draw_box_gap(style, window, state_type, shadow_type,
1702                              area, widget, detail, x, y, width, height,
1703                              gap_side, gap_x, gap_width);
1704 }
1705
1706 static void
1707 draw_flat_box (GtkStyle *style, GdkWindow *window,
1708                GtkStateType state_type, GtkShadowType shadow_type,
1709                GdkRectangle *area, GtkWidget *widget,
1710                const gchar *detail, gint x, gint y,
1711                gint width, gint height)
1712 {
1713   if (detail && ! strcmp (detail, "checkbutton"))
1714     {
1715       if (state_type == GTK_STATE_PRELIGHT)
1716         {
1717           return;
1718         }
1719     }
1720
1721   parent_class->draw_flat_box(style, window, state_type, shadow_type,
1722                               area, widget, detail, x, y, width, height);
1723 }
1724
1725 static void
1726 draw_shadow (GtkStyle      *style,
1727              GdkWindow     *window,
1728              GtkStateType   state_type,
1729              GtkShadowType  shadow_type,
1730              GdkRectangle  *area,
1731              GtkWidget     *widget,
1732              const gchar   *detail,
1733              gint           x,
1734              gint           y,
1735              gint           width,
1736              gint           height)
1737 {
1738   if(detail && ! strcmp(detail, "entry"))
1739     {
1740       if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1741                         x, y, width, height, state_type, area))
1742         {
1743           return;
1744         }
1745     }
1746   parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1747                              detail, x, y, width, height);
1748 }
1749
1750 static void
1751 draw_hline (GtkStyle            *style,
1752             GdkWindow           *window,
1753             GtkStateType         state_type,
1754             GdkRectangle        *area,
1755             GtkWidget           *widget,
1756             const gchar         *detail,
1757             gint                 x1,
1758             gint                 x2,
1759             gint                 y)
1760 {
1761
1762   if (detail && !strcmp(detail, "menuitem")) {
1763           if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1764                         x1, y, x2, style->ythickness, state_type, area)) {
1765                         return;
1766           }
1767   }
1768
1769   parent_class->draw_hline (style, window, state_type, area, widget,
1770                             detail, x1, x2, y);
1771 }
1772
1773 static void
1774 draw_vline (GtkStyle            *style,
1775             GdkWindow           *window,
1776             GtkStateType         state_type,
1777             GdkRectangle        *area,
1778             GtkWidget           *widget,
1779             const gchar         *detail,
1780             gint                 y1,
1781             gint                 y2,
1782             gint                 x)
1783 {
1784   parent_class->draw_vline (style, window, state_type, area, widget,
1785                             detail, y1, y2, x);
1786 }
1787
1788 static void
1789 draw_resize_grip (GtkStyle      *style,
1790                        GdkWindow     *window,
1791                        GtkStateType   state_type,
1792                        GdkRectangle  *area,
1793                        GtkWidget     *widget,
1794                        const gchar   *detail,
1795                        GdkWindowEdge  edge,
1796                        gint           x,
1797                        gint           y,
1798                        gint           width,
1799                        gint           height)
1800 {
1801         if (detail && !strcmp(detail, "statusbar")) {
1802                 if (xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1803                            state_type, area))
1804                         return;
1805         }
1806
1807         parent_class->draw_resize_grip (style, window, state_type, area,
1808                                                                         widget, detail, edge, x, y, width, height);
1809 }
1810
1811 static void
1812 draw_handle (GtkStyle        *style,
1813              GdkWindow       *window,
1814              GtkStateType     state_type,
1815              GtkShadowType    shadow_type,
1816              GdkRectangle    *area,
1817              GtkWidget       *widget,
1818              const gchar     *detail,
1819              gint             x,
1820              gint             y,
1821              gint             width,
1822              gint             height,
1823              GtkOrientation   orientation)
1824 {
1825   if (is_toolbar_child (widget))
1826     {
1827       XpThemeElement hndl;
1828
1829       sanitize_size (window, &width, &height);
1830
1831       if (orientation == GTK_ORIENTATION_VERTICAL)
1832         hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1833       else
1834         hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1835
1836       if (xp_theme_draw (window, hndl, style, x, y, width, height,
1837                          state_type, area))
1838         {
1839           return;
1840         }
1841
1842       /* grippers are just flat boxes when they're not a toolbar */
1843       parent_class->draw_box (style, window, state_type, shadow_type,
1844                               area, widget, detail, x, y, width, height);
1845     }
1846   else if (!GTK_IS_PANED (widget))
1847     {
1848       /* TODO: Draw handle boxes as double lines: || */
1849       parent_class->draw_handle (style, window, state_type, shadow_type,
1850                                  area, widget, detail, x, y, width, height,
1851                                  orientation);
1852     }
1853 }
1854
1855 static void
1856 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
1857 {
1858   setup_system_font (style);
1859   setup_menu_settings (gtk_settings_get_default ());
1860   setup_system_styles (style);
1861   parent_class->init_from_rc(style, rc_style);
1862 }
1863
1864 static void
1865 msw_style_class_init (MswStyleClass *klass)
1866 {
1867   GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1868
1869   parent_class = g_type_class_peek_parent (klass);
1870
1871   style_class->init_from_rc = msw_style_init_from_rc;
1872   style_class->draw_arrow = draw_arrow;
1873   style_class->draw_box = draw_box;
1874   style_class->draw_check = draw_check;
1875   style_class->draw_option = draw_option;
1876   style_class->draw_tab = draw_tab;
1877   style_class->draw_flat_box = draw_flat_box;
1878   style_class->draw_expander = draw_expander;
1879   style_class->draw_extension = draw_extension;
1880   style_class->draw_box_gap = draw_box_gap;
1881   style_class->draw_shadow = draw_shadow;
1882   style_class->draw_hline = draw_hline;
1883   style_class->draw_vline = draw_vline;
1884   style_class->draw_handle = draw_handle;
1885   style_class->draw_resize_grip = draw_resize_grip;
1886 }
1887
1888 GType msw_type_style = 0;
1889
1890 void
1891 msw_style_register_type (GTypeModule *module)
1892 {
1893   static const GTypeInfo object_info =
1894   {
1895     sizeof (MswStyleClass),
1896     (GBaseInitFunc) NULL,
1897     (GBaseFinalizeFunc) NULL,
1898     (GClassInitFunc) msw_style_class_init,
1899     NULL,           /* class_finalize */
1900     NULL,           /* class_data */
1901     sizeof (MswStyle),
1902     0,              /* n_preallocs */
1903     (GInstanceInitFunc) NULL,
1904   };
1905
1906   msw_type_style = g_type_module_register_type (module,
1907                                                    GTK_TYPE_STYLE,
1908                                                    "MswStyle",
1909                                                    &object_info, 0);
1910 }
1911
1912 void
1913 msw_style_init (void)
1914 {
1915   xp_theme_init ();
1916   msw_style_setup_system_settings ();
1917   setup_msw_rc_style ();
1918 }