[gtk+/native-layout] Created _gtk_cell_renderer_calc_offset()



commit c2abe27b03e412f8b6c70b952474d52c6febe58b
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Wed Jun 16 16:52:16 2010 -0400

    Created _gtk_cell_renderer_calc_offset()
    
    Created an internal helper to replace the meaningless 'cell_area',
    'x_offset' and 'y_offset' from gtk_cell_renderer_get_size() which
    will be deprecated in favor of the new h4w api. At this point GTK+
    does no longer depend on renderers calculating this alignment and
    its safe to change the calls to gtk_extended_cell_get_desired_size().

 gtk/gtkcellrenderer.c   |   33 +++++++++++++++++++++++++++++++++
 gtk/gtkcellrenderer.h   |    8 ++++++++
 gtk/gtkiconview.c       |    9 ++++++---
 gtk/gtktreeviewcolumn.c |   17 ++++++++++++-----
 4 files changed, 59 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c
index f4fe476..a6cfb8d 100644
--- a/gtk/gtkcellrenderer.c
+++ b/gtk/gtkcellrenderer.c
@@ -1124,6 +1124,39 @@ gtk_cell_renderer_get_width_for_height (GtkExtendedCell *cell,
   gtk_extended_cell_get_desired_width (cell, widget, minimum_width, natural_width);
 }
 
+/* An internal convenience function for some containers to peek at the
+ * cell alignment in a target allocation (used to draw focus and align
+ * cells in the icon view).
+ *
+ * Note this is only a trivial 'align * (allocation - request)' operation.
+ */
+void
+_gtk_cell_renderer_calc_offset    (GtkCellRenderer      *cell,
+				   GdkRectangle         *cell_area,
+				   GtkTextDirection      direction,
+				   gint                  width,
+				   gint                  height,
+				   gint                 *x_offset,
+				   gint                 *y_offset)
+{
+  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+  g_return_if_fail (cell_area != NULL);
+  g_return_if_fail (x_offset || y_offset);
+
+  if (x_offset)
+    {
+      *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
+		    (1.0 - cell->xalign) : cell->xalign) * 
+		   (cell_area->width - width));
+      *x_offset = MAX (*x_offset, 0);
+    }
+  if (y_offset)
+    {
+      *y_offset = (cell->yalign *
+		   (cell_area->height - height));
+      *y_offset = MAX (*y_offset, 0);
+    }
+}
 
 #define __GTK_CELL_RENDERER_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkcellrenderer.h b/gtk/gtkcellrenderer.h
index d16f3d4..cb5cf07 100644
--- a/gtk/gtkcellrenderer.h
+++ b/gtk/gtkcellrenderer.h
@@ -187,6 +187,14 @@ void             gtk_cell_renderer_stop_editing   (GtkCellRenderer      *cell,
                                                    gboolean              canceled);
 
 
+void            _gtk_cell_renderer_calc_offset    (GtkCellRenderer      *cell,
+						   GdkRectangle         *cell_area,
+						   GtkTextDirection      direction,
+						   gint                  width,
+						   gint                  height,
+						   gint                 *x_offset,
+						   gint                 *y_offset);
+
 G_END_DECLS
 
 #endif /* __GTK_CELL_RENDERER_H__ */
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index b46e660..62e002b 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -3094,10 +3094,13 @@ gtk_icon_view_calculate_item_size2 (GtkIconView     *icon_view,
 	    cell_area.height = max_height[i];
 	  }
 	
-	gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view), 
-				    &cell_area,
-				    &item->box[info->position].x, &item->box[info->position].y,
+	gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view), NULL, NULL, NULL,
 				    &item->box[info->position].width, &item->box[info->position].height);
+
+	_gtk_cell_renderer_calc_offset (info->cell, &cell_area,
+					gtk_widget_get_direction (GTK_WIDGET (icon_view)),
+					item->box[info->position].width, item->box[info->position].height,
+					&item->box[info->position].x, &item->box[info->position].y);
 	
 	item->box[info->position].x += cell_area.x;
 	item->box[info->position].y += cell_area.y;
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index cd40e4b..dcf5959 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -2874,12 +2874,16 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
 	{
 	  gint x_offset, y_offset, width, height;
 
+
 	  gtk_cell_renderer_get_size (info->cell,
 				      tree_column->tree_view,
-				      &rtl_cell_area,
-				      &x_offset, &y_offset,
+				      NULL, NULL, NULL,
 				      &width, &height);
 
+	  _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
+					  gtk_widget_get_direction (tree_column->tree_view),
+					  width, height, &x_offset, &y_offset);
+
 	  if (special_cells > 1)
 	    {
 	      if (info->has_focus)
@@ -3037,14 +3041,17 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
       /* FOCUS */
       else if (action == CELL_ACTION_FOCUS)
 	{
-	  gint x_offset, y_offset, width, height;
+	  gint width, height, x_offset, y_offset;
 
 	  gtk_cell_renderer_get_size (info->cell,
 				      tree_column->tree_view,
-				      &rtl_cell_area,
-				      &x_offset, &y_offset,
+				      NULL, NULL, NULL,
 				      &width, &height);
 
+	  _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
+					  gtk_widget_get_direction (tree_column->tree_view),
+					  width, height, &x_offset, &y_offset);
+
 	  if (special_cells > 1)
 	    {
 	      if (info->has_focus)



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