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://lxr.mozilla.org/seamonkey/source/widget/src/windows/nsLookAndFeel.cpp
28 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/functions/drawthemebackground.asp
31 #include "msw_style.h"
41 /* #include <gdk/gdkwin32.h> */
42 #include "gdk/win32/gdkwin32.h"
45 /* Default values, not normally used
47 static const GtkRequisition default_option_indicator_size = { 9, 8 };
48 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
50 static GtkStyleClass *parent_class;
70 static const guint8 check_aa_bits[] = {
71 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
72 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
73 static const guint8 check_base_bits[] = {
74 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
75 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
76 static const guint8 check_black_bits[] = {
77 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
78 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
79 static const guint8 check_dark_bits[] = {
80 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
81 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
82 static const guint8 check_light_bits[] = {
83 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
84 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
85 static const guint8 check_mid_bits[] = {
86 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
87 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
88 static const guint8 check_text_bits[] = {
89 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x88,0x03,0xd8,0x01,0xf8,
90 0x00,0x70,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
91 static const guint8 radio_base_bits[] = {
92 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
93 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
94 static const guint8 radio_black_bits[] = {
95 0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
96 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
97 static const guint8 radio_dark_bits[] = {
98 0xf0,0x01,0x0c,0x06,0x02,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
99 0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
100 static const guint8 radio_light_bits[] = {
101 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
102 0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x0c,0x06,0xf0,0x01};
103 static const guint8 radio_mid_bits[] = {
104 0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
105 0x08,0x00,0x08,0x00,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00};
106 static const guint8 radio_text_bits[] = {
107 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
108 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
114 { check_aa_bits, NULL },
115 { check_base_bits, NULL },
116 { check_black_bits, NULL },
117 { check_dark_bits, NULL },
118 { check_light_bits, NULL },
119 { check_mid_bits, NULL },
120 { check_text_bits, NULL },
121 { radio_base_bits, NULL },
122 { radio_black_bits, NULL },
123 { radio_dark_bits, NULL },
124 { radio_light_bits, NULL },
125 { radio_mid_bits, NULL },
126 { radio_text_bits, NULL }
130 get_system_font(XpThemeClass klazz, XpThemeFont type, LOGFONT *out_lf)
133 /* TODO: this causes crashes later because the font name is in UCS2, and the pango fns don't deal with that gracefully */
134 if (xp_theme_get_system_font(klazz, type, out_lf))
139 NONCLIENTMETRICS ncm;
140 ncm.cbSize = sizeof(NONCLIENTMETRICS);
142 if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
143 sizeof(NONCLIENTMETRICS), &ncm, 0))
145 if (type == XP_THEME_FONT_CAPTION)
146 *out_lf = ncm.lfCaptionFont;
147 else if (type == XP_THEME_FONT_MENU)
148 *out_lf = ncm.lfMenuFont;
149 else if (type == XP_THEME_FONT_STATUS)
150 *out_lf = ncm.lfStatusFont;
152 *out_lf = ncm.lfMessageFont;
160 /***************************** BEGIN STOLEN FROM PANGO *****************************/
163 This code is stolen from Pango 1.4. It attempts to address the following problems:
165 http://bugzilla.gnome.org/show_bug.cgi?id=135098
166 http://sourceforge.net/tracker/index.php?func=detail&aid=895762&group_id=76416&atid=547655
168 As Owen suggested in bug 135098, once Pango 1.6 is released, we need to get rid of this code.
171 #define PING(printlist)
173 /* TrueType defines: */
175 #define MAKE_TT_TABLE_NAME(c1, c2, c3, c4) \
176 (((guint32)c4) << 24 | ((guint32)c3) << 16 | ((guint32)c2) << 8 | ((guint32)c1))
178 #define CMAP (MAKE_TT_TABLE_NAME('c','m','a','p'))
179 #define CMAP_HEADER_SIZE 4
181 #define NAME (MAKE_TT_TABLE_NAME('n','a','m','e'))
182 #define NAME_HEADER_SIZE 6
184 #define ENCODING_TABLE_SIZE 8
186 #define APPLE_UNICODE_PLATFORM_ID 0
187 #define MACINTOSH_PLATFORM_ID 1
188 #define ISO_PLATFORM_ID 2
189 #define MICROSOFT_PLATFORM_ID 3
191 #define SYMBOL_ENCODING_ID 0
192 #define UNICODE_ENCODING_ID 1
193 #define UCS4_ENCODING_ID 10
197 guint16 format_selector;
199 guint16 string_storage_offset;
208 guint16 string_length;
209 guint16 string_offset;
213 pango_win32_get_name_header (HDC hdc,
214 struct name_header *header)
216 if (GetFontData (hdc, NAME, 0, header, sizeof (*header)) != sizeof (*header))
219 header->num_records = GUINT16_FROM_BE (header->num_records);
220 header->string_storage_offset = GUINT16_FROM_BE (header->string_storage_offset);
226 pango_win32_get_name_record (HDC hdc,
228 struct name_record *record)
230 if (GetFontData (hdc, NAME, 6 + i * sizeof (*record),
231 record, sizeof (*record)) != sizeof (*record))
234 record->platform_id = GUINT16_FROM_BE (record->platform_id);
235 record->encoding_id = GUINT16_FROM_BE (record->encoding_id);
236 record->language_id = GUINT16_FROM_BE (record->language_id);
237 record->name_id = GUINT16_FROM_BE (record->name_id);
238 record->string_length = GUINT16_FROM_BE (record->string_length);
239 record->string_offset = GUINT16_FROM_BE (record->string_offset);
245 get_family_name (LOGFONT *lfp, HDC pango_win32_hdc)
250 struct name_header header;
251 struct name_record record;
253 gint unicode_ix = -1, mac_ix = -1, microsoft_ix = -1;
257 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 = (HFONT)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)
556 char buf[1024], font_buf[256], *font_ptr;
559 GdkColor menu_text_color;
560 GdkColor tooltip_back;
561 GdkColor tooltip_fore;
564 GdkColor progress_back;
566 GdkColor fg_prelight;
567 GdkColor bg_prelight;
568 GdkColor base_prelight;
569 GdkColor text_prelight;
571 gboolean xp_theme = xp_theme_is_active();
574 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &fg_prelight);
575 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
576 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &base_prelight);
577 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &text_prelight);
579 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENUTEXT, &menu_text_color);
580 sys_color_to_gtk_color(XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);
583 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT, &tooltip_fore);
584 sys_color_to_gtk_color(XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK, &tooltip_back);
586 /* text on push buttons. TODO: button shadows, backgrounds, and highlights */
587 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
588 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
590 /* progress bar background color */
591 sys_color_to_gtk_color(XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT, &progress_back);
593 /* Enable coloring for menus. */
594 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,font_buf, sizeof (font_buf));
595 g_snprintf(buf, sizeof (buf),
596 "style \"msw-menu\" = \"msw-default\"\n"
598 "fg[PRELIGHT] = { %d, %d, %d }\n"
599 "bg[PRELIGHT] = { %d, %d, %d }\n"
600 "text[PRELIGHT] = { %d, %d, %d }\n"
601 "base[PRELIGHT] = { %d, %d, %d }\n"
602 "fg[NORMAL] = { %d, %d, %d }\n"
603 "bg[NORMAL] = { %d, %d, %d }\n"
605 "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
606 "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
607 "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
621 menu_text_color.green,
622 menu_text_color.blue,
626 (font_ptr ? "font_name" : "#"),
627 (font_ptr ? font_ptr : " font name should go here"));
628 gtk_rc_parse_string(buf);
630 /* Enable coloring for menu bars. */
631 g_snprintf(buf, sizeof (buf),
632 "style \"msw-menu-bar\" = \"msw-menu\"\n"
634 "bg[NORMAL] = { %d, %d, %d }\n"
635 "GtkMenuBar::shadow-type = %s\n"
636 "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
640 (xp_theme ? "etched-in" : "out"));
641 gtk_rc_parse_string(buf);
643 g_snprintf(buf, sizeof (buf),
644 "style \"msw-toolbar\" = \"msw-default\"\n"
646 "GtkHandleBox::shadow-type = %s\n"
647 "GtkToolbar::shadow-type = %s\n"
648 "}widget_class \"*HandleBox*\" style \"msw-toolbar\"\n",
649 (xp_theme ? "none" : "out"),
650 (xp_theme ? "none" : "out"));
651 gtk_rc_parse_string(buf);
653 /* enable tooltip fonts */
654 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
655 g_snprintf(buf, sizeof (buf),
656 "style \"msw-tooltips-caption\" = \"msw-default\"\n"
657 "{fg[NORMAL] = { %d, %d, %d }\n"
659 "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
663 (font_ptr ? "font_name" : "#"),
664 (font_ptr ? font_ptr : " font name should go here"));
665 gtk_rc_parse_string(buf);
667 g_snprintf(buf, sizeof (buf),
668 "style \"msw-tooltips\" = \"msw-default\"\n"
669 "{bg[NORMAL] = { %d, %d, %d }\n"
670 "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
674 gtk_rc_parse_string(buf);
676 /* enable font theming for status bars */
677 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,font_buf, sizeof (font_buf));
678 g_snprintf(buf, sizeof (buf),
679 "style \"msw-status\" = \"msw-default\"\n"
681 "bg[NORMAL] = { %d, %d, %d }\n"
682 "}widget_class \"*Status*\" style \"msw-status\"\n",
683 (font_ptr ? "font_name" : "#"),
684 (font_ptr ? font_ptr : " font name should go here"),
685 btn_face.red, btn_face.green, btn_face.blue);
686 gtk_rc_parse_string(buf);
688 /* enable coloring for text on buttons
689 TODO: use GetThemeMetric for the border and outside border */
690 g_snprintf(buf, sizeof (buf),
691 "style \"msw-button\" = \"msw-default\"\n"
693 "bg[NORMAL] = { %d, %d, %d }\n"
694 "bg[PRELIGHT] = { %d, %d, %d }\n"
695 "bg[INSENSITIVE] = { %d, %d, %d }\n"
696 "fg[PRELIGHT] = { %d, %d, %d }\n"
697 "GtkButton::default-border = { 1, 1, 1, 1 }\n"
698 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
699 "GtkButton::child-displacement-x = 1\n"
700 "GtkButton::child-displacement-y = 1\n"
701 "}widget_class \"*Button*\" style \"msw-button\"\n",
702 btn_face.red, btn_face.green, btn_face.blue,
703 btn_face.red, btn_face.green, btn_face.blue,
704 btn_face.red, btn_face.green, btn_face.blue,
705 btn_fore.red, btn_fore.green, btn_fore.blue
707 gtk_rc_parse_string(buf);
709 /* enable coloring for progress bars */
710 g_snprintf(buf, sizeof (buf),
711 "style \"msw-progress\" = \"msw-default\"\n"
712 "{bg[PRELIGHT] = { %d, %d, %d }\n"
713 "bg[NORMAL] = { %d, %d, %d }\n"
714 "}widget_class \"*Progress*\" style \"msw-progress\"\n",
718 btn_face.red, btn_face.green, btn_face.blue);
719 gtk_rc_parse_string(buf);
721 /* scrollbar thumb width and height */
722 g_snprintf(buf, sizeof (buf),
723 "style \"msw-vscrollbar\" = \"msw-default\"\n"
724 "{GtkRange::slider-width = %d\n"
725 "GtkRange::stepper-size = %d\n"
726 "GtkRange::stepper-spacing = 0\n"
727 "GtkRange::trough_border = 0\n"
728 "GtkScale::slider-length = %d\n"
729 "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n"
730 "widget_class \"*VScale*\" style \"msw-vscrollbar\"\n",
731 GetSystemMetrics(SM_CYVTHUMB),
732 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL),
734 gtk_rc_parse_string(buf);
736 g_snprintf(buf, sizeof (buf),
737 "style \"msw-hscrollbar\" = \"msw-default\"\n"
738 "{GtkRange::slider-width = %d\n"
739 "GtkRange::stepper-size = %d\n"
740 "GtkRange::stepper-spacing = 0\n"
741 "GtkRange::trough_border = 0\n"
742 "GtkScale::slider-length = %d\n"
743 "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n"
744 "widget_class \"*HScale*\" style \"msw-hscrollbar\"\n",
745 GetSystemMetrics(SM_CXHTHUMB),
746 get_system_metric(XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL),
748 gtk_rc_parse_string(buf);
750 /* radio/check button sizes */
751 g_snprintf(buf, sizeof (buf),
752 "style \"msw-checkbutton\" = \"msw-button\"\n"
753 "{GtkCheckButton::indicator-size = 13\n"
754 "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
755 "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
756 gtk_rc_parse_string(buf);
760 setup_system_styles(GtkStyle *style)
764 /* Default background */
765 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_NORMAL]);
766 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
767 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_INSENSITIVE]);
768 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_ACTIVE]);
769 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->bg[GTK_STATE_PRELIGHT]);
772 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_NORMAL]);
773 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
774 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_INSENSITIVE]);
775 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &style->base[GTK_STATE_ACTIVE]);
776 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOW, &style->base[GTK_STATE_PRELIGHT]);
779 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_NORMAL]);
780 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
781 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_GRAYTEXT, &style->text[GTK_STATE_INSENSITIVE]);
782 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->text[GTK_STATE_ACTIVE]);
783 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->text[GTK_STATE_PRELIGHT]);
785 /* Default foreground */
786 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_NORMAL]);
787 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
788 sys_color_to_gtk_color(XP_THEME_CLASS_TEXT, COLOR_GRAYTEXT, &style->fg[GTK_STATE_INSENSITIVE]);
789 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &style->fg[GTK_STATE_ACTIVE]);
790 sys_color_to_gtk_color(XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT, &style->fg[GTK_STATE_PRELIGHT]);
792 for (i = 0; i < 5; i++)
794 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW, &style->dark[i]);
795 sys_color_to_gtk_color(XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT, &style->light[i]);
797 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
798 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
799 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
801 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
802 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
803 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
808 sanitize_size (GdkWindow *window,
812 gboolean set_bg = FALSE;
814 if ((*width == -1) && (*height == -1))
816 set_bg = GDK_IS_WINDOW (window);
817 gdk_drawable_get_size (window, width, height);
819 else if (*width == -1)
820 gdk_drawable_get_size (window, width, NULL);
821 else if (*height == -1)
822 gdk_drawable_get_size (window, NULL, height);
827 static XpThemeElement
828 map_gtk_progress_bar_to_xp(GtkProgressBar *progress_bar, gboolean trough)
831 switch (progress_bar->orientation)
833 case GTK_PROGRESS_LEFT_TO_RIGHT:
834 case GTK_PROGRESS_RIGHT_TO_LEFT:
836 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
837 : XP_THEME_ELEMENT_PROGRESS_BAR_H;
841 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
842 : XP_THEME_ELEMENT_PROGRESS_BAR_V;
849 draw_part (GdkDrawable *drawable,
857 gdk_gc_set_clip_rectangle (gc, area);
859 if (!parts[part].bmap)
860 parts[part].bmap = gdk_bitmap_create_from_data (drawable,
862 PART_SIZE, PART_SIZE);
864 gdk_gc_set_ts_origin (gc, x, y);
865 gdk_gc_set_stipple (gc, parts[part].bmap);
866 gdk_gc_set_fill (gc, GDK_STIPPLED);
868 gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
870 gdk_gc_set_fill (gc, GDK_SOLID);
873 gdk_gc_set_clip_rectangle (gc, NULL);
877 draw_check(GtkStyle *style,
880 GtkShadowType shadow,
889 x -= (1 + PART_SIZE - width) / 2;
890 y -= (1 + PART_SIZE - height) / 2;
892 if (detail && strcmp (detail, "check") == 0) /* Menu item */
894 if (shadow == GTK_SHADOW_IN)
896 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
897 draw_part (window, style->dark_gc[state], area, x, y, CHECK_AA);
902 if (!xp_theme_draw(window, shadow == GTK_SHADOW_IN
903 ? XP_THEME_ELEMENT_PRESSED_CHECKBOX
904 : XP_THEME_ELEMENT_CHECKBOX,
905 style, x, y, width, height, state, area))
907 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
908 draw_part (window, style->dark_gc[state], area, x, y, CHECK_DARK);
909 draw_part (window, style->mid_gc[state], area, x, y, CHECK_MID);
910 draw_part (window, style->light_gc[state], area, x, y, CHECK_LIGHT);
911 draw_part (window, style->base_gc[state], area, x, y, CHECK_BASE);
913 if (shadow == GTK_SHADOW_IN)
915 draw_part (window, style->text_gc[state], area, x, y, CHECK_TEXT);
916 draw_part (window, style->text_aa_gc[state], area, x, y, CHECK_AA);
923 draw_expander(GtkStyle *style,
931 GtkExpanderStyle expander_style)
934 gint expander_semi_size;
938 XpThemeElement xp_expander;
940 gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
942 switch (expander_style)
944 case GTK_EXPANDER_COLLAPSED:
945 case GTK_EXPANDER_SEMI_COLLAPSED:
946 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
949 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
953 if ((expander_size % 2) == 0)
956 if (expander_size > 2)
960 gdk_gc_set_clip_rectangle (style->fg_gc[state], area);
962 expander_semi_size = expander_size / 2;
963 x -= expander_semi_size;
964 y -= expander_semi_size;
966 gdk_gc_get_values (style->fg_gc[state], &values);
968 if (! xp_theme_draw(window, xp_expander, style,
970 expander_size, expander_size, state, area))
972 /* RGB values to emulate Windows Classic style */
973 color.red = color.green = color.blue = 128 << 8;
975 success = gdk_colormap_alloc_color
976 (gtk_widget_get_default_colormap (), &color, FALSE, TRUE);
979 gdk_gc_set_foreground (style->fg_gc[state], &color);
982 (window, style->fg_gc[state], FALSE, x, y,
983 expander_size - 1, expander_size - 1);
986 (window, style->fg_gc[state], x + 2, y + expander_semi_size,
987 x + expander_size - 2, y + expander_semi_size);
989 switch (expander_style)
991 case GTK_EXPANDER_COLLAPSED:
992 case GTK_EXPANDER_SEMI_COLLAPSED:
994 (window, style->fg_gc[state], x + expander_semi_size, y + 2,
995 x + expander_semi_size, y + expander_size - 2);
1003 gdk_gc_set_foreground (style->fg_gc[state], &values.foreground);
1007 gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
1011 draw_option(GtkStyle *style,
1014 GtkShadowType shadow,
1017 const gchar *detail,
1023 x -= (1 + PART_SIZE - width) / 2;
1024 y -= (1 + PART_SIZE - height) / 2;
1026 if (detail && strcmp (detail, "option") == 0) /* Menu item */
1028 if (shadow == GTK_SHADOW_IN)
1029 draw_part (window, style->fg_gc[state], area, x, y, RADIO_TEXT);
1033 if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1034 ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1035 : XP_THEME_ELEMENT_RADIO_BUTTON,
1036 style, x, y, width, height, state, area))
1041 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
1042 draw_part (window, style->dark_gc[state], area, x, y, RADIO_DARK);
1043 draw_part (window, style->mid_gc[state], area, x, y, RADIO_MID);
1044 draw_part (window, style->light_gc[state], area, x, y, RADIO_LIGHT);
1045 draw_part (window, style->base_gc[state], area, x, y, RADIO_BASE);
1047 if (shadow == GTK_SHADOW_IN)
1048 draw_part (window, style->text_gc[state], area, x, y, RADIO_TEXT);
1054 draw_varrow (GdkWindow *window,
1056 GtkShadowType shadow_type,
1058 GtkArrowType arrow_type,
1065 gint y_start, y_increment;
1069 gdk_gc_set_clip_rectangle (gc, area);
1071 width = width + width % 2 - 1; /* Force odd */
1073 steps = 1 + width / 2;
1075 extra = height - steps;
1077 if (arrow_type == GTK_ARROW_DOWN)
1084 y_start = y + height - 1;
1088 for (i = extra; i < height; i++)
1090 gdk_draw_line (window, gc,
1091 x + (i - extra), y_start + i * y_increment,
1092 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;
1190 static XpThemeElement to_xp_arrow(GtkArrowType arrow_type)
1192 XpThemeElement xp_arrow;
1197 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1199 case GTK_ARROW_DOWN:
1200 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1202 case GTK_ARROW_LEFT:
1203 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1206 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1214 draw_arrow (GtkStyle *style,
1217 GtkShadowType shadow,
1220 const gchar *detail,
1221 GtkArrowType arrow_type,
1230 name = gtk_widget_get_name (widget);
1232 sanitize_size (window, &width, &height);
1234 if (detail && strcmp (detail, "spinbutton") == 0)
1236 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1242 x += (width - 7) / 2;
1244 if (arrow_type == GTK_ARROW_UP)
1245 y += (height - 4) / 2;
1247 y += (1 + height - 4) / 2;
1248 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1252 else if (detail && (!strcmp (detail, "vscrollbar")
1253 || !strcmp (detail, "hscrollbar")))
1255 gboolean is_disabled = FALSE;
1256 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1259 gint box_width = width;
1260 gint box_height = height;
1262 reverse_engineer_stepper_box (widget, arrow_type,
1263 &box_x, &box_y, &box_width, &box_height);
1265 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1268 if (xp_theme_draw(window, to_xp_arrow(arrow_type), style, box_x, box_y, box_width, box_height, state, area))
1271 else if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1273 x += (width - 7) / 2;
1274 y += (height - 5) / 2;
1276 draw_varrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1281 y += (height - 7) / 2;
1282 x += (width - 5) / 2;
1284 draw_harrow (window, is_disabled ? style->text_aa_gc[state] : style->fg_gc[state], shadow, area, arrow_type,
1290 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1291 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1293 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y, width, height, state, area))
1296 /* probably a gtk combo box on a toolbar */
1297 else if (0 /*widget->parent && GTK_IS_BUTTON (widget->parent)*/)
1299 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON, style, x-3, widget->allocation.y+1,
1300 width+5, widget->allocation.height-4, state, area))
1304 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1306 x += (width - 7) / 2;
1307 y += (height - 5) / 2;
1309 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
1314 x += (width - 5) / 2;
1315 y += (height - 7) / 2;
1317 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
1324 option_menu_get_props (GtkWidget *widget,
1325 GtkRequisition *indicator_size,
1326 GtkBorder *indicator_spacing)
1328 GtkRequisition *tmp_size = NULL;
1329 GtkBorder *tmp_spacing = NULL;
1332 gtk_widget_style_get (widget,
1333 "indicator_size", &tmp_size,
1334 "indicator_spacing", &tmp_spacing,
1339 *indicator_size = *tmp_size;
1343 *indicator_size = default_option_indicator_size;
1347 *indicator_spacing = *tmp_spacing;
1348 g_free (tmp_spacing);
1351 *indicator_spacing = default_option_indicator_spacing;
1354 static gboolean is_toolbar_child(GtkWidget * wid)
1358 if(GTK_IS_TOOLBAR(wid) || GTK_IS_HANDLE_BOX(wid))
1368 draw_box (GtkStyle *style,
1370 GtkStateType state_type,
1371 GtkShadowType shadow_type,
1374 const gchar *detail,
1381 (!strcmp (detail, "button") ||
1382 !strcmp (detail, "buttondefault")))
1384 if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
1386 if (xp_theme_draw(window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1387 width, height, state_type, area))
1390 else if (is_toolbar_child (widget->parent))
1392 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style, x, y,
1393 width, height, state_type, area))
1398 gboolean is_default = !strcmp (detail, "buttondefault");
1399 if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
1400 : XP_THEME_ELEMENT_BUTTON, style, x, y,
1401 width, height, state_type, area))
1405 else if (detail && !strcmp (detail, "spinbutton"))
1407 if (xp_theme_is_drawable(XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1412 else if (detail && (!strcmp (detail, "spinbutton_up")
1413 || !strcmp (detail, "spinbutton_down")))
1415 if (xp_theme_draw(window,
1416 (! strcmp (detail, "spinbutton_up"))
1417 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1418 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1419 style, x, y, width, height, state_type, area))
1424 else if (detail && !strcmp (detail, "slider"))
1426 if (GTK_IS_SCROLLBAR(widget))
1428 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1429 gboolean is_v = GTK_IS_VSCROLLBAR(widget);
1431 if (xp_theme_draw(window,
1433 ? XP_THEME_ELEMENT_SCROLLBAR_V
1434 : XP_THEME_ELEMENT_SCROLLBAR_H,
1435 style, x, y, width, height, state_type, area))
1437 XpThemeElement gripper = (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V : XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1439 /* Do not display grippers on tiny scroll bars, the limit imposed
1440 is rather arbitrary, perhaps we can fetch the gripper geometry
1441 from somewhere and use that... */
1442 if ((gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H && width < 16)
1443 || (gripper == XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1448 xp_theme_draw(window, gripper, style, x, y, width, height, state_type, area);
1453 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1458 else if (detail && !strcmp (detail, "bar"))
1460 if (widget && GTK_IS_PROGRESS_BAR (widget))
1462 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1463 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1464 if (xp_theme_draw (window, xp_progress_bar,
1465 style, x, y, width, height, state_type, area))
1471 else if (detail && strcmp (detail, "menuitem") == 0) {
1472 shadow_type = GTK_SHADOW_NONE;
1473 if (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style, x, y, width, height, state_type, area))
1478 else if (detail && !strcmp (detail, "trough"))
1480 if (widget && GTK_IS_PROGRESS_BAR (widget))
1482 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(widget);
1483 XpThemeElement xp_progress_bar = map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1484 if (xp_theme_draw (window, xp_progress_bar,
1485 style, x, y, width, height, state_type, area))
1491 /* Blank in classic Windows */
1494 else if (widget && GTK_IS_SCROLLBAR(widget))
1496 gboolean is_vertical = GTK_IS_VSCROLLBAR(widget);
1498 if (xp_theme_draw(window,
1500 ? XP_THEME_ELEMENT_TROUGH_V
1501 : XP_THEME_ELEMENT_TROUGH_H,
1503 x, y, width, height, state_type, area))
1509 GdkGCValues gc_values;
1513 sanitize_size (window, &width, &height);
1515 pixmap = gdk_pixmap_new (window, 2, 2, -1);
1517 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 0, 0);
1518 gdk_draw_point (pixmap, style->bg_gc[GTK_STATE_NORMAL], 1, 1);
1519 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 1, 0);
1520 gdk_draw_point (pixmap, style->light_gc[GTK_STATE_NORMAL], 0, 1);
1522 gc_values.fill = GDK_TILED;
1523 gc_values.tile = pixmap;
1524 gc_values.ts_x_origin = x;
1525 gc_values.ts_y_origin = y;
1526 gc = gdk_gc_new_with_values (window, &gc_values,
1527 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN | GDK_GC_FILL | GDK_GC_TILE);
1530 gdk_gc_set_clip_rectangle (gc, area);
1532 gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
1534 g_object_unref (gc);
1535 g_object_unref (pixmap);
1540 else if (widget && GTK_IS_SCALE(widget))
1542 gboolean is_vertical = GTK_IS_VSCALE(widget);
1544 if(!xp_theme_is_active ()) {
1545 parent_class->draw_box (style, window, state_type, GTK_SHADOW_NONE, area,
1546 widget, detail, x, y, width, height);
1550 if(xp_theme_draw(window, XP_THEME_ELEMENT_SCALE_TROUGH_V, style, (2 * x + width)/2, y, 2, height, state_type, area))
1553 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, (2 * x + width)/2, y, 1, height);
1556 if(xp_theme_draw(window, XP_THEME_ELEMENT_SCALE_TROUGH_H, style, x, (2 * y + height)/2, width, 2, state_type, area))
1559 parent_class->draw_box(style, window, state_type, GTK_SHADOW_ETCHED_IN, area, NULL, NULL, x, (2 * y + height)/2, width, 1);
1564 else if (detail && strcmp (detail, "optionmenu") == 0)
1566 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT,
1567 style, x, y, width, height, state_type, area))
1572 else if (detail && (strcmp (detail, "vscrollbar") == 0 || strcmp (detail, "hscrollbar") == 0))
1574 GtkScrollbar * scrollbar = GTK_SCROLLBAR(widget);
1575 if (shadow_type == GTK_SHADOW_IN)
1576 shadow_type = GTK_SHADOW_ETCHED_IN;
1577 if (scrollbar->range.adjustment->page_size >= (scrollbar->range.adjustment->upper-scrollbar->range.adjustment->lower))
1578 shadow_type = GTK_SHADOW_OUT;
1580 else if (detail && (strcmp (detail, "handlebox_bin") == 0 || strcmp (detail, "toolbar") == 0 ||
1581 strcmp (detail, "menubar") == 0))
1583 if (xp_theme_draw(window, XP_THEME_ELEMENT_REBAR,
1584 style, x, y, width, height, state_type, area))
1590 (!strcmp(detail, "handlebox"))) /* grip */
1595 const gchar * name = gtk_widget_get_name (widget);
1597 if (name && !strcmp (name, "gtk-tooltips")) {
1598 if (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width, height, state_type, area))
1605 GdkDrawable *drawable;
1609 if (!GDK_IS_WINDOW(window))
1617 gdk_window_get_internal_paint_info(window, &drawable, &xoff, &yoff);
1620 rect.left = x - xoff;
1621 rect.top = y - yoff;
1622 rect.right = rect.left + width;
1623 rect.bottom = rect.top + height;
1625 hdc = gdk_win32_hdc_get(window, style->dark_gc[state_type], 0);
1626 brush = GetSysColorBrush(COLOR_3DDKSHADOW);
1628 FrameRect(hdc, &rect, brush);
1629 InflateRect(&rect, -1, -1);
1630 FillRect(hdc, &rect, (HBRUSH) (COLOR_INFOBK+1));
1638 parent_class->draw_box (style, window, state_type, shadow_type, area,
1639 widget, detail, x, y, width, height);
1641 if (detail && strcmp (detail, "optionmenu") == 0)
1643 GtkRequisition indicator_size;
1644 GtkBorder indicator_spacing;
1647 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1649 sanitize_size (window, &width, &height);
1651 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1652 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
1654 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
1656 parent_class->draw_vline (style, window, state_type, area, widget,
1658 y + style->ythickness + 1,
1659 y + height - style->ythickness - 3,
1665 draw_tab (GtkStyle *style,
1668 GtkShadowType shadow,
1671 const gchar *detail,
1677 GtkRequisition indicator_size;
1678 GtkBorder indicator_spacing;
1682 g_return_if_fail (style != NULL);
1683 g_return_if_fail (window != NULL);
1685 if (detail && ! strcmp (detail, "optionmenutab"))
1687 if (xp_theme_draw(window, XP_THEME_ELEMENT_COMBOBUTTON,
1688 style, x-5, widget->allocation.y+1,
1689 width+10, widget->allocation.height-2, state, area))
1696 gtk_widget_style_get (widget, "indicator_size", &indicator_size, NULL);
1698 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
1700 x += (width - indicator_size.width) / 2;
1701 arrow_height = (indicator_size.width + 1) / 2;
1703 y += (height - arrow_height) / 2;
1705 draw_varrow (window, style->black_gc, shadow, area, GTK_ARROW_DOWN,
1706 x, y, indicator_size.width, arrow_height);
1709 /* this is an undefined magic value that, according to the mozilla folks,
1710 worked for all the various themes that they tried */
1711 #define XP_EDGE_SIZE 2
1714 draw_extension(GtkStyle *style,
1716 GtkStateType state_type,
1717 GtkShadowType shadow_type,
1720 const gchar *detail,
1725 GtkPositionType gap_side)
1727 if (GTK_IS_NOTEBOOK(widget) && detail && !strcmp(detail, "tab"))
1729 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
1730 gint x2, y2, w2, h2;
1732 x2 = x; y2 = y; w2 = width; h2 = height;
1733 if (gap_side == GTK_POS_TOP && state_type == GTK_STATE_NORMAL) {
1734 /*h2 += XP_EDGE_SIZE;*/
1736 else if (gap_side == GTK_POS_BOTTOM && state_type == GTK_STATE_NORMAL) {
1737 /*h2 += XP_EDGE_SIZE;*/
1739 else if (gap_side == GTK_POS_LEFT && state_type == GTK_STATE_NORMAL) {
1743 else if (gap_side == GTK_POS_RIGHT && state_type == GTK_STATE_NORMAL) {
1744 w2 -= (XP_EDGE_SIZE + 1);
1748 (window, gtk_notebook_get_current_page(notebook)==0
1749 ? XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE
1750 : XP_THEME_ELEMENT_TAB_ITEM,
1751 style, x2, y2, w2, h2, state_type, area))
1756 parent_class->draw_extension
1757 (style, window, state_type, shadow_type, area, widget, detail,
1758 x, y, width, height, gap_side);
1762 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1763 GtkShadowType shadow_type, GdkRectangle *area,
1764 GtkWidget *widget, const gchar *detail, gint x,
1765 gint y, gint width, gint height, GtkPositionType gap_side,
1766 gint gap_x, gint gap_width)
1768 if (GTK_IS_NOTEBOOK(widget) && detail && !strcmp(detail, "notebook"))
1770 /* FIXME: pos != TOP to be implemented */
1771 if (gap_side == GTK_POS_TOP && xp_theme_draw(window, XP_THEME_ELEMENT_TAB_PANE, style, x, y, width, height,
1777 parent_class->draw_box_gap(style, window, state_type, shadow_type,
1778 area, widget, detail, x, y, width, height,
1779 gap_side, gap_x, gap_width);
1783 draw_flat_box (GtkStyle *style, GdkWindow *window,
1784 GtkStateType state_type, GtkShadowType shadow_type,
1785 GdkRectangle *area, GtkWidget *widget,
1786 const gchar *detail, gint x, gint y,
1787 gint width, gint height)
1789 if (detail && ! strcmp (detail, "checkbutton"))
1791 if (state_type == GTK_STATE_PRELIGHT)
1797 parent_class->draw_flat_box(style, window, state_type, shadow_type,
1798 area, widget, detail, x, y, width, height);
1802 draw_shadow (GtkStyle *style,
1804 GtkStateType state_type,
1805 GtkShadowType shadow_type,
1808 const gchar *detail,
1814 if(detail && ! strcmp(detail, "entry"))
1816 if (xp_theme_draw(window, XP_THEME_ELEMENT_EDIT_TEXT, style,
1817 x, y, width, height, state_type, area))
1822 parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget,
1823 detail, x, y, width, height);
1827 draw_hline (GtkStyle *style,
1829 GtkStateType state_type,
1832 const gchar *detail,
1838 if (detail && !strcmp(detail, "menuitem")) {
1839 if (xp_theme_draw(window, XP_THEME_ELEMENT_MENU_SEPARATOR, style,
1840 x1, y, x2, style->ythickness, state_type, area)) {
1843 } else if (detail && !strcmp(detail, "toolbar")) {
1844 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_SEPARATOR_H, style,
1845 x1, y, x2, style->ythickness, state_type, area)) {
1850 if(xp_theme_draw(window, XP_THEME_ELEMENT_LINE_H, style, x1, y, x2, style->ythickness, state_type, area))
1854 parent_class->draw_hline (style, window, state_type, area, widget,
1859 draw_vline (GtkStyle *style,
1861 GtkStateType state_type,
1864 const gchar *detail,
1870 if (detail && !strcmp(detail, "toolbar")) {
1871 if (xp_theme_draw(window, XP_THEME_ELEMENT_TOOLBAR_SEPARATOR_V, style,
1872 x, y1, style->xthickness, y2, state_type, area)) {
1877 if(xp_theme_draw(window, XP_THEME_ELEMENT_LINE_V, style, x, y1, style->xthickness, y2, state_type, area))
1881 parent_class->draw_vline (style, window, state_type, area, widget,
1886 draw_slider (GtkStyle *style,
1888 GtkStateType state_type,
1889 GtkShadowType shadow_type,
1892 const gchar *detail,
1897 GtkOrientation orientation)
1899 if(GTK_IS_SCALE(widget) &&
1900 xp_theme_draw(window, ((orientation == GTK_ORIENTATION_VERTICAL) ? XP_THEME_ELEMENT_SCALE_SLIDER_V : XP_THEME_ELEMENT_SCALE_SLIDER_H), style, x, y, width, height, state_type, area)) {
1904 parent_class->draw_slider (style, window, state_type, shadow_type, area, widget,
1905 detail, x, y, width, height, orientation);
1909 draw_resize_grip (GtkStyle *style,
1911 GtkStateType state_type,
1914 const gchar *detail,
1921 if (detail && !strcmp(detail, "statusbar")) {
1922 if (xp_theme_draw(window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width, height,
1927 parent_class->draw_resize_grip (style, window, state_type, area,
1928 widget, detail, edge, x, y, width, height);
1932 draw_handle (GtkStyle *style,
1934 GtkStateType state_type,
1935 GtkShadowType shadow_type,
1938 const gchar *detail,
1943 GtkOrientation orientation)
1945 if (is_toolbar_child (widget))
1947 XpThemeElement hndl;
1949 sanitize_size (window, &width, &height);
1951 if (orientation == GTK_ORIENTATION_VERTICAL)
1952 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
1954 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
1956 if (xp_theme_draw (window, hndl, style, x, y, width, height,
1963 if (!GTK_IS_PANED(widget)) {
1964 gint xthick, ythick;
1965 GdkGC *light_gc, *dark_gc, *shadow_gc;
1968 sanitize_size (window, &width, &height);
1970 gtk_paint_box(style, window, state_type, shadow_type, area, widget,
1971 detail, x, y, width, height);
1973 light_gc = style->light_gc[state_type];
1974 dark_gc = style->dark_gc[state_type];
1975 shadow_gc = style->mid_gc[state_type];
1977 xthick = style->xthickness;
1978 ythick = style->ythickness;
1980 dest.x = x + xthick;
1981 dest.y = y + ythick;
1982 dest.width = width - (xthick * 2);
1983 dest.height = height - (ythick * 2);
1985 gdk_gc_set_clip_rectangle(light_gc, &dest);
1986 gdk_gc_set_clip_rectangle(dark_gc, &dest);
1987 gdk_gc_set_clip_rectangle(shadow_gc, &dest);
1989 if (dest.width < dest.height)
1991 gdk_draw_line(window, light_gc, dest.x, dest.y, dest.x, dest.height);
1992 gdk_draw_line(window, dark_gc, dest.x + (dest.width / 2), dest.y, dest.x + (dest.width / 2), dest.height);
1993 gdk_draw_line(window, shadow_gc, dest.x + dest.width, dest.y, dest.x + dest.width, dest.height);
1998 gdk_draw_line(window, light_gc, dest.x, dest.y, dest.x + dest.width, dest.y);
1999 gdk_draw_line(window, dark_gc, dest.x, dest.y + (dest.height / 2), dest.x + dest.width, dest.y + (dest.height / 2));
2000 gdk_draw_line(window, shadow_gc, dest.x, dest.y + dest.height, dest.x + dest.width, dest.y + dest.height);
2003 gdk_gc_set_clip_rectangle(shadow_gc, NULL);
2004 gdk_gc_set_clip_rectangle(light_gc, NULL);
2005 gdk_gc_set_clip_rectangle(dark_gc, NULL);
2010 msw_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
2012 setup_system_font (style);
2013 setup_menu_settings (gtk_settings_get_default ());
2014 setup_system_styles (style);
2015 parent_class->init_from_rc(style, rc_style);
2019 msw_style_class_init (MswStyleClass *klass)
2021 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
2023 parent_class = g_type_class_peek_parent (klass);
2025 style_class->init_from_rc = msw_style_init_from_rc;
2026 style_class->draw_arrow = draw_arrow;
2027 style_class->draw_box = draw_box;
2028 style_class->draw_check = draw_check;
2029 style_class->draw_option = draw_option;
2030 style_class->draw_tab = draw_tab;
2031 style_class->draw_flat_box = draw_flat_box;
2032 style_class->draw_expander = draw_expander;
2033 style_class->draw_extension = draw_extension;
2034 style_class->draw_box_gap = draw_box_gap;
2035 style_class->draw_shadow = draw_shadow;
2036 style_class->draw_hline = draw_hline;
2037 style_class->draw_vline = draw_vline;
2038 style_class->draw_handle = draw_handle;
2039 style_class->draw_resize_grip = draw_resize_grip;
2040 style_class->draw_slider = draw_slider;
2043 GType msw_type_style = 0;
2046 msw_style_register_type (GTypeModule *module)
2048 static const GTypeInfo object_info =
2050 sizeof (MswStyleClass),
2051 (GBaseInitFunc) NULL,
2052 (GBaseFinalizeFunc) NULL,
2053 (GClassInitFunc) msw_style_class_init,
2054 NULL, /* class_finalize */
2055 NULL, /* class_data */
2057 0, /* n_preallocs */
2058 (GInstanceInitFunc) NULL,
2061 msw_type_style = g_type_module_register_type (module,
2068 msw_style_init (void)
2071 msw_style_setup_system_settings ();
2072 setup_msw_rc_style ();