]> Pileus Git - ~andy/gtk/commitdiff
New function to scroll to a path. (#306838, Jonathan Blandford)
authorMatthias Clasen <mclasen@redhat.com>
Thu, 9 Jun 2005 06:07:57 +0000 (06:07 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 9 Jun 2005 06:07:57 +0000 (06:07 +0000)
2005-06-09  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtkiconview.h:
* gtk/gtkiconview.c (gtk_icon_view_scroll_to_path): New function
to scroll to a path.  (#306838, Jonathan Blandford)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-8
gtk/gtk.symbols
gtk/gtkiconview.c
gtk/gtkiconview.h

index 251b65b72bb849f031f64d0a0fb669eb3998cb07..31ec979889c53b0ca751bf6717571aca6fa04cea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-06-09  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkiconview.h: 
+       * gtk/gtkiconview.c (gtk_icon_view_scroll_to_path): New function
+       to scroll to a path.  (#306838, Jonathan Blandford)
+
 2005-06-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkiconview.c (gtk_icon_view_set_cursor): Scroll to the
index 251b65b72bb849f031f64d0a0fb669eb3998cb07..31ec979889c53b0ca751bf6717571aca6fa04cea 100644 (file)
@@ -1,3 +1,10 @@
+2005-06-09  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkiconview.h: 
+       * gtk/gtkiconview.c (gtk_icon_view_scroll_to_path): New function
+       to scroll to a path.  (#306838, Jonathan Blandford)
+
 2005-06-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkiconview.c (gtk_icon_view_set_cursor): Scroll to the
index 251b65b72bb849f031f64d0a0fb669eb3998cb07..31ec979889c53b0ca751bf6717571aca6fa04cea 100644 (file)
@@ -1,3 +1,10 @@
+2005-06-09  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkiconview.h: 
+       * gtk/gtkiconview.c (gtk_icon_view_scroll_to_path): New function
+       to scroll to a path.  (#306838, Jonathan Blandford)
+
 2005-06-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkiconview.c (gtk_icon_view_set_cursor): Scroll to the
index 3c8ed952a73660c10d4301bd9652cd179f85ebe5..2ae64fa07cac75044343afc43e1db04aa1980643 100644 (file)
@@ -1678,6 +1678,7 @@ gtk_icon_view_item_activated
 gtk_icon_view_new
 gtk_icon_view_new_with_model
 gtk_icon_view_path_is_selected
+gtk_icon_view_scroll_to_path
 gtk_icon_view_select_all
 gtk_icon_view_selected_foreach
 gtk_icon_view_select_path
index 4eae3915d37ce2eb977b0ff3bebef35c8a06eb2b..6ae1aba070bb52ee304c0c864a60bc226ea27f96 100644 (file)
@@ -3881,6 +3881,84 @@ gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
     g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
 }
 
+/**
+ * gtk_icon_view_scroll_to_path:
+ * @icon_view: A #GtkIconView.
+ * @path: The path of the item to move to.
+ * @use_align: whether to use alignment arguments, or %FALSE.
+ * @row_align: The vertical alignment of the item specified by @path.
+ * @col_align: The horizontal alignment of the item specified by @column.
+ *
+ * Moves the alignments of @icon_view to the position specified by @path.  
+ * @row_align determines where the row is placed, and @col_align determines where 
+ * @column is placed.  Both are expected to be between 0.0 and 1.0. 
+ * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
+ *
+ * If @use_align is %FALSE, then the alignment arguments are ignored, and the
+ * tree does the minimum amount of work to scroll the item onto the screen.
+ * This means that the item will be scrolled to the edge closest to its current
+ * position.  If the item is currently visible on the screen, nothing is done.
+ *
+ * This function only works if the model is set, and @path is a valid row on the
+ * model.  If the model changes before the @tree_view is realized, the centered
+ * path will be modified to reflect this change.
+ *
+ * Since: 2.8
+ **/
+void
+gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
+                             GtkTreePath *path,
+                             gboolean     use_align,
+                             gfloat       row_align,
+                             gfloat       col_align)
+{
+  GtkIconViewItem *item;
+
+  g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+  g_return_if_fail (path != NULL);
+  g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
+  g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
+  
+  item = g_list_nth (icon_view->priv->items,
+                    gtk_tree_path_get_indices(path)[0])->data;
+  
+  if (!item)
+    return;
+  
+  if (use_align)
+    {
+      gint x, y, width, height;
+      gint focus_width;
+      gfloat offset, value;
+
+      gtk_widget_style_get (GTK_WIDGET (icon_view),
+                           "focus-line-width", &focus_width,
+                           NULL);
+      
+      gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
+      
+      offset =  y + item->y - focus_width - 
+       row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
+      value = CLAMP (icon_view->priv->vadjustment->value + offset, 
+                    icon_view->priv->vadjustment->lower,
+                    icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
+      gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
+
+      offset = x + item->x - focus_width - 
+       col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
+      value = CLAMP (icon_view->priv->hadjustment->value + offset, 
+                    icon_view->priv->hadjustment->lower,
+                    icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
+      gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
+
+      gtk_adjustment_changed (icon_view->priv->hadjustment);
+      gtk_adjustment_changed (icon_view->priv->vadjustment);
+    }
+  else
+    gtk_icon_view_scroll_to_item (icon_view, item);    
+}
+
+
 static void     
 gtk_icon_view_scroll_to_item (GtkIconView     *icon_view, 
                              GtkIconViewItem *item)
index 7b42b50d69adc5df6b29851f35c56dfc2e8b9324..0929ce694c8485a990293ff94222878ebecd160e 100644 (file)
@@ -154,6 +154,11 @@ void             gtk_icon_view_set_cursor         (GtkIconView            *icon_
 gboolean         gtk_icon_view_get_cursor         (GtkIconView            *icon_view,
                                                   GtkTreePath           **path,
                                                   GtkCellRenderer       **cell);
+void             gtk_icon_view_scroll_to_path     (GtkIconView            *icon_view,
+                                                   GtkTreePath            *path,
+                                                  gboolean                use_align,
+                                                  gfloat                  row_align,
+                                                   gfloat                  col_align);
 
 /* Drag-and-Drop support */
 void                   gtk_icon_view_enable_model_drag_source (GtkIconView              *icon_view,