]> Pileus Git - ~andy/gtk/blobdiff - modules/engines/ms-windows/msw_style.c
Deprecate widget flag: GTK_WIDGET_HAS_FOCUS
[~andy/gtk] / modules / engines / ms-windows / msw_style.c
index 9c11b75bfc375f85ce5cd6e7101b358292b548c2..c69d1c7bb4017e57bba2ef994b40514ccb533f3f 100755 (executable)
 
 #include "gtk/gtk.h"
 #include "gtk/gtk.h"
-/* #include <gdk/gdkwin32.h> */
 
+#ifdef BUILDING_STANDALONE
+#include "gdk/gdkwin32.h"
+#else
 #include "gdk/win32/gdkwin32.h"
+#endif
 
 static HDC get_window_dc (GtkStyle *style, GdkWindow *window,
                          GtkStateType state_type, gint x, gint y, gint width,
@@ -533,29 +536,42 @@ sys_font_to_pango_font (XpThemeClass klazz, XpThemeFont type, char *buf,
    for now */
 #define XP_THEME_CLASS_TEXT XP_THEME_CLASS_BUTTON
 
+#define WIN95_VERSION   0x400
+#define WIN2K_VERSION   0x500
+#define WINXP_VERSION   0x501
+#define WIN2K3_VERSION  0x502
+#define VISTA_VERSION   0x600
+
+static gint32
+get_windows_version ()
+{
+  static gint32 version = 0;
+  static gboolean have_version = FALSE;
+
+  if (!have_version)
+    {
+      OSVERSIONINFOEX osvi;
+      have_version = TRUE;
+
+      ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX));
+      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
+
+      GetVersionEx((OSVERSIONINFO*) &osvi);
+
+      version = (osvi.dwMajorVersion & 0xff) << 8 | (osvi.dwMinorVersion & 0xff);
+    }
+
+  return version;
+}
+
 static void
 setup_menu_settings (GtkSettings *settings)
 {
   int menu_delay;
-  gboolean win95 = FALSE;
   OSVERSIONINFOEX osvi;
   GObjectClass *klazz = G_OBJECT_GET_CLASS (G_OBJECT (settings));
 
-  ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX));
-  osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
-
-  if (!GetVersionEx ((OSVERSIONINFO *) & osvi))
-    win95 = TRUE;              /* assume the worst */
-
-  if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
-    {
-      if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
-       {
-         win95 = TRUE;
-       }
-    }
-
-  if (!win95)
+  if (get_windows_version () > WIN95_VERSION)
     {
       if (SystemParametersInfo (SPI_GETMENUSHOWDELAY, 0, &menu_delay, 0))
        {
@@ -682,7 +698,8 @@ setup_msw_rc_style (void)
   GdkColor text_prelight;
 
   /* Prelight */
-  sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHTTEXT,
+  sys_color_to_gtk_color (get_windows_version () >= VISTA_VERSION ? XP_THEME_CLASS_MENU : XP_THEME_CLASS_TEXT,
+                         get_windows_version () >= VISTA_VERSION ? COLOR_MENUTEXT : COLOR_HIGHLIGHTTEXT,
                          &fg_prelight);
   sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT, &bg_prelight);
   sys_color_to_gtk_color (XP_THEME_CLASS_TEXT, COLOR_HIGHLIGHT,
@@ -778,7 +795,8 @@ setup_msw_rc_style (void)
   g_snprintf (buf, sizeof (buf),
              "style \"msw-tooltips-caption\" = \"msw-default\"\n"
              "{fg[NORMAL] = { %d, %d, %d }\n" "%s = \"%s\"\n"
-             "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n",
+             "}widget \"gtk-tooltips.GtkLabel\" style \"msw-tooltips-caption\"\n"
+             "widget \"gtk-tooltip.GtkLabel\" style \"msw-tooltips-caption\"\n",
              tooltip_fore.red, tooltip_fore.green, tooltip_fore.blue,
              (font_ptr ? "font_name" : "#"),
              (font_ptr ? font_ptr : " font name should go here"));
@@ -787,7 +805,8 @@ setup_msw_rc_style (void)
   g_snprintf (buf, sizeof (buf),
              "style \"msw-tooltips\" = \"msw-default\"\n"
              "{bg[NORMAL] = { %d, %d, %d }\n"
-             "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n",
+             "}widget \"gtk-tooltips*\" style \"msw-tooltips\"\n"
+             "widget \"gtk-tooltip*\" style \"msw-tooltips\"\n",
              tooltip_back.red, tooltip_back.green, tooltip_back.blue);
   gtk_rc_parse_string (buf);
 
@@ -902,24 +921,25 @@ setup_msw_rc_style (void)
              "ythickness = %d\n"
              "}\n"
              "class \"GtkComboBox\" style \"msw-combobox\"\n",
-             GetSystemMetrics (SM_CXEDGE), GetSystemMetrics (SM_CYEDGE));
+        xp_theme_is_active()? 1 : GetSystemMetrics (SM_CXEDGE),
+        xp_theme_is_active()? 1 : GetSystemMetrics (SM_CYEDGE));
   gtk_rc_parse_string (buf);
 
   /* size of tree view header */
   g_snprintf (buf, sizeof (buf),
              "style \"msw-header-button\" = \"msw-default\"\n"
              "{\n"
-             "xthickness = 4\n"
-             "ythickness = %d\n"
-             "GtkButton::default-border = { 0, 0, 0, 0 }\n"
+             "xthickness = 0\n"
+             "ythickness = 0\n"
+             "GtkWidget::draw-border = {0, 0, 0, 0}\n"
+        "GtkButton::default-border = { 0, 0, 0, 0 }\n"
              "GtkButton::default-outside-border = { 0, 0, 0, 0 }\n"
-             "GtkButton::child-displacement-x = 1\n"
-             "GtkButton::child-displacement-y = 1\n"
+             "GtkButton::child-displacement-x = 0\n"
+             "GtkButton::child-displacement-y = 0\n"
              "GtkWidget::focus-padding = 0\n"
              "GtkWidget::focus-line-width = 0\n"
              "}\n"
-             "widget_class \"*TreeView*Button*\" style \"msw-header-button\"\n",
-             xp_theme_is_active ()? 2 : 0);
+             "widget_class \"*TreeView*Button*\" style \"msw-header-button\"\n");
   gtk_rc_parse_string (buf);
 
   /* FIXME: This should be enabled once gtk+ support GtkNotebok::prelight-tab */
