[gtk+/gtk-style-context: 86/206] GtkNotebook: Set GtkChildClassFlags for tabs.



commit ded2ac774e9f1160426fe59377a9adafa253c6be
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue May 4 20:16:34 2010 +0200

    GtkNotebook: Set GtkChildClassFlags for tabs.

 gtk/gtknotebook.c |   58 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 47 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 44d1c9a..f1b912f 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -405,8 +405,10 @@ static void  gtk_notebook_child_reordered    (GtkNotebook      *notebook,
 static void gtk_notebook_paint               (GtkWidget        *widget,
 					      GdkRectangle     *area);
 static void gtk_notebook_draw_tab            (GtkNotebook      *notebook,
-					      GtkNotebookPage  *page,
-					      GdkRectangle     *area);
+                                              GtkNotebookPage  *page,
+                                              GdkRectangle     *area,
+                                              guint             position,
+                                              gboolean          is_last);
 static void gtk_notebook_draw_arrow          (GtkNotebook      *notebook,
 					      GtkNotebookArrow  arrow);
 
@@ -2261,8 +2263,9 @@ gtk_notebook_expose (GtkWidget      *widget,
       gdk_drawable_get_size (priv->drag_window,
 			     &area.width, &area.height);
       gtk_notebook_draw_tab (notebook,
-			     priv->cur_page,
-			     &area);
+                             priv->cur_page,
+                             &area,
+                             0, FALSE);
       gtk_notebook_draw_focus (widget, event);
       gtk_container_propagate_expose (GTK_CONTAINER (notebook),
 				      priv->cur_page->tab_label, event);
@@ -4809,8 +4812,8 @@ gtk_notebook_paint (GtkWidget    *widget,
   gint x, y;
   guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
   gint gap_x = 0, gap_width = 0, step = STEP_PREV;
-  gboolean is_rtl;
-  gint tab_pos;
+  gboolean is_rtl, cur_page_end;
+  gint tab_pos, i, cur_page_pos;
    
   if (!gtk_widget_is_drawable (widget))
     return;
@@ -4902,6 +4905,8 @@ gtk_notebook_paint (GtkWidget    *widget,
 
   showarrow = FALSE;
   children = gtk_notebook_search_page (notebook, NULL, step, TRUE);
+  i = 0;
+
   while (children)
     {
       page = children->data;
@@ -4911,8 +4916,18 @@ gtk_notebook_paint (GtkWidget    *widget,
 	continue;
       if (!gtk_widget_get_mapped (page->tab_label))
 	showarrow = TRUE;
-      else if (page != priv->cur_page)
-	gtk_notebook_draw_tab (notebook, page, area);
+      else
+        {
+          if (page != priv->cur_page)
+            gtk_notebook_draw_tab (notebook, page, area, i, children != NULL);
+          else
+            {
+              cur_page_pos = i;
+              cur_page_end = (children != NULL);
+            }
+
+          i++;
+        }
     }
 
   if (showarrow && priv->scrollable)
@@ -4926,13 +4941,15 @@ gtk_notebook_paint (GtkWidget    *widget,
       if (priv->has_after_next)
 	gtk_notebook_draw_arrow (notebook, ARROW_RIGHT_AFTER);
     }
-  gtk_notebook_draw_tab (notebook, priv->cur_page, area);
+  gtk_notebook_draw_tab (notebook, priv->cur_page, area, cur_page_pos, cur_page_end);
 }
 
 static void
 gtk_notebook_draw_tab (GtkNotebook     *notebook,
-		       GtkNotebookPage *page,
-		       GdkRectangle    *area)
+                       GtkNotebookPage *page,
+                       GdkRectangle    *area,
+                       guint            position,
+                       gboolean         is_last)
 {
   GtkNotebookPriv *priv;
   GdkRectangle child_area;
@@ -4962,6 +4979,20 @@ gtk_notebook_draw_tab (GtkNotebook     *notebook,
 
   if (gdk_rectangle_intersect (&page_area, area, &child_area))
     {
+      GtkStyleContext *context;
+      GtkChildClassFlags flags = 0;
+
+      if (position % 2 == 0)
+        flags |= GTK_CHILD_CLASS_ODD;
+      else
+        flags |= GTK_CHILD_CLASS_EVEN;
+
+      if (position == 0)
+        flags |= GTK_CHILD_CLASS_FIRST;
+
+      if (is_last)
+        flags |= GTK_CHILD_CLASS_LAST;
+
       gap_side = get_tab_gap_pos (notebook);
 
       if (priv->cur_page == page)
@@ -4969,12 +5000,17 @@ gtk_notebook_draw_tab (GtkNotebook     *notebook,
       else 
 	state_type = GTK_STATE_ACTIVE;
 
+      context = gtk_widget_get_style_context (widget);
+      gtk_style_context_set_child_class (context, "tab", flags);
+
       gtk_paint_extension (widget->style, window,
 			   state_type, GTK_SHADOW_OUT,
 			   area, widget, "tab",
 			   page_area.x, page_area.y,
 			   page_area.width, page_area.height,
 			   gap_side);
+
+      gtk_style_context_unset_child_class (context, "tab");
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]