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 (void)
442 gboolean win95 = FALSE;
444 GtkSettings * settings;
445 OSVERSIONINFOEX osvi;
447 settings = gtk_settings_get_default ();
451 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
452 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
454 if (!GetVersionEx ( (OSVERSIONINFO *) &osvi))
455 win95 = TRUE; /* assume the worst */
457 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
458 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
462 if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0)) {
463 GObjectClass * klazz = G_OBJECT_GET_CLASS(G_OBJECT(settings));
466 if (g_object_class_find_property (klazz, "gtk-menu-bar-popup-delay")) {
467 g_object_set (G_OBJECT (settings), "gtk-menu-bar-popup-delay",
470 if (g_object_class_find_property (klazz, "gtk-menu-popup-delay")) {
471 g_object_set (G_OBJECT (settings), "gtk-menu-popup-delay",
474 if (g_object_class_find_property (klazz, "gtk-menu-popdown-delay")) {
475 g_object_set (G_OBJECT (settings), "gtk-menu-popdown-delay",
484 msw_style_setup_system_settings (void)
486 GtkSettings * settings;
487 int cursor_blink_time;
489 settings = gtk_settings_get_default ();
493 cursor_blink_time = GetCaretBlinkTime ();
494 g_object_set (G_OBJECT (settings), "gtk-cursor-blink",
495 cursor_blink_time > 0, NULL);
497 if (cursor_blink_time > 0)
499 g_object_set (G_OBJECT (settings), "gtk-cursor-blink-time",
500 2*cursor_blink_time, NULL);
503 g_object_set (G_OBJECT (settings), "gtk-double-click-time",
504 GetDoubleClickTime(), NULL);
505 g_object_set (G_OBJECT (settings), "gtk-dnd-drag-threshold",
506 GetSystemMetrics(SM_CXDRAG), NULL);
508 setup_menu_settings ();
511 http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
512 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
513 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp
518 setup_system_font(GtkStyle *style)
520 char buf[256], * font; /* It's okay, lfFaceName is smaller than 32 chars */
522 if ((font = sys_font_to_pango_font(XP_THEME_CLASS_TEXT,
523 XP_THEME_FONT_MESSAGE,
524 buf, sizeof (buf))) != NULL)
526 if (style->font_desc)
528 pango_font_description_free (style->font_desc);
530 style->font_desc = pango_font_description_from_string(font);
535 sys_color_to_gtk_color(XpThemeClass klazz, int id, GdkColor *pcolor)
539 if (!xp_theme_get_system_color (klazz, id, &color))
540 color = GetSysColor(id);
542 pcolor->pixel = color;
543 pcolor->red = (GetRValue(color) << 8) | GetRValue(color);
544 pcolor->green = (GetGValue(color) << 8) | GetGValue(color);
545 pcolor->blue = (GetBValue(color) << 8) | GetBValue(color);
549 get_system_metric(XpThemeClass klazz, int id)
553 if (!xp_theme_get_system_metric(klazz, id, &rval))
554 rval = GetSystemMetrics (id);
560 setup_msw_rc_style(void)
563 "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" */
565 char buf[1024], font_buf[256], *font_ptr;
568 GdkColor menu_text_color;
569 GdkColor tooltip_back;
570 GdkColor tooltip_fore;
573 GdkColor progress_back;
575 GdkColor fg_prelight;
576 GdkColor bg_prelight;
577 GdkColor base_prelight;
578 GdkColor text_prelight;
583 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &fg_prelight);
584 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
585 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &base_prelight);
586 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &text_prelight);
588 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENUTEXT, &menu_text_color);
589 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);
592 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT, &tooltip_fore);
593 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK, &tooltip_back);
595 /* text on push buttons. TODO: button shadows, backgrounds, and highlights */
596 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
597 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
599 /* progress bar background color */
600 sys_color_to_gtk_color(XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT, &progress_back);
602 /* Enable coloring for menus. */
603 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,font_buf, sizeof (font_buf));
604 g_snprintf(buf, sizeof (buf),
605 "style \"msw-menu\" = \"msw-default\"\n"
607 "fg[PRELIGHT] = { %d, %d, %d }\n"
608 "bg[PRELIGHT] = { %d, %d, %d }\n"
609 "text[PRELIGHT] = { %d, %d, %d }\n"
610 "base[PRELIGHT] = { %d, %d, %d }\n"
611 "fg[NORMAL] = { %d, %d, %d }\n"
612 "bg[NORMAL] = { %d, %d, %d }\n"
614 "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
615 "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
616 "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
630 menu_text_color.green,
631 menu_text_color.blue,
635 (font_ptr ? "font_name" : "#"),
636 (font_ptr ? font_ptr : " font name should go here"));
637 gtk_rc_parse_string(buf);
639 /* Enable coloring for menu bars. */
640 g_snprintf(buf, sizeof (buf),
641 "style \"msw-menu-bar\" = \"msw-menu\"\n"
643 "bg[NORMAL] = { %d, %d, %d }\n"
644 "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
648 gtk_rc_parse_string(buf);
650 /* enable tooltip fonts */
651 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
652 g_snprintf(buf, sizeof (buf),
653 "style \"msw-tooltips-caption\" = \"msw-default\"\n"
654 "{fg[NORMAL] = { %d, %d, %d }\n"
656 "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
660 (font_ptr ? "font_name" : "#"),
661 (font_ptr ? font_ptr : " font name should go here"));
662 gtk_rc_parse_string(buf);
664 g_snprintf(buf, sizeof (buf),
665 "style \"msw-tooltips\" = \"msw-default\"\n"
666 "{bg[NORMAL] = { %d, %d, %d }\n"
667 "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
671 gtk_rc_parse_string(buf);
673 /* enable font theming for status bars */
674 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
675 g_snprintf(buf, sizeof (buf),
676 "style \"msw-status\" = \"msw-default\"\n"
678 "bg[NORMAL] = { %d, %d, %d }\n"
679 "}widget_class \"*Status*\" style \"msw-status\"\n",
680 (font_ptr ? "font_name" : "#"),
681 (font_ptr ? font_ptr : " font name should go here"),
682 btn_face.red, btn_face.green, btn_face.blue);
683 gtk_rc_parse_string(buf);
685 /* enable coloring for text on buttons
686 TODO: use GetThemeMetric for the border and outside border */
687 g_snprintf(buf, sizeof (buf),
688 "style \"msw-button\" = \"msw-default\"\n"
690 "bg[NORMAL] = { %d, %d, %d }\n"
691 "bg[PRELIGHT] = { %d, %d, %d }\n"
692 "bg[INSENSITIVE] = { %d, %d, %d }\n"
693 "fg[PRELIGHT] = { %d, %d, %d }\n"
694 "GtkButton::default-border = { 1, 1, 1, 1 }\n"
695 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
696 "GtkButton::child-displacement-x = 1\n"
697 "GtkButton::child-displacement-y = 1\n"
698 "}widget_class \"*Button*\" style \"msw-button\"\n",
699 btn_face.red, btn_face.green, btn_face.blue,
700 btn_face.red, btn_face.green, btn_face.blue,
701 btn_face.red, btn_face.green, btn_face.blue,
702 btn_fore.red, btn_fore.green, btn_fore.blue
704 gtk_rc_parse_string(buf);
706 /* enable coloring for progress bars */
707 g_snprintf(buf, sizeof (buf),
708 "style \"msw-progress\" = \"msw-default\"\n"
709 "{bg[PRELIGHT] = { %d, %d, %d }\n"
710 "bg[NORMAL] = { %d, %d, %d }\n"
711 "}widget_class \"*Progress*\" style \"msw-progress\"\n",
715 btn_face.red, btn_face.green, btn_face.blue);
716 gtk_rc_parse_string(buf);
718 /* scrollbar thumb width and height */
719 g_snprintf(buf, sizeof (buf),
720 "style \"msw-vscrollbar\" = \"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 \"*VScrollbar*\" style \"msw-vscrollbar\"\n",
726 GetSystemMetrics(SM_CYVTHUMB),
727 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL));
728 gtk_rc_parse_string(buf);
730 g_snprintf(buf, sizeof (buf),
731 "style \"msw-hscrollbar\" = \"msw-default\"\n"
732 "{GtkRange::slider-width = %d\n"
733 "GtkRange::stepper-size = %d\n"
734 "GtkRange::stepper-spacing = 0\n"
735 "GtkRange::trough_border = 0\n"
736 "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n",
737 GetSystemMetrics(SM_CXHTHUMB),
738 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL));
739 gtk_rc_parse_string(buf);
741 /* radio/check button sizes */
742 g_snprintf(buf, sizeof (buf),
743 "style \"msw-checkbutton\" = \"msw-button\"\n"
744 "{GtkCheckButton::indicator-size = 13\n"
745 "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
746 "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
747 gtk_rc_parse_string(buf);
751 setup_system_styles(GtkStyle *style)
755 /* Default background */
756 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_NORMAL]);
757 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
758 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_INSENSITIVE]);
759 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_ACTIVE]);
760 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_PRELIGHT]);
763 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_NORMAL]);
764 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
765 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_INSENSITIVE]);
766 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_ACTIVE]);
767 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_PRELIGHT]);
770 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_NORMAL]);
771 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
772 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_GRAYTEXT, &style->text[GTK_STATE_INSENSITIVE]);
773 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->text[GTK_STATE_ACTIVE]);
774 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_PRELIGHT]);
776 /* Default forgeground */
777 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_NORMAL]);
778 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
779 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_GRAYTEXT, &style->fg[GTK_STATE_INSENSITIVE]);
780 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_ACTIVE]);
781 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->fg[GTK_STATE_PRELIGHT]);
783 for (i = 0; i < 5; i++)
785 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW, &style->dark[i]);
786 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT, &style->light[i]);
788 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
789 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
790 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
792 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
793 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
794 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
799 sanitize_size (GdkWindow *window,
803 gboolean set_bg = FALSE;
805 if ((*width == -1) && (*height == -1))
807 set_bg = GDK_IS_WINDOW (window);
808 gdk_window_get_size (window, width, height);
810 else if (*width == -1)
811 gdk_window_get_size (window, width, NULL);
812 else if (*height == -1)
813 gdk_window_get_size (window, NULL, height);
818 static XpThemeElement
819 map_gtk_progress_bar_to_xp(GtkProgressBar *progress_bar, gboolean trough)
822 switch (progress_bar->orientation)
824 case GTK_PROGRESS_LEFT_TO_RIGHT:
825 case GTK_PROGRESS_RIGHT_TO_LEFT:
827 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
828 : XP_THEME_ELEMENT_PROGRESS_BAR_H;
832 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
833 : XP_THEME_ELEMENT_PROGRESS_BAR_V;
840 draw_part (GdkDrawable *drawable,
848 gdk_gc_set_clip_rectangle (gc, area);
850 if (!parts[part].bmap)
851 parts[part].bmap = gdk_bitmap_create_from_data (drawable,
853 PART_SIZE, PART_SIZE);
855 gdk_gc_set_ts_origin (gc, x, y);
856 gdk_gc_set_stipple (gc, parts[part].bmap);
857 gdk_gc_set_fill (gc, GDK_STIPPLED);
859 gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
861 gdk_gc_set_fill (gc, GDK_SOLID);
864 gdk_gc_set_clip_rectangle (gc, NULL);
868 draw_check(GtkStyle *style,
871 GtkShadowType shadow,
880 x -= (1 + PART_SIZE - width) / 2;
881 y -= (1 + PART_SIZE - height) / 2;
883 if (detail && strcmp (detail, "check") == 0) /* Menu item */
885 if (shadow == GTK_SHADOW_IN)
887 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
888 draw_part (window, style->dark_gc[state], area, x, y, CHECK_AA);
893 if (xp_theme_draw(window, shadow == GTK_SHADOW_IN
894 ? XP_THEME_ELEMENT_PRESSED_CHECKBOX
895 : XP_THEME_ELEMENT_CHECKBOX,
896 style, x, y, width, height, state, area))
901 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
902 draw_part (window, style->dark_gc[state], area, x, y, CHECK_DARK);
903 draw_part (window, style->mid_gc[state], area, x, y, CHECK_MID);
904 draw_part (window, style->light_gc[state], area, x, y, CHECK_LIGHT);
905 draw_part (window, style->base_gc[state], area, x, y, CHECK_BASE);
907 if (shadow == GTK_SHADOW_IN)
909 draw_part (window, style->text_gc[state], area, x, y, CHECK_TEXT);
910 draw_part (window, style->text_aa_gc[state], area, x, y, CHECK_AA);
917 draw_expander(GtkStyle *style,
925 GtkExpanderStyle expander_style)
928 gint expander_semi_size;
932 XpThemeElement xp_expander;
934 gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
936 switch (expander_style)
938 case GTK_EXPANDER_COLLAPSED:
939 case GTK_EXPANDER_SEMI_COLLAPSED:
940 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
943 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
947 if ((expander_size % 2) == 0)
950 if (expander_size > 2)
954 gdk_gc_set_clip_rectangle (style->fg_gc[state], area);
956 expander_semi_size = expander_size / 2;
957 x -= expander_semi_size;
958 y -= expander_semi_size;
960 gdk_gc_get_values (style->fg_gc[state], &values);
962 if (! xp_theme_draw(window, xp_expander, style,
964 expander_size, expander_size, state, area))
966 /* RGB values to emulate Windows Classic style */
967 color.red = color.green = color.blue = 128 << 8;
969 success = gdk_colormap_alloc_color
970 (gtk_widget_get_default_colormap (), &color, FALSE, TRUE);
973 gdk_gc_set_foreground (style->fg_gc[state], &color);
976 (window, style->fg_gc[state], FALSE, x, y,
977 expander_size - 1, expander_size - 1);
980 (window, style->fg_gc[state], x + 2, y + expander_semi_size,
981 x + expander_size - 2, y + expander_semi_size);
983 switch (expander_style)
985 case GTK_EXPANDER_COLLAPSED:
986 case GTK_EXPANDER_SEMI_COLLAPSED:
988 (window, style->fg_gc[state], x + expander_semi_size, y + 2,
989 x + expander_semi_size, y + expander_size - 2);
994 gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
998 gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
1002 draw_option(GtkStyle *style,
1005 GtkShadowType shadow,
1008 const gchar *detail,
1014 x -= (1 + PART_SIZE - width) / 2;
1015 y -= (1 + PART_SIZE - height) / 2;
1017 if (detail && strcmp (detail, "option") == 0) /* Menu item */
1019 if (shadow == GTK_SHADOW_IN)
1020 draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
1024 if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1025 ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1026 : XP_THEME_ELEMENT_RADIO_BUTTON,
1027 style, x, y, width, height, state, area))
1032 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
1033 draw_part (window, style->dark_gc[state], area, x, y, RADIO_DARK);
1034 draw_part (window, style->mid_gc[state], area, x, y, RADIO_MID);
1035 draw_part (window, style->light_gc[state], area, x, y, RADIO_LIGHT);
1036 draw_part (window, style->base_gc[state], area, x, y, RADIO_BASE);
1038 if (shadow == GTK_SHADOW_IN)
1039 draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
1045 draw_varrow (GdkWindow *window,
1047 GtkShadowType shadow_type,
1049 GtkArrowType arrow_type,
1056 gint y_start, y_increment;
1060 gdk_gc_set_clip_rectangle (gc, area);
1062 width = width + width % 2 - 1; /* Force odd */
1064 steps = 1 + width / 2;
1066 extra = height - steps;
1068 if (arrow_type == GTK_ARROW_DOWN)
1075 y_start = y + height - 1;
1080 for (i = 0; i < extra; i++)
1082 gdk_draw_line (window, gc,
1083 x, y_start + i * y_increment,
1084 x + width - 1, y_start + i * y_increment);
1087 for (i = extra; i < height; i++)
1089 gdk_draw_line (window, gc,
1090 x + (i - extra), y_start + i * y_increment,
1091 x + width - (i - extra) - 1, y_start + i * y_increment);
1096 gdk_gc_set_clip_rectangle (gc, NULL);
1100 draw_harrow (GdkWindow *window,
1102 GtkShadowType shadow_type,
1104 GtkArrowType arrow_type,
1111 gint x_start, x_increment;
1115 gdk_gc_set_clip_rectangle (gc, area);
1117 height = height + height % 2 - 1; /* Force odd */
1119 steps = 1 + height / 2;
1121 extra = width - steps;
1123 if (arrow_type == GTK_ARROW_RIGHT)
1130 x_start = x + width - 1;
1134 for (i = extra; i < width; i++)
1136 gdk_draw_line (window, gc,
1137 x_start + i * x_increment, y + (i - extra),
1138 x_start + i * x_increment, y + height - (i - extra) - 1);
1143 gdk_gc_set_clip_rectangle (gc, NULL);
1146 /* This function makes up for some brokeness in gtkrange.c
1147 * where we never get the full arrow of the stepper button
1148 * and the type of button in a single drawing function.
1150 * It doesn't work correctly when the scrollbar is squished
1151 * to the point we don't have room for full-sized steppers.
1154 reverse_engineer_stepper_box (GtkWidget *range,
1155 GtkArrowType arrow_type,
1161 gint slider_width = 14, stepper_size = 14;
1167 gtk_widget_style_get (range,
1168 "slider_width", &slider_width,
1169 "stepper_size", &stepper_size,
1173 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1175 box_width = slider_width;
1176 box_height = stepper_size;
1180 box_width = stepper_size;
1181 box_height = slider_width;
1184 *x = *x - (box_width - *width) / 2;
1185 *y = *y - (box_height - *height) / 2;
1187 *height = box_height;
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")))
1234 gint box_width = width;
1235 gint box_height = height;
1236 XpThemeElement xp_arrow;
1237 reverse_engineer_stepper_box (widget, arrow_type,
1238 &box_x, &box_y, &box_width, &box_height);
1243 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1245 case GTK_ARROW_DOWN:
1246 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1248 case GTK_ARROW_LEFT:
1249 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1252 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1255 if (xp_theme_draw(window, xp_arrow, style, box_x, box_y, box_width, box_height, state, area))
1258 else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1260 x += (width - 7) / 2;
1261 y += (height - 5) / 2;
1263 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1268 y += (height - 7) / 2;
1269 x += (width - 5) / 2;
1271 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1277 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1278 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1280 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1284 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1286 x += (width - 7) / 2;
1287 y += (height - 5) / 2;
1289 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1294 x += (width - 5) / 2;
1295 y += (height - 7) / 2;
1297 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1304 option_menu_get_props (GtkWidget *widget,
1305 GtkRequisition *indicator_size,
1306 GtkBorder *indicator_spacing)
1308 GtkRequisition *tmp_size = NULL;
1309 GtkBorder *tmp_spacing = NULL;
1312 gtk_widget_style_get (widget,
1313 "indicator_size", &tmp_size,
1314 "indicator_spacing", &tmp_spacing,
1319 *indicator_size = *tmp_size;
1323 *indicator_size = default_option_indicator_size;
1327 *indicator_spacing = *tmp_spacing;
1328 g_free (tmp_spacing);
1331 *indicator_spacing = default_option_indicator_spacing;
1334 static gboolean is_toolbar_child(GtkWidget * wid)
1338 if(GTK_IS_TOOLBAR(wid))
1348 draw_box (GtkStyle *style,
1350 GtkStateType state_type,
1351 GtkShadowType shadow_type,
1354 const gchar *detail,
1361 (!strcmp (detail, "button") ||
1362 !strcmp (detail, "buttondefault")))
1364 if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1366 if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1367 width, height, state_type, area))
1370 else if (is_toolbar_child (widget->parent))
1372 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1373 width, height, state_type, area))
1378 gboolean is_default = !strcmp (detail, "buttondefault");
1379 if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1380 : XP_THEME_ELEMENT_BUTTON, style, x, y,
1381 width, height, state_type, area))
1385 else if (detail && !strcmp (detail, "spinbutton"))
1387 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1392 else if (detail && (!strcmp (detail, "spinbutton_up")
1393 || !strcmp (detail, "spinbutton_down")))
1395 if (xp_theme_draw(window,
1396 (! strcmp (detail, "spinbutton_up"))
1397 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1398 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1399 style, x, y, width, height, state_type, area))
1405 else if (detail && !strcmp (detail, "slider"))
1407 if (GTK_IS_SCROLLBAR(widget))
1409 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1410 gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1411 if (xp_theme_draw(window,
1413 ? XP_THEME_ELEMENT_SCROLLBAR_V
1414 : XP_THEME_ELEMENT_SCROLLBAR_H,
1415 style, x, y, width, height, state_type, area))
1417 XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1419 /* Do not display grippers on tiny scroll bars, the limit imposed
1420 is rather arbitrary, perhaps we can fetch the gripper geometry
1421 from somewhere and use that... */
1422 if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1423 || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1428 xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1433 else if (detail && !strcmp (detail, "bar"))
1435 if (widget && GTK_IS_PROGRESS_BAR (widget))
1437 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1438 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1439 if (xp_theme_draw (window, xp_progress_bar,
1440 style, x, y, width, height, state_type, area))
1446 else if (detail && !strcmp (detail, "handlebox_bin")) {
1447 if (xp_theme_draw (window, XP_THEME_ELEMENT_REBAR, style, x, y, width, height, state_type, area))
1452 else if (detail && strcmp (detail, "menuitem") == 0) {
1453 shadow_type = GTK_SHADOW_NONE;
1454 if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1459 else if (detail && !strcmp (detail, "trough"))
1461 if (widget && GTK_IS_PROGRESS_BAR (widget))
1463 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1464 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1465 if (xp_theme_draw (window, xp_progress_bar,
1466 style, x, y, width, height, state_type, area))
1472 /* Blank in classic Windows */
1475 else if (widget && GTK_IS_SCROLLBAR(widget))
1477 gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1479 if (GTK_IS_RANGE(widget)
1480 && xp_theme_draw(window,
1482 ? XP_THEME_ELEMENT_TROUGH_V
1483 : XP_THEME_ELEMENT_TROUGH_H,
1485 x, y, width, height, state_type, area))
1491 GdkGCValues gc_values;
1495 sanitize_size (window, &width, &height);
1497 pixmap = gdk_pixmap_new (window, 2, 2, -1);
1499 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1500 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1501 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1502 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1504 gc_values.fill = GDK_TILED;
1505 gc_values.tile = pixmap;
1506 gc_values.ts_x_origin = x;
1507 gc_values.ts_y_origin = y;
1508 gc = gdk_gc_new_with_values (window, &gc_values,
1509 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1512 gdk_gc_set_clip_rectangle (gc, area);
1514 gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1517 gdk_pixmap_unref (pixmap);
1522 else if (widget && GTK_IS_SCALE(widget))
1524 gboolean is_vertical = GTK_IS_VSCALE(widget);
1526 parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1527 widget, detail, x, y, width, height);
1530 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1532 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1537 else if (detail && strcmp (detail, "optionmenu") == 0)
1539 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1540 style, x, y, width, height, state_type, area))
1545 else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1547 if (shadow_type == GTK_SHADOW_IN)
1548 shadow_type = GTK_SHADOW_ETCHED_IN;
1552 const gchar * name = gtk_widget_get_name (widget);
1554 if (name && !strcmp (name, "gtk-tooltips")) {
1555 if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1562 parent_class->draw_box (style, window, state_type, shadow_type, area,
1563 widget, detail, x, y, width, height);
1565 if (detail && strcmp (detail, "optionmenu") == 0)
1567 GtkRequisition indicator_size;
1568 GtkBorder indicator_spacing;
1571 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1573 sanitize_size (window, &width, &height);
1575 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1576 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1578 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1580 parent_class->draw_vline (style, window, state_type, area, widget,
1582 y + style->ythickness + 1,
1583 y + height - style->ythickness - 3,
1589 draw_tab (GtkStyle *style,
1592 GtkShadowType shadow,
1595 const gchar *detail,
1601 GtkRequisition indicator_size;
1602 GtkBorder indicator_spacing;
1606 g_return_if_fail (style != NULL);
1607 g_return_if_fail (window != NULL);
1609 if (detail && ! strcmp (detail, "optionmenutab"))
1611 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1612 style, x-5, widget->allocation.y+1,
1613 width+10, widget->allocation.height-2, state, area))
1620 gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1622 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1624 x += (width - indicator_size.width) / 2;
1625 arrow_height = (indicator_size.width + 1) / 2;
1627 y += (height - arrow_height) / 2;
1629 draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1630 x, y, indicator_size.width, arrow_height);
1633 /* this is an undefined magic value that, according to the mozilla folks,
1634 worked for all the various themes that they tried */
1635 #define XP_EDGE_SIZE 2
1638 draw_extension(GtkStyle *style,
1640 GtkStateType state_type,
1641 GtkShadowType shadow_type,
1644 const gchar *detail,
1649 GtkPositionType gap_side)
1651 if (detail && !strcmp(detail, "tab"))
1653 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1654 GtkPositionType pos_type = gtk_notebook_get_tab_pos(notebook);
1656 if (pos_type == GTK_POS_TOP && state_type == GTK_STATE_NORMAL)
1657 height += XP_EDGE_SIZE;
1660 /* FIXME: pos != TOP to be implemented */
1661 else if (pos_type == GTK_POS_BOTTOM)
1663 else if (pos_type == GTK_POS_RIGHT)
1664 width += XP_EDGE_SIZE;
1665 else if (pos_type == GTK_POS_LEFT)
1666 height -= XP_EDGE_SIZE;
1669 if (pos_type == GTK_POS_TOP
1671 (window, gtk_notebook_get_current_page(notebook)==0
1672 ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1673 : XP_THEME_ELEMENT_TAB_ITEM,
1674 style, x, y, width, height, state_type, area))
1679 parent_class->draw_extension
1680 (style, window, state_type, shadow_type, area, widget, detail,
1681 x, y, width, height, gap_side);
1685 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1686 GtkShadowType shadow_type, GdkRectangle *area,
1687 GtkWidget *widget, const gchar *detail, gint x,
1688 gint y, gint width, gint height, GtkPositionType gap_side,
1689 gint gap_x, gint gap_width)
1691 if (detail && !strcmp(detail, "notebook"))
1693 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1695 /* FIXME: pos != TOP to be implemented */
1696 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
1702 parent_class->draw_box_gap(style, window, state_type, shadow_type,
1703 area, widget, detail, x, y, width, height,
1704 gap_side, gap_x, gap_width);
1708 draw_flat_box (GtkStyle *style, GdkWindow *window,
1709 GtkStateType state_type, GtkShadowType shadow_type,
1710 GdkRectangle *area, GtkWidget *widget,
1711 const gchar *detail, gint x, gint y,
1712 gint width, gint height)
1714 if (detail && ! strcmp (detail, "checkbutton"))
1716 if (state_type == GTK_STATE_PRELIGHT)
1722 parent_class->draw_flat_box(style, window, state_type, shadow_type,
1723 area, widget, detail, x, y, width, height);
1727 draw_shadow (GtkStyle *style,
1729 GtkStateType state_type,
1730 GtkShadowType shadow_type,
1733 const gchar *detail,
1739 if(detail && ! strcmp(detail, "entry"))
1741 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1742 x, y, width, height, state_type, area))
1747 parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1748 detail, x, y, width, height);
1752 draw_hline (GtkStyle *style,
1754 GtkStateType state_type,
1757 const gchar *detail,
1763 if (detail && !strcmp(detail, "menuitem")) {
1764 if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1765 x1, y, x2, style->ythickness, state_type, area)) {
1770 parent_class->draw_hline (style, window, state_type, area, widget,
1775 draw_vline (GtkStyle *style,
1777 GtkStateType state_type,
1780 const gchar *detail,
1785 parent_class->draw_vline (style, window, state_type, area, widget,
1790 draw_resize_grip (GtkStyle *style,
1792 GtkStateType state_type,
1795 const gchar *detail,
1802 if (detail && !strcmp(detail, "statusbar")) {
1803 if (!xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1808 parent_class->draw_resize_grip (style, window, state_type, area,
1809 widget, detail, edge, x, y, width, height);
1813 draw_handle (GtkStyle *style,
1815 GtkStateType state_type,
1816 GtkShadowType shadow_type,
1819 const gchar *detail,
1824 GtkOrientation orientation)
1826 if (! GTK_IS_HANDLE_BOX (widget))
1828 XpThemeElement hndl;
1830 sanitize_size (window, &width, &height);
1832 if (orientation == GTK_ORIENTATION_VERTICAL)
1833 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1835 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1837 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);
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 ();
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 ();