*** modules/engines/ms-windows/msw_style.c.old	2011-02-19 15:31:37.000000000 +0100
--- modules/engines/ms-windows/msw_style.c	2011-05-16 08:15:33.897461000 +0200
***************
*** 2347,2352 ****
--- 2347,2414 ----
      DrawEdge (hdc, &shadeRect, EDGE_RAISED, BF_SOFT | shadeFlag);
  }
  
+ static void
+ get_notebook_tab_position (GtkNotebook *notebook, gboolean *start, gboolean *end)
+ {
+   /* default value */
+   *start = TRUE;
+   *end = FALSE;
+ 
+   gboolean found_tabs = FALSE;
+   gint i, n_pages;
+   
+   n_pages = gtk_notebook_get_n_pages (notebook);
+   for (i = 0; i < n_pages; i++) {
+     GtkWidget *tab_child;
+     GtkWidget *tab_label;
+     gboolean expand;
+     GtkPackType pack_type;
+     
+     tab_child = gtk_notebook_get_nth_page (notebook, i);
+     
+     /* Skip invisible tabs */
+     tab_label = gtk_notebook_get_tab_label (notebook, tab_child);
+     if (!tab_label || !GTK_WIDGET_VISIBLE (tab_label))
+       continue;
+     /* This is the same what the notebook does internally. */
+     if (tab_label && !gtk_widget_get_child_visible (tab_label)) {
+       /* One child is hidden because scroll arrows are present.
+        * So both corners are rounded. */
+       *start = FALSE;
+       *end = FALSE;
+       return;
+     }
+     
+     gtk_notebook_query_tab_label_packing 
+       (notebook, tab_child,
+        &expand,
+        NULL, /* don't need fill */
+        &pack_type);
+     
+     if (!found_tabs) {
+       //  First tab found
+       found_tabs = TRUE;
+       if (gtk_notebook_get_current_page (notebook) == i) {
+         *start = TRUE;
+       } else {
+         *start = FALSE;
+       }
+     }
+     
+     if (gtk_notebook_get_current_page (notebook) == i) {
+       if (expand) {
+         *end = TRUE;
+       } else {
+         *end = FALSE;
+         return;
+       }
+     } else {
+       *end = FALSE; 
+       return;
+     }
+   }
+ }
+ 
  static gboolean
  draw_themed_tab_button (GtkStyle *style,
  			GdkWindow *window,
***************
*** 2356,2576 ****
  			gint width, gint height, gint gap_side)
  {
    GdkPixmap *pixmap = NULL;
-   gint border_width =
-     gtk_container_get_border_width (GTK_CONTAINER (notebook));
-   GtkWidget *widget = GTK_WIDGET (notebook);
    GdkRectangle draw_rect, clip_rect;
-   GdkPixbufRotation rotation = GDK_PIXBUF_ROTATE_NONE;
    cairo_t *cr;
! 
!   if (gap_side == GTK_POS_TOP)
!     {
!       int widget_right;
! 
!       if (state_type == GTK_STATE_NORMAL)
! 	{
! 	  draw_rect.x = x;
! 	  draw_rect.y = y;
! 	  draw_rect.width = width + 2;
! 	  draw_rect.height = height;
! 
! 	  clip_rect = draw_rect;
! 	  clip_rect.height--;
! 	}
!       else
! 	{
! 	  draw_rect.x = x + 2;
! 	  draw_rect.y = y;
! 	  draw_rect.width = width - 2;
! 	  draw_rect.height = height - 2;
! 	  clip_rect = draw_rect;
! 	}
! 
!       /* If we are currently drawing the right-most tab, and if that tab is the selected tab... */
!       widget_right = widget->allocation.x + widget->allocation.width - border_width - 2;
! 
!       if (draw_rect.x + draw_rect.width >= widget_right)
! 	{
! 	  draw_rect.width = clip_rect.width = widget_right - draw_rect.x;
! 	}
!     }
!   if (gap_side == GTK_POS_BOTTOM)
!     {
!       int widget_right;
! 
!       if (state_type == GTK_STATE_NORMAL)
! 	{
! 	  draw_rect.x = x;
! 	  draw_rect.y = y;
! 	  draw_rect.width = width + 2;
! 	  draw_rect.height = height;
! 
! 	  clip_rect = draw_rect;
! 	}
!       else
! 	{
! 	  draw_rect.x = x + 2;
! 	  draw_rect.y = y + 2;
! 	  draw_rect.width = width - 2;
! 	  draw_rect.height = height - 2;
! 	  clip_rect = draw_rect;
! 	}
! 
!       /* If we are currently drawing the right-most tab, and if that tab is the selected tab... */
!       widget_right = widget->allocation.x + widget->allocation.width - border_width - 2;
! 
!       if (draw_rect.x + draw_rect.width >= widget_right)
! 	{
! 	  draw_rect.width = clip_rect.width = widget_right - draw_rect.x;
! 	}
! 
!       rotation = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
      }
!   else if (gap_side == GTK_POS_LEFT)
!     {
!       int widget_bottom;
! 
!       if (state_type == GTK_STATE_NORMAL)
! 	{
! 	  draw_rect.x = x;
! 	  draw_rect.y = y;
! 	  draw_rect.width = width;
! 	  draw_rect.height = height + 2;
! 
! 	  clip_rect = draw_rect;
! 	  clip_rect.width--;
! 	}
!       else
! 	{
! 	  draw_rect.x = x;
! 	  draw_rect.y = y + 2;
! 	  draw_rect.width = width - 2;
! 	  draw_rect.height = height - 2;
! 	  clip_rect = draw_rect;
! 	}
! 
!       /* If we are currently drawing the bottom-most tab, and if that tab is the selected tab... */
!       widget_bottom = widget->allocation.x + widget->allocation.height - border_width - 2;
  
!       if (draw_rect.y + draw_rect.height >= widget_bottom)
! 	{
! 	  draw_rect.height = clip_rect.height = widget_bottom - draw_rect.y;
! 	}
  
!       rotation = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
!     }
!   else if (gap_side == GTK_POS_RIGHT)
      {
!       int widget_bottom;
! 
!       if (state_type == GTK_STATE_NORMAL)
! 	{
! 	  draw_rect.x = x + 1;
! 	  draw_rect.y = y;
! 	  draw_rect.width = width;
! 	  draw_rect.height = height + 2;
! 
! 	  clip_rect = draw_rect;
! 	  clip_rect.width--;
! 	}
!       else
! 	{
! 	  draw_rect.x = x + 2;
! 	  draw_rect.y = y + 2;
! 	  draw_rect.width = width - 2;
! 	  draw_rect.height = height - 2;
! 	  clip_rect = draw_rect;
! 	}
! 
!       /* If we are currently drawing the bottom-most tab, and if that tab is the selected tab... */
!       widget_bottom = widget->allocation.x + widget->allocation.height - border_width - 2;
! 
!       if (draw_rect.y + draw_rect.height >= widget_bottom)
! 	{
! 	  draw_rect.height = clip_rect.height = widget_bottom - draw_rect.y;
! 	}
! 
!       rotation = GDK_PIXBUF_ROTATE_CLOCKWISE;
      }
  
!   if (gap_side == GTK_POS_TOP)
      {
!       if (!xp_theme_draw (window, XP_THEME_ELEMENT_TAB_ITEM, style,
! 			  draw_rect.x, draw_rect.y,
! 			  draw_rect.width, draw_rect.height,
! 			  state_type, &clip_rect))
  	{
  	  return FALSE;
  	}
      }
    else
      {
!       GdkPixbuf *pixbuf;
!       GdkPixbuf *rotated;
  
!       if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT)
! 	{
! 	  pixmap = gdk_pixmap_new (window, clip_rect.height, clip_rect.width, -1);
! 
! 	  if (!xp_theme_draw (pixmap, XP_THEME_ELEMENT_TAB_ITEM, style,
! 			      draw_rect.y - clip_rect.y, draw_rect.x - clip_rect.x,
! 			      draw_rect.height, draw_rect.width, state_type, 0))
! 	    {
! 	      g_object_unref (pixmap);
! 	      return FALSE;
! 	    }
! 
! 	  pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
! 						 clip_rect.height, clip_rect.width);
! 	  g_object_unref (pixmap);
! 	}
!       else
  	{
- 	  pixmap = gdk_pixmap_new (window, clip_rect.width, clip_rect.height, -1);
- 
- 	  if (!xp_theme_draw (pixmap, XP_THEME_ELEMENT_TAB_ITEM, style,
- 			      draw_rect.x - clip_rect.x, draw_rect.y - clip_rect.y,
- 			      draw_rect.width, draw_rect.height, state_type, 0))
- 	    {
- 	      g_object_unref (pixmap);
- 	      return FALSE;
- 	    }
- 
- 	  pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
- 						 clip_rect.width, clip_rect.height);
  	  g_object_unref (pixmap);
  	}
  
