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;
1167 static XpThemeElement to_xp_arrow(GtkArrowType arrow_type)
1169 XpThemeElement xp_arrow;
1174 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1176 case GTK_ARROW_DOWN:
1177 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1179 case GTK_ARROW_LEFT:
1180 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1183 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1191 draw_arrow (GtkStyle *style,
1194 GtkShadowType shadow,
1197 const gchar *detail,
1198 GtkArrowType arrow_type,
1207 name = gtk_widget_get_name (widget);
1209 sanitize_size (window, &width, &height);
1211 if (detail && strcmp (detail, "spinbutton") == 0)
1213 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1219 x += (width - 7) / 2;
1221 if (arrow_type == GTK_ARROW_UP)
1222 y += (height - 4) / 2;
1224 y += (1 + height - 4) / 2;
1225 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1229 else if (detail && (!strcmp (detail, "vscrollbar")
1230 || !strcmp (detail, "hscrollbar")))
1232 gboolean is_disabled = FALSE;
1233 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1236 gint box_width = width;
1237 gint box_height = height;
1239 reverse_engineer_stepper_box (widget, arrow_type,
1240 &box_x, &box_y, &box_width, &box_height);
1242 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1245 if (xp_theme_draw(window, to_xp_arrow(arrow_type), style, box_x, box_y, box_width, box_height, state, area))
1248 else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1250 x += (width - 7) / 2;
1251 y += (height - 5) / 2;
1253 draw_varrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1258 y += (height - 7) / 2;
1259 x += (width - 5) / 2;
1261 draw_harrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1267 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1268 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1270 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1273 /* probably a gtk combo box on a toolbar */
1274 else if (widget->parent && GTK_IS_BUTTON (widget->parent))
1276 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON, style, x-3, widget->allocation.y+1,
1277 width+5, widget->allocation.height-4, state, area))
1281 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1283 x += (width - 7) / 2;
1284 y += (height - 5) / 2;
1286 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1291 x += (width - 5) / 2;
1292 y += (height - 7) / 2;
1294 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1301 option_menu_get_props (GtkWidget *widget,
1302 GtkRequisition *indicator_size,
1303 GtkBorder *indicator_spacing)
1305 GtkRequisition *tmp_size = NULL;
1306 GtkBorder *tmp_spacing = NULL;
1309 gtk_widget_style_get (widget,
1310 "indicator_size", &tmp_size,
1311 "indicator_spacing", &tmp_spacing,
1316 *indicator_size = *tmp_size;
1320 *indicator_size = default_option_indicator_size;
1324 *indicator_spacing = *tmp_spacing;
1325 g_free (tmp_spacing);
1328 *indicator_spacing = default_option_indicator_spacing;
1331 static gboolean is_toolbar_child(GtkWidget * wid)
1335 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1345 draw_box (GtkStyle *style,
1347 GtkStateType state_type,
1348 GtkShadowType shadow_type,
1351 const gchar *detail,
1358 (!strcmp (detail, "button") ||
1359 !strcmp (detail, "buttondefault")))
1361 if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1363 if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1364 width, height, state_type, area))
1367 else if (is_toolbar_child (widget->parent))
1369 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1370 width, height, state_type, area))
1375 gboolean is_default = !strcmp (detail, "buttondefault");
1376 if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1377 : XP_THEME_ELEMENT_BUTTON, style, x, y,
1378 width, height, state_type, area))
1382 else if (detail && !strcmp (detail, "spinbutton"))
1384 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1389 else if (detail && (!strcmp (detail, "spinbutton_up")
1390 || !strcmp (detail, "spinbutton_down")))
1392 if (xp_theme_draw(window,
1393 (! strcmp (detail, "spinbutton_up"))
1394 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1395 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1396 style, x, y, width, height, state_type, area))
1402 else if (detail && !strcmp (detail, "slider"))
1404 if (GTK_IS_SCROLLBAR(widget))
1406 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1407 gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1408 if (xp_theme_draw(window,
1410 ? XP_THEME_ELEMENT_SCROLLBAR_V
1411 : XP_THEME_ELEMENT_SCROLLBAR_H,
1412 style, x, y, width, height, state_type, area))
1414 XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1416 /* Do not display grippers on tiny scroll bars, the limit imposed
1417 is rather arbitrary, perhaps we can fetch the gripper geometry
1418 from somewhere and use that... */
1419 if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1420 || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1425 xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1430 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1435 else if (detail && !strcmp (detail, "bar"))
1437 if (widget && GTK_IS_PROGRESS_BAR (widget))
1439 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1440 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1441 if (xp_theme_draw (window, xp_progress_bar,
1442 style, x, y, width, height, state_type, area))
1448 else if (detail && strcmp (detail, "menuitem") == 0) {
1449 shadow_type = GTK_SHADOW_NONE;
1450 if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1455 else if (detail && !strcmp (detail, "trough"))
1457 if (widget && GTK_IS_PROGRESS_BAR (widget))
1459 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1460 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1461 if (xp_theme_draw (window, xp_progress_bar,
1462 style, x, y, width, height, state_type, area))
1468 /* Blank in classic Windows */
1471 else if (widget && GTK_IS_SCROLLBAR(widget))
1473 gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1475 if (GTK_IS_RANGE(widget)
1476 && xp_theme_draw(window,
1478 ? XP_THEME_ELEMENT_TROUGH_V
1479 : XP_THEME_ELEMENT_TROUGH_H,
1481 x, y, width, height, state_type, area))
1487 GdkGCValues gc_values;
1491 sanitize_size (window, &width, &height);
1493 pixmap = gdk_pixmap_new (window, 2, 2, -1);
1495 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1496 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1497 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1498 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1500 gc_values.fill = GDK_TILED;
1501 gc_values.tile = pixmap;
1502 gc_values.ts_x_origin = x;
1503 gc_values.ts_y_origin = y;
1504 gc = gdk_gc_new_with_values (window, &gc_values,
1505 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1508 gdk_gc_set_clip_rectangle (gc, area);
1510 gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1513 gdk_drawable_unref (pixmap);
1518 else if (widget && GTK_IS_SCALE(widget))
1520 gboolean is_vertical = GTK_IS_VSCALE(widget);
1522 parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1523 widget, detail, x, y, width, height);
1526 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1528 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1533 else if (detail && strcmp (detail, "optionmenu") == 0)
1535 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1536 style, x, y, width, height, state_type, area))
1541 else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1543 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1544 if (shadow_type == GTK_SHADOW_IN)
1545 shadow_type = GTK_SHADOW_ETCHED_IN;
1546 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1547 shadow_type = GTK_SHADOW_OUT;
1551 const gchar * name = gtk_widget_get_name (widget);
1553 if (name && !strcmp (name, "gtk-tooltips")) {
1554 if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1561 parent_class->draw_box (style, window, state_type, shadow_type, area,
1562 widget, detail, x, y, width, height);
1564 if (detail && strcmp (detail, "optionmenu") == 0)
1566 GtkRequisition indicator_size;
1567 GtkBorder indicator_spacing;
1570 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1572 sanitize_size (window, &width, &height);
1574 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1575 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1577 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1579 parent_class->draw_vline (style, window, state_type, area, widget,
1581 y + style->ythickness + 1,
1582 y + height - style->ythickness - 3,
1588 draw_tab (GtkStyle *style,
1591 GtkShadowType shadow,
1594 const gchar *detail,
1600 GtkRequisition indicator_size;
1601 GtkBorder indicator_spacing;
1605 g_return_if_fail (style != NULL);
1606 g_return_if_fail (window != NULL);
1608 if (detail && ! strcmp (detail, "optionmenutab"))
1610 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1611 style, x-5, widget->allocation.y+1,
1612 width+10, widget->allocation.height-2, state, area))
1619 gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1621 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1623 x += (width - indicator_size.width) / 2;
1624 arrow_height = (indicator_size.width + 1) / 2;
1626 y += (height - arrow_height) / 2;
1628 draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1629 x, y, indicator_size.width, arrow_height);
1632 /* this is an undefined magic value that, according to the mozilla folks,
1633 worked for all the various themes that they tried */
1634 #define XP_EDGE_SIZE 2
1637 draw_extension(GtkStyle *style,
1639 GtkStateType state_type,
1640 GtkShadowType shadow_type,
1643 const gchar *detail,
1648 GtkPositionType gap_side)
1650 if (detail && !strcmp(detail, "tab"))
1652 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1653 GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1655 if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1656 height += XP_EDGE_SIZE;
1659 /* FIXME: pos != TOP to be implemented */
1660 else if (pos_type == GTK_POS_BOTTOM)
1662 else if (pos_type == GTK_POS_RIGHT)
1663 width += XP_EDGE_SIZE;
1664 else if (pos_type == GTK_POS_LEFT)
1665 height -= XP_EDGE_SIZE;
1668 if (pos_type == GTK_POS_TOP
1670 (window, gtk_notebook_get_current_page(notebook)==0
1671 ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1672 : XP_THEME_ELEMENT_TAB_ITEM,
1673 style, x, y, width, height, state_type, area))
1678 parent_class->draw_extension
1679 (style, window, state_type, shadow_type, area, widget, detail,
1680 x, y, width, height, gap_side);
1684 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1685 GtkShadowType shadow_type, GdkRectangle *area,
1686 GtkWidget *widget, const gchar *detail, gint x,
1687 gint y, gint width, gint height, GtkPositionType gap_side,
1688 gint gap_x, gint gap_width)
1690 if (detail && !strcmp(detail, "notebook"))
1692 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1694 /* FIXME: pos != TOP to be implemented */
1695 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
1701 parent_class->draw_box_gap(style, window, state_type, shadow_type,
1702 area, widget, detail, x, y, width, height,
1703 gap_side, gap_x, gap_width);
1707 draw_flat_box (GtkStyle *style, GdkWindow *window,
1708 GtkStateType state_type, GtkShadowType shadow_type,
1709 GdkRectangle *area, GtkWidget *widget,
1710 const gchar *detail, gint x, gint y,
1711 gint width, gint height)
1713 if (detail && ! strcmp (detail, "checkbutton"))
1715 if (state_type == GTK_STATE_PRELIGHT)
1721 parent_class->draw_flat_box(style, window, state_type, shadow_type,
1722 area, widget, detail, x, y, width, height);
1726 draw_shadow (GtkStyle *style,
1728 GtkStateType state_type,
1729 GtkShadowType shadow_type,
1732 const gchar *detail,
1738 if(detail && ! strcmp(detail, "entry"))
1740 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1741 x, y, width, height, state_type, area))
1746 parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1747 detail, x, y, width, height);
1751 draw_hline (GtkStyle *style,
1753 GtkStateType state_type,
1756 const gchar *detail,
1762 if (detail && !strcmp(detail, "menuitem")) {
1763 if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1764 x1, y, x2, style->ythickness, state_type, area)) {
1769 parent_class->draw_hline (style, window, state_type, area, widget,
1774 draw_vline (GtkStyle *style,
1776 GtkStateType state_type,
1779 const gchar *detail,
1784 parent_class->draw_vline (style, window, state_type, area, widget,
1789 draw_resize_grip (GtkStyle *style,
1791 GtkStateType state_type,
1794 const gchar *detail,
1801 if (detail && !strcmp(detail, "statusbar")) {
1802 if (xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1807 parent_class->draw_resize_grip (style, window, state_type, area,
1808 widget, detail, edge, x, y, width, height);
1812 draw_handle (GtkStyle *style,
1814 GtkStateType state_type,
1815 GtkShadowType shadow_type,
1818 const gchar *detail,
1823 GtkOrientation orientation)
1825 if (is_toolbar_child (widget))
1827 XpThemeElement hndl;
1829 sanitize_size (window, &width, &height);
1831 if (orientation == GTK_ORIENTATION_VERTICAL)
1832 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1834 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1836 if (xp_theme_draw (window, hndl, style, x, y, width, height,
1842 /* grippers are just flat boxes when they're not a toolbar */
1843 parent_class->draw_box (style, window, state_type, shadow_type,
1844 area, widget, detail, x, y, width, height);
1846 else if (!GTK_IS_PANED (widget))
1848 /* TODO: Draw handle boxes as double lines: || */
1849 parent_class->draw_handle (style, window, state_type, shadow_type,
1850 area, widget, detail, x, y, width, height,
1856 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
1858 setup_system_font (style);
1859 setup_menu_settings (gtk_settings_get_default ());
1860 setup_system_styles (style);
1861 parent_class->init_from_rc(style, rc_style);
1865 msw_style_class_init (MswStyleClass *klass)
1867 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1869 parent_class = g_type_class_peek_parent (klass);
1871 style_class->init_from_rc = msw_style_init_from_rc;
1872 style_class->draw_arrow = draw_arrow;
1873 style_class->draw_box = draw_box;
1874 style_class->draw_check = draw_check;
1875 style_class->draw_option = draw_option;
1876 style_class->draw_tab = draw_tab;
1877 style_class->draw_flat_box = draw_flat_box;
1878 style_class->draw_expander = draw_expander;
1879 style_class->draw_extension = draw_extension;
1880 style_class->draw_box_gap = draw_box_gap;
1881 style_class->draw_shadow = draw_shadow;
1882 style_class->draw_hline = draw_hline;
1883 style_class->draw_vline = draw_vline;
1884 style_class->draw_handle = draw_handle;
1885 style_class->draw_resize_grip = draw_resize_grip;
1888 GType msw_type_style = 0;
1891 msw_style_register_type (GTypeModule *module)
1893 static const GTypeInfo object_info =
1895 sizeof (MswStyleClass),
1896 (GBaseInitFunc) NULL,
1897 (GBaseFinalizeFunc) NULL,
1898 (GClassInitFunc) msw_style_class_init,
1899 NULL, /* class_finalize */
1900 NULL, /* class_data */
1902 0, /* n_preallocs */
1903 (GInstanceInitFunc) NULL,
1906 msw_type_style = g_type_module_register_type (module,
1913 msw_style_init (void)
1916 msw_style_setup_system_settings ();
1917 setup_msw_rc_style ();