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