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"
31 #include <gdk/gdkwin32.h>
35 /* Default values, not normally used
37 static const GtkRequisition default_option_indicator_size = { 9, 8 };
38 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
40 static GtkStyleClass *parent_class;
60 static const char check_aa_bits[] = {
61 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
62 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
63 static const char check_base_bits[] = {
64 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
65 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
66 static const char check_black_bits[] = {
67 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
68 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
69 static const char check_dark_bits[] = {
70 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
71 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
72 static const char check_light_bits[] = {
73 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
74 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
75 static const char check_mid_bits[] = {
76 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
77 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
78 static const char check_text_bits[] = {
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x88,0x03,0xd8,0x01,0xf8,
80 0x00,0x70,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
81 static const char radio_base_bits[] = {
82 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
83 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
84 static const char radio_black_bits[] = {
85 0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
86 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
87 static const char radio_dark_bits[] = {
88 0xf0,0x01,0x0c,0x06,0x02,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
89 0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
90 static const char radio_light_bits[] = {
91 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
92 0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x0c,0x06,0xf0,0x01};
93 static const char radio_mid_bits[] = {
94 0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
95 0x08,0x00,0x08,0x00,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00};
96 static const char radio_text_bits[] = {
97 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
98 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
104 { check_aa_bits, NULL },
105 { check_base_bits, NULL },
106 { check_black_bits, NULL },
107 { check_dark_bits, NULL },
108 { check_light_bits, NULL },
109 { check_mid_bits, NULL },
110 { check_text_bits, NULL },
111 { radio_base_bits, NULL },
112 { radio_black_bits, NULL },
113 { radio_dark_bits, NULL },
114 { radio_light_bits, NULL },
115 { radio_mid_bits, NULL },
116 { radio_text_bits, NULL }
120 get_system_font(XpThemeClass klazz, XpThemeFont type, LOGFONT *out_lf)
123 /* TODO: this crashes. need to figure out why and how to fix it */
124 if (xp_theme_get_system_font(klazz, type, out_lf))
129 NONCLIENTMETRICS ncm;
130 ncm.cbSize = sizeof(NONCLIENTMETRICS);
132 if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
133 sizeof(NONCLIENTMETRICS), &ncm, 0))
135 if (type == XP_THEME_FONT_CAPTION)
136 *out_lf = ncm.lfCaptionFont;
137 else if (type == XP_THEME_FONT_MENU)
138 *out_lf = ncm.lfMenuFont;
139 else if (type == XP_THEME_FONT_STATUS)
140 *out_lf = ncm.lfStatusFont;
142 *out_lf = ncm.lfMessageFont;
150 /***************************** STOLEN FROM PANGO *****************************/
153 This code is stolen from Pango 1.4. It attempts to address the following problems:
155 http://bugzilla.gnome.org/show_bug.cgi?id=135098
156 http://sourceforge.net/tracker/index.php?func=detail&aid=895762&group_id=76416&atid=547655
158 As Owen suggested in bug 135098, once Pango 1.6 is released, we need to get rid of this code.
161 #define PING(printlist)
163 /* TrueType defines: */
165 #define MAKE_TT_TABLE_NAME(c1, c2, c3, c4) \
166 (((guint32)c4) << 24 | ((guint32)c3) << 16 | ((guint32)c2) << 8 | ((guint32)c1))
168 #define CMAP (MAKE_TT_TABLE_NAME('c','m','a','p'))
169 #define CMAP_HEADER_SIZE 4
171 #define NAME (MAKE_TT_TABLE_NAME('n','a','m','e'))
172 #define NAME_HEADER_SIZE 6
174 #define ENCODING_TABLE_SIZE 8
176 #define APPLE_UNICODE_PLATFORM_ID 0
177 #define MACINTOSH_PLATFORM_ID 1
178 #define ISO_PLATFORM_ID 2
179 #define MICROSOFT_PLATFORM_ID 3
181 #define SYMBOL_ENCODING_ID 0
182 #define UNICODE_ENCODING_ID 1
183 #define UCS4_ENCODING_ID 10
187 guint16 format_selector;
189 guint16 string_storage_offset;
198 guint16 string_length;
199 guint16 string_offset;
203 pango_win32_get_name_header (HDC hdc,
204 struct name_header *header)
206 if (GetFontData (hdc, NAME, 0, header, sizeof (*header)) != sizeof (*header))
209 header->num_records = GUINT16_FROM_BE (header->num_records);
210 header->string_storage_offset = GUINT16_FROM_BE (header->string_storage_offset);
216 pango_win32_get_name_record (HDC hdc,
218 struct name_record *record)
220 if (GetFontData (hdc, NAME, 6 + i * sizeof (*record),
221 record, sizeof (*record)) != sizeof (*record))
224 record->platform_id = GUINT16_FROM_BE (record->platform_id);
225 record->encoding_id = GUINT16_FROM_BE (record->encoding_id);
226 record->language_id = GUINT16_FROM_BE (record->language_id);
227 record->name_id = GUINT16_FROM_BE (record->name_id);
228 record->string_length = GUINT16_FROM_BE (record->string_length);
229 record->string_offset = GUINT16_FROM_BE (record->string_offset);
235 get_family_name (LOGFONT *lfp, HDC pango_win32_hdc)
240 struct name_header header;
241 struct name_record record;
243 gint unicode_ix = -1, mac_ix = -1, microsoft_ix = -1;
247 gchar *string = NULL;
253 /* If lfFaceName is ASCII, assume it is the common (English) name
254 * for the font. Is this valid? Do some TrueType fonts have
255 * different names in French, German, etc, and does the system
256 * return these if the locale is set to use French, German, etc?
258 l = strlen (lfp->lfFaceName);
259 for (i = 0; i < l; i++)
260 if (lfp->lfFaceName[i] < ' ' || lfp->lfFaceName[i] > '~')
264 return g_strdup (lfp->lfFaceName);
266 if ((hfont = CreateFontIndirect (lfp)) == NULL)
269 if ((oldhfont = SelectObject (pango_win32_hdc, hfont)) == NULL)
272 if (!pango_win32_get_name_header (pango_win32_hdc, &header))
275 PING (("%d name records", header.num_records));
277 for (i = 0; i < header.num_records; i++)
279 if (!pango_win32_get_name_record (pango_win32_hdc, i, &record))
282 if ((record.name_id != 1 && record.name_id != 16) || record.string_length <= 0)
285 PING(("platform:%d encoding:%d language:%04x name_id:%d",
286 record.platform_id, record.encoding_id, record.language_id, record.name_id));
288 if (record.platform_id == APPLE_UNICODE_PLATFORM_ID ||
289 record.platform_id == ISO_PLATFORM_ID)
291 else if (record.platform_id == MACINTOSH_PLATFORM_ID &&
292 record.encoding_id == 0 && /* Roman */
293 record.language_id == 0) /* English */
295 else if (record.platform_id == MICROSOFT_PLATFORM_ID)
296 if ((microsoft_ix == -1 ||
297 PRIMARYLANGID (record.language_id) == LANG_ENGLISH) &&
298 (record.encoding_id == SYMBOL_ENCODING_ID ||
299 record.encoding_id == UNICODE_ENCODING_ID ||
300 record.encoding_id == UCS4_ENCODING_ID))
304 if (microsoft_ix >= 0)
305 name_ix = microsoft_ix;
306 else if (mac_ix >= 0)
308 else if (unicode_ix >= 0)
309 name_ix = unicode_ix;
313 if (!pango_win32_get_name_record (pango_win32_hdc, name_ix, &record))
316 string = g_malloc (record.string_length + 1);
317 if (GetFontData (pango_win32_hdc, NAME,
318 header.string_storage_offset + record.string_offset,
319 string, record.string_length) != record.string_length)
322 string[record.string_length] = '\0';
324 if (name_ix == microsoft_ix)
325 if (record.encoding_id == SYMBOL_ENCODING_ID ||
326 record.encoding_id == UNICODE_ENCODING_ID)
327 codeset = "UTF-16BE";
330 else if (name_ix == mac_ix)
331 codeset = "MacRoman";
332 else /* name_ix == unicode_ix */
335 name = g_convert (string, record.string_length, "UTF-8", codeset, NULL, &nbytes, NULL);
342 SelectObject (pango_win32_hdc, oldhfont);
343 DeleteObject (hfont);
349 SelectObject (pango_win32_hdc, oldhfont);
352 DeleteObject (hfont);
355 return g_locale_to_utf8 (lfp->lfFaceName, -1, NULL, NULL, NULL);
358 /***************************** STOLEN FROM PANGO *****************************/
361 sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char * buf, size_t bufsiz)
371 if (get_system_font(klazz, type, &lf))
373 switch (lf.lfWeight) {
376 weight = "Ultra-Light";
388 weight = "Semi-Bold";
392 weight = "Ultra-Bold";
409 hwnd = GetDesktopWindow();
412 pt_size = -MulDiv(lf.lfHeight, 72,
413 GetDeviceCaps(hDC,LOGPIXELSY));
414 ReleaseDC(hwnd, hDC);
418 font = get_family_name(&lf, hDC);
419 g_snprintf(buf, bufsiz, "%s %s %s %d", font, style, weight, pt_size);
428 /* missing from ms's header files */
429 #ifndef SPI_GETMENUSHOWDELAY
430 #define SPI_GETMENUSHOWDELAY 106
433 /* I don't know the proper XP theme class for things like
434 HIGHLIGHTTEXT, so we'll just define it to be "BUTTON"
436 #define XP_THEME_CLASS_TEXT XP_THEME_CLASS_BUTTON
439 setup_menu_settings (GtkSettings * settings)
442 gboolean win95 = FALSE;
443 OSVERSIONINFOEX osvi;
444 GObjectClass * klazz = G_OBJECT_GET_CLASS(G_OBJECT(settings));
446 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
447 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
449 if (!GetVersionEx ( (OSVERSIONINFO *) &osvi))
450 win95 = TRUE; /* assume the worst */
452 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
453 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
457 if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0)) {
459 if (g_object_class_find_property (klazz, "gtk-menu-bar-popup-delay")) {
460 g_object_set (G_OBJECT (settings), "gtk-menu-bar-popup-delay",
463 if (g_object_class_find_property (klazz, "gtk-menu-popup-delay")) {
464 g_object_set (G_OBJECT (settings), "gtk-menu-popup-delay",
467 if (g_object_class_find_property (klazz, "gtk-menu-popdown-delay")) {
468 g_object_set (G_OBJECT (settings), "gtk-menu-popdown-delay",
477 msw_style_setup_system_settings (void)
479 GtkSettings * settings;
480 int cursor_blink_time;
482 settings = gtk_settings_get_default ();
486 cursor_blink_time = GetCaretBlinkTime ();
487 g_object_set (G_OBJECT (settings), "gtk-cursor-blink",
488 cursor_blink_time > 0, NULL);
490 if (cursor_blink_time > 0)
492 g_object_set (G_OBJECT (settings), "gtk-cursor-blink-time",
493 2*cursor_blink_time, NULL);
496 g_object_set (G_OBJECT (settings), "gtk-double-click-time",
497 GetDoubleClickTime(), NULL);
498 g_object_set (G_OBJECT (settings), "gtk-dnd-drag-threshold",
499 GetSystemMetrics(SM_CXDRAG), NULL);
501 setup_menu_settings (settings);
504 http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
505 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
506 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp
511 setup_system_font(GtkStyle *style)
513 char buf[256], * font; /* It's okay, lfFaceName is smaller than 32 chars */
515 if ((font = sys_font_to_pango_font(XP_THEME_CLASS_TEXT,
516 XP_THEME_FONT_MESSAGE,
517 buf, sizeof (buf))) != NULL)
519 if (style->font_desc)
520 pango_font_description_free (style->font_desc);
522 style->font_desc = pango_font_description_from_string(font);
527 sys_color_to_gtk_color(XpThemeClass klazz, int id, GdkColor *pcolor)
531 if (!xp_theme_get_system_color (klazz, id, &color))
532 color = GetSysColor(id);
534 pcolor->pixel = color;
535 pcolor->red = (GetRValue(color) << 8) | GetRValue(color);
536 pcolor->green = (GetGValue(color) << 8) | GetGValue(color);
537 pcolor->blue = (GetBValue(color) << 8) | GetBValue(color);
541 get_system_metric(XpThemeClass klazz, int id)
545 if (!xp_theme_get_system_metric(klazz, id, &rval))
546 rval = GetSystemMetrics (id);
552 setup_msw_rc_style(void)
555 "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" */
557 char buf[1024], font_buf[256], *font_ptr;
560 GdkColor menu_text_color;
561 GdkColor tooltip_back;
562 GdkColor tooltip_fore;
565 GdkColor progress_back;
567 GdkColor fg_prelight;
568 GdkColor bg_prelight;
569 GdkColor base_prelight;
570 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 = etched-in\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_window_get_size (window, width, height);
803 else if (*width == -1)
804 gdk_window_get_size (window, width, NULL);
805 else if (*height == -1)
806 gdk_window_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);
984 gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
988 gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
992 draw_option(GtkStyle *style,
995 GtkShadowType shadow,
1004 x -= (1 + PART_SIZE - width) / 2;
1005 y -= (1 + PART_SIZE - height) / 2;
1007 if (detail && strcmp (detail, "option") == 0) /* Menu item */
1009 if (shadow == GTK_SHADOW_IN)
1010 draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
1014 if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1015 ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1016 : XP_THEME_ELEMENT_RADIO_BUTTON,
1017 style, x, y, width, height, state, area))
1022 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
1023 draw_part (window, style->dark_gc[state], area, x, y, RADIO_DARK);
1024 draw_part (window, style->mid_gc[state], area, x, y, RADIO_MID);
1025 draw_part (window, style->light_gc[state], area, x, y, RADIO_LIGHT);
1026 draw_part (window, style->base_gc[state], area, x, y, RADIO_BASE);
1028 if (shadow == GTK_SHADOW_IN)
1029 draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
1035 draw_varrow (GdkWindow *window,
1037 GtkShadowType shadow_type,
1039 GtkArrowType arrow_type,
1046 gint y_start, y_increment;
1050 gdk_gc_set_clip_rectangle (gc, area);
1052 width = width + width % 2 - 1; /* Force odd */
1054 steps = 1 + width / 2;
1056 extra = height - steps;
1058 if (arrow_type == GTK_ARROW_DOWN)
1065 y_start = y + height - 1;
1069 for (i = extra; i < height; i++)
1071 gdk_draw_line (window, gc,
1072 x + (i - extra), y_start + i * y_increment,
1073 x + width - (i - extra) - 1, y_start + i * y_increment);
1077 gdk_gc_set_clip_rectangle (gc, NULL);
1081 draw_harrow (GdkWindow *window,
1083 GtkShadowType shadow_type,
1085 GtkArrowType arrow_type,
1092 gint x_start, x_increment;
1096 gdk_gc_set_clip_rectangle (gc, area);
1098 height = height + height % 2 - 1; /* Force odd */
1100 steps = 1 + height / 2;
1102 extra = width - steps;
1104 if (arrow_type == GTK_ARROW_RIGHT)
1111 x_start = x + width - 1;
1115 for (i = extra; i < width; i++)
1117 gdk_draw_line (window, gc,
1118 x_start + i * x_increment, y + (i - extra),
1119 x_start + i * x_increment, y + height - (i - extra) - 1);
1124 gdk_gc_set_clip_rectangle (gc, NULL);
1127 /* This function makes up for some brokeness in gtkrange.c
1128 * where we never get the full arrow of the stepper button
1129 * and the type of button in a single drawing function.
1131 * It doesn't work correctly when the scrollbar is squished
1132 * to the point we don't have room for full-sized steppers.
1135 reverse_engineer_stepper_box (GtkWidget *range,
1136 GtkArrowType arrow_type,
1142 gint slider_width = 14, stepper_size = 14;
1148 gtk_widget_style_get (range,
1149 "slider_width", &slider_width,
1150 "stepper_size", &stepper_size,
1154 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1156 box_width = slider_width;
1157 box_height = stepper_size;
1161 box_width = stepper_size;
1162 box_height = slider_width;
1165 *x = *x - (box_width - *width) / 2;
1166 *y = *y - (box_height - *height) / 2;
1168 *height = box_height;
1172 draw_arrow (GtkStyle *style,
1175 GtkShadowType shadow,
1178 const gchar *detail,
1179 GtkArrowType arrow_type,
1188 name = gtk_widget_get_name (widget);
1190 sanitize_size (window, &width, &height);
1192 if (detail && strcmp (detail, "spinbutton") == 0)
1194 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1200 x += (width - 7) / 2;
1202 if (arrow_type == GTK_ARROW_UP)
1203 y += (height - 4) / 2;
1205 y += (1 + height - 4) / 2;
1206 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1210 else if (detail && (!strcmp (detail, "vscrollbar")
1211 || !strcmp (detail, "hscrollbar")))
1215 gint box_width = width;
1216 gint box_height = height;
1217 XpThemeElement xp_arrow;
1218 reverse_engineer_stepper_box (widget, arrow_type,
1219 &box_x, &box_y, &box_width, &box_height);
1224 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1226 case GTK_ARROW_DOWN:
1227 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1229 case GTK_ARROW_LEFT:
1230 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1233 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1236 if (xp_theme_draw(window, xp_arrow, style, box_x, box_y, box_width, box_height, state, area))
1239 else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1241 x += (width - 7) / 2;
1242 y += (height - 5) / 2;
1244 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1249 y += (height - 7) / 2;
1250 x += (width - 5) / 2;
1252 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1258 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1259 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1261 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1265 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1267 x += (width - 7) / 2;
1268 y += (height - 5) / 2;
1270 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1275 x += (width - 5) / 2;
1276 y += (height - 7) / 2;
1278 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1285 option_menu_get_props (GtkWidget *widget,
1286 GtkRequisition *indicator_size,
1287 GtkBorder *indicator_spacing)
1289 GtkRequisition *tmp_size = NULL;
1290 GtkBorder *tmp_spacing = NULL;
1293 gtk_widget_style_get (widget,
1294 "indicator_size", &tmp_size,
1295 "indicator_spacing", &tmp_spacing,
1300 *indicator_size = *tmp_size;
1304 *indicator_size = default_option_indicator_size;
1308 *indicator_spacing = *tmp_spacing;
1309 g_free (tmp_spacing);
1312 *indicator_spacing = default_option_indicator_spacing;
1315 static gboolean is_toolbar_child(GtkWidget * wid)
1319 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1329 draw_box (GtkStyle *style,
1331 GtkStateType state_type,
1332 GtkShadowType shadow_type,
1335 const gchar *detail,
1342 (!strcmp (detail, "button") ||
1343 !strcmp (detail, "buttondefault")))
1345 if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1347 if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1348 width, height, state_type, area))
1351 else if (is_toolbar_child (widget->parent))
1353 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1354 width, height, state_type, area))
1359 gboolean is_default = !strcmp (detail, "buttondefault");
1360 if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1361 : XP_THEME_ELEMENT_BUTTON, style, x, y,
1362 width, height, state_type, area))
1366 else if (detail && !strcmp (detail, "spinbutton"))
1368 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1373 else if (detail && (!strcmp (detail, "spinbutton_up")
1374 || !strcmp (detail, "spinbutton_down")))
1376 if (xp_theme_draw(window,
1377 (! strcmp (detail, "spinbutton_up"))
1378 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1379 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1380 style, x, y, width, height, state_type, area))
1386 else if (detail && !strcmp (detail, "slider"))
1388 if (GTK_IS_SCROLLBAR(widget))
1390 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1391 gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1392 if (xp_theme_draw(window,
1394 ? XP_THEME_ELEMENT_SCROLLBAR_V
1395 : XP_THEME_ELEMENT_SCROLLBAR_H,
1396 style, x, y, width, height, state_type, area))
1398 XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1400 /* Do not display grippers on tiny scroll bars, the limit imposed
1401 is rather arbitrary, perhaps we can fetch the gripper geometry
1402 from somewhere and use that... */
1403 if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1404 || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1409 xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1414 else if (detail && !strcmp (detail, "bar"))
1416 if (widget && GTK_IS_PROGRESS_BAR (widget))
1418 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1419 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1420 if (xp_theme_draw (window, xp_progress_bar,
1421 style, x, y, width, height, state_type, area))
1427 else if (detail && !strcmp (detail, "handlebox_bin")) {
1428 if (xp_theme_draw (window, XP_THEME_ELEMENT_REBAR, 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_pixmap_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 if (shadow_type == GTK_SHADOW_IN)
1529 shadow_type = GTK_SHADOW_ETCHED_IN;
1533 const gchar * name = gtk_widget_get_name (widget);
1535 if (name && !strcmp (name, "gtk-tooltips")) {
1536 if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1543 parent_class->draw_box (style, window, state_type, shadow_type, area,
1544 widget, detail, x, y, width, height);
1546 if (detail && strcmp (detail, "optionmenu") == 0)
1548 GtkRequisition indicator_size;
1549 GtkBorder indicator_spacing;
1552 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1554 sanitize_size (window, &width, &height);
1556 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1557 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1559 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1561 parent_class->draw_vline (style, window, state_type, area, widget,
1563 y + style->ythickness + 1,
1564 y + height - style->ythickness - 3,
1570 draw_tab (GtkStyle *style,
1573 GtkShadowType shadow,
1576 const gchar *detail,
1582 GtkRequisition indicator_size;
1583 GtkBorder indicator_spacing;
1587 g_return_if_fail (style != NULL);
1588 g_return_if_fail (window != NULL);
1590 if (detail && ! strcmp (detail, "optionmenutab"))
1592 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1593 style, x-5, widget->allocation.y+1,
1594 width+10, widget->allocation.height-2, state, area))
1601 gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1603 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1605 x += (width - indicator_size.width) / 2;
1606 arrow_height = (indicator_size.width + 1) / 2;
1608 y += (height - arrow_height) / 2;
1610 draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1611 x, y, indicator_size.width, arrow_height);
1614 /* this is an undefined magic value that, according to the mozilla folks,
1615 worked for all the various themes that they tried */
1616 #define XP_EDGE_SIZE 2
1619 draw_extension(GtkStyle *style,
1621 GtkStateType state_type,
1622 GtkShadowType shadow_type,
1625 const gchar *detail,
1630 GtkPositionType gap_side)
1632 if (detail && !strcmp(detail, "tab"))
1634 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1635 GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1637 if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1638 height += XP_EDGE_SIZE;
1641 /* FIXME: pos != TOP to be implemented */
1642 else if (pos_type == GTK_POS_BOTTOM)
1644 else if (pos_type == GTK_POS_RIGHT)
1645 width += XP_EDGE_SIZE;
1646 else if (pos_type == GTK_POS_LEFT)
1647 height -= XP_EDGE_SIZE;
1650 if (pos_type == GTK_POS_TOP
1652 (window, gtk_notebook_get_current_page(notebook)==0
1653 ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1654 : XP_THEME_ELEMENT_TAB_ITEM,
1655 style, x, y, width, height, state_type, area))
1660 parent_class->draw_extension
1661 (style, window, state_type, shadow_type, area, widget, detail,
1662 x, y, width, height, gap_side);
1666 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1667 GtkShadowType shadow_type, GdkRectangle *area,
1668 GtkWidget *widget, const gchar *detail, gint x,
1669 gint y, gint width, gint height, GtkPositionType gap_side,
1670 gint gap_x, gint gap_width)
1672 if (detail && !strcmp(detail, "notebook"))
1674 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1676 /* FIXME: pos != TOP to be implemented */
1677 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
1683 parent_class->draw_box_gap(style, window, state_type, shadow_type,
1684 area, widget, detail, x, y, width, height,
1685 gap_side, gap_x, gap_width);
1689 draw_flat_box (GtkStyle *style, GdkWindow *window,
1690 GtkStateType state_type, GtkShadowType shadow_type,
1691 GdkRectangle *area, GtkWidget *widget,
1692 const gchar *detail, gint x, gint y,
1693 gint width, gint height)
1695 if (detail && ! strcmp (detail, "checkbutton"))
1697 if (state_type == GTK_STATE_PRELIGHT)
1703 parent_class->draw_flat_box(style, window, state_type, shadow_type,
1704 area, widget, detail, x, y, width, height);
1708 draw_shadow (GtkStyle *style,
1710 GtkStateType state_type,
1711 GtkShadowType shadow_type,
1714 const gchar *detail,
1720 if(detail && ! strcmp(detail, "entry"))
1722 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1723 x, y, width, height, state_type, area))
1728 parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1729 detail, x, y, width, height);
1733 draw_hline (GtkStyle *style,
1735 GtkStateType state_type,
1738 const gchar *detail,
1744 if (detail && !strcmp(detail, "menuitem")) {
1745 if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1746 x1, y, x2, style->ythickness, state_type, area)) {
1751 parent_class->draw_hline (style, window, state_type, area, widget,
1756 draw_vline (GtkStyle *style,
1758 GtkStateType state_type,
1761 const gchar *detail,
1766 parent_class->draw_vline (style, window, state_type, area, widget,
1771 draw_resize_grip (GtkStyle *style,
1773 GtkStateType state_type,
1776 const gchar *detail,
1783 if (detail && !strcmp(detail, "statusbar")) {
1784 if (!xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1789 parent_class->draw_resize_grip (style, window, state_type, area,
1790 widget, detail, edge, x, y, width, height);
1794 draw_handle (GtkStyle *style,
1796 GtkStateType state_type,
1797 GtkShadowType shadow_type,
1800 const gchar *detail,
1805 GtkOrientation orientation)
1807 if (! GTK_IS_HANDLE_BOX (widget))
1809 XpThemeElement hndl;
1811 sanitize_size (window, &width, &height);
1813 if (orientation == GTK_ORIENTATION_VERTICAL)
1814 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1816 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1818 if (xp_theme_draw (window, hndl, style, x, y, width, height,
1823 /* grippers are just flat boxes when they're not a toolbar */
1824 parent_class->draw_box (style, window, state_type, shadow_type,
1825 area, widget, detail, x, y, width, height);
1829 /* TODO: Draw handle boxes as double lines: || */
1830 parent_class->draw_handle (style, window, state_type, shadow_type,
1831 area, widget, detail, x, y, width, height,
1837 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
1839 setup_system_font (style);
1840 setup_menu_settings (gtk_settings_get_default ());
1841 setup_system_styles (style);
1842 parent_class->init_from_rc(style, rc_style);
1846 msw_style_class_init (MswStyleClass *klass)
1848 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1850 parent_class = g_type_class_peek_parent (klass);
1852 style_class->init_from_rc = msw_style_init_from_rc;
1853 style_class->draw_arrow = draw_arrow;
1854 style_class->draw_box = draw_box;
1855 style_class->draw_check = draw_check;
1856 style_class->draw_option = draw_option;
1857 style_class->draw_tab = draw_tab;
1858 style_class->draw_flat_box = draw_flat_box;
1859 style_class->draw_expander = draw_expander;
1860 style_class->draw_extension = draw_extension;
1861 style_class->draw_box_gap = draw_box_gap;
1862 style_class->draw_shadow = draw_shadow;
1863 style_class->draw_hline = draw_hline;
1864 style_class->draw_vline = draw_vline;
1865 style_class->draw_handle = draw_handle;
1866 style_class->draw_resize_grip = draw_resize_grip;
1869 GType msw_type_style = 0;
1872 msw_style_register_type (GTypeModule *module)
1874 static const GTypeInfo object_info =
1876 sizeof (MswStyleClass),
1877 (GBaseInitFunc) NULL,
1878 (GBaseFinalizeFunc) NULL,
1879 (GClassInitFunc) msw_style_class_init,
1880 NULL, /* class_finalize */
1881 NULL, /* class_data */
1883 0, /* n_preallocs */
1884 (GInstanceInitFunc) NULL,
1887 msw_type_style = g_type_module_register_type (module,
1894 msw_style_init (void)
1897 msw_style_setup_system_settings ();
1898 setup_msw_rc_style ();