[gtk+/treeview-refactor] Distribute portions of GtkCellArea:render() background_area argument to cells



commit 7e821aa980d7219741946195be38a99d75407264
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Fri Nov 12 14:06:00 2010 +0900

    Distribute portions of GtkCellArea:render() background_area argument to cells
    
    Also added gtk_cell_area_get/set_style_detail() to set the string to be
    used by the area in gtk_paint_* functions.

 gtk/gtkcellarea.c    |   38 ++++++-
 gtk/gtkcellarea.h    |  327 +++++++++++++++++++++++++-------------------------
 gtk/gtkcellareabox.c |   46 ++++++--
 3 files changed, 236 insertions(+), 175 deletions(-)
---
diff --git a/gtk/gtkcellarea.c b/gtk/gtkcellarea.c
index 0e6a2ee..95eca93 100644
--- a/gtk/gtkcellarea.c
+++ b/gtk/gtkcellarea.c
@@ -161,9 +161,6 @@ struct _GtkCellAreaPrivate
    */
   GHashTable      *cell_info;
 
-  /* Tracking which cells are focus siblings of focusable cells */
-  GHashTable      *focus_siblings;
-
   /* The cell border decides how much space to reserve
    * around each cell for the background_area
    */
@@ -183,6 +180,12 @@ struct _GtkCellAreaPrivate
 
   /* Currently focused cell */
   GtkCellRenderer *focus_cell;
+
+  /* Tracking which cells are focus siblings of focusable cells */
+  GHashTable      *focus_siblings;
+
+  /* Detail string to pass to gtk_paint_*() functions */
+  gchar           *style_detail;
 };
 
 enum {
@@ -1065,6 +1068,35 @@ gtk_cell_area_render (GtkCellArea          *area,
 	       g_type_name (G_TYPE_FROM_INSTANCE (area)));
 }
 
+void
+gtk_cell_area_set_style_detail (GtkCellArea *area,
+				const gchar *detail)
+{
+  GtkCellAreaPrivate *priv;
+
+  g_return_if_fail (GTK_IS_CELL_AREA (area));
+
+  priv = area->priv;
+
+  if (g_strcmp0 (priv->style_detail, detail) != 0)
+    {
+      g_free (priv->style_detail);
+      priv->style_detail = g_strdup (detail);
+    }
+}
+
+G_CONST_RETURN gchar *
+gtk_cell_area_get_style_detail (GtkCellArea *area)
+{
+  GtkCellAreaPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
+
+  priv = area->priv;
+
+  return priv->style_detail;
+}
+
 /*************************************************************
  *                      API: Geometry                        *
  *************************************************************/
diff --git a/gtk/gtkcellarea.h b/gtk/gtkcellarea.h
index 685d695..6688451 100644
--- a/gtk/gtkcellarea.h
+++ b/gtk/gtkcellarea.h
@@ -160,196 +160,199 @@ struct _GtkCellAreaClass
   void (*_gtk_reserved8) (void);
 };
 
-GType              gtk_cell_area_get_type                       (void) G_GNUC_CONST;
+GType                 gtk_cell_area_get_type                       (void) G_GNUC_CONST;
 
 /* Basic methods */
