1 /* MS-Windows Engine (aka GTK-Wimp)
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
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.
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.
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.
23 #include "msw_style.h"
33 #include "gdk/win32/gdkwin32.h"
36 /* Default values, not normally used
38 static const GtkRequisition default_option_indicator_size = { 9, 8 };
39 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
41 static GtkStyleClass *parent_class;
61 static const char check_aa_bits[] = {
62 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
63 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
64 static const char check_base_bits[] = {
65 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
66 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
67 static const char check_black_bits[] = {
68 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
69 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
70 static const char check_dark_bits[] = {
71 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
72 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
73 static const char check_light_bits[] = {
74 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
75 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
76 static const char check_mid_bits[] = {
77 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
78 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
79 static const char check_text_bits[] = {
80 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x88,0x03,0xd8,0x01,0xf8,
81 0x00,0x70,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
82 static const char radio_base_bits[] = {
83 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
84 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
85 static const char radio_black_bits[] = {
86 0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
87 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
88 static const char radio_dark_bits[] = {
89 0xf0,0x01,0x0c,0x06,0x02,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
90 0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
91 static const char radio_light_bits[] = {
92 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
93 0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x0c,0x06,0xf0,0x01};
94 static const char radio_mid_bits[] = {
95 0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
96 0x08,0x00,0x08,0x00,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00};
97 static const char radio_text_bits[] = {
98 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
99 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
105 { check_aa_bits, NULL },
106 { check_base_bits, NULL },
107 { check_black_bits, NULL },
108 { check_dark_bits, NULL },
109 { check_light_bits, NULL },
110 { check_mid_bits, NULL },
111 { check_text_bits, NULL },
112 { radio_base_bits, NULL },
113 { radio_black_bits, NULL },
114 { radio_dark_bits, NULL },
115 { radio_light_bits, NULL },
116 { radio_mid_bits, NULL },
117 { radio_text_bits, NULL }
121 get_system_font(XpThemeClass klazz, XpThemeFont type, LOGFONT *out_lf)
124 /* TODO: this crashes. need to figure out why and how to fix it */
125 if (xp_theme_get_system_font(klazz, type, out_lf))
130 NONCLIENTMETRICS ncm;
131 ncm.cbSize = sizeof(NONCLIENTMETRICS);
133 if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
134 sizeof(NONCLIENTMETRICS), &ncm, 0))
136 if (type == XP_THEME_FONT_CAPTION)
137 *out_lf = ncm.lfCaptionFont;
138 else if (type == XP_THEME_FONT_MENU)
139 *out_lf = ncm.lfMenuFont;
140 else if (type == XP_THEME_FONT_STATUS)
141 *out_lf = ncm.lfStatusFont;
143 *out_lf = ncm.lfMessageFont;
151 /***************************** STOLEN FROM PANGO *****************************/
154 This code is stolen from Pango 1.4. It attempts to address the following problems:
156 http://bugzilla.gnome.org/show_bug.cgi?id=135098
157 http://sourceforge.net/tracker/index.php?func=detail&aid=895762&group_id=76416&atid=547655
159 As Owen suggested in bug 135098, once Pango 1.6 is released, we need to get rid of this code.
162 #define PING(printlist)
164 /* TrueType defines: */
166 #define MAKE_TT_TABLE_NAME(c1, c2, c3, c4) \
167 (((guint32)c4) << 24 | ((guint32)c3) << 16 | ((guint32)c2) << 8 | ((guint32)c1))
169 #define CMAP (MAKE_TT_TABLE_NAME('c','m','a','p'))
170 #define CMAP_HEADER_SIZE 4
172 #define NAME (MAKE_TT_TABLE_NAME('n','a','m','e'))
173 #define NAME_HEADER_SIZE 6
175 #define ENCODING_TABLE_SIZE 8
177 #define APPLE_UNICODE_PLATFORM_ID 0
178 #define MACINTOSH_PLATFORM_ID 1
179 #define ISO_PLATFORM_ID 2
180 #define MICROSOFT_PLATFORM_ID 3
182 #define SYMBOL_ENCODING_ID 0
183 #define UNICODE_ENCODING_ID 1
184 #define UCS4_ENCODING_ID 10
188 guint16 format_selector;
190 guint16 string_storage_offset;
199 guint16 string_length;
200 guint16 string_offset;
204 pango_win32_get_name_header (HDC hdc,
205 struct name_header *header)
207 if (GetFontData (hdc, NAME, 0, header, sizeof (*header)) != sizeof (*header))
210 header->num_records = GUINT16_FROM_BE (header->num_records);
211 header->string_storage_offset = GUINT16_FROM_BE (header->string_storage_offset);
217 pango_win32_get_name_record (HDC hdc,
219 struct name_record *record)
221 if (GetFontData (hdc, NAME, 6 + i * sizeof (*record),
222 record, sizeof (*record)) != sizeof (*record))
225 record->platform_id = GUINT16_FROM_BE (record->platform_id);
226 record->encoding_id = GUINT16_FROM_BE (record->encoding_id);
227 record->language_id = GUINT16_FROM_BE (record->language_id);
228 record->name_id = GUINT16_FROM_BE (record->name_id);
229 record->string_length = GUINT16_FROM_BE (record->string_length);
230 record->string_offset = GUINT16_FROM_BE (record->string_offset);
236 get_family_name (LOGFONT *lfp, HDC pango_win32_hdc)
241 struct name_header header;
242 struct name_record record;
244 gint unicode_ix = -1, mac_ix = -1, microsoft_ix = -1;
248 gchar *string = NULL;
254 /* If lfFaceName is ASCII, assume it is the common (English) name
255 * for the font. Is this valid? Do some TrueType fonts have
256 * different names in French, German, etc, and does the system
257 * return these if the locale is set to use French, German, etc?
259 l = strlen (lfp->lfFaceName);
260 for (i = 0; i < l; i++)
261 if (lfp->lfFaceName[i] < ' ' || lfp->lfFaceName[i] > '~')
265 return g_strdup (lfp->lfFaceName);
267 if ((hfont = CreateFontIndirect (lfp)) == NULL)
270 if ((oldhfont = SelectObject (pango_win32_hdc, hfont)) == NULL)
273 if (!pango_win32_get_name_header (pango_win32_hdc, &header))
276 PING (("%d name records", header.num_records));
278 for (i = 0; i < header.num_records; i++)
280 if (!pango_win32_get_name_record (pango_win32_hdc, i, &record))
283 if ((record.name_id != 1 && record.name_id != 16) || record.string_length <= 0)
286 PING(("platform:%d encoding:%d language:%04x name_id:%d",
287 record.platform_id, record.encoding_id, record.language_id, record.name_id));
289 if (record.platform_id == APPLE_UNICODE_PLATFORM_ID ||
290 record.platform_id == ISO_PLATFORM_ID)
292 else if (record.platform_id == MACINTOSH_PLATFORM_ID &&
293 record.encoding_id == 0 && /* Roman */
294 record.language_id == 0) /* English */
296 else if (record.platform_id == MICROSOFT_PLATFORM_ID)
297 if ((microsoft_ix == -1 ||
298 PRIMARYLANGID (record.language_id) == LANG_ENGLISH) &&
299 (record.encoding_id == SYMBOL_ENCODING_ID ||
300 record.encoding_id == UNICODE_ENCODING_ID ||
301 record.encoding_id == UCS4_ENCODING_ID))
305 if (microsoft_ix >= 0)
306 name_ix = microsoft_ix;
307 else if (mac_ix >= 0)
309 else if (unicode_ix >= 0)
310 name_ix = unicode_ix;
314 if (!pango_win32_get_name_record (pango_win32_hdc, name_ix, &record))
317 string = g_malloc (record.string_length + 1);
318 if (GetFontData (pango_win32_hdc, NAME,
319 header.string_storage_offset + record.string_offset,
320 string, record.string_length) != record.string_length)
323 string[record.string_length] = '\0';
325 if (name_ix == microsoft_ix)
326 if (record.encoding_id == SYMBOL_ENCODING_ID ||
327 record.encoding_id == UNICODE_ENCODING_ID)
328 codeset = "UTF-16BE";
331 else if (name_ix == mac_ix)
332 codeset = "MacRoman";
333 else /* name_ix == unicode_ix */
336 name = g_convert (string, record.string_length, "UTF-8", codeset, NULL, &nbytes, NULL);
343 SelectObject (pango_win32_hdc, oldhfont);
344 DeleteObject (hfont);
350 SelectObject (pango_win32_hdc, oldhfont);
353 DeleteObject (hfont);
356 return g_locale_to_utf8 (lfp->lfFaceName, -1, NULL, NULL, NULL);
359 /***************************** STOLEN FROM PANGO *****************************/
362 sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char * buf, size_t bufsiz)
372 if (get_system_font(klazz, type, &lf))
374 switch (lf.lfWeight) {
377 weight = "Ultra-Light";
389 weight = "Semi-Bold";
393 weight = "Ultra-Bold";
410 hwnd = GetDesktopWindow();
413 pt_size = -MulDiv(lf.lfHeight, 72,
414 GetDeviceCaps(hDC,LOGPIXELSY));
415 ReleaseDC(hwnd, hDC);
419 font = get_family_name(&lf, hDC);
420 g_snprintf(buf, bufsiz, "%s %s %s %d", font, style, weight, pt_size);
429 /* missing from ms's header files */
430 #ifndef SPI_GETMENUSHOWDELAY
431 #define SPI_GETMENUSHOWDELAY 106
434 /* I don't know the proper XP theme class for things like
435 HIGHLIGHTTEXT, so we'll just define it to be "BUTTON"
437 #define XP_THEME_CLASS_TEXT XP_THEME_CLASS_BUTTON
440 setup_menu_settings (GtkSettings * settings)
443 gboolean win95 = FALSE;
444 OSVERSIONINFOEX osvi;
445 GObjectClass * klazz = G_OBJECT_GET_CLASS(G_OBJECT(settings));
447 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
448 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
450 if (!GetVersionEx ( (OSVERSIONINFO *) &osvi))
451 win95 = TRUE; /* assume the worst */
453 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
454 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
458 if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0)) {
460 if (g_object_class_find_property (klazz, "gtk-menu-bar-popup-delay")) {
461 g_object_set (G_OBJECT (settings), "gtk-menu-bar-popup-delay",
464 if (g_object_class_find_property (klazz, "gtk-menu-popup-delay")) {
465 g_object_set (G_OBJECT (settings), "gtk-menu-popup-delay",
468 if (g_object_class_find_property (klazz, "gtk-menu-popdown-delay")) {
469 g_object_set (G_OBJECT (settings), "gtk-menu-popdown-delay",
478 msw_style_setup_system_settings (void)
480 GtkSettings * settings;
481 int cursor_blink_time;
483 settings = gtk_settings_get_default ();
487 cursor_blink_time = GetCaretBlinkTime ();
488 g_object_set (G_OBJECT (settings), "gtk-cursor-blink",
489 cursor_blink_time > 0, NULL);
491 if (cursor_blink_time > 0)
493 g_object_set (G_OBJECT (settings), "gtk-cursor-blink-time",
494 2*cursor_blink_time, NULL);
497 g_object_set (G_OBJECT (settings), "gtk-double-click-time",
498 GetDoubleClickTime(), NULL);
499 g_object_set (G_OBJECT (settings), "gtk-dnd-drag-threshold",
500 GetSystemMetrics(SM_CXDRAG), NULL);
502 setup_menu_settings (settings);
505 http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
506 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
507 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp
512 setup_system_font(GtkStyle *style)
514 char buf[256], * font; /* It's okay, lfFaceName is smaller than 32 chars */
516 if ((font = sys_font_to_pango_font(XP_THEME_CLASS_TEXT,
517 XP_THEME_FONT_MESSAGE,
518 buf, sizeof (buf))) != NULL)
520 if (style->font_desc)
521 pango_font_description_free (style->font_desc);
523 style->font_desc = pango_font_description_from_string(font);
528 sys_color_to_gtk_color(XpThemeClass klazz, int id, GdkColor *pcolor)
532 if (!xp_theme_get_system_color (klazz, id, &color))
533 color = GetSysColor(id);
535 pcolor->pixel = color;
536 pcolor->red = (GetRValue(color) << 8) | GetRValue(color);
537 pcolor->green = (GetGValue(color) << 8) | GetGValue(color);
538 pcolor->blue = (GetBValue(color) << 8) | GetBValue(color);
542 get_system_metric(XpThemeClass klazz, int id)
546 if (!xp_theme_get_system_metric(klazz, id, &rval))
547 rval = GetSystemMetrics (id);
553 setup_msw_rc_style(void)
556 "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 char buf[1024], font_buf[256], *font_ptr;
561 GdkColor menu_text_color;
562 GdkColor tooltip_back;
563 GdkColor tooltip_fore;
566 GdkColor progress_back;
568 GdkColor fg_prelight;
569 GdkColor bg_prelight;
570 GdkColor base_prelight;
571 GdkColor text_prelight;
576 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &fg_prelight);
577 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
578 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &base_prelight);
579 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &text_prelight);
581 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENUTEXT, &menu_text_color);
582 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);
585 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT, &tooltip_fore);
586 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK, &tooltip_back);
588 /* text on push buttons. TODO: button shadows, backgrounds, and highlights */
589 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
590 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
592 /* progress bar background color */
593 sys_color_to_gtk_color(XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT, &progress_back);
595 /* Enable coloring for menus. */
596 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,font_buf, sizeof (font_buf));
597 g_snprintf(buf, sizeof (buf),
598 "style \"msw-menu\" = \"msw-default\"\n"
600 "fg[PRELIGHT] = { %d, %d, %d }\n"
601 "bg[PRELIGHT] = { %d, %d, %d }\n"
602 "text[PRELIGHT] = { %d, %d, %d }\n"
603 "base[PRELIGHT] = { %d, %d, %d }\n"
604 "fg[NORMAL] = { %d, %d, %d }\n"
605 "bg[NORMAL] = { %d, %d, %d }\n"
607 "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
608 "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
609 "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
623 menu_text_color.green,
624 menu_text_color.blue,
628 (font_ptr ? "font_name" : "#"),
629 (font_ptr ? font_ptr : " font name should go here"));
630 gtk_rc_parse_string(buf);
632 /* Enable coloring for menu bars. */
633 g_snprintf(buf, sizeof (buf),
634 "style \"msw-menu-bar\" = \"msw-menu\"\n"
636 "bg[NORMAL] = { %d, %d, %d }\n"
637 "GtkMenuBar::shadow-type = etched-in\n"
638 "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
642 gtk_rc_parse_string(buf);
644 /* enable tooltip fonts */
645 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
646 g_snprintf(buf, sizeof (buf),
647 "style \"msw-tooltips-caption\" = \"msw-default\"\n"
648 "{fg[NORMAL] = { %d, %d, %d }\n"
650 "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
654 (font_ptr ? "font_name" : "#"),
655 (font_ptr ? font_ptr : " font name should go here"));
656 gtk_rc_parse_string(buf);
658 g_snprintf(buf, sizeof (buf),
659 "style \"msw-tooltips\" = \"msw-default\"\n"
660 "{bg[NORMAL] = { %d, %d, %d }\n"
661 "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
665 gtk_rc_parse_string(buf);
667 /* enable font theming for status bars */
668 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
669 g_snprintf(buf, sizeof (buf),
670 "style \"msw-status\" = \"msw-default\"\n"
672 "bg[NORMAL] = { %d, %d, %d }\n"
673 "}widget_class \"*Status*\" style \"msw-status\"\n",
674 (font_ptr ? "font_name" : "#"),
675 (font_ptr ? font_ptr : " font name should go here"),
676 btn_face.red, btn_face.green, btn_face.blue);
677 gtk_rc_parse_string(buf);
679 /* enable coloring for text on buttons
680 TODO: use GetThemeMetric for the border and outside border */
681 g_snprintf(buf, sizeof (buf),
682 "style \"msw-button\" = \"msw-default\"\n"
684 "bg[NORMAL] = { %d, %d, %d }\n"
685 "bg[PRELIGHT] = { %d, %d, %d }\n"
686 "bg[INSENSITIVE] = { %d, %d, %d }\n"
687 "fg[PRELIGHT] = { %d, %d, %d }\n"
688 "GtkButton::default-border = { 1, 1, 1, 1 }\n"
689 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
690 "GtkButton::child-displacement-x = 1\n"
691 "GtkButton::child-displacement-y = 1\n"
692 "}widget_class \"*Button*\" style \"msw-button\"\n",
693 btn_face.red, btn_face.green, btn_face.blue,
694 btn_face.red, btn_face.green, btn_face.blue,
695 btn_face.red, btn_face.green, btn_face.blue,
696 btn_fore.red, btn_fore.green, btn_fore.blue
698 gtk_rc_parse_string(buf);
700 /* enable coloring for progress bars */
701 g_snprintf(buf, sizeof (buf),
702 "style \"msw-progress\" = \"msw-default\"\n"
703 "{bg[PRELIGHT] = { %d, %d, %d }\n"
704 "bg[NORMAL] = { %d, %d, %d }\n"
705 "}widget_class \"*Progress*\" style \"msw-progress\"\n",
709 btn_face.red, btn_face.green, btn_face.blue);
710 gtk_rc_parse_string(buf);
712 /* scrollbar thumb width and height */
713 g_snprintf(buf, sizeof (buf),
714 "style \"msw-vscrollbar\" = \"msw-default\"\n"
715 "{GtkRange::slider-width = %d\n"
716 "GtkRange::stepper-size = %d\n"
717 "GtkRange::stepper-spacing = 0\n"
718 "GtkRange::trough_border = 0\n"
719 "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n",
720 GetSystemMetrics(SM_CYVTHUMB),
721 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL));
722 gtk_rc_parse_string(buf);
724 g_snprintf(buf, sizeof (buf),
725 "style \"msw-hscrollbar\" = \"msw-default\"\n"
726 "{GtkRange::slider-width = %d\n"
727 "GtkRange::stepper-size = %d\n"
728 "GtkRange::stepper-spacing = 0\n"
729 "GtkRange::trough_border = 0\n"
730 "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n",
731 GetSystemMetrics(SM_CXHTHUMB),
732 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL));
733 gtk_rc_parse_string(buf);
735 /* radio/check button sizes */
736 g_snprintf(buf, sizeof (buf),
737 "style \"msw-checkbutton\" = \"msw-button\"\n"
738 "{GtkCheckButton::indicator-size = 13\n"
739 "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
740 "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
741 gtk_rc_parse_string(buf);
745 setup_system_styles(GtkStyle *style)
749 /* Default background */
750 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_NORMAL]);
751 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
752 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_INSENSITIVE]);
753 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_ACTIVE]);
754 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_PRELIGHT]);
757 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_NORMAL]);
758 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
759 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_INSENSITIVE]);
760 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_ACTIVE]);
761 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_PRELIGHT]);
764 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_NORMAL]);
765 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
766 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_GRAYTEXT, &style->text[GTK_STATE_INSENSITIVE]);
767 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->text[GTK_STATE_ACTIVE]);
768 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_PRELIGHT]);
770 /* Default forgeground */
771 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_NORMAL]);
772 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
773 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_GRAYTEXT, &style->fg[GTK_STATE_INSENSITIVE]);
774 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_ACTIVE]);
775 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->fg[GTK_STATE_PRELIGHT]);
777 for (i = 0; i < 5; i++)
779 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW, &style->dark[i]);
780 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT, &style->light[i]);
782 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
783 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
784 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
786 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
787 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
788 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
793 sanitize_size (GdkWindow *window,
797 gboolean set_bg = FALSE;
799 if ((*width == -1) && (*height == -1))
801 set_bg = GDK_IS_WINDOW (window);
802 gdk_drawable_get_size (window, width, height);
804 else if (*width == -1)
805 gdk_drawable_get_size (window, width, NULL);
806 else if (*height == -1)
807 gdk_drawable_get_size (window, NULL, height);
812 static XpThemeElement
813 map_gtk_progress_bar_to_xp(GtkProgressBar *progress_bar, gboolean trough)
816 switch (progress_bar->orientation)
818 case GTK_PROGRESS_LEFT_TO_RIGHT:
819 case GTK_PROGRESS_RIGHT_TO_LEFT:
821 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
822 : XP_THEME_ELEMENT_PROGRESS_BAR_H;
826 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
827 : XP_THEME_ELEMENT_PROGRESS_BAR_V;
834 draw_part (GdkDrawable *drawable,
842 gdk_gc_set_clip_rectangle (gc, area);
844 if (!parts[part].bmap)
845 parts[part].bmap = gdk_bitmap_create_from_data (drawable,
847 PART_SIZE, PART_SIZE);
849 gdk_gc_set_ts_origin (gc, x, y);
850 gdk_gc_set_stipple (gc, parts[part].bmap);
851 gdk_gc_set_fill (gc, GDK_STIPPLED);
853 gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
855 gdk_gc_set_fill (gc, GDK_SOLID);
858 gdk_gc_set_clip_rectangle (gc, NULL);
862 draw_check(GtkStyle *style,
865 GtkShadowType shadow,
874 x -= (1 + PART_SIZE - width) / 2;
875 y -= (1 + PART_SIZE - height) / 2;
877 if (detail && strcmp (detail, "check") == 0) /* Menu item */
879 if (shadow == GTK_SHADOW_IN)
881 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
882 draw_part (window, style->dark_gc[state], area, x, y, CHECK_AA);
887 if (!xp_theme_draw(window, shadow == GTK_SHADOW_IN
888 ? XP_THEME_ELEMENT_PRESSED_CHECKBOX
889 : XP_THEME_ELEMENT_CHECKBOX,
890 style, x, y, width, height, state, area))
892 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
893 draw_part (window, style->dark_gc[state], area, x, y, CHECK_DARK);
894 draw_part (window, style->mid_gc[state], area, x, y, CHECK_MID);
895 draw_part (window, style->light_gc[state], area, x, y, CHECK_LIGHT);
896 draw_part (window, style->base_gc[state], area, x, y, CHECK_BASE);
898 if (shadow == GTK_SHADOW_IN)
900 draw_part (window, style->text_gc[state], area, x, y, CHECK_TEXT);
901 draw_part (window, style->text_aa_gc[state], area, x, y, CHECK_AA);
908 draw_expander(GtkStyle *style,
916 GtkExpanderStyle expander_style)
919 gint expander_semi_size;
923 XpThemeElement xp_expander;
925 gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
927 switch (expander_style)
929 case GTK_EXPANDER_COLLAPSED:
930 case GTK_EXPANDER_SEMI_COLLAPSED:
931 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
934 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
938 if ((expander_size % 2) == 0)
941 if (expander_size > 2)
945 gdk_gc_set_clip_rectangle (style->fg_gc[state], area);
947 expander_semi_size = expander_size / 2;
948 x -= expander_semi_size;
949 y -= expander_semi_size;
951 gdk_gc_get_values (style->fg_gc[state], &values);
953 if (! xp_theme_draw(window, xp_expander, style,
955 expander_size, expander_size, state, area))
957 /* RGB values to emulate Windows Classic style */
958 color.red = color.green = color.blue = 128 << 8;
960 success = gdk_colormap_alloc_color
961 (gtk_widget_get_default_colormap (), &color, FALSE, TRUE);
964 gdk_gc_set_foreground (style->fg_gc[state], &color);
967 (window, style->fg_gc[state], FALSE, x, y,
968 expander_size - 1, expander_size - 1);
971 (window, style->fg_gc[state], x + 2, y + expander_semi_size,
972 x + expander_size - 2, y + expander_semi_size);
974 switch (expander_style)
976 case GTK_EXPANDER_COLLAPSED:
977 case GTK_EXPANDER_SEMI_COLLAPSED:
979 (window, style->fg_gc[state], x + expander_semi_size, y + 2,
980 x + expander_semi_size, y + expander_size - 2);
985 gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
989 gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
993 draw_option(GtkStyle *style,
996 GtkShadowType shadow,
1005 x -= (1 + PART_SIZE - width) / 2;
1006 y -= (1 + PART_SIZE - height) / 2;
1008 if (detail && strcmp (detail, "option") == 0) /* Menu item */
1010 if (shadow == GTK_SHADOW_IN)
1011 draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
1015 if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1016 ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1017 : XP_THEME_ELEMENT_RADIO_BUTTON,
1018 style, x, y, width, height, state, area))
1023 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
1024 draw_part (window, style->dark_gc[state], area, x, y, RADIO_DARK);
1025 draw_part (window, style->mid_gc[state], area, x, y, RADIO_MID);
1026 draw_part (window, style->light_gc[state], area, x, y, RADIO_LIGHT);
1027 draw_part (window, style->base_gc[state], area, x, y, RADIO_BASE);
1029 if (shadow == GTK_SHADOW_IN)
1030 draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
1036 draw_varrow (GdkWindow *window,
1038 GtkShadowType shadow_type,
1040 GtkArrowType arrow_type,
1047 gint y_start, y_increment;
1051 gdk_gc_set_clip_rectangle (gc, area);
1053 width = width + width % 2 - 1; /* Force odd */
1055 steps = 1 + width / 2;
1057 extra = height - steps;
1059 if (arrow_type == GTK_ARROW_DOWN)
1066 y_start = y + height - 1;
1070 for (i = extra; i < height; i++)
1072 gdk_draw_line (window, gc,
1073 x + (i - extra), y_start + i * y_increment,
1074 x + width - (i - extra) - 1, y_start + i * y_increment);
1078 gdk_gc_set_clip_rectangle (gc, NULL);
1082 draw_harrow (GdkWindow *window,
1084 GtkShadowType shadow_type,
1086 GtkArrowType arrow_type,
1093 gint x_start, x_increment;
1097 gdk_gc_set_clip_rectangle (gc, area);
1099 height = height + height % 2 - 1; /* Force odd */
1101 steps = 1 + height / 2;
1103 extra = width - steps;
1105 if (arrow_type == GTK_ARROW_RIGHT)
1112 x_start = x + width - 1;
1116 for (i = extra; i < width; i++)
1118 gdk_draw_line (window, gc,
1119 x_start + i * x_increment, y + (i - extra),
1120 x_start + i * x_increment, y + height - (i - extra) - 1);
1125 gdk_gc_set_clip_rectangle (gc, NULL);
1128 /* This function makes up for some brokeness in gtkrange.c
1129 * where we never get the full arrow of the stepper button
1130 * and the type of button in a single drawing function.
1132 * It doesn't work correctly when the scrollbar is squished
1133 * to the point we don't have room for full-sized steppers.
1136 reverse_engineer_stepper_box (GtkWidget *range,
1137 GtkArrowType arrow_type,
1143 gint slider_width = 14, stepper_size = 14;
1149 gtk_widget_style_get (range,
1150 "slider_width", &slider_width,
1151 "stepper_size", &stepper_size,
1155 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1157 box_width = slider_width;
1158 box_height = stepper_size;
1162 box_width = stepper_size;
1163 box_height = slider_width;
1166 *x = *x - (box_width - *width) / 2;
1167 *y = *y - (box_height - *height) / 2;
1169 *height = box_height;
1173 draw_arrow (GtkStyle *style,
1176 GtkShadowType shadow,
1179 const gchar *detail,
1180 GtkArrowType arrow_type,
1189 name = gtk_widget_get_name (widget);
1191 sanitize_size (window, &width, &height);
1193 if (detail && strcmp (detail, "spinbutton") == 0)
1195 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1201 x += (width - 7) / 2;
1203 if (arrow_type == GTK_ARROW_UP)
1204 y += (height - 4) / 2;
1206 y += (1 + height - 4) / 2;
1207 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1211 else if (detail && (!strcmp (detail, "vscrollbar")
1212 || !strcmp (detail, "hscrollbar")))
1214 gboolean is_disabled = FALSE;
1215 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1218 gint box_width = width;
1219 gint box_height = height;
1220 XpThemeElement xp_arrow;
1221 reverse_engineer_stepper_box (widget, arrow_type,
1222 &box_x, &box_y, &box_width, &box_height);
1224 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1230 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1232 case GTK_ARROW_DOWN:
1233 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1235 case GTK_ARROW_LEFT:
1236 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1239 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1242 if (xp_theme_draw(window, xp_arrow, style, box_x, box_y, box_width, box_height, state, area))
1245 else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1247 x += (width - 7) / 2;
1248 y += (height - 5) / 2;
1250 draw_varrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1255 y += (height - 7) / 2;
1256 x += (width - 5) / 2;
1258 draw_harrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1264 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1265 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1267 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1271 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1273 x += (width - 7) / 2;
1274 y += (height - 5) / 2;
1276 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1281 x += (width - 5) / 2;
1282 y += (height - 7) / 2;
1284 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1291 option_menu_get_props (GtkWidget *widget,
1292 GtkRequisition *indicator_size,
1293 GtkBorder *indicator_spacing)
1295 GtkRequisition *tmp_size = NULL;
1296 GtkBorder *tmp_spacing = NULL;
1299 gtk_widget_style_get (widget,
1300 "indicator_size", &tmp_size,
1301 "indicator_spacing", &tmp_spacing,
1306 *indicator_size = *tmp_size;
1310 *indicator_size = default_option_indicator_size;
1314 *indicator_spacing = *tmp_spacing;
1315 g_free (tmp_spacing);
1318 *indicator_spacing = default_option_indicator_spacing;
1321 static gboolean is_toolbar_child(GtkWidget * wid)
1325 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1335 draw_box (GtkStyle *style,
1337 GtkStateType state_type,
1338 GtkShadowType shadow_type,
1341 const gchar *detail,
1348 (!strcmp (detail, "button") ||
1349 !strcmp (detail, "buttondefault")))
1351 if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1353 if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1354 width, height, state_type, area))
1357 else if (is_toolbar_child (widget->parent))
1359 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1360 width, height, state_type, area))
1365 gboolean is_default = !strcmp (detail, "buttondefault");
1366 if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1367 : XP_THEME_ELEMENT_BUTTON, style, x, y,
1368 width, height, state_type, area))
1372 else if (detail && !strcmp (detail, "spinbutton"))
1374 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1379 else if (detail && (!strcmp (detail, "spinbutton_up")
1380 || !strcmp (detail, "spinbutton_down")))
1382 if (xp_theme_draw(window,
1383 (! strcmp (detail, "spinbutton_up"))
1384 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1385 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1386 style, x, y, width, height, state_type, area))
1392 else if (detail && !strcmp (detail, "slider"))
1394 if (GTK_IS_SCROLLBAR(widget))
1396 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1397 gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1398 if (xp_theme_draw(window,
1400 ? XP_THEME_ELEMENT_SCROLLBAR_V
1401 : XP_THEME_ELEMENT_SCROLLBAR_H,
1402 style, x, y, width, height, state_type, area))
1404 XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1406 /* Do not display grippers on tiny scroll bars, the limit imposed
1407 is rather arbitrary, perhaps we can fetch the gripper geometry
1408 from somewhere and use that... */
1409 if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1410 || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1415 xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1420 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1425 else if (detail && !strcmp (detail, "bar"))
1427 if (widget && GTK_IS_PROGRESS_BAR (widget))
1429 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1430 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1431 if (xp_theme_draw (window, xp_progress_bar,
1432 style, x, y, width, height, state_type, area))
1438 else if (detail && strcmp (detail, "menuitem") == 0) {
1439 shadow_type = GTK_SHADOW_NONE;
1440 if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1445 else if (detail && !strcmp (detail, "trough"))
1447 if (widget && GTK_IS_PROGRESS_BAR (widget))
1449 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1450 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1451 if (xp_theme_draw (window, xp_progress_bar,
1452 style, x, y, width, height, state_type, area))
1458 /* Blank in classic Windows */
1461 else if (widget && GTK_IS_SCROLLBAR(widget))
1463 gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1465 if (GTK_IS_RANGE(widget)
1466 && xp_theme_draw(window,
1468 ? XP_THEME_ELEMENT_TROUGH_V
1469 : XP_THEME_ELEMENT_TROUGH_H,
1471 x, y, width, height, state_type, area))
1477 GdkGCValues gc_values;
1481 sanitize_size (window, &width, &height);
1483 pixmap = gdk_pixmap_new (window, 2, 2, -1);
1485 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1486 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1487 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1488 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1490 gc_values.fill = GDK_TILED;
1491 gc_values.tile = pixmap;
1492 gc_values.ts_x_origin = x;
1493 gc_values.ts_y_origin = y;
1494 gc = gdk_gc_new_with_values (window, &gc_values,
1495 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1498 gdk_gc_set_clip_rectangle (gc, area);
1500 gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1503 gdk_drawable_unref (pixmap);
1508 else if (widget && GTK_IS_SCALE(widget))
1510 gboolean is_vertical = GTK_IS_VSCALE(widget);
1512 parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1513 widget, detail, x, y, width, height);
1516 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1518 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1523 else if (detail && strcmp (detail, "optionmenu") == 0)
1525 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1526 style, x, y, width, height, state_type, area))
1531 else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1533 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1534 if (shadow_type == GTK_SHADOW_IN)
1535 shadow_type = GTK_SHADOW_ETCHED_IN;
1536 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1537 shadow_type = GTK_SHADOW_OUT;
1541 const gchar * name = gtk_widget_get_name (widget);
1543 if (name && !strcmp (name, "gtk-tooltips")) {
1544 if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1551 parent_class->draw_box (style, window, state_type, shadow_type, area,
1552 widget, detail, x, y, width, height);
1554 if (detail && strcmp (detail, "optionmenu") == 0)
1556 GtkRequisition indicator_size;
1557 GtkBorder indicator_spacing;
1560 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1562 sanitize_size (window, &width, &height);
1564 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1565 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1567 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1569 parent_class->draw_vline (style, window, state_type, area, widget,
1571 y + style->ythickness + 1,
1572 y + height - style->ythickness - 3,
1578 draw_tab (GtkStyle *style,
1581 GtkShadowType shadow,
1584 const gchar *detail,
1590 GtkRequisition indicator_size;
1591 GtkBorder indicator_spacing;
1595 g_return_if_fail (style != NULL);
1596 g_return_if_fail (window != NULL);
1598 if (detail && ! strcmp (detail, "optionmenutab"))
1600 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1601 style, x-5, widget->allocation.y+1,
1602 width+10, widget->allocation.height-2, state, area))
1609 gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1611 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1613 x += (width - indicator_size.width) / 2;
1614 arrow_height = (indicator_size.width + 1) / 2;
1616 y += (height - arrow_height) / 2;
1618 draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1619 x, y, indicator_size.width, arrow_height);
1622 /* this is an undefined magic value that, according to the mozilla folks,
1623 worked for all the various themes that they tried */
1624 #define XP_EDGE_SIZE 2
1627 draw_extension(GtkStyle *style,
1629 GtkStateType state_type,
1630 GtkShadowType shadow_type,
1633 const gchar *detail,
1638 GtkPositionType gap_side)
1640 if (detail && !strcmp(detail, "tab"))
1642 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1643 GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1645 if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1646 height += XP_EDGE_SIZE;
1649 /* FIXME: pos != TOP to be implemented */
1650 else if (pos_type == GTK_POS_BOTTOM)
1652 else if (pos_type == GTK_POS_RIGHT)
1653 width += XP_EDGE_SIZE;
1654 else if (pos_type == GTK_POS_LEFT)
1655 height -= XP_EDGE_SIZE;
1658 if (pos_type == GTK_POS_TOP
1660 (window, gtk_notebook_get_current_page(notebook)==0
1661 ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1662 : XP_THEME_ELEMENT_TAB_ITEM,
1663 style, x, y, width, height, state_type, area))
1668 parent_class->draw_extension
1669 (style, window, state_type, shadow_type, area, widget, detail,
1670 x, y, width, height, gap_side);
1674 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1675 GtkShadowType shadow_type, GdkRectangle *area,
1676 GtkWidget *widget, const gchar *detail, gint x,
1677 gint y, gint width, gint height, GtkPositionType gap_side,
1678 gint gap_x, gint gap_width)
1680 if (detail && !strcmp(detail, "notebook"))
1682 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1684 /* FIXME: pos != TOP to be implemented */
1685 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
1691 parent_class->draw_box_gap(style, window, state_type, shadow_type,
1692 area, widget, detail, x, y, width, height,
1693 gap_side, gap_x, gap_width);
1697 draw_flat_box (GtkStyle *style, GdkWindow *window,
1698 GtkStateType state_type, GtkShadowType shadow_type,
1699 GdkRectangle *area, GtkWidget *widget,
1700 const gchar *detail, gint x, gint y,
1701 gint width, gint height)
1703 if (detail && ! strcmp (detail, "checkbutton"))
1705 if (state_type == GTK_STATE_PRELIGHT)
1711 parent_class->draw_flat_box(style, window, state_type, shadow_type,
1712 area, widget, detail, x, y, width, height);
1716 draw_shadow (GtkStyle *style,
1718 GtkStateType state_type,
1719 GtkShadowType shadow_type,
1722 const gchar *detail,
1728 if(detail && ! strcmp(detail, "entry"))
1730 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1731 x, y, width, height, state_type, area))
1736 parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1737 detail, x, y, width, height);
1741 draw_hline (GtkStyle *style,
1743 GtkStateType state_type,
1746 const gchar *detail,
1752 if (detail && !strcmp(detail, "menuitem")) {
1753 if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1754 x1, y, x2, style->ythickness, state_type, area)) {
1759 parent_class->draw_hline (style, window, state_type, area, widget,
1764 draw_vline (GtkStyle *style,
1766 GtkStateType state_type,
1769 const gchar *detail,
1774 parent_class->draw_vline (style, window, state_type, area, widget,
1779 draw_resize_grip (GtkStyle *style,
1781 GtkStateType state_type,
1784 const gchar *detail,
1791 if (detail && !strcmp(detail, "statusbar")) {
1792 if (!xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1797 parent_class->draw_resize_grip (style, window, state_type, area,
1798 widget, detail, edge, x, y, width, height);
1802 draw_handle (GtkStyle *style,
1804 GtkStateType state_type,
1805 GtkShadowType shadow_type,
1808 const gchar *detail,
1813 GtkOrientation orientation)
1815 if (GTK_IS_HANDLE_BOX (widget))
1817 XpThemeElement hndl;
1819 sanitize_size (window, &width, &height);
1821 if (orientation == GTK_ORIENTATION_VERTICAL)
1822 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1824 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1826 if (xp_theme_draw (window, hndl, style, x, y, width, height,
1832 /* grippers are just flat boxes when they're not a toolbar */
1833 parent_class->draw_box (style, window, state_type, shadow_type,
1834 area, widget, detail, x, y, width, height);
1836 else if (!GTK_IS_PANED (widget))
1838 /* TODO: Draw handle boxes as double lines: || */
1839 parent_class->draw_handle (style, window, state_type, shadow_type,
1840 area, widget, detail, x, y, width, height,
1846 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
1848 setup_system_font (style);
1849 setup_menu_settings (gtk_settings_get_default ());
1850 setup_system_styles (style);
1851 parent_class->init_from_rc(style, rc_style);
1855 msw_style_class_init (MswStyleClass *klass)
1857 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1859 parent_class = g_type_class_peek_parent (klass);
1861 style_class->init_from_rc = msw_style_init_from_rc;
1862 style_class->draw_arrow = draw_arrow;
1863 style_class->draw_box = draw_box;
1864 style_class->draw_check = draw_check;
1865 style_class->draw_option = draw_option;
1866 style_class->draw_tab = draw_tab;
1867 style_class->draw_flat_box = draw_flat_box;
1868 style_class->draw_expander = draw_expander;
1869 style_class->draw_extension = draw_extension;
1870 style_class->draw_box_gap = draw_box_gap;
1871 style_class->draw_shadow = draw_shadow;
1872 style_class->draw_hline = draw_hline;
1873 style_class->draw_vline = draw_vline;
1874 style_class->draw_handle = draw_handle;
1875 style_class->draw_resize_grip = draw_resize_grip;
1878 GType msw_type_style = 0;
1881 msw_style_register_type (GTypeModule *module)
1883 static const GTypeInfo object_info =
1885 sizeof (MswStyleClass),
1886 (GBaseInitFunc) NULL,
1887 (GBaseFinalizeFunc) NULL,
1888 (GClassInitFunc) msw_style_class_init,
1889 NULL, /* class_finalize */
1890 NULL, /* class_data */
1892 0, /* n_preallocs */
1893 (GInstanceInitFunc) NULL,
1896 msw_type_style = g_type_module_register_type (module,
1903 msw_style_init (void)
1906 msw_style_setup_system_settings ();
1907 setup_msw_rc_style ();