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 (settings, "gtk-menu-bar-popup-delay", 0, NULL);
463 if (g_object_class_find_property (klazz, "gtk-menu-popup-delay")) {
464 g_object_set (settings, "gtk-menu-popup-delay", menu_delay, NULL);
466 if (g_object_class_find_property (klazz, "gtk-menu-popdown-delay")) {
467 g_object_set (settings, "gtk-menu-popdown-delay", menu_delay, NULL);
475 msw_style_setup_system_settings (void)
477 GtkSettings * settings;
478 int cursor_blink_time;
480 settings = gtk_settings_get_default ();
484 cursor_blink_time = GetCaretBlinkTime ();
485 g_object_set (settings, "gtk-cursor-blink", cursor_blink_time > 0, NULL);
487 if (cursor_blink_time > 0)
489 g_object_set (settings, "gtk-cursor-blink-time", 2*cursor_blink_time,
493 g_object_set (settings, "gtk-double-click-time", GetDoubleClickTime(), NULL);
494 g_object_set (settings, "gtk-dnd-drag-threshold", GetSystemMetrics(SM_CXDRAG),
497 setup_menu_settings (settings);
500 http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
501 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
502 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp
507 setup_system_font(GtkStyle *style)
509 char buf[256], * font; /* It's okay, lfFaceName is smaller than 32 chars */
511 if ((font = sys_font_to_pango_font(XP_THEME_CLASS_TEXT,
512 XP_THEME_FONT_MESSAGE,
513 buf, sizeof (buf))) != NULL)
515 if (style->font_desc)
516 pango_font_description_free (style->font_desc);
518 style->font_desc = pango_font_description_from_string(font);
523 sys_color_to_gtk_color(XpThemeClass klazz, int id, GdkColor *pcolor)
527 if (!xp_theme_get_system_color (klazz, id, &color))
528 color = GetSysColor(id);
530 pcolor->pixel = color;
531 pcolor->red = (GetRValue(color) << 8) | GetRValue(color);
532 pcolor->green = (GetGValue(color) << 8) | GetGValue(color);
533 pcolor->blue = (GetBValue(color) << 8) | GetBValue(color);
537 get_system_metric(XpThemeClass klazz, int id)
541 if (!xp_theme_get_system_metric(klazz, id, &rval))
542 rval = GetSystemMetrics (id);
548 setup_msw_rc_style(void)
551 "If your setup_system_styles() function called gtk_rc_parse_string(), then you are just piling a new set of strings on top each time the theme changes .. the old ones won't be removed" */
553 char buf[1024], font_buf[256], *font_ptr;
556 GdkColor menu_text_color;
557 GdkColor tooltip_back;
558 GdkColor tooltip_fore;
561 GdkColor progress_back;
563 GdkColor fg_prelight;
564 GdkColor bg_prelight;
565 GdkColor base_prelight;
566 GdkColor text_prelight;
571 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &fg_prelight);
572 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
573 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &base_prelight);
574 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &text_prelight);
576 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENUTEXT, &menu_text_color);
577 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);
580 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT, &tooltip_fore);
581 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK, &tooltip_back);
583 /* text on push buttons. TODO: button shadows, backgrounds, and highlights */
584 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
585 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
587 /* progress bar background color */
588 sys_color_to_gtk_color(XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT, &progress_back);
590 /* Enable coloring for menus. */
591 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,font_buf, sizeof (font_buf));
592 g_snprintf(buf, sizeof (buf),
593 "style \"msw-menu\" = \"msw-default\"\n"
595 "fg[PRELIGHT] = { %d, %d, %d }\n"
596 "bg[PRELIGHT] = { %d, %d, %d }\n"
597 "text[PRELIGHT] = { %d, %d, %d }\n"
598 "base[PRELIGHT] = { %d, %d, %d }\n"
599 "fg[NORMAL] = { %d, %d, %d }\n"
600 "bg[NORMAL] = { %d, %d, %d }\n"
602 "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
603 "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
604 "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
618 menu_text_color.green,
619 menu_text_color.blue,
623 (font_ptr ? "font_name" : "#"),
624 (font_ptr ? font_ptr : " font name should go here"));
625 gtk_rc_parse_string(buf);
627 /* Enable coloring for menu bars. */
628 g_snprintf(buf, sizeof (buf),
629 "style \"msw-menu-bar\" = \"msw-menu\"\n"
631 "bg[NORMAL] = { %d, %d, %d }\n"
632 "GtkMenuBar::shadow-type = etched-in\n"
633 "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
637 gtk_rc_parse_string(buf);
639 /* enable tooltip fonts */
640 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
641 g_snprintf(buf, sizeof (buf),
642 "style \"msw-tooltips-caption\" = \"msw-default\"\n"
643 "{fg[NORMAL] = { %d, %d, %d }\n"
645 "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
649 (font_ptr ? "font_name" : "#"),
650 (font_ptr ? font_ptr : " font name should go here"));
651 gtk_rc_parse_string(buf);
653 g_snprintf(buf, sizeof (buf),
654 "style \"msw-tooltips\" = \"msw-default\"\n"
655 "{bg[NORMAL] = { %d, %d, %d }\n"
656 "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
660 gtk_rc_parse_string(buf);
662 /* enable font theming for status bars */
663 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
664 g_snprintf(buf, sizeof (buf),
665 "style \"msw-status\" = \"msw-default\"\n"
667 "bg[NORMAL] = { %d, %d, %d }\n"
668 "}widget_class \"*Status*\" style \"msw-status\"\n",
669 (font_ptr ? "font_name" : "#"),
670 (font_ptr ? font_ptr : " font name should go here"),
671 btn_face.red, btn_face.green, btn_face.blue);
672 gtk_rc_parse_string(buf);
674 /* enable coloring for text on buttons
675 TODO: use GetThemeMetric for the border and outside border */
676 g_snprintf(buf, sizeof (buf),
677 "style \"msw-button\" = \"msw-default\"\n"
679 "bg[NORMAL] = { %d, %d, %d }\n"
680 "bg[PRELIGHT] = { %d, %d, %d }\n"
681 "bg[INSENSITIVE] = { %d, %d, %d }\n"
682 "fg[PRELIGHT] = { %d, %d, %d }\n"
683 "GtkButton::default-border = { 1, 1, 1, 1 }\n"
684 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
685 "GtkButton::child-displacement-x = 1\n"
686 "GtkButton::child-displacement-y = 1\n"
687 "}widget_class \"*Button*\" style \"msw-button\"\n",
688 btn_face.red, btn_face.green, btn_face.blue,
689 btn_face.red, btn_face.green, btn_face.blue,
690 btn_face.red, btn_face.green, btn_face.blue,
691 btn_fore.red, btn_fore.green, btn_fore.blue
693 gtk_rc_parse_string(buf);
695 /* enable coloring for progress bars */
696 g_snprintf(buf, sizeof (buf),
697 "style \"msw-progress\" = \"msw-default\"\n"
698 "{bg[PRELIGHT] = { %d, %d, %d }\n"
699 "bg[NORMAL] = { %d, %d, %d }\n"
700 "}widget_class \"*Progress*\" style \"msw-progress\"\n",
704 btn_face.red, btn_face.green, btn_face.blue);
705 gtk_rc_parse_string(buf);
707 /* scrollbar thumb width and height */
708 g_snprintf(buf, sizeof (buf),
709 "style \"msw-vscrollbar\" = \"msw-default\"\n"
710 "{GtkRange::slider-width = %d\n"
711 "GtkRange::stepper-size = %d\n"
712 "GtkRange::stepper-spacing = 0\n"
713 "GtkRange::trough_border = 0\n"
714 "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n",
715 GetSystemMetrics(SM_CYVTHUMB),
716 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL));
717 gtk_rc_parse_string(buf);
719 g_snprintf(buf, sizeof (buf),
720 "style \"msw-hscrollbar\" = \"msw-default\"\n"
721 "{GtkRange::slider-width = %d\n"
722 "GtkRange::stepper-size = %d\n"
723 "GtkRange::stepper-spacing = 0\n"
724 "GtkRange::trough_border = 0\n"
725 "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n",
726 GetSystemMetrics(SM_CXHTHUMB),
727 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL));
728 gtk_rc_parse_string(buf);
730 /* radio/check button sizes */
731 g_snprintf(buf, sizeof (buf),
732 "style \"msw-checkbutton\" = \"msw-button\"\n"
733 "{GtkCheckButton::indicator-size = 13\n"
734 "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
735 "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
736 gtk_rc_parse_string(buf);
740 setup_system_styles(GtkStyle *style)
744 /* Default background */
745 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_NORMAL]);
746 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
747 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_INSENSITIVE]);
748 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_ACTIVE]);
749 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_PRELIGHT]);
752 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_NORMAL]);
753 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
754 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_INSENSITIVE]);
755 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_ACTIVE]);
756 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_PRELIGHT]);
759 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_NORMAL]);
760 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
761 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_GRAYTEXT, &style->text[GTK_STATE_INSENSITIVE]);
762 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->text[GTK_STATE_ACTIVE]);
763 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_PRELIGHT]);
765 /* Default forgeground */
766 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_NORMAL]);
767 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
768 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_GRAYTEXT, &style->fg[GTK_STATE_INSENSITIVE]);
769 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_ACTIVE]);
770 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->fg[GTK_STATE_PRELIGHT]);
772 for (i = 0; i < 5; i++)
774 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW, &style->dark[i]);
775 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT, &style->light[i]);
777 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
778 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
779 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
781 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
782 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
783 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
788 sanitize_size (GdkWindow *window,
792 gboolean set_bg = FALSE;
794 if ((*width == -1) && (*height == -1))
796 set_bg = GDK_IS_WINDOW (window);
797 gdk_drawable_get_size (window, width, height);
799 else if (*width == -1)
800 gdk_drawable_get_size (window, width, NULL);
801 else if (*height == -1)
802 gdk_drawable_get_size (window, NULL, height);
807 static XpThemeElement
808 map_gtk_progress_bar_to_xp(GtkProgressBar *progress_bar, gboolean trough)
811 switch (progress_bar->orientation)
813 case GTK_PROGRESS_LEFT_TO_RIGHT:
814 case GTK_PROGRESS_RIGHT_TO_LEFT:
816 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
817 : XP_THEME_ELEMENT_PROGRESS_BAR_H;
821 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
822 : XP_THEME_ELEMENT_PROGRESS_BAR_V;
829 draw_part (GdkDrawable *drawable,
837 gdk_gc_set_clip_rectangle (gc, area);
839 if (!parts[part].bmap)
840 parts[part].bmap = gdk_bitmap_create_from_data (drawable,
842 PART_SIZE, PART_SIZE);
844 gdk_gc_set_ts_origin (gc, x, y);
845 gdk_gc_set_stipple (gc, parts[part].bmap);
846 gdk_gc_set_fill (gc, GDK_STIPPLED);
848 gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
850 gdk_gc_set_fill (gc, GDK_SOLID);
853 gdk_gc_set_clip_rectangle (gc, NULL);
857 draw_check(GtkStyle *style,
860 GtkShadowType shadow,
869 x -= (1 + PART_SIZE - width) / 2;
870 y -= (1 + PART_SIZE - height) / 2;
872 if (detail && strcmp (detail, "check") == 0) /* Menu item */
874 if (shadow == GTK_SHADOW_IN)
876 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
877 draw_part (window, style->dark_gc[state], area, x, y, CHECK_AA);
882 if (!xp_theme_draw(window, shadow == GTK_SHADOW_IN
883 ? XP_THEME_ELEMENT_PRESSED_CHECKBOX
884 : XP_THEME_ELEMENT_CHECKBOX,
885 style, x, y, width, height, state, area))
887 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
888 draw_part (window, style->dark_gc[state], area, x, y, CHECK_DARK);
889 draw_part (window, style->mid_gc[state], area, x, y, CHECK_MID);
890 draw_part (window, style->light_gc[state], area, x, y, CHECK_LIGHT);
891 draw_part (window, style->base_gc[state], area, x, y, CHECK_BASE);
893 if (shadow == GTK_SHADOW_IN)
895 draw_part (window, style->text_gc[state], area, x, y, CHECK_TEXT);
896 draw_part (window, style->text_aa_gc[state], area, x, y, CHECK_AA);
903 draw_expander(GtkStyle *style,
911 GtkExpanderStyle expander_style)
914 gint expander_semi_size;
918 XpThemeElement xp_expander;
920 gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
922 switch (expander_style)
924 case GTK_EXPANDER_COLLAPSED:
925 case GTK_EXPANDER_SEMI_COLLAPSED:
926 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
929 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
933 if ((expander_size % 2) == 0)
936 if (expander_size > 2)
940 gdk_gc_set_clip_rectangle (style->fg_gc[state], area);
942 expander_semi_size = expander_size / 2;
943 x -= expander_semi_size;
944 y -= expander_semi_size;
946 gdk_gc_get_values (style->fg_gc[state], &values);
948 if (! xp_theme_draw(window, xp_expander, style,
950 expander_size, expander_size, state, area))
952 /* RGB values to emulate Windows Classic style */
953 color.red = color.green = color.blue = 128 << 8;
955 success = gdk_colormap_alloc_color
956 (gtk_widget_get_default_colormap (), &color, FALSE, TRUE);
959 gdk_gc_set_foreground (style->fg_gc[state], &color);
962 (window, style->fg_gc[state], FALSE, x, y,
963 expander_size - 1, expander_size - 1);
966 (window, style->fg_gc[state], x + 2, y + expander_semi_size,
967 x + expander_size - 2, y + expander_semi_size);
969 switch (expander_style)
971 case GTK_EXPANDER_COLLAPSED:
972 case GTK_EXPANDER_SEMI_COLLAPSED:
974 (window, style->fg_gc[state], x + expander_semi_size, y + 2,
975 x + expander_semi_size, y + expander_size - 2);
980 gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
984 gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
988 draw_option(GtkStyle *style,
991 GtkShadowType shadow,
1000 x -= (1 + PART_SIZE - width) / 2;
1001 y -= (1 + PART_SIZE - height) / 2;
1003 if (detail && strcmp (detail, "option") == 0) /* Menu item */
1005 if (shadow == GTK_SHADOW_IN)
1006 draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
1010 if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1011 ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1012 : XP_THEME_ELEMENT_RADIO_BUTTON,
1013 style, x, y, width, height, state, area))
1018 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
1019 draw_part (window, style->dark_gc[state], area, x, y, RADIO_DARK);
1020 draw_part (window, style->mid_gc[state], area, x, y, RADIO_MID);
1021 draw_part (window, style->light_gc[state], area, x, y, RADIO_LIGHT);
1022 draw_part (window, style->base_gc[state], area, x, y, RADIO_BASE);
1024 if (shadow == GTK_SHADOW_IN)
1025 draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
1031 draw_varrow (GdkWindow *window,
1033 GtkShadowType shadow_type,
1035 GtkArrowType arrow_type,
1042 gint y_start, y_increment;
1046 gdk_gc_set_clip_rectangle (gc, area);
1048 width = width + width % 2 - 1; /* Force odd */
1050 steps = 1 + width / 2;
1052 extra = height - steps;
1054 if (arrow_type == GTK_ARROW_DOWN)
1061 y_start = y + height - 1;
1065 for (i = extra; i < height; i++)
1067 gdk_draw_line (window, gc,
1068 x + (i - extra), y_start + i * y_increment,
1069 x + width - (i - extra) - 1, y_start + i * y_increment);
1073 gdk_gc_set_clip_rectangle (gc, NULL);
1077 draw_harrow (GdkWindow *window,
1079 GtkShadowType shadow_type,
1081 GtkArrowType arrow_type,
1088 gint x_start, x_increment;
1092 gdk_gc_set_clip_rectangle (gc, area);
1094 height = height + height % 2 - 1; /* Force odd */
1096 steps = 1 + height / 2;
1098 extra = width - steps;
1100 if (arrow_type == GTK_ARROW_RIGHT)
1107 x_start = x + width - 1;
1111 for (i = extra; i < width; i++)
1113 gdk_draw_line (window, gc,
1114 x_start + i * x_increment, y + (i - extra),
1115 x_start + i * x_increment, y + height - (i - extra) - 1);
1120 gdk_gc_set_clip_rectangle (gc, NULL);
1123 /* This function makes up for some brokeness in gtkrange.c
1124 * where we never get the full arrow of the stepper button
1125 * and the type of button in a single drawing function.
1127 * It doesn't work correctly when the scrollbar is squished
1128 * to the point we don't have room for full-sized steppers.
1131 reverse_engineer_stepper_box (GtkWidget *range,
1132 GtkArrowType arrow_type,
1138 gint slider_width = 14, stepper_size = 14;
1144 gtk_widget_style_get (range,
1145 "slider_width", &slider_width,
1146 "stepper_size", &stepper_size,
1150 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1152 box_width = slider_width;
1153 box_height = stepper_size;
1157 box_width = stepper_size;
1158 box_height = slider_width;
1161 *x = *x - (box_width - *width) / 2;
1162 *y = *y - (box_height - *height) / 2;
1164 *height = box_height;
1168 draw_arrow (GtkStyle *style,
1171 GtkShadowType shadow,
1174 const gchar *detail,
1175 GtkArrowType arrow_type,
1184 name = gtk_widget_get_name (widget);
1186 sanitize_size (window, &width, &height);
1188 if (detail && strcmp (detail, "spinbutton") == 0)
1190 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1196 x += (width - 7) / 2;
1198 if (arrow_type == GTK_ARROW_UP)
1199 y += (height - 4) / 2;
1201 y += (1 + height - 4) / 2;
1202 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1206 else if (detail && (!strcmp (detail, "vscrollbar")
1207 || !strcmp (detail, "hscrollbar")))
1209 gboolean is_disabled = FALSE;
1210 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1213 gint box_width = width;
1214 gint box_height = height;
1215 XpThemeElement xp_arrow;
1216 reverse_engineer_stepper_box (widget, arrow_type,
1217 &box_x, &box_y, &box_width, &box_height);
1219 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1225 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1227 case GTK_ARROW_DOWN:
1228 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1230 case GTK_ARROW_LEFT:
1231 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1234 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1237 if (xp_theme_draw(window, xp_arrow, style, box_x, box_y, box_width, box_height, state, area))
1240 else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1242 x += (width - 7) / 2;
1243 y += (height - 5) / 2;
1245 draw_varrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1250 y += (height - 7) / 2;
1251 x += (width - 5) / 2;
1253 draw_harrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1259 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1260 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1262 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1266 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1268 x += (width - 7) / 2;
1269 y += (height - 5) / 2;
1271 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1276 x += (width - 5) / 2;
1277 y += (height - 7) / 2;
1279 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1286 option_menu_get_props (GtkWidget *widget,
1287 GtkRequisition *indicator_size,
1288 GtkBorder *indicator_spacing)
1290 GtkRequisition *tmp_size = NULL;
1291 GtkBorder *tmp_spacing = NULL;
1294 gtk_widget_style_get (widget,
1295 "indicator_size", &tmp_size,
1296 "indicator_spacing", &tmp_spacing,
1301 *indicator_size = *tmp_size;
1305 *indicator_size = default_option_indicator_size;
1309 *indicator_spacing = *tmp_spacing;
1310 g_free (tmp_spacing);
1313 *indicator_spacing = default_option_indicator_spacing;
1316 static gboolean is_toolbar_child(GtkWidget * wid)
1320 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1330 draw_box (GtkStyle *style,
1332 GtkStateType state_type,
1333 GtkShadowType shadow_type,
1336 const gchar *detail,
1343 (!strcmp (detail, "button") ||
1344 !strcmp (detail, "buttondefault")))
1346 if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1348 if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1349 width, height, state_type, area))
1352 else if (is_toolbar_child (widget->parent))
1354 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1355 width, height, state_type, area))
1360 gboolean is_default = !strcmp (detail, "buttondefault");
1361 if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1362 : XP_THEME_ELEMENT_BUTTON, style, x, y,
1363 width, height, state_type, area))
1367 else if (detail && !strcmp (detail, "spinbutton"))
1369 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1374 else if (detail && (!strcmp (detail, "spinbutton_up")
1375 || !strcmp (detail, "spinbutton_down")))
1377 if (xp_theme_draw(window,
1378 (! strcmp (detail, "spinbutton_up"))
1379 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1380 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1381 style, x, y, width, height, state_type, area))
1387 else if (detail && !strcmp (detail, "slider"))
1389 if (GTK_IS_SCROLLBAR(widget))
1391 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1392 gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1393 if (xp_theme_draw(window,
1395 ? XP_THEME_ELEMENT_SCROLLBAR_V
1396 : XP_THEME_ELEMENT_SCROLLBAR_H,
1397 style, x, y, width, height, state_type, area))
1399 XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1401 /* Do not display grippers on tiny scroll bars, the limit imposed
1402 is rather arbitrary, perhaps we can fetch the gripper geometry
1403 from somewhere and use that... */
1404 if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1405 || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1410 xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1415 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1420 else if (detail && !strcmp (detail, "bar"))
1422 if (widget && GTK_IS_PROGRESS_BAR (widget))
1424 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1425 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1426 if (xp_theme_draw (window, xp_progress_bar,
1427 style, x, y, width, height, state_type, area))
1433 else if (detail && strcmp (detail, "menuitem") == 0) {
1434 shadow_type = GTK_SHADOW_NONE;
1435 if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1440 else if (detail && !strcmp (detail, "trough"))
1442 if (widget && GTK_IS_PROGRESS_BAR (widget))
1444 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1445 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1446 if (xp_theme_draw (window, xp_progress_bar,
1447 style, x, y, width, height, state_type, area))
1453 /* Blank in classic Windows */
1456 else if (widget && GTK_IS_SCROLLBAR(widget))
1458 gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1460 if (GTK_IS_RANGE(widget)
1461 && xp_theme_draw(window,
1463 ? XP_THEME_ELEMENT_TROUGH_V
1464 : XP_THEME_ELEMENT_TROUGH_H,
1466 x, y, width, height, state_type, area))
1472 GdkGCValues gc_values;
1476 sanitize_size (window, &width, &height);
1478 pixmap = gdk_pixmap_new (window, 2, 2, -1);
1480 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1481 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1482 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1483 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1485 gc_values.fill = GDK_TILED;
1486 gc_values.tile = pixmap;
1487 gc_values.ts_x_origin = x;
1488 gc_values.ts_y_origin = y;
1489 gc = gdk_gc_new_with_values (window, &gc_values,
1490 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1493 gdk_gc_set_clip_rectangle (gc, area);
1495 gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1498 gdk_drawable_unref (pixmap);
1503 else if (widget && GTK_IS_SCALE(widget))
1505 gboolean is_vertical = GTK_IS_VSCALE(widget);
1507 parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1508 widget, detail, x, y, width, height);
1511 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1513 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1518 else if (detail && strcmp (detail, "optionmenu") == 0)
1520 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1521 style, x, y, width, height, state_type, area))
1526 else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1528 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1529 if (shadow_type == GTK_SHADOW_IN)
1530 shadow_type = GTK_SHADOW_ETCHED_IN;
1531 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1532 shadow_type = GTK_SHADOW_OUT;
1536 const gchar * name = gtk_widget_get_name (widget);
1538 if (name && !strcmp (name, "gtk-tooltips")) {
1539 if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1546 parent_class->draw_box (style, window, state_type, shadow_type, area,
1547 widget, detail, x, y, width, height);
1549 if (detail && strcmp (detail, "optionmenu") == 0)
1551 GtkRequisition indicator_size;
1552 GtkBorder indicator_spacing;
1555 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1557 sanitize_size (window, &width, &height);
1559 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1560 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1562 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1564 parent_class->draw_vline (style, window, state_type, area, widget,
1566 y + style->ythickness + 1,
1567 y + height - style->ythickness - 3,
1573 draw_tab (GtkStyle *style,
1576 GtkShadowType shadow,
1579 const gchar *detail,
1585 GtkRequisition indicator_size;
1586 GtkBorder indicator_spacing;
1590 g_return_if_fail (style != NULL);
1591 g_return_if_fail (window != NULL);
1593 if (detail && ! strcmp (detail, "optionmenutab"))
1595 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1596 style, x-5, widget->allocation.y+1,
1597 width+10, widget->allocation.height-2, state, area))
1604 gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1606 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1608 x += (width - indicator_size.width) / 2;
1609 arrow_height = (indicator_size.width + 1) / 2;
1611 y += (height - arrow_height) / 2;
1613 draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1614 x, y, indicator_size.width, arrow_height);
1617 /* this is an undefined magic value that, according to the mozilla folks,
1618 worked for all the various themes that they tried */
1619 #define XP_EDGE_SIZE 2
1622 draw_extension(GtkStyle *style,
1624 GtkStateType state_type,
1625 GtkShadowType shadow_type,
1628 const gchar *detail,
1633 GtkPositionType gap_side)
1635 if (detail && !strcmp(detail, "tab"))
1637 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1638 GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1640 if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1641 height += XP_EDGE_SIZE;
1644 /* FIXME: pos != TOP to be implemented */
1645 else if (pos_type == GTK_POS_BOTTOM)
1647 else if (pos_type == GTK_POS_RIGHT)
1648 width += XP_EDGE_SIZE;
1649 else if (pos_type == GTK_POS_LEFT)
1650 height -= XP_EDGE_SIZE;
1653 if (pos_type == GTK_POS_TOP
1655 (window, gtk_notebook_get_current_page(notebook)==0
1656 ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1657 : XP_THEME_ELEMENT_TAB_ITEM,
1658 style, x, y, width, height, state_type, area))
1663 parent_class->draw_extension
1664 (style, window, state_type, shadow_type, area, widget, detail,
1665 x, y, width, height, gap_side);
1669 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1670 GtkShadowType shadow_type, GdkRectangle *area,
1671 GtkWidget *widget, const gchar *detail, gint x,
1672 gint y, gint width, gint height, GtkPositionType gap_side,
1673 gint gap_x, gint gap_width)
1675 if (detail && !strcmp(detail, "notebook"))
1677 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1679 /* FIXME: pos != TOP to be implemented */
1680 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
1686 parent_class->draw_box_gap(style, window, state_type, shadow_type,
1687 area, widget, detail, x, y, width, height,
1688 gap_side, gap_x, gap_width);
1692 draw_flat_box (GtkStyle *style, GdkWindow *window,
1693 GtkStateType state_type, GtkShadowType shadow_type,
1694 GdkRectangle *area, GtkWidget *widget,
1695 const gchar *detail, gint x, gint y,
1696 gint width, gint height)
1698 if (detail && ! strcmp (detail, "checkbutton"))
1700 if (state_type == GTK_STATE_PRELIGHT)
1706 parent_class->draw_flat_box(style, window, state_type, shadow_type,
1707 area, widget, detail, x, y, width, height);
1711 draw_shadow (GtkStyle *style,
1713 GtkStateType state_type,
1714 GtkShadowType shadow_type,
1717 const gchar *detail,
1723 if(detail && ! strcmp(detail, "entry"))
1725 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1726 x, y, width, height, state_type, area))
1731 parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1732 detail, x, y, width, height);
1736 draw_hline (GtkStyle *style,
1738 GtkStateType state_type,
1741 const gchar *detail,
1747 if (detail && !strcmp(detail, "menuitem")) {
1748 if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1749 x1, y, x2, style->ythickness, state_type, area)) {
1754 parent_class->draw_hline (style, window, state_type, area, widget,
1759 draw_vline (GtkStyle *style,
1761 GtkStateType state_type,
1764 const gchar *detail,
1769 parent_class->draw_vline (style, window, state_type, area, widget,
1774 draw_resize_grip (GtkStyle *style,
1776 GtkStateType state_type,
1779 const gchar *detail,
1786 if (detail && !strcmp(detail, "statusbar")) {
1787 if (!xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1792 parent_class->draw_resize_grip (style, window, state_type, area,
1793 widget, detail, edge, x, y, width, height);
1797 draw_handle (GtkStyle *style,
1799 GtkStateType state_type,
1800 GtkShadowType shadow_type,
1803 const gchar *detail,
1808 GtkOrientation orientation)
1810 if (GTK_IS_HANDLE_BOX (widget))
1812 XpThemeElement hndl;
1814 sanitize_size (window, &width, &height);
1816 if (orientation == GTK_ORIENTATION_VERTICAL)
1817 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1819 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1821 if (xp_theme_draw (window, hndl, style, x, y, width, height,
1827 /* grippers are just flat boxes when they're not a toolbar */
1828 parent_class->draw_box (style, window, state_type, shadow_type,
1829 area, widget, detail, x, y, width, height);
1831 else if (!GTK_IS_PANED (widget))
1833 /* TODO: Draw handle boxes as double lines: || */
1834 parent_class->draw_handle (style, window, state_type, shadow_type,
1835 area, widget, detail, x, y, width, height,
1841 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
1843 setup_system_font (style);
1844 setup_menu_settings (gtk_settings_get_default ());
1845 setup_system_styles (style);
1846 parent_class->init_from_rc(style, rc_style);
1850 msw_style_class_init (MswStyleClass *klass)
1852 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1854 parent_class = g_type_class_peek_parent (klass);
1856 style_class->init_from_rc = msw_style_init_from_rc;
1857 style_class->draw_arrow = draw_arrow;
1858 style_class->draw_box = draw_box;
1859 style_class->draw_check = draw_check;
1860 style_class->draw_option = draw_option;
1861 style_class->draw_tab = draw_tab;
1862 style_class->draw_flat_box = draw_flat_box;
1863 style_class->draw_expander = draw_expander;
1864 style_class->draw_extension = draw_extension;
1865 style_class->draw_box_gap = draw_box_gap;
1866 style_class->draw_shadow = draw_shadow;
1867 style_class->draw_hline = draw_hline;
1868 style_class->draw_vline = draw_vline;
1869 style_class->draw_handle = draw_handle;
1870 style_class->draw_resize_grip = draw_resize_grip;
1873 GType msw_type_style = 0;
1876 msw_style_register_type (GTypeModule *module)
1878 static const GTypeInfo object_info =
1880 sizeof (MswStyleClass),
1881 (GBaseInitFunc) NULL,
1882 (GBaseFinalizeFunc) NULL,
1883 (GClassInitFunc) msw_style_class_init,
1884 NULL, /* class_finalize */
1885 NULL, /* class_data */
1887 0, /* n_preallocs */
1888 (GInstanceInitFunc) NULL,
1891 msw_type_style = g_type_module_register_type (module,
1898 msw_style_init (void)
1901 msw_style_setup_system_settings ();
1902 setup_msw_rc_style ();