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.
26 * http://lxr.mozilla.org/mozilla/source/gfx/src/windows/nsNativeThemeWin.cpp
27 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/functions/drawthemebackground.asp
30 #include "msw_style.h"
40 /* #include <gdk/gdkwin32.h> */
41 #include "gdk/win32/gdkwin32.h"
44 /* Default values, not normally used
46 static const GtkRequisition default_option_indicator_size = { 9, 8 };
47 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
49 static GtkStyleClass *parent_class;
69 static const char check_aa_bits[] = {
70 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
71 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
72 static const char check_base_bits[] = {
73 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
74 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
75 static const char check_black_bits[] = {
76 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
77 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
78 static const char check_dark_bits[] = {
79 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
80 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
81 static const char check_light_bits[] = {
82 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
83 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
84 static const char check_mid_bits[] = {
85 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
86 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
87 static const char check_text_bits[] = {
88 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x88,0x03,0xd8,0x01,0xf8,
89 0x00,0x70,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
90 static const char radio_base_bits[] = {
91 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
92 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
93 static const char radio_black_bits[] = {
94 0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
95 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
96 static const char radio_dark_bits[] = {
97 0xf0,0x01,0x0c,0x06,0x02,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
98 0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
99 static const char radio_light_bits[] = {
100 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
101 0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x0c,0x06,0xf0,0x01};
102 static const char radio_mid_bits[] = {
103 0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
104 0x08,0x00,0x08,0x00,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00};
105 static const char radio_text_bits[] = {
106 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
107 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
113 { check_aa_bits, NULL },
114 { check_base_bits, NULL },
115 { check_black_bits, NULL },
116 { check_dark_bits, NULL },
117 { check_light_bits, NULL },
118 { check_mid_bits, NULL },
119 { check_text_bits, NULL },
120 { radio_base_bits, NULL },
121 { radio_black_bits, NULL },
122 { radio_dark_bits, NULL },
123 { radio_light_bits, NULL },
124 { radio_mid_bits, NULL },
125 { radio_text_bits, NULL }
129 get_system_font(XpThemeClass klazz, XpThemeFont type, LOGFONT *out_lf)
132 /* TODO: this crashes. need to figure out why and how to fix it */
133 if (xp_theme_get_system_font(klazz, type, out_lf))
138 NONCLIENTMETRICS ncm;
139 ncm.cbSize = sizeof(NONCLIENTMETRICS);
141 if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
142 sizeof(NONCLIENTMETRICS), &ncm, 0))
144 if (type == XP_THEME_FONT_CAPTION)
145 *out_lf = ncm.lfCaptionFont;
146 else if (type == XP_THEME_FONT_MENU)
147 *out_lf = ncm.lfMenuFont;
148 else if (type == XP_THEME_FONT_STATUS)
149 *out_lf = ncm.lfStatusFont;
151 *out_lf = ncm.lfMessageFont;
159 /***************************** BEGIN STOLEN FROM PANGO *****************************/
162 This code is stolen from Pango 1.4. It attempts to address the following problems:
164 http://bugzilla.gnome.org/show_bug.cgi?id=135098
165 http://sourceforge.net/tracker/index.php?func=detail&aid=895762&group_id=76416&atid=547655
167 As Owen suggested in bug 135098, once Pango 1.6 is released, we need to get rid of this code.
170 #define PING(printlist)
172 /* TrueType defines: */
174 #define MAKE_TT_TABLE_NAME(c1, c2, c3, c4) \
175 (((guint32)c4) << 24 | ((guint32)c3) << 16 | ((guint32)c2) << 8 | ((guint32)c1))
177 #define CMAP (MAKE_TT_TABLE_NAME('c','m','a','p'))
178 #define CMAP_HEADER_SIZE 4
180 #define NAME (MAKE_TT_TABLE_NAME('n','a','m','e'))
181 #define NAME_HEADER_SIZE 6
183 #define ENCODING_TABLE_SIZE 8
185 #define APPLE_UNICODE_PLATFORM_ID 0
186 #define MACINTOSH_PLATFORM_ID 1
187 #define ISO_PLATFORM_ID 2
188 #define MICROSOFT_PLATFORM_ID 3
190 #define SYMBOL_ENCODING_ID 0
191 #define UNICODE_ENCODING_ID 1
192 #define UCS4_ENCODING_ID 10
196 guint16 format_selector;
198 guint16 string_storage_offset;
207 guint16 string_length;
208 guint16 string_offset;
212 pango_win32_get_name_header (HDC hdc,
213 struct name_header *header)
215 if (GetFontData (hdc, NAME, 0, header, sizeof (*header)) != sizeof (*header))
218 header->num_records = GUINT16_FROM_BE (header->num_records);
219 header->string_storage_offset = GUINT16_FROM_BE (header->string_storage_offset);
225 pango_win32_get_name_record (HDC hdc,
227 struct name_record *record)
229 if (GetFontData (hdc, NAME, 6 + i * sizeof (*record),
230 record, sizeof (*record)) != sizeof (*record))
233 record->platform_id = GUINT16_FROM_BE (record->platform_id);
234 record->encoding_id = GUINT16_FROM_BE (record->encoding_id);
235 record->language_id = GUINT16_FROM_BE (record->language_id);
236 record->name_id = GUINT16_FROM_BE (record->name_id);
237 record->string_length = GUINT16_FROM_BE (record->string_length);
238 record->string_offset = GUINT16_FROM_BE (record->string_offset);
244 get_family_name (LOGFONT *lfp, HDC pango_win32_hdc)
249 struct name_header header;
250 struct name_record record;
252 gint unicode_ix = -1, mac_ix = -1, microsoft_ix = -1;
256 gchar *string = NULL;
262 /* If lfFaceName is ASCII, assume it is the common (English) name
263 * for the font. Is this valid? Do some TrueType fonts have
264 * different names in French, German, etc, and does the system
265 * return these if the locale is set to use French, German, etc?
267 l = strlen (lfp->lfFaceName);
268 for (i = 0; i < l; i++)
269 if (lfp->lfFaceName[i] < ' ' || lfp->lfFaceName[i] > '~')
273 return g_strdup (lfp->lfFaceName);
275 if ((hfont = CreateFontIndirect (lfp)) == NULL)
278 if ((oldhfont = SelectObject (pango_win32_hdc, hfont)) == NULL)
281 if (!pango_win32_get_name_header (pango_win32_hdc, &header))
284 PING (("%d name records", header.num_records));
286 for (i = 0; i < header.num_records; i++)
288 if (!pango_win32_get_name_record (pango_win32_hdc, i, &record))
291 if ((record.name_id != 1 && record.name_id != 16) || record.string_length <= 0)
294 PING(("platform:%d encoding:%d language:%04x name_id:%d",
295 record.platform_id, record.encoding_id, record.language_id, record.name_id));
297 if (record.platform_id == APPLE_UNICODE_PLATFORM_ID ||
298 record.platform_id == ISO_PLATFORM_ID)
300 else if (record.platform_id == MACINTOSH_PLATFORM_ID &&
301 record.encoding_id == 0 && /* Roman */
302 record.language_id == 0) /* English */
304 else if (record.platform_id == MICROSOFT_PLATFORM_ID)
305 if ((microsoft_ix == -1 ||
306 PRIMARYLANGID (record.language_id) == LANG_ENGLISH) &&
307 (record.encoding_id == SYMBOL_ENCODING_ID ||
308 record.encoding_id == UNICODE_ENCODING_ID ||
309 record.encoding_id == UCS4_ENCODING_ID))
313 if (microsoft_ix >= 0)
314 name_ix = microsoft_ix;
315 else if (mac_ix >= 0)
317 else if (unicode_ix >= 0)
318 name_ix = unicode_ix;
322 if (!pango_win32_get_name_record (pango_win32_hdc, name_ix, &record))
325 string = g_malloc (record.string_length + 1);
326 if (GetFontData (pango_win32_hdc, NAME,
327 header.string_storage_offset + record.string_offset,
328 string, record.string_length) != record.string_length)
331 string[record.string_length] = '\0';
333 if (name_ix == microsoft_ix)
334 if (record.encoding_id == SYMBOL_ENCODING_ID ||
335 record.encoding_id == UNICODE_ENCODING_ID)
336 codeset = "UTF-16BE";
339 else if (name_ix == mac_ix)
340 codeset = "MacRoman";
341 else /* name_ix == unicode_ix */
344 name = g_convert (string, record.string_length, "UTF-8", codeset, NULL, &nbytes, NULL);
351 SelectObject (pango_win32_hdc, oldhfont);
352 DeleteObject (hfont);
358 SelectObject (pango_win32_hdc, oldhfont);
361 DeleteObject (hfont);
364 return g_locale_to_utf8 (lfp->lfFaceName, -1, NULL, NULL, NULL);
367 /***************************** END STOLEN FROM PANGO *****************************/
370 sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char * buf, size_t bufsiz)
380 if (get_system_font(klazz, type, &lf))
382 switch (lf.lfWeight) {
385 weight = "Ultra-Light";
397 weight = "Semi-Bold";
401 weight = "Ultra-Bold";
418 hwnd = GetDesktopWindow();
421 pt_size = -MulDiv(lf.lfHeight, 72,
422 GetDeviceCaps(hDC,LOGPIXELSY));
423 ReleaseDC(hwnd, hDC);
427 font = get_family_name(&lf, hDC);
428 g_snprintf(buf, bufsiz, "%s %s %s %d", font, style, weight, pt_size);
437 /* missing from ms's header files */
438 #ifndef SPI_GETMENUSHOWDELAY
439 #define SPI_GETMENUSHOWDELAY 106
442 /* I don't know the proper XP theme class for things like
443 HIGHLIGHTTEXT, so we'll just define it to be "BUTTON"
445 #define XP_THEME_CLASS_TEXT XP_THEME_CLASS_BUTTON
448 setup_menu_settings (GtkSettings * settings)
451 gboolean win95 = FALSE;
452 OSVERSIONINFOEX osvi;
453 GObjectClass * klazz = G_OBJECT_GET_CLASS(G_OBJECT(settings));
455 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
456 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
458 if (!GetVersionEx ( (OSVERSIONINFO *) &osvi))
459 win95 = TRUE; /* assume the worst */
461 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
462 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
466 if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0)) {
468 if (g_object_class_find_property (klazz, "gtk-menu-bar-popup-delay")) {
469 g_object_set (settings, "gtk-menu-bar-popup-delay", 0, NULL);
471 if (g_object_class_find_property (klazz, "gtk-menu-popup-delay")) {
472 g_object_set (settings, "gtk-menu-popup-delay", menu_delay, NULL);
474 if (g_object_class_find_property (klazz, "gtk-menu-popdown-delay")) {
475 g_object_set (settings, "gtk-menu-popdown-delay", menu_delay, NULL);
483 msw_style_setup_system_settings (void)
485 GtkSettings * settings;
486 int cursor_blink_time;
488 settings = gtk_settings_get_default ();
492 cursor_blink_time = GetCaretBlinkTime ();
493 g_object_set (settings, "gtk-cursor-blink", cursor_blink_time > 0, NULL);
495 if (cursor_blink_time > 0)
496 g_object_set (settings, "gtk-cursor-blink-time", 2*cursor_blink_time,
499 g_object_set (settings, "gtk-double-click-distance", GetSystemMetrics(SM_CXDOUBLECLK), NULL);
500 g_object_set (settings, "gtk-double-click-time", GetDoubleClickTime(), NULL);
501 g_object_set (settings, "gtk-dnd-drag-threshold", GetSystemMetrics(SM_CXDRAG), NULL);
503 setup_menu_settings (settings);
506 http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
507 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
508 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp
513 setup_system_font(GtkStyle *style)
515 char buf[256], * font; /* It's okay, lfFaceName is smaller than 32 chars */
517 if ((font = sys_font_to_pango_font(XP_THEME_CLASS_TEXT,
518 XP_THEME_FONT_MESSAGE,
519 buf, sizeof (buf))) != NULL)
521 if (style->font_desc)
522 pango_font_description_free (style->font_desc);
524 style->font_desc = pango_font_description_from_string(font);
529 sys_color_to_gtk_color(XpThemeClass klazz, int id, GdkColor *pcolor)
533 if (!xp_theme_get_system_color (klazz, id, &color))
534 color = GetSysColor(id);
536 pcolor->pixel = color;
537 pcolor->red = (GetRValue(color) << 8) | GetRValue(color);
538 pcolor->green = (GetGValue(color) << 8) | GetGValue(color);
539 pcolor->blue = (GetBValue(color) << 8) | GetBValue(color);
543 get_system_metric(XpThemeClass klazz, int id)
547 if (!xp_theme_get_system_metric(klazz, id, &rval))
548 rval = GetSystemMetrics (id);
554 setup_msw_rc_style(void)
557 "If your setup_system_styles() function called gtk_rc_parse_string(), then you are just piling a new set of strings on top each time the theme changes .. the old ones won't be removed" */
559 char buf[1024], font_buf[256], *font_ptr;
562 GdkColor menu_text_color;
563 GdkColor tooltip_back;
564 GdkColor tooltip_fore;
567 GdkColor progress_back;
569 GdkColor fg_prelight;
570 GdkColor bg_prelight;
571 GdkColor base_prelight;
572 GdkColor text_prelight;
575 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &fg_prelight);
576 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
577 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &base_prelight);
578 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &text_prelight);
580 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENUTEXT, &menu_text_color);
581 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);
584 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT, &tooltip_fore);
585 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK, &tooltip_back);
587 /* text on push buttons. TODO: button shadows, backgrounds, and highlights */
588 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
589 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
591 /* progress bar background color */
592 sys_color_to_gtk_color(XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT, &progress_back);
594 /* Enable coloring for menus. */
595 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,font_buf, sizeof (font_buf));
596 g_snprintf(buf, sizeof (buf),
597 "style \"msw-menu\" = \"msw-default\"\n"
599 "fg[PRELIGHT] = { %d, %d, %d }\n"
600 "bg[PRELIGHT] = { %d, %d, %d }\n"
601 "text[PRELIGHT] = { %d, %d, %d }\n"
602 "base[PRELIGHT] = { %d, %d, %d }\n"
603 "fg[NORMAL] = { %d, %d, %d }\n"
604 "bg[NORMAL] = { %d, %d, %d }\n"
606 "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
607 "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
608 "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
622 menu_text_color.green,
623 menu_text_color.blue,
627 (font_ptr ? "font_name" : "#"),
628 (font_ptr ? font_ptr : " font name should go here"));
629 gtk_rc_parse_string(buf);
631 /* Enable coloring for menu bars. */
632 g_snprintf(buf, sizeof (buf),
633 "style \"msw-menu-bar\" = \"msw-menu\"\n"
635 "bg[NORMAL] = { %d, %d, %d }\n"
636 "GtkMenuBar::shadow-type = out\n"
637 "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
641 gtk_rc_parse_string(buf);
643 /* enable tooltip fonts */
644 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
645 g_snprintf(buf, sizeof (buf),
646 "style \"msw-tooltips-caption\" = \"msw-default\"\n"
647 "{fg[NORMAL] = { %d, %d, %d }\n"
649 "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
653 (font_ptr ? "font_name" : "#"),
654 (font_ptr ? font_ptr : " font name should go here"));
655 gtk_rc_parse_string(buf);
657 g_snprintf(buf, sizeof (buf),
658 "style \"msw-tooltips\" = \"msw-default\"\n"
659 "{bg[NORMAL] = { %d, %d, %d }\n"
660 "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
664 gtk_rc_parse_string(buf);
666 /* enable font theming for status bars */
667 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
668 g_snprintf(buf, sizeof (buf),
669 "style \"msw-status\" = \"msw-default\"\n"
671 "bg[NORMAL] = { %d, %d, %d }\n"
672 "}widget_class \"*Status*\" style \"msw-status\"\n",
673 (font_ptr ? "font_name" : "#"),
674 (font_ptr ? font_ptr : " font name should go here"),
675 btn_face.red, btn_face.green, btn_face.blue);
676 gtk_rc_parse_string(buf);
678 /* enable coloring for text on buttons
679 TODO: use GetThemeMetric for the border and outside border */
680 g_snprintf(buf, sizeof (buf),
681 "style \"msw-button\" = \"msw-default\"\n"
683 "bg[NORMAL] = { %d, %d, %d }\n"
684 "bg[PRELIGHT] = { %d, %d, %d }\n"
685 "bg[INSENSITIVE] = { %d, %d, %d }\n"
686 "fg[PRELIGHT] = { %d, %d, %d }\n"
687 "GtkButton::default-border = { 1, 1, 1, 1 }\n"
688 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
689 "GtkButton::child-displacement-x = 1\n"
690 "GtkButton::child-displacement-y = 1\n"
691 "}widget_class \"*Button*\" style \"msw-button\"\n",
692 btn_face.red, btn_face.green, btn_face.blue,
693 btn_face.red, btn_face.green, btn_face.blue,
694 btn_face.red, btn_face.green, btn_face.blue,
695 btn_fore.red, btn_fore.green, btn_fore.blue
697 gtk_rc_parse_string(buf);
699 /* enable coloring for progress bars */
700 g_snprintf(buf, sizeof (buf),
701 "style \"msw-progress\" = \"msw-default\"\n"
702 "{bg[PRELIGHT] = { %d, %d, %d }\n"
703 "bg[NORMAL] = { %d, %d, %d }\n"
704 "}widget_class \"*Progress*\" style \"msw-progress\"\n",
708 btn_face.red, btn_face.green, btn_face.blue);
709 gtk_rc_parse_string(buf);
711 /* scrollbar thumb width and height */
712 g_snprintf(buf, sizeof (buf),
713 "style \"msw-vscrollbar\" = \"msw-default\"\n"
714 "{GtkRange::slider-width = %d\n"
715 "GtkRange::stepper-size = %d\n"
716 "GtkRange::stepper-spacing = 0\n"
717 "GtkRange::trough_border = 0\n"
718 "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n",
719 GetSystemMetrics(SM_CYVTHUMB),
720 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL));
721 gtk_rc_parse_string(buf);
723 g_snprintf(buf, sizeof (buf),
724 "style \"msw-hscrollbar\" = \"msw-default\"\n"
725 "{GtkRange::slider-width = %d\n"
726 "GtkRange::stepper-size = %d\n"
727 "GtkRange::stepper-spacing = 0\n"
728 "GtkRange::trough_border = 0\n"
729 "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n",
730 GetSystemMetrics(SM_CXHTHUMB),
731 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL));
732 gtk_rc_parse_string(buf);
734 /* radio/check button sizes */
735 g_snprintf(buf, sizeof (buf),
736 "style \"msw-checkbutton\" = \"msw-button\"\n"
737 "{GtkCheckButton::indicator-size = 13\n"
738 "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
739 "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
740 gtk_rc_parse_string(buf);
744 setup_system_styles(GtkStyle *style)
748 /* Default background */
749 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_NORMAL]);
750 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
751 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_INSENSITIVE]);
752 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_ACTIVE]);
753 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_PRELIGHT]);
756 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_NORMAL]);
757 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
758 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_INSENSITIVE]);
759 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_ACTIVE]);
760 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_PRELIGHT]);
763 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_NORMAL]);
764 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
765 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_GRAYTEXT, &style->text[GTK_STATE_INSENSITIVE]);
766 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->text[GTK_STATE_ACTIVE]);
767 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_PRELIGHT]);
769 /* Default forgeground */
770 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_NORMAL]);
771 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
772 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_GRAYTEXT, &style->fg[GTK_STATE_INSENSITIVE]);
773 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_ACTIVE]);
774 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->fg[GTK_STATE_PRELIGHT]);
776 for (i = 0; i < 5; i++)
778 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW, &style->dark[i]);
779 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT, &style->light[i]);
781 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
782 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
783 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
785 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
786 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
787 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
792 sanitize_size (GdkWindow *window,
796 gboolean set_bg = FALSE;
798 if ((*width == -1) && (*height == -1))
800 set_bg = GDK_IS_WINDOW (window);
801 gdk_drawable_get_size (window, width, height);
803 else if (*width == -1)
804 gdk_drawable_get_size (window, width, NULL);
805 else if (*height == -1)
806 gdk_drawable_get_size (window, NULL, height);
811 static XpThemeElement
812 map_gtk_progress_bar_to_xp(GtkProgressBar *progress_bar, gboolean trough)
815 switch (progress_bar->orientation)
817 case GTK_PROGRESS_LEFT_TO_RIGHT:
818 case GTK_PROGRESS_RIGHT_TO_LEFT:
820 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
821 : XP_THEME_ELEMENT_PROGRESS_BAR_H;
825 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
826 : XP_THEME_ELEMENT_PROGRESS_BAR_V;
833 draw_part (GdkDrawable *drawable,
841 gdk_gc_set_clip_rectangle (gc, area);
843 if (!parts[part].bmap)
844 parts[part].bmap = gdk_bitmap_create_from_data (drawable,
846 PART_SIZE, PART_SIZE);
848 gdk_gc_set_ts_origin (gc, x, y);
849 gdk_gc_set_stipple (gc, parts[part].bmap);
850 gdk_gc_set_fill (gc, GDK_STIPPLED);
852 gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
854 gdk_gc_set_fill (gc, GDK_SOLID);
857 gdk_gc_set_clip_rectangle (gc, NULL);
861 draw_check(GtkStyle *style,
864 GtkShadowType shadow,
873 x -= (1 + PART_SIZE - width) / 2;
874 y -= (1 + PART_SIZE - height) / 2;
876 if (detail && strcmp (detail, "check") == 0) /* Menu item */
878 if (shadow == GTK_SHADOW_IN)
880 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
881 draw_part (window, style->dark_gc[state], area, x, y, CHECK_AA);
886 if (!xp_theme_draw(window, shadow == GTK_SHADOW_IN
887 ? XP_THEME_ELEMENT_PRESSED_CHECKBOX
888 : XP_THEME_ELEMENT_CHECKBOX,
889 style, x, y, width, height, state, area))
891 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
892 draw_part (window, style->dark_gc[state], area, x, y, CHECK_DARK);
893 draw_part (window, style->mid_gc[state], area, x, y, CHECK_MID);
894 draw_part (window, style->light_gc[state], area, x, y, CHECK_LIGHT);
895 draw_part (window, style->base_gc[state], area, x, y, CHECK_BASE);
897 if (shadow == GTK_SHADOW_IN)
899 draw_part (window, style->text_gc[state], area, x, y, CHECK_TEXT);
900 draw_part (window, style->text_aa_gc[state], area, x, y, CHECK_AA);
907 draw_expander(GtkStyle *style,
915 GtkExpanderStyle expander_style)
918 gint expander_semi_size;
922 XpThemeElement xp_expander;
924 gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
926 switch (expander_style)
928 case GTK_EXPANDER_COLLAPSED:
929 case GTK_EXPANDER_SEMI_COLLAPSED:
930 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
933 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
937 if ((expander_size % 2) == 0)
940 if (expander_size > 2)
944 gdk_gc_set_clip_rectangle (style->fg_gc[state], area);
946 expander_semi_size = expander_size / 2;
947 x -= expander_semi_size;
948 y -= expander_semi_size;
950 gdk_gc_get_values (style->fg_gc[state], &values);
952 if (! xp_theme_draw(window, xp_expander, style,
954 expander_size, expander_size, state, area))
956 /* RGB values to emulate Windows Classic style */
957 color.red = color.green = color.blue = 128 << 8;
959 success = gdk_colormap_alloc_color
960 (gtk_widget_get_default_colormap (), &color, FALSE, TRUE);
963 gdk_gc_set_foreground (style->fg_gc[state], &color);
966 (window, style->fg_gc[state], FALSE, x, y,
967 expander_size - 1, expander_size - 1);
970 (window, style->fg_gc[state], x + 2, y + expander_semi_size,
971 x + expander_size - 2, y + expander_semi_size);
973 switch (expander_style)
975 case GTK_EXPANDER_COLLAPSED:
976 case GTK_EXPANDER_SEMI_COLLAPSED:
978 (window, style->fg_gc[state], x + expander_semi_size, y + 2,
979 x + expander_semi_size, y + expander_size - 2);
987 gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
991 gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
995 draw_option(GtkStyle *style,
998 GtkShadowType shadow,
1001 const gchar *detail,
1007 x -= (1 + PART_SIZE - width) / 2;
1008 y -= (1 + PART_SIZE - height) / 2;
1010 if (detail && strcmp (detail, "option") == 0) /* Menu item */
1012 if (shadow == GTK_SHADOW_IN)
1013 draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
1017 if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1018 ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1019 : XP_THEME_ELEMENT_RADIO_BUTTON,
1020 style, x, y, width, height, state, area))
1025 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
1026 draw_part (window, style->dark_gc[state], area, x, y, RADIO_DARK);
1027 draw_part (window, style->mid_gc[state], area, x, y, RADIO_MID);
1028 draw_part (window, style->light_gc[state], area, x, y, RADIO_LIGHT);
1029 draw_part (window, style->base_gc[state], area, x, y, RADIO_BASE);
1031 if (shadow == GTK_SHADOW_IN)
1032 draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
1038 draw_varrow (GdkWindow *window,
1040 GtkShadowType shadow_type,
1042 GtkArrowType arrow_type,
1049 gint y_start, y_increment;
1053 gdk_gc_set_clip_rectangle (gc, area);
1055 width = width + width % 2 - 1; /* Force odd */
1057 steps = 1 + width / 2;
1059 extra = height - steps;
1061 if (arrow_type == GTK_ARROW_DOWN)
1068 y_start = y + height - 1;
1072 for (i = extra; i < height; i++)
1074 gdk_draw_line (window, gc,
1075 x + (i - extra), y_start + i * y_increment,
1076 x + width - (i - extra) - 1, y_start + i * y_increment);
1080 gdk_gc_set_clip_rectangle (gc, NULL);
1084 draw_harrow (GdkWindow *window,
1086 GtkShadowType shadow_type,
1088 GtkArrowType arrow_type,
1095 gint x_start, x_increment;
1099 gdk_gc_set_clip_rectangle (gc, area);
1101 height = height + height % 2 - 1; /* Force odd */
1103 steps = 1 + height / 2;
1105 extra = width - steps;
1107 if (arrow_type == GTK_ARROW_RIGHT)
1114 x_start = x + width - 1;
1118 for (i = extra; i < width; i++)
1120 gdk_draw_line (window, gc,
1121 x_start + i * x_increment, y + (i - extra),
1122 x_start + i * x_increment, y + height - (i - extra) - 1);
1127 gdk_gc_set_clip_rectangle (gc, NULL);
1130 /* This function makes up for some brokeness in gtkrange.c
1131 * where we never get the full arrow of the stepper button
1132 * and the type of button in a single drawing function.
1134 * It doesn't work correctly when the scrollbar is squished
1135 * to the point we don't have room for full-sized steppers.
1138 reverse_engineer_stepper_box (GtkWidget *range,
1139 GtkArrowType arrow_type,
1145 gint slider_width = 14, stepper_size = 14;
1151 gtk_widget_style_get (range,
1152 "slider_width", &slider_width,
1153 "stepper_size", &stepper_size,
1157 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1159 box_width = slider_width;
1160 box_height = stepper_size;
1164 box_width = stepper_size;
1165 box_height = slider_width;
1168 *x = *x - (box_width - *width) / 2;
1169 *y = *y - (box_height - *height) / 2;
1171 *height = box_height;
1174 static XpThemeElement to_xp_arrow(GtkArrowType arrow_type)
1176 XpThemeElement xp_arrow;
1181 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1183 case GTK_ARROW_DOWN:
1184 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1186 case GTK_ARROW_LEFT:
1187 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1190 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1198 draw_arrow (GtkStyle *style,
1201 GtkShadowType shadow,
1204 const gchar *detail,
1205 GtkArrowType arrow_type,
1214 name = gtk_widget_get_name (widget);
1216 sanitize_size (window, &width, &height);
1218 if (detail && strcmp (detail, "spinbutton") == 0)
1220 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1226 x += (width - 7) / 2;
1228 if (arrow_type == GTK_ARROW_UP)
1229 y += (height - 4) / 2;
1231 y += (1 + height - 4) / 2;
1232 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1236 else if (detail && (!strcmp (detail, "vscrollbar")
1237 || !strcmp (detail, "hscrollbar")))
1239 gboolean is_disabled = FALSE;
1240 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1243 gint box_width = width;
1244 gint box_height = height;
1246 reverse_engineer_stepper_box (widget, arrow_type,
1247 &box_x, &box_y, &box_width, &box_height);
1249 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1252 if (xp_theme_draw(window, to_xp_arrow(arrow_type), style, box_x, box_y, box_width, box_height, state, area))
1255 else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1257 x += (width - 7) / 2;
1258 y += (height - 5) / 2;
1260 draw_varrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1265 y += (height - 7) / 2;
1266 x += (width - 5) / 2;
1268 draw_harrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1274 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1275 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1277 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1280 /* probably a gtk combo box on a toolbar */
1281 else if (0 /*widget->parent && GTK_IS_BUTTON (widget->parent)*/)
1283 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON, style, x-3, widget->allocation.y+1,
1284 width+5, widget->allocation.height-4, state, area))
1288 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1290 x += (width - 7) / 2;
1291 y += (height - 5) / 2;
1293 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1298 x += (width - 5) / 2;
1299 y += (height - 7) / 2;
1301 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1308 option_menu_get_props (GtkWidget *widget,
1309 GtkRequisition *indicator_size,
1310 GtkBorder *indicator_spacing)
1312 GtkRequisition *tmp_size = NULL;
1313 GtkBorder *tmp_spacing = NULL;
1316 gtk_widget_style_get (widget,
1317 "indicator_size", &tmp_size,
1318 "indicator_spacing", &tmp_spacing,
1323 *indicator_size = *tmp_size;
1327 *indicator_size = default_option_indicator_size;
1331 *indicator_spacing = *tmp_spacing;
1332 g_free (tmp_spacing);
1335 *indicator_spacing = default_option_indicator_spacing;
1338 static gboolean is_toolbar_child(GtkWidget * wid)
1342 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1352 draw_box (GtkStyle *style,
1354 GtkStateType state_type,
1355 GtkShadowType shadow_type,
1358 const gchar *detail,
1365 (!strcmp (detail, "button") ||
1366 !strcmp (detail, "buttondefault")))
1368 if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1370 if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1371 width, height, state_type, area))
1374 else if (is_toolbar_child (widget->parent))
1376 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1377 width, height, state_type, area))
1382 gboolean is_default = !strcmp (detail, "buttondefault");
1383 if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1384 : XP_THEME_ELEMENT_BUTTON, style, x, y,
1385 width, height, state_type, area))
1389 else if (detail && !strcmp (detail, "spinbutton"))
1391 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1396 else if (detail && (!strcmp (detail, "spinbutton_up")
1397 || !strcmp (detail, "spinbutton_down")))
1399 if (xp_theme_draw(window,
1400 (! strcmp (detail, "spinbutton_up"))
1401 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1402 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1403 style, x, y, width, height, state_type, area))
1409 else if (detail && !strcmp (detail, "slider"))
1411 if (GTK_IS_SCROLLBAR(widget))
1413 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1414 gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1415 if (xp_theme_draw(window,
1417 ? XP_THEME_ELEMENT_SCROLLBAR_V
1418 : XP_THEME_ELEMENT_SCROLLBAR_H,
1419 style, x, y, width, height, state_type, area))
1421 XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1423 /* Do not display grippers on tiny scroll bars, the limit imposed
1424 is rather arbitrary, perhaps we can fetch the gripper geometry
1425 from somewhere and use that... */
1426 if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1427 || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1432 xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1437 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1442 else if (detail && !strcmp (detail, "bar"))
1444 if (widget && GTK_IS_PROGRESS_BAR (widget))
1446 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1447 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1448 if (xp_theme_draw (window, xp_progress_bar,
1449 style, x, y, width, height, state_type, area))
1455 else if (detail && strcmp (detail, "menuitem") == 0) {
1456 shadow_type = GTK_SHADOW_NONE;
1457 if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1462 else if (detail && !strcmp (detail, "trough"))
1464 if (widget && GTK_IS_PROGRESS_BAR (widget))
1466 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1467 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1468 if (xp_theme_draw (window, xp_progress_bar,
1469 style, x, y, width, height, state_type, area))
1475 /* Blank in classic Windows */
1478 else if (widget && GTK_IS_SCROLLBAR(widget))
1480 gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1482 if (GTK_IS_RANGE(widget)
1483 && xp_theme_draw(window,
1485 ? XP_THEME_ELEMENT_TROUGH_V
1486 : XP_THEME_ELEMENT_TROUGH_H,
1488 x, y, width, height, state_type, area))
1494 GdkGCValues gc_values;
1498 sanitize_size (window, &width, &height);
1500 pixmap = gdk_pixmap_new (window, 2, 2, -1);
1502 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1503 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1504 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1505 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1507 gc_values.fill = GDK_TILED;
1508 gc_values.tile = pixmap;
1509 gc_values.ts_x_origin = x;
1510 gc_values.ts_y_origin = y;
1511 gc = gdk_gc_new_with_values (window, &gc_values,
1512 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1515 gdk_gc_set_clip_rectangle (gc, area);
1517 gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1519 g_object_unref (gc);
1520 g_object_unref (pixmap);
1525 else if (widget && GTK_IS_SCALE(widget))
1527 gboolean is_vertical = GTK_IS_VSCALE(widget);
1529 parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1530 widget, detail, x, y, width, height);
1533 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1535 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1540 else if (detail && strcmp (detail, "optionmenu") == 0)
1542 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1543 style, x, y, width, height, state_type, area))
1548 else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1550 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1551 if (shadow_type == GTK_SHADOW_IN)
1552 shadow_type = GTK_SHADOW_ETCHED_IN;
1553 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1554 shadow_type = GTK_SHADOW_OUT;
1556 else if (detail && strcmp (detail, "handlebox_bin") == 0)
1558 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR,
1559 style, x, y, width, height, state_type, area))
1566 const gchar * name = gtk_widget_get_name (widget);
1568 if (name && !strcmp (name, "gtk-tooltips")) {
1569 if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1576 GdkDrawable *drawable;
1580 if (!GDK_IS_WINDOW(window))
1588 gdk_window_get_internal_paint_info(window, &drawable, &xoff, &yoff);
1591 rect.left = x - xoff;
1592 rect.top = y - yoff;
1593 rect.right = rect.left + width;
1594 rect.bottom = rect.top + height;
1596 hdc = gdk_win32_hdc_get(window, style->dark_gc[state_type], 0);
1597 brush = GetSysColorBrush(COLOR_3DDKSHADOW);
1599 FrameRect(hdc, &rect, brush);
1600 InflateRect(&rect, -1, -1);
1601 FillRect(hdc, &rect, (HBRUSH) (COLOR_INFOBK+1));
1609 parent_class->draw_box (style, window, state_type, shadow_type, area,
1610 widget, detail, x, y, width, height);
1612 if (detail && strcmp (detail, "optionmenu") == 0)
1614 GtkRequisition indicator_size;
1615 GtkBorder indicator_spacing;
1618 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1620 sanitize_size (window, &width, &height);
1622 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1623 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1625 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1627 parent_class->draw_vline (style, window, state_type, area, widget,
1629 y + style->ythickness + 1,
1630 y + height - style->ythickness - 3,
1636 draw_tab (GtkStyle *style,
1639 GtkShadowType shadow,
1642 const gchar *detail,
1648 GtkRequisition indicator_size;
1649 GtkBorder indicator_spacing;
1653 g_return_if_fail (style != NULL);
1654 g_return_if_fail (window != NULL);
1656 if (detail && ! strcmp (detail, "optionmenutab"))
1658 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1659 style, x-5, widget->allocation.y+1,
1660 width+10, widget->allocation.height-2, state, area))
1667 gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1669 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1671 x += (width - indicator_size.width) / 2;
1672 arrow_height = (indicator_size.width + 1) / 2;
1674 y += (height - arrow_height) / 2;
1676 draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1677 x, y, indicator_size.width, arrow_height);
1680 /* this is an undefined magic value that, according to the mozilla folks,
1681 worked for all the various themes that they tried */
1682 #define XP_EDGE_SIZE 2
1685 draw_extension(GtkStyle *style,
1687 GtkStateType state_type,
1688 GtkShadowType shadow_type,
1691 const gchar *detail,
1696 GtkPositionType gap_side)
1698 if (detail && !strcmp(detail, "tab"))
1700 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1701 GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1703 if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1704 height += XP_EDGE_SIZE;
1707 /* FIXME: pos != TOP to be implemented */
1708 else if (pos_type == GTK_POS_BOTTOM)
1710 else if (pos_type == GTK_POS_RIGHT)
1711 width += XP_EDGE_SIZE;
1712 else if (pos_type == GTK_POS_LEFT)
1713 height -= XP_EDGE_SIZE;
1716 if (pos_type == GTK_POS_TOP
1718 (window, gtk_notebook_get_current_page(notebook)==0
1719 ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1720 : XP_THEME_ELEMENT_TAB_ITEM,
1721 style, x, y, width, height, state_type, area))
1726 parent_class->draw_extension
1727 (style, window, state_type, shadow_type, area, widget, detail,
1728 x, y, width, height, gap_side);
1732 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1733 GtkShadowType shadow_type, GdkRectangle *area,
1734 GtkWidget *widget, const gchar *detail, gint x,
1735 gint y, gint width, gint height, GtkPositionType gap_side,
1736 gint gap_x, gint gap_width)
1738 if (detail && !strcmp(detail, "notebook"))
1740 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1742 /* FIXME: pos != TOP to be implemented */
1743 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
1749 parent_class->draw_box_gap(style, window, state_type, shadow_type,
1750 area, widget, detail, x, y, width, height,
1751 gap_side, gap_x, gap_width);
1755 draw_flat_box (GtkStyle *style, GdkWindow *window,
1756 GtkStateType state_type, GtkShadowType shadow_type,
1757 GdkRectangle *area, GtkWidget *widget,
1758 const gchar *detail, gint x, gint y,
1759 gint width, gint height)
1761 if (detail && ! strcmp (detail, "checkbutton"))
1763 if (state_type == GTK_STATE_PRELIGHT)
1769 parent_class->draw_flat_box(style, window, state_type, shadow_type,
1770 area, widget, detail, x, y, width, height);
1774 draw_shadow (GtkStyle *style,
1776 GtkStateType state_type,
1777 GtkShadowType shadow_type,
1780 const gchar *detail,
1786 if(detail && ! strcmp(detail, "entry"))
1788 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1789 x, y, width, height, state_type, area))
1794 parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1795 detail, x, y, width, height);
1799 draw_hline (GtkStyle *style,
1801 GtkStateType state_type,
1804 const gchar *detail,
1810 if (detail && !strcmp(detail, "menuitem")) {
1811 if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1812 x1, y, x2, style->ythickness, state_type, area)) {
1817 parent_class->draw_hline (style, window, state_type, area, widget,
1822 draw_vline (GtkStyle *style,
1824 GtkStateType state_type,
1827 const gchar *detail,
1832 parent_class->draw_vline (style, window, state_type, area, widget,
1837 draw_resize_grip (GtkStyle *style,
1839 GtkStateType state_type,
1842 const gchar *detail,
1849 if (detail && !strcmp(detail, "statusbar")) {
1851 /* DAL: TODO: find out why this regressed */
1852 if (xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1858 parent_class->draw_resize_grip (style, window, state_type, area,
1859 widget, detail, edge, x, y, width, height);
1863 draw_handle (GtkStyle *style,
1865 GtkStateType state_type,
1866 GtkShadowType shadow_type,
1869 const gchar *detail,
1874 GtkOrientation orientation)
1876 if (is_toolbar_child (widget))
1878 XpThemeElement hndl;
1880 sanitize_size (window, &width, &height);
1882 if (orientation == GTK_ORIENTATION_VERTICAL)
1883 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1885 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1887 if (xp_theme_draw (window, hndl, style, x, y, width, height,
1893 /* grippers are just flat boxes when they're not a toolbar */
1894 parent_class->draw_box (style, window, state_type, shadow_type,
1895 area, widget, detail, x, y, width, height);
1897 else if (!GTK_IS_PANED (widget))
1899 /* TODO: Draw handle boxes as double lines: || */
1900 parent_class->draw_handle (style, window, state_type, shadow_type,
1901 area, widget, detail, x, y, width, height,
1907 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
1909 setup_system_font (style);
1910 setup_menu_settings (gtk_settings_get_default ());
1911 setup_system_styles (style);
1912 parent_class->init_from_rc(style, rc_style);
1916 msw_style_class_init (MswStyleClass *klass)
1918 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1920 parent_class = g_type_class_peek_parent (klass);
1922 style_class->init_from_rc = msw_style_init_from_rc;
1923 style_class->draw_arrow = draw_arrow;
1924 style_class->draw_box = draw_box;
1925 style_class->draw_check = draw_check;
1926 style_class->draw_option = draw_option;
1927 style_class->draw_tab = draw_tab;
1928 style_class->draw_flat_box = draw_flat_box;
1929 style_class->draw_expander = draw_expander;
1930 style_class->draw_extension = draw_extension;
1931 style_class->draw_box_gap = draw_box_gap;
1932 style_class->draw_shadow = draw_shadow;
1933 style_class->draw_hline = draw_hline;
1934 style_class->draw_vline = draw_vline;
1935 style_class->draw_handle = draw_handle;
1936 style_class->draw_resize_grip = draw_resize_grip;
1939 GType msw_type_style = 0;
1942 msw_style_register_type (GTypeModule *module)
1944 static const GTypeInfo object_info =
1946 sizeof (MswStyleClass),
1947 (GBaseInitFunc) NULL,
1948 (GBaseFinalizeFunc) NULL,
1949 (GClassInitFunc) msw_style_class_init,
1950 NULL, /* class_finalize */
1951 NULL, /* class_data */
1953 0, /* n_preallocs */
1954 (GInstanceInitFunc) NULL,
1957 msw_type_style = g_type_module_register_type (module,
1964 msw_style_init (void)
1967 msw_style_setup_system_settings ();
1968 setup_msw_rc_style ();