@@ -1078,7 +1098,8 @@ is_combo_box_child (GtkWidget *w)
   return FALSE;
 }
 
-static gboolean
+/* This function is not needed anymore */
+/* static gboolean
 combo_box_draw_arrow (GtkStyle *style,
                      GdkWindow *window,
                      GtkStateType state,
@@ -1107,7 +1128,7 @@ combo_box_draw_arrow (GtkStyle *style,
     }
 
   return FALSE;
-}
+}*/
 
 static void
 draw_part (GdkDrawable *drawable,
@@ -1494,13 +1515,8 @@ draw_arrow (GtkStyle *style,
 
   sanitize_size (window, &width, &height);
 
-  if (GTK_IS_ARROW (widget) && is_combo_box_child (widget))
-    {
-      if (combo_box_draw_arrow (style, window, state, area, widget))
-       {
-         return;
-       }
-    }
+  if (GTK_IS_ARROW (widget) && is_combo_box_child (widget) && xp_theme_is_active ())
+    return;
 
   if (detail && strcmp (detail, "spinbutton") == 0)
     {
@@ -1808,6 +1824,12 @@ draw_menu_item (GdkWindow *window, GtkWidget *widget, GtkStyle *style,
   HDC dc;
   RECT rect;
 
+  if (xp_theme_is_active ())
+    {
+      return (xp_theme_draw (window, XP_THEME_ELEMENT_MENU_ITEM, style,
+                             x, y, width, height, state_type, area));
+    }
+
   if ((parent = gtk_widget_get_parent (widget))
       && GTK_IS_MENU_BAR (parent) && !xp_theme_is_active ())
     {
@@ -1949,7 +1971,7 @@ draw_push_button (GdkWindow *window, GtkWidget *widget, GtkStyle *style,
     }
   else
     {
-      if (is_default || GTK_WIDGET_HAS_FOCUS (widget))
+      if (is_default || gtk_widget_has_focus (widget))
        {
          FrameRect (dc, &rect, GetSysColorBrush (COLOR_WINDOWFRAME));
          InflateRect (&rect, -1, -1);
@@ -1973,22 +1995,29 @@ draw_box (GtkStyle *style,
   if (is_combo_box_child (widget) && detail && !strcmp (detail, "button"))
     {
       RECT rect;
+      DWORD border;
       HDC dc;
       int cx;
 
-      dc = get_window_dc (style, window, state_type, x, y, width - cx, height, &rect);
-      FillRect (dc, &rect, GetSysColorBrush (COLOR_WINDOW));
-      release_window_dc (style, window, state_type);
+      border = (GTK_TOGGLE_BUTTON (widget)->active ? DFCS_PUSHED | DFCS_FLAT : 0);
 
-      cx = 2 * GetSystemMetrics (SM_CXEDGE) + 16;      /* TODO evaluate arrow width */
-      x += width - cx;
-      width = cx;
+      dc = get_window_dc (style, window, state_type, x, y, width, height, &rect);
+      DrawFrameControl (dc, &rect, DFC_SCROLL, DFCS_SCROLLDOWN | border);
+      release_window_dc (style, window, state_type);
 
       if (xp_theme_is_active ()
          && xp_theme_draw (window, XP_THEME_ELEMENT_COMBOBUTTON, style, x, y,
                            width, height, state_type, area))
        {
-         return;
+      cx = GetSystemMetrics(SM_CXVSCROLL);
+      x += width - cx;
+      width = cx;
+
+
+      dc = get_window_dc (style, window, state_type, x, y, width - cx, height, &rect);
+      FillRect (dc, &rect, GetSysColorBrush (COLOR_WINDOW));
+      release_window_dc (style, window, state_type);
+      return;
        }
     }
 
@@ -1996,8 +2025,8 @@ draw_box (GtkStyle *style,
       (!strcmp (detail, "button") || !strcmp (detail, "buttondefault")))
     {
       if (GTK_IS_TREE_VIEW (widget->parent) || GTK_IS_CLIST (widget->parent))
-       {
-         if (xp_theme_draw
+      {
+        if (xp_theme_draw
              (window, XP_THEME_ELEMENT_LIST_HEADER, style, x, y,
               width, height, state_type, area))
            {
@@ -2028,7 +2057,7 @@ draw_box (GtkStyle *style,
        }
       else
        {
-         gboolean is_default = GTK_WIDGET_HAS_DEFAULT (widget);
+         gboolean is_default = gtk_widget_has_default (widget);
          if (xp_theme_draw
              (window,
               is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON :
@@ -2893,7 +2922,16 @@ draw_flat_box (GtkStyle *style, GdkWindow *window,
 {
   if (detail)
     {
-      if (!strcmp (detail, "checkbutton"))
+      if (state_type == GTK_STATE_SELECTED &&
+         (!strncmp ("cell_even", detail, 9) || !strncmp ("cell_odd", detail, 8)))
+       {
+         GdkGC *gc = gtk_widget_has_focus (widget) ? style->base_gc[state_type] : style->base_gc[GTK_STATE_ACTIVE];
+
+         gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
+
+         return;
+       }
+      else if (!strcmp (detail, "checkbutton"))
        {
          if (state_type == GTK_STATE_PRELIGHT)
            {
@@ -2946,11 +2984,18 @@ draw_shadow (GtkStyle *style,
 
   if (detail && !strcmp (detail, "frame"))
     {
+
       HDC dc;
       RECT rect;
-      dc = get_window_dc (style, window, state_type, x, y, width, height, &rect);
 
-      if (is_popup_window_child (widget))
+
+
+      dc = get_window_dc (style, window, state_type, x, y, width, height, &rect);
+      if (is_combo_box_child (widget))
+        {
+          FillRect (dc, &rect, GetSysColorBrush (COLOR_WINDOW));
+        }
+      else if (is_popup_window_child (widget))
        {
          FrameRect (dc, &rect, GetSysColorBrush (COLOR_WINDOWFRAME));
        }
@@ -3054,7 +3099,7 @@ draw_shadow (GtkStyle *style,
            {
              pos = gtk_handle_box_get_handle_position (GTK_HANDLE_BOX (widget));
              /*
-                If the handle box is at left side, 
+                If the handle box is at left side,
                 we shouldn't draw its right border.
                 The same holds true for top, right, and bottom.
               */
@@ -3434,7 +3479,7 @@ draw_focus (GtkStyle *style,
   HDC dc;
   RECT rect;
 
-  if (!GTK_WIDGET_CAN_FOCUS (widget))
+  if (!gtk_widget_get_can_focus (widget))
     {
       return;
     }
@@ -3483,8 +3528,9 @@ draw_layout (GtkStyle *style,
        {
          if (GTK_IS_NOTEBOOK (widget->parent))
            {
+             int side;
              notebook = GTK_NOTEBOOK (widget->parent);
-             int side = gtk_notebook_get_tab_pos (notebook);
+             side = gtk_notebook_get_tab_pos (notebook);
 
              if (side == GTK_POS_TOP || side == GTK_POS_BOTTOM)
                {
@@ -3699,7 +3745,7 @@ GType msw_type_style = 0;
 void
 msw_style_register_type (GTypeModule *module)
 {
-  static const GTypeInfo object_info = {
+  const GTypeInfo object_info = {
     sizeof (MswStyleClass),
     (GBaseInitFunc) NULL,
     (GBaseFinalizeFunc) NULL,