1 /* MS-Windows Engine (aka GTK-Wimp)
3 * Copyright (C) 2003, 2004 Raymond Penners <raymond@dotsphinx.com>
4 * Copyright (C) 2006 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
5 * Includes code adapted from redmond95 by Owen Taylor, and
6 * gtk-nativewin by Evan Martin
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
27 * http://lxr.mozilla.org/seamonkey/source/widget/src/windows/nsNativeThemeWin.cpp
28 * http://lxr.mozilla.org/seamonkey/source/widget/src/windows/nsLookAndFeel.cpp
29 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/functions/drawthemebackground.asp
30 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_4b3g.asp
33 /* Include first, else we get redefinition warnings about STRICT */
34 #include "pango/pangowin32.h"
36 #include "msw_style.h"
47 #ifdef BUILDING_STANDALONE
48 #include "gdk/gdkwin32.h"
50 #include "gdk/win32/gdkwin32.h"
54 /* Default values, not normally used
56 static const GtkRequisition default_option_indicator_size = { 9, 8 };
57 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
59 static GtkStyleClass *parent_class;
60 static HBRUSH g_dither_brush = NULL;
62 static HPEN g_light_pen = NULL;
63 static HPEN g_dark_pen = NULL;
85 static const gchar check_aa_bits[] = {
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
90 static const gchar check_base_bits[] = {
91 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xfc, 0x07, 0xfc, 0x07, 0xfc, 0x07,
93 0x07, 0xfc, 0x07, 0xfc, 0x07, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00
95 static const gchar check_black_bits[] = {
96 0x00, 0x00, 0xfe, 0x0f, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00,
98 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00
100 static const gchar check_dark_bits[] = {
101 0xff, 0x1f, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
103 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00
105 static const gchar check_light_bits[] = {
106 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
108 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0xfe, 0x1f
110 static const gchar check_mid_bits[] = {
111 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08,
113 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0xfc, 0x0f, 0x00, 0x00
115 static const gchar check_text_bits[] = {
116 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x88, 0x03,
118 0x00, 0x70, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
120 static const gchar check_inconsistent_bits[] = {
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
125 static const gchar radio_base_bits[] = {
126 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0xf8, 0x03, 0xfc, 0x07, 0xfc, 0x07,
128 0x07, 0xfc, 0x07, 0xf8, 0x03, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00
130 static const gchar radio_black_bits[] = {
131 0x00, 0x00, 0xf0, 0x01, 0x0c, 0x02, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00,
133 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
135 static const gchar radio_dark_bits[] = {
136 0xf0, 0x01, 0x0c, 0x06, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00,
138 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
140 static const gchar radio_light_bits[] = {
141 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x10, 0x00, 0x10,
143 0x10, 0x00, 0x10, 0x00, 0x08, 0x00, 0x08, 0x0c, 0x06, 0xf0, 0x01
145 static const gchar radio_mid_bits[] = {
146 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08,
148 0x08, 0x00, 0x08, 0x00, 0x04, 0x0c, 0x06, 0xf0, 0x01, 0x00, 0x00
150 static const gchar radio_text_bits[] = {
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0xf0, 0x01,
153 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
161 { check_aa_bits, NULL },
162 { check_base_bits, NULL },
163 { check_black_bits, NULL },
164 { check_dark_bits, NULL },
165 { check_light_bits, NULL },
166 { check_mid_bits, NULL },
167 { check_text_bits, NULL },
168 { check_inconsistent_bits, NULL },
169 { radio_base_bits, NULL },
170 { radio_black_bits, NULL },
171 { radio_dark_bits, NULL },
172 { radio_light_bits, NULL },
173 { radio_mid_bits, NULL },
174 { radio_text_bits, NULL }
178 _cairo_draw_line (cairo_t *cr,
187 gdk_cairo_set_source_color (cr, color);
188 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
189 cairo_set_line_width (cr, 1.0);
191 cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
192 cairo_line_to (cr, x2 + 0.5, y2 + 0.5);
199 _cairo_draw_rectangle (cairo_t *cr,
207 gdk_cairo_set_source_color (cr, color);
211 cairo_rectangle (cr, x, y, width, height);
216 cairo_rectangle (cr, x + 0.5, y + 0.5, width, height);
222 get_system_font (XpThemeClass klazz, XpThemeFont type, LOGFONTW *out_lf)
224 if (xp_theme_get_system_font (klazz, type, out_lf))
230 /* Use wide char versions here, as the theming functions only support
231 * wide chars versions of the structures. */
232 NONCLIENTMETRICSW ncm;
234 ncm.cbSize = sizeof (NONCLIENTMETRICSW);
236 if (SystemParametersInfoW (SPI_GETNONCLIENTMETRICS,
237 sizeof (NONCLIENTMETRICSW), &ncm, 0))
239 if (type == XP_THEME_FONT_CAPTION)
240 *out_lf = ncm.lfCaptionFont;
241 else if (type == XP_THEME_FONT_MENU)
242 *out_lf = ncm.lfMenuFont;
243 else if (type == XP_THEME_FONT_STATUS)
244 *out_lf = ncm.lfStatusFont;
246 *out_lf = ncm.lfMessageFont;
256 sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char *buf,
261 if (get_system_font (klazz, type, &lf))
263 PangoFontDescription *desc = NULL;
267 desc = pango_win32_font_description_from_logfontw (&lf);
271 font = pango_font_description_to_string (desc);
272 pt_size = pango_font_description_get_size (desc);
274 if (!(font && *font))
276 pango_font_description_free (desc);
285 hwnd = GetDesktopWindow ();
289 pt_size = -MulDiv (lf.lfHeight, 72, GetDeviceCaps (hDC, LOGPIXELSY));
294 ReleaseDC (hwnd, hDC);
296 g_snprintf (buf, bufsiz, "%s %d", font, pt_size);
300 g_snprintf (buf, bufsiz, "%s", font);
304 pango_font_description_free (desc);
312 /* missing from ms's header files */
313 #ifndef SPI_GETMENUSHOWDELAY
314 #define SPI_GETMENUSHOWDELAY 106
317 /* I don't know the proper XP theme class for things like
318 HIGHLIGHTTEXT, so we'll just define it to be "BUTTON"
320 #define XP_THEME_CLASS_TEXT XP_THEME_CLASS_BUTTON
322 #define WIN95_VERSION 0x400
323 #define WIN2K_VERSION 0x500
324 #define WINXP_VERSION 0x501
325 #define WIN2K3_VERSION 0x502
326 #define VISTA_VERSION 0x600
329 get_windows_version ()
331 static gint32 version = 0;
332 static gboolean have_version = FALSE;
336 OSVERSIONINFOEX osvi;
339 ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX));
340 osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
342 GetVersionEx((OSVERSIONINFO*) &osvi);
344 version = (osvi.dwMajorVersion & 0xff) << 8 | (osvi.dwMinorVersion & 0xff);
351 setup_menu_settings (GtkSettings *settings)
354 GObjectClass *klazz = G_OBJECT_GET_CLASS (G_OBJECT (settings));
356 if (get_windows_version () > WIN95_VERSION)
358 if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0))
362 if (g_object_class_find_property
363 (klazz, "gtk-menu-bar-popup-delay"))
365 g_object_set (settings,
366 "gtk-menu-bar-popup-delay", 0, NULL);
368 if (g_object_class_find_property
369 (klazz, "gtk-menu-popup-delay"))
371 g_object_set (settings,
372 "gtk-menu-popup-delay", menu_delay, NULL);
374 if (g_object_class_find_property
375 (klazz, "gtk-menu-popdown-delay"))
377 g_object_set (settings,
378 "gtk-menu-popdown-delay", menu_delay, NULL);
386 msw_style_setup_system_settings (void)
388 GtkSettings *settings;
389 int cursor_blink_time;
391 settings = gtk_settings_get_default ();
395 cursor_blink_time = GetCaretBlinkTime ();
396 g_object_set (settings, "gtk-cursor-blink", cursor_blink_time > 0, NULL);
398 if (cursor_blink_time > 0)
400 g_object_set (settings, "gtk-cursor-blink-time",
401 2 * cursor_blink_time, NULL);
404 g_object_set (settings, "gtk-double-click-distance",
405 GetSystemMetrics (SM_CXDOUBLECLK), NULL);
406 g_object_set (settings, "gtk-double-click-time", GetDoubleClickTime (),
408 g_object_set (settings, "gtk-dnd-drag-threshold",
409 GetSystemMetrics (SM_CXDRAG), NULL);
411 setup_menu_settings (settings);
414 http://developer.gnome.org/doc/API/2.0/gtk/GtkSettings.html
415 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
416 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemmetrics.asp */
420 setup_system_font (GtkStyle *style)
422 char buf[256], *font; /* It's okay, lfFaceName is smaller than 32
425 if ((font = sys_font_to_pango_font (XP_THEME_CLASS_TEXT,
426 XP_THEME_FONT_MESSAGE,
427 buf, sizeof (buf))) != NULL)
429 if (style->font_desc)
431 pango_font_description_free (style->font_desc);
434 style->font_desc = pango_font_description_from_string (font);
439 sys_color_to_gtk_color (XpThemeClass klazz, int id, GdkColor * pcolor)
443 if (!xp_theme_get_system_color (klazz, id, &color))
444 color = GetSysColor (id);
446 pcolor->pixel = color;
447 pcolor->red = (GetRValue (color) << 8) | GetRValue (color);
448 pcolor->green = (GetGValue (color) << 8) | GetGValue (color);
449 pcolor->blue = (GetBValue (color) << 8) | GetBValue (color);
453 get_system_metric (XpThemeClass klazz, int id)
457 if (!xp_theme_get_system_metric (klazz, id, &rval))
458 rval = GetSystemMetrics (id);
464 setup_msw_rc_style (void)
466 char buf[1024], font_buf[256], *font_ptr;
467 char menu_bar_prelight_str[128];
470 GdkColor menu_text_color;
471 GdkColor tooltip_back;
472 GdkColor tooltip_fore;
475 GdkColor progress_back;
477 GdkColor fg_prelight;
478 GdkColor bg_prelight;
479 GdkColor base_prelight;
480 GdkColor text_prelight;
483 sys_color_to_gtk_color (get_windows_version () >= VISTA_VERSION ? XP_THEME_CLASS_MENU : XP_THEME_CLASS_TEXT,
484 get_windows_version () >= VISTA_VERSION ? COLOR_MENUTEXT : COLOR_HIGHLIGHTTEXT,
486 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
487 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
489 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
492 sys_color_to_gtk_color (XP_THEME_CLASS_MENU, COLOR_MENUTEXT,
494 sys_color_to_gtk_color (XP_THEME_CLASS_MENU, COLOR_MENU, &menu_color);
497 sys_color_to_gtk_color (XP_THEME_CLASS_TOOLTIP, COLOR_INFOTEXT,
499 sys_color_to_gtk_color (XP_THEME_CLASS_TOOLTIP, COLOR_INFOBK,
502 /* text on push buttons. TODO: button shadows, backgrounds, and
504 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT, &btn_fore);
505 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE, &btn_face);
507 /* progress bar background color */
508 sys_color_to_gtk_color (XP_THEME_CLASS_PROGRESS, COLOR_HIGHLIGHT,
511 /* Enable coloring for menus. */
513 sys_font_to_pango_font (XP_THEME_CLASS_MENU, XP_THEME_FONT_MENU,
514 font_buf, sizeof (font_buf));
515 g_snprintf (buf, sizeof (buf),
516 "style \"msw-menu\" = \"msw-default\"\n" "{\n"
517 "GtkMenuItem::toggle-spacing = 8\n"
518 "fg[PRELIGHT] = { %d, %d, %d }\n"
519 "bg[PRELIGHT] = { %d, %d, %d }\n"
520 "text[PRELIGHT] = { %d, %d, %d }\n"
521 "base[PRELIGHT] = { %d, %d, %d }\n"
522 "fg[NORMAL] = { %d, %d, %d }\n"
523 "bg[NORMAL] = { %d, %d, %d }\n" "%s = \"%s\"\n"
524 "}widget_class \"*MenuItem*\" style \"msw-menu\"\n"
525 "widget_class \"*GtkMenu\" style \"msw-menu\"\n"
526 "widget_class \"*GtkMenuShell*\" style \"msw-menu\"\n",
527 fg_prelight.red, fg_prelight.green, fg_prelight.blue,
528 bg_prelight.red, bg_prelight.green, bg_prelight.blue,
529 text_prelight.red, text_prelight.green, text_prelight.blue,
530 base_prelight.red, base_prelight.green, base_prelight.blue,
531 menu_text_color.red, menu_text_color.green,
532 menu_text_color.blue, menu_color.red, menu_color.green,
533 menu_color.blue, (font_ptr ? "font_name" : "#"),
534 (font_ptr ? font_ptr : " font name should go here"));
535 gtk_rc_parse_string (buf);
537 if (xp_theme_is_active ())
539 *menu_bar_prelight_str = '\0';
543 g_snprintf (menu_bar_prelight_str, sizeof (menu_bar_prelight_str),
544 "fg[PRELIGHT] = { %d, %d, %d }\n",
545 menu_text_color.red, menu_text_color.green,
546 menu_text_color.blue);
549 /* Enable coloring for menu bars. */
550 g_snprintf (buf, sizeof (buf),
551 "style \"msw-menu-bar\" = \"msw-menu\"\n"
553 "bg[NORMAL] = { %d, %d, %d }\n"
554 "%s" "GtkMenuBar::shadow-type = %d\n"
556 FIXME: This should be enabled once gtk+ support
557 GtkMenuBar::prelight-item style property.
559 /* "GtkMenuBar::prelight-item = 1\n" */
560 "}widget_class \"*MenuBar*\" style \"msw-menu-bar\"\n",
561 btn_face.red, btn_face.green, btn_face.blue,
562 menu_bar_prelight_str, xp_theme_is_active ()? 0 : 2);
563 gtk_rc_parse_string (buf);
565 g_snprintf (buf, sizeof (buf),
566 "style \"msw-toolbar\" = \"msw-default\"\n"
568 "GtkHandleBox::shadow-type = %s\n"
569 "GtkToolbar::shadow-type = %s\n"
570 "}widget_class \"*HandleBox*\" style \"msw-toolbar\"\n",
571 "etched-in", "etched-in");
572 gtk_rc_parse_string (buf);
574 /* enable tooltip fonts */
575 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,
576 font_buf, sizeof (font_buf));
577 g_snprintf (buf, sizeof (buf),
578 "style \"msw-tooltips-caption\" = \"msw-default\"\n"
579 "{fg[NORMAL] = { %d, %d, %d }\n" "%s = \"%s\"\n"
580 "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n"
581 "widget \"gtk-tooltip.GtkLabel\" style \"msw-tooltips-caption\"\n",
582 tooltip_fore.red, tooltip_fore.green, tooltip_fore.blue,
583 (font_ptr ? "font_name" : "#"),
584 (font_ptr ? font_ptr : " font name should go here"));
585 gtk_rc_parse_string (buf);
587 g_snprintf (buf, sizeof (buf),
588 "style \"msw-tooltips\" = \"msw-default\"\n"
589 "{bg[NORMAL] = { %d, %d, %d }\n"
590 "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n"
591 "widget \"gtk-tooltip*\" style \"msw-tooltips\"\n",
592 tooltip_back.red, tooltip_back.green, tooltip_back.blue);
593 gtk_rc_parse_string (buf);
595 /* enable font theming for status bars */
596 font_ptr = sys_font_to_pango_font (XP_THEME_CLASS_STATUS, XP_THEME_FONT_STATUS,
597 font_buf, sizeof (font_buf));
598 g_snprintf (buf, sizeof (buf),
599 "style \"msw-status\" = \"msw-default\"\n" "{%s = \"%s\"\n"
600 "bg[NORMAL] = { %d, %d, %d }\n"
601 "}widget_class \"*Status*\" style \"msw-status\"\n",
602 (font_ptr ? "font_name" : "#"),
603 (font_ptr ? font_ptr : " font name should go here"),
604 btn_face.red, btn_face.green, btn_face.blue);
605 gtk_rc_parse_string (buf);
607 /* enable coloring for text on buttons TODO: use GetThemeMetric for the
608 border and outside border */
609 g_snprintf (buf, sizeof (buf),
610 "style \"msw-button\" = \"msw-default\"\n"
612 "bg[NORMAL] = { %d, %d, %d }\n"
613 "bg[PRELIGHT] = { %d, %d, %d }\n"
614 "bg[INSENSITIVE] = { %d, %d, %d }\n"
615 "fg[PRELIGHT] = { %d, %d, %d }\n"
616 "GtkButton::default-border = { 0, 0, 0, 0 }\n"
617 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
618 "GtkButton::child-displacement-x = 1\n"
619 "GtkButton::child-displacement-y = 1\n"
620 "GtkButton::focus-padding = %d\n"
621 "}widget_class \"*Button*\" style \"msw-button\"\n",
622 btn_face.red, btn_face.green, btn_face.blue,
623 btn_face.red, btn_face.green, btn_face.blue,
624 btn_face.red, btn_face.green, btn_face.blue,
625 btn_fore.red, btn_fore.green, btn_fore.blue,
626 xp_theme_is_active ()? 1 : 2);
627 gtk_rc_parse_string (buf);
629 /* enable coloring for progress bars */
630 g_snprintf (buf, sizeof (buf),
631 "style \"msw-progress\" = \"msw-default\"\n"
632 "{bg[PRELIGHT] = { %d, %d, %d }\n"
633 "bg[NORMAL] = { %d, %d, %d }\n"
634 "}widget_class \"*Progress*\" style \"msw-progress\"\n",
638 btn_face.red, btn_face.green, btn_face.blue);
639 gtk_rc_parse_string (buf);
641 /* scrollbar thumb width and height */
642 g_snprintf (buf, sizeof (buf),
643 "style \"msw-vscrollbar\" = \"msw-default\"\n"
644 "{GtkRange::slider-width = %d\n"
645 "GtkRange::stepper-size = %d\n"
646 "GtkRange::stepper-spacing = 0\n"
647 "GtkRange::trough_border = 0\n"
648 "GtkScale::slider-length = %d\n"
649 "GtkScrollbar::min-slider-length = 8\n"
650 "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n"
651 "widget_class \"*VScale*\" style \"msw-vscrollbar\"\n",
652 GetSystemMetrics (SM_CYVTHUMB),
653 get_system_metric (XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL), 11);
654 gtk_rc_parse_string (buf);
656 g_snprintf (buf, sizeof (buf),
657 "style \"msw-hscrollbar\" = \"msw-default\"\n"
658 "{GtkRange::slider-width = %d\n"
659 "GtkRange::stepper-size = %d\n"
660 "GtkRange::stepper-spacing = 0\n"
661 "GtkRange::trough_border = 0\n"
662 "GtkScale::slider-length = %d\n"
663 "GtkScrollbar::min-slider-length = 8\n"
664 "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n"
665 "widget_class \"*HScale*\" style \"msw-hscrollbar\"\n",
666 GetSystemMetrics (SM_CXHTHUMB),
667 get_system_metric (XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL), 11);
668 gtk_rc_parse_string (buf);
670 gtk_rc_parse_string ("style \"msw-scrolled-window\" = \"msw-default\"\n"
671 "{GtkScrolledWindow::scrollbars-within-bevel = 1}\n"
672 "class \"GtkScrolledWindow\" style \"msw-scrolled-window\"\n");
674 /* radio/check button sizes */
675 g_snprintf (buf, sizeof (buf),
676 "style \"msw-checkbutton\" = \"msw-button\"\n"
677 "{GtkCheckButton::indicator-size = 13\n"
678 "}widget_class \"*CheckButton*\" style \"msw-checkbutton\"\n"
679 "widget_class \"*RadioButton*\" style \"msw-checkbutton\"\n");
680 gtk_rc_parse_string (buf);
682 /* size of combo box toggle button */
683 g_snprintf (buf, sizeof (buf),
684 "style \"msw-combobox-button\" = \"msw-default\"\n"
688 "GtkButton::default-border = { 0, 0, 0, 0 }\n"
689 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
690 "GtkButton::child-displacement-x = 0\n"
691 "GtkButton::child-displacement-y = 0\n"
692 "GtkWidget::focus-padding = 0\n"
693 "GtkWidget::focus-line-width = 0\n"
695 "widget_class \"*ComboBox*ToggleButton*\" style \"msw-combobox-button\"\n");
696 gtk_rc_parse_string (buf);
698 g_snprintf (buf, sizeof (buf),
699 "style \"msw-combobox\" = \"msw-default\"\n"
701 "GtkComboBox::shadow-type = in\n"
705 "class \"GtkComboBox\" style \"msw-combobox\"\n",
706 xp_theme_is_active()? 1 : GetSystemMetrics (SM_CXEDGE),
707 xp_theme_is_active()? 1 : GetSystemMetrics (SM_CYEDGE));
708 gtk_rc_parse_string (buf);
710 /* size of tree view header */
711 g_snprintf (buf, sizeof (buf),
712 "style \"msw-header-button\" = \"msw-default\"\n"
716 "GtkWidget::draw-border = {0, 0, 0, 0}\n"
717 "GtkButton::default-border = { 0, 0, 0, 0 }\n"
718 "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
719 "GtkButton::child-displacement-x = 0\n"
720 "GtkButton::child-displacement-y = 0\n"
721 "GtkWidget::focus-padding = 0\n"
722 "GtkWidget::focus-line-width = 0\n"
724 "widget_class \"*TreeView*Button*\" style \"msw-header-button\"\n");
725 gtk_rc_parse_string (buf);
727 /* FIXME: This should be enabled once gtk+ support GtkNotebok::prelight-tab */
728 /* enable prelight tab of GtkNotebook */
730 g_snprintf (buf, sizeof (buf),
731 "style \"msw-notebook\" = \"msw-default\"\n"
732 "{GtkNotebook::prelight-tab=1\n"
733 "}widget_class \"*Notebook*\" style \"msw-notebook\"\n");
734 gtk_rc_parse_string (buf);
737 /* FIXME: This should be enabled once gtk+ support GtkTreeView::full-row-focus */
739 g_snprintf (buf, sizeof (buf),
740 "style \"msw-treeview\" = \"msw-default\"\n"
741 "{GtkTreeView::full-row-focus=0\n"
742 "}widget_class \"*TreeView*\" style \"msw-treeview\"\n");
743 gtk_rc_parse_string (buf);
748 setup_system_styles (GtkStyle *style)
752 /* Default background */
753 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
754 &style->bg[GTK_STATE_NORMAL]);
755 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
756 &style->bg[GTK_STATE_SELECTED]);
757 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
758 &style->bg[GTK_STATE_INSENSITIVE]);
759 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
760 &style->bg[GTK_STATE_ACTIVE]);
761 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
762 &style->bg[GTK_STATE_PRELIGHT]);
765 sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOW,
766 &style->base[GTK_STATE_NORMAL]);
767 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
768 &style->base[GTK_STATE_SELECTED]);
769 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
770 &style->base[GTK_STATE_INSENSITIVE]);
771 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNFACE,
772 &style->base[GTK_STATE_ACTIVE]);
773 sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOW,
774 &style->base[GTK_STATE_PRELIGHT]);
777 sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT,
778 &style->text[GTK_STATE_NORMAL]);
779 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
780 &style->text[GTK_STATE_SELECTED]);
781 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_GRAYTEXT,
782 &style->text[GTK_STATE_INSENSITIVE]);
783 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT,
784 &style->text[GTK_STATE_ACTIVE]);
785 sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT,
786 &style->text[GTK_STATE_PRELIGHT]);
788 /* Default foreground */
789 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT,
790 &style->fg[GTK_STATE_NORMAL]);
791 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
792 &style->fg[GTK_STATE_SELECTED]);
793 sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_GRAYTEXT,
794 &style->fg[GTK_STATE_INSENSITIVE]);
795 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_BTNTEXT,
796 &style->bg[GTK_STATE_ACTIVE]);
797 sys_color_to_gtk_color (XP_THEME_CLASS_WINDOW, COLOR_WINDOWTEXT,
798 &style->fg[GTK_STATE_PRELIGHT]);
800 for (i = 0; i < 5; i++)
802 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_3DSHADOW,
804 sys_color_to_gtk_color (XP_THEME_CLASS_BUTTON, COLOR_3DHILIGHT,
807 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
808 style->mid[i].green =
809 (style->light[i].green + style->dark[i].green) / 2;
810 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
812 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
813 style->text_aa[i].green =
814 (style->text[i].green + style->base[i].green) / 2;
815 style->text_aa[i].blue =
816 (style->text[i].blue + style->base[i].blue) / 2;
821 sanitize_size (GdkWindow *window, gint *width, gint *height)
823 gboolean set_bg = FALSE;
825 if ((*width == -1) && (*height == -1))
827 set_bg = GDK_IS_WINDOW (window);
828 gdk_drawable_get_size (window, width, height);
830 else if (*width == -1)
832 gdk_drawable_get_size (window, width, NULL);
834 else if (*height == -1)
836 gdk_drawable_get_size (window, NULL, height);
842 static XpThemeElement
843 map_gtk_progress_bar_to_xp (GtkProgressBar *progress_bar, gboolean trough)
847 switch (gtk_progress_bar_get_orientation (progress_bar))
849 case GTK_PROGRESS_LEFT_TO_RIGHT:
850 case GTK_PROGRESS_RIGHT_TO_LEFT:
852 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_H
853 : XP_THEME_ELEMENT_PROGRESS_BAR_H;
858 ? XP_THEME_ELEMENT_PROGRESS_TROUGH_V
859 : XP_THEME_ELEMENT_PROGRESS_BAR_V;
867 is_combo_box_child (GtkWidget *w)
874 for (tmp = w->parent; tmp; tmp = tmp->parent)
876 if (GTK_IS_COMBO_BOX (tmp))
883 /* This function is not needed anymore */
885 combo_box_draw_arrow (GtkStyle *style,
888 GdkRectangle *area, GtkWidget *widget)
890 if (xp_theme_is_active ())
893 if (widget && GTK_IS_TOGGLE_BUTTON (widget->parent))
900 dc = get_window_dc (style, window, state, &dc_info, area->x, area->y, area->width,
901 area->height, &rect);
902 border = (GTK_TOGGLE_BUTTON (widget->parent)->
903 active ? DFCS_PUSHED | DFCS_FLAT : 0);
905 InflateRect (&rect, 1, 1);
906 DrawFrameControl (dc, &rect, DFC_SCROLL, DFCS_SCROLLDOWN | border);
908 release_window_dc (&dc_info);
917 draw_part (GdkDrawable *drawable,
918 GdkGC *gc, GdkRectangle *area, gint x, gint y, Part part)
921 gdk_gc_set_clip_rectangle (gc, area);
923 if (!parts[part].bmap)
925 parts[part].bmap = gdk_bitmap_create_from_data (drawable,
927 PART_SIZE, PART_SIZE);
930 gdk_gc_set_ts_origin (gc, x, y);
931 gdk_gc_set_stipple (gc, parts[part].bmap);
932 gdk_gc_set_fill (gc, GDK_STIPPLED);
934 gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
936 gdk_gc_set_fill (gc, GDK_SOLID);
939 gdk_gc_set_clip_rectangle (gc, NULL);
943 draw_check (GtkStyle *style,
946 GtkShadowType shadow,
949 const gchar *detail, gint x, gint y, gint width, gint height)
951 x -= (1 + PART_SIZE - width) / 2;
952 y -= (1 + PART_SIZE - height) / 2;
954 if (detail && strcmp (detail, "check") == 0) /* Menu item */
956 if (shadow == GTK_SHADOW_IN)
958 draw_part (window, &style->black, area, x, y, CHECK_TEXT);
959 draw_part (window, &style->dark[state], area, x, y, CHECK_AA);
964 XpThemeElement theme_elt = XP_THEME_ELEMENT_CHECKBOX;
967 case GTK_SHADOW_ETCHED_IN:
968 theme_elt = XP_THEME_ELEMENT_INCONSISTENT_CHECKBOX;
972 theme_elt = XP_THEME_ELEMENT_PRESSED_CHECKBOX;
979 if (!xp_theme_draw (window, theme_elt,
980 style, x, y, width, height, state, area))
982 if (detail && !strcmp (detail, "cellcheck"))
983 state = GTK_STATE_NORMAL;
985 draw_part (window, &style->black, area, x, y, CHECK_BLACK);
986 draw_part (window, &style->dark[state], area, x, y, CHECK_DARK);
987 draw_part (window, &style->mid[state], area, x, y, CHECK_MID);
988 draw_part (window, &style->light[state], area, x, y, CHECK_LIGHT);
989 draw_part (window, &style->base[state], area, x, y, CHECK_BASE);
991 if (shadow == GTK_SHADOW_IN)
993 draw_part (window, &style->text[state], area, x,
995 draw_part (window, &style->text_aa[state], area,
998 else if (shadow == GTK_SHADOW_ETCHED_IN)
1000 draw_part (window, &style->text[state], area, x, y,
1001 CHECK_INCONSISTENT);
1002 draw_part (window, &style->text_aa[state], area, x, y,
1010 draw_expander (GtkStyle *style,
1015 const gchar *detail,
1016 gint x, gint y, GtkExpanderStyle expander_style)
1018 cairo_t *cr = gdk_cairo_create (window);
1021 gint expander_semi_size;
1022 XpThemeElement xp_expander;
1024 gtk_widget_style_get (widget, "expander_size", &expander_size, NULL);
1026 switch (expander_style)
1028 case GTK_EXPANDER_COLLAPSED:
1029 case GTK_EXPANDER_SEMI_COLLAPSED:
1030 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED;
1034 xp_expander = XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED;
1038 if ((expander_size % 2) == 0)
1041 if (expander_size > 2)
1046 gdk_cairo_rectangle (cr, area);
1048 gdk_cairo_set_source_color (cr, &style->fg[state]);
1051 expander_semi_size = expander_size / 2;
1052 x -= expander_semi_size;
1053 y -= expander_semi_size;
1055 if (!xp_theme_draw (window, xp_expander, style,
1056 x, y, expander_size, expander_size, state, area))
1064 dc = get_window_dc (style, window, state, &dc_info, x, y, expander_size,
1065 expander_size, &rect);
1066 FrameRect (dc, &rect, GetSysColorBrush (COLOR_GRAYTEXT));
1067 InflateRect (&rect, -1, -1);
1068 FillRect (dc, &rect,
1069 GetSysColorBrush (state ==
1070 GTK_STATE_INSENSITIVE ? COLOR_BTNFACE :
1073 InflateRect (&rect, -1, -1);
1075 pen = CreatePen (PS_SOLID, 1, GetSysColor (COLOR_WINDOWTEXT));
1076 old_pen = SelectObject (dc, pen);
1078 MoveToEx (dc, rect.left, rect.top - 2 + expander_semi_size, NULL);
1079 LineTo (dc, rect.right, rect.top - 2 + expander_semi_size);
1081 if (expander_style == GTK_EXPANDER_COLLAPSED ||
1082 expander_style == GTK_EXPANDER_SEMI_COLLAPSED)
1084 MoveToEx (dc, rect.left - 2 + expander_semi_size, rect.top, NULL);
1085 LineTo (dc, rect.left - 2 + expander_semi_size, rect.bottom);
1088 SelectObject (dc, old_pen);
1090 release_window_dc (&dc_info);
1097 draw_option (GtkStyle *style,
1100 GtkShadowType shadow,
1103 const gchar *detail, gint x, gint y, gint width, gint height)
1105 x -= (1 + PART_SIZE - width) / 2;
1106 y -= (1 + PART_SIZE - height) / 2;
1108 if (detail && strcmp (detail, "option") == 0) /* Menu item */
1110 if (shadow == GTK_SHADOW_IN)
1112 draw_part (window, &style->fg[state], area, x, y, RADIO_TEXT);
1117 if (xp_theme_draw (window, shadow == GTK_SHADOW_IN
1118 ? XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON
1119 : XP_THEME_ELEMENT_RADIO_BUTTON,
1120 style, x, y, width, height, state, area))
1125 if (detail && !strcmp (detail, "cellradio"))
1126 state = GTK_STATE_NORMAL;
1128 draw_part (window, &style->black, area, x, y, RADIO_BLACK);
1129 draw_part (window, &style->dark[state], area, x, y, RADIO_DARK);
1130 draw_part (window, &style->mid[state], area, x, y, RADIO_MID);
1131 draw_part (window, &style->light[state], area, x, y, RADIO_LIGHT);
1132 draw_part (window, &style->base[state], area, x, y, RADIO_BASE);
1134 if (shadow == GTK_SHADOW_IN)
1135 draw_part (window, &style->text[state], area, x, y, RADIO_TEXT);
1141 draw_varrow (GdkWindow *window,
1143 GtkShadowType shadow_type,
1145 GtkArrowType arrow_type, gint x, gint y, gint width, gint height)
1148 gint y_start, y_increment;
1152 cr = gdk_cairo_create (window);
1156 gdk_cairo_rectangle (cr, area);
1160 width = width + width % 2 - 1; /* Force odd */
1161 steps = 1 + width / 2;
1162 extra = height - steps;
1164 if (arrow_type == GTK_ARROW_DOWN)
1171 y_start = y + height - 1;
1175 for (i = extra; i < height; i++)
1177 _cairo_draw_line (cr, gc,
1178 x + (i - extra), y_start + i * y_increment,
1179 x + width - (i - extra) - 1, y_start + i * y_increment);
1186 draw_harrow (GdkWindow *window,
1188 GtkShadowType shadow_type,
1190 GtkArrowType arrow_type, gint x, gint y, gint width, gint height)
1193 gint x_start, x_increment;
1197 cr = gdk_cairo_create (window);
1201 gdk_cairo_rectangle (cr, area);
1205 height = height + height % 2 - 1; /* Force odd */
1206 steps = 1 + height / 2;
1207 extra = width - steps;
1209 if (arrow_type == GTK_ARROW_RIGHT)
1216 x_start = x + width - 1;
1220 for (i = extra; i < width; i++)
1222 _cairo_draw_line (cr, gc,
1223 x_start + i * x_increment, y + (i - extra),
1224 x_start + i * x_increment, y + height - (i - extra) - 1);
1230 /* This function makes up for some brokeness in gtkrange.c
1231 * where we never get the full arrow of the stepper button
1232 * and the type of button in a single drawing function.
1234 * It doesn't work correctly when the scrollbar is squished
1235 * to the point we don't have room for full-sized steppers.
1238 reverse_engineer_stepper_box (GtkWidget *range,
1239 GtkArrowType arrow_type,
1240 gint *x, gint *y, gint *width, gint *height)
1242 gint slider_width = 14, stepper_size = 14;
1248 gtk_widget_style_get (range,
1249 "slider_width", &slider_width,
1250 "stepper_size", &stepper_size, NULL);
1253 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1255 box_width = slider_width;
1256 box_height = stepper_size;
1260 box_width = stepper_size;
1261 box_height = slider_width;
1264 *x = *x - (box_width - *width) / 2;
1265 *y = *y - (box_height - *height) / 2;
1267 *height = box_height;
1270 static XpThemeElement
1271 to_xp_arrow (GtkArrowType arrow_type)
1273 XpThemeElement xp_arrow;
1278 xp_arrow = XP_THEME_ELEMENT_ARROW_UP;
1281 case GTK_ARROW_DOWN:
1282 xp_arrow = XP_THEME_ELEMENT_ARROW_DOWN;
1285 case GTK_ARROW_LEFT:
1286 xp_arrow = XP_THEME_ELEMENT_ARROW_LEFT;
1290 xp_arrow = XP_THEME_ELEMENT_ARROW_RIGHT;
1298 draw_arrow (GtkStyle *style,
1301 GtkShadowType shadow,
1304 const gchar *detail,
1305 GtkArrowType arrow_type,
1306 gboolean fill, gint x, gint y, gint width, gint height)
1313 name = gtk_widget_get_name (widget);
1315 sanitize_size (window, &width, &height);
1317 if (GTK_IS_ARROW (widget) && is_combo_box_child (widget) && xp_theme_is_active ())
1320 if (detail && strcmp (detail, "spinbutton") == 0)
1322 if (xp_theme_is_drawable (XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1329 if (arrow_type == GTK_ARROW_DOWN)
1333 if (state == GTK_STATE_ACTIVE)
1339 draw_varrow (window, &style->fg[state], shadow, area,
1340 arrow_type, x, y, width, height);
1344 else if (detail && (!strcmp (detail, "vscrollbar")
1345 || !strcmp (detail, "hscrollbar")))
1347 gboolean is_disabled = FALSE;
1349 GtkScrollbar *scrollbar = GTK_SCROLLBAR (widget);
1353 gint box_width = width;
1354 gint box_height = height;
1356 reverse_engineer_stepper_box (widget, arrow_type,
1357 &box_x, &box_y, &box_width, &box_height);
1359 if (gtk_range_get_adjustment(&scrollbar->range)->page_size >=
1360 (gtk_range_get_adjustment(&scrollbar->range)->upper -
1361 gtk_range_get_adjustment(&scrollbar->range)->lower))
1366 if (xp_theme_draw (window, to_xp_arrow (arrow_type), style, box_x, box_y,
1367 box_width, box_height, state, area))
1375 btn_type = DFCS_SCROLLUP;
1378 case GTK_ARROW_DOWN:
1379 btn_type = DFCS_SCROLLDOWN;
1382 case GTK_ARROW_LEFT:
1383 btn_type = DFCS_SCROLLLEFT;
1386 case GTK_ARROW_RIGHT:
1387 btn_type = DFCS_SCROLLRIGHT;
1390 case GTK_ARROW_NONE:
1394 if (state == GTK_STATE_INSENSITIVE)
1396 btn_type |= DFCS_INACTIVE;
1401 sanitize_size (window, &width, &height);
1403 dc = get_window_dc (style, window, state, &dc_info,
1404 box_x, box_y, box_width, box_height, &rect);
1405 DrawFrameControl (dc, &rect, DFC_SCROLL,
1406 btn_type | (shadow ==
1407 GTK_SHADOW_IN ? (DFCS_PUSHED |
1409 release_window_dc (&dc_info);
1415 /* draw the toolbar chevrons - waiting for GTK 2.4 */
1416 if (name && !strcmp (name, "gtk-toolbar-arrow"))
1419 (window, XP_THEME_ELEMENT_REBAR_CHEVRON, style, x, y,
1420 width, height, state, area))
1425 /* probably a gtk combo box on a toolbar */
1426 else if (0 /* widget->parent && GTK_IS_BUTTON
1427 (widget->parent) */ )
1430 (window, XP_THEME_ELEMENT_COMBOBUTTON, style, x - 3,
1431 widget->allocation.y + 1, width + 5,
1432 widget->allocation.height - 4, state, area))
1438 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
1440 x += (width - 7) / 2;
1441 y += (height - 5) / 2;
1443 draw_varrow (window, &style->fg[state], shadow, area,
1444 arrow_type, x, y, 7, 5);
1448 x += (width - 5) / 2;
1449 y += (height - 7) / 2;
1451 draw_harrow (window, &style->fg[state], shadow, area,
1452 arrow_type, x, y, 5, 7);
1458 option_menu_get_props (GtkWidget *widget,
1459 GtkRequisition *indicator_size,
1460 GtkBorder *indicator_spacing)
1462 GtkRequisition *tmp_size = NULL;
1463 GtkBorder *tmp_spacing = NULL;
1466 gtk_widget_style_get (widget,
1467 "indicator_size", &tmp_size,
1468 "indicator_spacing", &tmp_spacing, NULL);
1472 *indicator_size = *tmp_size;
1473 gtk_requisition_free (tmp_size);
1477 *indicator_size = default_option_indicator_size;
1482 *indicator_spacing = *tmp_spacing;
1483 gtk_border_free (tmp_spacing);
1487 *indicator_spacing = default_option_indicator_spacing;
1492 is_toolbar_child (GtkWidget *wid)
1496 if (GTK_IS_TOOLBAR (wid) || GTK_IS_HANDLE_BOX (wid))
1506 is_menu_tool_button_child (GtkWidget *wid)
1510 if (GTK_IS_MENU_TOOL_BUTTON (wid))
1523 g_light_pen = CreatePen (PS_SOLID | PS_INSIDEFRAME, 1,
1524 GetSysColor (COLOR_BTNHIGHLIGHT));
1535 g_dark_pen = CreatePen (PS_SOLID | PS_INSIDEFRAME, 1,
1536 GetSysColor (COLOR_BTNSHADOW));
1543 draw_3d_border (HDC hdc, RECT *rc, gboolean sunken)
1550 pen1 = get_dark_pen ();
1551 pen2 = get_light_pen ();
1555 pen1 = get_light_pen ();
1556 pen2 = get_dark_pen ();
1559 MoveToEx (hdc, rc->left, rc->bottom - 1, NULL);
1561 old_pen = SelectObject (hdc, pen1);
1562 LineTo (hdc, rc->left, rc->top);
1563 LineTo (hdc, rc->right - 1, rc->top);
1564 SelectObject (hdc, old_pen);
1566 old_pen = SelectObject (hdc, pen2);
1567 LineTo (hdc, rc->right - 1, rc->bottom - 1);
1568 LineTo (hdc, rc->left, rc->bottom - 1);
1569 SelectObject (hdc, old_pen);
1573 draw_menu_item (GdkWindow *window, GtkWidget *widget, GtkStyle *style,
1574 gint x, gint y, gint width, gint height,
1575 GtkStateType state_type, GdkRectangle *area)
1583 if (xp_theme_is_active ())
1585 return (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style,
1586 x, y, width, height, state_type, area));
1589 if ((parent = gtk_widget_get_parent (widget))
1590 && GTK_IS_MENU_BAR (parent) && !xp_theme_is_active ())
1592 bar = GTK_MENU_SHELL (parent);
1594 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
1596 if (state_type == GTK_STATE_PRELIGHT)
1598 draw_3d_border (dc, &rect, bar->active);
1601 release_window_dc (&dc_info);
1610 get_dither_brush (void)
1613 HBITMAP pattern_bmp;
1617 return g_dither_brush;
1619 for (i = 0; i < 8; i++)
1621 pattern[i] = (WORD) (0x5555 << (i & 1));
1624 pattern_bmp = CreateBitmap (8, 8, 1, 1, &pattern);
1628 g_dither_brush = CreatePatternBrush (pattern_bmp);
1629 DeleteObject (pattern_bmp);
1632 return g_dither_brush;
1636 draw_tool_button (GdkWindow *window, GtkWidget *widget, GtkStyle *style,
1637 gint x, gint y, gint width, gint height,
1638 GtkStateType state_type, GdkRectangle *area)
1643 gboolean is_toggled = FALSE;
1645 if (xp_theme_is_active ())
1647 return (xp_theme_draw (window, XP_THEME_ELEMENT_TOOLBAR_BUTTON, style,
1648 x, y, width, height, state_type, area));
1651 if (GTK_IS_TOGGLE_BUTTON (widget))
1653 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
1659 if (state_type != GTK_STATE_PRELIGHT
1660 && state_type != GTK_STATE_ACTIVE && !is_toggled)
1665 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
1666 if (state_type == GTK_STATE_PRELIGHT)
1670 FillRect (dc, &rect, GetSysColorBrush (COLOR_BTNFACE));
1673 draw_3d_border (dc, &rect, is_toggled);
1675 else if (state_type == GTK_STATE_ACTIVE)
1677 if (is_toggled && !is_menu_tool_button_child (widget->parent))
1679 SetTextColor (dc, GetSysColor (COLOR_3DHILIGHT));
1680 SetBkColor (dc, GetSysColor (COLOR_BTNFACE));
1681 FillRect (dc, &rect, get_dither_brush ());
1684 draw_3d_border (dc, &rect, TRUE);
1687 release_window_dc (&dc_info);
1693 draw_push_button (GdkWindow *window, GtkWidget *widget, GtkStyle *style,
1694 gint x, gint y, gint width, gint height,
1695 GtkStateType state_type, gboolean is_default)
1701 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
1703 if (GTK_IS_TOGGLE_BUTTON (widget))
1705 if (state_type == GTK_STATE_PRELIGHT &&
1706 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
1708 state_type = GTK_STATE_ACTIVE;
1712 if (state_type == GTK_STATE_ACTIVE)
1714 if (GTK_IS_TOGGLE_BUTTON (widget))
1716 DrawEdge (dc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1717 SetTextColor (dc, GetSysColor (COLOR_3DHILIGHT));
1718 SetBkColor (dc, GetSysColor (COLOR_BTNFACE));
1719 FillRect (dc, &rect, get_dither_brush ());
1723 FrameRect (dc, &rect, GetSysColorBrush (COLOR_WINDOWFRAME));
1724 InflateRect (&rect, -1, -1);
1725 FrameRect (dc, &rect, GetSysColorBrush (COLOR_BTNSHADOW));
1726 InflateRect (&rect, -1, -1);
1727 FillRect (dc, &rect, GetSysColorBrush (COLOR_BTNFACE));
1732 if (is_default || gtk_widget_has_focus (widget))
1734 FrameRect (dc, &rect, GetSysColorBrush (COLOR_WINDOWFRAME));
1735 InflateRect (&rect, -1, -1);
1738 DrawFrameControl (dc, &rect, DFC_BUTTON, DFCS_BUTTONPUSH);
1741 release_window_dc (&dc_info);
1745 draw_box (GtkStyle *style,
1747 GtkStateType state_type,
1748 GtkShadowType shadow_type,
1751 const gchar *detail, gint x, gint y, gint width, gint height)
1753 if (is_combo_box_child (widget) && detail && !strcmp (detail, "button"))
1761 border = (GTK_TOGGLE_BUTTON (widget)->active ? DFCS_PUSHED | DFCS_FLAT : 0);
1763 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
1764 DrawFrameControl (dc, &rect, DFC_SCROLL, DFCS_SCROLLDOWN | border);
1765 release_window_dc (&dc_info);
1767 if (xp_theme_is_active ()
1768 && xp_theme_draw (window, XP_THEME_ELEMENT_COMBOBUTTON, style, x, y,
1769 width, height, state_type, area))
1771 cx = GetSystemMetrics(SM_CXVSCROLL);
1776 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width - cx, height, &rect);
1777 FillRect (dc, &rect, GetSysColorBrush (COLOR_WINDOW));
1778 release_window_dc (&dc_info);
1784 (!strcmp (detail, "button") || !strcmp (detail, "buttondefault")))
1786 if (GTK_IS_TREE_VIEW (widget->parent))
1789 (window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
1790 width, height, state_type, area))
1799 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
1801 DrawFrameControl (dc, &rect, DFC_BUTTON, DFCS_BUTTONPUSH |
1803 GTK_STATE_ACTIVE ? (DFCS_PUSHED | DFCS_FLAT)
1805 release_window_dc (&dc_info);
1808 else if (is_toolbar_child (widget->parent)
1809 || (!GTK_IS_BUTTON (widget) ||
1810 (GTK_RELIEF_NONE == gtk_button_get_relief (GTK_BUTTON (widget)))))
1812 if (draw_tool_button (window, widget, style, x, y,
1813 width, height, state_type, area))
1820 gboolean is_default = gtk_widget_has_default (widget);
1823 is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON :
1824 XP_THEME_ELEMENT_BUTTON, style, x, y, width, height,
1830 draw_push_button (window, widget, style,
1831 x, y, width, height, state_type, is_default);
1838 else if (detail && !strcmp (detail, "spinbutton"))
1840 if (xp_theme_is_drawable (XP_THEME_ELEMENT_SPIN_BUTTON_UP))
1845 else if (detail && (!strcmp (detail, "spinbutton_up")
1846 || !strcmp (detail, "spinbutton_down")))
1848 if (!xp_theme_draw (window,
1849 (!strcmp (detail, "spinbutton_up"))
1850 ? XP_THEME_ELEMENT_SPIN_BUTTON_UP
1851 : XP_THEME_ELEMENT_SPIN_BUTTON_DOWN,
1852 style, x, y, width, height, state_type, area))
1858 dc = get_window_dc (style, window, state_type, &dc_info,
1859 x, y, width, height, &rect);
1860 DrawEdge (dc, &rect,
1862 GTK_STATE_ACTIVE ? EDGE_SUNKEN : EDGE_RAISED, BF_RECT);
1863 release_window_dc (&dc_info);
1867 else if (detail && !strcmp (detail, "slider"))
1869 if (GTK_IS_SCROLLBAR (widget))
1871 GtkScrollbar *scrollbar = GTK_SCROLLBAR (widget);
1872 gboolean is_v = GTK_IS_VSCROLLBAR (widget);
1874 if (xp_theme_draw (window,
1876 ? XP_THEME_ELEMENT_SCROLLBAR_V
1877 : XP_THEME_ELEMENT_SCROLLBAR_H,
1878 style, x, y, width, height, state_type, area))
1880 XpThemeElement gripper =
1881 (is_v ? XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V :
1882 XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H);
1884 /* Do not display grippers on tiny scroll bars,
1885 the limit imposed is rather arbitrary, perhaps
1886 we can fetch the gripper geometry from
1887 somewhere and use that... */
1889 XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H
1892 XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V && height < 16))
1897 xp_theme_draw (window, gripper, style, x, y,
1898 width, height, state_type, area);
1903 if (gtk_range_get_adjustment(&scrollbar->range)->page_size >=
1904 (gtk_range_get_adjustment(&scrollbar->range)->upper -
1905 gtk_range_get_adjustment(&scrollbar->range)->lower))
1912 else if (detail && !strcmp (detail, "bar"))
1914 if (widget && GTK_IS_PROGRESS_BAR (widget))
1916 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR (widget);
1917 XpThemeElement xp_progress_bar =
1918 map_gtk_progress_bar_to_xp (progress_bar, FALSE);
1920 if (xp_theme_draw (window, xp_progress_bar, style, x, y,
1921 width, height, state_type, area))
1926 shadow_type = GTK_SHADOW_NONE;
1929 else if (detail && strcmp (detail, "menuitem") == 0)
1931 shadow_type = GTK_SHADOW_NONE;
1932 if (draw_menu_item (window, widget, style,
1933 x, y, width, height, state_type, area))
1938 else if (detail && !strcmp (detail, "trough"))
1940 if (widget && GTK_IS_PROGRESS_BAR (widget))
1942 GtkProgressBar *progress_bar = GTK_PROGRESS_BAR (widget);
1943 XpThemeElement xp_progress_bar =
1944 map_gtk_progress_bar_to_xp (progress_bar, TRUE);
1946 (window, xp_progress_bar, style, x, y, width, height,
1953 /* Blank in classic Windows */
1956 else if (widget && GTK_IS_SCROLLBAR (widget))
1958 gboolean is_vertical = GTK_IS_VSCROLLBAR (widget);
1960 if (xp_theme_draw (window,
1962 ? XP_THEME_ELEMENT_TROUGH_V
1963 : XP_THEME_ELEMENT_TROUGH_H,
1964 style, x, y, width, height, state_type, area))
1974 sanitize_size (window, &width, &height);
1975 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
1977 SetTextColor (dc, GetSysColor (COLOR_3DHILIGHT));
1978 SetBkColor (dc, GetSysColor (COLOR_BTNFACE));
1979 FillRect (dc, &rect, get_dither_brush ());
1981 release_window_dc (&dc_info);
1986 else if (widget && GTK_IS_SCALE (widget))
1988 gboolean is_vertical = GTK_IS_VSCALE (widget);
1990 if (!xp_theme_is_active ())
1992 parent_class->draw_box (style, window, state_type,
1993 GTK_SHADOW_NONE, area,
1994 widget, detail, x, y, width, height);
2000 (window, XP_THEME_ELEMENT_SCALE_TROUGH_V,
2001 style, (2 * x + width) / 2, y, 2, height,
2007 parent_class->draw_box (style, window, state_type,
2008 GTK_SHADOW_ETCHED_IN,
2010 (2 * x + width) / 2, y, 1, height);
2015 (window, XP_THEME_ELEMENT_SCALE_TROUGH_H,
2016 style, x, (2 * y + height) / 2, width, 2,
2022 parent_class->draw_box (style, window, state_type,
2023 GTK_SHADOW_ETCHED_IN,
2024 area, NULL, NULL, x,
2025 (2 * y + height) / 2, width, 1);
2031 else if (detail && strcmp (detail, "optionmenu") == 0)
2033 if (xp_theme_draw (window, XP_THEME_ELEMENT_EDIT_TEXT,
2034 style, x, y, width, height, state_type, area))
2040 && (strcmp (detail, "vscrollbar") == 0
2041 || strcmp (detail, "hscrollbar") == 0))
2046 && (strcmp (detail, "handlebox_bin") == 0
2047 || strcmp (detail, "toolbar") == 0
2048 || strcmp (detail, "menubar") == 0))
2050 sanitize_size (window, &width, &height);
2051 if (xp_theme_draw (window, XP_THEME_ELEMENT_REBAR,
2052 style, x, y, width, height, state_type, area))
2057 else if (detail && (!strcmp (detail, "handlebox"))) /* grip */
2059 if (!xp_theme_is_active ())
2064 else if (detail && !strcmp (detail, "notebook") && GTK_IS_NOTEBOOK (widget))
2066 if (xp_theme_draw (window, XP_THEME_ELEMENT_TAB_PANE, style,
2067 x, y, width, height, state_type, area))
2075 const gchar *name = gtk_widget_get_name (widget);
2077 if (name && !strcmp (name, "gtk-tooltips"))
2080 (window, XP_THEME_ELEMENT_TOOLTIP, style, x, y, width,
2081 height, state_type, area))
2092 hdc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
2094 brush = GetSysColorBrush (COLOR_3DDKSHADOW);
2098 FrameRect (hdc, &rect, brush);
2101 InflateRect (&rect, -1, -1);
2102 FillRect (hdc, &rect, (HBRUSH) (COLOR_INFOBK + 1));
2104 release_window_dc (&dc_info);
2111 parent_class->draw_box (style, window, state_type, shadow_type, area,
2112 widget, detail, x, y, width, height);
2114 if (detail && strcmp (detail, "optionmenu") == 0)
2116 GtkRequisition indicator_size;
2117 GtkBorder indicator_spacing;
2120 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2122 sanitize_size (window, &width, &height);
2124 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
2127 x + indicator_size.width + indicator_spacing.left +
2128 indicator_spacing.right;
2132 vline_x = x + width - (indicator_size.width +
2133 indicator_spacing.left +
2134 indicator_spacing.right) - style->xthickness;
2136 parent_class->draw_vline (style, window, state_type, area, widget,
2138 y + style->ythickness + 1,
2139 y + height - style->ythickness - 3, vline_x);
2145 draw_tab (GtkStyle *style,
2148 GtkShadowType shadow,
2151 const gchar *detail, gint x, gint y, gint width, gint height)
2153 GtkRequisition indicator_size;
2154 GtkBorder indicator_spacing;
2158 g_return_if_fail (style != NULL);
2159 g_return_if_fail (window != NULL);
2161 if (detail && !strcmp (detail, "optionmenutab"))
2163 if (xp_theme_draw (window, XP_THEME_ELEMENT_COMBOBUTTON,
2164 style, x - 5, widget->allocation.y + 1,
2165 width + 10, widget->allocation.height - 2,
2172 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2174 x += (width - indicator_size.width) / 2;
2175 arrow_height = (indicator_size.width + 1) / 2;
2177 y += (height - arrow_height) / 2;
2179 draw_varrow (window, &style->black, shadow, area, GTK_ARROW_DOWN,
2180 x, y, indicator_size.width, arrow_height);
2183 /* Draw classic Windows tab - thanks Mozilla!
2184 (no system API for this, but DrawEdge can draw all the parts of a tab) */
2186 DrawTab (HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
2187 gboolean aDrawLeft, gboolean aDrawRight)
2189 gint32 leftFlag, topFlag, rightFlag, lightFlag, shadeFlag;
2190 RECT topRect, sideRect, bottomRect, lightRect, shadeRect;
2191 gint32 selectedOffset, lOffset, rOffset;
2193 selectedOffset = aSelected ? 1 : 0;
2194 lOffset = aDrawLeft ? 2 : 0;
2195 rOffset = aDrawRight ? 2 : 0;
2197 /* Get info for tab orientation/position (Left, Top, Right, Bottom) */
2203 rightFlag = BF_BOTTOM;
2204 lightFlag = BF_DIAGONAL_ENDTOPRIGHT;
2205 shadeFlag = BF_DIAGONAL_ENDBOTTOMRIGHT;
2207 SetRect (&topRect, R.left, R.top + lOffset, R.right,
2208 R.bottom - rOffset);
2209 SetRect (&sideRect, R.left + 2, R.top, R.right - 2 + selectedOffset,
2211 SetRect (&bottomRect, R.right - 2, R.top, R.right, R.bottom);
2212 SetRect (&lightRect, R.left, R.top, R.left + 3, R.top + 3);
2213 SetRect (&shadeRect, R.left + 1, R.bottom - 2, R.left + 2,
2220 rightFlag = BF_RIGHT;
2221 lightFlag = BF_DIAGONAL_ENDTOPRIGHT;
2222 shadeFlag = BF_DIAGONAL_ENDBOTTOMRIGHT;
2224 SetRect (&topRect, R.left + lOffset, R.top, R.right - rOffset,
2226 SetRect (&sideRect, R.left, R.top + 2, R.right,
2227 R.bottom - 1 + selectedOffset);
2228 SetRect (&bottomRect, R.left, R.bottom - 1, R.right, R.bottom);
2229 SetRect (&lightRect, R.left, R.top, R.left + 3, R.top + 3);
2230 SetRect (&shadeRect, R.right - 2, R.top + 1, R.right - 1, R.top + 2);
2236 rightFlag = BF_BOTTOM;
2237 lightFlag = BF_DIAGONAL_ENDTOPLEFT;
2238 shadeFlag = BF_DIAGONAL_ENDBOTTOMLEFT;
2240 SetRect (&topRect, R.left, R.top + lOffset, R.right,
2241 R.bottom - rOffset);
2242 SetRect (&sideRect, R.left + 2 - selectedOffset, R.top, R.right - 2,
2244 SetRect (&bottomRect, R.left, R.top, R.left + 2, R.bottom);
2245 SetRect (&lightRect, R.right - 3, R.top, R.right - 1, R.top + 2);
2246 SetRect (&shadeRect, R.right - 2, R.bottom - 3, R.right, R.bottom - 1);
2251 topFlag = BF_BOTTOM;
2252 rightFlag = BF_RIGHT;
2253 lightFlag = BF_DIAGONAL_ENDTOPLEFT;
2254 shadeFlag = BF_DIAGONAL_ENDBOTTOMLEFT;
2256 SetRect (&topRect, R.left + lOffset, R.top, R.right - rOffset,
2258 SetRect (&sideRect, R.left, R.top + 2 - selectedOffset, R.right,
2260 SetRect (&bottomRect, R.left, R.top, R.right, R.top + 2);
2261 SetRect (&lightRect, R.left, R.bottom - 3, R.left + 2, R.bottom - 1);
2262 SetRect (&shadeRect, R.right - 2, R.bottom - 3, R.right, R.bottom - 1);
2266 g_return_if_reached ();
2270 FillRect (hdc, &R, (HBRUSH) (COLOR_3DFACE + 1));
2273 DrawEdge (hdc, &topRect, EDGE_RAISED, BF_SOFT | topFlag);
2277 DrawEdge (hdc, &bottomRect, EDGE_RAISED, BF_SOFT | topFlag);
2285 DrawEdge (hdc, &sideRect, EDGE_RAISED, BF_SOFT | leftFlag | rightFlag);
2287 /* Tab Diagonal Corners */
2289 DrawEdge (hdc, &lightRect, EDGE_RAISED, BF_SOFT | lightFlag);
2292 DrawEdge (hdc, &shadeRect, EDGE_RAISED, BF_SOFT | shadeFlag);
2296 draw_themed_tab_button (GtkStyle *style,
2298 GtkStateType state_type,
2299 GtkNotebook *notebook,
2301 gint width, gint height, gint gap_side)
2303 GdkPixmap *pixmap = NULL;
2305 gtk_container_get_border_width (GTK_CONTAINER (notebook));
2306 GtkWidget *widget = GTK_WIDGET (notebook);
2307 GdkRectangle draw_rect, clip_rect;
2308 GdkPixbufRotation rotation = GDK_PIXBUF_ROTATE_NONE;
2311 if (gap_side == GTK_POS_TOP)
2315 if (state_type == GTK_STATE_NORMAL)
2319 draw_rect.width = width + 2;
2320 draw_rect.height = height;
2322 clip_rect = draw_rect;
2327 draw_rect.x = x + 2;
2329 draw_rect.width = width - 2;
2330 draw_rect.height = height - 2;
2331 clip_rect = draw_rect;
2334 /* If we are currently drawing the right-most tab, and if that tab is the selected tab... */
2335 widget_right = widget->allocation.x + widget->allocation.width - border_width - 2;
2337 if (draw_rect.x + draw_rect.width >= widget_right)
2339 draw_rect.width = clip_rect.width = widget_right - draw_rect.x;
2342 if (gap_side == GTK_POS_BOTTOM)
2346 if (state_type == GTK_STATE_NORMAL)
2350 draw_rect.width = width + 2;
2351 draw_rect.height = height;
2353 clip_rect = draw_rect;
2357 draw_rect.x = x + 2;
2358 draw_rect.y = y + 2;
2359 draw_rect.width = width - 2;
2360 draw_rect.height = height - 2;
2361 clip_rect = draw_rect;
2364 /* If we are currently drawing the right-most tab, and if that tab is the selected tab... */
2365 widget_right = widget->allocation.x + widget->allocation.width - border_width - 2;
2367 if (draw_rect.x + draw_rect.width >= widget_right)
2369 draw_rect.width = clip_rect.width = widget_right - draw_rect.x;
2372 rotation = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
2374 else if (gap_side == GTK_POS_LEFT)
2378 if (state_type == GTK_STATE_NORMAL)
2382 draw_rect.width = width;
2383 draw_rect.height = height + 2;
2385 clip_rect = draw_rect;
2391 draw_rect.y = y + 2;
2392 draw_rect.width = width - 2;
2393 draw_rect.height = height - 2;
2394 clip_rect = draw_rect;
2397 /* If we are currently drawing the bottom-most tab, and if that tab is the selected tab... */
2398 widget_bottom = widget->allocation.x + widget->allocation.height - border_width - 2;
2400 if (draw_rect.y + draw_rect.height >= widget_bottom)
2402 draw_rect.height = clip_rect.height = widget_bottom - draw_rect.y;
2405 rotation = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
2407 else if (gap_side == GTK_POS_RIGHT)
2411 if (state_type == GTK_STATE_NORMAL)
2413 draw_rect.x = x + 1;
2415 draw_rect.width = width;
2416 draw_rect.height = height + 2;
2418 clip_rect = draw_rect;
2423 draw_rect.x = x + 2;
2424 draw_rect.y = y + 2;
2425 draw_rect.width = width - 2;
2426 draw_rect.height = height - 2;
2427 clip_rect = draw_rect;
2430 /* If we are currently drawing the bottom-most tab, and if that tab is the selected tab... */
2431 widget_bottom = widget->allocation.x + widget->allocation.height - border_width - 2;
2433 if (draw_rect.y + draw_rect.height >= widget_bottom)
2435 draw_rect.height = clip_rect.height = widget_bottom - draw_rect.y;
2438 rotation = GDK_PIXBUF_ROTATE_CLOCKWISE;
2441 if (gap_side == GTK_POS_TOP)
2443 if (!xp_theme_draw (window, XP_THEME_ELEMENT_TAB_ITEM, style,
2444 draw_rect.x, draw_rect.y,
2445 draw_rect.width, draw_rect.height,
2446 state_type, &clip_rect))
2456 if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT)
2458 pixmap = gdk_pixmap_new (window, clip_rect.height, clip_rect.width, -1);
2460 if (!xp_theme_draw (pixmap, XP_THEME_ELEMENT_TAB_ITEM, style,
2461 draw_rect.y - clip_rect.y, draw_rect.x - clip_rect.x,
2462 draw_rect.height, draw_rect.width, state_type, 0))
2464 g_object_unref (pixmap);
2468 pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
2469 clip_rect.height, clip_rect.width);
2470 g_object_unref (pixmap);
2474 pixmap = gdk_pixmap_new (window, clip_rect.width, clip_rect.height, -1);
2476 if (!xp_theme_draw (pixmap, XP_THEME_ELEMENT_TAB_ITEM, style,
2477 draw_rect.x - clip_rect.x, draw_rect.y - clip_rect.y,
2478 draw_rect.width, draw_rect.height, state_type, 0))
2480 g_object_unref (pixmap);
2484 pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
2485 clip_rect.width, clip_rect.height);
2486 g_object_unref (pixmap);
2489 rotated = gdk_pixbuf_rotate_simple (pixbuf, rotation);
2490 g_object_unref (pixbuf);
2493 // XXX - This is really hacky and evil. When we're drawing the left-most tab
2494 // while it is active on a bottom-oriented notebook, there is one white
2495 // pixel at the top. There may be a better solution than this if someone
2496 // has time to discover it.
2497 if (gap_side == GTK_POS_BOTTOM && state_type == GTK_STATE_NORMAL
2498 && x == widget->allocation.x)
2500 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
2501 int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2504 guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
2505 guchar *p = pixels + rowstride;
2507 for (psub = 0; psub < n_channels; psub++)
2509 pixels[psub] = p[psub];
2513 cr = gdk_cairo_create (window);
2514 gdk_cairo_set_source_pixbuf (cr, pixbuf, clip_rect.x, clip_rect.y);
2517 g_object_unref (pixbuf);
2524 draw_tab_button (GtkStyle *style,
2526 GtkStateType state_type,
2527 GtkShadowType shadow_type,
2530 const gchar *detail,
2531 gint x, gint y, gint width, gint height, gint gap_side)
2533 if (gap_side == GTK_POS_TOP || gap_side == GTK_POS_BOTTOM)
2535 /* experimental tab-drawing code from mozilla */
2542 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
2543 cr = gdk_cairo_create (window);
2545 if (gap_side == GTK_POS_TOP)
2547 else if (gap_side == GTK_POS_BOTTOM)
2548 aPosition = BF_BOTTOM;
2549 else if (gap_side == GTK_POS_LEFT)
2550 aPosition = BF_LEFT;
2552 aPosition = BF_RIGHT;
2554 if (state_type == GTK_STATE_PRELIGHT)
2555 state_type = GTK_STATE_NORMAL;
2558 gdk_cairo_rectangle (cr, area);
2560 gdk_cairo_set_source_color (cr, &style->dark[state_type]);
2563 DrawTab (dc, rect, aPosition,
2564 state_type != GTK_STATE_PRELIGHT,
2565 (gap_side != GTK_POS_LEFT), (gap_side != GTK_POS_RIGHT));
2569 release_window_dc (&dc_info);
2577 draw_extension (GtkStyle *style,
2579 GtkStateType state_type,
2580 GtkShadowType shadow_type,
2583 const gchar *detail,
2585 gint width, gint height, GtkPositionType gap_side)
2587 if (widget && GTK_IS_NOTEBOOK (widget) && detail && !strcmp (detail, "tab"))
2589 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2591 /* Why this differs from gap_side, I have no idea.. */
2592 int real_gap_side = gtk_notebook_get_tab_pos (notebook);
2594 if (!draw_themed_tab_button (style, window, state_type,
2595 GTK_NOTEBOOK (widget), x, y,
2596 width, height, real_gap_side))
2598 if (!draw_tab_button (style, window, state_type,
2599 shadow_type, area, widget,
2600 detail, x, y, width, height, real_gap_side))
2602 parent_class->draw_extension (style, window, state_type,
2603 shadow_type, area, widget, detail,
2604 x, y, width, height,
2612 draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
2613 GtkShadowType shadow_type, GdkRectangle *area,
2614 GtkWidget *widget, const gchar *detail, gint x,
2615 gint y, gint width, gint height, GtkPositionType gap_side,
2616 gint gap_x, gint gap_width)
2618 if (GTK_IS_NOTEBOOK (widget) && detail && !strcmp (detail, "notebook"))
2620 GtkNotebook *notebook = GTK_NOTEBOOK (widget);
2621 int side = gtk_notebook_get_tab_pos (notebook);
2622 int x2 = x, y2 = y, w2 = width, h2 = height;
2624 if (side == GTK_POS_TOP)
2627 y2 = y - gtk_notebook_get_tab_vborder (notebook);
2629 h2 = height + gtk_notebook_get_tab_vborder (notebook) * 2;
2631 else if (side == GTK_POS_BOTTOM)
2636 h2 = height + gtk_notebook_get_tab_vborder (notebook) * 2;
2638 else if (side == GTK_POS_LEFT)
2640 x2 = x - gtk_notebook_get_tab_hborder (notebook);
2642 w2 = width + gtk_notebook_get_tab_hborder (notebook);
2645 else if (side == GTK_POS_RIGHT)
2649 w2 = width + gtk_notebook_get_tab_hborder (notebook) * 2;
2653 if (xp_theme_draw (window, XP_THEME_ELEMENT_TAB_PANE, style,
2654 x2, y2, w2, h2, state_type, area))
2660 parent_class->draw_box_gap (style, window, state_type, shadow_type,
2661 area, widget, detail, x, y, width, height,
2662 gap_side, gap_x, gap_width);
2666 is_popup_window_child (GtkWidget *widget)
2669 GtkWindowType type = -1;
2671 top = gtk_widget_get_toplevel (widget);
2673 if (top && GTK_IS_WINDOW (top))
2675 g_object_get (top, "type", &type, NULL);
2677 if (type == GTK_WINDOW_POPUP)
2678 { /* Hack for combo boxes */
2687 draw_flat_box (GtkStyle *style, GdkWindow *window,
2688 GtkStateType state_type, GtkShadowType shadow_type,
2689 GdkRectangle *area, GtkWidget *widget,
2690 const gchar *detail, gint x, gint y, gint width, gint height)
2694 if (state_type == GTK_STATE_SELECTED &&
2695 (!strncmp ("cell_even", detail, 9) || !strncmp ("cell_odd", detail, 8)))
2697 GdkColor *gc = gtk_widget_has_focus (widget) ? &style->base[state_type] : &style->base[GTK_STATE_ACTIVE];
2698 cairo_t *cr = gdk_cairo_create (window);
2700 _cairo_draw_rectangle (cr, gc, TRUE, x, y, width, height);
2706 else if (!strcmp (detail, "checkbutton"))
2708 if (state_type == GTK_STATE_PRELIGHT)
2715 parent_class->draw_flat_box (style, window, state_type, shadow_type,
2716 area, widget, detail, x, y, width, height);
2720 draw_menu_border (GdkWindow *win, GtkStyle *style,
2721 gint x, gint y, gint width, gint height)
2727 dc = get_window_dc (style, win, GTK_STATE_NORMAL, &dc_info, x, y, width, height, &rect);
2732 if (xp_theme_is_active ())
2734 FrameRect (dc, &rect, GetSysColorBrush (COLOR_3DSHADOW));
2738 DrawEdge (dc, &rect, EDGE_RAISED, BF_RECT);
2741 release_window_dc (&dc_info);
2747 draw_shadow (GtkStyle *style,
2749 GtkStateType state_type,
2750 GtkShadowType shadow_type,
2753 const gchar *detail, gint x, gint y, gint width, gint height)
2755 gboolean is_handlebox;
2756 gboolean is_toolbar;
2758 if (detail && !strcmp (detail, "frame"))
2767 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
2768 if (is_combo_box_child (widget))
2770 FillRect (dc, &rect, GetSysColorBrush (COLOR_WINDOW));
2772 else if (is_popup_window_child (widget))
2774 FrameRect (dc, &rect, GetSysColorBrush (COLOR_WINDOWFRAME));
2778 switch (shadow_type)
2781 draw_3d_border (dc, &rect, TRUE);
2784 case GTK_SHADOW_OUT:
2785 draw_3d_border (dc, &rect, FALSE);
2788 case GTK_SHADOW_ETCHED_IN:
2789 draw_3d_border (dc, &rect, TRUE);
2790 InflateRect (&rect, -1, -1);
2791 draw_3d_border (dc, &rect, FALSE);
2794 case GTK_SHADOW_ETCHED_OUT:
2795 draw_3d_border (dc, &rect, FALSE);
2796 InflateRect (&rect, -1, -1);
2797 draw_3d_border (dc, &rect, TRUE);
2800 case GTK_SHADOW_NONE:
2805 release_window_dc (&dc_info);
2809 if (detail && (!strcmp (detail, "entry") || !strcmp (detail, "combobox")))
2811 if (shadow_type != GTK_SHADOW_IN)
2814 if (!xp_theme_draw (window, XP_THEME_ELEMENT_EDIT_TEXT, style,
2815 x, y, width, height, state_type, area))
2821 dc = get_window_dc (style, window, state_type, &dc_info,
2822 x, y, width, height, &rect);
2824 DrawEdge (dc, &rect, EDGE_SUNKEN, BF_RECT);
2825 release_window_dc (&dc_info);
2831 if (detail && !strcmp (detail, "scrolled_window") &&
2832 xp_theme_draw (window, XP_THEME_ELEMENT_EDIT_TEXT, style,
2833 x, y, width, height, state_type, area))
2838 if (detail && !strcmp (detail, "spinbutton"))
2841 if (detail && !strcmp (detail, "menu"))
2843 if (draw_menu_border (window, style, x, y, width, height))
2849 if (detail && !strcmp (detail, "handlebox"))
2852 is_handlebox = (detail && !strcmp (detail, "handlebox_bin"));
2853 is_toolbar = (detail
2854 && (!strcmp (detail, "toolbar")
2855 || !strcmp (detail, "menubar")));
2857 if (is_toolbar || is_handlebox)
2859 if (shadow_type == GTK_SHADOW_NONE)
2869 HGDIOBJ old_pen = NULL;
2870 GtkPositionType pos;
2872 sanitize_size (window, &width, &height);
2876 pos = gtk_handle_box_get_handle_position (GTK_HANDLE_BOX (widget));
2878 If the handle box is at left side,
2879 we shouldn't draw its right border.
2880 The same holds true for top, right, and bottom.
2885 pos = GTK_POS_RIGHT;
2893 pos = GTK_POS_BOTTOM;
2896 case GTK_POS_BOTTOM:
2903 GtkWidget *parent = gtk_widget_get_parent (widget);
2905 /* Dirty hack for toolbars contained in handle boxes */
2906 if (GTK_IS_HANDLE_BOX (parent))
2908 pos = gtk_handle_box_get_handle_position (GTK_HANDLE_BOX (parent));
2914 Make pos != all legal enum vaules of GtkPositionType.
2915 So every border will be draw.
2917 pos = (GtkPositionType) - 1;
2921 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
2923 if (pos != GTK_POS_LEFT)
2925 old_pen = SelectObject (dc, get_light_pen ());
2926 MoveToEx (dc, rect.left, rect.top, NULL);
2927 LineTo (dc, rect.left, rect.bottom);
2929 if (pos != GTK_POS_TOP)
2931 old_pen = SelectObject (dc, get_light_pen ());
2932 MoveToEx (dc, rect.left, rect.top, NULL);
2933 LineTo (dc, rect.right, rect.top);
2935 if (pos != GTK_POS_RIGHT)
2937 old_pen = SelectObject (dc, get_dark_pen ());
2938 MoveToEx (dc, rect.right - 1, rect.top, NULL);
2939 LineTo (dc, rect.right - 1, rect.bottom);
2941 if (pos != GTK_POS_BOTTOM)
2943 old_pen = SelectObject (dc, get_dark_pen ());
2944 MoveToEx (dc, rect.left, rect.bottom - 1, NULL);
2945 LineTo (dc, rect.right, rect.bottom - 1);
2948 SelectObject (dc, old_pen);
2949 release_window_dc (&dc_info);
2955 if (detail && !strcmp (detail, "statusbar"))
2960 parent_class->draw_shadow (style, window, state_type, shadow_type, area,
2961 widget, detail, x, y, width, height);
2965 draw_hline (GtkStyle *style,
2967 GtkStateType state_type,
2970 const gchar *detail, gint x1, gint x2, gint y)
2974 cr = gdk_cairo_create (window);
2976 if (xp_theme_is_active () && detail && !strcmp (detail, "menuitem"))
2979 gint new_y, new_height;
2982 xp_theme_get_element_dimensions (XP_THEME_ELEMENT_MENU_SEPARATOR,
2986 /* Center the separator */
2987 y_offset = (area->height / 2) - (cy / 2);
2988 new_y = y_offset >= 0 ? area->y + y_offset : area->y;
2992 (window, XP_THEME_ELEMENT_MENU_SEPARATOR, style, x1, new_y, x2, new_height,
3001 gdk_cairo_rectangle (cr, area);
3005 _cairo_draw_line (cr, &style->dark[state_type], x1, y, x2, y);
3011 if (style->ythickness == 2)
3015 gdk_cairo_rectangle (cr, area);
3019 _cairo_draw_line (cr, &style->dark[state_type], x1, y, x2, y);
3021 _cairo_draw_line (cr, &style->light[state_type], x1, y, x2, y);
3026 parent_class->draw_hline (style, window, state_type, area, widget,
3034 draw_vline (GtkStyle *style,
3036 GtkStateType state_type,
3039 const gchar *detail, gint y1, gint y2, gint x)
3043 cr = gdk_cairo_create (window);
3045 if (style->xthickness == 2)
3049 gdk_cairo_rectangle (cr, area);
3053 _cairo_draw_line (cr, &style->dark[state_type], x, y1, x, y2);
3055 _cairo_draw_line (cr, &style->light[state_type], x, y1, x, y2);
3060 parent_class->draw_vline (style, window, state_type, area, widget,
3068 draw_slider (GtkStyle *style,
3070 GtkStateType state_type,
3071 GtkShadowType shadow_type,
3074 const gchar *detail,
3076 gint y, gint width, gint height, GtkOrientation orientation)
3078 if (GTK_IS_SCALE (widget) &&
3079 xp_theme_draw (window, ((orientation == GTK_ORIENTATION_VERTICAL) ?
3080 XP_THEME_ELEMENT_SCALE_SLIDER_V :
3081 XP_THEME_ELEMENT_SCALE_SLIDER_H), style, x, y, width,
3082 height, state_type, area))
3087 parent_class->draw_slider (style, window, state_type, shadow_type, area,
3088 widget, detail, x, y, width, height,
3093 draw_resize_grip (GtkStyle *style,
3095 GtkStateType state_type,
3098 const gchar *detail,
3099 GdkWindowEdge edge, gint x, gint y, gint width, gint height)
3103 cr = gdk_cairo_create (window);
3105 if (detail && !strcmp (detail, "statusbar"))
3108 (window, XP_THEME_ELEMENT_STATUS_GRIPPER, style, x, y, width,
3109 height, state_type, area))
3118 HDC dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
3122 gdk_cairo_rectangle (cr, area);
3124 gdk_cairo_set_source_color (cr, &style->dark[state_type]);
3127 DrawFrameControl (dc, &rect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
3128 release_window_dc (&dc_info);
3135 parent_class->draw_resize_grip (style, window, state_type, area,
3136 widget, detail, edge, x, y, width, height);
3140 draw_handle (GtkStyle *style,
3142 GtkStateType state_type,
3143 GtkShadowType shadow_type,
3146 const gchar *detail,
3148 gint y, gint width, gint height, GtkOrientation orientation)
3155 cr = gdk_cairo_create (window);
3157 if (is_toolbar_child (widget))
3159 XpThemeElement hndl;
3161 sanitize_size (window, &width, &height);
3163 if (GTK_IS_HANDLE_BOX (widget))
3165 GtkPositionType pos;
3166 pos = gtk_handle_box_get_handle_position (GTK_HANDLE_BOX (widget));
3168 if (pos == GTK_POS_TOP || pos == GTK_POS_BOTTOM)
3170 orientation = GTK_ORIENTATION_HORIZONTAL;
3174 orientation = GTK_ORIENTATION_VERTICAL;
3178 if (orientation == GTK_ORIENTATION_VERTICAL)
3179 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_V;
3181 hndl = XP_THEME_ELEMENT_REBAR_GRIPPER_H;
3183 if (xp_theme_draw (window, hndl, style, x, y, width, height,
3189 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
3191 if (orientation == GTK_ORIENTATION_VERTICAL)
3194 rect.right = rect.left + 3;
3201 rect.bottom = rect.top + 3;
3206 draw_3d_border (dc, &rect, FALSE);
3207 release_window_dc (&dc_info);
3211 if (!GTK_IS_PANED (widget))
3213 gint xthick, ythick;
3214 GdkColor *light, *dark, *shadow;
3217 sanitize_size (window, &width, &height);
3219 gtk_paint_box (style, window, state_type, shadow_type, area,
3220 widget, detail, x, y, width, height);
3222 light = &style->light[state_type];
3223 dark = &style->dark[state_type];
3224 shadow = &style->mid[state_type];
3226 xthick = style->xthickness;
3227 ythick = style->ythickness;
3229 dest.x = x + xthick;
3230 dest.y = y + ythick;
3231 dest.width = width - (xthick * 2);
3232 dest.height = height - (ythick * 2);
3234 if (dest.width < dest.height)
3239 gdk_cairo_rectangle (cr, &dest);
3242 if (dest.width < dest.height)
3244 _cairo_draw_line (cr, light, dest.x, dest.y, dest.x,
3246 _cairo_draw_line (cr, dark, dest.x + (dest.width / 2),
3247 dest.y, dest.x + (dest.width / 2), dest.height);
3248 _cairo_draw_line (cr, shadow, dest.x + dest.width,
3249 dest.y, dest.x + dest.width, dest.height);
3253 _cairo_draw_line (cr, light, dest.x, dest.y,
3254 dest.x + dest.width, dest.y);
3255 _cairo_draw_line (cr, dark, dest.x,
3256 dest.y + (dest.height / 2),
3257 dest.x + dest.width, dest.y + (dest.height / 2));
3258 _cairo_draw_line (cr, shadow, dest.x,
3259 dest.y + dest.height, dest.x + dest.width,
3260 dest.y + dest.height);
3268 draw_focus (GtkStyle *style,
3270 GtkStateType state_type,
3273 const gchar *detail, gint x, gint y, gint width, gint height)
3279 if (!gtk_widget_get_can_focus (widget))
3284 if (is_combo_box_child (widget)
3285 && (GTK_IS_ARROW (widget) || GTK_IS_BUTTON (widget)))
3289 if (GTK_IS_TREE_VIEW (widget->parent) /* list view bheader */)
3294 dc = get_window_dc (style, window, state_type, &dc_info, x, y, width, height, &rect);
3295 DrawFocusRect (dc, &rect);
3296 release_window_dc (&dc_info);
3298 parent_class->draw_focus (style, window, state_type,
3299 area, widget, detail, x, y, width, height);
3304 draw_layout (GtkStyle *style,
3306 GtkStateType state_type,
3310 const gchar *detail,
3311 gint old_x, gint old_y, PangoLayout *layout)
3313 GtkNotebook *notebook = NULL;
3317 /* In the XP theme, labels don't appear correctly centered inside
3318 * notebook tabs, so we give them a gentle nudge two pixels to the
3319 * right. A little hackish, but what are 'ya gonna do? -- Cody
3321 if (xp_theme_is_active () && detail && !strcmp (detail, "label"))
3323 if (widget->parent != NULL)
3325 if (GTK_IS_NOTEBOOK (widget->parent))
3328 notebook = GTK_NOTEBOOK (widget->parent);
3329 side = gtk_notebook_get_tab_pos (notebook);
3331 if (side == GTK_POS_TOP || side == GTK_POS_BOTTOM)
3339 parent_class->draw_layout (style, window, state_type,
3340 use_text, area, widget, detail, x, y, layout);
3344 msw_style_init_from_rc (GtkStyle *style, GtkRcStyle *rc_style)
3346 setup_system_font (style);
3347 setup_menu_settings (gtk_settings_get_default ());
3348 setup_system_styles (style);
3349 parent_class->init_from_rc (style, rc_style);
3353 msw_style_class_init (MswStyleClass *klass)
3355 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
3357 parent_class = g_type_class_peek_parent (klass);
3359 style_class->init_from_rc = msw_style_init_from_rc;
3360 style_class->draw_arrow = draw_arrow;
3361 style_class->draw_box = draw_box;
3362 style_class->draw_check = draw_check;
3363 style_class->draw_option = draw_option;
3364 style_class->draw_tab = draw_tab;
3365 style_class->draw_flat_box = draw_flat_box;
3366 style_class->draw_expander = draw_expander;
3367 style_class->draw_extension = draw_extension;
3368 style_class->draw_box_gap = draw_box_gap;
3369 style_class->draw_shadow = draw_shadow;
3370 style_class->draw_hline = draw_hline;
3371 style_class->draw_vline = draw_vline;
3372 style_class->draw_handle = draw_handle;
3373 style_class->draw_resize_grip = draw_resize_grip;
3374 style_class->draw_slider = draw_slider;
3375 style_class->draw_focus = draw_focus;
3376 style_class->draw_layout = draw_layout;
3379 GType msw_type_style = 0;
3382 msw_style_register_type (GTypeModule *module)
3384 const GTypeInfo object_info = {
3385 sizeof (MswStyleClass),
3386 (GBaseInitFunc) NULL,
3387 (GBaseFinalizeFunc) NULL,
3388 (GClassInitFunc) msw_style_class_init,
3389 NULL, /* class_finalize */
3390 NULL, /* class_data */
3392 0, /* n_preallocs */
3393 (GInstanceInitFunc) NULL,
3396 msw_type_style = g_type_module_register_type (module,
3398 "MswStyle", &object_info, 0);
3402 msw_style_init (void)
3405 msw_style_setup_system_settings ();
3406 setup_msw_rc_style ();
3410 DeleteObject (g_light_pen);
3416 DeleteObject (g_dark_pen);
3422 msw_style_finalize (void)
3426 DeleteObject (g_dither_brush);
3431 DeleteObject (g_light_pen);
3436 DeleteObject (g_dark_pen);