diff --git modules/engines/ms-windows/msw_style.c modules/engines/ms-windows/msw_style.c
index 38bc1e6..b060de2 100644
--- modules/engines/ms-windows/msw_style.c
+++ modules/engines/ms-windows/msw_style.c
@@ -41,7 +41,7 @@
 #include <string.h>
 #include <stdio.h>
 
-#include "gtk/gtk.h"
+#include "gdk/gdk.h"
 #include "gtk/gtk.h"
 
 #ifdef BUILDING_STANDALONE
@@ -2347,6 +2347,68 @@ DrawTab (HDC hdc, const RECT R, gint32 aPosition, gboolean aSelected,
     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,221 +2418,126 @@ draw_themed_tab_button (GtkStyle *style,
 			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;
+  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_EDGE;
+  } 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;
     }
-  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;
+  draw_rect.x = x;
+  draw_rect.y = y;
+  draw_rect.width = width;
+  draw_rect.height = height;
+  clip_rect = draw_rect;
 
-	  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)
+  /* Take care of obvious case where the cliping is an empty region */
+  if (clip_rect.width <= 0 || clip_rect.height <= 0)
+    return TRUE;
+      
+  /* Simple case: tabs on top are just drawn as is */
+  if (gap_side == GTK_POS_TOP)
     {
-      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;
+       return xp_theme_draw
+	 (window, element, style,
+	  draw_rect.x, draw_rect.y,
+	  draw_rect.width, draw_rect.height,
+	  state_type, &clip_rect);
     }
 
-  if (gap_side == GTK_POS_TOP)
+  /* For other cases, we need to print the tab on a pixmap, and then rotate
+     it according to the gap side */
+  if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT)
     {
-      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))
+      /* pixmap will have width/height inverted as we'll rotate +- PI / 2 */
+      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
     {
-      GdkPixbuf *pixbuf;
-      GdkPixbuf *rotated;
+      pixmap = gdk_pixmap_new (window, clip_rect.width, clip_rect.height, -1);
 
-      if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT)
+      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))
 	{
-	  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);
+	  return FALSE;
 	}
 
-      rotated = gdk_pixbuf_rotate_simple (pixbuf, rotation);
-      g_object_unref (pixbuf);
-      pixbuf = rotated;
+      pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL, 0, 0, 0, 0,
+					     clip_rect.width, clip_rect.height);
+      g_object_unref (pixmap);
+    }
 
-      // 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;
+  if (pixbuf == NULL) return FALSE;
 
-	  guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
-	  guchar *p = pixels + rowstride;
+  /* At this point, we have a pixbuf with the tab printed on it. Let's rotate
+     it and then print it on screen */
 
-	  for (psub = 0; psub < n_channels; psub++)
-	    {
-	      pixels[psub] = p[psub];
-	    }
-	}
+  /* The following transformations are performed:
+     BOTTOM: just flip horizontally
+     LEFT: flip horizontaly, then rotate clockwise
+     RIGHT: rotate clockwise */
+  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);
-    }
+  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;
 }
@@ -2676,36 +2643,22 @@ draw_box_gap (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
     {
       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;
-	}
+      int x2 = x, y2 = y;
+      int 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))
diff --git modules/engines/ms-windows/xp_theme.c modules/engines/ms-windows/xp_theme.c
index bdd4240..48fb594 100644
--- modules/engines/ms-windows/xp_theme.c
+++ modules/engines/ms-windows/xp_theme.c
@@ -121,6 +121,7 @@ static const short element_part_map[XP_THEME_ELEMENT__SIZEOF] = {
   TABP_TABITEM,
   TABP_TABITEMLEFTEDGE,
   TABP_TABITEMRIGHTEDGE,
+  TABP_TABITEMBOTHEDGE,
   TABP_PANE,
   SBP_THUMBBTNHORZ,
   SBP_THUMBBTNVERT,
@@ -408,6 +409,7 @@ xp_theme_get_handle_by_element (XpThemeElement element)
     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_EDGE:
     case XP_THEME_ELEMENT_TAB_PANE:
       klazz = XP_THEME_CLASS_TAB;
       break;
@@ -536,6 +538,7 @@ xp_theme_map_gtk_state (XpThemeElement element, GtkStateType state)
 
     case XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE:
     case XP_THEME_ELEMENT_TAB_ITEM_RIGHT_EDGE:
+    case XP_THEME_ELEMENT_TAB_ITEM_BOTH_EDGE:
     case XP_THEME_ELEMENT_TAB_ITEM:
       switch (state)
 	{
diff --git modules/engines/ms-windows/xp_theme.h modules/engines/ms-windows/xp_theme.h
index dfacb43..33a56b3 100644
--- modules/engines/ms-windows/xp_theme.h
+++ modules/engines/ms-windows/xp_theme.h
@@ -59,6 +59,7 @@ typedef enum
   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_EDGE,
   XP_THEME_ELEMENT_TAB_PANE,
   XP_THEME_ELEMENT_SCROLLBAR_H,
   XP_THEME_ELEMENT_SCROLLBAR_V,