-void               gtk_cell_area_add                            (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer);
-void               gtk_cell_area_remove                         (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer);
-gboolean           gtk_cell_area_has_renderer                   (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer);
-void               gtk_cell_area_forall                         (GtkCellArea          *area,
-								 GtkCellCallback       callback,
-								 gpointer              callback_data);
-void               gtk_cell_area_get_cell_allocation            (GtkCellArea          *area,
-								 GtkCellAreaIter      *iter,
-								 GtkWidget            *widget,
-								 GtkCellRenderer      *renderer,
-								 const GdkRectangle   *cell_area,
-								 GdkRectangle         *allocation);
-gint               gtk_cell_area_event                          (GtkCellArea          *area,
-								 GtkCellAreaIter      *iter,
-								 GtkWidget            *widget,
-								 GdkEvent             *event,
-								 const GdkRectangle   *cell_area,
-								 GtkCellRendererState  flags);
-void               gtk_cell_area_render                         (GtkCellArea          *area,
-								 GtkCellAreaIter      *iter,
-								 GtkWidget            *widget,
-								 cairo_t              *cr,
-								 const GdkRectangle   *background_area,
-								 const GdkRectangle   *cell_area,
-								 GtkCellRendererState  flags,
-								 gboolean              paint_focus);
+void                  gtk_cell_area_add                            (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer);
+void                  gtk_cell_area_remove                         (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer);
+gboolean              gtk_cell_area_has_renderer                   (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer);
+void                  gtk_cell_area_forall                         (GtkCellArea          *area,
+								    GtkCellCallback       callback,
+								    gpointer              callback_data);
+void                  gtk_cell_area_get_cell_allocation            (GtkCellArea          *area,
+								    GtkCellAreaIter      *iter,
+								    GtkWidget            *widget,
+								    GtkCellRenderer      *renderer,
+								    const GdkRectangle   *cell_area,
+								    GdkRectangle         *allocation);
+gint                  gtk_cell_area_event                          (GtkCellArea          *area,
+								    GtkCellAreaIter      *iter,
+								    GtkWidget            *widget,
+								    GdkEvent             *event,
+								    const GdkRectangle   *cell_area,
+								    GtkCellRendererState  flags);
+void                  gtk_cell_area_render                         (GtkCellArea          *area,
+								    GtkCellAreaIter      *iter,
+								    GtkWidget            *widget,
+								    cairo_t              *cr,
+								    const GdkRectangle   *background_area,
+								    const GdkRectangle   *cell_area,
+								    GtkCellRendererState  flags,
+								    gboolean              paint_focus);
+void                  gtk_cell_area_set_style_detail               (GtkCellArea          *area,
+								    const gchar          *detail);
+G_CONST_RETURN gchar *gtk_cell_area_get_style_detail               (GtkCellArea          *area);
 
 /* Geometry */
-GtkCellAreaIter   *gtk_cell_area_create_iter                    (GtkCellArea        *area);
-GtkSizeRequestMode gtk_cell_area_get_request_mode               (GtkCellArea        *area);
-void               gtk_cell_area_get_preferred_width            (GtkCellArea        *area,
-								 GtkCellAreaIter    *iter,
-								 GtkWidget          *widget,
-								 gint               *minimum_size,
-								 gint               *natural_size);
-void               gtk_cell_area_get_preferred_height_for_width (GtkCellArea        *area,
-								 GtkCellAreaIter    *iter,
-								 GtkWidget          *widget,
-								 gint                width,
-								 gint               *minimum_height,
-								 gint               *natural_height);
-void               gtk_cell_area_get_preferred_height           (GtkCellArea        *area,
-								 GtkCellAreaIter    *iter,
-								 GtkWidget          *widget,
-								 gint               *minimum_size,
-								 gint               *natural_size);
-void               gtk_cell_area_get_preferred_width_for_height (GtkCellArea        *area,
-								 GtkCellAreaIter    *iter,
-								 GtkWidget          *widget,
-								 gint                height,
-								 gint               *minimum_width,
-								 gint               *natural_width);
-G_CONST_RETURN gchar *gtk_cell_area_get_current_path_string     (GtkCellArea        *area);
+GtkCellAreaIter      *gtk_cell_area_create_iter                    (GtkCellArea        *area);
+GtkSizeRequestMode    gtk_cell_area_get_request_mode               (GtkCellArea        *area);
+void                  gtk_cell_area_get_preferred_width            (GtkCellArea        *area,
+								    GtkCellAreaIter    *iter,
+								    GtkWidget          *widget,
+								    gint               *minimum_size,
+								    gint               *natural_size);
+void                  gtk_cell_area_get_preferred_height_for_width (GtkCellArea        *area,
+								    GtkCellAreaIter    *iter,
+								    GtkWidget          *widget,
+								    gint                width,
+								    gint               *minimum_height,
+								    gint               *natural_height);
+void                  gtk_cell_area_get_preferred_height           (GtkCellArea        *area,
+								    GtkCellAreaIter    *iter,
+								    GtkWidget          *widget,
+								    gint               *minimum_size,
+								    gint               *natural_size);
+void                  gtk_cell_area_get_preferred_width_for_height (GtkCellArea        *area,
+								    GtkCellAreaIter    *iter,
+								    GtkWidget          *widget,
+								    gint                height,
+								    gint               *minimum_width,
+								    gint               *natural_width);
+G_CONST_RETURN gchar *gtk_cell_area_get_current_path_string        (GtkCellArea        *area);
 
 
 /* Attributes */
