]> Pileus Git - ~andy/gtk/commitdiff
[win32] Properly draw the menu separator for Windows Vista/7.
authorMartin Schlemmer <11285613@nwu.ac.za>
Mon, 30 Aug 2010 18:03:04 +0000 (20:03 +0200)
committerFridrich Štrba <fridrich.strba@bluewin.ch>
Mon, 30 Aug 2010 18:05:09 +0000 (20:05 +0200)
Also adds the bits for transparency.

modules/engines/ms-windows/msw_style.c
modules/engines/ms-windows/xp_theme.c
modules/engines/ms-windows/xp_theme.h
modules/engines/ms-windows/xp_theme_defs.h

index e76519b2c88d55d23a1271222042bb73075a2969..d08e1cd37bceb265f9334442a8348bcb17665ba5 100755 (executable)
@@ -2903,8 +2903,21 @@ draw_hline (GtkStyle *style,
 {
   if (xp_theme_is_active () && detail && !strcmp (detail, "menuitem"))
     {
+      gint cx, cy;
+      gint new_y, new_height;
+      gint y_offset;
+
+      xp_theme_get_element_dimensions (XP_THEME_ELEMENT_MENU_SEPARATOR,
+                                      state_type,
+                                      &cx, &cy);
+
+      /* Center the separator */
+      y_offset = (area->height / 2) - (cy / 2);
+      new_y = y_offset >= 0 ? area->y + y_offset : area->y;
+      new_height = cy;
+
       if (xp_theme_draw
-         (window, XP_THEME_ELEMENT_MENU_SEPARATOR, style, x1, y, x2, 1,
+         (window, XP_THEME_ELEMENT_MENU_SEPARATOR, style, x1, new_y, x2, new_height,
           state_type, area))
        {
          return;
index f86451570dcd95385f2b64338e0bd599db0bbcd0..79698ac6f6101ca2f7cd77141086bd334793eb89 100755 (executable)
@@ -86,6 +86,7 @@
 #define MBI_DISABLEDHOT    5
 #define MBI_DISABLEDPUSHED 6
 
+#define MENU_POPUPGUTTER    13
 #define MENU_POPUPITEM      14
 #define MENU_POPUPSEPARATOR 15
 
@@ -188,6 +189,13 @@ typedef BOOL (FAR PASCAL *IsThemeBackgroundPartiallyTransparentFunc) (HTHEME hTh
 typedef HRESULT (FAR PASCAL *DrawThemeParentBackgroundFunc) (HWND hwnd,
                                                             HDC hdc,
                                                             RECT *prc);
+typedef HRESULT (FAR PASCAL *GetThemePartSizeFunc)          (HTHEME hTheme,
+                                                            HDC hdc,
+                                                            int iPartId,
+                                                            int iStateId,
+                                                            RECT *prc,
+                                                            int eSize,
+                                                            SIZE *psz);
 
 static GetThemeSysFontFunc get_theme_sys_font_func = NULL;
 static GetThemeSysColorFunc get_theme_sys_color_func = NULL;
@@ -200,6 +208,7 @@ static IsThemeActiveFunc is_theme_active_func = NULL;
 static IsAppThemedFunc is_app_themed_func = NULL;
 static IsThemeBackgroundPartiallyTransparentFunc is_theme_partially_transparent_func = NULL;
 static DrawThemeParentBackgroundFunc draw_theme_parent_background_func = NULL;
+static GetThemePartSizeFunc get_theme_part_size_func = NULL;
 
 static void
 xp_theme_close_open_handles (void)
@@ -242,6 +251,7 @@ xp_theme_init (void)
       get_theme_sys_metric_func = (GetThemeSysSizeFunc) GetProcAddress (uxtheme_dll, "GetThemeSysSize");
       is_theme_partially_transparent_func = (IsThemeBackgroundPartiallyTransparentFunc) GetProcAddress (uxtheme_dll, "IsThemeBackgroundPartiallyTransparent");
       draw_theme_parent_background_func = (DrawThemeParentBackgroundFunc) GetProcAddress (uxtheme_dll, "DrawThemeParentBackground");
+      get_theme_part_size_func = (GetThemePartSizeFunc) GetProcAddress (uxtheme_dll, "GetThemePartSize");
     }
 
   if (is_app_themed_func && is_theme_active_func)
@@ -292,6 +302,7 @@ xp_theme_exit (void)
   get_theme_sys_metric_func = NULL;
   is_theme_partially_transparent_func = NULL;
   draw_theme_parent_background_func = NULL;
+  get_theme_part_size_func = NULL;
 }
 
 static HTHEME
@@ -782,8 +793,11 @@ xp_theme_map_gtk_state (XpThemeElement element, GtkStateType state)
       ret = 1;
       break;
 
-    case XP_THEME_ELEMENT_MENU_ITEM:
     case XP_THEME_ELEMENT_MENU_SEPARATOR:
+      ret = TS_NORMAL;
+      break;
+
+    case XP_THEME_ELEMENT_MENU_ITEM:
       switch (state)
        {
        case GTK_STATE_SELECTED:
@@ -934,6 +948,10 @@ xp_theme_draw (GdkWindow *win, XpThemeElement element, GtkStyle *style,
 
   part_state = xp_theme_map_gtk_state (element, state_type);
 
+  /* Support transparency */
+  if (is_theme_partially_transparent_func (theme, element_part_map[element], part_state))
+    draw_theme_parent_background_func (GDK_WINDOW_HWND (win), dc, pClip);
+
   draw_theme_background_func (theme, dc, element_part_map[element],
                              part_state, &rect, pClip);
 
@@ -957,6 +975,55 @@ xp_theme_is_drawable (XpThemeElement element)
   return FALSE;
 }
 
+gboolean
+xp_theme_get_element_dimensions (XpThemeElement element,
+                                GtkStateType state_type,
+                                gint *cx, gint *cy)
+{
+  HTHEME theme;
+  SIZE part_size;
+  int part_state;
+
+  if (!xp_theme_is_active ())
+    return FALSE;
+
+  theme = xp_theme_get_handle_by_element (element);
+  if (!theme)
+    return FALSE;
+
+  part_state = xp_theme_map_gtk_state (element, state_type);
+
+  get_theme_part_size_func (theme,
+                           NULL,
+                           element_part_map[element],
+                           part_state,
+                           NULL,
+                           TS_MIN,
+                           &part_size);
+
+  *cx = part_size.cx;
+  *cy = part_size.cy;
+
+  if (element == XP_THEME_ELEMENT_MENU_ITEM ||
+      element == XP_THEME_ELEMENT_MENU_SEPARATOR)
+  {
+    SIZE gutter_size;
+
+    get_theme_part_size_func (theme,
+                             NULL,
+                             MENU_POPUPGUTTER,
+                             0,
+                             NULL,
+                             TS_MIN,
+                             &gutter_size);
+
+       *cx += gutter_size.cx * 2;
+       *cy += gutter_size.cy * 2;
+  }
+
+  return TRUE;
+}
+
 gboolean
 xp_theme_get_system_font (XpThemeClass klazz, XpThemeFont fontId,
                          OUT LOGFONTW *lf)
index 2d172f35292cac100848bbbcc746a5ebacc60529..dfacb434cc1fb935661a867b7cea9317d4f9d77b 100755 (executable)
@@ -141,6 +141,9 @@ gboolean xp_theme_draw (GdkWindow *win, XpThemeElement element,
                         int height, GtkStateType state_type,
                         GdkRectangle *area);
 gboolean xp_theme_is_drawable (XpThemeElement element);
+gboolean xp_theme_get_element_dimensions (XpThemeElement element,
+                                          GtkStateType state_type,
+                                          gint *cx, gint *cy);
 gboolean xp_theme_get_system_font (XpThemeClass klazz, XpThemeFont fontId, OUT LOGFONTW *lf);
 gboolean xp_theme_get_system_color (XpThemeClass klazz, int colorId, OUT DWORD *pColor);
 gboolean xp_theme_get_system_metric (XpThemeClass klazz, int metricId, OUT int *pVal);
index 49f5179fdb94b4cefada804384daadddf30c1491..aaae6d9316bf408991d86365cb1395fbd6b29b86 100644 (file)
@@ -756,4 +756,10 @@ enum {
   VTS_DISABLED = 4
 };
 
+enum {
+  TS_MIN,
+  TS_TRUE,
+  TS_DRAW
+};
+
 #endif /* XP_THEME_DFNS_H */