2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 #include "gtkiconview.h"
23 #include "gtkiconviewprivate.h"
25 #include "gtkadjustment.h"
26 #include "gtkcelllayout.h"
27 #include "gtkcellrenderer.h"
28 #include "gtkcellareabox.h"
29 #include "gtkcellareacontext.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkorientable.h"
33 #include "gtkmarshalers.h"
34 #include "gtkbindings.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtkscrollable.h"
43 #include "gtksizerequest.h"
44 #include "gtktreednd.h"
45 #include "gtktypebuiltins.h"
46 #include "gtkprivate.h"
47 #include "a11y/gtkiconviewaccessibleprivate.h"
52 * @short_description: A widget which displays a list of icons in a grid
54 * #GtkIconView provides an alternative view on a #GtkTreeModel.
55 * It displays the model as a grid of icons with labels. Like
56 * #GtkTreeView, it allows to select one or multiple items
57 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
58 * In addition to selection with the arrow keys, #GtkIconView supports
59 * rubberband selection, which is controlled by dragging the pointer.
61 * Note that if the tree model is backed by an actual tree store (as
62 * opposed to a flat list where the mapping to icons is obvious),
63 * #GtkIconView will only display the first level of the tree and
64 * ignore the tree's branches.
67 #define SCROLL_EDGE_SIZE 15
69 typedef struct _GtkIconViewChild GtkIconViewChild;
70 struct _GtkIconViewChild
98 PROP_ITEM_ORIENTATION,
111 /* For scrollable interface */
119 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
120 static void gtk_icon_view_dispose (GObject *object);
121 static GObject *gtk_icon_view_constructor (GType type,
122 guint n_construct_properties,
123 GObjectConstructParam *construct_properties);
124 static void gtk_icon_view_set_property (GObject *object,
128 static void gtk_icon_view_get_property (GObject *object,
132 /* GtkWidget vfuncs */
133 static void gtk_icon_view_destroy (GtkWidget *widget);
134 static void gtk_icon_view_realize (GtkWidget *widget);
135 static void gtk_icon_view_unrealize (GtkWidget *widget);
136 static GtkSizeRequestMode gtk_icon_view_get_request_mode (GtkWidget *widget);
137 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
140 static void gtk_icon_view_get_preferred_width_for_height
145 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
148 static void gtk_icon_view_get_preferred_height_for_width
153 static void gtk_icon_view_size_allocate (GtkWidget *widget,
154 GtkAllocation *allocation);
155 static gboolean gtk_icon_view_draw (GtkWidget *widget,
157 static gboolean gtk_icon_view_motion (GtkWidget *widget,
158 GdkEventMotion *event);
159 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
160 GdkEventButton *event);
161 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
162 GdkEventButton *event);
163 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
165 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
169 /* GtkContainer vfuncs */
170 static void gtk_icon_view_remove (GtkContainer *container,
172 static void gtk_icon_view_forall (GtkContainer *container,
173 gboolean include_internals,
174 GtkCallback callback,
175 gpointer callback_data);
177 /* GtkIconView vfuncs */
178 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
179 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
180 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
181 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
182 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
184 /* Internal functions */
185 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
186 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
187 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
188 GtkAdjustment *adjustment);
189 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
190 GtkAdjustment *adjustment);
191 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
192 GtkIconView *icon_view);
193 static void gtk_icon_view_layout (GtkIconView *icon_view);
194 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
196 GtkIconViewItem *item,
199 gboolean draw_focus);
200 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
202 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
204 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
205 GtkIconViewItem *item);
206 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
210 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
211 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
212 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
213 GtkIconViewItem *item,
218 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
219 static void gtk_icon_view_update_rubberband (gpointer data);
220 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
221 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
222 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
225 GtkMovementStep step,
227 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
228 GtkMovementStep step,
230 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
232 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
234 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
236 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
238 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
239 GtkIconViewItem *item);
240 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
241 GtkIconViewItem *anchor,
242 GtkIconViewItem *cursor);
244 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
245 GtkCellArea *cell_area);
247 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
249 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
250 GtkIconViewItem *item);
252 static void gtk_icon_view_add_editable (GtkCellArea *area,
253 GtkCellRenderer *renderer,
254 GtkCellEditable *editable,
255 GdkRectangle *cell_area,
257 GtkIconView *icon_view);
258 static void gtk_icon_view_remove_editable (GtkCellArea *area,
259 GtkCellRenderer *renderer,
260 GtkCellEditable *editable,
261 GtkIconView *icon_view);
262 static void update_text_cell (GtkIconView *icon_view);
263 static void update_pixbuf_cell (GtkIconView *icon_view);
265 /* Source side drag signals */
266 static void gtk_icon_view_drag_begin (GtkWidget *widget,
267 GdkDragContext *context);
268 static void gtk_icon_view_drag_end (GtkWidget *widget,
269 GdkDragContext *context);
270 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
271 GdkDragContext *context,
272 GtkSelectionData *selection_data,
275 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
276 GdkDragContext *context);
278 /* Target side drag signals */
279 static void gtk_icon_view_drag_leave (GtkWidget *widget,
280 GdkDragContext *context,
282 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
283 GdkDragContext *context,
287 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
288 GdkDragContext *context,
292 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
293 GdkDragContext *context,
296 GtkSelectionData *selection_data,
299 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
300 GdkEventMotion *event);
302 static void remove_scroll_timeout (GtkIconView *icon_view);
305 static GtkBuildableIface *parent_buildable_iface;
306 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
307 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
310 const gchar *tagname,
311 GMarkupParser *parser,
313 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
316 const gchar *tagname,
319 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
321 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
322 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
323 gtk_icon_view_cell_layout_init)
324 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
325 gtk_icon_view_buildable_init)
326 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
329 gtk_icon_view_class_init (GtkIconViewClass *klass)
331 GObjectClass *gobject_class;
332 GtkWidgetClass *widget_class;
333 GtkContainerClass *container_class;
334 GtkBindingSet *binding_set;
336 binding_set = gtk_binding_set_by_class (klass);
338 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
340 gobject_class = (GObjectClass *) klass;
341 widget_class = (GtkWidgetClass *) klass;
342 container_class = (GtkContainerClass *) klass;
344 gobject_class->constructor = gtk_icon_view_constructor;
345 gobject_class->dispose = gtk_icon_view_dispose;
346 gobject_class->set_property = gtk_icon_view_set_property;
347 gobject_class->get_property = gtk_icon_view_get_property;
349 widget_class->destroy = gtk_icon_view_destroy;
350 widget_class->realize = gtk_icon_view_realize;
351 widget_class->unrealize = gtk_icon_view_unrealize;
352 widget_class->get_request_mode = gtk_icon_view_get_request_mode;
353 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
354 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
355 widget_class->get_preferred_width_for_height = gtk_icon_view_get_preferred_width_for_height;
356 widget_class->get_preferred_height_for_width = gtk_icon_view_get_preferred_height_for_width;
357 widget_class->size_allocate = gtk_icon_view_size_allocate;
358 widget_class->draw = gtk_icon_view_draw;
359 widget_class->motion_notify_event = gtk_icon_view_motion;
360 widget_class->button_press_event = gtk_icon_view_button_press;
361 widget_class->button_release_event = gtk_icon_view_button_release;
362 widget_class->key_press_event = gtk_icon_view_key_press;
363 widget_class->key_release_event = gtk_icon_view_key_release;
364 widget_class->drag_begin = gtk_icon_view_drag_begin;
365 widget_class->drag_end = gtk_icon_view_drag_end;
366 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
367 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
368 widget_class->drag_leave = gtk_icon_view_drag_leave;
369 widget_class->drag_motion = gtk_icon_view_drag_motion;
370 widget_class->drag_drop = gtk_icon_view_drag_drop;
371 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
373 container_class->remove = gtk_icon_view_remove;
374 container_class->forall = gtk_icon_view_forall;
376 klass->select_all = gtk_icon_view_real_select_all;
377 klass->unselect_all = gtk_icon_view_real_unselect_all;
378 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
379 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
380 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
381 klass->move_cursor = gtk_icon_view_real_move_cursor;
385 * GtkIconView:selection-mode:
387 * The ::selection-mode property specifies the selection mode of
388 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
389 * is enabled, for the other modes, only keyboard selection is possible.
393 g_object_class_install_property (gobject_class,
395 g_param_spec_enum ("selection-mode",
396 P_("Selection mode"),
397 P_("The selection mode"),
398 GTK_TYPE_SELECTION_MODE,
399 GTK_SELECTION_SINGLE,
400 GTK_PARAM_READWRITE));
403 * GtkIconView:pixbuf-column:
405 * The ::pixbuf-column property contains the number of the model column
406 * containing the pixbufs which are displayed. The pixbuf column must be
407 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
408 * display of pixbufs.
412 g_object_class_install_property (gobject_class,
414 g_param_spec_int ("pixbuf-column",
416 P_("Model column used to retrieve the icon pixbuf from"),
418 GTK_PARAM_READWRITE));
421 * GtkIconView:text-column:
423 * The ::text-column property contains the number of the model column
424 * containing the texts which are displayed. The text column must be
425 * of type #G_TYPE_STRING. If this property and the :markup-column
426 * property are both set to -1, no texts are displayed.
430 g_object_class_install_property (gobject_class,
432 g_param_spec_int ("text-column",
434 P_("Model column used to retrieve the text from"),
436 GTK_PARAM_READWRITE));
440 * GtkIconView:markup-column:
442 * The ::markup-column property contains the number of the model column
443 * containing markup information to be displayed. The markup column must be
444 * of type #G_TYPE_STRING. If this property and the :text-column property
445 * are both set to column numbers, it overrides the text column.
446 * If both are set to -1, no texts are displayed.
450 g_object_class_install_property (gobject_class,
452 g_param_spec_int ("markup-column",
454 P_("Model column used to retrieve the text if using Pango markup"),
456 GTK_PARAM_READWRITE));
458 g_object_class_install_property (gobject_class,
460 g_param_spec_object ("model",
461 P_("Icon View Model"),
462 P_("The model for the icon view"),
464 GTK_PARAM_READWRITE));
467 * GtkIconView:columns:
469 * The columns property contains the number of the columns in which the
470 * items should be displayed. If it is -1, the number of columns will
471 * be chosen automatically to fill the available area.
475 g_object_class_install_property (gobject_class,
477 g_param_spec_int ("columns",
478 P_("Number of columns"),
479 P_("Number of columns to display"),
481 GTK_PARAM_READWRITE));
485 * GtkIconView:item-width:
487 * The item-width property specifies the width to use for each item.
488 * If it is set to -1, the icon view will automatically determine a
489 * suitable item size.
493 g_object_class_install_property (gobject_class,
495 g_param_spec_int ("item-width",
496 P_("Width for each item"),
497 P_("The width used for each item"),
499 GTK_PARAM_READWRITE));
502 * GtkIconView:spacing:
504 * The spacing property specifies the space which is inserted between
505 * the cells (i.e. the icon and the text) of an item.
509 g_object_class_install_property (gobject_class,
511 g_param_spec_int ("spacing",
513 P_("Space which is inserted between cells of an item"),
515 GTK_PARAM_READWRITE));
518 * GtkIconView:row-spacing:
520 * The row-spacing property specifies the space which is inserted between
521 * the rows of the icon view.
525 g_object_class_install_property (gobject_class,
527 g_param_spec_int ("row-spacing",
529 P_("Space which is inserted between grid rows"),
531 GTK_PARAM_READWRITE));
534 * GtkIconView:column-spacing:
536 * The column-spacing property specifies the space which is inserted between
537 * the columns of the icon view.
541 g_object_class_install_property (gobject_class,
543 g_param_spec_int ("column-spacing",
544 P_("Column Spacing"),
545 P_("Space which is inserted between grid columns"),
547 GTK_PARAM_READWRITE));
550 * GtkIconView:margin:
552 * The margin property specifies the space which is inserted
553 * at the edges of the icon view.
557 g_object_class_install_property (gobject_class,
559 g_param_spec_int ("margin",
561 P_("Space which is inserted at the edges of the icon view"),
563 GTK_PARAM_READWRITE));
566 * GtkIconView:item-orientation:
568 * The item-orientation property specifies how the cells (i.e. the icon and
569 * the text) of the item are positioned relative to each other.
573 g_object_class_install_property (gobject_class,
574 PROP_ITEM_ORIENTATION,
575 g_param_spec_enum ("item-orientation",
576 P_("Item Orientation"),
577 P_("How the text and icon of each item are positioned relative to each other"),
578 GTK_TYPE_ORIENTATION,
579 GTK_ORIENTATION_VERTICAL,
580 GTK_PARAM_READWRITE));
583 * GtkIconView:reorderable:
585 * The reorderable property specifies if the items can be reordered
590 g_object_class_install_property (gobject_class,
592 g_param_spec_boolean ("reorderable",
594 P_("View is reorderable"),
598 g_object_class_install_property (gobject_class,
600 g_param_spec_int ("tooltip-column",
601 P_("Tooltip Column"),
602 P_("The column in the model containing the tooltip texts for the items"),
606 GTK_PARAM_READWRITE));
609 * GtkIconView:item-padding:
611 * The item-padding property specifies the padding around each
612 * of the icon view's item.
616 g_object_class_install_property (gobject_class,
618 g_param_spec_int ("item-padding",
620 P_("Padding around icon view items"),
622 GTK_PARAM_READWRITE));
625 * GtkIconView:cell-area:
627 * The #GtkCellArea used to layout cell renderers for this view.
629 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
630 * a #GtkCellAreaBox will be used.
634 g_object_class_install_property (gobject_class,
636 g_param_spec_object ("cell-area",
638 P_("The GtkCellArea used to layout cells"),
640 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
642 /* Scrollable interface properties */
643 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
644 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
645 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
646 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
648 /* Style properties */
649 gtk_widget_class_install_style_property (widget_class,
650 g_param_spec_boxed ("selection-box-color",
651 P_("Selection Box Color"),
652 P_("Color of the selection box"),
654 GTK_PARAM_READABLE));
656 gtk_widget_class_install_style_property (widget_class,
657 g_param_spec_uchar ("selection-box-alpha",
658 P_("Selection Box Alpha"),
659 P_("Opacity of the selection box"),
662 GTK_PARAM_READABLE));
666 * GtkIconView::item-activated:
667 * @iconview: the object on which the signal is emitted
668 * @path: the #GtkTreePath for the activated item
670 * The ::item-activated signal is emitted when the method
671 * gtk_icon_view_item_activated() is called or the user double
672 * clicks an item. It is also emitted when a non-editable item
673 * is selected and one of the keys: Space, Return or Enter is
676 icon_view_signals[ITEM_ACTIVATED] =
677 g_signal_new (I_("item-activated"),
678 G_TYPE_FROM_CLASS (gobject_class),
680 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
682 g_cclosure_marshal_VOID__BOXED,
687 * GtkIconView::selection-changed:
688 * @iconview: the object on which the signal is emitted
690 * The ::selection-changed signal is emitted when the selection
691 * (i.e. the set of selected items) changes.
693 icon_view_signals[SELECTION_CHANGED] =
694 g_signal_new (I_("selection-changed"),
695 G_TYPE_FROM_CLASS (gobject_class),
697 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
699 g_cclosure_marshal_VOID__VOID,
703 * GtkIconView::select-all:
704 * @iconview: the object on which the signal is emitted
706 * A <link linkend="keybinding-signals">keybinding signal</link>
707 * which gets emitted when the user selects all items.
709 * Applications should not connect to it, but may emit it with
710 * g_signal_emit_by_name() if they need to control selection
713 * The default binding for this signal is Ctrl-a.
715 icon_view_signals[SELECT_ALL] =
716 g_signal_new (I_("select-all"),
717 G_TYPE_FROM_CLASS (gobject_class),
718 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
719 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
721 g_cclosure_marshal_VOID__VOID,
725 * GtkIconView::unselect-all:
726 * @iconview: the object on which the signal is emitted
728 * A <link linkend="keybinding-signals">keybinding signal</link>
729 * which gets emitted when the user unselects all items.
731 * Applications should not connect to it, but may emit it with
732 * g_signal_emit_by_name() if they need to control selection
735 * The default binding for this signal is Ctrl-Shift-a.
737 icon_view_signals[UNSELECT_ALL] =
738 g_signal_new (I_("unselect-all"),
739 G_TYPE_FROM_CLASS (gobject_class),
740 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
741 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
743 g_cclosure_marshal_VOID__VOID,
747 * GtkIconView::select-cursor-item:
748 * @iconview: the object on which the signal is emitted
750 * A <link linkend="keybinding-signals">keybinding signal</link>
751 * which gets emitted when the user selects the item that is currently
754 * Applications should not connect to it, but may emit it with
755 * g_signal_emit_by_name() if they need to control selection
758 * There is no default binding for this signal.
760 icon_view_signals[SELECT_CURSOR_ITEM] =
761 g_signal_new (I_("select-cursor-item"),
762 G_TYPE_FROM_CLASS (gobject_class),
763 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
764 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
766 g_cclosure_marshal_VOID__VOID,
770 * GtkIconView::toggle-cursor-item:
771 * @iconview: the object on which the signal is emitted
773 * A <link linkend="keybinding-signals">keybinding signal</link>
774 * which gets emitted when the user toggles whether the currently
775 * focused item is selected or not. The exact effect of this
776 * depend on the selection mode.
778 * Applications should not connect to it, but may emit it with
779 * g_signal_emit_by_name() if they need to control selection
782 * There is no default binding for this signal is Ctrl-Space.
784 icon_view_signals[TOGGLE_CURSOR_ITEM] =
785 g_signal_new (I_("toggle-cursor-item"),
786 G_TYPE_FROM_CLASS (gobject_class),
787 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
788 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
790 g_cclosure_marshal_VOID__VOID,
794 * GtkIconView::activate-cursor-item:
795 * @iconview: the object on which the signal is emitted
797 * A <link linkend="keybinding-signals">keybinding signal</link>
798 * which gets emitted when the user activates the currently
801 * Applications should not connect to it, but may emit it with
802 * g_signal_emit_by_name() if they need to control activation
805 * The default bindings for this signal are Space, Return and Enter.
807 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
808 g_signal_new (I_("activate-cursor-item"),
809 G_TYPE_FROM_CLASS (gobject_class),
810 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
811 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
813 _gtk_marshal_BOOLEAN__VOID,
817 * GtkIconView::move-cursor:
818 * @iconview: the object which received the signal
819 * @step: the granularity of the move, as a #GtkMovementStep
820 * @count: the number of @step units to move
822 * The ::move-cursor signal is a
823 * <link linkend="keybinding-signals">keybinding signal</link>
824 * which gets emitted when the user initiates a cursor movement.
826 * Applications should not connect to it, but may emit it with
827 * g_signal_emit_by_name() if they need to control the cursor
830 * The default bindings for this signal include
832 * <listitem>Arrow keys which move by individual steps</listitem>
833 * <listitem>Home/End keys which move to the first/last item</listitem>
834 * <listitem>PageUp/PageDown which move by "pages"</listitem>
837 * All of these will extend the selection when combined with
838 * the Shift modifier.
840 icon_view_signals[MOVE_CURSOR] =
841 g_signal_new (I_("move-cursor"),
842 G_TYPE_FROM_CLASS (gobject_class),
843 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
844 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
846 _gtk_marshal_BOOLEAN__ENUM_INT,
848 GTK_TYPE_MOVEMENT_STEP,
852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
854 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
857 "toggle-cursor-item", 0);
858 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
859 "toggle-cursor-item", 0);
861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
862 "activate-cursor-item", 0);
863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
864 "activate-cursor-item", 0);
865 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
866 "activate-cursor-item", 0);
867 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
868 "activate-cursor-item", 0);
869 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
870 "activate-cursor-item", 0);
872 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
873 GTK_MOVEMENT_DISPLAY_LINES, -1);
874 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
875 GTK_MOVEMENT_DISPLAY_LINES, -1);
877 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
878 GTK_MOVEMENT_DISPLAY_LINES, 1);
879 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
880 GTK_MOVEMENT_DISPLAY_LINES, 1);
882 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
883 GTK_MOVEMENT_DISPLAY_LINES, -1);
885 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
886 GTK_MOVEMENT_DISPLAY_LINES, 1);
888 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
889 GTK_MOVEMENT_BUFFER_ENDS, -1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
891 GTK_MOVEMENT_BUFFER_ENDS, -1);
893 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
894 GTK_MOVEMENT_BUFFER_ENDS, 1);
895 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
896 GTK_MOVEMENT_BUFFER_ENDS, 1);
898 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
899 GTK_MOVEMENT_PAGES, -1);
900 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
901 GTK_MOVEMENT_PAGES, -1);
903 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
904 GTK_MOVEMENT_PAGES, 1);
905 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
906 GTK_MOVEMENT_PAGES, 1);
908 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
909 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
910 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
911 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
913 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
914 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
915 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
916 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
918 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
922 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
924 parent_buildable_iface = g_type_interface_peek_parent (iface);
925 iface->add_child = _gtk_cell_layout_buildable_add_child;
926 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
927 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
931 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
933 iface->get_area = gtk_icon_view_cell_layout_get_area;
937 gtk_icon_view_init (GtkIconView *icon_view)
939 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
943 icon_view->priv->width = 0;
944 icon_view->priv->height = 0;
945 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
946 icon_view->priv->pressed_button = -1;
947 icon_view->priv->press_start_x = -1;
948 icon_view->priv->press_start_y = -1;
949 icon_view->priv->text_column = -1;
950 icon_view->priv->markup_column = -1;
951 icon_view->priv->pixbuf_column = -1;
952 icon_view->priv->text_cell = NULL;
953 icon_view->priv->pixbuf_cell = NULL;
954 icon_view->priv->tooltip_column = -1;
956 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
958 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
960 icon_view->priv->columns = -1;
961 icon_view->priv->item_width = -1;
962 icon_view->priv->spacing = 0;
963 icon_view->priv->row_spacing = 6;
964 icon_view->priv->column_spacing = 6;
965 icon_view->priv->margin = 6;
966 icon_view->priv->item_padding = 6;
968 icon_view->priv->draw_focus = TRUE;
970 icon_view->priv->row_contexts =
971 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
973 gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (icon_view)),
974 GTK_STYLE_CLASS_VIEW);
977 /* GObject methods */
979 gtk_icon_view_constructor (GType type,
980 guint n_construct_properties,
981 GObjectConstructParam *construct_properties)
983 GtkIconView *icon_view;
986 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
987 (type, n_construct_properties, construct_properties);
989 icon_view = (GtkIconView *) object;
991 gtk_icon_view_ensure_cell_area (icon_view, NULL);
997 gtk_icon_view_dispose (GObject *object)
999 GtkIconView *icon_view;
1000 GtkIconViewPrivate *priv;
1002 icon_view = GTK_ICON_VIEW (object);
1003 priv = icon_view->priv;
1005 if (priv->cell_area_context)
1007 g_object_unref (priv->cell_area_context);
1008 priv->cell_area_context = NULL;
1011 if (priv->row_contexts)
1013 g_ptr_array_free (priv->row_contexts, TRUE);
1014 priv->row_contexts = NULL;
1017 if (priv->cell_area)
1019 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1021 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1022 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1023 priv->add_editable_id = 0;
1024 priv->remove_editable_id = 0;
1026 g_object_unref (priv->cell_area);
1027 priv->cell_area = NULL;
1030 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1034 gtk_icon_view_set_property (GObject *object,
1036 const GValue *value,
1039 GtkIconView *icon_view;
1042 icon_view = GTK_ICON_VIEW (object);
1046 case PROP_SELECTION_MODE:
1047 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1049 case PROP_PIXBUF_COLUMN:
1050 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1052 case PROP_TEXT_COLUMN:
1053 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1055 case PROP_MARKUP_COLUMN:
1056 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1059 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1061 case PROP_ITEM_ORIENTATION:
1062 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1065 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1067 case PROP_ITEM_WIDTH:
1068 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1071 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1073 case PROP_ROW_SPACING:
1074 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1076 case PROP_COLUMN_SPACING:
1077 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1080 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1082 case PROP_REORDERABLE:
1083 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1086 case PROP_TOOLTIP_COLUMN:
1087 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1090 case PROP_ITEM_PADDING:
1091 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1094 case PROP_CELL_AREA:
1095 /* Construct-only, can only be assigned once */
1096 area = g_value_get_object (value);
1099 if (icon_view->priv->cell_area != NULL)
1101 g_warning ("cell-area has already been set, ignoring construct property");
1102 g_object_ref_sink (area);
1103 g_object_unref (area);
1106 gtk_icon_view_ensure_cell_area (icon_view, area);
1110 case PROP_HADJUSTMENT:
1111 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1113 case PROP_VADJUSTMENT:
1114 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1116 case PROP_HSCROLL_POLICY:
1117 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1118 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1120 case PROP_VSCROLL_POLICY:
1121 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1122 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1132 gtk_icon_view_get_property (GObject *object,
1137 GtkIconView *icon_view;
1139 icon_view = GTK_ICON_VIEW (object);
1143 case PROP_SELECTION_MODE:
1144 g_value_set_enum (value, icon_view->priv->selection_mode);
1146 case PROP_PIXBUF_COLUMN:
1147 g_value_set_int (value, icon_view->priv->pixbuf_column);
1149 case PROP_TEXT_COLUMN:
1150 g_value_set_int (value, icon_view->priv->text_column);
1152 case PROP_MARKUP_COLUMN:
1153 g_value_set_int (value, icon_view->priv->markup_column);
1156 g_value_set_object (value, icon_view->priv->model);
1158 case PROP_ITEM_ORIENTATION:
1159 g_value_set_enum (value, icon_view->priv->item_orientation);
1162 g_value_set_int (value, icon_view->priv->columns);
1164 case PROP_ITEM_WIDTH:
1165 g_value_set_int (value, icon_view->priv->item_width);
1168 g_value_set_int (value, icon_view->priv->spacing);
1170 case PROP_ROW_SPACING:
1171 g_value_set_int (value, icon_view->priv->row_spacing);
1173 case PROP_COLUMN_SPACING:
1174 g_value_set_int (value, icon_view->priv->column_spacing);
1177 g_value_set_int (value, icon_view->priv->margin);
1179 case PROP_REORDERABLE:
1180 g_value_set_boolean (value, icon_view->priv->reorderable);
1182 case PROP_TOOLTIP_COLUMN:
1183 g_value_set_int (value, icon_view->priv->tooltip_column);
1186 case PROP_ITEM_PADDING:
1187 g_value_set_int (value, icon_view->priv->item_padding);
1190 case PROP_CELL_AREA:
1191 g_value_set_object (value, icon_view->priv->cell_area);
1194 case PROP_HADJUSTMENT:
1195 g_value_set_object (value, icon_view->priv->hadjustment);
1197 case PROP_VADJUSTMENT:
1198 g_value_set_object (value, icon_view->priv->vadjustment);
1200 case PROP_HSCROLL_POLICY:
1201 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1203 case PROP_VSCROLL_POLICY:
1204 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1208 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1213 /* GtkWidget methods */
1215 gtk_icon_view_destroy (GtkWidget *widget)
1217 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1219 gtk_icon_view_set_model (icon_view, NULL);
1221 if (icon_view->priv->scroll_to_path != NULL)
1223 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1224 icon_view->priv->scroll_to_path = NULL;
1227 remove_scroll_timeout (icon_view);
1229 if (icon_view->priv->hadjustment != NULL)
1231 g_object_unref (icon_view->priv->hadjustment);
1232 icon_view->priv->hadjustment = NULL;
1235 if (icon_view->priv->vadjustment != NULL)
1237 g_object_unref (icon_view->priv->vadjustment);
1238 icon_view->priv->vadjustment = NULL;
1241 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1245 gtk_icon_view_realize (GtkWidget *widget)
1247 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1248 GtkAllocation allocation;
1250 GdkWindowAttr attributes;
1251 gint attributes_mask;
1253 gtk_widget_set_realized (widget, TRUE);
1255 gtk_widget_get_allocation (widget, &allocation);
1257 /* Make the main, clipping window */
1258 attributes.window_type = GDK_WINDOW_CHILD;
1259 attributes.x = allocation.x;
1260 attributes.y = allocation.y;
1261 attributes.width = allocation.width;
1262 attributes.height = allocation.height;
1263 attributes.wclass = GDK_INPUT_OUTPUT;
1264 attributes.visual = gtk_widget_get_visual (widget);
1265 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1267 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1269 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1270 &attributes, attributes_mask);
1271 gtk_widget_set_window (widget, window);
1272 gdk_window_set_user_data (window, widget);
1274 gtk_widget_get_allocation (widget, &allocation);
1276 /* Make the window for the icon view */
1279 attributes.width = MAX (icon_view->priv->width, allocation.width);
1280 attributes.height = MAX (icon_view->priv->height, allocation.height);
1281 attributes.event_mask = (GDK_EXPOSURE_MASK |
1283 GDK_SMOOTH_SCROLL_MASK |
1284 GDK_POINTER_MOTION_MASK |
1285 GDK_BUTTON_PRESS_MASK |
1286 GDK_BUTTON_RELEASE_MASK |
1287 GDK_KEY_PRESS_MASK |
1288 GDK_KEY_RELEASE_MASK) |
1289 gtk_widget_get_events (widget);
1291 icon_view->priv->bin_window = gdk_window_new (window,
1292 &attributes, attributes_mask);
1293 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1294 gdk_window_show (icon_view->priv->bin_window);
1298 gtk_icon_view_unrealize (GtkWidget *widget)
1300 GtkIconView *icon_view;
1302 icon_view = GTK_ICON_VIEW (widget);
1304 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1305 gdk_window_destroy (icon_view->priv->bin_window);
1306 icon_view->priv->bin_window = NULL;
1308 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1312 gtk_icon_view_get_n_items (GtkIconView *icon_view)
1314 GtkIconViewPrivate *priv = icon_view->priv;
1316 if (priv->model == NULL)
1319 return gtk_tree_model_iter_n_children (priv->model, NULL);
1323 adjust_wrap_width (GtkIconView *icon_view)
1325 if (icon_view->priv->text_cell)
1327 gint wrap_width = 50;
1329 /* Here we go with the same old guess, try the icon size and set double
1330 * the size of the first icon found in the list, naive but works much
1332 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
1334 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
1335 GTK_WIDGET (icon_view),
1338 wrap_width = MAX (wrap_width * 2, 50);
1341 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
1342 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
1346 /* General notes about layout
1348 * The icon view is layouted like this:
1350 * +----------+ s +----------+
1351 * | padding | p | padding |
1352 * | +------+ | a | +------+ |
1353 * | | cell | | c | | cell | |
1354 * | +------+ | i | +------+ |
1356 * +----------+ g +----------+
1358 * In size request and allocation code, there are 3 sizes that are used:
1360 * This is the size returned by gtk_cell_area_get_preferred_foo(). In places
1361 * where code is interacting with the cell area and renderers this is useful.
1363 * This is the cell size plus the item padding on each side.
1365 * This is the padded size plus the spacing. This is what's used for most
1366 * calculations because it can (ab)use the following formula:
1367 * iconview_size = 2 * margin + n_items * spaced_size - spacing
1368 * So when reading this code and fixing my bugs where I confuse these two, be
1369 * aware of this distinction.
1372 cell_area_get_preferred_size (GtkIconView *icon_view,
1373 GtkCellAreaContext *context,
1374 GtkOrientation orientation,
1379 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1382 gtk_cell_area_get_preferred_width_for_height (icon_view->priv->cell_area,
1384 GTK_WIDGET (icon_view),
1388 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
1390 GTK_WIDGET (icon_view),
1396 gtk_cell_area_get_preferred_height_for_width (icon_view->priv->cell_area,
1398 GTK_WIDGET (icon_view),
1402 gtk_cell_area_get_preferred_height (icon_view->priv->cell_area,
1404 GTK_WIDGET (icon_view),
1410 gtk_icon_view_is_empty (GtkIconView *icon_view)
1412 return icon_view->priv->items == NULL;
1416 gtk_icon_view_get_preferred_item_size (GtkIconView *icon_view,
1417 GtkOrientation orientation,
1422 GtkIconViewPrivate *priv = icon_view->priv;
1423 GtkCellAreaContext *context;
1426 g_assert (!gtk_icon_view_is_empty (icon_view));
1428 context = gtk_cell_area_create_context (priv->cell_area);
1430 for_size -= 2 * priv->item_padding;
1434 /* This is necessary for the context to work properly */
1435 for (items = priv->items; items; items = items->next)
1437 GtkIconViewItem *item = items->data;
1439 _gtk_icon_view_set_cell_data (icon_view, item);
1440 cell_area_get_preferred_size (icon_view, context, 1 - orientation, -1, NULL, NULL);
1444 for (items = priv->items; items; items = items->next)
1446 GtkIconViewItem *item = items->data;
1448 _gtk_icon_view_set_cell_data (icon_view, item);
1449 if (items == priv->items)
1450 adjust_wrap_width (icon_view);
1451 cell_area_get_preferred_size (icon_view, context, orientation, for_size, NULL, NULL);
1454 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1457 gtk_cell_area_context_get_preferred_width_for_height (context,
1461 gtk_cell_area_context_get_preferred_width (context,
1467 gtk_cell_area_context_get_preferred_height_for_width (context,
1471 gtk_cell_area_context_get_preferred_height (context,
1475 if (orientation == GTK_ORIENTATION_HORIZONTAL && priv->item_width >= 0)
1478 *minimum = MAX (*minimum, priv->item_width);
1480 *natural = *minimum;
1484 *minimum = MAX (1, *minimum + 2 * priv->item_padding);
1486 *natural = MAX (1, *natural + 2 * priv->item_padding);
1488 g_object_unref (context);
1492 gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
1493 GtkOrientation orientation,
1496 gint *min_item_size,
1498 gint *max_item_size)
1500 GtkIconViewPrivate *priv = icon_view->priv;
1501 int minimum, natural, spacing;
1503 g_return_if_fail (min_item_size == NULL || min_items != NULL);
1504 g_return_if_fail (max_item_size == NULL || max_items != NULL);
1505 g_return_if_fail (!gtk_icon_view_is_empty (icon_view));
1507 gtk_icon_view_get_preferred_item_size (icon_view, orientation, -1, &minimum, &natural);
1509 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1510 spacing = priv->column_spacing;
1512 spacing = priv->row_spacing;
1514 size -= 2 * priv->margin;
1519 if (priv->columns > 0)
1521 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1524 *min_items = priv->columns;
1526 *max_items = priv->columns;
1530 int n_items = gtk_icon_view_get_n_items (icon_view);
1533 *min_items = (n_items + priv->columns - 1) / priv->columns;
1535 *max_items = (n_items + priv->columns - 1) / priv->columns;
1542 if (size <= minimum)
1545 *max_items = size / minimum;
1550 if (size <= natural)
1553 *min_items = size / natural;
1559 *min_item_size = size / *min_items;
1560 *min_item_size = CLAMP (*min_item_size, minimum, natural);
1561 *min_item_size -= spacing;
1562 *min_item_size -= 2 * priv->item_padding;
1567 *max_item_size = size / *max_items;
1568 *max_item_size = CLAMP (*max_item_size, minimum, natural);
1569 *max_item_size -= spacing;
1570 *max_item_size -= 2 * priv->item_padding;
1574 static GtkSizeRequestMode
1575 gtk_icon_view_get_request_mode (GtkWidget *widget)
1577 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1581 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1585 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1586 GtkIconViewPrivate *priv = icon_view->priv;
1587 int item_min, item_nat;
1589 if (gtk_icon_view_is_empty (icon_view))
1591 *minimum = *natural = 2 * priv->margin;
1595 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_min, &item_nat);
1597 if (priv->columns > 0)
1599 *minimum = item_min * priv->columns + priv->column_spacing * (priv->columns - 1);
1600 *natural = item_nat * priv->columns + priv->column_spacing * (priv->columns - 1);
1604 int n_items = gtk_icon_view_get_n_items (icon_view);
1606 *minimum = item_min;
1607 *natural = item_nat * n_items + priv->column_spacing * (n_items - 1);
1610 *minimum += 2 * priv->margin;
1611 *natural += 2 * priv->margin;
1615 gtk_icon_view_get_preferred_width_for_height (GtkWidget *widget,
1620 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1621 GtkIconViewPrivate *priv = icon_view->priv;
1622 int item_min, item_nat, rows, row_height, n_items;
1624 if (gtk_icon_view_is_empty (icon_view))
1626 *minimum = *natural = 2 * priv->margin;
1630 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_VERTICAL, height, &rows, &row_height, NULL, NULL);
1631 n_items = gtk_icon_view_get_n_items (icon_view);
1633 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, row_height, &item_min, &item_nat);
1634 *minimum = (item_min + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1635 *natural = (item_nat + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1637 *minimum += 2 * priv->margin;
1638 *natural += 2 * priv->margin;
1642 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1646 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1647 GtkIconViewPrivate *priv = icon_view->priv;
1648 int item_min, item_nat, n_items;
1650 if (gtk_icon_view_is_empty (icon_view))
1652 *minimum = *natural = 2 * priv->margin;
1656 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, -1, &item_min, &item_nat);
1657 n_items = gtk_icon_view_get_n_items (icon_view);
1659 if (priv->columns > 0)
1661 int n_rows = (n_items + priv->columns - 1) / priv->columns;
1663 *minimum = item_min * n_rows + priv->row_spacing * (n_rows - 1);
1664 *natural = item_nat * n_rows + priv->row_spacing * (n_rows - 1);
1668 *minimum = item_min;
1669 *natural = item_nat * n_items + priv->row_spacing * (n_items - 1);
1672 *minimum += 2 * priv->margin;
1673 *natural += 2 * priv->margin;
1677 gtk_icon_view_get_preferred_height_for_width (GtkWidget *widget,
1682 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1683 GtkIconViewPrivate *priv = icon_view->priv;
1684 int item_min, item_nat, columns, column_width, n_items;
1686 if (gtk_icon_view_is_empty (icon_view))
1688 *minimum = *natural = 2 * priv->margin;
1692 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_HORIZONTAL, width, NULL, NULL, &columns, &column_width);
1693 n_items = gtk_icon_view_get_n_items (icon_view);
1695 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, column_width, &item_min, &item_nat);
1696 *minimum = (item_min + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1697 *natural = (item_nat + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1699 *minimum += 2 * priv->margin;
1700 *natural += 2 * priv->margin;
1704 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1708 for (list = icon_view->priv->children; list; list = list->next)
1710 GtkIconViewChild *child = list->data;
1712 /* totally ignore our child's requisition */
1713 gtk_widget_size_allocate (child->widget, &child->area);
1718 gtk_icon_view_size_allocate (GtkWidget *widget,
1719 GtkAllocation *allocation)
1721 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1723 gtk_widget_set_allocation (widget, allocation);
1725 gtk_icon_view_layout (icon_view);
1727 if (gtk_widget_get_realized (widget))
1729 gdk_window_move_resize (gtk_widget_get_window (widget),
1730 allocation->x, allocation->y,
1731 allocation->width, allocation->height);
1732 gdk_window_resize (icon_view->priv->bin_window,
1733 MAX (icon_view->priv->width, allocation->width),
1734 MAX (icon_view->priv->height, allocation->height));
1737 gtk_icon_view_allocate_children (icon_view);
1739 /* Delay signal emission */
1740 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1741 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1743 gtk_icon_view_set_hadjustment_values (icon_view);
1744 gtk_icon_view_set_vadjustment_values (icon_view);
1746 if (gtk_widget_get_realized (widget) &&
1747 icon_view->priv->scroll_to_path)
1750 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1751 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1752 icon_view->priv->scroll_to_path = NULL;
1754 gtk_icon_view_scroll_to_path (icon_view, path,
1755 icon_view->priv->scroll_to_use_align,
1756 icon_view->priv->scroll_to_row_align,
1757 icon_view->priv->scroll_to_col_align);
1758 gtk_tree_path_free (path);
1761 /* Emit any pending signals now */
1762 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1763 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1767 gtk_icon_view_draw (GtkWidget *widget,
1770 GtkIconView *icon_view;
1774 GtkIconViewDropPosition dest_pos;
1775 GtkIconViewItem *dest_item = NULL;
1776 GtkStyleContext *context;
1778 icon_view = GTK_ICON_VIEW (widget);
1780 context = gtk_widget_get_style_context (widget);
1781 gtk_render_background (context, cr,
1783 gtk_widget_get_allocated_width (widget),
1784 gtk_widget_get_allocated_height (widget));
1786 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1791 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1793 cairo_set_line_width (cr, 1.);
1795 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1799 dest_index = gtk_tree_path_get_indices (path)[0];
1800 gtk_tree_path_free (path);
1805 for (icons = icon_view->priv->items; icons; icons = icons->next)
1807 GtkIconViewItem *item = icons->data;
1808 GdkRectangle paint_area;
1810 paint_area.x = item->cell_area.x - icon_view->priv->item_padding;
1811 paint_area.y = item->cell_area.y - icon_view->priv->item_padding;
1812 paint_area.width = item->cell_area.width + icon_view->priv->item_padding * 2;
1813 paint_area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
1817 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1820 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1822 gtk_icon_view_paint_item (icon_view, cr, item,
1823 item->cell_area.x, item->cell_area.y,
1824 icon_view->priv->draw_focus);
1826 if (dest_index == item->index)
1834 dest_pos != GTK_ICON_VIEW_NO_DROP)
1836 GtkStyleContext *context;
1837 GdkRectangle rect = { 0 };
1839 context = gtk_widget_get_style_context (widget);
1843 case GTK_ICON_VIEW_DROP_INTO:
1844 rect = dest_item->cell_area;
1846 case GTK_ICON_VIEW_DROP_ABOVE:
1847 rect.x = dest_item->cell_area.x;
1848 rect.y = dest_item->cell_area.y - 1;
1849 rect.width = dest_item->cell_area.width;
1852 case GTK_ICON_VIEW_DROP_LEFT:
1853 rect.x = dest_item->cell_area.x - 1;
1854 rect.y = dest_item->cell_area.y;
1856 rect.height = dest_item->cell_area.height;
1858 case GTK_ICON_VIEW_DROP_BELOW:
1859 rect.x = dest_item->cell_area.x;
1860 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1861 rect.width = dest_item->cell_area.width;
1864 case GTK_ICON_VIEW_DROP_RIGHT:
1865 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1866 rect.y = dest_item->cell_area.y;
1868 rect.height = dest_item->cell_area.height;
1869 case GTK_ICON_VIEW_NO_DROP: ;
1873 gtk_render_focus (context, cr,
1875 rect.width, rect.height);
1878 if (icon_view->priv->doing_rubberband)
1879 gtk_icon_view_paint_rubberband (icon_view, cr);
1883 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1887 rubberband_scroll_timeout (gpointer data)
1889 GtkIconView *icon_view = data;
1891 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1892 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1893 icon_view->priv->scroll_value_diff);
1895 gtk_icon_view_update_rubberband (icon_view);
1901 gtk_icon_view_motion (GtkWidget *widget,
1902 GdkEventMotion *event)
1904 GtkAllocation allocation;
1905 GtkIconView *icon_view;
1908 icon_view = GTK_ICON_VIEW (widget);
1910 gtk_icon_view_maybe_begin_drag (icon_view, event);
1912 if (icon_view->priv->doing_rubberband)
1914 gtk_icon_view_update_rubberband (widget);
1916 abs_y = event->y - icon_view->priv->height *
1917 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1918 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1919 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1921 gtk_widget_get_allocation (widget, &allocation);
1923 if (abs_y < 0 || abs_y > allocation.height)
1926 icon_view->priv->scroll_value_diff = abs_y;
1928 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1930 icon_view->priv->event_last_x = event->x;
1931 icon_view->priv->event_last_y = event->y;
1933 if (icon_view->priv->scroll_timeout_id == 0)
1934 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1938 remove_scroll_timeout (icon_view);
1942 GtkIconViewItem *item, *last_prelight_item;
1943 GtkCellRenderer *cell = NULL;
1945 last_prelight_item = icon_view->priv->last_prelight;
1946 item = _gtk_icon_view_get_item_at_coords (icon_view,
1953 item->prelight = TRUE;
1954 gtk_icon_view_queue_draw_item (icon_view, item);
1957 if (last_prelight_item != NULL &&
1958 last_prelight_item != item)
1960 last_prelight_item->prelight = FALSE;
1961 gtk_icon_view_queue_draw_item (icon_view,
1962 icon_view->priv->last_prelight);
1965 icon_view->priv->last_prelight = item;
1972 gtk_icon_view_remove (GtkContainer *container,
1975 GtkIconView *icon_view;
1976 GtkIconViewChild *child = NULL;
1979 icon_view = GTK_ICON_VIEW (container);
1981 tmp_list = icon_view->priv->children;
1984 child = tmp_list->data;
1985 if (child->widget == widget)
1987 gtk_widget_unparent (widget);
1989 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1990 g_list_free_1 (tmp_list);
1995 tmp_list = tmp_list->next;
2000 gtk_icon_view_forall (GtkContainer *container,
2001 gboolean include_internals,
2002 GtkCallback callback,
2003 gpointer callback_data)
2005 GtkIconView *icon_view;
2006 GtkIconViewChild *child = NULL;
2009 icon_view = GTK_ICON_VIEW (container);
2011 tmp_list = icon_view->priv->children;
2014 child = tmp_list->data;
2015 tmp_list = tmp_list->next;
2017 (* callback) (child->widget, callback_data);
2022 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
2023 GtkIconViewItem *item)
2026 AtkObject *item_obj;
2028 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2031 item_obj = atk_object_ref_accessible_child (obj, item->index);
2032 if (item_obj != NULL)
2034 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
2035 g_object_unref (item_obj);
2041 gtk_icon_view_add_editable (GtkCellArea *area,
2042 GtkCellRenderer *renderer,
2043 GtkCellEditable *editable,
2044 GdkRectangle *cell_area,
2046 GtkIconView *icon_view)
2048 GtkIconViewChild *child;
2049 GtkWidget *widget = GTK_WIDGET (editable);
2051 child = g_new (GtkIconViewChild, 1);
2053 child->widget = widget;
2054 child->area.x = cell_area->x;
2055 child->area.y = cell_area->y;
2056 child->area.width = cell_area->width;
2057 child->area.height = cell_area->height;
2059 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
2061 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2062 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
2064 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
2068 gtk_icon_view_remove_editable (GtkCellArea *area,
2069 GtkCellRenderer *renderer,
2070 GtkCellEditable *editable,
2071 GtkIconView *icon_view)
2075 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
2076 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
2078 gtk_container_remove (GTK_CONTAINER (icon_view),
2079 GTK_WIDGET (editable));
2081 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
2082 gtk_icon_view_queue_draw_path (icon_view, path);
2083 gtk_tree_path_free (path);
2087 * gtk_icon_view_set_cursor:
2088 * @icon_view: A #GtkIconView
2089 * @path: A #GtkTreePath
2090 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2091 * @start_editing: %TRUE if the specified cell should start being edited.
2093 * Sets the current keyboard focus to be at @path, and selects it. This is
2094 * useful when you want to focus the user's attention on a particular item.
2095 * If @cell is not %NULL, then focus is given to the cell specified by
2096 * it. Additionally, if @start_editing is %TRUE, then editing should be
2097 * started in the specified cell.
2099 * This function is often followed by <literal>gtk_widget_grab_focus
2100 * (icon_view)</literal> in order to give keyboard focus to the widget.
2101 * Please note that editing can only happen when the widget is realized.
2106 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2108 GtkCellRenderer *cell,
2109 gboolean start_editing)
2111 GtkIconViewItem *item = NULL;
2113 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2114 g_return_if_fail (path != NULL);
2115 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2117 if (icon_view->priv->cell_area)
2118 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2120 if (gtk_tree_path_get_depth (path) == 1)
2121 item = g_list_nth_data (icon_view->priv->items,
2122 gtk_tree_path_get_indices(path)[0]);
2127 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
2128 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2130 if (start_editing &&
2131 icon_view->priv->cell_area)
2133 GtkCellAreaContext *context;
2135 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2136 _gtk_icon_view_set_cell_data (icon_view, item);
2137 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2138 GTK_WIDGET (icon_view), &item->cell_area,
2139 0 /* XXX flags */, TRUE);
2144 * gtk_icon_view_get_cursor:
2145 * @icon_view: A #GtkIconView
2146 * @path: (out) (allow-none): Return location for the current cursor path,
2148 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
2150 * Fills in @path and @cell with the current cursor path and cell.
2151 * If the cursor isn't currently set, then *@path will be %NULL.
2152 * If no cell currently has focus, then *@cell will be %NULL.
2154 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2156 * Return value: %TRUE if the cursor is set.
2161 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2163 GtkCellRenderer **cell)
2165 GtkIconViewItem *item;
2167 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2169 item = icon_view->priv->cursor_item;
2174 *path = gtk_tree_path_new_from_indices (item->index, -1);
2179 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
2180 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
2182 return (item != NULL);
2186 gtk_icon_view_button_press (GtkWidget *widget,
2187 GdkEventButton *event)
2189 GtkIconView *icon_view;
2190 GtkIconViewItem *item;
2191 gboolean dirty = FALSE;
2192 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2194 icon_view = GTK_ICON_VIEW (widget);
2196 if (event->window != icon_view->priv->bin_window)
2199 if (!gtk_widget_has_focus (widget))
2200 gtk_widget_grab_focus (widget);
2202 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
2204 GdkModifierType extend_mod_mask;
2205 GdkModifierType modify_mod_mask;
2208 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2211 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2213 item = _gtk_icon_view_get_item_at_coords (icon_view,
2219 * We consider only the cells' area as the item area if the
2220 * item is not selected, but if it *is* selected, the complete
2221 * selection rectangle is considered to be part of the item.
2223 if (item != NULL && (cell != NULL || item->selected))
2227 if (gtk_cell_renderer_is_activatable (cell))
2231 gtk_icon_view_scroll_to_item (icon_view, item);
2233 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2235 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2237 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2238 (event->state & extend_mod_mask))
2240 gtk_icon_view_unselect_all_internal (icon_view);
2242 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2243 if (!icon_view->priv->anchor_item)
2244 icon_view->priv->anchor_item = item;
2246 gtk_icon_view_select_all_between (icon_view,
2247 icon_view->priv->anchor_item,
2253 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2254 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2255 (event->state & modify_mod_mask))
2257 item->selected = !item->selected;
2258 gtk_icon_view_queue_draw_item (icon_view, item);
2263 gtk_icon_view_unselect_all_internal (icon_view);
2265 item->selected = TRUE;
2266 gtk_icon_view_queue_draw_item (icon_view, item);
2269 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2270 icon_view->priv->anchor_item = item;
2273 /* Save press to possibly begin a drag */
2274 if (icon_view->priv->pressed_button < 0)
2276 icon_view->priv->pressed_button = event->button;
2277 icon_view->priv->press_start_x = event->x;
2278 icon_view->priv->press_start_y = event->y;
2281 if (!icon_view->priv->last_single_clicked)
2282 icon_view->priv->last_single_clicked = item;
2284 /* cancel the current editing, if it exists */
2285 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2287 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2289 GtkCellAreaContext *context;
2291 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2293 _gtk_icon_view_set_cell_data (icon_view, item);
2294 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2295 GTK_WIDGET (icon_view),
2296 &item->cell_area, 0/* XXX flags */, FALSE);
2301 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2302 !(event->state & modify_mod_mask))
2304 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2307 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2308 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2311 /* don't draw keyboard focus around an clicked-on item */
2312 icon_view->priv->draw_focus = FALSE;
2315 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
2317 item = _gtk_icon_view_get_item_at_coords (icon_view,
2322 if (item && item == icon_view->priv->last_single_clicked)
2326 path = gtk_tree_path_new_from_indices (item->index, -1);
2327 gtk_icon_view_item_activated (icon_view, path);
2328 gtk_tree_path_free (path);
2331 icon_view->priv->last_single_clicked = NULL;
2332 icon_view->priv->pressed_button = -1;
2336 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2338 return event->button == GDK_BUTTON_PRIMARY;
2342 gtk_icon_view_button_release (GtkWidget *widget,
2343 GdkEventButton *event)
2345 GtkIconView *icon_view;
2347 icon_view = GTK_ICON_VIEW (widget);
2349 if (icon_view->priv->pressed_button == event->button)
2350 icon_view->priv->pressed_button = -1;
2352 gtk_icon_view_stop_rubberbanding (icon_view);
2354 remove_scroll_timeout (icon_view);
2360 gtk_icon_view_key_press (GtkWidget *widget,
2363 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2365 if (icon_view->priv->doing_rubberband)
2367 if (event->keyval == GDK_KEY_Escape)
2368 gtk_icon_view_stop_rubberbanding (icon_view);
2373 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2377 gtk_icon_view_key_release (GtkWidget *widget,
2380 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2382 if (icon_view->priv->doing_rubberband)
2385 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2389 gtk_icon_view_update_rubberband (gpointer data)
2391 GtkIconView *icon_view;
2393 GdkRectangle old_area;
2394 GdkRectangle new_area;
2395 GdkRectangle common;
2396 cairo_region_t *invalid_region;
2398 icon_view = GTK_ICON_VIEW (data);
2400 gdk_window_get_device_position (icon_view->priv->bin_window,
2401 icon_view->priv->rubberband_device,
2407 old_area.x = MIN (icon_view->priv->rubberband_x1,
2408 icon_view->priv->rubberband_x2);
2409 old_area.y = MIN (icon_view->priv->rubberband_y1,
2410 icon_view->priv->rubberband_y2);
2411 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2412 icon_view->priv->rubberband_x1) + 1;
2413 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2414 icon_view->priv->rubberband_y1) + 1;
2416 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2417 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2418 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2419 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2421 invalid_region = cairo_region_create_rectangle (&old_area);
2422 cairo_region_union_rectangle (invalid_region, &new_area);
2424 gdk_rectangle_intersect (&old_area, &new_area, &common);
2425 if (common.width > 2 && common.height > 2)
2427 cairo_region_t *common_region;
2429 /* make sure the border is invalidated */
2435 common_region = cairo_region_create_rectangle (&common);
2437 cairo_region_subtract (invalid_region, common_region);
2438 cairo_region_destroy (common_region);
2441 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2443 cairo_region_destroy (invalid_region);
2445 icon_view->priv->rubberband_x2 = x;
2446 icon_view->priv->rubberband_y2 = y;
2448 gtk_icon_view_update_rubberband_selection (icon_view);
2452 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2459 if (icon_view->priv->rubberband_device)
2462 for (items = icon_view->priv->items; items; items = items->next)
2464 GtkIconViewItem *item = items->data;
2466 item->selected_before_rubberbanding = item->selected;
2469 icon_view->priv->rubberband_x1 = x;
2470 icon_view->priv->rubberband_y1 = y;
2471 icon_view->priv->rubberband_x2 = x;
2472 icon_view->priv->rubberband_y2 = y;
2474 icon_view->priv->doing_rubberband = TRUE;
2475 icon_view->priv->rubberband_device = device;
2477 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2481 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2483 if (!icon_view->priv->doing_rubberband)
2486 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2487 icon_view->priv->rubberband_device);
2489 icon_view->priv->doing_rubberband = FALSE;
2490 icon_view->priv->rubberband_device = NULL;
2492 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2496 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2499 gint x, y, width, height;
2500 gboolean dirty = FALSE;
2502 x = MIN (icon_view->priv->rubberband_x1,
2503 icon_view->priv->rubberband_x2);
2504 y = MIN (icon_view->priv->rubberband_y1,
2505 icon_view->priv->rubberband_y2);
2506 width = ABS (icon_view->priv->rubberband_x1 -
2507 icon_view->priv->rubberband_x2);
2508 height = ABS (icon_view->priv->rubberband_y1 -
2509 icon_view->priv->rubberband_y2);
2511 for (items = icon_view->priv->items; items; items = items->next)
2513 GtkIconViewItem *item = items->data;
2517 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2518 x, y, width, height);
2520 selected = is_in ^ item->selected_before_rubberbanding;
2522 if (item->selected != selected)
2524 item->selected = selected;
2526 gtk_icon_view_queue_draw_item (icon_view, item);
2531 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2536 GdkRectangle hit_rect;
2541 hit_test (GtkCellRenderer *renderer,
2542 const GdkRectangle *cell_area,
2543 const GdkRectangle *cell_background,
2546 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2547 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2548 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2549 MAX (data->hit_rect.y, cell_area->y) > 0)
2552 return (data->hit != FALSE);
2556 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2557 GtkIconViewItem *item,
2563 HitTestData data = { { x, y, width, height }, FALSE };
2564 GtkCellAreaContext *context;
2565 GdkRectangle *item_area = &item->cell_area;
2567 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2568 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2571 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2573 _gtk_icon_view_set_cell_data (icon_view, item);
2574 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2575 GTK_WIDGET (icon_view),
2576 item_area, item_area,
2577 (GtkCellAllocCallback)hit_test, &data);
2583 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2585 gboolean dirty = FALSE;
2588 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2591 for (items = icon_view->priv->items; items; items = items->next)
2593 GtkIconViewItem *item = items->data;
2597 item->selected = FALSE;
2599 gtk_icon_view_queue_draw_item (icon_view, item);
2600 gtk_icon_view_item_selected_changed (icon_view, item);
2608 /* GtkIconView signals */
2610 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2612 gtk_icon_view_select_all (icon_view);
2616 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2618 gtk_icon_view_unselect_all (icon_view);
2622 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2624 gtk_icon_view_unselect_all (icon_view);
2626 if (icon_view->priv->cursor_item != NULL)
2627 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2631 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2634 GtkCellAreaContext *context;
2636 if (!icon_view->priv->cursor_item)
2639 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2641 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2642 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2643 GTK_WIDGET (icon_view),
2644 &icon_view->priv->cursor_item->cell_area,
2648 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2649 gtk_icon_view_item_activated (icon_view, path);
2650 gtk_tree_path_free (path);
2656 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2658 if (!icon_view->priv->cursor_item)
2661 switch (icon_view->priv->selection_mode)
2663 case GTK_SELECTION_NONE:
2665 case GTK_SELECTION_BROWSE:
2666 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2668 case GTK_SELECTION_SINGLE:
2669 if (icon_view->priv->cursor_item->selected)
2670 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2672 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2674 case GTK_SELECTION_MULTIPLE:
2675 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2676 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2678 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2679 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2685 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2687 GtkAllocation allocation;
2688 GtkAdjustment *adj = icon_view->priv->hadjustment;
2689 gdouble old_page_size;
2695 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2697 old_value = gtk_adjustment_get_value (adj);
2698 old_upper = gtk_adjustment_get_upper (adj);
2699 old_page_size = gtk_adjustment_get_page_size (adj);
2700 new_upper = MAX (allocation.width, icon_view->priv->width);
2702 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2704 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2705 /* Quick explanation:
2706 * In LTR locales, leftmost portion of visible rectangle should stay
2707 * fixed, which means left edge of scrollbar thumb should remain fixed
2708 * and thus adjustment's value should stay the same.
2710 * In RTL locales, we want to keep rightmost portion of visible
2711 * rectangle fixed. This means right edge of thumb should remain fixed.
2712 * In this case, upper - value - page_size should remain constant.
2714 new_value = (new_upper - allocation.width) -
2715 (old_upper - old_value - old_page_size);
2716 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2719 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2721 gtk_adjustment_configure (adj,
2725 allocation.width * 0.1,
2726 allocation.width * 0.9,
2731 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2733 GtkAllocation allocation;
2734 GtkAdjustment *adj = icon_view->priv->vadjustment;
2736 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2738 gtk_adjustment_configure (adj,
2739 gtk_adjustment_get_value (adj),
2741 MAX (allocation.height, icon_view->priv->height),
2742 allocation.height * 0.1,
2743 allocation.height * 0.9,
2748 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2749 GtkAdjustment *adjustment)
2751 GtkIconViewPrivate *priv = icon_view->priv;
2753 if (adjustment && priv->hadjustment == adjustment)
2756 if (priv->hadjustment != NULL)
2758 g_signal_handlers_disconnect_matched (priv->hadjustment,
2759 G_SIGNAL_MATCH_DATA,
2760 0, 0, NULL, NULL, icon_view);
2761 g_object_unref (priv->hadjustment);
2765 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2768 g_signal_connect (adjustment, "value-changed",
2769 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2770 priv->hadjustment = g_object_ref_sink (adjustment);
2771 gtk_icon_view_set_hadjustment_values (icon_view);
2773 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2777 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2778 GtkAdjustment *adjustment)
2780 GtkIconViewPrivate *priv = icon_view->priv;
2782 if (adjustment && priv->vadjustment == adjustment)
2785 if (priv->vadjustment != NULL)
2787 g_signal_handlers_disconnect_matched (priv->vadjustment,
2788 G_SIGNAL_MATCH_DATA,
2789 0, 0, NULL, NULL, icon_view);
2790 g_object_unref (priv->vadjustment);
2794 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2797 g_signal_connect (adjustment, "value-changed",
2798 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2799 priv->vadjustment = g_object_ref_sink (adjustment);
2800 gtk_icon_view_set_vadjustment_values (icon_view);
2802 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2806 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2807 GtkIconView *icon_view)
2809 GtkIconViewPrivate *priv = icon_view->priv;
2811 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2813 gdk_window_move (priv->bin_window,
2814 - gtk_adjustment_get_value (priv->hadjustment),
2815 - gtk_adjustment_get_value (priv->vadjustment));
2817 if (icon_view->priv->doing_rubberband)
2818 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2820 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2825 compare_sizes (gconstpointer p1,
2829 return GPOINTER_TO_INT (((const GtkRequestedSize *) p1)->data)
2830 - GPOINTER_TO_INT (((const GtkRequestedSize *) p2)->data);
2834 gtk_icon_view_layout (GtkIconView *icon_view)
2836 GtkIconViewPrivate *priv = icon_view->priv;
2837 GtkWidget *widget = GTK_WIDGET (icon_view);
2839 gint item_width; /* this doesn't include item_padding */
2840 gint n_columns, n_rows, n_items;
2842 GtkRequestedSize *sizes;
2845 if (gtk_icon_view_is_empty (icon_view))
2848 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2849 n_items = gtk_icon_view_get_n_items (icon_view);
2851 gtk_icon_view_compute_n_items_for_size (icon_view,
2852 GTK_ORIENTATION_HORIZONTAL,
2853 gtk_widget_get_allocated_width (widget),
2855 &n_columns, &item_width);
2856 n_rows = (n_items + n_columns - 1) / n_columns;
2858 priv->width = n_columns * (item_width + 2 * priv->item_padding + priv->column_spacing) - priv->column_spacing;
2859 priv->width += 2 * priv->margin;
2860 priv->width = MAX (priv->width, gtk_widget_get_allocated_width (widget));
2862 /* Clear the per row contexts */
2863 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2865 gtk_cell_area_context_reset (priv->cell_area_context);
2866 /* because layouting is complicated. We designed an API
2867 * that is O(N²) and nonsensical.
2868 * And we're proud of it. */
2869 for (items = priv->items; items; items = items->next)
2871 _gtk_icon_view_set_cell_data (icon_view, items->data);
2872 gtk_cell_area_get_preferred_width (priv->cell_area,
2873 priv->cell_area_context,
2878 sizes = g_newa (GtkRequestedSize, n_rows);
2879 items = priv->items;
2880 priv->height = priv->margin;
2882 /* Collect the heights for all rows */
2883 for (row = 0; row < n_rows; row++)
2885 GtkCellAreaContext *context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2886 g_ptr_array_add (priv->row_contexts, context);
2888 for (col = 0; col < n_columns && items; col++, items = items->next)
2890 GtkIconViewItem *item = items->data;
2892 _gtk_icon_view_set_cell_data (icon_view, item);
2893 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2900 sizes[row].data = GINT_TO_POINTER (row);
2901 gtk_cell_area_context_get_preferred_height_for_width (context,
2903 &sizes[row].minimum_size,
2904 &sizes[row].natural_size);
2905 priv->height += sizes[row].minimum_size + 2 * priv->item_padding + priv->row_spacing;
2908 priv->height -= priv->row_spacing;
2909 priv->height += priv->margin;
2910 priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget));
2912 gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height,
2916 /* Actually allocate the rows */
2917 g_qsort_with_data (sizes, n_rows, sizeof (GtkRequestedSize), compare_sizes, NULL);
2919 items = priv->items;
2920 priv->height = priv->margin;
2922 for (row = 0; row < n_rows; row++)
2924 GtkCellAreaContext *context = g_ptr_array_index (priv->row_contexts, row);
2925 gtk_cell_area_context_allocate (context, item_width, sizes[row].minimum_size);
2927 priv->height += priv->item_padding;
2929 for (col = 0; col < n_columns && items; col++, items = items->next)
2931 GtkIconViewItem *item = items->data;
2933 item->cell_area.x = priv->margin + (col * 2 + 1) * priv->item_padding + col * (priv->column_spacing + item_width);
2934 item->cell_area.width = item_width;
2935 item->cell_area.y = priv->height;
2936 item->cell_area.height = sizes[row].minimum_size;
2941 item->cell_area.x = priv->width - item_width - item->cell_area.x;
2942 item->col = n_columns - 1 - col;
2946 priv->height += sizes[row].minimum_size + priv->item_padding + priv->row_spacing;
2949 priv->height -= priv->row_spacing;
2950 priv->height += priv->margin;
2951 priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget));
2955 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2957 /* Clear all item sizes */
2958 g_list_foreach (icon_view->priv->items,
2959 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2961 /* Re-layout the items */
2962 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
2966 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2968 item->cell_area.width = -1;
2969 item->cell_area.height = -1;
2973 gtk_icon_view_paint_item (GtkIconView *icon_view,
2975 GtkIconViewItem *item,
2978 gboolean draw_focus)
2980 GdkRectangle cell_area;
2981 GtkStateFlags state = 0;
2982 GtkCellRendererState flags = 0;
2983 GtkStyleContext *style_context;
2984 GtkWidget *widget = GTK_WIDGET (icon_view);
2985 GtkIconViewPrivate *priv = icon_view->priv;
2986 GtkCellAreaContext *context;
2988 if (priv->model == NULL || item->cell_area.width <= 0 || item->cell_area.height <= 0)
2991 _gtk_icon_view_set_cell_data (icon_view, item);
2993 style_context = gtk_widget_get_style_context (widget);
2994 state = gtk_widget_get_state_flags (widget);
2996 gtk_style_context_save (style_context);
2997 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2999 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
3001 if ((state & GTK_STATE_FLAG_FOCUSED) &&
3002 item == icon_view->priv->cursor_item)
3003 flags |= GTK_CELL_RENDERER_FOCUSED;
3007 state |= GTK_STATE_FLAG_SELECTED;
3008 flags |= GTK_CELL_RENDERER_SELECTED;
3013 state |= GTK_STATE_FLAG_PRELIGHT;
3014 flags |= GTK_CELL_RENDERER_PRELIT;
3017 gtk_style_context_set_state (style_context, state);
3021 gtk_render_background (style_context, cr,
3022 x - icon_view->priv->item_padding,
3023 y - icon_view->priv->item_padding,
3024 item->cell_area.width + icon_view->priv->item_padding * 2,
3025 item->cell_area.height + icon_view->priv->item_padding * 2);
3026 gtk_render_frame (style_context, cr,
3027 x - icon_view->priv->item_padding,
3028 y - icon_view->priv->item_padding,
3029 item->cell_area.width + icon_view->priv->item_padding * 2,
3030 item->cell_area.height + icon_view->priv->item_padding * 2);
3035 cell_area.width = item->cell_area.width;
3036 cell_area.height = item->cell_area.height;
3038 context = g_ptr_array_index (priv->row_contexts, item->row);
3039 gtk_cell_area_render (priv->cell_area, context,
3040 widget, cr, &cell_area, &cell_area, flags,
3043 gtk_style_context_restore (style_context);
3047 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3050 GtkStyleContext *context;
3055 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3056 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3057 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3058 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3060 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3062 gtk_style_context_save (context);
3063 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3065 gdk_cairo_rectangle (cr, &rect);
3068 gtk_render_background (context, cr,
3070 rect.width, rect.height);
3071 gtk_render_frame (context, cr,
3073 rect.width, rect.height);
3075 gtk_style_context_restore (context);
3080 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3086 index = gtk_tree_path_get_indices (path)[0];
3088 for (l = icon_view->priv->items; l; l = l->next)
3090 GtkIconViewItem *item = l->data;
3092 if (item->index == index)
3094 gtk_icon_view_queue_draw_item (icon_view, item);
3101 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3102 GtkIconViewItem *item)
3105 GdkRectangle *item_area = &item->cell_area;
3107 rect.x = item_area->x - icon_view->priv->item_padding;
3108 rect.y = item_area->y - icon_view->priv->item_padding;
3109 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3110 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3112 if (icon_view->priv->bin_window)
3113 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3117 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3118 GtkIconViewItem *item,
3119 GtkCellRenderer *cursor_cell)
3122 AtkObject *item_obj;
3123 AtkObject *cursor_item_obj;
3125 /* When hitting this path from keynav, the focus cell is
3126 * already set, we dont need to notify the atk object
3127 * but we still need to queue the draw here (in the case
3128 * that the focus cell changes but not the cursor item).
3130 gtk_icon_view_queue_draw_item (icon_view, item);
3132 if (icon_view->priv->cursor_item == item &&
3133 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3136 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3137 if (icon_view->priv->cursor_item != NULL)
3139 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3142 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3143 if (cursor_item_obj != NULL)
3144 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3147 icon_view->priv->cursor_item = item;
3150 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3153 /* Make sure there is a cell in focus initially */
3154 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3155 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3158 /* Notify that accessible focus object has changed */
3159 item_obj = atk_object_ref_accessible_child (obj, item->index);
3161 if (item_obj != NULL)
3163 atk_focus_tracker_notify (item_obj);
3164 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3165 g_object_unref (item_obj);
3170 static GtkIconViewItem *
3171 gtk_icon_view_item_new (void)
3173 GtkIconViewItem *item;
3175 item = g_slice_new0 (GtkIconViewItem);
3177 item->cell_area.width = -1;
3178 item->cell_area.height = -1;
3184 gtk_icon_view_item_free (GtkIconViewItem *item)
3186 g_return_if_fail (item != NULL);
3188 g_slice_free (GtkIconViewItem, item);
3192 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3195 gboolean only_in_cell,
3196 GtkCellRenderer **cell_at_pos)
3201 *cell_at_pos = NULL;
3203 for (items = icon_view->priv->items; items; items = items->next)
3205 GtkIconViewItem *item = items->data;
3206 GdkRectangle *item_area = &item->cell_area;
3208 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3209 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3210 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3211 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3213 if (only_in_cell || cell_at_pos)
3215 GtkCellRenderer *cell = NULL;
3216 GtkCellAreaContext *context;
3218 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3219 _gtk_icon_view_set_cell_data (icon_view, item);
3221 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3222 y >= item_area->y && y <= item_area->y + item_area->height)
3223 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3224 GTK_WIDGET (icon_view),
3229 *cell_at_pos = cell;
3232 return cell != NULL ? item : NULL;
3243 _gtk_icon_view_select_item (GtkIconView *icon_view,
3244 GtkIconViewItem *item)
3246 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3247 g_return_if_fail (item != NULL);
3252 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3254 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3255 gtk_icon_view_unselect_all_internal (icon_view);
3257 item->selected = TRUE;
3259 gtk_icon_view_item_selected_changed (icon_view, item);
3260 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3262 gtk_icon_view_queue_draw_item (icon_view, item);
3267 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3268 GtkIconViewItem *item)
3270 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3271 g_return_if_fail (item != NULL);
3273 if (!item->selected)
3276 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3277 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3280 item->selected = FALSE;
3282 gtk_icon_view_item_selected_changed (icon_view, item);
3283 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3285 gtk_icon_view_queue_draw_item (icon_view, item);
3289 verify_items (GtkIconView *icon_view)
3294 for (items = icon_view->priv->items; items; items = items->next)
3296 GtkIconViewItem *item = items->data;
3298 if (item->index != i)
3299 g_error ("List item does not match its index: "
3300 "item index %d and list index %d\n", item->index, i);
3307 gtk_icon_view_row_changed (GtkTreeModel *model,
3312 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3314 /* ignore changes in branches */
3315 if (gtk_tree_path_get_depth (path) > 1)
3318 /* An icon view subclass might add it's own model and populate
3319 * things at init() time instead of waiting for the constructor()
3322 if (icon_view->priv->cell_area)
3323 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3325 /* Here we can use a "grow-only" strategy for optimization
3326 * and only invalidate a single item and queue a relayout
3327 * instead of invalidating the whole thing.
3329 * For now GtkIconView still cant deal with huge models
3330 * so just invalidate the whole thing when the model
3333 gtk_icon_view_invalidate_sizes (icon_view);
3335 verify_items (icon_view);
3339 gtk_icon_view_row_inserted (GtkTreeModel *model,
3344 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3346 GtkIconViewItem *item;
3349 /* ignore changes in branches */
3350 if (gtk_tree_path_get_depth (path) > 1)
3353 index = gtk_tree_path_get_indices(path)[0];
3355 item = gtk_icon_view_item_new ();
3357 item->index = index;
3359 /* FIXME: We can be more efficient here,
3360 we can store a tail pointer and use that when
3361 appending (which is a rather common operation)
3363 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3366 list = g_list_nth (icon_view->priv->items, index + 1);
3367 for (; list; list = list->next)
3374 verify_items (icon_view);
3376 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3380 gtk_icon_view_row_deleted (GtkTreeModel *model,
3384 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3386 GtkIconViewItem *item;
3388 gboolean emit = FALSE;
3390 /* ignore changes in branches */
3391 if (gtk_tree_path_get_depth (path) > 1)
3394 index = gtk_tree_path_get_indices(path)[0];
3396 list = g_list_nth (icon_view->priv->items, index);
3399 if (icon_view->priv->cell_area)
3400 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3402 if (item == icon_view->priv->anchor_item)
3403 icon_view->priv->anchor_item = NULL;
3405 if (item == icon_view->priv->cursor_item)
3406 icon_view->priv->cursor_item = NULL;
3408 if (item == icon_view->priv->last_prelight)
3409 icon_view->priv->last_prelight = NULL;
3414 gtk_icon_view_item_free (item);
3416 for (next = list->next; next; next = next->next)
3423 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3425 verify_items (icon_view);
3427 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3430 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3434 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3435 GtkTreePath *parent,
3440 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3443 GList *items = NULL, *list;
3444 GtkIconViewItem **item_array;
3447 /* ignore changes in branches */
3451 if (icon_view->priv->cell_area)
3452 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3454 length = gtk_tree_model_iter_n_children (model, NULL);
3456 order = g_new (gint, length);
3457 for (i = 0; i < length; i++)
3458 order [new_order[i]] = i;
3460 item_array = g_new (GtkIconViewItem *, length);
3461 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3462 item_array[order[i]] = list->data;
3465 for (i = length - 1; i >= 0; i--)
3467 item_array[i]->index = i;
3468 items = g_list_prepend (items, item_array[i]);
3471 g_free (item_array);
3472 g_list_free (icon_view->priv->items);
3473 icon_view->priv->items = items;
3475 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3477 verify_items (icon_view);
3481 gtk_icon_view_build_items (GtkIconView *icon_view)
3485 GList *items = NULL;
3487 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3495 GtkIconViewItem *item = gtk_icon_view_item_new ();
3501 items = g_list_prepend (items, item);
3503 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3505 icon_view->priv->items = g_list_reverse (items);
3509 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3512 GtkMovementStep step,
3516 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3517 I_("move-cursor"), 2,
3521 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3526 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3529 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3534 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3541 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3542 GtkMovementStep step,
3545 GdkModifierType state;
3547 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3548 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3549 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3550 step == GTK_MOVEMENT_DISPLAY_LINES ||
3551 step == GTK_MOVEMENT_PAGES ||
3552 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3554 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3557 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3558 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3560 if (gtk_get_current_event_state (&state))
3562 GdkModifierType extend_mod_mask;
3563 GdkModifierType modify_mod_mask;
3566 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3567 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3569 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3570 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3572 if ((state & modify_mod_mask) == modify_mod_mask)
3573 icon_view->priv->modify_selection_pressed = TRUE;
3574 if ((state & extend_mod_mask) == extend_mod_mask)
3575 icon_view->priv->extend_selection_pressed = TRUE;
3577 /* else we assume not pressed */
3581 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3582 case GTK_MOVEMENT_VISUAL_POSITIONS:
3583 gtk_icon_view_move_cursor_left_right (icon_view, count);
3585 case GTK_MOVEMENT_DISPLAY_LINES:
3586 gtk_icon_view_move_cursor_up_down (icon_view, count);
3588 case GTK_MOVEMENT_PAGES:
3589 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3591 case GTK_MOVEMENT_BUFFER_ENDS:
3592 gtk_icon_view_move_cursor_start_end (icon_view, count);
3595 g_assert_not_reached ();
3598 icon_view->priv->modify_selection_pressed = FALSE;
3599 icon_view->priv->extend_selection_pressed = FALSE;
3601 icon_view->priv->draw_focus = TRUE;
3606 static GtkIconViewItem *
3607 find_item (GtkIconView *icon_view,
3608 GtkIconViewItem *current,
3614 GtkIconViewItem *item;
3616 /* FIXME: this could be more efficient
3618 row = current->row + row_ofs;
3619 col = current->col + col_ofs;
3621 for (items = icon_view->priv->items; items; items = items->next)
3624 if (item->row == row && item->col == col)
3631 static GtkIconViewItem *
3632 find_item_page_up_down (GtkIconView *icon_view,
3633 GtkIconViewItem *current,
3640 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3642 item = g_list_find (icon_view->priv->items, current);
3647 for (next = item->next; next; next = next->next)
3649 if (((GtkIconViewItem *)next->data)->col == col)
3652 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3662 for (next = item->prev; next; next = next->prev)
3664 if (((GtkIconViewItem *)next->data)->col == col)
3667 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3681 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3682 GtkIconViewItem *anchor,
3683 GtkIconViewItem *cursor)
3686 GtkIconViewItem *item;
3687 gint row1, row2, col1, col2;
3688 gboolean dirty = FALSE;
3690 if (anchor->row < cursor->row)
3701 if (anchor->col < cursor->col)
3712 for (items = icon_view->priv->items; items; items = items->next)
3716 if (row1 <= item->row && item->row <= row2 &&
3717 col1 <= item->col && item->col <= col2)
3719 if (!item->selected)
3722 item->selected = TRUE;
3723 gtk_icon_view_item_selected_changed (icon_view, item);
3725 gtk_icon_view_queue_draw_item (icon_view, item);
3733 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3736 GtkIconViewItem *item;
3737 GtkCellRenderer *cell = NULL;
3738 gboolean dirty = FALSE;
3740 GtkDirectionType direction;
3742 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3745 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3747 if (!icon_view->priv->cursor_item)
3752 list = icon_view->priv->items;
3754 list = g_list_last (icon_view->priv->items);
3760 /* Give focus to the first cell initially */
3761 _gtk_icon_view_set_cell_data (icon_view, item);
3762 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3771 item = icon_view->priv->cursor_item;
3772 step = count > 0 ? 1 : -1;
3774 /* Save the current focus cell in case we hit the edge */
3775 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3779 _gtk_icon_view_set_cell_data (icon_view, item);
3781 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3784 item = find_item (icon_view, item, step, 0);
3790 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3792 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3794 gtk_widget_child_focus (toplevel,
3795 direction == GTK_DIR_UP ?
3796 GTK_DIR_TAB_BACKWARD :
3797 GTK_DIR_TAB_FORWARD);
3801 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3805 if (icon_view->priv->modify_selection_pressed ||
3806 !icon_view->priv->extend_selection_pressed ||
3807 !icon_view->priv->anchor_item ||
3808 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3809 icon_view->priv->anchor_item = item;
3811 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3812 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3814 if (!icon_view->priv->modify_selection_pressed &&
3815 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3817 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3818 dirty = gtk_icon_view_select_all_between (icon_view,
3819 icon_view->priv->anchor_item,
3823 gtk_icon_view_scroll_to_item (icon_view, item);
3826 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3830 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3833 GtkIconViewItem *item;
3834 gboolean dirty = FALSE;
3836 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3839 if (!icon_view->priv->cursor_item)
3844 list = icon_view->priv->items;
3846 list = g_list_last (icon_view->priv->items);
3848 item = list ? list->data : NULL;
3851 item = find_item_page_up_down (icon_view,
3852 icon_view->priv->cursor_item,
3855 if (item == icon_view->priv->cursor_item)
3856 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3861 if (icon_view->priv->modify_selection_pressed ||
3862 !icon_view->priv->extend_selection_pressed ||
3863 !icon_view->priv->anchor_item ||
3864 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3865 icon_view->priv->anchor_item = item;
3867 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3869 if (!icon_view->priv->modify_selection_pressed &&
3870 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3872 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3873 dirty = gtk_icon_view_select_all_between (icon_view,
3874 icon_view->priv->anchor_item,
3878 gtk_icon_view_scroll_to_item (icon_view, item);
3881 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3885 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3888 GtkIconViewItem *item;
3889 GtkCellRenderer *cell = NULL;
3890 gboolean dirty = FALSE;
3892 GtkDirectionType direction;
3894 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3897 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3899 if (!icon_view->priv->cursor_item)
3904 list = icon_view->priv->items;
3906 list = g_list_last (icon_view->priv->items);
3912 /* Give focus to the first cell initially */
3913 _gtk_icon_view_set_cell_data (icon_view, item);
3914 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3923 item = icon_view->priv->cursor_item;
3924 step = count > 0 ? 1 : -1;
3926 /* Save the current focus cell in case we hit the edge */
3927 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3931 _gtk_icon_view_set_cell_data (icon_view, item);
3933 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3936 item = find_item (icon_view, item, 0, step);
3942 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3944 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3946 gtk_widget_child_focus (toplevel,
3947 direction == GTK_DIR_LEFT ?
3948 GTK_DIR_TAB_BACKWARD :
3949 GTK_DIR_TAB_FORWARD);
3953 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3957 if (icon_view->priv->modify_selection_pressed ||
3958 !icon_view->priv->extend_selection_pressed ||
3959 !icon_view->priv->anchor_item ||
3960 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3961 icon_view->priv->anchor_item = item;
3963 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3964 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3966 if (!icon_view->priv->modify_selection_pressed &&
3967 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3969 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3970 dirty = gtk_icon_view_select_all_between (icon_view,
3971 icon_view->priv->anchor_item,
3975 gtk_icon_view_scroll_to_item (icon_view, item);
3978 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3982 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3985 GtkIconViewItem *item;
3987 gboolean dirty = FALSE;
3989 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3993 list = icon_view->priv->items;
3995 list = g_list_last (icon_view->priv->items);
3997 item = list ? list->data : NULL;
3999 if (item == icon_view->priv->cursor_item)
4000 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4005 if (icon_view->priv->modify_selection_pressed ||
4006 !icon_view->priv->extend_selection_pressed ||
4007 !icon_view->priv->anchor_item ||
4008 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4009 icon_view->priv->anchor_item = item;
4011 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
4013 if (!icon_view->priv->modify_selection_pressed &&
4014 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4016 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4017 dirty = gtk_icon_view_select_all_between (icon_view,
4018 icon_view->priv->anchor_item,
4022 gtk_icon_view_scroll_to_item (icon_view, item);
4025 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4029 * gtk_icon_view_scroll_to_path:
4030 * @icon_view: A #GtkIconView.
4031 * @path: The path of the item to move to.
4032 * @use_align: whether to use alignment arguments, or %FALSE.
4033 * @row_align: The vertical alignment of the item specified by @path.
4034 * @col_align: The horizontal alignment of the item specified by @path.
4036 * Moves the alignments of @icon_view to the position specified by @path.
4037 * @row_align determines where the row is placed, and @col_align determines
4038 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4039 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4042 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4043 * tree does the minimum amount of work to scroll the item onto the screen.
4044 * This means that the item will be scrolled to the edge closest to its current
4045 * position. If the item is currently visible on the screen, nothing is done.
4047 * This function only works if the model is set, and @path is a valid row on
4048 * the model. If the model changes before the @icon_view is realized, the
4049 * centered path will be modified to reflect this change.
4054 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4060 GtkIconViewItem *item = NULL;
4063 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4064 g_return_if_fail (path != NULL);
4065 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4066 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4068 widget = GTK_WIDGET (icon_view);
4070 if (gtk_tree_path_get_depth (path) > 0)
4071 item = g_list_nth_data (icon_view->priv->items,
4072 gtk_tree_path_get_indices(path)[0]);
4074 if (!item || item->cell_area.width < 0 ||
4075 !gtk_widget_get_realized (widget))
4077 if (icon_view->priv->scroll_to_path)
4078 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4080 icon_view->priv->scroll_to_path = NULL;
4083 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4085 icon_view->priv->scroll_to_use_align = use_align;
4086 icon_view->priv->scroll_to_row_align = row_align;
4087 icon_view->priv->scroll_to_col_align = col_align;
4094 GtkAllocation allocation;
4097 GdkRectangle item_area =
4099 item->cell_area.x - icon_view->priv->item_padding,
4100 item->cell_area.y - icon_view->priv->item_padding,
4101 item->cell_area.width + icon_view->priv->item_padding * 2,
4102 item->cell_area.height + icon_view->priv->item_padding * 2
4105 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4107 gtk_widget_get_allocation (widget, &allocation);
4109 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4111 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4112 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4114 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4116 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4117 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4119 gtk_adjustment_changed (icon_view->priv->hadjustment);
4120 gtk_adjustment_changed (icon_view->priv->vadjustment);
4123 gtk_icon_view_scroll_to_item (icon_view, item);
4128 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4129 GtkIconViewItem *item)
4131 GtkIconViewPrivate *priv = icon_view->priv;
4132 GtkWidget *widget = GTK_WIDGET (icon_view);
4133 GtkAdjustment *hadj, *vadj;
4134 GtkAllocation allocation;
4136 GdkRectangle item_area;
4138 item_area.x = item->cell_area.x - priv->item_padding;
4139 item_area.y = item->cell_area.y - priv->item_padding;
4140 item_area.width = item->cell_area.width + priv->item_padding * 2;
4141 item_area.height = item->cell_area.height + priv->item_padding * 2;
4143 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4144 gtk_widget_get_allocation (widget, &allocation);
4146 hadj = icon_view->priv->hadjustment;
4147 vadj = icon_view->priv->vadjustment;
4149 if (y + item_area.y < 0)
4150 gtk_adjustment_set_value (vadj,
4151 gtk_adjustment_get_value (vadj)
4153 else if (y + item_area.y + item_area.height > allocation.height)
4154 gtk_adjustment_set_value (vadj,
4155 gtk_adjustment_get_value (vadj)
4156 + y + item_area.y + item_area.height - allocation.height);
4158 if (x + item_area.x < 0)
4159 gtk_adjustment_set_value (hadj,
4160 gtk_adjustment_get_value (hadj)
4162 else if (x + item_area.x + item_area.width > allocation.width)
4163 gtk_adjustment_set_value (hadj,
4164 gtk_adjustment_get_value (hadj)
4165 + x + item_area.x + item_area.width - allocation.width);
4167 gtk_adjustment_changed (hadj);
4168 gtk_adjustment_changed (vadj);
4171 /* GtkCellLayout implementation */
4174 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4175 GtkCellArea *cell_area)
4177 GtkIconViewPrivate *priv = icon_view->priv;
4179 if (priv->cell_area)
4183 priv->cell_area = cell_area;
4185 priv->cell_area = gtk_cell_area_box_new ();
4187 g_object_ref_sink (priv->cell_area);
4189 if (GTK_IS_ORIENTABLE (priv->cell_area))
4190 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4192 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4194 priv->add_editable_id =
4195 g_signal_connect (priv->cell_area, "add-editable",
4196 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4197 priv->remove_editable_id =
4198 g_signal_connect (priv->cell_area, "remove-editable",
4199 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4201 update_text_cell (icon_view);
4202 update_pixbuf_cell (icon_view);
4205 static GtkCellArea *
4206 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4208 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4209 GtkIconViewPrivate *priv = icon_view->priv;
4211 if (G_UNLIKELY (!priv->cell_area))
4212 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4214 return icon_view->priv->cell_area;
4218 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4219 GtkIconViewItem *item)
4224 path = gtk_tree_path_new_from_indices (item->index, -1);
4225 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4227 gtk_tree_path_free (path);
4229 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4230 icon_view->priv->model,
4231 &iter, FALSE, FALSE);
4240 * gtk_icon_view_new:
4242 * Creates a new #GtkIconView widget
4244 * Return value: A newly created #GtkIconView widget
4249 gtk_icon_view_new (void)
4251 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4255 * gtk_icon_view_new_with_area:
4256 * @area: the #GtkCellArea to use to layout cells
4258 * Creates a new #GtkIconView widget using the
4259 * specified @area to layout cells inside the icons.
4261 * Return value: A newly created #GtkIconView widget
4266 gtk_icon_view_new_with_area (GtkCellArea *area)
4268 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4272 * gtk_icon_view_new_with_model:
4273 * @model: The model.
4275 * Creates a new #GtkIconView widget with the model @model.
4277 * Return value: A newly created #GtkIconView widget.
4282 gtk_icon_view_new_with_model (GtkTreeModel *model)
4284 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4288 * gtk_icon_view_convert_widget_to_bin_window_coords:
4289 * @icon_view: a #GtkIconView
4290 * @wx: X coordinate relative to the widget
4291 * @wy: Y coordinate relative to the widget
4292 * @bx: (out): return location for bin_window X coordinate
4293 * @by: (out): return location for bin_window Y coordinate
4295 * Converts widget coordinates to coordinates for the bin_window,
4296 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4301 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4309 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4311 if (icon_view->priv->bin_window)
4312 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4323 * gtk_icon_view_get_path_at_pos:
4324 * @icon_view: A #GtkIconView.
4325 * @x: The x position to be identified
4326 * @y: The y position to be identified
4328 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4329 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4330 * the cell at the specified position.
4331 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4332 * widget coordinates to bin_window coordinates.
4334 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4335 * if no icon exists at that position.
4340 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4344 GtkIconViewItem *item;
4347 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4349 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4354 path = gtk_tree_path_new_from_indices (item->index, -1);
4360 * gtk_icon_view_get_item_at_pos:
4361 * @icon_view: A #GtkIconView.
4362 * @x: The x position to be identified
4363 * @y: The y position to be identified
4364 * @path: (out) (allow-none): Return location for the path, or %NULL
4365 * @cell: (out) (allow-none): Return location for the renderer
4366 * responsible for the cell at (@x, @y), or %NULL
4368 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4369 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4370 * obtains the cell at the specified position. The returned path should
4371 * be freed with gtk_tree_path_free().
4372 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4373 * widget coordinates to bin_window coordinates.
4375 * Return value: %TRUE if an item exists at the specified position
4380 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4384 GtkCellRenderer **cell)
4386 GtkIconViewItem *item;
4387 GtkCellRenderer *renderer = NULL;
4389 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4391 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4396 *path = gtk_tree_path_new_from_indices (item->index, -1);
4404 return (item != NULL);
4408 * gtk_icon_view_get_cell_rect:
4409 * @icon_view: a #GtkIconView
4410 * @path: a #GtkTreePath
4411 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4412 * @rect: (out): rectangle to fill with cell rect
4414 * Fills the bounding rectangle in widget coordinates for the cell specified by
4415 * @path and @cell. If @cell is %NULL the main cell area is used.
4417 * This function is only valid if @icon_view is realized.
4419 * Return value: %FALSE if there is no such item, %TRUE otherwise
4424 gtk_icon_view_get_cell_rect (GtkIconView *icon_view,
4426 GtkCellRenderer *cell,
4429 GtkIconViewItem *item = NULL;
4432 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4433 g_return_val_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell), FALSE);
4435 if (gtk_tree_path_get_depth (path) > 0)
4436 item = g_list_nth_data (icon_view->priv->items,
4437 gtk_tree_path_get_indices(path)[0]);
4444 GtkCellAreaContext *context;
4446 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4447 _gtk_icon_view_set_cell_data (icon_view, item);
4448 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4449 GTK_WIDGET (icon_view),
4450 cell, &item->cell_area, rect);
4454 rect->x = item->cell_area.x - icon_view->priv->item_padding;
4455 rect->y = item->cell_area.y - icon_view->priv->item_padding;
4456 rect->width = item->cell_area.width + icon_view->priv->item_padding * 2;
4457 rect->height = item->cell_area.height + icon_view->priv->item_padding * 2;
4460 if (icon_view->priv->bin_window)
4462 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4471 * gtk_icon_view_set_tooltip_item:
4472 * @icon_view: a #GtkIconView
4473 * @tooltip: a #GtkTooltip
4474 * @path: a #GtkTreePath
4476 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4477 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4478 * See also gtk_tooltip_set_tip_area().
4483 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4484 GtkTooltip *tooltip,
4487 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4488 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4490 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4494 * gtk_icon_view_set_tooltip_cell:
4495 * @icon_view: a #GtkIconView
4496 * @tooltip: a #GtkTooltip
4497 * @path: a #GtkTreePath
4498 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4500 * Sets the tip area of @tooltip to the area which @cell occupies in
4501 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4503 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4508 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4509 GtkTooltip *tooltip,
4511 GtkCellRenderer *cell)
4515 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4516 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4517 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4519 if (!gtk_icon_view_get_cell_rect (icon_view, path, cell, &rect))
4522 gtk_tooltip_set_tip_area (tooltip, &rect);
4527 * gtk_icon_view_get_tooltip_context:
4528 * @icon_view: an #GtkIconView
4529 * @x: (inout): the x coordinate (relative to widget coordinates)
4530 * @y: (inout): the y coordinate (relative to widget coordinates)
4531 * @keyboard_tip: whether this is a keyboard tooltip or not
4532 * @model: (out) (allow-none) (transfer none): a pointer to receive a
4533 * #GtkTreeModel or %NULL
4534 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4535 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4537 * This function is supposed to be used in a #GtkWidget::query-tooltip
4538 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4539 * which are received in the signal handler, should be passed to this
4540 * function without modification.
4542 * The return value indicates whether there is an icon view item at the given
4543 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4544 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4545 * @model, @path and @iter which have been provided will be set to point to
4546 * that row and the corresponding model. @x and @y will always be converted
4547 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4549 * Return value: whether or not the given tooltip context points to a item
4554 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4557 gboolean keyboard_tip,
4558 GtkTreeModel **model,
4562 GtkTreePath *tmppath = NULL;
4564 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4565 g_return_val_if_fail (x != NULL, FALSE);
4566 g_return_val_if_fail (y != NULL, FALSE);
4570 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4577 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4580 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4585 *model = gtk_icon_view_get_model (icon_view);
4588 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4594 gtk_tree_path_free (tmppath);
4600 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4603 gboolean keyboard_tip,
4604 GtkTooltip *tooltip,
4610 GtkTreeModel *model;
4611 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4613 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4616 &model, &path, &iter))
4619 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4623 gtk_tree_path_free (path);
4627 gtk_tooltip_set_markup (tooltip, str);
4628 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4630 gtk_tree_path_free (path);
4638 * gtk_icon_view_set_tooltip_column:
4639 * @icon_view: a #GtkIconView
4640 * @column: an integer, which is a valid column number for @icon_view's model
4642 * If you only plan to have simple (text-only) tooltips on full items, you
4643 * can use this function to have #GtkIconView handle these automatically
4644 * for you. @column should be set to the column in @icon_view's model
4645 * containing the tooltip texts, or -1 to disable this feature.
4647 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4648 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4650 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4651 * so &, <, etc have to be escaped in the text.
4656 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4659 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4661 if (column == icon_view->priv->tooltip_column)
4666 g_signal_handlers_disconnect_by_func (icon_view,
4667 gtk_icon_view_set_tooltip_query_cb,
4669 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4673 if (icon_view->priv->tooltip_column == -1)
4675 g_signal_connect (icon_view, "query-tooltip",
4676 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4677 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4681 icon_view->priv->tooltip_column = column;
4682 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4686 * gtk_icon_view_get_tooltip_column:
4687 * @icon_view: a #GtkIconView
4689 * Returns the column of @icon_view's model which is being used for
4690 * displaying tooltips on @icon_view's rows.
4692 * Return value: the index of the tooltip column that is currently being
4693 * used, or -1 if this is disabled.
4698 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4700 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4702 return icon_view->priv->tooltip_column;
4706 * gtk_icon_view_get_visible_range:
4707 * @icon_view: A #GtkIconView
4708 * @start_path: (out) (allow-none): Return location for start of region,
4710 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4712 * Sets @start_path and @end_path to be the first and last visible path.
4713 * Note that there may be invisible paths in between.
4715 * Both paths should be freed with gtk_tree_path_free() after use.
4717 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4722 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4723 GtkTreePath **start_path,
4724 GtkTreePath **end_path)
4726 gint start_index = -1;
4727 gint end_index = -1;
4730 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4732 if (icon_view->priv->hadjustment == NULL ||
4733 icon_view->priv->vadjustment == NULL)
4736 if (start_path == NULL && end_path == NULL)
4739 for (icons = icon_view->priv->items; icons; icons = icons->next)
4741 GtkIconViewItem *item = icons->data;
4742 GdkRectangle *item_area = &item->cell_area;
4744 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4745 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4747 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4748 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4750 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4751 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4753 if (start_index == -1)
4754 start_index = item->index;
4755 end_index = item->index;
4759 if (start_path && start_index != -1)
4760 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4761 if (end_path && end_index != -1)
4762 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4764 return start_index != -1;
4768 * gtk_icon_view_selected_foreach:
4769 * @icon_view: A #GtkIconView.
4770 * @func: (scope call): The function to call for each selected icon.
4771 * @data: User data to pass to the function.
4773 * Calls a function for each selected icon. Note that the model or
4774 * selection cannot be modified from within this function.
4779 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4780 GtkIconViewForeachFunc func,
4785 for (list = icon_view->priv->items; list; list = list->next)
4787 GtkIconViewItem *item = list->data;
4788 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4791 (* func) (icon_view, path, data);
4793 gtk_tree_path_free (path);
4798 * gtk_icon_view_set_selection_mode:
4799 * @icon_view: A #GtkIconView.
4800 * @mode: The selection mode
4802 * Sets the selection mode of the @icon_view.
4807 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4808 GtkSelectionMode mode)
4810 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4812 if (mode == icon_view->priv->selection_mode)
4815 if (mode == GTK_SELECTION_NONE ||
4816 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4817 gtk_icon_view_unselect_all (icon_view);
4819 icon_view->priv->selection_mode = mode;
4821 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4825 * gtk_icon_view_get_selection_mode:
4826 * @icon_view: A #GtkIconView.
4828 * Gets the selection mode of the @icon_view.
4830 * Return value: the current selection mode
4835 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4837 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4839 return icon_view->priv->selection_mode;
4843 * gtk_icon_view_set_model:
4844 * @icon_view: A #GtkIconView.
4845 * @model: (allow-none): The model.
4847 * Sets the model for a #GtkIconView.
4848 * If the @icon_view already has a model set, it will remove
4849 * it before setting the new model. If @model is %NULL, then
4850 * it will unset the old model.
4855 gtk_icon_view_set_model (GtkIconView *icon_view,
4856 GtkTreeModel *model)
4860 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4861 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4863 if (icon_view->priv->model == model)
4866 if (icon_view->priv->scroll_to_path)
4868 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4869 icon_view->priv->scroll_to_path = NULL;
4872 /* The area can be NULL while disposing */
4873 if (icon_view->priv->cell_area)
4874 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4876 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4882 if (icon_view->priv->pixbuf_column != -1)
4884 column_type = gtk_tree_model_get_column_type (model,
4885 icon_view->priv->pixbuf_column);
4887 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4890 if (icon_view->priv->text_column != -1)
4892 column_type = gtk_tree_model_get_column_type (model,
4893 icon_view->priv->text_column);
4895 g_return_if_fail (column_type == G_TYPE_STRING);
4898 if (icon_view->priv->markup_column != -1)
4900 column_type = gtk_tree_model_get_column_type (model,
4901 icon_view->priv->markup_column);
4903 g_return_if_fail (column_type == G_TYPE_STRING);
4908 if (icon_view->priv->model)
4910 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4911 gtk_icon_view_row_changed,
4913 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4914 gtk_icon_view_row_inserted,
4916 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4917 gtk_icon_view_row_deleted,
4919 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4920 gtk_icon_view_rows_reordered,
4923 g_object_unref (icon_view->priv->model);
4925 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4926 icon_view->priv->items = NULL;
4927 icon_view->priv->anchor_item = NULL;
4928 icon_view->priv->cursor_item = NULL;
4929 icon_view->priv->last_single_clicked = NULL;
4930 icon_view->priv->last_prelight = NULL;
4931 icon_view->priv->width = 0;
4932 icon_view->priv->height = 0;
4935 icon_view->priv->model = model;
4937 if (icon_view->priv->model)
4939 g_object_ref (icon_view->priv->model);
4940 g_signal_connect (icon_view->priv->model,
4942 G_CALLBACK (gtk_icon_view_row_changed),
4944 g_signal_connect (icon_view->priv->model,
4946 G_CALLBACK (gtk_icon_view_row_inserted),
4948 g_signal_connect (icon_view->priv->model,
4950 G_CALLBACK (gtk_icon_view_row_deleted),
4952 g_signal_connect (icon_view->priv->model,
4954 G_CALLBACK (gtk_icon_view_rows_reordered),
4957 gtk_icon_view_build_items (icon_view);
4960 g_object_notify (G_OBJECT (icon_view), "model");
4963 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4965 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4969 * gtk_icon_view_get_model:
4970 * @icon_view: a #GtkIconView
4972 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4975 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4976 * currently being used.
4981 gtk_icon_view_get_model (GtkIconView *icon_view)
4983 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4985 return icon_view->priv->model;
4989 update_text_cell (GtkIconView *icon_view)
4991 if (!icon_view->priv->cell_area)
4994 if (icon_view->priv->text_column == -1 &&
4995 icon_view->priv->markup_column == -1)
4997 if (icon_view->priv->text_cell != NULL)
4999 gtk_cell_area_remove (icon_view->priv->cell_area,
5000 icon_view->priv->text_cell);
5001 icon_view->priv->text_cell = NULL;
5006 if (icon_view->priv->text_cell == NULL)
5008 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
5010 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
5013 if (icon_view->priv->markup_column != -1)
5014 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5015 icon_view->priv->text_cell,
5016 "markup", icon_view->priv->markup_column,
5019 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5020 icon_view->priv->text_cell,
5021 "text", icon_view->priv->text_column,
5024 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5025 g_object_set (icon_view->priv->text_cell,
5026 "alignment", PANGO_ALIGN_CENTER,
5027 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5032 g_object_set (icon_view->priv->text_cell,
5033 "alignment", PANGO_ALIGN_LEFT,
5034 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5042 update_pixbuf_cell (GtkIconView *icon_view)
5044 if (!icon_view->priv->cell_area)
5047 if (icon_view->priv->pixbuf_column == -1)
5049 if (icon_view->priv->pixbuf_cell != NULL)
5051 gtk_cell_area_remove (icon_view->priv->cell_area,
5052 icon_view->priv->pixbuf_cell);
5054 icon_view->priv->pixbuf_cell = NULL;
5059 if (icon_view->priv->pixbuf_cell == NULL)
5061 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
5063 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
5066 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5067 icon_view->priv->pixbuf_cell,
5068 "pixbuf", icon_view->priv->pixbuf_column,
5071 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5072 g_object_set (icon_view->priv->pixbuf_cell,
5077 g_object_set (icon_view->priv->pixbuf_cell,
5085 * gtk_icon_view_set_text_column:
5086 * @icon_view: A #GtkIconView.
5087 * @column: A column in the currently used model, or -1 to display no text
5089 * Sets the column with text for @icon_view to be @column. The text
5090 * column must be of type #G_TYPE_STRING.
5095 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5098 if (column == icon_view->priv->text_column)
5102 icon_view->priv->text_column = -1;
5105 if (icon_view->priv->model != NULL)
5109 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5111 g_return_if_fail (column_type == G_TYPE_STRING);
5114 icon_view->priv->text_column = column;
5117 if (icon_view->priv->cell_area)
5118 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5120 update_text_cell (icon_view);
5122 gtk_icon_view_invalidate_sizes (icon_view);
5124 g_object_notify (G_OBJECT (icon_view), "text-column");
5128 * gtk_icon_view_get_text_column:
5129 * @icon_view: A #GtkIconView.
5131 * Returns the column with text for @icon_view.
5133 * Returns: the text column, or -1 if it's unset.
5138 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5140 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5142 return icon_view->priv->text_column;
5146 * gtk_icon_view_set_markup_column:
5147 * @icon_view: A #GtkIconView.
5148 * @column: A column in the currently used model, or -1 to display no text
5150 * Sets the column with markup information for @icon_view to be
5151 * @column. The markup column must be of type #G_TYPE_STRING.
5152 * If the markup column is set to something, it overrides
5153 * the text column set by gtk_icon_view_set_text_column().
5158 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5161 if (column == icon_view->priv->markup_column)
5165 icon_view->priv->markup_column = -1;
5168 if (icon_view->priv->model != NULL)
5172 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5174 g_return_if_fail (column_type == G_TYPE_STRING);
5177 icon_view->priv->markup_column = column;
5180 if (icon_view->priv->cell_area)
5181 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5183 update_text_cell (icon_view);
5185 gtk_icon_view_invalidate_sizes (icon_view);
5187 g_object_notify (G_OBJECT (icon_view), "markup-column");
5191 * gtk_icon_view_get_markup_column:
5192 * @icon_view: A #GtkIconView.
5194 * Returns the column with markup text for @icon_view.
5196 * Returns: the markup column, or -1 if it's unset.
5201 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5203 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5205 return icon_view->priv->markup_column;
5209 * gtk_icon_view_set_pixbuf_column:
5210 * @icon_view: A #GtkIconView.
5211 * @column: A column in the currently used model, or -1 to disable
5213 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5214 * column must be of type #GDK_TYPE_PIXBUF
5219 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5222 if (column == icon_view->priv->pixbuf_column)
5226 icon_view->priv->pixbuf_column = -1;
5229 if (icon_view->priv->model != NULL)
5233 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5235 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5238 icon_view->priv->pixbuf_column = column;
5241 if (icon_view->priv->cell_area)
5242 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5244 update_pixbuf_cell (icon_view);
5246 gtk_icon_view_invalidate_sizes (icon_view);
5248 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5253 * gtk_icon_view_get_pixbuf_column:
5254 * @icon_view: A #GtkIconView.
5256 * Returns the column with pixbufs for @icon_view.
5258 * Returns: the pixbuf column, or -1 if it's unset.
5263 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5265 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5267 return icon_view->priv->pixbuf_column;
5271 * gtk_icon_view_select_path:
5272 * @icon_view: A #GtkIconView.
5273 * @path: The #GtkTreePath to be selected.
5275 * Selects the row at @path.
5280 gtk_icon_view_select_path (GtkIconView *icon_view,
5283 GtkIconViewItem *item = NULL;
5285 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5286 g_return_if_fail (icon_view->priv->model != NULL);
5287 g_return_if_fail (path != NULL);
5289 if (gtk_tree_path_get_depth (path) > 0)
5290 item = g_list_nth_data (icon_view->priv->items,
5291 gtk_tree_path_get_indices(path)[0]);
5294 _gtk_icon_view_select_item (icon_view, item);
5298 * gtk_icon_view_unselect_path:
5299 * @icon_view: A #GtkIconView.
5300 * @path: The #GtkTreePath to be unselected.
5302 * Unselects the row at @path.
5307 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5310 GtkIconViewItem *item;
5312 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5313 g_return_if_fail (icon_view->priv->model != NULL);
5314 g_return_if_fail (path != NULL);
5316 item = g_list_nth_data (icon_view->priv->items,
5317 gtk_tree_path_get_indices(path)[0]);
5322 _gtk_icon_view_unselect_item (icon_view, item);
5326 * gtk_icon_view_get_selected_items:
5327 * @icon_view: A #GtkIconView.
5329 * Creates a list of paths of all selected items. Additionally, if you are
5330 * planning on modifying the model after calling this function, you may
5331 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5332 * To do this, you can use gtk_tree_row_reference_new().
5334 * To free the return value, use:
5336 * g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
5339 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5344 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5347 GList *selected = NULL;
5349 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5351 for (list = icon_view->priv->items; list != NULL; list = list->next)
5353 GtkIconViewItem *item = list->data;
5357 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5359 selected = g_list_prepend (selected, path);
5367 * gtk_icon_view_select_all:
5368 * @icon_view: A #GtkIconView.
5370 * Selects all the icons. @icon_view must has its selection mode set
5371 * to #GTK_SELECTION_MULTIPLE.
5376 gtk_icon_view_select_all (GtkIconView *icon_view)
5379 gboolean dirty = FALSE;
5381 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5383 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5386 for (items = icon_view->priv->items; items; items = items->next)
5388 GtkIconViewItem *item = items->data;
5390 if (!item->selected)
5393 item->selected = TRUE;
5394 gtk_icon_view_queue_draw_item (icon_view, item);
5399 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5403 * gtk_icon_view_unselect_all:
5404 * @icon_view: A #GtkIconView.
5406 * Unselects all the icons.
5411 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5413 gboolean dirty = FALSE;
5415 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5417 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5420 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5423 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5427 * gtk_icon_view_path_is_selected:
5428 * @icon_view: A #GtkIconView.
5429 * @path: A #GtkTreePath to check selection on.
5431 * Returns %TRUE if the icon pointed to by @path is currently
5432 * selected. If @path does not point to a valid location, %FALSE is returned.
5434 * Return value: %TRUE if @path is selected.
5439 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5442 GtkIconViewItem *item;
5444 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5445 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5446 g_return_val_if_fail (path != NULL, FALSE);
5448 item = g_list_nth_data (icon_view->priv->items,
5449 gtk_tree_path_get_indices(path)[0]);
5454 return item->selected;
5458 * gtk_icon_view_get_item_row:
5459 * @icon_view: a #GtkIconView
5460 * @path: the #GtkTreePath of the item
5462 * Gets the row in which the item @path is currently
5463 * displayed. Row numbers start at 0.
5465 * Returns: The row in which the item is displayed
5470 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5473 GtkIconViewItem *item;
5475 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5476 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5477 g_return_val_if_fail (path != NULL, -1);
5479 item = g_list_nth_data (icon_view->priv->items,
5480 gtk_tree_path_get_indices(path)[0]);
5489 * gtk_icon_view_get_item_column:
5490 * @icon_view: a #GtkIconView
5491 * @path: the #GtkTreePath of the item
5493 * Gets the column in which the item @path is currently
5494 * displayed. Column numbers start at 0.
5496 * Returns: The column in which the item is displayed
5501 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5504 GtkIconViewItem *item;
5506 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5507 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5508 g_return_val_if_fail (path != NULL, -1);
5510 item = g_list_nth_data (icon_view->priv->items,
5511 gtk_tree_path_get_indices(path)[0]);
5520 * gtk_icon_view_item_activated:
5521 * @icon_view: A #GtkIconView
5522 * @path: The #GtkTreePath to be activated
5524 * Activates the item determined by @path.
5529 gtk_icon_view_item_activated (GtkIconView *icon_view,
5532 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5533 g_return_if_fail (path != NULL);
5535 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5539 * gtk_icon_view_set_item_orientation:
5540 * @icon_view: a #GtkIconView
5541 * @orientation: the relative position of texts and icons
5543 * Sets the ::item-orientation property which determines whether the labels
5544 * are drawn beside the icons instead of below.
5549 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5550 GtkOrientation orientation)
5552 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5554 if (icon_view->priv->item_orientation != orientation)
5556 icon_view->priv->item_orientation = orientation;
5558 if (icon_view->priv->cell_area)
5560 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5561 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5562 icon_view->priv->item_orientation);
5564 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5567 gtk_icon_view_invalidate_sizes (icon_view);
5569 update_text_cell (icon_view);
5570 update_pixbuf_cell (icon_view);
5572 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5577 * gtk_icon_view_get_item_orientation:
5578 * @icon_view: a #GtkIconView
5580 * Returns the value of the ::item-orientation property which determines
5581 * whether the labels are drawn beside the icons instead of below.
5583 * Return value: the relative position of texts and icons
5588 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5590 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5591 GTK_ORIENTATION_VERTICAL);
5593 return icon_view->priv->item_orientation;
5597 * gtk_icon_view_set_columns:
5598 * @icon_view: a #GtkIconView
5599 * @columns: the number of columns
5601 * Sets the ::columns property which determines in how
5602 * many columns the icons are arranged. If @columns is
5603 * -1, the number of columns will be chosen automatically
5604 * to fill the available area.
5609 gtk_icon_view_set_columns (GtkIconView *icon_view,
5612 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5614 if (icon_view->priv->columns != columns)
5616 icon_view->priv->columns = columns;
5618 if (icon_view->priv->cell_area)
5619 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5621 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5623 g_object_notify (G_OBJECT (icon_view), "columns");
5628 * gtk_icon_view_get_columns:
5629 * @icon_view: a #GtkIconView
5631 * Returns the value of the ::columns property.
5633 * Return value: the number of columns, or -1
5638 gtk_icon_view_get_columns (GtkIconView *icon_view)
5640 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5642 return icon_view->priv->columns;
5646 * gtk_icon_view_set_item_width:
5647 * @icon_view: a #GtkIconView
5648 * @item_width: the width for each item
5650 * Sets the ::item-width property which specifies the width
5651 * to use for each item. If it is set to -1, the icon view will
5652 * automatically determine a suitable item size.
5657 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5660 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5662 if (icon_view->priv->item_width != item_width)
5664 icon_view->priv->item_width = item_width;
5666 if (icon_view->priv->cell_area)
5667 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5669 gtk_icon_view_invalidate_sizes (icon_view);
5671 update_text_cell (icon_view);
5673 g_object_notify (G_OBJECT (icon_view), "item-width");
5678 * gtk_icon_view_get_item_width:
5679 * @icon_view: a #GtkIconView
5681 * Returns the value of the ::item-width property.
5683 * Return value: the width of a single item, or -1
5688 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5690 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5692 return icon_view->priv->item_width;
5697 * gtk_icon_view_set_spacing:
5698 * @icon_view: a #GtkIconView
5699 * @spacing: the spacing
5701 * Sets the ::spacing property which specifies the space
5702 * which is inserted between the cells (i.e. the icon and
5703 * the text) of an item.
5708 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5711 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5713 if (icon_view->priv->spacing != spacing)
5715 icon_view->priv->spacing = spacing;
5717 if (icon_view->priv->cell_area)
5718 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5720 gtk_icon_view_invalidate_sizes (icon_view);
5722 g_object_notify (G_OBJECT (icon_view), "spacing");
5727 * gtk_icon_view_get_spacing:
5728 * @icon_view: a #GtkIconView
5730 * Returns the value of the ::spacing property.
5732 * Return value: the space between cells
5737 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5739 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5741 return icon_view->priv->spacing;
5745 * gtk_icon_view_set_row_spacing:
5746 * @icon_view: a #GtkIconView
5747 * @row_spacing: the row spacing
5749 * Sets the ::row-spacing property which specifies the space
5750 * which is inserted between the rows of the icon view.
5755 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5758 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5760 if (icon_view->priv->row_spacing != row_spacing)
5762 icon_view->priv->row_spacing = row_spacing;
5764 if (icon_view->priv->cell_area)
5765 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5767 gtk_icon_view_invalidate_sizes (icon_view);
5769 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5774 * gtk_icon_view_get_row_spacing:
5775 * @icon_view: a #GtkIconView
5777 * Returns the value of the ::row-spacing property.
5779 * Return value: the space between rows
5784 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5786 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5788 return icon_view->priv->row_spacing;
5792 * gtk_icon_view_set_column_spacing:
5793 * @icon_view: a #GtkIconView
5794 * @column_spacing: the column spacing
5796 * Sets the ::column-spacing property which specifies the space
5797 * which is inserted between the columns of the icon view.
5802 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5803 gint column_spacing)
5805 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5807 if (icon_view->priv->column_spacing != column_spacing)
5809 icon_view->priv->column_spacing = column_spacing;
5811 if (icon_view->priv->cell_area)
5812 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5814 gtk_icon_view_invalidate_sizes (icon_view);
5816 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5821 * gtk_icon_view_get_column_spacing:
5822 * @icon_view: a #GtkIconView
5824 * Returns the value of the ::column-spacing property.
5826 * Return value: the space between columns
5831 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5833 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5835 return icon_view->priv->column_spacing;
5839 * gtk_icon_view_set_margin:
5840 * @icon_view: a #GtkIconView
5841 * @margin: the margin
5843 * Sets the ::margin property which specifies the space
5844 * which is inserted at the top, bottom, left and right
5850 gtk_icon_view_set_margin (GtkIconView *icon_view,
5853 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5855 if (icon_view->priv->margin != margin)
5857 icon_view->priv->margin = margin;
5859 if (icon_view->priv->cell_area)
5860 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5862 gtk_icon_view_invalidate_sizes (icon_view);
5864 g_object_notify (G_OBJECT (icon_view), "margin");
5869 * gtk_icon_view_get_margin:
5870 * @icon_view: a #GtkIconView
5872 * Returns the value of the ::margin property.
5874 * Return value: the space at the borders
5879 gtk_icon_view_get_margin (GtkIconView *icon_view)
5881 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5883 return icon_view->priv->margin;
5887 * gtk_icon_view_set_item_padding:
5888 * @icon_view: a #GtkIconView
5889 * @item_padding: the item padding
5891 * Sets the #GtkIconView:item-padding property which specifies the padding
5892 * around each of the icon view's items.
5897 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5900 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5902 if (icon_view->priv->item_padding != item_padding)
5904 icon_view->priv->item_padding = item_padding;
5906 if (icon_view->priv->cell_area)
5907 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5909 gtk_icon_view_invalidate_sizes (icon_view);
5911 g_object_notify (G_OBJECT (icon_view), "item-padding");
5916 * gtk_icon_view_get_item_padding:
5917 * @icon_view: a #GtkIconView
5919 * Returns the value of the ::item-padding property.
5921 * Return value: the padding around items
5926 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5928 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5930 return icon_view->priv->item_padding;
5933 /* Get/set whether drag_motion requested the drag data and
5934 * drag_data_received should thus not actually insert the data,
5935 * since the data doesn't result from a drop.
5938 set_status_pending (GdkDragContext *context,
5939 GdkDragAction suggested_action)
5941 g_object_set_data (G_OBJECT (context),
5942 I_("gtk-icon-view-status-pending"),
5943 GINT_TO_POINTER (suggested_action));
5946 static GdkDragAction
5947 get_status_pending (GdkDragContext *context)
5949 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5950 "gtk-icon-view-status-pending"));
5954 unset_reorderable (GtkIconView *icon_view)
5956 if (icon_view->priv->reorderable)
5958 icon_view->priv->reorderable = FALSE;
5959 g_object_notify (G_OBJECT (icon_view), "reorderable");
5964 set_source_row (GdkDragContext *context,
5965 GtkTreeModel *model,
5966 GtkTreePath *source_row)
5969 g_object_set_data_full (G_OBJECT (context),
5970 I_("gtk-icon-view-source-row"),
5971 gtk_tree_row_reference_new (model, source_row),
5972 (GDestroyNotify) gtk_tree_row_reference_free);
5974 g_object_set_data_full (G_OBJECT (context),
5975 I_("gtk-icon-view-source-row"),
5980 get_source_row (GdkDragContext *context)
5982 GtkTreeRowReference *ref;
5984 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5987 return gtk_tree_row_reference_get_path (ref);
5994 GtkTreeRowReference *dest_row;
5995 gboolean empty_view_drop;
5996 gboolean drop_append_mode;
6000 dest_row_free (gpointer data)
6002 DestRow *dr = (DestRow *)data;
6004 gtk_tree_row_reference_free (dr->dest_row);
6009 set_dest_row (GdkDragContext *context,
6010 GtkTreeModel *model,
6011 GtkTreePath *dest_row,
6012 gboolean empty_view_drop,
6013 gboolean drop_append_mode)
6019 g_object_set_data_full (G_OBJECT (context),
6020 I_("gtk-icon-view-dest-row"),
6025 dr = g_new0 (DestRow, 1);
6027 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6028 dr->empty_view_drop = empty_view_drop;
6029 dr->drop_append_mode = drop_append_mode;
6030 g_object_set_data_full (G_OBJECT (context),
6031 I_("gtk-icon-view-dest-row"),
6032 dr, (GDestroyNotify) dest_row_free);
6036 get_dest_row (GdkDragContext *context)
6040 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6044 GtkTreePath *path = NULL;
6047 path = gtk_tree_row_reference_get_path (dr->dest_row);
6048 else if (dr->empty_view_drop)
6049 path = gtk_tree_path_new_from_indices (0, -1);
6053 if (path && dr->drop_append_mode)
6054 gtk_tree_path_next (path);
6063 check_model_dnd (GtkTreeModel *model,
6064 GType required_iface,
6065 const gchar *signal)
6067 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6069 g_warning ("You must override the default '%s' handler "
6070 "on GtkIconView when using models that don't support "
6071 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6072 "is to connect to '%s' and call "
6073 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6074 "the default handler from running. Look at the source code "
6075 "for the default handler in gtkiconview.c to get an idea what "
6076 "your handler should do. (gtkiconview.c is in the GTK+ source "
6077 "code.) If you're using GTK+ from a language other than C, "
6078 "there may be a more natural way to override default handlers, e.g. via derivation.",
6079 signal, g_type_name (required_iface), signal);
6087 remove_scroll_timeout (GtkIconView *icon_view)
6089 if (icon_view->priv->scroll_timeout_id != 0)
6091 g_source_remove (icon_view->priv->scroll_timeout_id);
6093 icon_view->priv->scroll_timeout_id = 0;
6098 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6102 gint px, py, width, height;
6103 gint hoffset, voffset;
6105 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6107 gdk_window_get_device_position (window, device, &px, &py, NULL);
6108 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
6110 /* see if we are near the edge. */
6111 voffset = py - 2 * SCROLL_EDGE_SIZE;
6113 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
6115 hoffset = px - 2 * SCROLL_EDGE_SIZE;
6117 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
6120 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6121 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6124 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6125 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6129 GtkIconView *icon_view;
6134 drag_scroll_timeout (gpointer datap)
6136 DragScrollData *data = datap;
6138 gtk_icon_view_autoscroll (data->icon_view, data->device);
6144 drag_scroll_data_free (DragScrollData *data)
6146 g_slice_free (DragScrollData, data);
6150 set_destination (GtkIconView *icon_view,
6151 GdkDragContext *context,
6154 GdkDragAction *suggested_action,
6158 GtkTreePath *path = NULL;
6159 GtkIconViewDropPosition pos;
6160 GtkIconViewDropPosition old_pos;
6161 GtkTreePath *old_dest_path = NULL;
6162 gboolean can_drop = FALSE;
6164 widget = GTK_WIDGET (icon_view);
6166 *suggested_action = 0;
6169 if (!icon_view->priv->dest_set)
6171 /* someone unset us as a drag dest, note that if
6172 * we return FALSE drag_leave isn't called
6175 gtk_icon_view_set_drag_dest_item (icon_view,
6177 GTK_ICON_VIEW_DROP_LEFT);
6179 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6181 return FALSE; /* no longer a drop site */
6184 *target = gtk_drag_dest_find_target (widget, context,
6185 gtk_drag_dest_get_target_list (widget));
6186 if (*target == GDK_NONE)
6189 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6192 GtkTreeModel *model;
6194 /* the row got dropped on empty space, let's setup a special case
6198 gtk_tree_path_free (path);
6200 model = gtk_icon_view_get_model (icon_view);
6202 n_children = gtk_tree_model_iter_n_children (model, NULL);
6205 pos = GTK_ICON_VIEW_DROP_BELOW;
6206 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6210 pos = GTK_ICON_VIEW_DROP_ABOVE;
6211 path = gtk_tree_path_new_from_indices (0, -1);
6221 gtk_icon_view_get_drag_dest_item (icon_view,
6226 gtk_tree_path_free (old_dest_path);
6228 if (TRUE /* FIXME if the location droppable predicate */)
6236 GtkWidget *source_widget;
6238 *suggested_action = gdk_drag_context_get_suggested_action (context);
6239 source_widget = gtk_drag_get_source_widget (context);
6241 if (source_widget == widget)
6243 /* Default to MOVE, unless the user has
6244 * pressed ctrl or shift to affect available actions
6246 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6247 *suggested_action = GDK_ACTION_MOVE;
6250 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6255 /* can't drop here */
6256 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6258 GTK_ICON_VIEW_DROP_LEFT);
6262 gtk_tree_path_free (path);
6268 get_logical_destination (GtkIconView *icon_view,
6269 gboolean *drop_append_mode)
6271 /* adjust path to point to the row the drop goes in front of */
6272 GtkTreePath *path = NULL;
6273 GtkIconViewDropPosition pos;
6275 *drop_append_mode = FALSE;
6277 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6282 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6283 pos == GTK_ICON_VIEW_DROP_BELOW)
6286 GtkTreeModel *model = icon_view->priv->model;
6288 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6289 !gtk_tree_model_iter_next (model, &iter))
6290 *drop_append_mode = TRUE;
6293 *drop_append_mode = FALSE;
6294 gtk_tree_path_next (path);
6302 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6303 GdkEventMotion *event)
6305 GtkWidget *widget = GTK_WIDGET (icon_view);
6306 GdkDragContext *context;
6307 GtkTreePath *path = NULL;
6309 GtkTreeModel *model;
6310 gboolean retval = FALSE;
6312 if (!icon_view->priv->source_set)
6315 if (icon_view->priv->pressed_button < 0)
6318 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6319 icon_view->priv->press_start_x,
6320 icon_view->priv->press_start_y,
6321 event->x, event->y))
6324 model = gtk_icon_view_get_model (icon_view);
6329 button = icon_view->priv->pressed_button;
6330 icon_view->priv->pressed_button = -1;
6332 path = gtk_icon_view_get_path_at_pos (icon_view,
6333 icon_view->priv->press_start_x,
6334 icon_view->priv->press_start_y);
6339 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6340 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6344 /* FIXME Check whether we're a start button, if not return FALSE and
6348 /* Now we can begin the drag */
6352 context = gtk_drag_begin (widget,
6353 gtk_drag_source_get_target_list (widget),
6354 icon_view->priv->source_actions,
6358 set_source_row (context, model, path);
6362 gtk_tree_path_free (path);
6367 /* Source side drag signals */
6369 gtk_icon_view_drag_begin (GtkWidget *widget,
6370 GdkDragContext *context)
6372 GtkIconView *icon_view;
6373 GtkIconViewItem *item;
6374 cairo_surface_t *icon;
6378 icon_view = GTK_ICON_VIEW (widget);
6380 /* if the user uses a custom DnD impl, we don't set the icon here */
6381 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6384 item = _gtk_icon_view_get_item_at_coords (icon_view,
6385 icon_view->priv->press_start_x,
6386 icon_view->priv->press_start_y,
6390 g_return_if_fail (item != NULL);
6392 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6393 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6395 path = gtk_tree_path_new_from_indices (item->index, -1);
6396 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6397 gtk_tree_path_free (path);
6399 cairo_surface_set_device_offset (icon, -x, -y);
6401 gtk_drag_set_icon_surface (context, icon);
6403 cairo_surface_destroy (icon);
6407 gtk_icon_view_drag_end (GtkWidget *widget,
6408 GdkDragContext *context)
6414 gtk_icon_view_drag_data_get (GtkWidget *widget,
6415 GdkDragContext *context,
6416 GtkSelectionData *selection_data,
6420 GtkIconView *icon_view;
6421 GtkTreeModel *model;
6422 GtkTreePath *source_row;
6424 icon_view = GTK_ICON_VIEW (widget);
6425 model = gtk_icon_view_get_model (icon_view);
6430 if (!icon_view->priv->source_set)
6433 source_row = get_source_row (context);
6435 if (source_row == NULL)
6438 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6439 * any model; for DragSource models there are some other targets
6443 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6444 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6449 /* If drag_data_get does nothing, try providing row data. */
6450 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6451 gtk_tree_set_row_drag_data (selection_data,
6456 gtk_tree_path_free (source_row);
6460 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6461 GdkDragContext *context)
6463 GtkTreeModel *model;
6464 GtkIconView *icon_view;
6465 GtkTreePath *source_row;
6467 icon_view = GTK_ICON_VIEW (widget);
6468 model = gtk_icon_view_get_model (icon_view);
6470 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6473 if (!icon_view->priv->source_set)
6476 source_row = get_source_row (context);
6478 if (source_row == NULL)
6481 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6484 gtk_tree_path_free (source_row);
6486 set_source_row (context, NULL, NULL);
6489 /* Target side drag signals */
6491 gtk_icon_view_drag_leave (GtkWidget *widget,
6492 GdkDragContext *context,
6495 GtkIconView *icon_view;
6497 icon_view = GTK_ICON_VIEW (widget);
6499 /* unset any highlight row */
6500 gtk_icon_view_set_drag_dest_item (icon_view,
6502 GTK_ICON_VIEW_DROP_LEFT);
6504 remove_scroll_timeout (icon_view);
6508 gtk_icon_view_drag_motion (GtkWidget *widget,
6509 GdkDragContext *context,
6514 GtkTreePath *path = NULL;
6515 GtkIconViewDropPosition pos;
6516 GtkIconView *icon_view;
6517 GdkDragAction suggested_action = 0;
6521 icon_view = GTK_ICON_VIEW (widget);
6523 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6526 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6528 /* we only know this *after* set_desination_row */
6529 empty = icon_view->priv->empty_view_drop;
6531 if (path == NULL && !empty)
6533 /* Can't drop here. */
6534 gdk_drag_status (context, 0, time);
6538 if (icon_view->priv->scroll_timeout_id == 0)
6540 DragScrollData *data = g_slice_new (DragScrollData);
6541 data->icon_view = icon_view;
6542 data->device = gdk_drag_context_get_device (context);
6544 icon_view->priv->scroll_timeout_id =
6545 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6548 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6550 /* Request data so we can use the source row when
6551 * determining whether to accept the drop
6553 set_status_pending (context, suggested_action);
6554 gtk_drag_get_data (widget, context, target, time);
6558 set_status_pending (context, 0);
6559 gdk_drag_status (context, suggested_action, time);
6564 gtk_tree_path_free (path);
6570 gtk_icon_view_drag_drop (GtkWidget *widget,
6571 GdkDragContext *context,
6576 GtkIconView *icon_view;
6578 GdkDragAction suggested_action = 0;
6579 GdkAtom target = GDK_NONE;
6580 GtkTreeModel *model;
6581 gboolean drop_append_mode;
6583 icon_view = GTK_ICON_VIEW (widget);
6584 model = gtk_icon_view_get_model (icon_view);
6586 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6588 if (!icon_view->priv->dest_set)
6591 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6594 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6597 path = get_logical_destination (icon_view, &drop_append_mode);
6599 if (target != GDK_NONE && path != NULL)
6601 /* in case a motion had requested drag data, change things so we
6602 * treat drag data receives as a drop.
6604 set_status_pending (context, 0);
6605 set_dest_row (context, model, path,
6606 icon_view->priv->empty_view_drop, drop_append_mode);
6610 gtk_tree_path_free (path);
6612 /* Unset this thing */
6613 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6615 if (target != GDK_NONE)
6617 gtk_drag_get_data (widget, context, target, time);
6625 gtk_icon_view_drag_data_received (GtkWidget *widget,
6626 GdkDragContext *context,
6629 GtkSelectionData *selection_data,
6634 gboolean accepted = FALSE;
6635 GtkTreeModel *model;
6636 GtkIconView *icon_view;
6637 GtkTreePath *dest_row;
6638 GdkDragAction suggested_action;
6639 gboolean drop_append_mode;
6641 icon_view = GTK_ICON_VIEW (widget);
6642 model = gtk_icon_view_get_model (icon_view);
6644 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6647 if (!icon_view->priv->dest_set)
6650 suggested_action = get_status_pending (context);
6652 if (suggested_action)
6654 /* We are getting this data due to a request in drag_motion,
6655 * rather than due to a request in drag_drop, so we are just
6656 * supposed to call drag_status, not actually paste in the
6659 path = get_logical_destination (icon_view, &drop_append_mode);
6662 suggested_action = 0;
6664 if (suggested_action)
6666 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6669 suggested_action = 0;
6672 gdk_drag_status (context, suggested_action, time);
6675 gtk_tree_path_free (path);
6677 /* If you can't drop, remove user drop indicator until the next motion */
6678 if (suggested_action == 0)
6679 gtk_icon_view_set_drag_dest_item (icon_view,
6681 GTK_ICON_VIEW_DROP_LEFT);
6686 dest_row = get_dest_row (context);
6688 if (dest_row == NULL)
6691 if (gtk_selection_data_get_length (selection_data) >= 0)
6693 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6699 gtk_drag_finish (context,
6701 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6704 gtk_tree_path_free (dest_row);
6707 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6710 /* Drag-and-Drop support */
6712 * gtk_icon_view_enable_model_drag_source:
6713 * @icon_view: a #GtkIconView
6714 * @start_button_mask: Mask of allowed buttons to start drag
6715 * @targets: (array length=n_targets): the table of targets that the drag will
6717 * @n_targets: the number of items in @targets
6718 * @actions: the bitmask of possible actions for a drag from this
6721 * Turns @icon_view into a drag source for automatic DND. Calling this
6722 * method sets #GtkIconView:reorderable to %FALSE.
6727 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6728 GdkModifierType start_button_mask,
6729 const GtkTargetEntry *targets,
6731 GdkDragAction actions)
6733 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6735 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6737 icon_view->priv->start_button_mask = start_button_mask;
6738 icon_view->priv->source_actions = actions;
6740 icon_view->priv->source_set = TRUE;
6742 unset_reorderable (icon_view);
6746 * gtk_icon_view_enable_model_drag_dest:
6747 * @icon_view: a #GtkIconView
6748 * @targets: (array length=n_targets): the table of targets that the drag will
6750 * @n_targets: the number of items in @targets
6751 * @actions: the bitmask of possible actions for a drag to this
6754 * Turns @icon_view into a drop destination for automatic DND. Calling this
6755 * method sets #GtkIconView:reorderable to %FALSE.
6760 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6761 const GtkTargetEntry *targets,
6763 GdkDragAction actions)
6765 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6767 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6769 icon_view->priv->dest_actions = actions;
6771 icon_view->priv->dest_set = TRUE;
6773 unset_reorderable (icon_view);
6777 * gtk_icon_view_unset_model_drag_source:
6778 * @icon_view: a #GtkIconView
6780 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6781 * method sets #GtkIconView:reorderable to %FALSE.
6786 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6788 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6790 if (icon_view->priv->source_set)
6792 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6793 icon_view->priv->source_set = FALSE;
6796 unset_reorderable (icon_view);
6800 * gtk_icon_view_unset_model_drag_dest:
6801 * @icon_view: a #GtkIconView
6803 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6804 * method sets #GtkIconView:reorderable to %FALSE.
6809 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6811 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6813 if (icon_view->priv->dest_set)
6815 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6816 icon_view->priv->dest_set = FALSE;
6819 unset_reorderable (icon_view);
6822 /* These are useful to implement your own custom stuff. */
6824 * gtk_icon_view_set_drag_dest_item:
6825 * @icon_view: a #GtkIconView
6826 * @path: (allow-none): The path of the item to highlight, or %NULL.
6827 * @pos: Specifies where to drop, relative to the item
6829 * Sets the item that is highlighted for feedback.
6834 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6836 GtkIconViewDropPosition pos)
6838 /* Note; this function is exported to allow a custom DND
6839 * implementation, so it can't touch TreeViewDragInfo
6842 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6844 if (icon_view->priv->dest_item)
6846 GtkTreePath *current_path;
6847 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6848 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6849 icon_view->priv->dest_item = NULL;
6851 gtk_icon_view_queue_draw_path (icon_view, current_path);
6852 gtk_tree_path_free (current_path);
6855 /* special case a drop on an empty model */
6856 icon_view->priv->empty_view_drop = FALSE;
6857 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6858 && gtk_tree_path_get_depth (path) == 1
6859 && gtk_tree_path_get_indices (path)[0] == 0)
6863 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6866 if (n_children == 0)
6867 icon_view->priv->empty_view_drop = TRUE;
6870 icon_view->priv->dest_pos = pos;
6874 icon_view->priv->dest_item =
6875 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6876 icon_view->priv->model, path);
6878 gtk_icon_view_queue_draw_path (icon_view, path);
6883 * gtk_icon_view_get_drag_dest_item:
6884 * @icon_view: a #GtkIconView
6885 * @path: (out) (allow-none): Return location for the path of
6886 * the highlighted item, or %NULL.
6887 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6889 * Gets information about the item that is highlighted for feedback.
6894 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6896 GtkIconViewDropPosition *pos)
6898 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6902 if (icon_view->priv->dest_item)
6903 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6909 *pos = icon_view->priv->dest_pos;
6913 * gtk_icon_view_get_dest_item_at_pos:
6914 * @icon_view: a #GtkIconView
6915 * @drag_x: the position to determine the destination item for
6916 * @drag_y: the position to determine the destination item for
6917 * @path: (out) (allow-none): Return location for the path of the item,
6919 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6921 * Determines the destination item for a given position.
6923 * Return value: whether there is an item at the given position.
6928 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6932 GtkIconViewDropPosition *pos)
6934 GtkIconViewItem *item;
6936 /* Note; this function is exported to allow a custom DND
6937 * implementation, so it can't touch TreeViewDragInfo
6940 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6941 g_return_val_if_fail (drag_x >= 0, FALSE);
6942 g_return_val_if_fail (drag_y >= 0, FALSE);
6943 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6949 item = _gtk_icon_view_get_item_at_coords (icon_view,
6950 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6951 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6958 *path = gtk_tree_path_new_from_indices (item->index, -1);
6962 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6963 *pos = GTK_ICON_VIEW_DROP_LEFT;
6964 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6965 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6966 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6967 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6968 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6969 *pos = GTK_ICON_VIEW_DROP_BELOW;
6971 *pos = GTK_ICON_VIEW_DROP_INTO;
6978 * gtk_icon_view_create_drag_icon:
6979 * @icon_view: a #GtkIconView
6980 * @path: a #GtkTreePath in @icon_view
6982 * Creates a #cairo_surface_t representation of the item at @path.
6983 * This image is used for a drag icon.
6985 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6990 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6994 GtkStyleContext *context;
6996 cairo_surface_t *surface;
7000 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7001 g_return_val_if_fail (path != NULL, NULL);
7003 widget = GTK_WIDGET (icon_view);
7004 context = gtk_widget_get_style_context (widget);
7006 if (!gtk_widget_get_realized (widget))
7009 index = gtk_tree_path_get_indices (path)[0];
7011 for (l = icon_view->priv->items; l; l = l->next)
7013 GtkIconViewItem *item = l->data;
7015 if (index == item->index)
7017 GdkRectangle rect = {
7018 item->cell_area.x - icon_view->priv->item_padding,
7019 item->cell_area.y - icon_view->priv->item_padding,
7020 item->cell_area.width + icon_view->priv->item_padding * 2,
7021 item->cell_area.height + icon_view->priv->item_padding * 2
7024 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
7025 CAIRO_CONTENT_COLOR,
7029 cr = cairo_create (surface);
7030 cairo_set_line_width (cr, 1.);
7032 gtk_render_background (context, cr, 0, 0,
7033 rect.width + 2, rect.height + 2);
7037 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
7040 gtk_icon_view_paint_item (icon_view, cr, item,
7041 icon_view->priv->item_padding + 1,
7042 icon_view->priv->item_padding + 1, FALSE);
7046 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7047 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
7060 * gtk_icon_view_get_reorderable:
7061 * @icon_view: a #GtkIconView
7063 * Retrieves whether the user can reorder the list via drag-and-drop.
7064 * See gtk_icon_view_set_reorderable().
7066 * Return value: %TRUE if the list can be reordered.
7071 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7073 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7075 return icon_view->priv->reorderable;
7078 static const GtkTargetEntry item_targets[] = {
7079 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7084 * gtk_icon_view_set_reorderable:
7085 * @icon_view: A #GtkIconView.
7086 * @reorderable: %TRUE, if the list of items can be reordered.
7088 * This function is a convenience function to allow you to reorder models that
7089 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7090 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7091 * the user can reorder the model by dragging and dropping rows. The
7092 * developer can listen to these changes by connecting to the model's
7093 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7094 * the icon view as a drag source and destination. Therefore, drag and
7095 * drop can not be used in a reorderable view for any other purpose.
7097 * This function does not give you any degree of control over the order -- any
7098 * reordering is allowed. If more control is needed, you should probably
7099 * handle drag and drop manually.
7104 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7105 gboolean reorderable)
7107 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7109 reorderable = reorderable != FALSE;
7111 if (icon_view->priv->reorderable == reorderable)
7116 gtk_icon_view_enable_model_drag_source (icon_view,
7119 G_N_ELEMENTS (item_targets),
7121 gtk_icon_view_enable_model_drag_dest (icon_view,
7123 G_N_ELEMENTS (item_targets),
7128 gtk_icon_view_unset_model_drag_source (icon_view);
7129 gtk_icon_view_unset_model_drag_dest (icon_view);
7132 icon_view->priv->reorderable = reorderable;
7134 g_object_notify (G_OBJECT (icon_view), "reorderable");
7138 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7139 GtkBuilder *builder,
7141 const gchar *tagname,
7142 GMarkupParser *parser,
7145 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7146 tagname, parser, data))
7149 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7150 tagname, parser, data);
7154 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7155 GtkBuilder *builder,
7157 const gchar *tagname,
7160 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7161 child, tagname, data))
7162 parent_buildable_iface->custom_tag_end (buildable, builder,
7163 child, tagname, data);