-void               gtk_cell_area_apply_attributes               (GtkCellArea        *area,
-								 GtkTreeModel       *tree_model,
-								 GtkTreeIter        *iter,
-								 gboolean            is_expander,
-								 gboolean            is_expanded);
-void               gtk_cell_area_attribute_connect              (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *attribute,
-								 gint                column); 
-void               gtk_cell_area_attribute_disconnect           (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *attribute);
+void                  gtk_cell_area_apply_attributes               (GtkCellArea        *area,
+								    GtkTreeModel       *tree_model,
+								    GtkTreeIter        *iter,
+								    gboolean            is_expander,
+								    gboolean            is_expanded);
+void                  gtk_cell_area_attribute_connect              (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *attribute,
+								    gint                column); 
+void                  gtk_cell_area_attribute_disconnect           (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *attribute);
 
 /* Cell Properties */
-void               gtk_cell_area_class_install_cell_property    (GtkCellAreaClass   *aclass,
-								 guint               property_id,
-								 GParamSpec         *pspec);
-GParamSpec*        gtk_cell_area_class_find_cell_property       (GtkCellAreaClass   *aclass,
-								 const gchar        *property_name);
-GParamSpec**       gtk_cell_area_class_list_cell_properties     (GtkCellAreaClass   *aclass,
-								 guint		    *n_properties);
-void               gtk_cell_area_add_with_properties            (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar	    *first_prop_name,
-								 ...) G_GNUC_NULL_TERMINATED;
-void               gtk_cell_area_cell_set                       (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *first_prop_name,
-								 ...) G_GNUC_NULL_TERMINATED;
-void               gtk_cell_area_cell_get                       (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *first_prop_name,
-								 ...) G_GNUC_NULL_TERMINATED;
-void               gtk_cell_area_cell_set_valist                (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *first_property_name,
-								 va_list             var_args);
-void               gtk_cell_area_cell_get_valist                (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *first_property_name,
-								 va_list             var_args);
-void               gtk_cell_area_cell_set_property              (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *property_name,
-								 const GValue       *value);
-void               gtk_cell_area_cell_get_property              (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 const gchar        *property_name,
-								 GValue             *value);
+void                  gtk_cell_area_class_install_cell_property    (GtkCellAreaClass   *aclass,
+								    guint               property_id,
+								    GParamSpec         *pspec);
+GParamSpec*           gtk_cell_area_class_find_cell_property       (GtkCellAreaClass   *aclass,
+								    const gchar        *property_name);
+GParamSpec**          gtk_cell_area_class_list_cell_properties     (GtkCellAreaClass   *aclass,
+								    guint		    *n_properties);
+void                  gtk_cell_area_add_with_properties            (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar	    *first_prop_name,
+								    ...) G_GNUC_NULL_TERMINATED;
+void                  gtk_cell_area_cell_set                       (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *first_prop_name,
+								    ...) G_GNUC_NULL_TERMINATED;
+void                  gtk_cell_area_cell_get                       (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *first_prop_name,
+								    ...) G_GNUC_NULL_TERMINATED;
+void                  gtk_cell_area_cell_set_valist                (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *first_property_name,
+								    va_list             var_args);
+void                  gtk_cell_area_cell_get_valist                (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *first_property_name,
+								    va_list             var_args);
+void                  gtk_cell_area_cell_set_property              (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *property_name,
+								    const GValue       *value);
+void                  gtk_cell_area_cell_get_property              (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    const gchar        *property_name,
+								    GValue             *value);
 
 #define GTK_CELL_AREA_WARN_INVALID_CHILD_PROPERTY_ID(object, property_id, pspec) \
   G_OBJECT_WARN_INVALID_PSPEC ((object), "cell property id", (property_id), (pspec))
 
 
 /* Focus */
