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,
114 PROP_ACTIVATE_ON_SINGLE_CLICK
118 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
119 static void gtk_icon_view_dispose (GObject *object);
120 static GObject *gtk_icon_view_constructor (GType type,
121 guint n_construct_properties,
122 GObjectConstructParam *construct_properties);
123 static void gtk_icon_view_set_property (GObject *object,
127 static void gtk_icon_view_get_property (GObject *object,
131 /* GtkWidget vfuncs */
132 static void gtk_icon_view_destroy (GtkWidget *widget);
133 static void gtk_icon_view_realize (GtkWidget *widget);
134 static void gtk_icon_view_unrealize (GtkWidget *widget);
135 static GtkSizeRequestMode gtk_icon_view_get_request_mode (GtkWidget *widget);
136 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
139 static void gtk_icon_view_get_preferred_width_for_height
144 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
147 static void gtk_icon_view_get_preferred_height_for_width
152 static void gtk_icon_view_size_allocate (GtkWidget *widget,
153 GtkAllocation *allocation);
154 static gboolean gtk_icon_view_draw (GtkWidget *widget,
156 static gboolean gtk_icon_view_motion (GtkWidget *widget,
157 GdkEventMotion *event);
158 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
159 GdkEventButton *event);
160 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
161 GdkEventButton *event);
162 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
164 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
168 /* GtkContainer vfuncs */
169 static void gtk_icon_view_remove (GtkContainer *container,
171 static void gtk_icon_view_forall (GtkContainer *container,
172 gboolean include_internals,
173 GtkCallback callback,
174 gpointer callback_data);
176 /* GtkIconView vfuncs */
177 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
178 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
179 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
180 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
181 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
183 /* Internal functions */
184 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
185 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
186 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
187 GtkAdjustment *adjustment);
188 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
189 GtkAdjustment *adjustment);
190 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
191 GtkIconView *icon_view);
192 static void gtk_icon_view_layout (GtkIconView *icon_view);
193 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
195 GtkIconViewItem *item,
198 gboolean draw_focus);
199 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
201 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
203 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
204 GtkIconViewItem *item);
205 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
209 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
210 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
211 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
212 GtkIconViewItem *item,
217 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
218 static void gtk_icon_view_update_rubberband (gpointer data);
219 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
220 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
221 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
224 GtkMovementStep step,
226 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
227 GtkMovementStep step,
229 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
231 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
233 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
235 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
237 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
238 GtkIconViewItem *item);
239 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
240 GtkIconViewItem *anchor,
241 GtkIconViewItem *cursor);
243 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
244 GtkCellArea *cell_area);
246 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
248 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
249 GtkIconViewItem *item);
251 static void gtk_icon_view_add_editable (GtkCellArea *area,
252 GtkCellRenderer *renderer,
253 GtkCellEditable *editable,
254 GdkRectangle *cell_area,
256 GtkIconView *icon_view);
257 static void gtk_icon_view_remove_editable (GtkCellArea *area,
258 GtkCellRenderer *renderer,
259 GtkCellEditable *editable,
260 GtkIconView *icon_view);
261 static void update_text_cell (GtkIconView *icon_view);
262 static void update_pixbuf_cell (GtkIconView *icon_view);
264 /* Source side drag signals */
265 static void gtk_icon_view_drag_begin (GtkWidget *widget,
266 GdkDragContext *context);
267 static void gtk_icon_view_drag_end (GtkWidget *widget,
268 GdkDragContext *context);
269 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
270 GdkDragContext *context,
271 GtkSelectionData *selection_data,
274 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
275 GdkDragContext *context);
277 /* Target side drag signals */
278 static void gtk_icon_view_drag_leave (GtkWidget *widget,
279 GdkDragContext *context,
281 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
282 GdkDragContext *context,
286 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
287 GdkDragContext *context,
291 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
292 GdkDragContext *context,
295 GtkSelectionData *selection_data,
298 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
299 GdkEventMotion *event);
301 static void remove_scroll_timeout (GtkIconView *icon_view);
304 static GtkBuildableIface *parent_buildable_iface;
305 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
306 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
309 const gchar *tagname,
310 GMarkupParser *parser,
312 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
315 const gchar *tagname,
318 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
320 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
321 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
322 gtk_icon_view_cell_layout_init)
323 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
324 gtk_icon_view_buildable_init)
325 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
328 gtk_icon_view_class_init (GtkIconViewClass *klass)
330 GObjectClass *gobject_class;
331 GtkWidgetClass *widget_class;
332 GtkContainerClass *container_class;
333 GtkBindingSet *binding_set;
335 binding_set = gtk_binding_set_by_class (klass);
337 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
339 gobject_class = (GObjectClass *) klass;
340 widget_class = (GtkWidgetClass *) klass;
341 container_class = (GtkContainerClass *) klass;
343 gobject_class->constructor = gtk_icon_view_constructor;
344 gobject_class->dispose = gtk_icon_view_dispose;
345 gobject_class->set_property = gtk_icon_view_set_property;
346 gobject_class->get_property = gtk_icon_view_get_property;
348 widget_class->destroy = gtk_icon_view_destroy;
349 widget_class->realize = gtk_icon_view_realize;
350 widget_class->unrealize = gtk_icon_view_unrealize;
351 widget_class->get_request_mode = gtk_icon_view_get_request_mode;
352 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
353 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
354 widget_class->get_preferred_width_for_height = gtk_icon_view_get_preferred_width_for_height;
355 widget_class->get_preferred_height_for_width = gtk_icon_view_get_preferred_height_for_width;
356 widget_class->size_allocate = gtk_icon_view_size_allocate;
357 widget_class->draw = gtk_icon_view_draw;
358 widget_class->motion_notify_event = gtk_icon_view_motion;
359 widget_class->button_press_event = gtk_icon_view_button_press;
360 widget_class->button_release_event = gtk_icon_view_button_release;
361 widget_class->key_press_event = gtk_icon_view_key_press;
362 widget_class->key_release_event = gtk_icon_view_key_release;
363 widget_class->drag_begin = gtk_icon_view_drag_begin;
364 widget_class->drag_end = gtk_icon_view_drag_end;
365 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
366 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
367 widget_class->drag_leave = gtk_icon_view_drag_leave;
368 widget_class->drag_motion = gtk_icon_view_drag_motion;
369 widget_class->drag_drop = gtk_icon_view_drag_drop;
370 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
372 container_class->remove = gtk_icon_view_remove;
373 container_class->forall = gtk_icon_view_forall;
375 klass->select_all = gtk_icon_view_real_select_all;
376 klass->unselect_all = gtk_icon_view_real_unselect_all;
377 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
378 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
379 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
380 klass->move_cursor = gtk_icon_view_real_move_cursor;
384 * GtkIconView:selection-mode:
386 * The ::selection-mode property specifies the selection mode of
387 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
388 * is enabled, for the other modes, only keyboard selection is possible.
392 g_object_class_install_property (gobject_class,
394 g_param_spec_enum ("selection-mode",
395 P_("Selection mode"),
396 P_("The selection mode"),
397 GTK_TYPE_SELECTION_MODE,
398 GTK_SELECTION_SINGLE,
399 GTK_PARAM_READWRITE));
402 * GtkIconView:pixbuf-column:
404 * The ::pixbuf-column property contains the number of the model column
405 * containing the pixbufs which are displayed. The pixbuf column must be
406 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
407 * display of pixbufs.
411 g_object_class_install_property (gobject_class,
413 g_param_spec_int ("pixbuf-column",
415 P_("Model column used to retrieve the icon pixbuf from"),
417 GTK_PARAM_READWRITE));
420 * GtkIconView:text-column:
422 * The ::text-column property contains the number of the model column
423 * containing the texts which are displayed. The text column must be
424 * of type #G_TYPE_STRING. If this property and the :markup-column
425 * property are both set to -1, no texts are displayed.
429 g_object_class_install_property (gobject_class,
431 g_param_spec_int ("text-column",
433 P_("Model column used to retrieve the text from"),
435 GTK_PARAM_READWRITE));
439 * GtkIconView:markup-column:
441 * The ::markup-column property contains the number of the model column
442 * containing markup information to be displayed. The markup column must be
443 * of type #G_TYPE_STRING. If this property and the :text-column property
444 * are both set to column numbers, it overrides the text column.
445 * If both are set to -1, no texts are displayed.
449 g_object_class_install_property (gobject_class,
451 g_param_spec_int ("markup-column",
453 P_("Model column used to retrieve the text if using Pango markup"),
455 GTK_PARAM_READWRITE));
457 g_object_class_install_property (gobject_class,
459 g_param_spec_object ("model",
460 P_("Icon View Model"),
461 P_("The model for the icon view"),
463 GTK_PARAM_READWRITE));
466 * GtkIconView:columns:
468 * The columns property contains the number of the columns in which the
469 * items should be displayed. If it is -1, the number of columns will
470 * be chosen automatically to fill the available area.
474 g_object_class_install_property (gobject_class,
476 g_param_spec_int ("columns",
477 P_("Number of columns"),
478 P_("Number of columns to display"),
480 GTK_PARAM_READWRITE));
484 * GtkIconView:item-width:
486 * The item-width property specifies the width to use for each item.
487 * If it is set to -1, the icon view will automatically determine a
488 * suitable item size.
492 g_object_class_install_property (gobject_class,
494 g_param_spec_int ("item-width",
495 P_("Width for each item"),
496 P_("The width used for each item"),
498 GTK_PARAM_READWRITE));
501 * GtkIconView:spacing:
503 * The spacing property specifies the space which is inserted between
504 * the cells (i.e. the icon and the text) of an item.
508 g_object_class_install_property (gobject_class,
510 g_param_spec_int ("spacing",
512 P_("Space which is inserted between cells of an item"),
514 GTK_PARAM_READWRITE));
517 * GtkIconView:row-spacing:
519 * The row-spacing property specifies the space which is inserted between
520 * the rows of the icon view.
524 g_object_class_install_property (gobject_class,
526 g_param_spec_int ("row-spacing",
528 P_("Space which is inserted between grid rows"),
530 GTK_PARAM_READWRITE));
533 * GtkIconView:column-spacing:
535 * The column-spacing property specifies the space which is inserted between
536 * the columns of the icon view.
540 g_object_class_install_property (gobject_class,
542 g_param_spec_int ("column-spacing",
543 P_("Column Spacing"),
544 P_("Space which is inserted between grid columns"),
546 GTK_PARAM_READWRITE));
549 * GtkIconView:margin:
551 * The margin property specifies the space which is inserted
552 * at the edges of the icon view.
556 g_object_class_install_property (gobject_class,
558 g_param_spec_int ("margin",
560 P_("Space which is inserted at the edges of the icon view"),
562 GTK_PARAM_READWRITE));
565 * GtkIconView:item-orientation:
567 * The item-orientation property specifies how the cells (i.e. the icon and
568 * the text) of the item are positioned relative to each other.
572 g_object_class_install_property (gobject_class,
573 PROP_ITEM_ORIENTATION,
574 g_param_spec_enum ("item-orientation",
575 P_("Item Orientation"),
576 P_("How the text and icon of each item are positioned relative to each other"),
577 GTK_TYPE_ORIENTATION,
578 GTK_ORIENTATION_VERTICAL,
579 GTK_PARAM_READWRITE));
582 * GtkIconView:reorderable:
584 * The reorderable property specifies if the items can be reordered
589 g_object_class_install_property (gobject_class,
591 g_param_spec_boolean ("reorderable",
593 P_("View is reorderable"),
597 g_object_class_install_property (gobject_class,
599 g_param_spec_int ("tooltip-column",
600 P_("Tooltip Column"),
601 P_("The column in the model containing the tooltip texts for the items"),
605 GTK_PARAM_READWRITE));
608 * GtkIconView:item-padding:
610 * The item-padding property specifies the padding around each
611 * of the icon view's item.
615 g_object_class_install_property (gobject_class,
617 g_param_spec_int ("item-padding",
619 P_("Padding around icon view items"),
621 GTK_PARAM_READWRITE));
624 * GtkIconView:cell-area:
626 * The #GtkCellArea used to layout cell renderers for this view.
628 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
629 * a #GtkCellAreaBox will be used.
633 g_object_class_install_property (gobject_class,
635 g_param_spec_object ("cell-area",
637 P_("The GtkCellArea used to layout cells"),
639 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
642 * GtkIconView:activate-on-single-click:
644 * The activate-on-single-click property specifies whether the "item-activated" signal
645 * will be emitted after a single click.
649 g_object_class_install_property (gobject_class,
650 PROP_ACTIVATE_ON_SINGLE_CLICK,
651 g_param_spec_boolean ("activate-on-single-click",
652 P_("Activate on Single Click"),
653 P_("Activate row on a single click"),
655 GTK_PARAM_READWRITE));
657 /* Scrollable interface properties */
658 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
659 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
660 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
661 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
663 /* Style properties */
664 gtk_widget_class_install_style_property (widget_class,
665 g_param_spec_boxed ("selection-box-color",
666 P_("Selection Box Color"),
667 P_("Color of the selection box"),
669 GTK_PARAM_READABLE));
671 gtk_widget_class_install_style_property (widget_class,
672 g_param_spec_uchar ("selection-box-alpha",
673 P_("Selection Box Alpha"),
674 P_("Opacity of the selection box"),
677 GTK_PARAM_READABLE));
681 * GtkIconView::item-activated:
682 * @iconview: the object on which the signal is emitted
683 * @path: the #GtkTreePath for the activated item
685 * The ::item-activated signal is emitted when the method
686 * gtk_icon_view_item_activated() is called, when the user double
687 * clicks an item with the "activate-on-single-click" property set
688 * to %FALSE, or when the user single clicks an item when the
689 * "activate-on-single-click" property set to %TRUE. It is also
690 * emitted when a non-editable item is selected and one of the keys:
691 * Space, Return or Enter is pressed.
693 icon_view_signals[ITEM_ACTIVATED] =
694 g_signal_new (I_("item-activated"),
695 G_TYPE_FROM_CLASS (gobject_class),
697 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
699 g_cclosure_marshal_VOID__BOXED,
704 * GtkIconView::selection-changed:
705 * @iconview: the object on which the signal is emitted
707 * The ::selection-changed signal is emitted when the selection
708 * (i.e. the set of selected items) changes.
710 icon_view_signals[SELECTION_CHANGED] =
711 g_signal_new (I_("selection-changed"),
712 G_TYPE_FROM_CLASS (gobject_class),
714 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
716 g_cclosure_marshal_VOID__VOID,
720 * GtkIconView::select-all:
721 * @iconview: the object on which the signal is emitted
723 * A <link linkend="keybinding-signals">keybinding signal</link>
724 * which gets emitted when the user selects all items.
726 * Applications should not connect to it, but may emit it with
727 * g_signal_emit_by_name() if they need to control selection
730 * The default binding for this signal is Ctrl-a.
732 icon_view_signals[SELECT_ALL] =
733 g_signal_new (I_("select-all"),
734 G_TYPE_FROM_CLASS (gobject_class),
735 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
736 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
738 g_cclosure_marshal_VOID__VOID,
742 * GtkIconView::unselect-all:
743 * @iconview: the object on which the signal is emitted
745 * A <link linkend="keybinding-signals">keybinding signal</link>
746 * which gets emitted when the user unselects all items.
748 * Applications should not connect to it, but may emit it with
749 * g_signal_emit_by_name() if they need to control selection
752 * The default binding for this signal is Ctrl-Shift-a.
754 icon_view_signals[UNSELECT_ALL] =
755 g_signal_new (I_("unselect-all"),
756 G_TYPE_FROM_CLASS (gobject_class),
757 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
758 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
760 g_cclosure_marshal_VOID__VOID,
764 * GtkIconView::select-cursor-item:
765 * @iconview: the object on which the signal is emitted
767 * A <link linkend="keybinding-signals">keybinding signal</link>
768 * which gets emitted when the user selects the item that is currently
771 * Applications should not connect to it, but may emit it with
772 * g_signal_emit_by_name() if they need to control selection
775 * There is no default binding for this signal.
777 icon_view_signals[SELECT_CURSOR_ITEM] =
778 g_signal_new (I_("select-cursor-item"),
779 G_TYPE_FROM_CLASS (gobject_class),
780 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
781 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
783 g_cclosure_marshal_VOID__VOID,
787 * GtkIconView::toggle-cursor-item:
788 * @iconview: the object on which the signal is emitted
790 * A <link linkend="keybinding-signals">keybinding signal</link>
791 * which gets emitted when the user toggles whether the currently
792 * focused item is selected or not. The exact effect of this
793 * depend on the selection mode.
795 * Applications should not connect to it, but may emit it with
796 * g_signal_emit_by_name() if they need to control selection
799 * There is no default binding for this signal is Ctrl-Space.
801 icon_view_signals[TOGGLE_CURSOR_ITEM] =
802 g_signal_new (I_("toggle-cursor-item"),
803 G_TYPE_FROM_CLASS (gobject_class),
804 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
805 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
807 g_cclosure_marshal_VOID__VOID,
811 * GtkIconView::activate-cursor-item:
812 * @iconview: the object on which the signal is emitted
814 * A <link linkend="keybinding-signals">keybinding signal</link>
815 * which gets emitted when the user activates the currently
818 * Applications should not connect to it, but may emit it with
819 * g_signal_emit_by_name() if they need to control activation
822 * The default bindings for this signal are Space, Return and Enter.
824 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
825 g_signal_new (I_("activate-cursor-item"),
826 G_TYPE_FROM_CLASS (gobject_class),
827 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
828 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
830 _gtk_marshal_BOOLEAN__VOID,
834 * GtkIconView::move-cursor:
835 * @iconview: the object which received the signal
836 * @step: the granularity of the move, as a #GtkMovementStep
837 * @count: the number of @step units to move
839 * The ::move-cursor signal is a
840 * <link linkend="keybinding-signals">keybinding signal</link>
841 * which gets emitted when the user initiates a cursor movement.
843 * Applications should not connect to it, but may emit it with
844 * g_signal_emit_by_name() if they need to control the cursor
847 * The default bindings for this signal include
849 * <listitem>Arrow keys which move by individual steps</listitem>
850 * <listitem>Home/End keys which move to the first/last item</listitem>
851 * <listitem>PageUp/PageDown which move by "pages"</listitem>
854 * All of these will extend the selection when combined with
855 * the Shift modifier.
857 icon_view_signals[MOVE_CURSOR] =
858 g_signal_new (I_("move-cursor"),
859 G_TYPE_FROM_CLASS (gobject_class),
860 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
861 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
863 _gtk_marshal_BOOLEAN__ENUM_INT,
865 GTK_TYPE_MOVEMENT_STEP,
869 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
871 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
873 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
874 "toggle-cursor-item", 0);
875 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
876 "toggle-cursor-item", 0);
878 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
879 "activate-cursor-item", 0);
880 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
881 "activate-cursor-item", 0);
882 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
883 "activate-cursor-item", 0);
884 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
885 "activate-cursor-item", 0);
886 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
887 "activate-cursor-item", 0);
889 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
890 GTK_MOVEMENT_DISPLAY_LINES, -1);
891 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
892 GTK_MOVEMENT_DISPLAY_LINES, -1);
894 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
895 GTK_MOVEMENT_DISPLAY_LINES, 1);
896 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
897 GTK_MOVEMENT_DISPLAY_LINES, 1);
899 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
900 GTK_MOVEMENT_DISPLAY_LINES, -1);
902 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
903 GTK_MOVEMENT_DISPLAY_LINES, 1);
905 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
906 GTK_MOVEMENT_BUFFER_ENDS, -1);
907 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
908 GTK_MOVEMENT_BUFFER_ENDS, -1);
910 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
911 GTK_MOVEMENT_BUFFER_ENDS, 1);
912 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
913 GTK_MOVEMENT_BUFFER_ENDS, 1);
915 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
916 GTK_MOVEMENT_PAGES, -1);
917 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
918 GTK_MOVEMENT_PAGES, -1);
920 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
921 GTK_MOVEMENT_PAGES, 1);
922 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
923 GTK_MOVEMENT_PAGES, 1);
925 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
926 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
927 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
928 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
930 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
931 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
932 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
933 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
935 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
939 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
941 parent_buildable_iface = g_type_interface_peek_parent (iface);
942 iface->add_child = _gtk_cell_layout_buildable_add_child;
943 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
944 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
948 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
950 iface->get_area = gtk_icon_view_cell_layout_get_area;
954 gtk_icon_view_init (GtkIconView *icon_view)
956 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
960 icon_view->priv->width = 0;
961 icon_view->priv->height = 0;
962 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
963 icon_view->priv->pressed_button = -1;
964 icon_view->priv->press_start_x = -1;
965 icon_view->priv->press_start_y = -1;
966 icon_view->priv->text_column = -1;
967 icon_view->priv->markup_column = -1;
968 icon_view->priv->pixbuf_column = -1;
969 icon_view->priv->text_cell = NULL;
970 icon_view->priv->pixbuf_cell = NULL;
971 icon_view->priv->tooltip_column = -1;
973 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
975 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
977 icon_view->priv->columns = -1;
978 icon_view->priv->item_width = -1;
979 icon_view->priv->spacing = 0;
980 icon_view->priv->row_spacing = 6;
981 icon_view->priv->column_spacing = 6;
982 icon_view->priv->margin = 6;
983 icon_view->priv->item_padding = 6;
984 icon_view->priv->activate_on_single_click = FALSE;
986 icon_view->priv->draw_focus = TRUE;
988 icon_view->priv->row_contexts =
989 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
991 gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (icon_view)),
992 GTK_STYLE_CLASS_VIEW);
995 /* GObject methods */
997 gtk_icon_view_constructor (GType type,
998 guint n_construct_properties,
999 GObjectConstructParam *construct_properties)
1001 GtkIconView *icon_view;
1004 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1005 (type, n_construct_properties, construct_properties);
1007 icon_view = (GtkIconView *) object;
1009 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1015 gtk_icon_view_dispose (GObject *object)
1017 GtkIconView *icon_view;
1018 GtkIconViewPrivate *priv;
1020 icon_view = GTK_ICON_VIEW (object);
1021 priv = icon_view->priv;
1023 if (priv->cell_area_context)
1025 g_object_unref (priv->cell_area_context);
1026 priv->cell_area_context = NULL;
1029 if (priv->row_contexts)
1031 g_ptr_array_free (priv->row_contexts, TRUE);
1032 priv->row_contexts = NULL;
1035 if (priv->cell_area)
1037 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1039 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1040 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1041 priv->add_editable_id = 0;
1042 priv->remove_editable_id = 0;
1044 g_object_unref (priv->cell_area);
1045 priv->cell_area = NULL;
1048 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1052 gtk_icon_view_set_property (GObject *object,
1054 const GValue *value,
1057 GtkIconView *icon_view;
1060 icon_view = GTK_ICON_VIEW (object);
1064 case PROP_SELECTION_MODE:
1065 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1067 case PROP_PIXBUF_COLUMN:
1068 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1070 case PROP_TEXT_COLUMN:
1071 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1073 case PROP_MARKUP_COLUMN:
1074 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1077 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1079 case PROP_ITEM_ORIENTATION:
1080 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1083 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1085 case PROP_ITEM_WIDTH:
1086 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1089 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1091 case PROP_ROW_SPACING:
1092 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1094 case PROP_COLUMN_SPACING:
1095 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1098 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1100 case PROP_REORDERABLE:
1101 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1104 case PROP_TOOLTIP_COLUMN:
1105 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1108 case PROP_ITEM_PADDING:
1109 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1112 case PROP_ACTIVATE_ON_SINGLE_CLICK:
1113 gtk_icon_view_set_activate_on_single_click (icon_view, g_value_get_boolean (value));
1116 case PROP_CELL_AREA:
1117 /* Construct-only, can only be assigned once */
1118 area = g_value_get_object (value);
1121 if (icon_view->priv->cell_area != NULL)
1123 g_warning ("cell-area has already been set, ignoring construct property");
1124 g_object_ref_sink (area);
1125 g_object_unref (area);
1128 gtk_icon_view_ensure_cell_area (icon_view, area);
1132 case PROP_HADJUSTMENT:
1133 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1135 case PROP_VADJUSTMENT:
1136 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1138 case PROP_HSCROLL_POLICY:
1139 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1140 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1142 case PROP_VSCROLL_POLICY:
1143 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1144 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1148 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1154 gtk_icon_view_get_property (GObject *object,
1159 GtkIconView *icon_view;
1161 icon_view = GTK_ICON_VIEW (object);
1165 case PROP_SELECTION_MODE:
1166 g_value_set_enum (value, icon_view->priv->selection_mode);
1168 case PROP_PIXBUF_COLUMN:
1169 g_value_set_int (value, icon_view->priv->pixbuf_column);
1171 case PROP_TEXT_COLUMN:
1172 g_value_set_int (value, icon_view->priv->text_column);
1174 case PROP_MARKUP_COLUMN:
1175 g_value_set_int (value, icon_view->priv->markup_column);
1178 g_value_set_object (value, icon_view->priv->model);
1180 case PROP_ITEM_ORIENTATION:
1181 g_value_set_enum (value, icon_view->priv->item_orientation);
1184 g_value_set_int (value, icon_view->priv->columns);
1186 case PROP_ITEM_WIDTH:
1187 g_value_set_int (value, icon_view->priv->item_width);
1190 g_value_set_int (value, icon_view->priv->spacing);
1192 case PROP_ROW_SPACING:
1193 g_value_set_int (value, icon_view->priv->row_spacing);
1195 case PROP_COLUMN_SPACING:
1196 g_value_set_int (value, icon_view->priv->column_spacing);
1199 g_value_set_int (value, icon_view->priv->margin);
1201 case PROP_REORDERABLE:
1202 g_value_set_boolean (value, icon_view->priv->reorderable);
1204 case PROP_TOOLTIP_COLUMN:
1205 g_value_set_int (value, icon_view->priv->tooltip_column);
1208 case PROP_ITEM_PADDING:
1209 g_value_set_int (value, icon_view->priv->item_padding);
1212 case PROP_ACTIVATE_ON_SINGLE_CLICK:
1213 g_value_set_boolean (value, icon_view->priv->activate_on_single_click);
1216 case PROP_CELL_AREA:
1217 g_value_set_object (value, icon_view->priv->cell_area);
1220 case PROP_HADJUSTMENT:
1221 g_value_set_object (value, icon_view->priv->hadjustment);
1223 case PROP_VADJUSTMENT:
1224 g_value_set_object (value, icon_view->priv->vadjustment);
1226 case PROP_HSCROLL_POLICY:
1227 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1229 case PROP_VSCROLL_POLICY:
1230 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1234 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1239 /* GtkWidget methods */
1241 gtk_icon_view_destroy (GtkWidget *widget)
1243 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1245 gtk_icon_view_set_model (icon_view, NULL);
1247 if (icon_view->priv->scroll_to_path != NULL)
1249 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1250 icon_view->priv->scroll_to_path = NULL;
1253 remove_scroll_timeout (icon_view);
1255 if (icon_view->priv->hadjustment != NULL)
1257 g_object_unref (icon_view->priv->hadjustment);
1258 icon_view->priv->hadjustment = NULL;
1261 if (icon_view->priv->vadjustment != NULL)
1263 g_object_unref (icon_view->priv->vadjustment);
1264 icon_view->priv->vadjustment = NULL;
1267 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1271 gtk_icon_view_realize (GtkWidget *widget)
1273 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1274 GtkAllocation allocation;
1276 GdkWindowAttr attributes;
1277 gint attributes_mask;
1279 gtk_widget_set_realized (widget, TRUE);
1281 gtk_widget_get_allocation (widget, &allocation);
1283 /* Make the main, clipping window */
1284 attributes.window_type = GDK_WINDOW_CHILD;
1285 attributes.x = allocation.x;
1286 attributes.y = allocation.y;
1287 attributes.width = allocation.width;
1288 attributes.height = allocation.height;
1289 attributes.wclass = GDK_INPUT_OUTPUT;
1290 attributes.visual = gtk_widget_get_visual (widget);
1291 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1293 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1295 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1296 &attributes, attributes_mask);
1297 gtk_widget_set_window (widget, window);
1298 gdk_window_set_user_data (window, widget);
1300 gtk_widget_get_allocation (widget, &allocation);
1302 /* Make the window for the icon view */
1305 attributes.width = MAX (icon_view->priv->width, allocation.width);
1306 attributes.height = MAX (icon_view->priv->height, allocation.height);
1307 attributes.event_mask = (GDK_EXPOSURE_MASK |
1309 GDK_SMOOTH_SCROLL_MASK |
1310 GDK_POINTER_MOTION_MASK |
1311 GDK_BUTTON_PRESS_MASK |
1312 GDK_BUTTON_RELEASE_MASK |
1313 GDK_KEY_PRESS_MASK |
1314 GDK_KEY_RELEASE_MASK) |
1315 gtk_widget_get_events (widget);
1317 icon_view->priv->bin_window = gdk_window_new (window,
1318 &attributes, attributes_mask);
1319 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1320 gdk_window_show (icon_view->priv->bin_window);
1324 gtk_icon_view_unrealize (GtkWidget *widget)
1326 GtkIconView *icon_view;
1328 icon_view = GTK_ICON_VIEW (widget);
1330 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1331 gdk_window_destroy (icon_view->priv->bin_window);
1332 icon_view->priv->bin_window = NULL;
1334 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1338 gtk_icon_view_get_n_items (GtkIconView *icon_view)
1340 GtkIconViewPrivate *priv = icon_view->priv;
1342 if (priv->model == NULL)
1345 return gtk_tree_model_iter_n_children (priv->model, NULL);
1349 adjust_wrap_width (GtkIconView *icon_view)
1351 if (icon_view->priv->text_cell)
1353 gint wrap_width = 50;
1355 /* Here we go with the same old guess, try the icon size and set double
1356 * the size of the first icon found in the list, naive but works much
1358 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
1360 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
1361 GTK_WIDGET (icon_view),
1364 wrap_width = MAX (wrap_width * 2, 50);
1367 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
1368 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
1372 /* General notes about layout
1374 * The icon view is layouted like this:
1376 * +----------+ s +----------+
1377 * | padding | p | padding |
1378 * | +------+ | a | +------+ |
1379 * | | cell | | c | | cell | |
1380 * | +------+ | i | +------+ |
1382 * +----------+ g +----------+
1384 * In size request and allocation code, there are 3 sizes that are used:
1386 * This is the size returned by gtk_cell_area_get_preferred_foo(). In places
1387 * where code is interacting with the cell area and renderers this is useful.
1389 * This is the cell size plus the item padding on each side.
1391 * This is the padded size plus the spacing. This is what's used for most
1392 * calculations because it can (ab)use the following formula:
1393 * iconview_size = 2 * margin + n_items * spaced_size - spacing
1394 * So when reading this code and fixing my bugs where I confuse these two, be
1395 * aware of this distinction.
1398 cell_area_get_preferred_size (GtkIconView *icon_view,
1399 GtkCellAreaContext *context,
1400 GtkOrientation orientation,
1405 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1408 gtk_cell_area_get_preferred_width_for_height (icon_view->priv->cell_area,
1410 GTK_WIDGET (icon_view),
1414 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
1416 GTK_WIDGET (icon_view),
1422 gtk_cell_area_get_preferred_height_for_width (icon_view->priv->cell_area,
1424 GTK_WIDGET (icon_view),
1428 gtk_cell_area_get_preferred_height (icon_view->priv->cell_area,
1430 GTK_WIDGET (icon_view),
1436 gtk_icon_view_is_empty (GtkIconView *icon_view)
1438 return icon_view->priv->items == NULL;
1442 gtk_icon_view_get_preferred_item_size (GtkIconView *icon_view,
1443 GtkOrientation orientation,
1448 GtkIconViewPrivate *priv = icon_view->priv;
1449 GtkCellAreaContext *context;
1452 g_assert (!gtk_icon_view_is_empty (icon_view));
1454 context = gtk_cell_area_create_context (priv->cell_area);
1456 for_size -= 2 * priv->item_padding;
1460 /* This is necessary for the context to work properly */
1461 for (items = priv->items; items; items = items->next)
1463 GtkIconViewItem *item = items->data;
1465 _gtk_icon_view_set_cell_data (icon_view, item);
1466 cell_area_get_preferred_size (icon_view, context, 1 - orientation, -1, NULL, NULL);
1470 for (items = priv->items; items; items = items->next)
1472 GtkIconViewItem *item = items->data;
1474 _gtk_icon_view_set_cell_data (icon_view, item);
1475 if (items == priv->items)
1476 adjust_wrap_width (icon_view);
1477 cell_area_get_preferred_size (icon_view, context, orientation, for_size, NULL, NULL);
1480 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1483 gtk_cell_area_context_get_preferred_width_for_height (context,
1487 gtk_cell_area_context_get_preferred_width (context,
1493 gtk_cell_area_context_get_preferred_height_for_width (context,
1497 gtk_cell_area_context_get_preferred_height (context,
1501 if (orientation == GTK_ORIENTATION_HORIZONTAL && priv->item_width >= 0)
1504 *minimum = MAX (*minimum, priv->item_width);
1506 *natural = *minimum;
1510 *minimum = MAX (1, *minimum + 2 * priv->item_padding);
1512 *natural = MAX (1, *natural + 2 * priv->item_padding);
1514 g_object_unref (context);
1518 gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
1519 GtkOrientation orientation,
1522 gint *min_item_size,
1524 gint *max_item_size)
1526 GtkIconViewPrivate *priv = icon_view->priv;
1527 int minimum, natural, spacing;
1529 g_return_if_fail (min_item_size == NULL || min_items != NULL);
1530 g_return_if_fail (max_item_size == NULL || max_items != NULL);
1531 g_return_if_fail (!gtk_icon_view_is_empty (icon_view));
1533 gtk_icon_view_get_preferred_item_size (icon_view, orientation, -1, &minimum, &natural);
1535 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1536 spacing = priv->column_spacing;
1538 spacing = priv->row_spacing;
1540 size -= 2 * priv->margin;
1545 if (priv->columns > 0)
1547 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1550 *min_items = priv->columns;
1552 *max_items = priv->columns;
1556 int n_items = gtk_icon_view_get_n_items (icon_view);
1559 *min_items = (n_items + priv->columns - 1) / priv->columns;
1561 *max_items = (n_items + priv->columns - 1) / priv->columns;
1568 if (size <= minimum)
1571 *max_items = size / minimum;
1576 if (size <= natural)
1579 *min_items = size / natural;
1585 *min_item_size = size / *min_items;
1586 *min_item_size = CLAMP (*min_item_size, minimum, natural);
1587 *min_item_size -= spacing;
1588 *min_item_size -= 2 * priv->item_padding;
1593 *max_item_size = size / *max_items;
1594 *max_item_size = CLAMP (*max_item_size, minimum, natural);
1595 *max_item_size -= spacing;
1596 *max_item_size -= 2 * priv->item_padding;
1600 static GtkSizeRequestMode
1601 gtk_icon_view_get_request_mode (GtkWidget *widget)
1603 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1607 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1611 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1612 GtkIconViewPrivate *priv = icon_view->priv;
1613 int item_min, item_nat;
1615 if (gtk_icon_view_is_empty (icon_view))
1617 *minimum = *natural = 2 * priv->margin;
1621 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_min, &item_nat);
1623 if (priv->columns > 0)
1625 *minimum = item_min * priv->columns + priv->column_spacing * (priv->columns - 1);
1626 *natural = item_nat * priv->columns + priv->column_spacing * (priv->columns - 1);
1630 int n_items = gtk_icon_view_get_n_items (icon_view);
1632 *minimum = item_min;
1633 *natural = item_nat * n_items + priv->column_spacing * (n_items - 1);
1636 *minimum += 2 * priv->margin;
1637 *natural += 2 * priv->margin;
1641 gtk_icon_view_get_preferred_width_for_height (GtkWidget *widget,
1646 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1647 GtkIconViewPrivate *priv = icon_view->priv;
1648 int item_min, item_nat, rows, row_height, n_items;
1650 if (gtk_icon_view_is_empty (icon_view))
1652 *minimum = *natural = 2 * priv->margin;
1656 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_VERTICAL, height, &rows, &row_height, NULL, NULL);
1657 n_items = gtk_icon_view_get_n_items (icon_view);
1659 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, row_height, &item_min, &item_nat);
1660 *minimum = (item_min + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1661 *natural = (item_nat + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1663 *minimum += 2 * priv->margin;
1664 *natural += 2 * priv->margin;
1668 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1672 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1673 GtkIconViewPrivate *priv = icon_view->priv;
1674 int item_min, item_nat, n_items;
1676 if (gtk_icon_view_is_empty (icon_view))
1678 *minimum = *natural = 2 * priv->margin;
1682 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, -1, &item_min, &item_nat);
1683 n_items = gtk_icon_view_get_n_items (icon_view);
1685 if (priv->columns > 0)
1687 int n_rows = (n_items + priv->columns - 1) / priv->columns;
1689 *minimum = item_min * n_rows + priv->row_spacing * (n_rows - 1);
1690 *natural = item_nat * n_rows + priv->row_spacing * (n_rows - 1);
1694 *minimum = item_min;
1695 *natural = item_nat * n_items + priv->row_spacing * (n_items - 1);
1698 *minimum += 2 * priv->margin;
1699 *natural += 2 * priv->margin;
1703 gtk_icon_view_get_preferred_height_for_width (GtkWidget *widget,
1708 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1709 GtkIconViewPrivate *priv = icon_view->priv;
1710 int item_min, item_nat, columns, column_width, n_items;
1712 if (gtk_icon_view_is_empty (icon_view))
1714 *minimum = *natural = 2 * priv->margin;
1718 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_HORIZONTAL, width, NULL, NULL, &columns, &column_width);
1719 n_items = gtk_icon_view_get_n_items (icon_view);
1721 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, column_width, &item_min, &item_nat);
1722 *minimum = (item_min + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1723 *natural = (item_nat + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1725 *minimum += 2 * priv->margin;
1726 *natural += 2 * priv->margin;
1730 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1734 for (list = icon_view->priv->children; list; list = list->next)
1736 GtkIconViewChild *child = list->data;
1738 /* totally ignore our child's requisition */
1739 gtk_widget_size_allocate (child->widget, &child->area);
1744 gtk_icon_view_size_allocate (GtkWidget *widget,
1745 GtkAllocation *allocation)
1747 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1749 gtk_widget_set_allocation (widget, allocation);
1751 gtk_icon_view_layout (icon_view);
1753 if (gtk_widget_get_realized (widget))
1755 gdk_window_move_resize (gtk_widget_get_window (widget),
1756 allocation->x, allocation->y,
1757 allocation->width, allocation->height);
1758 gdk_window_resize (icon_view->priv->bin_window,
1759 MAX (icon_view->priv->width, allocation->width),
1760 MAX (icon_view->priv->height, allocation->height));
1763 gtk_icon_view_allocate_children (icon_view);
1765 /* Delay signal emission */
1766 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1767 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1769 gtk_icon_view_set_hadjustment_values (icon_view);
1770 gtk_icon_view_set_vadjustment_values (icon_view);
1772 if (gtk_widget_get_realized (widget) &&
1773 icon_view->priv->scroll_to_path)
1776 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1777 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1778 icon_view->priv->scroll_to_path = NULL;
1780 gtk_icon_view_scroll_to_path (icon_view, path,
1781 icon_view->priv->scroll_to_use_align,
1782 icon_view->priv->scroll_to_row_align,
1783 icon_view->priv->scroll_to_col_align);
1784 gtk_tree_path_free (path);
1787 /* Emit any pending signals now */
1788 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1789 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1793 gtk_icon_view_draw (GtkWidget *widget,
1796 GtkIconView *icon_view;
1800 GtkIconViewDropPosition dest_pos;
1801 GtkIconViewItem *dest_item = NULL;
1802 GtkStyleContext *context;
1804 icon_view = GTK_ICON_VIEW (widget);
1806 context = gtk_widget_get_style_context (widget);
1807 gtk_render_background (context, cr,
1809 gtk_widget_get_allocated_width (widget),
1810 gtk_widget_get_allocated_height (widget));
1812 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1817 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1819 cairo_set_line_width (cr, 1.);
1821 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1825 dest_index = gtk_tree_path_get_indices (path)[0];
1826 gtk_tree_path_free (path);
1831 for (icons = icon_view->priv->items; icons; icons = icons->next)
1833 GtkIconViewItem *item = icons->data;
1834 GdkRectangle paint_area;
1836 paint_area.x = item->cell_area.x - icon_view->priv->item_padding;
1837 paint_area.y = item->cell_area.y - icon_view->priv->item_padding;
1838 paint_area.width = item->cell_area.width + icon_view->priv->item_padding * 2;
1839 paint_area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
1843 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1846 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1848 gtk_icon_view_paint_item (icon_view, cr, item,
1849 item->cell_area.x, item->cell_area.y,
1850 icon_view->priv->draw_focus);
1852 if (dest_index == item->index)
1860 dest_pos != GTK_ICON_VIEW_NO_DROP)
1862 GtkStyleContext *context;
1863 GdkRectangle rect = { 0 };
1865 context = gtk_widget_get_style_context (widget);
1869 case GTK_ICON_VIEW_DROP_INTO:
1870 rect = dest_item->cell_area;
1872 case GTK_ICON_VIEW_DROP_ABOVE:
1873 rect.x = dest_item->cell_area.x;
1874 rect.y = dest_item->cell_area.y - 1;
1875 rect.width = dest_item->cell_area.width;
1878 case GTK_ICON_VIEW_DROP_LEFT:
1879 rect.x = dest_item->cell_area.x - 1;
1880 rect.y = dest_item->cell_area.y;
1882 rect.height = dest_item->cell_area.height;
1884 case GTK_ICON_VIEW_DROP_BELOW:
1885 rect.x = dest_item->cell_area.x;
1886 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1887 rect.width = dest_item->cell_area.width;
1890 case GTK_ICON_VIEW_DROP_RIGHT:
1891 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1892 rect.y = dest_item->cell_area.y;
1894 rect.height = dest_item->cell_area.height;
1895 case GTK_ICON_VIEW_NO_DROP: ;
1899 gtk_render_focus (context, cr,
1901 rect.width, rect.height);
1904 if (icon_view->priv->doing_rubberband)
1905 gtk_icon_view_paint_rubberband (icon_view, cr);
1909 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1913 rubberband_scroll_timeout (gpointer data)
1915 GtkIconView *icon_view = data;
1917 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1918 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1919 icon_view->priv->scroll_value_diff);
1921 gtk_icon_view_update_rubberband (icon_view);
1927 gtk_icon_view_motion (GtkWidget *widget,
1928 GdkEventMotion *event)
1930 GtkAllocation allocation;
1931 GtkIconView *icon_view;
1934 icon_view = GTK_ICON_VIEW (widget);
1936 gtk_icon_view_maybe_begin_drag (icon_view, event);
1938 if (icon_view->priv->doing_rubberband)
1940 gtk_icon_view_update_rubberband (widget);
1942 abs_y = event->y - icon_view->priv->height *
1943 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1944 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1945 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1947 gtk_widget_get_allocation (widget, &allocation);
1949 if (abs_y < 0 || abs_y > allocation.height)
1952 icon_view->priv->scroll_value_diff = abs_y;
1954 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1956 icon_view->priv->event_last_x = event->x;
1957 icon_view->priv->event_last_y = event->y;
1959 if (icon_view->priv->scroll_timeout_id == 0)
1960 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1964 remove_scroll_timeout (icon_view);
1968 GtkIconViewItem *item, *last_prelight_item;
1969 GtkCellRenderer *cell = NULL;
1971 last_prelight_item = icon_view->priv->last_prelight;
1972 item = _gtk_icon_view_get_item_at_coords (icon_view,
1979 item->prelight = TRUE;
1980 gtk_icon_view_queue_draw_item (icon_view, item);
1983 if (last_prelight_item != NULL &&
1984 last_prelight_item != item)
1986 last_prelight_item->prelight = FALSE;
1987 gtk_icon_view_queue_draw_item (icon_view,
1988 icon_view->priv->last_prelight);
1991 icon_view->priv->last_prelight = item;
1998 gtk_icon_view_remove (GtkContainer *container,
2001 GtkIconView *icon_view;
2002 GtkIconViewChild *child = NULL;
2005 icon_view = GTK_ICON_VIEW (container);
2007 tmp_list = icon_view->priv->children;
2010 child = tmp_list->data;
2011 if (child->widget == widget)
2013 gtk_widget_unparent (widget);
2015 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
2016 g_list_free_1 (tmp_list);
2021 tmp_list = tmp_list->next;
2026 gtk_icon_view_forall (GtkContainer *container,
2027 gboolean include_internals,
2028 GtkCallback callback,
2029 gpointer callback_data)
2031 GtkIconView *icon_view;
2032 GtkIconViewChild *child = NULL;
2035 icon_view = GTK_ICON_VIEW (container);
2037 tmp_list = icon_view->priv->children;
2040 child = tmp_list->data;
2041 tmp_list = tmp_list->next;
2043 (* callback) (child->widget, callback_data);
2048 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
2049 GtkIconViewItem *item)
2052 AtkObject *item_obj;
2054 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2057 item_obj = atk_object_ref_accessible_child (obj, item->index);
2058 if (item_obj != NULL)
2060 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
2061 g_object_unref (item_obj);
2067 gtk_icon_view_add_editable (GtkCellArea *area,
2068 GtkCellRenderer *renderer,
2069 GtkCellEditable *editable,
2070 GdkRectangle *cell_area,
2072 GtkIconView *icon_view)
2074 GtkIconViewChild *child;
2075 GtkWidget *widget = GTK_WIDGET (editable);
2077 child = g_new (GtkIconViewChild, 1);
2079 child->widget = widget;
2080 child->area.x = cell_area->x;
2081 child->area.y = cell_area->y;
2082 child->area.width = cell_area->width;
2083 child->area.height = cell_area->height;
2085 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
2087 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2088 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
2090 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
2094 gtk_icon_view_remove_editable (GtkCellArea *area,
2095 GtkCellRenderer *renderer,
2096 GtkCellEditable *editable,
2097 GtkIconView *icon_view)
2101 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
2102 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
2104 gtk_container_remove (GTK_CONTAINER (icon_view),
2105 GTK_WIDGET (editable));
2107 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
2108 gtk_icon_view_queue_draw_path (icon_view, path);
2109 gtk_tree_path_free (path);
2113 * gtk_icon_view_set_cursor:
2114 * @icon_view: A #GtkIconView
2115 * @path: A #GtkTreePath
2116 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2117 * @start_editing: %TRUE if the specified cell should start being edited.
2119 * Sets the current keyboard focus to be at @path, and selects it. This is
2120 * useful when you want to focus the user's attention on a particular item.
2121 * If @cell is not %NULL, then focus is given to the cell specified by
2122 * it. Additionally, if @start_editing is %TRUE, then editing should be
2123 * started in the specified cell.
2125 * This function is often followed by <literal>gtk_widget_grab_focus
2126 * (icon_view)</literal> in order to give keyboard focus to the widget.
2127 * Please note that editing can only happen when the widget is realized.
2132 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2134 GtkCellRenderer *cell,
2135 gboolean start_editing)
2137 GtkIconViewItem *item = NULL;
2139 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2140 g_return_if_fail (path != NULL);
2141 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2143 if (icon_view->priv->cell_area)
2144 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2146 if (gtk_tree_path_get_depth (path) == 1)
2147 item = g_list_nth_data (icon_view->priv->items,
2148 gtk_tree_path_get_indices(path)[0]);
2153 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
2154 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2156 if (start_editing &&
2157 icon_view->priv->cell_area)
2159 GtkCellAreaContext *context;
2161 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2162 _gtk_icon_view_set_cell_data (icon_view, item);
2163 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2164 GTK_WIDGET (icon_view), &item->cell_area,
2165 0 /* XXX flags */, TRUE);
2170 * gtk_icon_view_get_cursor:
2171 * @icon_view: A #GtkIconView
2172 * @path: (out) (allow-none): Return location for the current cursor path,
2174 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
2176 * Fills in @path and @cell with the current cursor path and cell.
2177 * If the cursor isn't currently set, then *@path will be %NULL.
2178 * If no cell currently has focus, then *@cell will be %NULL.
2180 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2182 * Return value: %TRUE if the cursor is set.
2187 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2189 GtkCellRenderer **cell)
2191 GtkIconViewItem *item;
2193 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2195 item = icon_view->priv->cursor_item;
2200 *path = gtk_tree_path_new_from_indices (item->index, -1);
2205 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
2206 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
2208 return (item != NULL);
2212 gtk_icon_view_button_press (GtkWidget *widget,
2213 GdkEventButton *event)
2215 GtkIconView *icon_view;
2216 GtkIconViewItem *item;
2217 gboolean dirty = FALSE;
2218 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2220 icon_view = GTK_ICON_VIEW (widget);
2222 if (event->window != icon_view->priv->bin_window)
2225 if (!gtk_widget_has_focus (widget))
2226 gtk_widget_grab_focus (widget);
2228 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
2230 GdkModifierType extend_mod_mask;
2231 GdkModifierType modify_mod_mask;
2234 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2237 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2239 item = _gtk_icon_view_get_item_at_coords (icon_view,
2245 * We consider only the cells' area as the item area if the
2246 * item is not selected, but if it *is* selected, the complete
2247 * selection rectangle is considered to be part of the item.
2249 if (item != NULL && (cell != NULL || item->selected))
2253 if (gtk_cell_renderer_is_activatable (cell))
2257 gtk_icon_view_scroll_to_item (icon_view, item);
2259 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2261 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2263 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2264 (event->state & extend_mod_mask))
2266 gtk_icon_view_unselect_all_internal (icon_view);
2268 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2269 if (!icon_view->priv->anchor_item)
2270 icon_view->priv->anchor_item = item;
2272 gtk_icon_view_select_all_between (icon_view,
2273 icon_view->priv->anchor_item,
2279 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2280 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2281 (event->state & modify_mod_mask))
2283 item->selected = !item->selected;
2284 gtk_icon_view_queue_draw_item (icon_view, item);
2289 gtk_icon_view_unselect_all_internal (icon_view);
2291 item->selected = TRUE;
2292 gtk_icon_view_queue_draw_item (icon_view, item);
2295 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2296 icon_view->priv->anchor_item = item;
2299 /* Save press to possibly begin a drag */
2300 if (icon_view->priv->pressed_button < 0)
2302 icon_view->priv->pressed_button = event->button;
2303 icon_view->priv->press_start_x = event->x;
2304 icon_view->priv->press_start_y = event->y;
2307 if (!icon_view->priv->last_single_clicked)
2308 icon_view->priv->last_single_clicked = item;
2310 /* cancel the current editing, if it exists */
2311 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2313 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2315 GtkCellAreaContext *context;
2317 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2319 _gtk_icon_view_set_cell_data (icon_view, item);
2320 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2321 GTK_WIDGET (icon_view),
2322 &item->cell_area, 0/* XXX flags */, FALSE);
2327 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2328 !(event->state & modify_mod_mask))
2330 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2333 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2334 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2337 /* don't draw keyboard focus around an clicked-on item */
2338 icon_view->priv->draw_focus = FALSE;
2341 if (!icon_view->priv->activate_on_single_click
2342 && event->button == GDK_BUTTON_PRIMARY
2343 && event->type == GDK_2BUTTON_PRESS)
2345 item = _gtk_icon_view_get_item_at_coords (icon_view,
2350 if (item && item == icon_view->priv->last_single_clicked)
2354 path = gtk_tree_path_new_from_indices (item->index, -1);
2355 gtk_icon_view_item_activated (icon_view, path);
2356 gtk_tree_path_free (path);
2359 icon_view->priv->last_single_clicked = NULL;
2360 icon_view->priv->pressed_button = -1;
2364 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2366 return event->button == GDK_BUTTON_PRIMARY;
2370 button_event_modifies_selection (GdkEventButton *event)
2372 return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
2376 gtk_icon_view_button_release (GtkWidget *widget,
2377 GdkEventButton *event)
2379 GtkIconView *icon_view;
2381 icon_view = GTK_ICON_VIEW (widget);
2383 if (icon_view->priv->pressed_button == event->button)
2384 icon_view->priv->pressed_button = -1;
2386 gtk_icon_view_stop_rubberbanding (icon_view);
2388 remove_scroll_timeout (icon_view);
2390 if (event->button == GDK_BUTTON_PRIMARY
2391 && icon_view->priv->activate_on_single_click
2392 && !button_event_modifies_selection (event)
2393 && icon_view->priv->last_single_clicked != NULL)
2395 GtkIconViewItem *item;
2397 item = _gtk_icon_view_get_item_at_coords (icon_view,
2401 if (item == icon_view->priv->last_single_clicked)
2404 path = gtk_tree_path_new_from_indices (item->index, -1);
2405 gtk_icon_view_item_activated (icon_view, path);
2406 gtk_tree_path_free (path);
2409 icon_view->priv->last_single_clicked = NULL;
2416 gtk_icon_view_key_press (GtkWidget *widget,
2419 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2421 if (icon_view->priv->doing_rubberband)
2423 if (event->keyval == GDK_KEY_Escape)
2424 gtk_icon_view_stop_rubberbanding (icon_view);
2429 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2433 gtk_icon_view_key_release (GtkWidget *widget,
2436 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2438 if (icon_view->priv->doing_rubberband)
2441 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2445 gtk_icon_view_update_rubberband (gpointer data)
2447 GtkIconView *icon_view;
2449 GdkRectangle old_area;
2450 GdkRectangle new_area;
2451 GdkRectangle common;
2452 cairo_region_t *invalid_region;
2454 icon_view = GTK_ICON_VIEW (data);
2456 gdk_window_get_device_position (icon_view->priv->bin_window,
2457 icon_view->priv->rubberband_device,
2463 old_area.x = MIN (icon_view->priv->rubberband_x1,
2464 icon_view->priv->rubberband_x2);
2465 old_area.y = MIN (icon_view->priv->rubberband_y1,
2466 icon_view->priv->rubberband_y2);
2467 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2468 icon_view->priv->rubberband_x1) + 1;
2469 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2470 icon_view->priv->rubberband_y1) + 1;
2472 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2473 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2474 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2475 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2477 invalid_region = cairo_region_create_rectangle (&old_area);
2478 cairo_region_union_rectangle (invalid_region, &new_area);
2480 gdk_rectangle_intersect (&old_area, &new_area, &common);
2481 if (common.width > 2 && common.height > 2)
2483 cairo_region_t *common_region;
2485 /* make sure the border is invalidated */
2491 common_region = cairo_region_create_rectangle (&common);
2493 cairo_region_subtract (invalid_region, common_region);
2494 cairo_region_destroy (common_region);
2497 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2499 cairo_region_destroy (invalid_region);
2501 icon_view->priv->rubberband_x2 = x;
2502 icon_view->priv->rubberband_y2 = y;
2504 gtk_icon_view_update_rubberband_selection (icon_view);
2508 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2515 if (icon_view->priv->rubberband_device)
2518 for (items = icon_view->priv->items; items; items = items->next)
2520 GtkIconViewItem *item = items->data;
2522 item->selected_before_rubberbanding = item->selected;
2525 icon_view->priv->rubberband_x1 = x;
2526 icon_view->priv->rubberband_y1 = y;
2527 icon_view->priv->rubberband_x2 = x;
2528 icon_view->priv->rubberband_y2 = y;
2530 icon_view->priv->doing_rubberband = TRUE;
2531 icon_view->priv->rubberband_device = device;
2533 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2537 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2539 if (!icon_view->priv->doing_rubberband)
2542 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2543 icon_view->priv->rubberband_device);
2545 icon_view->priv->doing_rubberband = FALSE;
2546 icon_view->priv->rubberband_device = NULL;
2548 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2552 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2555 gint x, y, width, height;
2556 gboolean dirty = FALSE;
2558 x = MIN (icon_view->priv->rubberband_x1,
2559 icon_view->priv->rubberband_x2);
2560 y = MIN (icon_view->priv->rubberband_y1,
2561 icon_view->priv->rubberband_y2);
2562 width = ABS (icon_view->priv->rubberband_x1 -
2563 icon_view->priv->rubberband_x2);
2564 height = ABS (icon_view->priv->rubberband_y1 -
2565 icon_view->priv->rubberband_y2);
2567 for (items = icon_view->priv->items; items; items = items->next)
2569 GtkIconViewItem *item = items->data;
2573 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2574 x, y, width, height);
2576 selected = is_in ^ item->selected_before_rubberbanding;
2578 if (item->selected != selected)
2580 item->selected = selected;
2582 gtk_icon_view_queue_draw_item (icon_view, item);
2587 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2592 GdkRectangle hit_rect;
2597 hit_test (GtkCellRenderer *renderer,
2598 const GdkRectangle *cell_area,
2599 const GdkRectangle *cell_background,
2602 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2603 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2604 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2605 MAX (data->hit_rect.y, cell_area->y) > 0)
2608 return (data->hit != FALSE);
2612 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2613 GtkIconViewItem *item,
2619 HitTestData data = { { x, y, width, height }, FALSE };
2620 GtkCellAreaContext *context;
2621 GdkRectangle *item_area = &item->cell_area;
2623 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2624 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2627 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2629 _gtk_icon_view_set_cell_data (icon_view, item);
2630 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2631 GTK_WIDGET (icon_view),
2632 item_area, item_area,
2633 (GtkCellAllocCallback)hit_test, &data);
2639 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2641 gboolean dirty = FALSE;
2644 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2647 for (items = icon_view->priv->items; items; items = items->next)
2649 GtkIconViewItem *item = items->data;
2653 item->selected = FALSE;
2655 gtk_icon_view_queue_draw_item (icon_view, item);
2656 gtk_icon_view_item_selected_changed (icon_view, item);
2664 /* GtkIconView signals */
2666 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2668 gtk_icon_view_select_all (icon_view);
2672 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2674 gtk_icon_view_unselect_all (icon_view);
2678 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2680 gtk_icon_view_unselect_all (icon_view);
2682 if (icon_view->priv->cursor_item != NULL)
2683 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2687 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2690 GtkCellAreaContext *context;
2692 if (!icon_view->priv->cursor_item)
2695 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2697 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2698 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2699 GTK_WIDGET (icon_view),
2700 &icon_view->priv->cursor_item->cell_area,
2704 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2705 gtk_icon_view_item_activated (icon_view, path);
2706 gtk_tree_path_free (path);
2712 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2714 if (!icon_view->priv->cursor_item)
2717 switch (icon_view->priv->selection_mode)
2719 case GTK_SELECTION_NONE:
2721 case GTK_SELECTION_BROWSE:
2722 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2724 case GTK_SELECTION_SINGLE:
2725 if (icon_view->priv->cursor_item->selected)
2726 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2728 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2730 case GTK_SELECTION_MULTIPLE:
2731 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2732 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2734 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2735 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2741 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2743 GtkAllocation allocation;
2744 GtkAdjustment *adj = icon_view->priv->hadjustment;
2745 gdouble old_page_size;
2751 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2753 old_value = gtk_adjustment_get_value (adj);
2754 old_upper = gtk_adjustment_get_upper (adj);
2755 old_page_size = gtk_adjustment_get_page_size (adj);
2756 new_upper = MAX (allocation.width, icon_view->priv->width);
2758 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2760 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2761 /* Quick explanation:
2762 * In LTR locales, leftmost portion of visible rectangle should stay
2763 * fixed, which means left edge of scrollbar thumb should remain fixed
2764 * and thus adjustment's value should stay the same.
2766 * In RTL locales, we want to keep rightmost portion of visible
2767 * rectangle fixed. This means right edge of thumb should remain fixed.
2768 * In this case, upper - value - page_size should remain constant.
2770 new_value = (new_upper - allocation.width) -
2771 (old_upper - old_value - old_page_size);
2772 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2775 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2777 gtk_adjustment_configure (adj,
2781 allocation.width * 0.1,
2782 allocation.width * 0.9,
2787 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2789 GtkAllocation allocation;
2790 GtkAdjustment *adj = icon_view->priv->vadjustment;
2792 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2794 gtk_adjustment_configure (adj,
2795 gtk_adjustment_get_value (adj),
2797 MAX (allocation.height, icon_view->priv->height),
2798 allocation.height * 0.1,
2799 allocation.height * 0.9,
2804 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2805 GtkAdjustment *adjustment)
2807 GtkIconViewPrivate *priv = icon_view->priv;
2809 if (adjustment && priv->hadjustment == adjustment)
2812 if (priv->hadjustment != NULL)
2814 g_signal_handlers_disconnect_matched (priv->hadjustment,
2815 G_SIGNAL_MATCH_DATA,
2816 0, 0, NULL, NULL, icon_view);
2817 g_object_unref (priv->hadjustment);
2821 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2824 g_signal_connect (adjustment, "value-changed",
2825 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2826 priv->hadjustment = g_object_ref_sink (adjustment);
2827 gtk_icon_view_set_hadjustment_values (icon_view);
2829 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2833 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2834 GtkAdjustment *adjustment)
2836 GtkIconViewPrivate *priv = icon_view->priv;
2838 if (adjustment && priv->vadjustment == adjustment)
2841 if (priv->vadjustment != NULL)
2843 g_signal_handlers_disconnect_matched (priv->vadjustment,
2844 G_SIGNAL_MATCH_DATA,
2845 0, 0, NULL, NULL, icon_view);
2846 g_object_unref (priv->vadjustment);
2850 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2853 g_signal_connect (adjustment, "value-changed",
2854 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2855 priv->vadjustment = g_object_ref_sink (adjustment);
2856 gtk_icon_view_set_vadjustment_values (icon_view);
2858 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2862 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2863 GtkIconView *icon_view)
2865 GtkIconViewPrivate *priv = icon_view->priv;
2867 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2869 gdk_window_move (priv->bin_window,
2870 - gtk_adjustment_get_value (priv->hadjustment),
2871 - gtk_adjustment_get_value (priv->vadjustment));
2873 if (icon_view->priv->doing_rubberband)
2874 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2876 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2881 compare_sizes (gconstpointer p1,
2885 return GPOINTER_TO_INT (((const GtkRequestedSize *) p1)->data)
2886 - GPOINTER_TO_INT (((const GtkRequestedSize *) p2)->data);
2890 gtk_icon_view_layout (GtkIconView *icon_view)
2892 GtkIconViewPrivate *priv = icon_view->priv;
2893 GtkWidget *widget = GTK_WIDGET (icon_view);
2895 gint item_width; /* this doesn't include item_padding */
2896 gint n_columns, n_rows, n_items;
2898 GtkRequestedSize *sizes;
2901 if (gtk_icon_view_is_empty (icon_view))
2904 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2905 n_items = gtk_icon_view_get_n_items (icon_view);
2907 gtk_icon_view_compute_n_items_for_size (icon_view,
2908 GTK_ORIENTATION_HORIZONTAL,
2909 gtk_widget_get_allocated_width (widget),
2911 &n_columns, &item_width);
2912 n_rows = (n_items + n_columns - 1) / n_columns;
2914 priv->width = n_columns * (item_width + 2 * priv->item_padding + priv->column_spacing) - priv->column_spacing;
2915 priv->width += 2 * priv->margin;
2916 priv->width = MAX (priv->width, gtk_widget_get_allocated_width (widget));
2918 /* Clear the per row contexts */
2919 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2921 gtk_cell_area_context_reset (priv->cell_area_context);
2922 /* because layouting is complicated. We designed an API
2923 * that is O(N²) and nonsensical.
2924 * And we're proud of it. */
2925 for (items = priv->items; items; items = items->next)
2927 _gtk_icon_view_set_cell_data (icon_view, items->data);
2928 gtk_cell_area_get_preferred_width (priv->cell_area,
2929 priv->cell_area_context,
2934 sizes = g_newa (GtkRequestedSize, n_rows);
2935 items = priv->items;
2936 priv->height = priv->margin;
2938 /* Collect the heights for all rows */
2939 for (row = 0; row < n_rows; row++)
2941 GtkCellAreaContext *context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2942 g_ptr_array_add (priv->row_contexts, context);
2944 for (col = 0; col < n_columns && items; col++, items = items->next)
2946 GtkIconViewItem *item = items->data;
2948 _gtk_icon_view_set_cell_data (icon_view, item);
2949 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2956 sizes[row].data = GINT_TO_POINTER (row);
2957 gtk_cell_area_context_get_preferred_height_for_width (context,
2959 &sizes[row].minimum_size,
2960 &sizes[row].natural_size);
2961 priv->height += sizes[row].minimum_size + 2 * priv->item_padding + priv->row_spacing;
2964 priv->height -= priv->row_spacing;
2965 priv->height += priv->margin;
2966 priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget));
2968 gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height,
2972 /* Actually allocate the rows */
2973 g_qsort_with_data (sizes, n_rows, sizeof (GtkRequestedSize), compare_sizes, NULL);
2975 items = priv->items;
2976 priv->height = priv->margin;
2978 for (row = 0; row < n_rows; row++)
2980 GtkCellAreaContext *context = g_ptr_array_index (priv->row_contexts, row);
2981 gtk_cell_area_context_allocate (context, item_width, sizes[row].minimum_size);
2983 priv->height += priv->item_padding;
2985 for (col = 0; col < n_columns && items; col++, items = items->next)
2987 GtkIconViewItem *item = items->data;
2989 item->cell_area.x = priv->margin + (col * 2 + 1) * priv->item_padding + col * (priv->column_spacing + item_width);
2990 item->cell_area.width = item_width;
2991 item->cell_area.y = priv->height;
2992 item->cell_area.height = sizes[row].minimum_size;
2997 item->cell_area.x = priv->width - item_width - item->cell_area.x;
2998 item->col = n_columns - 1 - col;
3002 priv->height += sizes[row].minimum_size + priv->item_padding + priv->row_spacing;
3005 priv->height -= priv->row_spacing;
3006 priv->height += priv->margin;
3007 priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget));
3011 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3013 /* Clear all item sizes */
3014 g_list_foreach (icon_view->priv->items,
3015 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3017 /* Re-layout the items */
3018 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3022 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3024 item->cell_area.width = -1;
3025 item->cell_area.height = -1;
3029 gtk_icon_view_paint_item (GtkIconView *icon_view,
3031 GtkIconViewItem *item,
3034 gboolean draw_focus)
3036 GdkRectangle cell_area;
3037 GtkStateFlags state = 0;
3038 GtkCellRendererState flags = 0;
3039 GtkStyleContext *style_context;
3040 GtkWidget *widget = GTK_WIDGET (icon_view);
3041 GtkIconViewPrivate *priv = icon_view->priv;
3042 GtkCellAreaContext *context;
3044 if (priv->model == NULL || item->cell_area.width <= 0 || item->cell_area.height <= 0)
3047 _gtk_icon_view_set_cell_data (icon_view, item);
3049 style_context = gtk_widget_get_style_context (widget);
3050 state = gtk_widget_get_state_flags (widget);
3052 gtk_style_context_save (style_context);
3053 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
3055 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
3057 if ((state & GTK_STATE_FLAG_FOCUSED) &&
3058 item == icon_view->priv->cursor_item)
3059 flags |= GTK_CELL_RENDERER_FOCUSED;
3063 state |= GTK_STATE_FLAG_SELECTED;
3064 flags |= GTK_CELL_RENDERER_SELECTED;
3069 state |= GTK_STATE_FLAG_PRELIGHT;
3070 flags |= GTK_CELL_RENDERER_PRELIT;
3073 gtk_style_context_set_state (style_context, state);
3077 gtk_render_background (style_context, cr,
3078 x - icon_view->priv->item_padding,
3079 y - icon_view->priv->item_padding,
3080 item->cell_area.width + icon_view->priv->item_padding * 2,
3081 item->cell_area.height + icon_view->priv->item_padding * 2);
3082 gtk_render_frame (style_context, cr,
3083 x - icon_view->priv->item_padding,
3084 y - icon_view->priv->item_padding,
3085 item->cell_area.width + icon_view->priv->item_padding * 2,
3086 item->cell_area.height + icon_view->priv->item_padding * 2);
3091 cell_area.width = item->cell_area.width;
3092 cell_area.height = item->cell_area.height;
3094 context = g_ptr_array_index (priv->row_contexts, item->row);
3095 gtk_cell_area_render (priv->cell_area, context,
3096 widget, cr, &cell_area, &cell_area, flags,
3099 gtk_style_context_restore (style_context);
3103 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3106 GtkStyleContext *context;
3111 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3112 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3113 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3114 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3116 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3118 gtk_style_context_save (context);
3119 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3121 gdk_cairo_rectangle (cr, &rect);
3124 gtk_render_background (context, cr,
3126 rect.width, rect.height);
3127 gtk_render_frame (context, cr,
3129 rect.width, rect.height);
3131 gtk_style_context_restore (context);
3136 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3142 index = gtk_tree_path_get_indices (path)[0];
3144 for (l = icon_view->priv->items; l; l = l->next)
3146 GtkIconViewItem *item = l->data;
3148 if (item->index == index)
3150 gtk_icon_view_queue_draw_item (icon_view, item);
3157 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3158 GtkIconViewItem *item)
3161 GdkRectangle *item_area = &item->cell_area;
3163 rect.x = item_area->x - icon_view->priv->item_padding;
3164 rect.y = item_area->y - icon_view->priv->item_padding;
3165 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3166 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3168 if (icon_view->priv->bin_window)
3169 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3173 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3174 GtkIconViewItem *item,
3175 GtkCellRenderer *cursor_cell)
3178 AtkObject *item_obj;
3179 AtkObject *cursor_item_obj;
3181 /* When hitting this path from keynav, the focus cell is
3182 * already set, we dont need to notify the atk object
3183 * but we still need to queue the draw here (in the case
3184 * that the focus cell changes but not the cursor item).
3186 gtk_icon_view_queue_draw_item (icon_view, item);
3188 if (icon_view->priv->cursor_item == item &&
3189 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3192 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3193 if (icon_view->priv->cursor_item != NULL)
3195 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3198 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3199 if (cursor_item_obj != NULL)
3200 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3203 icon_view->priv->cursor_item = item;
3206 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3209 /* Make sure there is a cell in focus initially */
3210 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3211 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3214 /* Notify that accessible focus object has changed */
3215 item_obj = atk_object_ref_accessible_child (obj, item->index);
3217 if (item_obj != NULL)
3219 atk_focus_tracker_notify (item_obj);
3220 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3221 g_object_unref (item_obj);
3226 static GtkIconViewItem *
3227 gtk_icon_view_item_new (void)
3229 GtkIconViewItem *item;
3231 item = g_slice_new0 (GtkIconViewItem);
3233 item->cell_area.width = -1;
3234 item->cell_area.height = -1;
3240 gtk_icon_view_item_free (GtkIconViewItem *item)
3242 g_return_if_fail (item != NULL);
3244 g_slice_free (GtkIconViewItem, item);
3248 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3251 gboolean only_in_cell,
3252 GtkCellRenderer **cell_at_pos)
3257 *cell_at_pos = NULL;
3259 for (items = icon_view->priv->items; items; items = items->next)
3261 GtkIconViewItem *item = items->data;
3262 GdkRectangle *item_area = &item->cell_area;
3264 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3265 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3266 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3267 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3269 if (only_in_cell || cell_at_pos)
3271 GtkCellRenderer *cell = NULL;
3272 GtkCellAreaContext *context;
3274 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3275 _gtk_icon_view_set_cell_data (icon_view, item);
3277 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3278 y >= item_area->y && y <= item_area->y + item_area->height)
3279 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3280 GTK_WIDGET (icon_view),
3285 *cell_at_pos = cell;
3288 return cell != NULL ? item : NULL;
3299 _gtk_icon_view_select_item (GtkIconView *icon_view,
3300 GtkIconViewItem *item)
3302 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3303 g_return_if_fail (item != NULL);
3308 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3310 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3311 gtk_icon_view_unselect_all_internal (icon_view);
3313 item->selected = TRUE;
3315 gtk_icon_view_item_selected_changed (icon_view, item);
3316 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3318 gtk_icon_view_queue_draw_item (icon_view, item);
3323 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3324 GtkIconViewItem *item)
3326 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3327 g_return_if_fail (item != NULL);
3329 if (!item->selected)
3332 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3333 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3336 item->selected = FALSE;
3338 gtk_icon_view_item_selected_changed (icon_view, item);
3339 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3341 gtk_icon_view_queue_draw_item (icon_view, item);
3345 verify_items (GtkIconView *icon_view)
3350 for (items = icon_view->priv->items; items; items = items->next)
3352 GtkIconViewItem *item = items->data;
3354 if (item->index != i)
3355 g_error ("List item does not match its index: "
3356 "item index %d and list index %d\n", item->index, i);
3363 gtk_icon_view_row_changed (GtkTreeModel *model,
3368 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3370 /* ignore changes in branches */
3371 if (gtk_tree_path_get_depth (path) > 1)
3374 /* An icon view subclass might add it's own model and populate
3375 * things at init() time instead of waiting for the constructor()
3378 if (icon_view->priv->cell_area)
3379 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3381 /* Here we can use a "grow-only" strategy for optimization
3382 * and only invalidate a single item and queue a relayout
3383 * instead of invalidating the whole thing.
3385 * For now GtkIconView still cant deal with huge models
3386 * so just invalidate the whole thing when the model
3389 gtk_icon_view_invalidate_sizes (icon_view);
3391 verify_items (icon_view);
3395 gtk_icon_view_row_inserted (GtkTreeModel *model,
3400 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3402 GtkIconViewItem *item;
3405 /* ignore changes in branches */
3406 if (gtk_tree_path_get_depth (path) > 1)
3409 index = gtk_tree_path_get_indices(path)[0];
3411 item = gtk_icon_view_item_new ();
3413 item->index = index;
3415 /* FIXME: We can be more efficient here,
3416 we can store a tail pointer and use that when
3417 appending (which is a rather common operation)
3419 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3422 list = g_list_nth (icon_view->priv->items, index + 1);
3423 for (; list; list = list->next)
3430 verify_items (icon_view);
3432 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3436 gtk_icon_view_row_deleted (GtkTreeModel *model,
3440 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3442 GtkIconViewItem *item;
3444 gboolean emit = FALSE;
3446 /* ignore changes in branches */
3447 if (gtk_tree_path_get_depth (path) > 1)
3450 index = gtk_tree_path_get_indices(path)[0];
3452 list = g_list_nth (icon_view->priv->items, index);
3455 if (icon_view->priv->cell_area)
3456 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3458 if (item == icon_view->priv->anchor_item)
3459 icon_view->priv->anchor_item = NULL;
3461 if (item == icon_view->priv->cursor_item)
3462 icon_view->priv->cursor_item = NULL;
3464 if (item == icon_view->priv->last_prelight)
3465 icon_view->priv->last_prelight = NULL;
3470 gtk_icon_view_item_free (item);
3472 for (next = list->next; next; next = next->next)
3479 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3481 verify_items (icon_view);
3483 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3486 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3490 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3491 GtkTreePath *parent,
3496 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3499 GList *items = NULL, *list;
3500 GtkIconViewItem **item_array;
3503 /* ignore changes in branches */
3507 if (icon_view->priv->cell_area)
3508 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3510 length = gtk_tree_model_iter_n_children (model, NULL);
3512 order = g_new (gint, length);
3513 for (i = 0; i < length; i++)
3514 order [new_order[i]] = i;
3516 item_array = g_new (GtkIconViewItem *, length);
3517 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3518 item_array[order[i]] = list->data;
3521 for (i = length - 1; i >= 0; i--)
3523 item_array[i]->index = i;
3524 items = g_list_prepend (items, item_array[i]);
3527 g_free (item_array);
3528 g_list_free (icon_view->priv->items);
3529 icon_view->priv->items = items;
3531 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3533 verify_items (icon_view);
3537 gtk_icon_view_build_items (GtkIconView *icon_view)
3541 GList *items = NULL;
3543 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3551 GtkIconViewItem *item = gtk_icon_view_item_new ();
3557 items = g_list_prepend (items, item);
3559 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3561 icon_view->priv->items = g_list_reverse (items);
3565 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3568 GtkMovementStep step,
3572 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3573 I_("move-cursor"), 2,
3577 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3582 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3585 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3590 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3597 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3598 GtkMovementStep step,
3601 GdkModifierType state;
3603 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3604 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3605 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3606 step == GTK_MOVEMENT_DISPLAY_LINES ||
3607 step == GTK_MOVEMENT_PAGES ||
3608 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3610 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3613 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3614 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3616 if (gtk_get_current_event_state (&state))
3618 GdkModifierType extend_mod_mask;
3619 GdkModifierType modify_mod_mask;
3622 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3623 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3625 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3626 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3628 if ((state & modify_mod_mask) == modify_mod_mask)
3629 icon_view->priv->modify_selection_pressed = TRUE;
3630 if ((state & extend_mod_mask) == extend_mod_mask)
3631 icon_view->priv->extend_selection_pressed = TRUE;
3633 /* else we assume not pressed */
3637 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3638 case GTK_MOVEMENT_VISUAL_POSITIONS:
3639 gtk_icon_view_move_cursor_left_right (icon_view, count);
3641 case GTK_MOVEMENT_DISPLAY_LINES:
3642 gtk_icon_view_move_cursor_up_down (icon_view, count);
3644 case GTK_MOVEMENT_PAGES:
3645 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3647 case GTK_MOVEMENT_BUFFER_ENDS:
3648 gtk_icon_view_move_cursor_start_end (icon_view, count);
3651 g_assert_not_reached ();
3654 icon_view->priv->modify_selection_pressed = FALSE;
3655 icon_view->priv->extend_selection_pressed = FALSE;
3657 icon_view->priv->draw_focus = TRUE;
3662 static GtkIconViewItem *
3663 find_item (GtkIconView *icon_view,
3664 GtkIconViewItem *current,
3670 GtkIconViewItem *item;
3672 /* FIXME: this could be more efficient
3674 row = current->row + row_ofs;
3675 col = current->col + col_ofs;
3677 for (items = icon_view->priv->items; items; items = items->next)
3680 if (item->row == row && item->col == col)
3687 static GtkIconViewItem *
3688 find_item_page_up_down (GtkIconView *icon_view,
3689 GtkIconViewItem *current,
3696 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3698 item = g_list_find (icon_view->priv->items, current);
3703 for (next = item->next; next; next = next->next)
3705 if (((GtkIconViewItem *)next->data)->col == col)
3708 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3718 for (next = item->prev; next; next = next->prev)
3720 if (((GtkIconViewItem *)next->data)->col == col)
3723 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3737 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3738 GtkIconViewItem *anchor,
3739 GtkIconViewItem *cursor)
3742 GtkIconViewItem *item;
3743 gint row1, row2, col1, col2;
3744 gboolean dirty = FALSE;
3746 if (anchor->row < cursor->row)
3757 if (anchor->col < cursor->col)
3768 for (items = icon_view->priv->items; items; items = items->next)
3772 if (row1 <= item->row && item->row <= row2 &&
3773 col1 <= item->col && item->col <= col2)
3775 if (!item->selected)
3778 item->selected = TRUE;
3779 gtk_icon_view_item_selected_changed (icon_view, item);
3781 gtk_icon_view_queue_draw_item (icon_view, item);
3789 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3792 GtkIconViewItem *item;
3793 GtkCellRenderer *cell = NULL;
3794 gboolean dirty = FALSE;
3796 GtkDirectionType direction;
3798 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3801 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3803 if (!icon_view->priv->cursor_item)
3808 list = icon_view->priv->items;
3810 list = g_list_last (icon_view->priv->items);
3816 /* Give focus to the first cell initially */
3817 _gtk_icon_view_set_cell_data (icon_view, item);
3818 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3827 item = icon_view->priv->cursor_item;
3828 step = count > 0 ? 1 : -1;
3830 /* Save the current focus cell in case we hit the edge */
3831 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3835 _gtk_icon_view_set_cell_data (icon_view, item);
3837 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3840 item = find_item (icon_view, item, step, 0);
3846 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3848 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3850 gtk_widget_child_focus (toplevel,
3851 direction == GTK_DIR_UP ?
3852 GTK_DIR_TAB_BACKWARD :
3853 GTK_DIR_TAB_FORWARD);
3857 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
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 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3868 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3870 if (!icon_view->priv->modify_selection_pressed &&
3871 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3873 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3874 dirty = gtk_icon_view_select_all_between (icon_view,
3875 icon_view->priv->anchor_item,
3879 gtk_icon_view_scroll_to_item (icon_view, item);
3882 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3886 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3889 GtkIconViewItem *item;
3890 gboolean dirty = FALSE;
3892 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3895 if (!icon_view->priv->cursor_item)
3900 list = icon_view->priv->items;
3902 list = g_list_last (icon_view->priv->items);
3904 item = list ? list->data : NULL;
3907 item = find_item_page_up_down (icon_view,
3908 icon_view->priv->cursor_item,
3911 if (item == icon_view->priv->cursor_item)
3912 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3917 if (icon_view->priv->modify_selection_pressed ||
3918 !icon_view->priv->extend_selection_pressed ||
3919 !icon_view->priv->anchor_item ||
3920 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3921 icon_view->priv->anchor_item = item;
3923 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3925 if (!icon_view->priv->modify_selection_pressed &&
3926 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3928 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3929 dirty = gtk_icon_view_select_all_between (icon_view,
3930 icon_view->priv->anchor_item,
3934 gtk_icon_view_scroll_to_item (icon_view, item);
3937 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3941 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3944 GtkIconViewItem *item;
3945 GtkCellRenderer *cell = NULL;
3946 gboolean dirty = FALSE;
3948 GtkDirectionType direction;
3950 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3953 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3955 if (!icon_view->priv->cursor_item)
3960 list = icon_view->priv->items;
3962 list = g_list_last (icon_view->priv->items);
3968 /* Give focus to the first cell initially */
3969 _gtk_icon_view_set_cell_data (icon_view, item);
3970 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3979 item = icon_view->priv->cursor_item;
3980 step = count > 0 ? 1 : -1;
3982 /* Save the current focus cell in case we hit the edge */
3983 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3987 _gtk_icon_view_set_cell_data (icon_view, item);
3989 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3992 item = find_item (icon_view, item, 0, step);
3998 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4000 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4002 gtk_widget_child_focus (toplevel,
4003 direction == GTK_DIR_LEFT ?
4004 GTK_DIR_TAB_BACKWARD :
4005 GTK_DIR_TAB_FORWARD);
4009 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
4013 if (icon_view->priv->modify_selection_pressed ||
4014 !icon_view->priv->extend_selection_pressed ||
4015 !icon_view->priv->anchor_item ||
4016 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4017 icon_view->priv->anchor_item = item;
4019 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
4020 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
4022 if (!icon_view->priv->modify_selection_pressed &&
4023 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4025 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4026 dirty = gtk_icon_view_select_all_between (icon_view,
4027 icon_view->priv->anchor_item,
4031 gtk_icon_view_scroll_to_item (icon_view, item);
4034 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4038 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4041 GtkIconViewItem *item;
4043 gboolean dirty = FALSE;
4045 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4049 list = icon_view->priv->items;
4051 list = g_list_last (icon_view->priv->items);
4053 item = list ? list->data : NULL;
4055 if (item == icon_view->priv->cursor_item)
4056 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4061 if (icon_view->priv->modify_selection_pressed ||
4062 !icon_view->priv->extend_selection_pressed ||
4063 !icon_view->priv->anchor_item ||
4064 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4065 icon_view->priv->anchor_item = item;
4067 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
4069 if (!icon_view->priv->modify_selection_pressed &&
4070 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4072 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4073 dirty = gtk_icon_view_select_all_between (icon_view,
4074 icon_view->priv->anchor_item,
4078 gtk_icon_view_scroll_to_item (icon_view, item);
4081 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4085 * gtk_icon_view_scroll_to_path:
4086 * @icon_view: A #GtkIconView.
4087 * @path: The path of the item to move to.
4088 * @use_align: whether to use alignment arguments, or %FALSE.
4089 * @row_align: The vertical alignment of the item specified by @path.
4090 * @col_align: The horizontal alignment of the item specified by @path.
4092 * Moves the alignments of @icon_view to the position specified by @path.
4093 * @row_align determines where the row is placed, and @col_align determines
4094 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4095 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4098 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4099 * tree does the minimum amount of work to scroll the item onto the screen.
4100 * This means that the item will be scrolled to the edge closest to its current
4101 * position. If the item is currently visible on the screen, nothing is done.
4103 * This function only works if the model is set, and @path is a valid row on
4104 * the model. If the model changes before the @icon_view is realized, the
4105 * centered path will be modified to reflect this change.
4110 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4116 GtkIconViewItem *item = NULL;
4119 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4120 g_return_if_fail (path != NULL);
4121 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4122 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4124 widget = GTK_WIDGET (icon_view);
4126 if (gtk_tree_path_get_depth (path) > 0)
4127 item = g_list_nth_data (icon_view->priv->items,
4128 gtk_tree_path_get_indices(path)[0]);
4130 if (!item || item->cell_area.width < 0 ||
4131 !gtk_widget_get_realized (widget))
4133 if (icon_view->priv->scroll_to_path)
4134 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4136 icon_view->priv->scroll_to_path = NULL;
4139 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4141 icon_view->priv->scroll_to_use_align = use_align;
4142 icon_view->priv->scroll_to_row_align = row_align;
4143 icon_view->priv->scroll_to_col_align = col_align;
4150 GtkAllocation allocation;
4153 GdkRectangle item_area =
4155 item->cell_area.x - icon_view->priv->item_padding,
4156 item->cell_area.y - icon_view->priv->item_padding,
4157 item->cell_area.width + icon_view->priv->item_padding * 2,
4158 item->cell_area.height + icon_view->priv->item_padding * 2
4161 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4163 gtk_widget_get_allocation (widget, &allocation);
4165 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4167 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4168 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4170 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4172 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4173 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4175 gtk_adjustment_changed (icon_view->priv->hadjustment);
4176 gtk_adjustment_changed (icon_view->priv->vadjustment);
4179 gtk_icon_view_scroll_to_item (icon_view, item);
4184 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4185 GtkIconViewItem *item)
4187 GtkIconViewPrivate *priv = icon_view->priv;
4188 GtkWidget *widget = GTK_WIDGET (icon_view);
4189 GtkAdjustment *hadj, *vadj;
4190 GtkAllocation allocation;
4192 GdkRectangle item_area;
4194 item_area.x = item->cell_area.x - priv->item_padding;
4195 item_area.y = item->cell_area.y - priv->item_padding;
4196 item_area.width = item->cell_area.width + priv->item_padding * 2;
4197 item_area.height = item->cell_area.height + priv->item_padding * 2;
4199 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4200 gtk_widget_get_allocation (widget, &allocation);
4202 hadj = icon_view->priv->hadjustment;
4203 vadj = icon_view->priv->vadjustment;
4205 if (y + item_area.y < 0)
4206 gtk_adjustment_set_value (vadj,
4207 gtk_adjustment_get_value (vadj)
4209 else if (y + item_area.y + item_area.height > allocation.height)
4210 gtk_adjustment_set_value (vadj,
4211 gtk_adjustment_get_value (vadj)
4212 + y + item_area.y + item_area.height - allocation.height);
4214 if (x + item_area.x < 0)
4215 gtk_adjustment_set_value (hadj,
4216 gtk_adjustment_get_value (hadj)
4218 else if (x + item_area.x + item_area.width > allocation.width)
4219 gtk_adjustment_set_value (hadj,
4220 gtk_adjustment_get_value (hadj)
4221 + x + item_area.x + item_area.width - allocation.width);
4223 gtk_adjustment_changed (hadj);
4224 gtk_adjustment_changed (vadj);
4227 /* GtkCellLayout implementation */
4230 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4231 GtkCellArea *cell_area)
4233 GtkIconViewPrivate *priv = icon_view->priv;
4235 if (priv->cell_area)
4239 priv->cell_area = cell_area;
4241 priv->cell_area = gtk_cell_area_box_new ();
4243 g_object_ref_sink (priv->cell_area);
4245 if (GTK_IS_ORIENTABLE (priv->cell_area))
4246 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4248 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4250 priv->add_editable_id =
4251 g_signal_connect (priv->cell_area, "add-editable",
4252 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4253 priv->remove_editable_id =
4254 g_signal_connect (priv->cell_area, "remove-editable",
4255 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4257 update_text_cell (icon_view);
4258 update_pixbuf_cell (icon_view);
4261 static GtkCellArea *
4262 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4264 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4265 GtkIconViewPrivate *priv = icon_view->priv;
4267 if (G_UNLIKELY (!priv->cell_area))
4268 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4270 return icon_view->priv->cell_area;
4274 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4275 GtkIconViewItem *item)
4280 path = gtk_tree_path_new_from_indices (item->index, -1);
4281 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4283 gtk_tree_path_free (path);
4285 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4286 icon_view->priv->model,
4287 &iter, FALSE, FALSE);
4296 * gtk_icon_view_new:
4298 * Creates a new #GtkIconView widget
4300 * Return value: A newly created #GtkIconView widget
4305 gtk_icon_view_new (void)
4307 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4311 * gtk_icon_view_new_with_area:
4312 * @area: the #GtkCellArea to use to layout cells
4314 * Creates a new #GtkIconView widget using the
4315 * specified @area to layout cells inside the icons.
4317 * Return value: A newly created #GtkIconView widget
4322 gtk_icon_view_new_with_area (GtkCellArea *area)
4324 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4328 * gtk_icon_view_new_with_model:
4329 * @model: The model.
4331 * Creates a new #GtkIconView widget with the model @model.
4333 * Return value: A newly created #GtkIconView widget.
4338 gtk_icon_view_new_with_model (GtkTreeModel *model)
4340 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4344 * gtk_icon_view_convert_widget_to_bin_window_coords:
4345 * @icon_view: a #GtkIconView
4346 * @wx: X coordinate relative to the widget
4347 * @wy: Y coordinate relative to the widget
4348 * @bx: (out): return location for bin_window X coordinate
4349 * @by: (out): return location for bin_window Y coordinate
4351 * Converts widget coordinates to coordinates for the bin_window,
4352 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4357 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4365 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4367 if (icon_view->priv->bin_window)
4368 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4379 * gtk_icon_view_get_path_at_pos:
4380 * @icon_view: A #GtkIconView.
4381 * @x: The x position to be identified
4382 * @y: The y position to be identified
4384 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4385 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4386 * the cell at the specified position.
4387 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4388 * widget coordinates to bin_window coordinates.
4390 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4391 * if no icon exists at that position.
4396 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4400 GtkIconViewItem *item;
4403 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4405 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4410 path = gtk_tree_path_new_from_indices (item->index, -1);
4416 * gtk_icon_view_get_item_at_pos:
4417 * @icon_view: A #GtkIconView.
4418 * @x: The x position to be identified
4419 * @y: The y position to be identified
4420 * @path: (out) (allow-none): Return location for the path, or %NULL
4421 * @cell: (out) (allow-none): Return location for the renderer
4422 * responsible for the cell at (@x, @y), or %NULL
4424 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4425 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4426 * obtains the cell at the specified position. The returned path should
4427 * be freed with gtk_tree_path_free().
4428 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4429 * widget coordinates to bin_window coordinates.
4431 * Return value: %TRUE if an item exists at the specified position
4436 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4440 GtkCellRenderer **cell)
4442 GtkIconViewItem *item;
4443 GtkCellRenderer *renderer = NULL;
4445 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4447 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4452 *path = gtk_tree_path_new_from_indices (item->index, -1);
4460 return (item != NULL);
4464 * gtk_icon_view_get_cell_rect:
4465 * @icon_view: a #GtkIconView
4466 * @path: a #GtkTreePath
4467 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4468 * @rect: (out): rectangle to fill with cell rect
4470 * Fills the bounding rectangle in widget coordinates for the cell specified by
4471 * @path and @cell. If @cell is %NULL the main cell area is used.
4473 * This function is only valid if @icon_view is realized.
4475 * Return value: %FALSE if there is no such item, %TRUE otherwise
4480 gtk_icon_view_get_cell_rect (GtkIconView *icon_view,
4482 GtkCellRenderer *cell,
4485 GtkIconViewItem *item = NULL;
4488 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4489 g_return_val_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell), FALSE);
4491 if (gtk_tree_path_get_depth (path) > 0)
4492 item = g_list_nth_data (icon_view->priv->items,
4493 gtk_tree_path_get_indices(path)[0]);
4500 GtkCellAreaContext *context;
4502 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4503 _gtk_icon_view_set_cell_data (icon_view, item);
4504 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4505 GTK_WIDGET (icon_view),
4506 cell, &item->cell_area, rect);
4510 rect->x = item->cell_area.x - icon_view->priv->item_padding;
4511 rect->y = item->cell_area.y - icon_view->priv->item_padding;
4512 rect->width = item->cell_area.width + icon_view->priv->item_padding * 2;
4513 rect->height = item->cell_area.height + icon_view->priv->item_padding * 2;
4516 if (icon_view->priv->bin_window)
4518 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4527 * gtk_icon_view_set_tooltip_item:
4528 * @icon_view: a #GtkIconView
4529 * @tooltip: a #GtkTooltip
4530 * @path: a #GtkTreePath
4532 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4533 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4534 * See also gtk_tooltip_set_tip_area().
4539 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4540 GtkTooltip *tooltip,
4543 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4544 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4546 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4550 * gtk_icon_view_set_tooltip_cell:
4551 * @icon_view: a #GtkIconView
4552 * @tooltip: a #GtkTooltip
4553 * @path: a #GtkTreePath
4554 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4556 * Sets the tip area of @tooltip to the area which @cell occupies in
4557 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4559 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4564 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4565 GtkTooltip *tooltip,
4567 GtkCellRenderer *cell)
4571 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4572 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4573 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4575 if (!gtk_icon_view_get_cell_rect (icon_view, path, cell, &rect))
4578 gtk_tooltip_set_tip_area (tooltip, &rect);
4583 * gtk_icon_view_get_tooltip_context:
4584 * @icon_view: an #GtkIconView
4585 * @x: (inout): the x coordinate (relative to widget coordinates)
4586 * @y: (inout): the y coordinate (relative to widget coordinates)
4587 * @keyboard_tip: whether this is a keyboard tooltip or not
4588 * @model: (out) (allow-none) (transfer none): a pointer to receive a
4589 * #GtkTreeModel or %NULL
4590 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4591 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4593 * This function is supposed to be used in a #GtkWidget::query-tooltip
4594 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4595 * which are received in the signal handler, should be passed to this
4596 * function without modification.
4598 * The return value indicates whether there is an icon view item at the given
4599 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4600 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4601 * @model, @path and @iter which have been provided will be set to point to
4602 * that row and the corresponding model. @x and @y will always be converted
4603 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4605 * Return value: whether or not the given tooltip context points to a item
4610 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4613 gboolean keyboard_tip,
4614 GtkTreeModel **model,
4618 GtkTreePath *tmppath = NULL;
4620 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4621 g_return_val_if_fail (x != NULL, FALSE);
4622 g_return_val_if_fail (y != NULL, FALSE);
4626 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4633 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4636 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4641 *model = gtk_icon_view_get_model (icon_view);
4644 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4650 gtk_tree_path_free (tmppath);
4656 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4659 gboolean keyboard_tip,
4660 GtkTooltip *tooltip,
4666 GtkTreeModel *model;
4667 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4669 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4672 &model, &path, &iter))
4675 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4679 gtk_tree_path_free (path);
4683 gtk_tooltip_set_markup (tooltip, str);
4684 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4686 gtk_tree_path_free (path);
4694 * gtk_icon_view_set_tooltip_column:
4695 * @icon_view: a #GtkIconView
4696 * @column: an integer, which is a valid column number for @icon_view's model
4698 * If you only plan to have simple (text-only) tooltips on full items, you
4699 * can use this function to have #GtkIconView handle these automatically
4700 * for you. @column should be set to the column in @icon_view's model
4701 * containing the tooltip texts, or -1 to disable this feature.
4703 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4704 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4706 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4707 * so &, <, etc have to be escaped in the text.
4712 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4715 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4717 if (column == icon_view->priv->tooltip_column)
4722 g_signal_handlers_disconnect_by_func (icon_view,
4723 gtk_icon_view_set_tooltip_query_cb,
4725 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4729 if (icon_view->priv->tooltip_column == -1)
4731 g_signal_connect (icon_view, "query-tooltip",
4732 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4733 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4737 icon_view->priv->tooltip_column = column;
4738 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4742 * gtk_icon_view_get_tooltip_column:
4743 * @icon_view: a #GtkIconView
4745 * Returns the column of @icon_view's model which is being used for
4746 * displaying tooltips on @icon_view's rows.
4748 * Return value: the index of the tooltip column that is currently being
4749 * used, or -1 if this is disabled.
4754 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4756 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4758 return icon_view->priv->tooltip_column;
4762 * gtk_icon_view_get_visible_range:
4763 * @icon_view: A #GtkIconView
4764 * @start_path: (out) (allow-none): Return location for start of region,
4766 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4768 * Sets @start_path and @end_path to be the first and last visible path.
4769 * Note that there may be invisible paths in between.
4771 * Both paths should be freed with gtk_tree_path_free() after use.
4773 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4778 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4779 GtkTreePath **start_path,
4780 GtkTreePath **end_path)
4782 gint start_index = -1;
4783 gint end_index = -1;
4786 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4788 if (icon_view->priv->hadjustment == NULL ||
4789 icon_view->priv->vadjustment == NULL)
4792 if (start_path == NULL && end_path == NULL)
4795 for (icons = icon_view->priv->items; icons; icons = icons->next)
4797 GtkIconViewItem *item = icons->data;
4798 GdkRectangle *item_area = &item->cell_area;
4800 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4801 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4803 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4804 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4806 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4807 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4809 if (start_index == -1)
4810 start_index = item->index;
4811 end_index = item->index;
4815 if (start_path && start_index != -1)
4816 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4817 if (end_path && end_index != -1)
4818 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4820 return start_index != -1;
4824 * gtk_icon_view_selected_foreach:
4825 * @icon_view: A #GtkIconView.
4826 * @func: (scope call): The function to call for each selected icon.
4827 * @data: User data to pass to the function.
4829 * Calls a function for each selected icon. Note that the model or
4830 * selection cannot be modified from within this function.
4835 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4836 GtkIconViewForeachFunc func,
4841 for (list = icon_view->priv->items; list; list = list->next)
4843 GtkIconViewItem *item = list->data;
4844 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4847 (* func) (icon_view, path, data);
4849 gtk_tree_path_free (path);
4854 * gtk_icon_view_set_selection_mode:
4855 * @icon_view: A #GtkIconView.
4856 * @mode: The selection mode
4858 * Sets the selection mode of the @icon_view.
4863 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4864 GtkSelectionMode mode)
4866 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4868 if (mode == icon_view->priv->selection_mode)
4871 if (mode == GTK_SELECTION_NONE ||
4872 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4873 gtk_icon_view_unselect_all (icon_view);
4875 icon_view->priv->selection_mode = mode;
4877 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4881 * gtk_icon_view_get_selection_mode:
4882 * @icon_view: A #GtkIconView.
4884 * Gets the selection mode of the @icon_view.
4886 * Return value: the current selection mode
4891 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4893 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4895 return icon_view->priv->selection_mode;
4899 * gtk_icon_view_set_model:
4900 * @icon_view: A #GtkIconView.
4901 * @model: (allow-none): The model.
4903 * Sets the model for a #GtkIconView.
4904 * If the @icon_view already has a model set, it will remove
4905 * it before setting the new model. If @model is %NULL, then
4906 * it will unset the old model.
4911 gtk_icon_view_set_model (GtkIconView *icon_view,
4912 GtkTreeModel *model)
4916 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4917 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4919 if (icon_view->priv->model == model)
4922 if (icon_view->priv->scroll_to_path)
4924 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4925 icon_view->priv->scroll_to_path = NULL;
4928 /* The area can be NULL while disposing */
4929 if (icon_view->priv->cell_area)
4930 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4932 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4938 if (icon_view->priv->pixbuf_column != -1)
4940 column_type = gtk_tree_model_get_column_type (model,
4941 icon_view->priv->pixbuf_column);
4943 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4946 if (icon_view->priv->text_column != -1)
4948 column_type = gtk_tree_model_get_column_type (model,
4949 icon_view->priv->text_column);
4951 g_return_if_fail (column_type == G_TYPE_STRING);
4954 if (icon_view->priv->markup_column != -1)
4956 column_type = gtk_tree_model_get_column_type (model,
4957 icon_view->priv->markup_column);
4959 g_return_if_fail (column_type == G_TYPE_STRING);
4964 if (icon_view->priv->model)
4966 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4967 gtk_icon_view_row_changed,
4969 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4970 gtk_icon_view_row_inserted,
4972 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4973 gtk_icon_view_row_deleted,
4975 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4976 gtk_icon_view_rows_reordered,
4979 g_object_unref (icon_view->priv->model);
4981 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4982 icon_view->priv->items = NULL;
4983 icon_view->priv->anchor_item = NULL;
4984 icon_view->priv->cursor_item = NULL;
4985 icon_view->priv->last_single_clicked = NULL;
4986 icon_view->priv->last_prelight = NULL;
4987 icon_view->priv->width = 0;
4988 icon_view->priv->height = 0;
4991 icon_view->priv->model = model;
4993 if (icon_view->priv->model)
4995 g_object_ref (icon_view->priv->model);
4996 g_signal_connect (icon_view->priv->model,
4998 G_CALLBACK (gtk_icon_view_row_changed),
5000 g_signal_connect (icon_view->priv->model,
5002 G_CALLBACK (gtk_icon_view_row_inserted),
5004 g_signal_connect (icon_view->priv->model,
5006 G_CALLBACK (gtk_icon_view_row_deleted),
5008 g_signal_connect (icon_view->priv->model,
5010 G_CALLBACK (gtk_icon_view_rows_reordered),
5013 gtk_icon_view_build_items (icon_view);
5016 g_object_notify (G_OBJECT (icon_view), "model");
5019 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5021 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5025 * gtk_icon_view_get_model:
5026 * @icon_view: a #GtkIconView
5028 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5031 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
5032 * currently being used.
5037 gtk_icon_view_get_model (GtkIconView *icon_view)
5039 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5041 return icon_view->priv->model;
5045 update_text_cell (GtkIconView *icon_view)
5047 if (!icon_view->priv->cell_area)
5050 if (icon_view->priv->text_column == -1 &&
5051 icon_view->priv->markup_column == -1)
5053 if (icon_view->priv->text_cell != NULL)
5055 gtk_cell_area_remove (icon_view->priv->cell_area,
5056 icon_view->priv->text_cell);
5057 icon_view->priv->text_cell = NULL;
5062 if (icon_view->priv->text_cell == NULL)
5064 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
5066 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
5069 if (icon_view->priv->markup_column != -1)
5070 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5071 icon_view->priv->text_cell,
5072 "markup", icon_view->priv->markup_column,
5075 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5076 icon_view->priv->text_cell,
5077 "text", icon_view->priv->text_column,
5080 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5081 g_object_set (icon_view->priv->text_cell,
5082 "alignment", PANGO_ALIGN_CENTER,
5083 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5088 g_object_set (icon_view->priv->text_cell,
5089 "alignment", PANGO_ALIGN_LEFT,
5090 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5098 update_pixbuf_cell (GtkIconView *icon_view)
5100 if (!icon_view->priv->cell_area)
5103 if (icon_view->priv->pixbuf_column == -1)
5105 if (icon_view->priv->pixbuf_cell != NULL)
5107 gtk_cell_area_remove (icon_view->priv->cell_area,
5108 icon_view->priv->pixbuf_cell);
5110 icon_view->priv->pixbuf_cell = NULL;
5115 if (icon_view->priv->pixbuf_cell == NULL)
5117 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
5119 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
5122 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5123 icon_view->priv->pixbuf_cell,
5124 "pixbuf", icon_view->priv->pixbuf_column,
5127 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5128 g_object_set (icon_view->priv->pixbuf_cell,
5133 g_object_set (icon_view->priv->pixbuf_cell,
5141 * gtk_icon_view_set_text_column:
5142 * @icon_view: A #GtkIconView.
5143 * @column: A column in the currently used model, or -1 to display no text
5145 * Sets the column with text for @icon_view to be @column. The text
5146 * column must be of type #G_TYPE_STRING.
5151 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5154 if (column == icon_view->priv->text_column)
5158 icon_view->priv->text_column = -1;
5161 if (icon_view->priv->model != NULL)
5165 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5167 g_return_if_fail (column_type == G_TYPE_STRING);
5170 icon_view->priv->text_column = column;
5173 if (icon_view->priv->cell_area)
5174 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5176 update_text_cell (icon_view);
5178 gtk_icon_view_invalidate_sizes (icon_view);
5180 g_object_notify (G_OBJECT (icon_view), "text-column");
5184 * gtk_icon_view_get_text_column:
5185 * @icon_view: A #GtkIconView.
5187 * Returns the column with text for @icon_view.
5189 * Returns: the text column, or -1 if it's unset.
5194 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5196 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5198 return icon_view->priv->text_column;
5202 * gtk_icon_view_set_markup_column:
5203 * @icon_view: A #GtkIconView.
5204 * @column: A column in the currently used model, or -1 to display no text
5206 * Sets the column with markup information for @icon_view to be
5207 * @column. The markup column must be of type #G_TYPE_STRING.
5208 * If the markup column is set to something, it overrides
5209 * the text column set by gtk_icon_view_set_text_column().
5214 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5217 if (column == icon_view->priv->markup_column)
5221 icon_view->priv->markup_column = -1;
5224 if (icon_view->priv->model != NULL)
5228 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5230 g_return_if_fail (column_type == G_TYPE_STRING);
5233 icon_view->priv->markup_column = column;
5236 if (icon_view->priv->cell_area)
5237 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5239 update_text_cell (icon_view);
5241 gtk_icon_view_invalidate_sizes (icon_view);
5243 g_object_notify (G_OBJECT (icon_view), "markup-column");
5247 * gtk_icon_view_get_markup_column:
5248 * @icon_view: A #GtkIconView.
5250 * Returns the column with markup text for @icon_view.
5252 * Returns: the markup column, or -1 if it's unset.
5257 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5259 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5261 return icon_view->priv->markup_column;
5265 * gtk_icon_view_set_pixbuf_column:
5266 * @icon_view: A #GtkIconView.
5267 * @column: A column in the currently used model, or -1 to disable
5269 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5270 * column must be of type #GDK_TYPE_PIXBUF
5275 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5278 if (column == icon_view->priv->pixbuf_column)
5282 icon_view->priv->pixbuf_column = -1;
5285 if (icon_view->priv->model != NULL)
5289 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5291 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5294 icon_view->priv->pixbuf_column = column;
5297 if (icon_view->priv->cell_area)
5298 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5300 update_pixbuf_cell (icon_view);
5302 gtk_icon_view_invalidate_sizes (icon_view);
5304 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5309 * gtk_icon_view_get_pixbuf_column:
5310 * @icon_view: A #GtkIconView.
5312 * Returns the column with pixbufs for @icon_view.
5314 * Returns: the pixbuf column, or -1 if it's unset.
5319 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5321 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5323 return icon_view->priv->pixbuf_column;
5327 * gtk_icon_view_select_path:
5328 * @icon_view: A #GtkIconView.
5329 * @path: The #GtkTreePath to be selected.
5331 * Selects the row at @path.
5336 gtk_icon_view_select_path (GtkIconView *icon_view,
5339 GtkIconViewItem *item = NULL;
5341 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5342 g_return_if_fail (icon_view->priv->model != NULL);
5343 g_return_if_fail (path != NULL);
5345 if (gtk_tree_path_get_depth (path) > 0)
5346 item = g_list_nth_data (icon_view->priv->items,
5347 gtk_tree_path_get_indices(path)[0]);
5350 _gtk_icon_view_select_item (icon_view, item);
5354 * gtk_icon_view_unselect_path:
5355 * @icon_view: A #GtkIconView.
5356 * @path: The #GtkTreePath to be unselected.
5358 * Unselects the row at @path.
5363 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5366 GtkIconViewItem *item;
5368 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5369 g_return_if_fail (icon_view->priv->model != NULL);
5370 g_return_if_fail (path != NULL);
5372 item = g_list_nth_data (icon_view->priv->items,
5373 gtk_tree_path_get_indices(path)[0]);
5378 _gtk_icon_view_unselect_item (icon_view, item);
5382 * gtk_icon_view_get_selected_items:
5383 * @icon_view: A #GtkIconView.
5385 * Creates a list of paths of all selected items. Additionally, if you are
5386 * planning on modifying the model after calling this function, you may
5387 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5388 * To do this, you can use gtk_tree_row_reference_new().
5390 * To free the return value, use:
5392 * g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
5395 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5400 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5403 GList *selected = NULL;
5405 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5407 for (list = icon_view->priv->items; list != NULL; list = list->next)
5409 GtkIconViewItem *item = list->data;
5413 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5415 selected = g_list_prepend (selected, path);
5423 * gtk_icon_view_select_all:
5424 * @icon_view: A #GtkIconView.
5426 * Selects all the icons. @icon_view must has its selection mode set
5427 * to #GTK_SELECTION_MULTIPLE.
5432 gtk_icon_view_select_all (GtkIconView *icon_view)
5435 gboolean dirty = FALSE;
5437 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5439 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5442 for (items = icon_view->priv->items; items; items = items->next)
5444 GtkIconViewItem *item = items->data;
5446 if (!item->selected)
5449 item->selected = TRUE;
5450 gtk_icon_view_queue_draw_item (icon_view, item);
5455 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5459 * gtk_icon_view_unselect_all:
5460 * @icon_view: A #GtkIconView.
5462 * Unselects all the icons.
5467 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5469 gboolean dirty = FALSE;
5471 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5473 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5476 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5479 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5483 * gtk_icon_view_path_is_selected:
5484 * @icon_view: A #GtkIconView.
5485 * @path: A #GtkTreePath to check selection on.
5487 * Returns %TRUE if the icon pointed to by @path is currently
5488 * selected. If @path does not point to a valid location, %FALSE is returned.
5490 * Return value: %TRUE if @path is selected.
5495 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5498 GtkIconViewItem *item;
5500 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5501 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5502 g_return_val_if_fail (path != NULL, FALSE);
5504 item = g_list_nth_data (icon_view->priv->items,
5505 gtk_tree_path_get_indices(path)[0]);
5510 return item->selected;
5514 * gtk_icon_view_get_item_row:
5515 * @icon_view: a #GtkIconView
5516 * @path: the #GtkTreePath of the item
5518 * Gets the row in which the item @path is currently
5519 * displayed. Row numbers start at 0.
5521 * Returns: The row in which the item is displayed
5526 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5529 GtkIconViewItem *item;
5531 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5532 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5533 g_return_val_if_fail (path != NULL, -1);
5535 item = g_list_nth_data (icon_view->priv->items,
5536 gtk_tree_path_get_indices(path)[0]);
5545 * gtk_icon_view_get_item_column:
5546 * @icon_view: a #GtkIconView
5547 * @path: the #GtkTreePath of the item
5549 * Gets the column in which the item @path is currently
5550 * displayed. Column numbers start at 0.
5552 * Returns: The column in which the item is displayed
5557 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5560 GtkIconViewItem *item;
5562 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5563 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5564 g_return_val_if_fail (path != NULL, -1);
5566 item = g_list_nth_data (icon_view->priv->items,
5567 gtk_tree_path_get_indices(path)[0]);
5576 * gtk_icon_view_item_activated:
5577 * @icon_view: A #GtkIconView
5578 * @path: The #GtkTreePath to be activated
5580 * Activates the item determined by @path.
5585 gtk_icon_view_item_activated (GtkIconView *icon_view,
5588 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5589 g_return_if_fail (path != NULL);
5591 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5595 * gtk_icon_view_set_item_orientation:
5596 * @icon_view: a #GtkIconView
5597 * @orientation: the relative position of texts and icons
5599 * Sets the ::item-orientation property which determines whether the labels
5600 * are drawn beside the icons instead of below.
5605 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5606 GtkOrientation orientation)
5608 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5610 if (icon_view->priv->item_orientation != orientation)
5612 icon_view->priv->item_orientation = orientation;
5614 if (icon_view->priv->cell_area)
5616 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5617 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5618 icon_view->priv->item_orientation);
5620 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5623 gtk_icon_view_invalidate_sizes (icon_view);
5625 update_text_cell (icon_view);
5626 update_pixbuf_cell (icon_view);
5628 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5633 * gtk_icon_view_get_item_orientation:
5634 * @icon_view: a #GtkIconView
5636 * Returns the value of the ::item-orientation property which determines
5637 * whether the labels are drawn beside the icons instead of below.
5639 * Return value: the relative position of texts and icons
5644 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5646 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5647 GTK_ORIENTATION_VERTICAL);
5649 return icon_view->priv->item_orientation;
5653 * gtk_icon_view_set_columns:
5654 * @icon_view: a #GtkIconView
5655 * @columns: the number of columns
5657 * Sets the ::columns property which determines in how
5658 * many columns the icons are arranged. If @columns is
5659 * -1, the number of columns will be chosen automatically
5660 * to fill the available area.
5665 gtk_icon_view_set_columns (GtkIconView *icon_view,
5668 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5670 if (icon_view->priv->columns != columns)
5672 icon_view->priv->columns = columns;
5674 if (icon_view->priv->cell_area)
5675 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5677 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5679 g_object_notify (G_OBJECT (icon_view), "columns");
5684 * gtk_icon_view_get_columns:
5685 * @icon_view: a #GtkIconView
5687 * Returns the value of the ::columns property.
5689 * Return value: the number of columns, or -1
5694 gtk_icon_view_get_columns (GtkIconView *icon_view)
5696 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5698 return icon_view->priv->columns;
5702 * gtk_icon_view_set_item_width:
5703 * @icon_view: a #GtkIconView
5704 * @item_width: the width for each item
5706 * Sets the ::item-width property which specifies the width
5707 * to use for each item. If it is set to -1, the icon view will
5708 * automatically determine a suitable item size.
5713 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5716 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5718 if (icon_view->priv->item_width != item_width)
5720 icon_view->priv->item_width = item_width;
5722 if (icon_view->priv->cell_area)
5723 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5725 gtk_icon_view_invalidate_sizes (icon_view);
5727 update_text_cell (icon_view);
5729 g_object_notify (G_OBJECT (icon_view), "item-width");
5734 * gtk_icon_view_get_item_width:
5735 * @icon_view: a #GtkIconView
5737 * Returns the value of the ::item-width property.
5739 * Return value: the width of a single item, or -1
5744 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5746 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5748 return icon_view->priv->item_width;
5753 * gtk_icon_view_set_spacing:
5754 * @icon_view: a #GtkIconView
5755 * @spacing: the spacing
5757 * Sets the ::spacing property which specifies the space
5758 * which is inserted between the cells (i.e. the icon and
5759 * the text) of an item.
5764 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5767 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5769 if (icon_view->priv->spacing != spacing)
5771 icon_view->priv->spacing = spacing;
5773 if (icon_view->priv->cell_area)
5774 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5776 gtk_icon_view_invalidate_sizes (icon_view);
5778 g_object_notify (G_OBJECT (icon_view), "spacing");
5783 * gtk_icon_view_get_spacing:
5784 * @icon_view: a #GtkIconView
5786 * Returns the value of the ::spacing property.
5788 * Return value: the space between cells
5793 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5795 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5797 return icon_view->priv->spacing;
5801 * gtk_icon_view_set_row_spacing:
5802 * @icon_view: a #GtkIconView
5803 * @row_spacing: the row spacing
5805 * Sets the ::row-spacing property which specifies the space
5806 * which is inserted between the rows of the icon view.
5811 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5814 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5816 if (icon_view->priv->row_spacing != row_spacing)
5818 icon_view->priv->row_spacing = row_spacing;
5820 if (icon_view->priv->cell_area)
5821 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5823 gtk_icon_view_invalidate_sizes (icon_view);
5825 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5830 * gtk_icon_view_get_row_spacing:
5831 * @icon_view: a #GtkIconView
5833 * Returns the value of the ::row-spacing property.
5835 * Return value: the space between rows
5840 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5842 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5844 return icon_view->priv->row_spacing;
5848 * gtk_icon_view_set_column_spacing:
5849 * @icon_view: a #GtkIconView
5850 * @column_spacing: the column spacing
5852 * Sets the ::column-spacing property which specifies the space
5853 * which is inserted between the columns of the icon view.
5858 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5859 gint column_spacing)
5861 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5863 if (icon_view->priv->column_spacing != column_spacing)
5865 icon_view->priv->column_spacing = column_spacing;
5867 if (icon_view->priv->cell_area)
5868 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5870 gtk_icon_view_invalidate_sizes (icon_view);
5872 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5877 * gtk_icon_view_get_column_spacing:
5878 * @icon_view: a #GtkIconView
5880 * Returns the value of the ::column-spacing property.
5882 * Return value: the space between columns
5887 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5889 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5891 return icon_view->priv->column_spacing;
5895 * gtk_icon_view_set_margin:
5896 * @icon_view: a #GtkIconView
5897 * @margin: the margin
5899 * Sets the ::margin property which specifies the space
5900 * which is inserted at the top, bottom, left and right
5906 gtk_icon_view_set_margin (GtkIconView *icon_view,
5909 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5911 if (icon_view->priv->margin != margin)
5913 icon_view->priv->margin = margin;
5915 if (icon_view->priv->cell_area)
5916 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5918 gtk_icon_view_invalidate_sizes (icon_view);
5920 g_object_notify (G_OBJECT (icon_view), "margin");
5925 * gtk_icon_view_get_margin:
5926 * @icon_view: a #GtkIconView
5928 * Returns the value of the ::margin property.
5930 * Return value: the space at the borders
5935 gtk_icon_view_get_margin (GtkIconView *icon_view)
5937 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5939 return icon_view->priv->margin;
5943 * gtk_icon_view_set_item_padding:
5944 * @icon_view: a #GtkIconView
5945 * @item_padding: the item padding
5947 * Sets the #GtkIconView:item-padding property which specifies the padding
5948 * around each of the icon view's items.
5953 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5956 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5958 if (icon_view->priv->item_padding != item_padding)
5960 icon_view->priv->item_padding = item_padding;
5962 if (icon_view->priv->cell_area)
5963 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5965 gtk_icon_view_invalidate_sizes (icon_view);
5967 g_object_notify (G_OBJECT (icon_view), "item-padding");
5972 * gtk_icon_view_get_item_padding:
5973 * @icon_view: a #GtkIconView
5975 * Returns the value of the ::item-padding property.
5977 * Return value: the padding around items
5982 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5984 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5986 return icon_view->priv->item_padding;
5989 /* Get/set whether drag_motion requested the drag data and
5990 * drag_data_received should thus not actually insert the data,
5991 * since the data doesn't result from a drop.
5994 set_status_pending (GdkDragContext *context,
5995 GdkDragAction suggested_action)
5997 g_object_set_data (G_OBJECT (context),
5998 I_("gtk-icon-view-status-pending"),
5999 GINT_TO_POINTER (suggested_action));
6002 static GdkDragAction
6003 get_status_pending (GdkDragContext *context)
6005 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6006 "gtk-icon-view-status-pending"));
6010 unset_reorderable (GtkIconView *icon_view)
6012 if (icon_view->priv->reorderable)
6014 icon_view->priv->reorderable = FALSE;
6015 g_object_notify (G_OBJECT (icon_view), "reorderable");
6020 set_source_row (GdkDragContext *context,
6021 GtkTreeModel *model,
6022 GtkTreePath *source_row)
6025 g_object_set_data_full (G_OBJECT (context),
6026 I_("gtk-icon-view-source-row"),
6027 gtk_tree_row_reference_new (model, source_row),
6028 (GDestroyNotify) gtk_tree_row_reference_free);
6030 g_object_set_data_full (G_OBJECT (context),
6031 I_("gtk-icon-view-source-row"),
6036 get_source_row (GdkDragContext *context)
6038 GtkTreeRowReference *ref;
6040 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6043 return gtk_tree_row_reference_get_path (ref);
6050 GtkTreeRowReference *dest_row;
6051 gboolean empty_view_drop;
6052 gboolean drop_append_mode;
6056 dest_row_free (gpointer data)
6058 DestRow *dr = (DestRow *)data;
6060 gtk_tree_row_reference_free (dr->dest_row);
6065 set_dest_row (GdkDragContext *context,
6066 GtkTreeModel *model,
6067 GtkTreePath *dest_row,
6068 gboolean empty_view_drop,
6069 gboolean drop_append_mode)
6075 g_object_set_data_full (G_OBJECT (context),
6076 I_("gtk-icon-view-dest-row"),
6081 dr = g_new0 (DestRow, 1);
6083 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6084 dr->empty_view_drop = empty_view_drop;
6085 dr->drop_append_mode = drop_append_mode;
6086 g_object_set_data_full (G_OBJECT (context),
6087 I_("gtk-icon-view-dest-row"),
6088 dr, (GDestroyNotify) dest_row_free);
6092 get_dest_row (GdkDragContext *context)
6096 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6100 GtkTreePath *path = NULL;
6103 path = gtk_tree_row_reference_get_path (dr->dest_row);
6104 else if (dr->empty_view_drop)
6105 path = gtk_tree_path_new_from_indices (0, -1);
6109 if (path && dr->drop_append_mode)
6110 gtk_tree_path_next (path);
6119 check_model_dnd (GtkTreeModel *model,
6120 GType required_iface,
6121 const gchar *signal)
6123 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6125 g_warning ("You must override the default '%s' handler "
6126 "on GtkIconView when using models that don't support "
6127 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6128 "is to connect to '%s' and call "
6129 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6130 "the default handler from running. Look at the source code "
6131 "for the default handler in gtkiconview.c to get an idea what "
6132 "your handler should do. (gtkiconview.c is in the GTK+ source "
6133 "code.) If you're using GTK+ from a language other than C, "
6134 "there may be a more natural way to override default handlers, e.g. via derivation.",
6135 signal, g_type_name (required_iface), signal);
6143 remove_scroll_timeout (GtkIconView *icon_view)
6145 if (icon_view->priv->scroll_timeout_id != 0)
6147 g_source_remove (icon_view->priv->scroll_timeout_id);
6149 icon_view->priv->scroll_timeout_id = 0;
6154 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6158 gint px, py, width, height;
6159 gint hoffset, voffset;
6161 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6163 gdk_window_get_device_position (window, device, &px, &py, NULL);
6164 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
6166 /* see if we are near the edge. */
6167 voffset = py - 2 * SCROLL_EDGE_SIZE;
6169 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
6171 hoffset = px - 2 * SCROLL_EDGE_SIZE;
6173 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
6176 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6177 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6180 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6181 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6185 GtkIconView *icon_view;
6190 drag_scroll_timeout (gpointer datap)
6192 DragScrollData *data = datap;
6194 gtk_icon_view_autoscroll (data->icon_view, data->device);
6200 drag_scroll_data_free (DragScrollData *data)
6202 g_slice_free (DragScrollData, data);
6206 set_destination (GtkIconView *icon_view,
6207 GdkDragContext *context,
6210 GdkDragAction *suggested_action,
6214 GtkTreePath *path = NULL;
6215 GtkIconViewDropPosition pos;
6216 GtkIconViewDropPosition old_pos;
6217 GtkTreePath *old_dest_path = NULL;
6218 gboolean can_drop = FALSE;
6220 widget = GTK_WIDGET (icon_view);
6222 *suggested_action = 0;
6225 if (!icon_view->priv->dest_set)
6227 /* someone unset us as a drag dest, note that if
6228 * we return FALSE drag_leave isn't called
6231 gtk_icon_view_set_drag_dest_item (icon_view,
6233 GTK_ICON_VIEW_DROP_LEFT);
6235 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6237 return FALSE; /* no longer a drop site */
6240 *target = gtk_drag_dest_find_target (widget, context,
6241 gtk_drag_dest_get_target_list (widget));
6242 if (*target == GDK_NONE)
6245 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6248 GtkTreeModel *model;
6250 /* the row got dropped on empty space, let's setup a special case
6254 gtk_tree_path_free (path);
6256 model = gtk_icon_view_get_model (icon_view);
6258 n_children = gtk_tree_model_iter_n_children (model, NULL);
6261 pos = GTK_ICON_VIEW_DROP_BELOW;
6262 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6266 pos = GTK_ICON_VIEW_DROP_ABOVE;
6267 path = gtk_tree_path_new_from_indices (0, -1);
6277 gtk_icon_view_get_drag_dest_item (icon_view,
6282 gtk_tree_path_free (old_dest_path);
6284 if (TRUE /* FIXME if the location droppable predicate */)
6292 GtkWidget *source_widget;
6294 *suggested_action = gdk_drag_context_get_suggested_action (context);
6295 source_widget = gtk_drag_get_source_widget (context);
6297 if (source_widget == widget)
6299 /* Default to MOVE, unless the user has
6300 * pressed ctrl or shift to affect available actions
6302 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6303 *suggested_action = GDK_ACTION_MOVE;
6306 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6311 /* can't drop here */
6312 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6314 GTK_ICON_VIEW_DROP_LEFT);
6318 gtk_tree_path_free (path);
6324 get_logical_destination (GtkIconView *icon_view,
6325 gboolean *drop_append_mode)
6327 /* adjust path to point to the row the drop goes in front of */
6328 GtkTreePath *path = NULL;
6329 GtkIconViewDropPosition pos;
6331 *drop_append_mode = FALSE;
6333 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6338 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6339 pos == GTK_ICON_VIEW_DROP_BELOW)
6342 GtkTreeModel *model = icon_view->priv->model;
6344 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6345 !gtk_tree_model_iter_next (model, &iter))
6346 *drop_append_mode = TRUE;
6349 *drop_append_mode = FALSE;
6350 gtk_tree_path_next (path);
6358 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6359 GdkEventMotion *event)
6361 GtkWidget *widget = GTK_WIDGET (icon_view);
6362 GdkDragContext *context;
6363 GtkTreePath *path = NULL;
6365 GtkTreeModel *model;
6366 gboolean retval = FALSE;
6368 if (!icon_view->priv->source_set)
6371 if (icon_view->priv->pressed_button < 0)
6374 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6375 icon_view->priv->press_start_x,
6376 icon_view->priv->press_start_y,
6377 event->x, event->y))
6380 model = gtk_icon_view_get_model (icon_view);
6385 button = icon_view->priv->pressed_button;
6386 icon_view->priv->pressed_button = -1;
6388 path = gtk_icon_view_get_path_at_pos (icon_view,
6389 icon_view->priv->press_start_x,
6390 icon_view->priv->press_start_y);
6395 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6396 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6400 /* FIXME Check whether we're a start button, if not return FALSE and
6404 /* Now we can begin the drag */
6408 context = gtk_drag_begin (widget,
6409 gtk_drag_source_get_target_list (widget),
6410 icon_view->priv->source_actions,
6414 set_source_row (context, model, path);
6418 gtk_tree_path_free (path);
6423 /* Source side drag signals */
6425 gtk_icon_view_drag_begin (GtkWidget *widget,
6426 GdkDragContext *context)
6428 GtkIconView *icon_view;
6429 GtkIconViewItem *item;
6430 cairo_surface_t *icon;
6434 icon_view = GTK_ICON_VIEW (widget);
6436 /* if the user uses a custom DnD impl, we don't set the icon here */
6437 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6440 item = _gtk_icon_view_get_item_at_coords (icon_view,
6441 icon_view->priv->press_start_x,
6442 icon_view->priv->press_start_y,
6446 g_return_if_fail (item != NULL);
6448 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6449 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6451 path = gtk_tree_path_new_from_indices (item->index, -1);
6452 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6453 gtk_tree_path_free (path);
6455 cairo_surface_set_device_offset (icon, -x, -y);
6457 gtk_drag_set_icon_surface (context, icon);
6459 cairo_surface_destroy (icon);
6463 gtk_icon_view_drag_end (GtkWidget *widget,
6464 GdkDragContext *context)
6470 gtk_icon_view_drag_data_get (GtkWidget *widget,
6471 GdkDragContext *context,
6472 GtkSelectionData *selection_data,
6476 GtkIconView *icon_view;
6477 GtkTreeModel *model;
6478 GtkTreePath *source_row;
6480 icon_view = GTK_ICON_VIEW (widget);
6481 model = gtk_icon_view_get_model (icon_view);
6486 if (!icon_view->priv->source_set)
6489 source_row = get_source_row (context);
6491 if (source_row == NULL)
6494 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6495 * any model; for DragSource models there are some other targets
6499 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6500 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6505 /* If drag_data_get does nothing, try providing row data. */
6506 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6507 gtk_tree_set_row_drag_data (selection_data,
6512 gtk_tree_path_free (source_row);
6516 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6517 GdkDragContext *context)
6519 GtkTreeModel *model;
6520 GtkIconView *icon_view;
6521 GtkTreePath *source_row;
6523 icon_view = GTK_ICON_VIEW (widget);
6524 model = gtk_icon_view_get_model (icon_view);
6526 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6529 if (!icon_view->priv->source_set)
6532 source_row = get_source_row (context);
6534 if (source_row == NULL)
6537 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6540 gtk_tree_path_free (source_row);
6542 set_source_row (context, NULL, NULL);
6545 /* Target side drag signals */
6547 gtk_icon_view_drag_leave (GtkWidget *widget,
6548 GdkDragContext *context,
6551 GtkIconView *icon_view;
6553 icon_view = GTK_ICON_VIEW (widget);
6555 /* unset any highlight row */
6556 gtk_icon_view_set_drag_dest_item (icon_view,
6558 GTK_ICON_VIEW_DROP_LEFT);
6560 remove_scroll_timeout (icon_view);
6564 gtk_icon_view_drag_motion (GtkWidget *widget,
6565 GdkDragContext *context,
6570 GtkTreePath *path = NULL;
6571 GtkIconViewDropPosition pos;
6572 GtkIconView *icon_view;
6573 GdkDragAction suggested_action = 0;
6577 icon_view = GTK_ICON_VIEW (widget);
6579 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6582 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6584 /* we only know this *after* set_desination_row */
6585 empty = icon_view->priv->empty_view_drop;
6587 if (path == NULL && !empty)
6589 /* Can't drop here. */
6590 gdk_drag_status (context, 0, time);
6594 if (icon_view->priv->scroll_timeout_id == 0)
6596 DragScrollData *data = g_slice_new (DragScrollData);
6597 data->icon_view = icon_view;
6598 data->device = gdk_drag_context_get_device (context);
6600 icon_view->priv->scroll_timeout_id =
6601 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6604 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6606 /* Request data so we can use the source row when
6607 * determining whether to accept the drop
6609 set_status_pending (context, suggested_action);
6610 gtk_drag_get_data (widget, context, target, time);
6614 set_status_pending (context, 0);
6615 gdk_drag_status (context, suggested_action, time);
6620 gtk_tree_path_free (path);
6626 gtk_icon_view_drag_drop (GtkWidget *widget,
6627 GdkDragContext *context,
6632 GtkIconView *icon_view;
6634 GdkDragAction suggested_action = 0;
6635 GdkAtom target = GDK_NONE;
6636 GtkTreeModel *model;
6637 gboolean drop_append_mode;
6639 icon_view = GTK_ICON_VIEW (widget);
6640 model = gtk_icon_view_get_model (icon_view);
6642 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6644 if (!icon_view->priv->dest_set)
6647 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6650 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6653 path = get_logical_destination (icon_view, &drop_append_mode);
6655 if (target != GDK_NONE && path != NULL)
6657 /* in case a motion had requested drag data, change things so we
6658 * treat drag data receives as a drop.
6660 set_status_pending (context, 0);
6661 set_dest_row (context, model, path,
6662 icon_view->priv->empty_view_drop, drop_append_mode);
6666 gtk_tree_path_free (path);
6668 /* Unset this thing */
6669 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6671 if (target != GDK_NONE)
6673 gtk_drag_get_data (widget, context, target, time);
6681 gtk_icon_view_drag_data_received (GtkWidget *widget,
6682 GdkDragContext *context,
6685 GtkSelectionData *selection_data,
6690 gboolean accepted = FALSE;
6691 GtkTreeModel *model;
6692 GtkIconView *icon_view;
6693 GtkTreePath *dest_row;
6694 GdkDragAction suggested_action;
6695 gboolean drop_append_mode;
6697 icon_view = GTK_ICON_VIEW (widget);
6698 model = gtk_icon_view_get_model (icon_view);
6700 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6703 if (!icon_view->priv->dest_set)
6706 suggested_action = get_status_pending (context);
6708 if (suggested_action)
6710 /* We are getting this data due to a request in drag_motion,
6711 * rather than due to a request in drag_drop, so we are just
6712 * supposed to call drag_status, not actually paste in the
6715 path = get_logical_destination (icon_view, &drop_append_mode);
6718 suggested_action = 0;
6720 if (suggested_action)
6722 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6725 suggested_action = 0;
6728 gdk_drag_status (context, suggested_action, time);
6731 gtk_tree_path_free (path);
6733 /* If you can't drop, remove user drop indicator until the next motion */
6734 if (suggested_action == 0)
6735 gtk_icon_view_set_drag_dest_item (icon_view,
6737 GTK_ICON_VIEW_DROP_LEFT);
6742 dest_row = get_dest_row (context);
6744 if (dest_row == NULL)
6747 if (gtk_selection_data_get_length (selection_data) >= 0)
6749 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6755 gtk_drag_finish (context,
6757 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6760 gtk_tree_path_free (dest_row);
6763 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6766 /* Drag-and-Drop support */
6768 * gtk_icon_view_enable_model_drag_source:
6769 * @icon_view: a #GtkIconView
6770 * @start_button_mask: Mask of allowed buttons to start drag
6771 * @targets: (array length=n_targets): the table of targets that the drag will
6773 * @n_targets: the number of items in @targets
6774 * @actions: the bitmask of possible actions for a drag from this
6777 * Turns @icon_view into a drag source for automatic DND. Calling this
6778 * method sets #GtkIconView:reorderable to %FALSE.
6783 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6784 GdkModifierType start_button_mask,
6785 const GtkTargetEntry *targets,
6787 GdkDragAction actions)
6789 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6791 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6793 icon_view->priv->start_button_mask = start_button_mask;
6794 icon_view->priv->source_actions = actions;
6796 icon_view->priv->source_set = TRUE;
6798 unset_reorderable (icon_view);
6802 * gtk_icon_view_enable_model_drag_dest:
6803 * @icon_view: a #GtkIconView
6804 * @targets: (array length=n_targets): the table of targets that the drag will
6806 * @n_targets: the number of items in @targets
6807 * @actions: the bitmask of possible actions for a drag to this
6810 * Turns @icon_view into a drop destination for automatic DND. Calling this
6811 * method sets #GtkIconView:reorderable to %FALSE.
6816 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6817 const GtkTargetEntry *targets,
6819 GdkDragAction actions)
6821 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6823 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6825 icon_view->priv->dest_actions = actions;
6827 icon_view->priv->dest_set = TRUE;
6829 unset_reorderable (icon_view);
6833 * gtk_icon_view_unset_model_drag_source:
6834 * @icon_view: a #GtkIconView
6836 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6837 * method sets #GtkIconView:reorderable to %FALSE.
6842 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6844 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6846 if (icon_view->priv->source_set)
6848 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6849 icon_view->priv->source_set = FALSE;
6852 unset_reorderable (icon_view);
6856 * gtk_icon_view_unset_model_drag_dest:
6857 * @icon_view: a #GtkIconView
6859 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6860 * method sets #GtkIconView:reorderable to %FALSE.
6865 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6867 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6869 if (icon_view->priv->dest_set)
6871 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6872 icon_view->priv->dest_set = FALSE;
6875 unset_reorderable (icon_view);
6878 /* These are useful to implement your own custom stuff. */
6880 * gtk_icon_view_set_drag_dest_item:
6881 * @icon_view: a #GtkIconView
6882 * @path: (allow-none): The path of the item to highlight, or %NULL.
6883 * @pos: Specifies where to drop, relative to the item
6885 * Sets the item that is highlighted for feedback.
6890 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6892 GtkIconViewDropPosition pos)
6894 /* Note; this function is exported to allow a custom DND
6895 * implementation, so it can't touch TreeViewDragInfo
6898 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6900 if (icon_view->priv->dest_item)
6902 GtkTreePath *current_path;
6903 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6904 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6905 icon_view->priv->dest_item = NULL;
6907 gtk_icon_view_queue_draw_path (icon_view, current_path);
6908 gtk_tree_path_free (current_path);
6911 /* special case a drop on an empty model */
6912 icon_view->priv->empty_view_drop = FALSE;
6913 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6914 && gtk_tree_path_get_depth (path) == 1
6915 && gtk_tree_path_get_indices (path)[0] == 0)
6919 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6922 if (n_children == 0)
6923 icon_view->priv->empty_view_drop = TRUE;
6926 icon_view->priv->dest_pos = pos;
6930 icon_view->priv->dest_item =
6931 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6932 icon_view->priv->model, path);
6934 gtk_icon_view_queue_draw_path (icon_view, path);
6939 * gtk_icon_view_get_drag_dest_item:
6940 * @icon_view: a #GtkIconView
6941 * @path: (out) (allow-none): Return location for the path of
6942 * the highlighted item, or %NULL.
6943 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6945 * Gets information about the item that is highlighted for feedback.
6950 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6952 GtkIconViewDropPosition *pos)
6954 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6958 if (icon_view->priv->dest_item)
6959 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6965 *pos = icon_view->priv->dest_pos;
6969 * gtk_icon_view_get_dest_item_at_pos:
6970 * @icon_view: a #GtkIconView
6971 * @drag_x: the position to determine the destination item for
6972 * @drag_y: the position to determine the destination item for
6973 * @path: (out) (allow-none): Return location for the path of the item,
6975 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6977 * Determines the destination item for a given position.
6979 * Return value: whether there is an item at the given position.
6984 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6988 GtkIconViewDropPosition *pos)
6990 GtkIconViewItem *item;
6992 /* Note; this function is exported to allow a custom DND
6993 * implementation, so it can't touch TreeViewDragInfo
6996 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6997 g_return_val_if_fail (drag_x >= 0, FALSE);
6998 g_return_val_if_fail (drag_y >= 0, FALSE);
6999 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7005 item = _gtk_icon_view_get_item_at_coords (icon_view,
7006 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
7007 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
7014 *path = gtk_tree_path_new_from_indices (item->index, -1);
7018 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
7019 *pos = GTK_ICON_VIEW_DROP_LEFT;
7020 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
7021 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7022 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
7023 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7024 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
7025 *pos = GTK_ICON_VIEW_DROP_BELOW;
7027 *pos = GTK_ICON_VIEW_DROP_INTO;
7034 * gtk_icon_view_create_drag_icon:
7035 * @icon_view: a #GtkIconView
7036 * @path: a #GtkTreePath in @icon_view
7038 * Creates a #cairo_surface_t representation of the item at @path.
7039 * This image is used for a drag icon.
7041 * Return value: (transfer full): a newly-allocated surface of the drag icon.
7046 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7050 GtkStyleContext *context;
7052 cairo_surface_t *surface;
7056 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7057 g_return_val_if_fail (path != NULL, NULL);
7059 widget = GTK_WIDGET (icon_view);
7060 context = gtk_widget_get_style_context (widget);
7062 if (!gtk_widget_get_realized (widget))
7065 index = gtk_tree_path_get_indices (path)[0];
7067 for (l = icon_view->priv->items; l; l = l->next)
7069 GtkIconViewItem *item = l->data;
7071 if (index == item->index)
7073 GdkRectangle rect = {
7074 item->cell_area.x - icon_view->priv->item_padding,
7075 item->cell_area.y - icon_view->priv->item_padding,
7076 item->cell_area.width + icon_view->priv->item_padding * 2,
7077 item->cell_area.height + icon_view->priv->item_padding * 2
7080 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
7081 CAIRO_CONTENT_COLOR,
7085 cr = cairo_create (surface);
7086 cairo_set_line_width (cr, 1.);
7088 gtk_render_background (context, cr, 0, 0,
7089 rect.width + 2, rect.height + 2);
7093 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
7096 gtk_icon_view_paint_item (icon_view, cr, item,
7097 icon_view->priv->item_padding + 1,
7098 icon_view->priv->item_padding + 1, FALSE);
7102 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7103 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
7116 * gtk_icon_view_get_reorderable:
7117 * @icon_view: a #GtkIconView
7119 * Retrieves whether the user can reorder the list via drag-and-drop.
7120 * See gtk_icon_view_set_reorderable().
7122 * Return value: %TRUE if the list can be reordered.
7127 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7129 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7131 return icon_view->priv->reorderable;
7134 static const GtkTargetEntry item_targets[] = {
7135 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7140 * gtk_icon_view_set_reorderable:
7141 * @icon_view: A #GtkIconView.
7142 * @reorderable: %TRUE, if the list of items can be reordered.
7144 * This function is a convenience function to allow you to reorder models that
7145 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7146 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7147 * the user can reorder the model by dragging and dropping rows. The
7148 * developer can listen to these changes by connecting to the model's
7149 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7150 * the icon view as a drag source and destination. Therefore, drag and
7151 * drop can not be used in a reorderable view for any other purpose.
7153 * This function does not give you any degree of control over the order -- any
7154 * reordering is allowed. If more control is needed, you should probably
7155 * handle drag and drop manually.
7160 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7161 gboolean reorderable)
7163 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7165 reorderable = reorderable != FALSE;
7167 if (icon_view->priv->reorderable == reorderable)
7172 gtk_icon_view_enable_model_drag_source (icon_view,
7175 G_N_ELEMENTS (item_targets),
7177 gtk_icon_view_enable_model_drag_dest (icon_view,
7179 G_N_ELEMENTS (item_targets),
7184 gtk_icon_view_unset_model_drag_source (icon_view);
7185 gtk_icon_view_unset_model_drag_dest (icon_view);
7188 icon_view->priv->reorderable = reorderable;
7190 g_object_notify (G_OBJECT (icon_view), "reorderable");
7194 * gtk_icon_view_set_activate_on_single_click:
7195 * @icon_view: a #GtkIconView
7196 * @setting: %TRUE to emit item-activated on a single click
7198 * Causes the "item-activated" signal to be emitted on a single click
7199 * instead of a double click.
7204 gtk_icon_view_set_activate_on_single_click (GtkIconView *icon_view,
7207 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7209 setting = setting != FALSE;
7211 if (icon_view->priv->activate_on_single_click == setting)
7214 icon_view->priv->activate_on_single_click = setting;
7215 g_object_notify (G_OBJECT (icon_view), "activate-on-single-click");
7219 * gtk_icon_view_get_activate_on_single_click:
7220 * @icon_view: a #GtkIconView
7222 * Gets the setting set by gtk_icon_view_set_activate_on_single_click().
7224 * Return value: %TRUE if item-activated will be emitted on a single click
7229 gtk_icon_view_get_activate_on_single_click (GtkIconView *icon_view)
7231 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7233 return icon_view->priv->activate_on_single_click;
7237 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7238 GtkBuilder *builder,
7240 const gchar *tagname,
7241 GMarkupParser *parser,
7244 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7245 tagname, parser, data))
7248 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7249 tagname, parser, data);
7253 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7254 GtkBuilder *builder,
7256 const gchar *tagname,
7259 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7260 child, tagname, data))
7261 parent_buildable_iface->custom_tag_end (buildable, builder,
7262 child, tagname, data);