]> Pileus Git - ~andy/gtk/commitdiff
Add gtk_icon_view_get_cell_area
authorAlexander Larsson <alexl@redhat.com>
Tue, 19 Jun 2012 16:58:13 +0000 (18:58 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 22 Jun 2012 17:50:33 +0000 (13:50 -0400)
This gets the current cell area of a particular item. Its similar
to gtk_tree_view_get_cell_area().

The code is extracted from gtk_icon_view_set_tooltip_cell which now
just calls the old code.

https://bugzilla.gnome.org/show_bug.cgi?id=678418

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkiconview.c
gtk/gtkiconview.h

index cf2399b0da2dc59433dbfda7fa53bf023e46c449..a80d569f6b4415c1c97d3518a3b8ade83f4da7b0 100644 (file)
@@ -1741,6 +1741,7 @@ gtk_icon_view_set_margin
 gtk_icon_view_get_margin
 gtk_icon_view_set_item_padding
 gtk_icon_view_get_item_padding
+gtk_icon_view_get_cell_area
 gtk_icon_view_select_path
 gtk_icon_view_unselect_path
 gtk_icon_view_path_is_selected
index 0247de8fa830987d74129361cc805633f2ec026a..7a86608761f3bcd278b8603be8c9ef7e73b772c1 100644 (file)
@@ -1293,6 +1293,7 @@ gtk_icon_view_create_drag_icon
 gtk_icon_view_drop_position_get_type
 gtk_icon_view_enable_model_drag_dest
 gtk_icon_view_enable_model_drag_source
+gtk_icon_view_get_cell_area
 gtk_icon_view_get_columns
 gtk_icon_view_get_column_spacing
 gtk_icon_view_get_cursor
index d838331dd76bc2c473f8c74fde87c117fc2c9c7c..2d33fe443e463776757f4eb37df293d8a8f2730e 100644 (file)
@@ -4450,6 +4450,69 @@ gtk_icon_view_get_item_at_pos (GtkIconView      *icon_view,
   return (item != NULL);
 }
 
+/**
+ * gtk_icon_view_get_cell_area:
+ * @icon_view: a #GtkIconView
+ * @path: a #GtkTreePath
+ * @cell: (allow-none): a #GtkCellRenderer or %NULL
+ * @rect: (out): rectangle to fill with cell rect
+ *
+ * Fills the bounding rectangle in widget coordinates for the cell specified by
+ * @path and @cell. If @cell is %NULL the main cell area is used.
+ *
+ * This function is only valid if @icon_view is realized.
+ *
+ * Return value: %FALSE if there is no such item, %TRUE otherwise
+ *
+ * Since: 3.6
+ */
+gboolean
+gtk_icon_view_get_cell_area (GtkIconView     *icon_view,
+                             GtkTreePath     *path,
+                             GtkCellRenderer *cell,
+                             GdkRectangle    *rect)
+{
+  GtkIconViewItem *item = NULL;
+  gint x, y;
+
+  g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
+  g_return_val_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell), FALSE);
+
+  if (gtk_tree_path_get_depth (path) > 0)
+    item = g_list_nth_data (icon_view->priv->items,
+                           gtk_tree_path_get_indices(path)[0]);
+
+  if (!item)
+    return FALSE;
+
+  if (cell)
+    {
+      GtkCellAreaContext *context;
+
+      context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
+      _gtk_icon_view_set_cell_data (icon_view, item);
+      gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
+                                        GTK_WIDGET (icon_view),
+                                        cell, &item->cell_area, rect);
+    }
+  else
+    {
+      rect->x = item->cell_area.x - icon_view->priv->item_padding;
+      rect->y = item->cell_area.y - icon_view->priv->item_padding;
+      rect->width  = item->cell_area.width  + icon_view->priv->item_padding * 2;
+      rect->height = item->cell_area.height + icon_view->priv->item_padding * 2;
+    }
+
+  if (icon_view->priv->bin_window)
+    {
+      gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
+      rect->x += x;
+      rect->y += y;
+    }
+
+  return TRUE;
+}
+
 /**
  * gtk_icon_view_set_tooltip_item:
  * @icon_view: a #GtkIconView
@@ -4494,46 +4557,15 @@ gtk_icon_view_set_tooltip_cell (GtkIconView     *icon_view,
                                 GtkCellRenderer *cell)
 {
   GdkRectangle rect;
-  GtkIconViewItem *item = NULL;
-  gint x, y;
+
   g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
   g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
   g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
 
-  if (gtk_tree_path_get_depth (path) > 0)
-    item = g_list_nth_data (icon_view->priv->items,
-                            gtk_tree_path_get_indices(path)[0]);
-  if (!item)
+  if (!gtk_icon_view_get_cell_area (icon_view, path, cell, &rect))
     return;
 
-  if (cell)
-    {
-      GtkCellAreaContext *context;
-
-      context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
-      _gtk_icon_view_set_cell_data (icon_view, item);
-      gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
-                                        GTK_WIDGET (icon_view),
-                                        cell, &item->cell_area, &rect);
-    }
-  else
-    {
-      rect.x = item->cell_area.x - icon_view->priv->item_padding;
-      rect.y = item->cell_area.y - icon_view->priv->item_padding;
-      rect.width  = item->cell_area.width  + icon_view->priv->item_padding * 2;
-      rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
-    }
-  
-  if (icon_view->priv->bin_window)
-    {
-      gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
-      rect.x += x;
-      rect.y += y; 
-    }
-
-  gtk_tooltip_set_tip_area (tooltip, &rect); 
+  gtk_tooltip_set_tip_area (tooltip, &rect);
 }
 
 
index 6e9f6c49639a62692017900567fdbde5eb0d8e99..469e9ffa8167b8f92f1b8ccde0cd68a08b5d3908 100644 (file)
@@ -235,6 +235,11 @@ void    gtk_icon_view_convert_widget_to_bin_window_coords     (GtkIconView *icon
                                                                gint         wy,
                                                                gint        *bx,
                                                                gint        *by);
+GDK_AVAILABLE_IN_3_6
+gboolean gtk_icon_view_get_cell_area                          (GtkIconView     *icon_view,
+                                                              GtkTreePath     *path,
+                                                              GtkCellRenderer *cell,
+                                                              GdkRectangle    *rect);
 
 
 void    gtk_icon_view_set_tooltip_item                        (GtkIconView     *icon_view,