-gboolean           gtk_cell_area_can_focus                      (GtkCellArea         *area);
-gboolean           gtk_cell_area_focus                          (GtkCellArea         *area,
-								 GtkDirectionType     direction);
-gboolean           gtk_cell_area_activate                       (GtkCellArea         *area,
-								 GtkCellAreaIter     *iter,
-								 GtkWidget           *widget,
-								 const GdkRectangle  *cell_area,
-								 GtkCellRendererState flags);
-void               gtk_cell_area_set_focus_cell                 (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer);
-GtkCellRenderer   *gtk_cell_area_get_focus_cell                 (GtkCellArea          *area);
+gboolean              gtk_cell_area_can_focus                      (GtkCellArea         *area);
+gboolean              gtk_cell_area_focus                          (GtkCellArea         *area,
+								    GtkDirectionType     direction);
+gboolean              gtk_cell_area_activate                       (GtkCellArea         *area,
+								    GtkCellAreaIter     *iter,
+								    GtkWidget           *widget,
+								    const GdkRectangle  *cell_area,
+								    GtkCellRendererState flags);
+void                  gtk_cell_area_set_focus_cell                 (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer);
+GtkCellRenderer      *gtk_cell_area_get_focus_cell                 (GtkCellArea          *area);
 
 
 /* Focus siblings */
-void               gtk_cell_area_add_focus_sibling              (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer,
-								 GtkCellRenderer      *sibling);
-void               gtk_cell_area_remove_focus_sibling           (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer,
-								 GtkCellRenderer      *sibling);
-gboolean           gtk_cell_area_is_focus_sibling               (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer,
-								 GtkCellRenderer      *sibling);
-G_CONST_RETURN GList *gtk_cell_area_get_focus_siblings          (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer);
-GtkCellRenderer   *gtk_cell_area_get_focus_from_sibling         (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer);
+void                  gtk_cell_area_add_focus_sibling              (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer,
+								    GtkCellRenderer      *sibling);
+void                  gtk_cell_area_remove_focus_sibling           (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer,
+								    GtkCellRenderer      *sibling);
+gboolean              gtk_cell_area_is_focus_sibling               (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer,
+								    GtkCellRenderer      *sibling);
+G_CONST_RETURN GList *gtk_cell_area_get_focus_siblings             (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer);
+GtkCellRenderer      *gtk_cell_area_get_focus_from_sibling         (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer);
 
 /* Cell Activation/Editing */
-void               gtk_cell_area_set_edited_cell                (GtkCellArea          *area,
-								 GtkCellRenderer      *renderer);
-GtkCellRenderer   *gtk_cell_area_get_edited_cell                (GtkCellArea          *area);
-void               gtk_cell_area_set_edit_widget                (GtkCellArea          *area,
-								 GtkCellEditable      *editable);
-GtkCellEditable   *gtk_cell_area_get_edit_widget                (GtkCellArea          *area);
-gboolean           gtk_cell_area_activate_cell                  (GtkCellArea          *area,
-								 GtkWidget            *widget,
-								 GtkCellRenderer      *renderer,
-								 GdkEvent             *event,
-								 const GdkRectangle   *cell_area,
-								 GtkCellRendererState  flags);
-void               gtk_cell_area_stop_editing                   (GtkCellArea          *area,
-								 gboolean              canceled);
+void                  gtk_cell_area_set_edited_cell                (GtkCellArea          *area,
+								    GtkCellRenderer      *renderer);
+GtkCellRenderer      *gtk_cell_area_get_edited_cell                (GtkCellArea          *area);
+void                  gtk_cell_area_set_edit_widget                (GtkCellArea          *area,
+								    GtkCellEditable      *editable);
+GtkCellEditable      *gtk_cell_area_get_edit_widget                (GtkCellArea          *area);
+gboolean              gtk_cell_area_activate_cell                  (GtkCellArea          *area,
+								    GtkWidget            *widget,
+								    GtkCellRenderer      *renderer,
+								    GdkEvent             *event,
+								    const GdkRectangle   *cell_area,
+								    GtkCellRendererState  flags);
+void                  gtk_cell_area_stop_editing                   (GtkCellArea          *area,
+								    gboolean              canceled);
 
 /* Margins */
