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