!       rotated = gdk_pixbuf_rotate_simple (pixbuf, rotation);
!       g_object_unref (pixbuf);
!       pixbuf = rotated;
! 
!       // XXX - This is really hacky and evil.  When we're drawing the left-most tab
!       //       while it is active on a bottom-oriented notebook, there is one white
!       //       pixel at the top.  There may be a better solution than this if someone
!       //       has time to discover it.
!       if (gap_side == GTK_POS_BOTTOM && state_type == GTK_STATE_NORMAL
! 	  && x == widget->allocation.x)
! 	{
! 	  int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
! 	  int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
! 	  int psub = 0;
! 
! 	  guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
! 	  guchar *p = pixels + rowstride;
! 
! 	  for (psub = 0; psub < n_channels; psub++)
! 	    {
! 	      pixels[psub] = p[psub];
! 	    }
! 	}
  
!       cr = gdk_cairo_create (window);
!       gdk_cairo_set_source_pixbuf (cr, pixbuf, clip_rect.x, clip_rect.y);
!       cairo_paint (cr);
!       cairo_destroy (cr);
!       g_object_unref (pixbuf);
!     }
  
    return TRUE;
  }
--- 2418,2532 ----
  			gint width, gint height, gint gap_side)
  {
    GdkPixmap *pixmap = NULL;
    GdkRectangle draw_rect, clip_rect;
    cairo_t *cr;
!   gboolean start, stop;
!   XpThemeElement element;
!   GdkPixbuf *pixbuf;
!   GdkPixbuf *rotated;
! 
!   get_notebook_tab_position (notebook, &start, &stop);
!   if (start && stop) {
!     // Both edges of the notebook are covered by the item
!     element = XP_THEME_ELEMENT_TAB_ITEM_BOTH_EDGES;
!   } else if (start) {
!     // The start edge is covered by the item
!     element = XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE;
!   } else if (stop) {
!     //  the stop edge is reached by the item
!     element = XP_THEME_ELEMENT_TAB_ITEM_RIGHT_EDGE;
!   } else {
!     //  no edge should be aligned with the tab
!     element = XP_THEME_ELEMENT_TAB_ITEM;
!   }
! 
!   if (state_type == GTK_STATE_ACTIVE) {
!     switch (gap_side) {
!     case GTK_POS_TOP:
!       y -= 1;
!       break;
!     case GTK_POS_BOTTOM:
!       y += 1;
!       break;
!     case GTK_POS_LEFT:
!       x -= 1;
!       break;
!     case GTK_POS_RIGHT:
!       x += 1;
!       break;
      }
!   }
  
!   draw_rect.x = x;
!   draw_rect.y = y;
!   draw_rect.width = width;
!   draw_rect.height = height;
!   clip_rect = draw_rect;
  
!   /* Simple case: tabs on top are just drawn as is */
!   if (gap_side == GTK_POS_TOP)
      {
!        return xp_theme_draw
! 	 (window, element, style,
! 	  draw_rect.x, draw_rect.y,
! 	  draw_rect.width, draw_rect.height,
! 	  state_type, &clip_rect);
      }
  
!   if (clip_rect.width <= 0 || clip_rect.height <= 0)
!     return TRUE;
!       
!   if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT)
      {
!       pixmap = gdk_pixmap_new (window, clip_rect.height, clip_rect.width, -1);
!       
!       if (!xp_theme_draw (pixmap, element, style,
! 			  draw_rect.y - clip_rect.y, draw_rect.x - clip_rect.x,
! 			  draw_rect.height, draw_rect.width, state_type, 0))
  	{
+ 	  g_object_unref (pixmap);
  	  return FALSE;
  	}
+ 
+       pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
+ 					     clip_rect.height, clip_rect.width);
+       g_object_unref (pixmap);
      }
    else
      {
!       pixmap = gdk_pixmap_new (window, clip_rect.width, clip_rect.height, -1);
  
!       if (!xp_theme_draw (pixmap, element, style,
! 			  draw_rect.x - clip_rect.x, draw_rect.y - clip_rect.y,
! 			  draw_rect.width, draw_rect.height, state_type, 0))
  	{
  	  g_object_unref (pixmap);
+ 	  return FALSE;
  	}
  
!       pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
! 					     clip_rect.width, clip_rect.height);
!       g_object_unref (pixmap);
!     }
! 
!   if (pixbuf == NULL) return FALSE;
! 
!   if (gap_side == GTK_POS_BOTTOM || gap_side == GTK_POS_LEFT) {
!     rotated = gdk_pixbuf_flip (pixbuf, FALSE);
!     g_object_unref (pixbuf);
!     pixbuf = rotated;
!   }
!   if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT) {
!     rotated = gdk_pixbuf_rotate_simple (pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
!     g_object_unref (pixbuf);
!     pixbuf = rotated;
!   }
  
!   cr = gdk_cairo_create (window);
!   gdk_cairo_set_source_pixbuf (cr, pixbuf, clip_rect.x, clip_rect.y);
!   cairo_paint (cr);
!   cairo_destroy (cr);
!   g_object_unref (pixbuf);
  
    return TRUE;
  }