-gint               gtk_cell_area_get_cell_margin_left           (GtkCellArea        *area);
-void               gtk_cell_area_set_cell_margin_left           (GtkCellArea        *area,
-								 gint                margin);
-gint               gtk_cell_area_get_cell_margin_right          (GtkCellArea        *area);
-void               gtk_cell_area_set_cell_margin_right          (GtkCellArea        *area,
-								 gint                margin);
-gint               gtk_cell_area_get_cell_margin_top            (GtkCellArea        *area);
-void               gtk_cell_area_set_cell_margin_top            (GtkCellArea        *area,
-								 gint                margin);
-gint               gtk_cell_area_get_cell_margin_bottom         (GtkCellArea        *area);
-void               gtk_cell_area_set_cell_margin_bottom         (GtkCellArea        *area,
-								 gint                margin);
+gint                  gtk_cell_area_get_cell_margin_left           (GtkCellArea        *area);
+void                  gtk_cell_area_set_cell_margin_left           (GtkCellArea        *area,
+								    gint                margin);
+gint                  gtk_cell_area_get_cell_margin_right          (GtkCellArea        *area);
+void                  gtk_cell_area_set_cell_margin_right          (GtkCellArea        *area,
+								    gint                margin);
+gint                  gtk_cell_area_get_cell_margin_top            (GtkCellArea        *area);
+void                  gtk_cell_area_set_cell_margin_top            (GtkCellArea        *area,
+								    gint                margin);
+gint                  gtk_cell_area_get_cell_margin_bottom         (GtkCellArea        *area);
+void                  gtk_cell_area_set_cell_margin_bottom         (GtkCellArea        *area,
+								    gint                margin);
 
 /* Functions for area implementations */
 
 /* Distinguish the inner cell area from the whole requested area including margins */
-void               gtk_cell_area_inner_cell_area                (GtkCellArea        *area,
-								 const GdkRectangle *cell_area,
-								 GdkRectangle       *inner_cell_area);
+void                  gtk_cell_area_inner_cell_area                (GtkCellArea        *area,
+								    const GdkRectangle *cell_area,
+								    GdkRectangle       *inner_cell_area);
 
 /* Request the size of a cell while respecting the cell margins (requests are margin inclusive) */
-void               gtk_cell_area_request_renderer               (GtkCellArea        *area,
-								 GtkCellRenderer    *renderer,
-								 GtkOrientation      orientation,
-								 GtkWidget          *widget,
-								 gint                for_size,
-								 gint               *minimum_size,
-								 gint               *natural_size);
+void                  gtk_cell_area_request_renderer               (GtkCellArea        *area,
+								    GtkCellRenderer    *renderer,
+								    GtkOrientation      orientation,
+								    GtkWidget          *widget,
+								    gint                for_size,
+								    gint               *minimum_size,
+								    gint               *natural_size);
 
 G_END_DECLS
 
diff --git a/gtk/gtkcellareabox.c b/gtk/gtkcellareabox.c
index 0b0f23c..7fbcf9b 100644
--- a/gtk/gtkcellareabox.c
+++ b/gtk/gtkcellareabox.c
@@ -1041,8 +1041,38 @@ gtk_cell_area_box_render (GtkCellArea          *area,
        */
       gtk_cell_area_inner_cell_area (area, &cell_background, &inner_area);
 
-      /* XXX TODO Here after getting the inner area of the cell background,
+      /* Here after getting the inner area of the cell background,
        * add portions of the background area to the cell background */
+      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+	{
+	  if (l == allocated_cells)
+	    {
+	      cell_background.width += cell_background.x - background_area->x;
+	      cell_background.x      = background_area->x;
+	    }
+
+	  if (l->next == NULL)
+	      cell_background.width = 
+		background_area->width - (cell_background.x - background_area->x);
+
+	  cell_background.y      = background_area->y;
+	  cell_background.height = background_area->height;
+	}
+      else
+	{
+	  if (l == allocated_cells)
+	    {
+	      cell_background.height += cell_background.y - background_area->y;
+	      cell_background.y       = background_area->y;
+	    }
+
+	  if (l->next == NULL)
+	      cell_background.height = 
+		background_area->height - (cell_background.y - background_area->y);
+
+	  cell_background.x     = background_area->x;
+	  cell_background.width = background_area->width;
+	}
 
       if (focus_cell && 
 	  (cell->renderer == focus_cell || 
@@ -1108,15 +1138,11 @@ gtk_cell_area_box_render (GtkCellArea          *area,
 	(flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
 	 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
 
-      gtk_paint_focus (gtk_widget_get_style (widget),
-		       cr, renderer_state,
-		       widget,
-		       /* XXX This hint should be a property on GtkCellArea I suppose */
-		       "treeview",
-		       focus_rect.x,
-		       focus_rect.y,
-		       focus_rect.width,
-		       focus_rect.height);
+      gtk_paint_focus (gtk_widget_get_style (widget), cr, 
+		       renderer_state, widget,
+		       gtk_cell_area_get_style_detail (area),
+		       focus_rect.x,     focus_rect.y,
+		       focus_rect.width, focus_rect.height);
     }
 
 



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