***************
*** 2670,2709 ****
  	      gint y, gint width, gint height, GtkPositionType gap_side,
  	      gint gap_x, gint gap_width)
  {
!   if (GTK_IS_NOTEBOOK (widget) && detail && !strcmp (detail, "notebook"))
      {
        GtkNotebook *notebook = GTK_NOTEBOOK (widget);
        int side = gtk_notebook_get_tab_pos (notebook);
!       int x2 = x, y2 = y, w2 = width, h2 = height;
  
!       if (side == GTK_POS_TOP)
! 	{
! 	  x2 = x;
! 	  y2 = y - gtk_notebook_get_tab_vborder (notebook);
! 	  w2 = width;
! 	  h2 = height + gtk_notebook_get_tab_vborder (notebook) * 2;
! 	}
!       else if (side == GTK_POS_BOTTOM)
! 	{
! 	  x2 = x;
! 	  y2 = y;
! 	  w2 = width;
! 	  h2 = height + gtk_notebook_get_tab_vborder (notebook) * 2;
! 	}
!       else if (side == GTK_POS_LEFT)
! 	{
! 	  x2 = x - gtk_notebook_get_tab_hborder (notebook);
! 	  y2 = y;
! 	  w2 = width + gtk_notebook_get_tab_hborder (notebook);
! 	  h2 = height;
! 	}
!       else if (side == GTK_POS_RIGHT)
! 	{
! 	  x2 = x;
! 	  y2 = y;
! 	  w2 = width + gtk_notebook_get_tab_hborder (notebook) * 2;
! 	  h2 = height;
! 	}
  
        if (xp_theme_draw (window, XP_THEME_ELEMENT_TAB_PANE, style,
  			 x2, y2, w2, h2, state_type, area))
--- 2627,2656 ----
  	      gint y, gint width, gint height, GtkPositionType gap_side,
  	      gint gap_x, gint gap_width)
  {
!   if (detail && !strcmp (detail, "notebook"))
      {
        GtkNotebook *notebook = GTK_NOTEBOOK (widget);
        int side = gtk_notebook_get_tab_pos (notebook);
!       int x2, y2, w2, h2;
  
!       x2 = x;
!       y2 = y;
!       w2 = width + style->xthickness;
!       h2 = height + style->ythickness;
! 
!       switch (side) {
!       case GTK_POS_TOP:
!         y2 -= 1;
!         break;
!       case GTK_POS_BOTTOM:
!         break;
!       case GTK_POS_LEFT:
!         x2 -= 1;
!         break;
!       case GTK_POS_RIGHT:
!         w2 += 1;
!         break;
!       }
  
        if (xp_theme_draw (window, XP_THEME_ELEMENT_TAB_PANE, style,
  			 x2, y2, w2, h2, state_type, area))
*** modules/engines/ms-windows/xp_theme.c.old	2011-02-19 15:31:37.000000000 +0100
--- modules/engines/ms-windows/xp_theme.c	2011-05-16 00:12:17.436523400 +0200
***************
*** 111,126 ****
  };
  
  static const short element_part_map[XP_THEME_ELEMENT__SIZEOF] = {
!   BP_CHECKBOX,
!   BP_CHECKBOX,
!   BP_CHECKBOX,
!   BP_PUSHBUTTON,
!   HP_HEADERITEM,
    CP_DROPDOWNBUTTON,
    TABP_BODY,
!   TABP_TABITEM,
!   TABP_TABITEMLEFTEDGE,
!   TABP_TABITEMRIGHTEDGE,
    TABP_PANE,
    SBP_THUMBBTNHORZ,
    SBP_THUMBBTNVERT,
--- 111,127 ----
  };
  
  static const short element_part_map[XP_THEME_ELEMENT__SIZEOF] = {
!   BP_CHECKBOX, // PRESSED_CHECKBOX
!   BP_CHECKBOX, // CHECKBOX
!   BP_CHECKBOX, // INCONSISTENT_CHECKBOX
!   BP_PUSHBUTTON, // BUTTON
!   HP_HEADERITEM, // LIST_HEADER
    CP_DROPDOWNBUTTON,
    TABP_BODY,
!   TABP_TABITEM,             // TAB_ITEM
!   TABP_TABITEMLEFTEDGE,     // TAB_ITEM_LEFT_EDGE
!   TABP_TABITEMRIGHTEDGE,    // TAB_ITEM_RIGHT_EDGE
!   TABP_TABITEMBOTHEDGE,     // TAB_ITEM_BOTH_EDGES
    TABP_PANE,
    SBP_THUMBBTNHORZ,
    SBP_THUMBBTNVERT,
***************
*** 408,413 ****
--- 409,415 ----
      case XP_THEME_ELEMENT_TAB_ITEM:
      case XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE:
      case XP_THEME_ELEMENT_TAB_ITEM_RIGHT_EDGE:
+     case XP_THEME_ELEMENT_TAB_ITEM_BOTH_EDGES:
      case XP_THEME_ELEMENT_TAB_PANE:
        klazz = XP_THEME_CLASS_TAB;
        break;
***************
*** 536,541 ****
--- 538,544 ----
  
      case XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE:
      case XP_THEME_ELEMENT_TAB_ITEM_RIGHT_EDGE:
+     case XP_THEME_ELEMENT_TAB_ITEM_BOTH_EDGES:
      case XP_THEME_ELEMENT_TAB_ITEM:
        switch (state)
  	{
*** modules/engines/ms-windows/xp_theme.h.old	2011-02-19 15:31:37.000000000 +0100
--- modules/engines/ms-windows/xp_theme.h	2011-05-16 00:11:54.692382800 +0200
***************
*** 59,64 ****
--- 59,65 ----
    XP_THEME_ELEMENT_TAB_ITEM,
    XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE,
    XP_THEME_ELEMENT_TAB_ITEM_RIGHT_EDGE,
+   XP_THEME_ELEMENT_TAB_ITEM_BOTH_EDGES,
    XP_THEME_ELEMENT_TAB_PANE,
    XP_THEME_ELEMENT_SCROLLBAR_H,
    XP_THEME_ELEMENT_SCROLLBAR_V,
