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/gtkiconviewaccessible.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 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
71 typedef struct _GtkIconViewChild GtkIconViewChild;
72 struct _GtkIconViewChild
100 PROP_ITEM_ORIENTATION,
113 /* For scrollable interface */
121 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
122 static void gtk_icon_view_dispose (GObject *object);
123 static GObject *gtk_icon_view_constructor (GType type,
124 guint n_construct_properties,
125 GObjectConstructParam *construct_properties);
126 static void gtk_icon_view_set_property (GObject *object,
130 static void gtk_icon_view_get_property (GObject *object,
134 /* GtkWidget vfuncs */
135 static void gtk_icon_view_destroy (GtkWidget *widget);
136 static void gtk_icon_view_realize (GtkWidget *widget);
137 static void gtk_icon_view_unrealize (GtkWidget *widget);
138 static void gtk_icon_view_style_updated (GtkWidget *widget);
139 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
140 GtkStateFlags previous_state);
141 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
144 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
147 static void gtk_icon_view_size_allocate (GtkWidget *widget,
148 GtkAllocation *allocation);
149 static gboolean gtk_icon_view_draw (GtkWidget *widget,
151 static gboolean gtk_icon_view_motion (GtkWidget *widget,
152 GdkEventMotion *event);
153 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
154 GdkEventButton *event);
155 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
156 GdkEventButton *event);
157 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
159 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
163 /* GtkContainer vfuncs */
164 static void gtk_icon_view_remove (GtkContainer *container,
166 static void gtk_icon_view_forall (GtkContainer *container,
167 gboolean include_internals,
168 GtkCallback callback,
169 gpointer callback_data);
171 /* GtkIconView vfuncs */
172 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
173 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
174 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
175 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
176 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
178 /* Internal functions */
179 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
180 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
181 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
182 GtkAdjustment *adjustment);
183 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
184 GtkAdjustment *adjustment);
185 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
186 GtkIconView *icon_view);
187 static void gtk_icon_view_layout (GtkIconView *icon_view);
188 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
190 GtkIconViewItem *item,
193 gboolean draw_focus);
194 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
196 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
198 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
199 GtkIconViewItem *item);
200 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
201 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
205 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
206 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
207 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
208 GtkIconViewItem *item,
213 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
214 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
215 static void gtk_icon_view_update_rubberband (gpointer data);
216 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
217 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
218 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
221 GtkMovementStep step,
223 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
224 GtkMovementStep step,
226 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
228 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
230 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
232 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
234 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
235 GtkIconViewItem *item);
236 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
237 GtkIconViewItem *anchor,
238 GtkIconViewItem *cursor);
240 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
241 GtkCellArea *cell_area);
243 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
245 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
246 GtkIconViewItem *item);
248 static void gtk_icon_view_add_editable (GtkCellArea *area,
249 GtkCellRenderer *renderer,
250 GtkCellEditable *editable,
251 GdkRectangle *cell_area,
253 GtkIconView *icon_view);
254 static void gtk_icon_view_remove_editable (GtkCellArea *area,
255 GtkCellRenderer *renderer,
256 GtkCellEditable *editable,
257 GtkIconView *icon_view);
258 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
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->style_updated = gtk_icon_view_style_updated;
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->size_allocate = gtk_icon_view_size_allocate;
355 widget_class->draw = gtk_icon_view_draw;
356 widget_class->motion_notify_event = gtk_icon_view_motion;
357 widget_class->button_press_event = gtk_icon_view_button_press;
358 widget_class->button_release_event = gtk_icon_view_button_release;
359 widget_class->key_press_event = gtk_icon_view_key_press;
360 widget_class->key_release_event = gtk_icon_view_key_release;
361 widget_class->drag_begin = gtk_icon_view_drag_begin;
362 widget_class->drag_end = gtk_icon_view_drag_end;
363 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
364 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
365 widget_class->drag_leave = gtk_icon_view_drag_leave;
366 widget_class->drag_motion = gtk_icon_view_drag_motion;
367 widget_class->drag_drop = gtk_icon_view_drag_drop;
368 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
369 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
371 container_class->remove = gtk_icon_view_remove;
372 container_class->forall = gtk_icon_view_forall;
374 klass->select_all = gtk_icon_view_real_select_all;
375 klass->unselect_all = gtk_icon_view_real_unselect_all;
376 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
377 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
378 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
379 klass->move_cursor = gtk_icon_view_real_move_cursor;
383 * GtkIconView:selection-mode:
385 * The ::selection-mode property specifies the selection mode of
386 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
387 * is enabled, for the other modes, only keyboard selection is possible.
391 g_object_class_install_property (gobject_class,
393 g_param_spec_enum ("selection-mode",
394 P_("Selection mode"),
395 P_("The selection mode"),
396 GTK_TYPE_SELECTION_MODE,
397 GTK_SELECTION_SINGLE,
398 GTK_PARAM_READWRITE));
401 * GtkIconView:pixbuf-column:
403 * The ::pixbuf-column property contains the number of the model column
404 * containing the pixbufs which are displayed. The pixbuf column must be
405 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
406 * display of pixbufs.
410 g_object_class_install_property (gobject_class,
412 g_param_spec_int ("pixbuf-column",
414 P_("Model column used to retrieve the icon pixbuf from"),
416 GTK_PARAM_READWRITE));
419 * GtkIconView:text-column:
421 * The ::text-column property contains the number of the model column
422 * containing the texts which are displayed. The text column must be
423 * of type #G_TYPE_STRING. If this property and the :markup-column
424 * property are both set to -1, no texts are displayed.
428 g_object_class_install_property (gobject_class,
430 g_param_spec_int ("text-column",
432 P_("Model column used to retrieve the text from"),
434 GTK_PARAM_READWRITE));
438 * GtkIconView:markup-column:
440 * The ::markup-column property contains the number of the model column
441 * containing markup information to be displayed. The markup column must be
442 * of type #G_TYPE_STRING. If this property and the :text-column property
443 * are both set to column numbers, it overrides the text column.
444 * If both are set to -1, no texts are displayed.
448 g_object_class_install_property (gobject_class,
450 g_param_spec_int ("markup-column",
452 P_("Model column used to retrieve the text if using Pango markup"),
454 GTK_PARAM_READWRITE));
456 g_object_class_install_property (gobject_class,
458 g_param_spec_object ("model",
459 P_("Icon View Model"),
460 P_("The model for the icon view"),
462 GTK_PARAM_READWRITE));
465 * GtkIconView:columns:
467 * The columns property contains the number of the columns in which the
468 * items should be displayed. If it is -1, the number of columns will
469 * be chosen automatically to fill the available area.
473 g_object_class_install_property (gobject_class,
475 g_param_spec_int ("columns",
476 P_("Number of columns"),
477 P_("Number of columns to display"),
479 GTK_PARAM_READWRITE));
483 * GtkIconView:item-width:
485 * The item-width property specifies the width to use for each item.
486 * If it is set to -1, the icon view will automatically determine a
487 * suitable item size.
491 g_object_class_install_property (gobject_class,
493 g_param_spec_int ("item-width",
494 P_("Width for each item"),
495 P_("The width used for each item"),
497 GTK_PARAM_READWRITE));
500 * GtkIconView:spacing:
502 * The spacing property specifies the space which is inserted between
503 * the cells (i.e. the icon and the text) of an item.
507 g_object_class_install_property (gobject_class,
509 g_param_spec_int ("spacing",
511 P_("Space which is inserted between cells of an item"),
513 GTK_PARAM_READWRITE));
516 * GtkIconView:row-spacing:
518 * The row-spacing property specifies the space which is inserted between
519 * the rows of the icon view.
523 g_object_class_install_property (gobject_class,
525 g_param_spec_int ("row-spacing",
527 P_("Space which is inserted between grid rows"),
529 GTK_PARAM_READWRITE));
532 * GtkIconView:column-spacing:
534 * The column-spacing property specifies the space which is inserted between
535 * the columns of the icon view.
539 g_object_class_install_property (gobject_class,
541 g_param_spec_int ("column-spacing",
542 P_("Column Spacing"),
543 P_("Space which is inserted between grid columns"),
545 GTK_PARAM_READWRITE));
548 * GtkIconView:margin:
550 * The margin property specifies the space which is inserted
551 * at the edges of the icon view.
555 g_object_class_install_property (gobject_class,
557 g_param_spec_int ("margin",
559 P_("Space which is inserted at the edges of the icon view"),
561 GTK_PARAM_READWRITE));
564 * GtkIconView:item-orientation:
566 * The item-orientation property specifies how the cells (i.e. the icon and
567 * the text) of the item are positioned relative to each other.
571 g_object_class_install_property (gobject_class,
572 PROP_ITEM_ORIENTATION,
573 g_param_spec_enum ("item-orientation",
574 P_("Item Orientation"),
575 P_("How the text and icon of each item are positioned relative to each other"),
576 GTK_TYPE_ORIENTATION,
577 GTK_ORIENTATION_VERTICAL,
578 GTK_PARAM_READWRITE));
581 * GtkIconView:reorderable:
583 * The reorderable property specifies if the items can be reordered
588 g_object_class_install_property (gobject_class,
590 g_param_spec_boolean ("reorderable",
592 P_("View is reorderable"),
596 g_object_class_install_property (gobject_class,
598 g_param_spec_int ("tooltip-column",
599 P_("Tooltip Column"),
600 P_("The column in the model containing the tooltip texts for the items"),
604 GTK_PARAM_READWRITE));
607 * GtkIconView:item-padding:
609 * The item-padding property specifies the padding around each
610 * of the icon view's item.
614 g_object_class_install_property (gobject_class,
616 g_param_spec_int ("item-padding",
618 P_("Padding around icon view items"),
620 GTK_PARAM_READWRITE));
623 * GtkIconView:cell-area:
625 * The #GtkCellArea used to layout cell renderers for this view.
627 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
628 * a #GtkCellAreaBox will be used.
632 g_object_class_install_property (gobject_class,
634 g_param_spec_object ("cell-area",
636 P_("The GtkCellArea used to layout cells"),
638 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
640 /* Scrollable interface properties */
641 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
642 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
643 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
644 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
646 /* Style properties */
647 gtk_widget_class_install_style_property (widget_class,
648 g_param_spec_boxed ("selection-box-color",
649 P_("Selection Box Color"),
650 P_("Color of the selection box"),
652 GTK_PARAM_READABLE));
654 gtk_widget_class_install_style_property (widget_class,
655 g_param_spec_uchar ("selection-box-alpha",
656 P_("Selection Box Alpha"),
657 P_("Opacity of the selection box"),
660 GTK_PARAM_READABLE));
664 * GtkIconView::item-activated:
665 * @iconview: the object on which the signal is emitted
666 * @path: the #GtkTreePath for the activated item
668 * The ::item-activated signal is emitted when the method
669 * gtk_icon_view_item_activated() is called or the user double
670 * clicks an item. It is also emitted when a non-editable item
671 * is selected and one of the keys: Space, Return or Enter is
674 icon_view_signals[ITEM_ACTIVATED] =
675 g_signal_new (I_("item-activated"),
676 G_TYPE_FROM_CLASS (gobject_class),
678 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
680 g_cclosure_marshal_VOID__BOXED,
685 * GtkIconView::selection-changed:
686 * @iconview: the object on which the signal is emitted
688 * The ::selection-changed signal is emitted when the selection
689 * (i.e. the set of selected items) changes.
691 icon_view_signals[SELECTION_CHANGED] =
692 g_signal_new (I_("selection-changed"),
693 G_TYPE_FROM_CLASS (gobject_class),
695 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
697 g_cclosure_marshal_VOID__VOID,
701 * GtkIconView::select-all:
702 * @iconview: the object on which the signal is emitted
704 * A <link linkend="keybinding-signals">keybinding signal</link>
705 * which gets emitted when the user selects all items.
707 * Applications should not connect to it, but may emit it with
708 * g_signal_emit_by_name() if they need to control selection
711 * The default binding for this signal is Ctrl-a.
713 icon_view_signals[SELECT_ALL] =
714 g_signal_new (I_("select-all"),
715 G_TYPE_FROM_CLASS (gobject_class),
716 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
717 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
719 g_cclosure_marshal_VOID__VOID,
723 * GtkIconView::unselect-all:
724 * @iconview: the object on which the signal is emitted
726 * A <link linkend="keybinding-signals">keybinding signal</link>
727 * which gets emitted when the user unselects all items.
729 * Applications should not connect to it, but may emit it with
730 * g_signal_emit_by_name() if they need to control selection
733 * The default binding for this signal is Ctrl-Shift-a.
735 icon_view_signals[UNSELECT_ALL] =
736 g_signal_new (I_("unselect-all"),
737 G_TYPE_FROM_CLASS (gobject_class),
738 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
739 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
741 g_cclosure_marshal_VOID__VOID,
745 * GtkIconView::select-cursor-item:
746 * @iconview: the object on which the signal is emitted
748 * A <link linkend="keybinding-signals">keybinding signal</link>
749 * which gets emitted when the user selects the item that is currently
752 * Applications should not connect to it, but may emit it with
753 * g_signal_emit_by_name() if they need to control selection
756 * There is no default binding for this signal.
758 icon_view_signals[SELECT_CURSOR_ITEM] =
759 g_signal_new (I_("select-cursor-item"),
760 G_TYPE_FROM_CLASS (gobject_class),
761 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
762 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
764 g_cclosure_marshal_VOID__VOID,
768 * GtkIconView::toggle-cursor-item:
769 * @iconview: the object on which the signal is emitted
771 * A <link linkend="keybinding-signals">keybinding signal</link>
772 * which gets emitted when the user toggles whether the currently
773 * focused item is selected or not. The exact effect of this
774 * depend on the selection mode.
776 * Applications should not connect to it, but may emit it with
777 * g_signal_emit_by_name() if they need to control selection
780 * There is no default binding for this signal is Ctrl-Space.
782 icon_view_signals[TOGGLE_CURSOR_ITEM] =
783 g_signal_new (I_("toggle-cursor-item"),
784 G_TYPE_FROM_CLASS (gobject_class),
785 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
786 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
788 g_cclosure_marshal_VOID__VOID,
792 * GtkIconView::activate-cursor-item:
793 * @iconview: the object on which the signal is emitted
795 * A <link linkend="keybinding-signals">keybinding signal</link>
796 * which gets emitted when the user activates the currently
799 * Applications should not connect to it, but may emit it with
800 * g_signal_emit_by_name() if they need to control activation
803 * The default bindings for this signal are Space, Return and Enter.
805 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
806 g_signal_new (I_("activate-cursor-item"),
807 G_TYPE_FROM_CLASS (gobject_class),
808 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
809 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
811 _gtk_marshal_BOOLEAN__VOID,
815 * GtkIconView::move-cursor:
816 * @iconview: the object which received the signal
817 * @step: the granularity of the move, as a #GtkMovementStep
818 * @count: the number of @step units to move
820 * The ::move-cursor signal is a
821 * <link linkend="keybinding-signals">keybinding signal</link>
822 * which gets emitted when the user initiates a cursor movement.
824 * Applications should not connect to it, but may emit it with
825 * g_signal_emit_by_name() if they need to control the cursor
828 * The default bindings for this signal include
830 * <listitem>Arrow keys which move by individual steps</listitem>
831 * <listitem>Home/End keys which move to the first/last item</listitem>
832 * <listitem>PageUp/PageDown which move by "pages"</listitem>
835 * All of these will extend the selection when combined with
836 * the Shift modifier.
838 icon_view_signals[MOVE_CURSOR] =
839 g_signal_new (I_("move-cursor"),
840 G_TYPE_FROM_CLASS (gobject_class),
841 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
842 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
844 _gtk_marshal_BOOLEAN__ENUM_INT,
846 GTK_TYPE_MOVEMENT_STEP,
850 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
852 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
854 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
855 "toggle-cursor-item", 0);
856 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
857 "toggle-cursor-item", 0);
859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
860 "activate-cursor-item", 0);
861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
862 "activate-cursor-item", 0);
863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
864 "activate-cursor-item", 0);
865 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
866 "activate-cursor-item", 0);
867 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
868 "activate-cursor-item", 0);
870 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
871 GTK_MOVEMENT_DISPLAY_LINES, -1);
872 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
873 GTK_MOVEMENT_DISPLAY_LINES, -1);
875 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
876 GTK_MOVEMENT_DISPLAY_LINES, 1);
877 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
878 GTK_MOVEMENT_DISPLAY_LINES, 1);
880 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
881 GTK_MOVEMENT_DISPLAY_LINES, -1);
883 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
884 GTK_MOVEMENT_DISPLAY_LINES, 1);
886 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
887 GTK_MOVEMENT_BUFFER_ENDS, -1);
888 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
889 GTK_MOVEMENT_BUFFER_ENDS, -1);
891 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
892 GTK_MOVEMENT_BUFFER_ENDS, 1);
893 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
894 GTK_MOVEMENT_BUFFER_ENDS, 1);
896 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
897 GTK_MOVEMENT_PAGES, -1);
898 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
899 GTK_MOVEMENT_PAGES, -1);
901 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
902 GTK_MOVEMENT_PAGES, 1);
903 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
904 GTK_MOVEMENT_PAGES, 1);
906 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
907 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
908 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
909 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
911 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
912 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
913 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
914 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
916 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
920 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
922 parent_buildable_iface = g_type_interface_peek_parent (iface);
923 iface->add_child = _gtk_cell_layout_buildable_add_child;
924 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
925 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
929 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
931 iface->get_area = gtk_icon_view_cell_layout_get_area;
935 gtk_icon_view_init (GtkIconView *icon_view)
937 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
941 icon_view->priv->width = 0;
942 icon_view->priv->height = 0;
943 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
944 icon_view->priv->pressed_button = -1;
945 icon_view->priv->press_start_x = -1;
946 icon_view->priv->press_start_y = -1;
947 icon_view->priv->text_column = -1;
948 icon_view->priv->markup_column = -1;
949 icon_view->priv->pixbuf_column = -1;
950 icon_view->priv->text_cell = NULL;
951 icon_view->priv->pixbuf_cell = NULL;
952 icon_view->priv->tooltip_column = -1;
954 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
956 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
958 icon_view->priv->columns = -1;
959 icon_view->priv->item_width = -1;
960 icon_view->priv->spacing = 0;
961 icon_view->priv->row_spacing = 6;
962 icon_view->priv->column_spacing = 6;
963 icon_view->priv->margin = 6;
964 icon_view->priv->item_padding = 6;
966 icon_view->priv->draw_focus = TRUE;
968 icon_view->priv->row_contexts =
969 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
972 /* GObject methods */
974 gtk_icon_view_constructor (GType type,
975 guint n_construct_properties,
976 GObjectConstructParam *construct_properties)
978 GtkIconView *icon_view;
981 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
982 (type, n_construct_properties, construct_properties);
984 icon_view = (GtkIconView *) object;
986 gtk_icon_view_ensure_cell_area (icon_view, NULL);
992 gtk_icon_view_dispose (GObject *object)
994 GtkIconView *icon_view;
995 GtkIconViewPrivate *priv;
997 icon_view = GTK_ICON_VIEW (object);
998 priv = icon_view->priv;
1000 if (priv->cell_area_context)
1002 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1003 priv->context_changed_id = 0;
1005 g_object_unref (priv->cell_area_context);
1006 priv->cell_area_context = NULL;
1009 if (priv->row_contexts)
1011 g_ptr_array_free (priv->row_contexts, TRUE);
1012 priv->row_contexts = NULL;
1015 if (priv->cell_area)
1017 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1019 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1020 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1021 priv->add_editable_id = 0;
1022 priv->remove_editable_id = 0;
1024 g_object_unref (priv->cell_area);
1025 priv->cell_area = NULL;
1028 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1032 gtk_icon_view_set_property (GObject *object,
1034 const GValue *value,
1037 GtkIconView *icon_view;
1040 icon_view = GTK_ICON_VIEW (object);
1044 case PROP_SELECTION_MODE:
1045 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1047 case PROP_PIXBUF_COLUMN:
1048 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1050 case PROP_TEXT_COLUMN:
1051 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1053 case PROP_MARKUP_COLUMN:
1054 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1057 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1059 case PROP_ITEM_ORIENTATION:
1060 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1063 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1065 case PROP_ITEM_WIDTH:
1066 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1069 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1071 case PROP_ROW_SPACING:
1072 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1074 case PROP_COLUMN_SPACING:
1075 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1078 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1080 case PROP_REORDERABLE:
1081 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1084 case PROP_TOOLTIP_COLUMN:
1085 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1088 case PROP_ITEM_PADDING:
1089 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1092 case PROP_CELL_AREA:
1093 /* Construct-only, can only be assigned once */
1094 area = g_value_get_object (value);
1097 if (icon_view->priv->cell_area != NULL)
1099 g_warning ("cell-area has already been set, ignoring construct property");
1100 g_object_ref_sink (area);
1101 g_object_unref (area);
1104 gtk_icon_view_ensure_cell_area (icon_view, area);
1108 case PROP_HADJUSTMENT:
1109 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1111 case PROP_VADJUSTMENT:
1112 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1114 case PROP_HSCROLL_POLICY:
1115 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1116 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1118 case PROP_VSCROLL_POLICY:
1119 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1120 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1124 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1130 gtk_icon_view_get_property (GObject *object,
1135 GtkIconView *icon_view;
1137 icon_view = GTK_ICON_VIEW (object);
1141 case PROP_SELECTION_MODE:
1142 g_value_set_enum (value, icon_view->priv->selection_mode);
1144 case PROP_PIXBUF_COLUMN:
1145 g_value_set_int (value, icon_view->priv->pixbuf_column);
1147 case PROP_TEXT_COLUMN:
1148 g_value_set_int (value, icon_view->priv->text_column);
1150 case PROP_MARKUP_COLUMN:
1151 g_value_set_int (value, icon_view->priv->markup_column);
1154 g_value_set_object (value, icon_view->priv->model);
1156 case PROP_ITEM_ORIENTATION:
1157 g_value_set_enum (value, icon_view->priv->item_orientation);
1160 g_value_set_int (value, icon_view->priv->columns);
1162 case PROP_ITEM_WIDTH:
1163 g_value_set_int (value, icon_view->priv->item_width);
1166 g_value_set_int (value, icon_view->priv->spacing);
1168 case PROP_ROW_SPACING:
1169 g_value_set_int (value, icon_view->priv->row_spacing);
1171 case PROP_COLUMN_SPACING:
1172 g_value_set_int (value, icon_view->priv->column_spacing);
1175 g_value_set_int (value, icon_view->priv->margin);
1177 case PROP_REORDERABLE:
1178 g_value_set_boolean (value, icon_view->priv->reorderable);
1180 case PROP_TOOLTIP_COLUMN:
1181 g_value_set_int (value, icon_view->priv->tooltip_column);
1184 case PROP_ITEM_PADDING:
1185 g_value_set_int (value, icon_view->priv->item_padding);
1188 case PROP_CELL_AREA:
1189 g_value_set_object (value, icon_view->priv->cell_area);
1192 case PROP_HADJUSTMENT:
1193 g_value_set_object (value, icon_view->priv->hadjustment);
1195 case PROP_VADJUSTMENT:
1196 g_value_set_object (value, icon_view->priv->vadjustment);
1198 case PROP_HSCROLL_POLICY:
1199 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1201 case PROP_VSCROLL_POLICY:
1202 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1211 /* GtkWidget methods */
1213 gtk_icon_view_destroy (GtkWidget *widget)
1215 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1217 gtk_icon_view_set_model (icon_view, NULL);
1219 if (icon_view->priv->layout_idle_id != 0)
1221 g_source_remove (icon_view->priv->layout_idle_id);
1222 icon_view->priv->layout_idle_id = 0;
1225 if (icon_view->priv->scroll_to_path != NULL)
1227 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1228 icon_view->priv->scroll_to_path = NULL;
1231 remove_scroll_timeout (icon_view);
1233 if (icon_view->priv->hadjustment != NULL)
1235 g_object_unref (icon_view->priv->hadjustment);
1236 icon_view->priv->hadjustment = NULL;
1239 if (icon_view->priv->vadjustment != NULL)
1241 g_object_unref (icon_view->priv->vadjustment);
1242 icon_view->priv->vadjustment = NULL;
1245 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1249 gtk_icon_view_realize (GtkWidget *widget)
1251 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1252 GtkAllocation allocation;
1254 GdkWindowAttr attributes;
1255 gint attributes_mask;
1256 GtkStyleContext *context;
1258 gtk_widget_set_realized (widget, TRUE);
1260 gtk_widget_get_allocation (widget, &allocation);
1262 /* Make the main, clipping window */
1263 attributes.window_type = GDK_WINDOW_CHILD;
1264 attributes.x = allocation.x;
1265 attributes.y = allocation.y;
1266 attributes.width = allocation.width;
1267 attributes.height = allocation.height;
1268 attributes.wclass = GDK_INPUT_OUTPUT;
1269 attributes.visual = gtk_widget_get_visual (widget);
1270 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1272 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1274 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1275 &attributes, attributes_mask);
1276 gtk_widget_set_window (widget, window);
1277 gdk_window_set_user_data (window, widget);
1279 gtk_widget_get_allocation (widget, &allocation);
1281 /* Make the window for the icon view */
1284 attributes.width = MAX (icon_view->priv->width, allocation.width);
1285 attributes.height = MAX (icon_view->priv->height, allocation.height);
1286 attributes.event_mask = (GDK_EXPOSURE_MASK |
1288 GDK_SMOOTH_SCROLL_MASK |
1289 GDK_POINTER_MOTION_MASK |
1290 GDK_BUTTON_PRESS_MASK |
1291 GDK_BUTTON_RELEASE_MASK |
1292 GDK_KEY_PRESS_MASK |
1293 GDK_KEY_RELEASE_MASK) |
1294 gtk_widget_get_events (widget);
1296 icon_view->priv->bin_window = gdk_window_new (window,
1297 &attributes, attributes_mask);
1298 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1300 context = gtk_widget_get_style_context (widget);
1302 gtk_style_context_save (context);
1303 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1304 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1305 gtk_style_context_set_background (context, window);
1306 gtk_style_context_restore (context);
1308 gdk_window_show (icon_view->priv->bin_window);
1312 gtk_icon_view_unrealize (GtkWidget *widget)
1314 GtkIconView *icon_view;
1316 icon_view = GTK_ICON_VIEW (widget);
1318 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1319 gdk_window_destroy (icon_view->priv->bin_window);
1320 icon_view->priv->bin_window = NULL;
1322 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1326 _gtk_icon_view_update_background (GtkIconView *icon_view)
1328 GtkWidget *widget = GTK_WIDGET (icon_view);
1330 if (gtk_widget_get_realized (widget))
1332 GtkStyleContext *context;
1334 context = gtk_widget_get_style_context (widget);
1336 gtk_style_context_save (context);
1337 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1339 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1340 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1342 gtk_style_context_restore (context);
1347 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1348 GtkStateFlags previous_state)
1350 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1351 gtk_widget_queue_draw (widget);
1355 gtk_icon_view_style_updated (GtkWidget *widget)
1357 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1359 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1360 gtk_widget_queue_resize (widget);
1364 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1368 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1372 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1376 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1380 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1384 for (list = icon_view->priv->children; list; list = list->next)
1386 GtkIconViewChild *child = list->data;
1388 /* totally ignore our child's requisition */
1389 gtk_widget_size_allocate (child->widget, &child->area);
1394 gtk_icon_view_size_allocate (GtkWidget *widget,
1395 GtkAllocation *allocation)
1397 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1399 gtk_widget_set_allocation (widget, allocation);
1401 if (gtk_widget_get_realized (widget))
1403 gdk_window_move_resize (gtk_widget_get_window (widget),
1404 allocation->x, allocation->y,
1405 allocation->width, allocation->height);
1406 gdk_window_resize (icon_view->priv->bin_window,
1407 MAX (icon_view->priv->width, allocation->width),
1408 MAX (icon_view->priv->height, allocation->height));
1411 gtk_icon_view_allocate_children (icon_view);
1413 /* Delay signal emission */
1414 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1415 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1417 gtk_icon_view_set_hadjustment_values (icon_view);
1418 gtk_icon_view_set_vadjustment_values (icon_view);
1420 if (gtk_widget_get_realized (widget) &&
1421 icon_view->priv->scroll_to_path)
1424 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1425 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1426 icon_view->priv->scroll_to_path = NULL;
1428 gtk_icon_view_scroll_to_path (icon_view, path,
1429 icon_view->priv->scroll_to_use_align,
1430 icon_view->priv->scroll_to_row_align,
1431 icon_view->priv->scroll_to_col_align);
1432 gtk_tree_path_free (path);
1435 /* Emit any pending signals now */
1436 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1437 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1441 gtk_icon_view_draw (GtkWidget *widget,
1444 GtkIconView *icon_view;
1448 GtkIconViewDropPosition dest_pos;
1449 GtkIconViewItem *dest_item = NULL;
1451 icon_view = GTK_ICON_VIEW (widget);
1453 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1458 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1460 cairo_set_line_width (cr, 1.);
1462 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1466 dest_index = gtk_tree_path_get_indices (path)[0];
1467 gtk_tree_path_free (path);
1472 for (icons = icon_view->priv->items; icons; icons = icons->next)
1474 GtkIconViewItem *item = icons->data;
1475 GdkRectangle paint_area;
1477 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1478 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1479 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1480 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1484 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1487 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1489 gtk_icon_view_paint_item (icon_view, cr, item,
1490 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1491 icon_view->priv->draw_focus);
1493 if (dest_index == item->index)
1501 dest_pos != GTK_ICON_VIEW_NO_DROP)
1503 GtkStyleContext *context;
1504 GdkRectangle rect = { 0 };
1506 context = gtk_widget_get_style_context (widget);
1510 case GTK_ICON_VIEW_DROP_INTO:
1511 rect = dest_item->cell_area;
1513 case GTK_ICON_VIEW_DROP_ABOVE:
1514 rect.x = dest_item->cell_area.x;
1515 rect.y = dest_item->cell_area.y - 1;
1516 rect.width = dest_item->cell_area.width;
1519 case GTK_ICON_VIEW_DROP_LEFT:
1520 rect.x = dest_item->cell_area.x - 1;
1521 rect.y = dest_item->cell_area.y;
1523 rect.height = dest_item->cell_area.height;
1525 case GTK_ICON_VIEW_DROP_BELOW:
1526 rect.x = dest_item->cell_area.x;
1527 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1528 rect.width = dest_item->cell_area.width;
1531 case GTK_ICON_VIEW_DROP_RIGHT:
1532 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1533 rect.y = dest_item->cell_area.y;
1535 rect.height = dest_item->cell_area.height;
1536 case GTK_ICON_VIEW_NO_DROP: ;
1540 gtk_render_focus (context, cr,
1542 rect.width, rect.height);
1545 if (icon_view->priv->doing_rubberband)
1546 gtk_icon_view_paint_rubberband (icon_view, cr);
1550 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1554 rubberband_scroll_timeout (gpointer data)
1556 GtkIconView *icon_view = data;
1558 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1559 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1560 icon_view->priv->scroll_value_diff);
1562 gtk_icon_view_update_rubberband (icon_view);
1568 gtk_icon_view_motion (GtkWidget *widget,
1569 GdkEventMotion *event)
1571 GtkAllocation allocation;
1572 GtkIconView *icon_view;
1575 icon_view = GTK_ICON_VIEW (widget);
1577 gtk_icon_view_maybe_begin_drag (icon_view, event);
1579 if (icon_view->priv->doing_rubberband)
1581 gtk_icon_view_update_rubberband (widget);
1583 abs_y = event->y - icon_view->priv->height *
1584 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1585 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1586 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1588 gtk_widget_get_allocation (widget, &allocation);
1590 if (abs_y < 0 || abs_y > allocation.height)
1593 icon_view->priv->scroll_value_diff = abs_y;
1595 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1597 icon_view->priv->event_last_x = event->x;
1598 icon_view->priv->event_last_y = event->y;
1600 if (icon_view->priv->scroll_timeout_id == 0)
1601 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1605 remove_scroll_timeout (icon_view);
1609 GtkIconViewItem *item, *last_prelight_item;
1610 GtkCellRenderer *cell = NULL;
1612 last_prelight_item = icon_view->priv->last_prelight;
1613 item = _gtk_icon_view_get_item_at_coords (icon_view,
1620 item->prelight = TRUE;
1621 gtk_icon_view_queue_draw_item (icon_view, item);
1624 if (last_prelight_item != NULL &&
1625 last_prelight_item != item)
1627 last_prelight_item->prelight = FALSE;
1628 gtk_icon_view_queue_draw_item (icon_view,
1629 icon_view->priv->last_prelight);
1632 icon_view->priv->last_prelight = item;
1639 gtk_icon_view_remove (GtkContainer *container,
1642 GtkIconView *icon_view;
1643 GtkIconViewChild *child = NULL;
1646 icon_view = GTK_ICON_VIEW (container);
1648 tmp_list = icon_view->priv->children;
1651 child = tmp_list->data;
1652 if (child->widget == widget)
1654 gtk_widget_unparent (widget);
1656 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1657 g_list_free_1 (tmp_list);
1662 tmp_list = tmp_list->next;
1667 gtk_icon_view_forall (GtkContainer *container,
1668 gboolean include_internals,
1669 GtkCallback callback,
1670 gpointer callback_data)
1672 GtkIconView *icon_view;
1673 GtkIconViewChild *child = NULL;
1676 icon_view = GTK_ICON_VIEW (container);
1678 tmp_list = icon_view->priv->children;
1681 child = tmp_list->data;
1682 tmp_list = tmp_list->next;
1684 (* callback) (child->widget, callback_data);
1689 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1690 GtkIconViewItem *item)
1693 AtkObject *item_obj;
1695 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1698 item_obj = atk_object_ref_accessible_child (obj, item->index);
1699 if (item_obj != NULL)
1701 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1702 g_object_unref (item_obj);
1708 gtk_icon_view_add_editable (GtkCellArea *area,
1709 GtkCellRenderer *renderer,
1710 GtkCellEditable *editable,
1711 GdkRectangle *cell_area,
1713 GtkIconView *icon_view)
1715 GtkIconViewChild *child;
1716 GtkWidget *widget = GTK_WIDGET (editable);
1718 child = g_new (GtkIconViewChild, 1);
1720 child->widget = widget;
1721 child->area.x = cell_area->x;
1722 child->area.y = cell_area->y;
1723 child->area.width = cell_area->width;
1724 child->area.height = cell_area->height;
1726 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1728 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1729 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1731 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1735 gtk_icon_view_remove_editable (GtkCellArea *area,
1736 GtkCellRenderer *renderer,
1737 GtkCellEditable *editable,
1738 GtkIconView *icon_view)
1742 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1743 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1745 gtk_container_remove (GTK_CONTAINER (icon_view),
1746 GTK_WIDGET (editable));
1748 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1749 gtk_icon_view_queue_draw_path (icon_view, path);
1750 gtk_tree_path_free (path);
1754 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1756 GtkIconView *icon_view)
1758 if (!strcmp (pspec->name, "minimum-width") ||
1759 !strcmp (pspec->name, "natural-width") ||
1760 !strcmp (pspec->name, "minimum-height") ||
1761 !strcmp (pspec->name, "natural-height"))
1762 gtk_icon_view_invalidate_sizes (icon_view);
1766 * gtk_icon_view_set_cursor:
1767 * @icon_view: A #GtkIconView
1768 * @path: A #GtkTreePath
1769 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1770 * @start_editing: %TRUE if the specified cell should start being edited.
1772 * Sets the current keyboard focus to be at @path, and selects it. This is
1773 * useful when you want to focus the user's attention on a particular item.
1774 * If @cell is not %NULL, then focus is given to the cell specified by
1775 * it. Additionally, if @start_editing is %TRUE, then editing should be
1776 * started in the specified cell.
1778 * This function is often followed by <literal>gtk_widget_grab_focus
1779 * (icon_view)</literal> in order to give keyboard focus to the widget.
1780 * Please note that editing can only happen when the widget is realized.
1785 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1787 GtkCellRenderer *cell,
1788 gboolean start_editing)
1790 GtkIconViewItem *item = NULL;
1792 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1793 g_return_if_fail (path != NULL);
1794 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1796 if (icon_view->priv->cell_area)
1797 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1799 if (gtk_tree_path_get_depth (path) == 1)
1800 item = g_list_nth_data (icon_view->priv->items,
1801 gtk_tree_path_get_indices(path)[0]);
1806 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
1807 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1809 if (start_editing &&
1810 icon_view->priv->cell_area)
1812 GtkCellAreaContext *context;
1814 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1815 _gtk_icon_view_set_cell_data (icon_view, item);
1816 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1817 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1818 0 /* XXX flags */, TRUE);
1823 * gtk_icon_view_get_cursor:
1824 * @icon_view: A #GtkIconView
1825 * @path: (out) (allow-none): Return location for the current cursor path,
1827 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1829 * Fills in @path and @cell with the current cursor path and cell.
1830 * If the cursor isn't currently set, then *@path will be %NULL.
1831 * If no cell currently has focus, then *@cell will be %NULL.
1833 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1835 * Return value: %TRUE if the cursor is set.
1840 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1842 GtkCellRenderer **cell)
1844 GtkIconViewItem *item;
1846 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1848 item = icon_view->priv->cursor_item;
1853 *path = gtk_tree_path_new_from_indices (item->index, -1);
1858 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1859 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1861 return (item != NULL);
1865 gtk_icon_view_button_press (GtkWidget *widget,
1866 GdkEventButton *event)
1868 GtkIconView *icon_view;
1869 GtkIconViewItem *item;
1870 gboolean dirty = FALSE;
1871 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1873 icon_view = GTK_ICON_VIEW (widget);
1875 if (event->window != icon_view->priv->bin_window)
1878 if (!gtk_widget_has_focus (widget))
1879 gtk_widget_grab_focus (widget);
1881 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
1883 GdkModifierType extend_mod_mask;
1884 GdkModifierType modify_mod_mask;
1887 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
1890 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
1892 item = _gtk_icon_view_get_item_at_coords (icon_view,
1898 * We consider only the the cells' area as the item area if the
1899 * item is not selected, but if it *is* selected, the complete
1900 * selection rectangle is considered to be part of the item.
1902 if (item != NULL && (cell != NULL || item->selected))
1906 if (gtk_cell_renderer_is_activatable (cell))
1910 gtk_icon_view_scroll_to_item (icon_view, item);
1912 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1914 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1916 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1917 (event->state & extend_mod_mask))
1919 gtk_icon_view_unselect_all_internal (icon_view);
1921 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1922 if (!icon_view->priv->anchor_item)
1923 icon_view->priv->anchor_item = item;
1925 gtk_icon_view_select_all_between (icon_view,
1926 icon_view->priv->anchor_item,
1932 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1933 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1934 (event->state & modify_mod_mask))
1936 item->selected = !item->selected;
1937 gtk_icon_view_queue_draw_item (icon_view, item);
1942 gtk_icon_view_unselect_all_internal (icon_view);
1944 item->selected = TRUE;
1945 gtk_icon_view_queue_draw_item (icon_view, item);
1948 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1949 icon_view->priv->anchor_item = item;
1952 /* Save press to possibly begin a drag */
1953 if (icon_view->priv->pressed_button < 0)
1955 icon_view->priv->pressed_button = event->button;
1956 icon_view->priv->press_start_x = event->x;
1957 icon_view->priv->press_start_y = event->y;
1960 if (!icon_view->priv->last_single_clicked)
1961 icon_view->priv->last_single_clicked = item;
1963 /* cancel the current editing, if it exists */
1964 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1966 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
1968 GtkCellAreaContext *context;
1970 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1972 _gtk_icon_view_set_cell_data (icon_view, item);
1973 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1974 GTK_WIDGET (icon_view),
1975 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
1980 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1981 !(event->state & modify_mod_mask))
1983 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1986 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1987 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
1990 /* don't draw keyboard focus around an clicked-on item */
1991 icon_view->priv->draw_focus = FALSE;
1994 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
1996 item = _gtk_icon_view_get_item_at_coords (icon_view,
2001 if (item && item == icon_view->priv->last_single_clicked)
2005 path = gtk_tree_path_new_from_indices (item->index, -1);
2006 gtk_icon_view_item_activated (icon_view, path);
2007 gtk_tree_path_free (path);
2010 icon_view->priv->last_single_clicked = NULL;
2011 icon_view->priv->pressed_button = -1;
2015 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2017 return event->button == GDK_BUTTON_PRIMARY;
2021 gtk_icon_view_button_release (GtkWidget *widget,
2022 GdkEventButton *event)
2024 GtkIconView *icon_view;
2026 icon_view = GTK_ICON_VIEW (widget);
2028 if (icon_view->priv->pressed_button == event->button)
2029 icon_view->priv->pressed_button = -1;
2031 gtk_icon_view_stop_rubberbanding (icon_view);
2033 remove_scroll_timeout (icon_view);
2039 gtk_icon_view_key_press (GtkWidget *widget,
2042 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2044 if (icon_view->priv->doing_rubberband)
2046 if (event->keyval == GDK_KEY_Escape)
2047 gtk_icon_view_stop_rubberbanding (icon_view);
2052 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2056 gtk_icon_view_key_release (GtkWidget *widget,
2059 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2061 if (icon_view->priv->doing_rubberband)
2064 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2068 gtk_icon_view_update_rubberband (gpointer data)
2070 GtkIconView *icon_view;
2072 GdkRectangle old_area;
2073 GdkRectangle new_area;
2074 GdkRectangle common;
2075 cairo_region_t *invalid_region;
2077 icon_view = GTK_ICON_VIEW (data);
2079 gdk_window_get_device_position (icon_view->priv->bin_window,
2080 icon_view->priv->rubberband_device,
2086 old_area.x = MIN (icon_view->priv->rubberband_x1,
2087 icon_view->priv->rubberband_x2);
2088 old_area.y = MIN (icon_view->priv->rubberband_y1,
2089 icon_view->priv->rubberband_y2);
2090 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2091 icon_view->priv->rubberband_x1) + 1;
2092 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2093 icon_view->priv->rubberband_y1) + 1;
2095 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2096 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2097 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2098 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2100 invalid_region = cairo_region_create_rectangle (&old_area);
2101 cairo_region_union_rectangle (invalid_region, &new_area);
2103 gdk_rectangle_intersect (&old_area, &new_area, &common);
2104 if (common.width > 2 && common.height > 2)
2106 cairo_region_t *common_region;
2108 /* make sure the border is invalidated */
2114 common_region = cairo_region_create_rectangle (&common);
2116 cairo_region_subtract (invalid_region, common_region);
2117 cairo_region_destroy (common_region);
2120 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2122 cairo_region_destroy (invalid_region);
2124 icon_view->priv->rubberband_x2 = x;
2125 icon_view->priv->rubberband_y2 = y;
2127 gtk_icon_view_update_rubberband_selection (icon_view);
2131 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2138 if (icon_view->priv->rubberband_device)
2141 for (items = icon_view->priv->items; items; items = items->next)
2143 GtkIconViewItem *item = items->data;
2145 item->selected_before_rubberbanding = item->selected;
2148 icon_view->priv->rubberband_x1 = x;
2149 icon_view->priv->rubberband_y1 = y;
2150 icon_view->priv->rubberband_x2 = x;
2151 icon_view->priv->rubberband_y2 = y;
2153 icon_view->priv->doing_rubberband = TRUE;
2154 icon_view->priv->rubberband_device = device;
2156 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2160 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2162 if (!icon_view->priv->doing_rubberband)
2165 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2166 icon_view->priv->rubberband_device);
2168 icon_view->priv->doing_rubberband = FALSE;
2169 icon_view->priv->rubberband_device = NULL;
2171 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2175 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2178 gint x, y, width, height;
2179 gboolean dirty = FALSE;
2181 x = MIN (icon_view->priv->rubberband_x1,
2182 icon_view->priv->rubberband_x2);
2183 y = MIN (icon_view->priv->rubberband_y1,
2184 icon_view->priv->rubberband_y2);
2185 width = ABS (icon_view->priv->rubberband_x1 -
2186 icon_view->priv->rubberband_x2);
2187 height = ABS (icon_view->priv->rubberband_y1 -
2188 icon_view->priv->rubberband_y2);
2190 for (items = icon_view->priv->items; items; items = items->next)
2192 GtkIconViewItem *item = items->data;
2196 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2197 x, y, width, height);
2199 selected = is_in ^ item->selected_before_rubberbanding;
2201 if (item->selected != selected)
2203 item->selected = selected;
2205 gtk_icon_view_queue_draw_item (icon_view, item);
2210 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2215 GdkRectangle hit_rect;
2220 hit_test (GtkCellRenderer *renderer,
2221 const GdkRectangle *cell_area,
2222 const GdkRectangle *cell_background,
2225 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2226 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2227 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2228 MAX (data->hit_rect.y, cell_area->y) > 0)
2231 return (data->hit != FALSE);
2235 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2236 GtkIconViewItem *item,
2242 HitTestData data = { { x, y, width, height }, FALSE };
2243 GtkCellAreaContext *context;
2244 GdkRectangle *item_area = (GdkRectangle *)item;
2246 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2247 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2250 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2252 _gtk_icon_view_set_cell_data (icon_view, item);
2253 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2254 GTK_WIDGET (icon_view),
2255 item_area, item_area,
2256 (GtkCellAllocCallback)hit_test, &data);
2262 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2264 gboolean dirty = FALSE;
2267 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2270 for (items = icon_view->priv->items; items; items = items->next)
2272 GtkIconViewItem *item = items->data;
2276 item->selected = FALSE;
2278 gtk_icon_view_queue_draw_item (icon_view, item);
2279 gtk_icon_view_item_selected_changed (icon_view, item);
2287 /* GtkIconView signals */
2289 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2291 gtk_icon_view_select_all (icon_view);
2295 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2297 gtk_icon_view_unselect_all (icon_view);
2301 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2303 gtk_icon_view_unselect_all (icon_view);
2305 if (icon_view->priv->cursor_item != NULL)
2306 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2310 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2313 GtkCellAreaContext *context;
2315 if (!icon_view->priv->cursor_item)
2318 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2320 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2321 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2322 GTK_WIDGET (icon_view),
2323 (GdkRectangle *)icon_view->priv->cursor_item,
2327 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2328 gtk_icon_view_item_activated (icon_view, path);
2329 gtk_tree_path_free (path);
2335 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2337 if (!icon_view->priv->cursor_item)
2340 switch (icon_view->priv->selection_mode)
2342 case GTK_SELECTION_NONE:
2344 case GTK_SELECTION_BROWSE:
2345 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2347 case GTK_SELECTION_SINGLE:
2348 if (icon_view->priv->cursor_item->selected)
2349 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2351 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2353 case GTK_SELECTION_MULTIPLE:
2354 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2355 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2357 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2358 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2364 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2366 GtkAllocation allocation;
2367 GtkAdjustment *adj = icon_view->priv->hadjustment;
2368 gdouble old_page_size;
2374 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2376 old_value = gtk_adjustment_get_value (adj);
2377 old_upper = gtk_adjustment_get_upper (adj);
2378 old_page_size = gtk_adjustment_get_page_size (adj);
2379 new_upper = MAX (allocation.width, icon_view->priv->width);
2381 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2383 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2384 /* Quick explanation:
2385 * In LTR locales, leftmost portion of visible rectangle should stay
2386 * fixed, which means left edge of scrollbar thumb should remain fixed
2387 * and thus adjustment's value should stay the same.
2389 * In RTL locales, we want to keep rightmost portion of visible
2390 * rectangle fixed. This means right edge of thumb should remain fixed.
2391 * In this case, upper - value - page_size should remain constant.
2393 new_value = (new_upper - allocation.width) -
2394 (old_upper - old_value - old_page_size);
2395 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2398 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2400 gtk_adjustment_configure (adj,
2404 allocation.width * 0.1,
2405 allocation.width * 0.9,
2410 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2412 GtkAllocation allocation;
2413 GtkAdjustment *adj = icon_view->priv->vadjustment;
2415 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2417 gtk_adjustment_configure (adj,
2418 gtk_adjustment_get_value (adj),
2420 MAX (allocation.height, icon_view->priv->height),
2421 allocation.height * 0.1,
2422 allocation.height * 0.9,
2427 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2428 GtkAdjustment *adjustment)
2430 GtkIconViewPrivate *priv = icon_view->priv;
2432 if (adjustment && priv->hadjustment == adjustment)
2435 if (priv->hadjustment != NULL)
2437 g_signal_handlers_disconnect_matched (priv->hadjustment,
2438 G_SIGNAL_MATCH_DATA,
2439 0, 0, NULL, NULL, icon_view);
2440 g_object_unref (priv->hadjustment);
2444 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2447 g_signal_connect (adjustment, "value-changed",
2448 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2449 priv->hadjustment = g_object_ref_sink (adjustment);
2450 gtk_icon_view_set_hadjustment_values (icon_view);
2452 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2456 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2457 GtkAdjustment *adjustment)
2459 GtkIconViewPrivate *priv = icon_view->priv;
2461 if (adjustment && priv->vadjustment == adjustment)
2464 if (priv->vadjustment != NULL)
2466 g_signal_handlers_disconnect_matched (priv->vadjustment,
2467 G_SIGNAL_MATCH_DATA,
2468 0, 0, NULL, NULL, icon_view);
2469 g_object_unref (priv->vadjustment);
2473 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2476 g_signal_connect (adjustment, "value-changed",
2477 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2478 priv->vadjustment = g_object_ref_sink (adjustment);
2479 gtk_icon_view_set_vadjustment_values (icon_view);
2481 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2485 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2486 GtkIconView *icon_view)
2488 GtkIconViewPrivate *priv = icon_view->priv;
2490 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2492 gdk_window_move (priv->bin_window,
2493 - gtk_adjustment_get_value (priv->hadjustment),
2494 - gtk_adjustment_get_value (priv->vadjustment));
2496 if (icon_view->priv->doing_rubberband)
2497 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2499 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2504 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2509 gint *maximum_width)
2511 GtkAllocation allocation;
2512 GtkCellAreaContext *context;
2513 GtkIconViewPrivate *priv = icon_view->priv;
2514 GtkWidget *widget = GTK_WIDGET (icon_view);
2515 gint x, current_width;
2516 GList *items, *last_item;
2518 gint max_height = 0;
2521 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2529 current_width += 2 * priv->margin;
2531 gtk_widget_get_allocation (widget, &allocation);
2533 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2534 g_ptr_array_add (priv->row_contexts, context);
2536 /* In the first loop we iterate horizontally until we hit allocation width
2537 * and collect the aligned height-for-width */
2541 GtkIconViewItem *item = items->data;
2542 GdkRectangle *item_area = (GdkRectangle *)item;
2544 item_area->width = item_width;
2546 current_width += item_area->width + icon_view->priv->item_padding * 2;
2548 if (items != first_item)
2550 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2551 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2555 /* Get this item's particular width & height (all alignments are cached by now) */
2556 _gtk_icon_view_set_cell_data (icon_view, item);
2557 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2562 current_width += icon_view->priv->column_spacing;
2564 item_area->y = *y + icon_view->priv->item_padding;
2565 item_area->x = x + icon_view->priv->item_padding;
2567 x = current_width - icon_view->priv->margin;
2569 if (current_width > *maximum_width)
2570 *maximum_width = current_width;
2576 items = items->next;
2581 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2582 gtk_cell_area_context_allocate (context, item_width, max_height);
2584 /* In the second loop the item height has been aligned and derived and
2585 * we just set the height and handle rtl layout */
2586 for (items = first_item; items != last_item; items = items->next)
2588 GtkIconViewItem *item = items->data;
2589 GdkRectangle *item_area = (GdkRectangle *)item;
2593 item_area->x = *maximum_width - item_area->width - item_area->x;
2594 item->col = col - 1 - item->col;
2597 /* All items in the same row get the same height */
2598 item_area->height = max_height;
2601 /* Adjust the new y coordinate. */
2602 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2608 adjust_wrap_width (GtkIconView *icon_view)
2610 if (icon_view->priv->text_cell)
2612 gint wrap_width = 50;
2614 /* Here we go with the same old guess, try the icon size and set double
2615 * the size of the first icon found in the list, naive but works much
2617 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2619 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2620 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2621 GTK_WIDGET (icon_view),
2624 wrap_width = MAX (wrap_width * 2, 50);
2627 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2628 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2633 gtk_icon_view_layout (GtkIconView *icon_view)
2635 GtkAllocation allocation;
2638 gint y = 0, maximum_width = 0;
2641 gboolean size_changed = FALSE;
2643 if (icon_view->priv->layout_idle_id != 0)
2645 g_source_remove (icon_view->priv->layout_idle_id);
2646 icon_view->priv->layout_idle_id = 0;
2649 if (icon_view->priv->model == NULL)
2652 widget = GTK_WIDGET (icon_view);
2654 item_width = icon_view->priv->item_width;
2656 /* Update the wrap width for the text cell before going and requesting sizes */
2657 adjust_wrap_width (icon_view);
2659 /* Update the context widths for any invalidated items */
2660 gtk_icon_view_cache_widths (icon_view);
2662 /* Fetch the new item width if needed */
2664 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2667 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2669 icons = icon_view->priv->items;
2670 y += icon_view->priv->margin;
2673 /* Clear the per row contexts */
2674 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2678 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2680 &y, &maximum_width);
2683 while (icons != NULL);
2685 if (maximum_width != icon_view->priv->width)
2687 icon_view->priv->width = maximum_width;
2688 size_changed = TRUE;
2691 y += icon_view->priv->margin;
2693 if (y != icon_view->priv->height)
2695 icon_view->priv->height = y;
2696 size_changed = TRUE;
2699 gtk_icon_view_set_hadjustment_values (icon_view);
2700 gtk_icon_view_set_vadjustment_values (icon_view);
2703 gtk_widget_queue_resize_no_redraw (widget);
2705 gtk_widget_get_allocation (widget, &allocation);
2706 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2707 gdk_window_resize (icon_view->priv->bin_window,
2708 MAX (icon_view->priv->width, allocation.width),
2709 MAX (icon_view->priv->height, allocation.height));
2711 if (icon_view->priv->scroll_to_path)
2715 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2716 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2717 icon_view->priv->scroll_to_path = NULL;
2719 gtk_icon_view_scroll_to_path (icon_view, path,
2720 icon_view->priv->scroll_to_use_align,
2721 icon_view->priv->scroll_to_row_align,
2722 icon_view->priv->scroll_to_col_align);
2723 gtk_tree_path_free (path);
2726 gtk_widget_queue_draw (widget);
2729 /* This ensures that all widths have been cached in the
2730 * context and we have proper alignments to go on.
2733 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2737 g_signal_handler_block (icon_view->priv->cell_area_context,
2738 icon_view->priv->context_changed_id);
2740 for (items = icon_view->priv->items; items; items = items->next)
2742 GtkIconViewItem *item = items->data;
2744 /* Only fetch the width of items with invalidated sizes */
2745 if (item->cell_area.width < 0)
2747 _gtk_icon_view_set_cell_data (icon_view, item);
2748 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2749 icon_view->priv->cell_area_context,
2750 GTK_WIDGET (icon_view), NULL, NULL);
2754 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2755 icon_view->priv->context_changed_id);
2759 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2761 /* Clear all item sizes */
2762 g_list_foreach (icon_view->priv->items,
2763 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2765 /* Reset the context */
2766 if (icon_view->priv->cell_area_context)
2768 g_signal_handler_block (icon_view->priv->cell_area_context,
2769 icon_view->priv->context_changed_id);
2770 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2771 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2772 icon_view->priv->context_changed_id);
2775 /* Re-layout the items */
2776 gtk_icon_view_queue_layout (icon_view);
2780 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2782 item->cell_area.width = -1;
2783 item->cell_area.height = -1;
2787 gtk_icon_view_paint_item (GtkIconView *icon_view,
2789 GtkIconViewItem *item,
2792 gboolean draw_focus)
2794 GdkRectangle cell_area;
2795 GtkStateFlags state = 0;
2796 GtkCellRendererState flags = 0;
2797 GtkStyleContext *style_context;
2798 GtkWidget *widget = GTK_WIDGET (icon_view);
2799 GtkIconViewPrivate *priv = icon_view->priv;
2800 GtkCellAreaContext *context;
2802 if (priv->model == NULL)
2805 _gtk_icon_view_set_cell_data (icon_view, item);
2807 style_context = gtk_widget_get_style_context (widget);
2808 state = gtk_widget_get_state_flags (widget);
2810 gtk_style_context_save (style_context);
2811 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2812 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2814 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
2818 if ((state & GTK_STATE_FLAG_FOCUSED) &&
2819 item == icon_view->priv->cursor_item)
2821 flags |= GTK_CELL_RENDERER_FOCUSED;
2824 state |= GTK_STATE_FLAG_SELECTED;
2825 flags |= GTK_CELL_RENDERER_SELECTED;
2830 state |= GTK_STATE_FLAG_PRELIGHT;
2831 flags |= GTK_CELL_RENDERER_PRELIT;
2834 gtk_style_context_set_state (style_context, state);
2838 gtk_render_background (style_context, cr,
2839 x - icon_view->priv->item_padding,
2840 y - icon_view->priv->item_padding,
2841 item->cell_area.width + icon_view->priv->item_padding * 2,
2842 item->cell_area.height + icon_view->priv->item_padding * 2);
2843 gtk_render_frame (style_context, cr,
2844 x - icon_view->priv->item_padding,
2845 y - icon_view->priv->item_padding,
2846 item->cell_area.width + icon_view->priv->item_padding * 2,
2847 item->cell_area.height + icon_view->priv->item_padding * 2);
2852 cell_area.width = item->cell_area.width;
2853 cell_area.height = item->cell_area.height;
2855 context = g_ptr_array_index (priv->row_contexts, item->row);
2856 gtk_cell_area_render (priv->cell_area, context,
2857 widget, cr, &cell_area, &cell_area, flags,
2860 gtk_style_context_restore (style_context);
2864 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2867 GtkStyleContext *context;
2872 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2873 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2874 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2875 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2877 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2879 gtk_style_context_save (context);
2880 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2882 gdk_cairo_rectangle (cr, &rect);
2885 gtk_render_background (context, cr,
2887 rect.width, rect.height);
2888 gtk_render_frame (context, cr,
2890 rect.width, rect.height);
2892 gtk_style_context_restore (context);
2897 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2903 index = gtk_tree_path_get_indices (path)[0];
2905 for (l = icon_view->priv->items; l; l = l->next)
2907 GtkIconViewItem *item = l->data;
2909 if (item->index == index)
2911 gtk_icon_view_queue_draw_item (icon_view, item);
2918 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2919 GtkIconViewItem *item)
2922 GdkRectangle *item_area = (GdkRectangle *)item;
2924 rect.x = item_area->x - icon_view->priv->item_padding;
2925 rect.y = item_area->y - icon_view->priv->item_padding;
2926 rect.width = item_area->width + icon_view->priv->item_padding * 2;
2927 rect.height = item_area->height + icon_view->priv->item_padding * 2;
2929 if (icon_view->priv->bin_window)
2930 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
2934 layout_callback (gpointer user_data)
2936 GtkIconView *icon_view;
2938 icon_view = GTK_ICON_VIEW (user_data);
2940 icon_view->priv->layout_idle_id = 0;
2942 gtk_icon_view_layout (icon_view);
2948 gtk_icon_view_queue_layout (GtkIconView *icon_view)
2950 if (icon_view->priv->layout_idle_id != 0)
2953 icon_view->priv->layout_idle_id =
2954 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
2955 layout_callback, icon_view, NULL);
2959 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
2960 GtkIconViewItem *item,
2961 GtkCellRenderer *cursor_cell)
2964 AtkObject *item_obj;
2965 AtkObject *cursor_item_obj;
2967 /* When hitting this path from keynav, the focus cell is
2968 * already set, we dont need to notify the atk object
2969 * but we still need to queue the draw here (in the case
2970 * that the focus cell changes but not the cursor item).
2972 gtk_icon_view_queue_draw_item (icon_view, item);
2974 if (icon_view->priv->cursor_item == item &&
2975 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
2978 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2979 if (icon_view->priv->cursor_item != NULL)
2981 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2984 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
2985 if (cursor_item_obj != NULL)
2986 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
2989 icon_view->priv->cursor_item = item;
2992 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
2995 /* Make sure there is a cell in focus initially */
2996 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
2997 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3000 /* Notify that accessible focus object has changed */
3001 item_obj = atk_object_ref_accessible_child (obj, item->index);
3003 if (item_obj != NULL)
3005 atk_focus_tracker_notify (item_obj);
3006 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3007 g_object_unref (item_obj);
3012 static GtkIconViewItem *
3013 gtk_icon_view_item_new (void)
3015 GtkIconViewItem *item;
3017 item = g_slice_new0 (GtkIconViewItem);
3019 item->cell_area.width = -1;
3020 item->cell_area.height = -1;
3026 gtk_icon_view_item_free (GtkIconViewItem *item)
3028 g_return_if_fail (item != NULL);
3030 g_slice_free (GtkIconViewItem, item);
3034 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3037 gboolean only_in_cell,
3038 GtkCellRenderer **cell_at_pos)
3043 *cell_at_pos = NULL;
3045 for (items = icon_view->priv->items; items; items = items->next)
3047 GtkIconViewItem *item = items->data;
3048 GdkRectangle *item_area = (GdkRectangle *)item;
3050 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3051 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3052 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3053 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3055 if (only_in_cell || cell_at_pos)
3057 GtkCellRenderer *cell = NULL;
3058 GtkCellAreaContext *context;
3060 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3061 _gtk_icon_view_set_cell_data (icon_view, item);
3063 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3064 y >= item_area->y && y <= item_area->y + item_area->height)
3065 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3066 GTK_WIDGET (icon_view),
3071 *cell_at_pos = cell;
3074 return cell != NULL ? item : NULL;
3085 _gtk_icon_view_select_item (GtkIconView *icon_view,
3086 GtkIconViewItem *item)
3088 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3089 g_return_if_fail (item != NULL);
3094 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3096 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3097 gtk_icon_view_unselect_all_internal (icon_view);
3099 item->selected = TRUE;
3101 gtk_icon_view_item_selected_changed (icon_view, item);
3102 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3104 gtk_icon_view_queue_draw_item (icon_view, item);
3109 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3110 GtkIconViewItem *item)
3112 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3113 g_return_if_fail (item != NULL);
3115 if (!item->selected)
3118 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3119 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3122 item->selected = FALSE;
3124 gtk_icon_view_item_selected_changed (icon_view, item);
3125 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3127 gtk_icon_view_queue_draw_item (icon_view, item);
3131 verify_items (GtkIconView *icon_view)
3136 for (items = icon_view->priv->items; items; items = items->next)
3138 GtkIconViewItem *item = items->data;
3140 if (item->index != i)
3141 g_error ("List item does not match its index: "
3142 "item index %d and list index %d\n", item->index, i);
3149 gtk_icon_view_row_changed (GtkTreeModel *model,
3154 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3156 /* ignore changes in branches */
3157 if (gtk_tree_path_get_depth (path) > 1)
3160 /* An icon view subclass might add it's own model and populate
3161 * things at init() time instead of waiting for the constructor()
3164 if (icon_view->priv->cell_area)
3165 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3167 /* Here we can use a "grow-only" strategy for optimization
3168 * and only invalidate a single item and queue a relayout
3169 * instead of invalidating the whole thing.
3171 * For now GtkIconView still cant deal with huge models
3172 * so just invalidate the whole thing when the model
3175 gtk_icon_view_invalidate_sizes (icon_view);
3177 verify_items (icon_view);
3181 gtk_icon_view_row_inserted (GtkTreeModel *model,
3186 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3188 GtkIconViewItem *item;
3189 gboolean iters_persist;
3192 /* ignore changes in branches */
3193 if (gtk_tree_path_get_depth (path) > 1)
3196 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3198 index = gtk_tree_path_get_indices(path)[0];
3200 item = gtk_icon_view_item_new ();
3205 item->index = index;
3207 /* FIXME: We can be more efficient here,
3208 we can store a tail pointer and use that when
3209 appending (which is a rather common operation)
3211 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3214 list = g_list_nth (icon_view->priv->items, index + 1);
3215 for (; list; list = list->next)
3222 verify_items (icon_view);
3224 gtk_icon_view_queue_layout (icon_view);
3228 gtk_icon_view_row_deleted (GtkTreeModel *model,
3232 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3234 GtkIconViewItem *item;
3236 gboolean emit = FALSE;
3238 /* ignore changes in branches */
3239 if (gtk_tree_path_get_depth (path) > 1)
3242 index = gtk_tree_path_get_indices(path)[0];
3244 list = g_list_nth (icon_view->priv->items, index);
3247 if (icon_view->priv->cell_area)
3248 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3250 if (item == icon_view->priv->anchor_item)
3251 icon_view->priv->anchor_item = NULL;
3253 if (item == icon_view->priv->cursor_item)
3254 icon_view->priv->cursor_item = NULL;
3256 if (item == icon_view->priv->last_prelight)
3257 icon_view->priv->last_prelight = NULL;
3262 gtk_icon_view_item_free (item);
3264 for (next = list->next; next; next = next->next)
3271 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3273 verify_items (icon_view);
3275 gtk_icon_view_queue_layout (icon_view);
3278 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3282 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3283 GtkTreePath *parent,
3288 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3291 GList *items = NULL, *list;
3292 GtkIconViewItem **item_array;
3295 /* ignore changes in branches */
3299 if (icon_view->priv->cell_area)
3300 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3302 length = gtk_tree_model_iter_n_children (model, NULL);
3304 order = g_new (gint, length);
3305 for (i = 0; i < length; i++)
3306 order [new_order[i]] = i;
3308 item_array = g_new (GtkIconViewItem *, length);
3309 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3310 item_array[order[i]] = list->data;
3313 for (i = length - 1; i >= 0; i--)
3315 item_array[i]->index = i;
3316 items = g_list_prepend (items, item_array[i]);
3319 g_free (item_array);
3320 g_list_free (icon_view->priv->items);
3321 icon_view->priv->items = items;
3323 gtk_icon_view_queue_layout (icon_view);
3325 verify_items (icon_view);
3329 gtk_icon_view_build_items (GtkIconView *icon_view)
3333 gboolean iters_persist;
3334 GList *items = NULL;
3336 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3338 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3346 GtkIconViewItem *item = gtk_icon_view_item_new ();
3355 items = g_list_prepend (items, item);
3357 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3359 icon_view->priv->items = g_list_reverse (items);
3363 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3366 GtkMovementStep step,
3370 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3371 I_("move-cursor"), 2,
3375 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3380 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3383 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3388 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3395 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3396 GtkMovementStep step,
3399 GdkModifierType state;
3401 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3402 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3403 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3404 step == GTK_MOVEMENT_DISPLAY_LINES ||
3405 step == GTK_MOVEMENT_PAGES ||
3406 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3408 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3411 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3412 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3414 if (gtk_get_current_event_state (&state))
3416 GdkModifierType extend_mod_mask;
3417 GdkModifierType modify_mod_mask;
3420 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3421 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3423 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3424 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3426 if ((state & modify_mod_mask) == modify_mod_mask)
3427 icon_view->priv->modify_selection_pressed = TRUE;
3428 if ((state & extend_mod_mask) == extend_mod_mask)
3429 icon_view->priv->extend_selection_pressed = TRUE;
3431 /* else we assume not pressed */
3435 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3436 case GTK_MOVEMENT_VISUAL_POSITIONS:
3437 gtk_icon_view_move_cursor_left_right (icon_view, count);
3439 case GTK_MOVEMENT_DISPLAY_LINES:
3440 gtk_icon_view_move_cursor_up_down (icon_view, count);
3442 case GTK_MOVEMENT_PAGES:
3443 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3445 case GTK_MOVEMENT_BUFFER_ENDS:
3446 gtk_icon_view_move_cursor_start_end (icon_view, count);
3449 g_assert_not_reached ();
3452 icon_view->priv->modify_selection_pressed = FALSE;
3453 icon_view->priv->extend_selection_pressed = FALSE;
3455 icon_view->priv->draw_focus = TRUE;
3460 static GtkIconViewItem *
3461 find_item (GtkIconView *icon_view,
3462 GtkIconViewItem *current,
3468 GtkIconViewItem *item;
3470 /* FIXME: this could be more efficient
3472 row = current->row + row_ofs;
3473 col = current->col + col_ofs;
3475 for (items = icon_view->priv->items; items; items = items->next)
3478 if (item->row == row && item->col == col)
3485 static GtkIconViewItem *
3486 find_item_page_up_down (GtkIconView *icon_view,
3487 GtkIconViewItem *current,
3494 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3496 item = g_list_find (icon_view->priv->items, current);
3501 for (next = item->next; next; next = next->next)
3503 if (((GtkIconViewItem *)next->data)->col == col)
3506 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3516 for (next = item->prev; next; next = next->prev)
3518 if (((GtkIconViewItem *)next->data)->col == col)
3521 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3535 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3536 GtkIconViewItem *anchor,
3537 GtkIconViewItem *cursor)
3540 GtkIconViewItem *item;
3541 gint row1, row2, col1, col2;
3542 gboolean dirty = FALSE;
3544 if (anchor->row < cursor->row)
3555 if (anchor->col < cursor->col)
3566 for (items = icon_view->priv->items; items; items = items->next)
3570 if (row1 <= item->row && item->row <= row2 &&
3571 col1 <= item->col && item->col <= col2)
3573 if (!item->selected)
3576 item->selected = TRUE;
3577 gtk_icon_view_item_selected_changed (icon_view, item);
3579 gtk_icon_view_queue_draw_item (icon_view, item);
3587 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3590 GtkIconViewItem *item;
3591 GtkCellRenderer *cell = NULL;
3592 gboolean dirty = FALSE;
3594 GtkDirectionType direction;
3596 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3599 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3601 if (!icon_view->priv->cursor_item)
3606 list = icon_view->priv->items;
3608 list = g_list_last (icon_view->priv->items);
3614 /* Give focus to the first cell initially */
3615 _gtk_icon_view_set_cell_data (icon_view, item);
3616 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3625 item = icon_view->priv->cursor_item;
3626 step = count > 0 ? 1 : -1;
3628 /* Save the current focus cell in case we hit the edge */
3629 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3633 _gtk_icon_view_set_cell_data (icon_view, item);
3635 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3638 item = find_item (icon_view, item, step, 0);
3644 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3646 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3648 gtk_widget_child_focus (toplevel,
3649 direction == GTK_DIR_UP ?
3650 GTK_DIR_TAB_BACKWARD :
3651 GTK_DIR_TAB_FORWARD);
3655 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3659 if (icon_view->priv->modify_selection_pressed ||
3660 !icon_view->priv->extend_selection_pressed ||
3661 !icon_view->priv->anchor_item ||
3662 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3663 icon_view->priv->anchor_item = item;
3665 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3666 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3668 if (!icon_view->priv->modify_selection_pressed &&
3669 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3671 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3672 dirty = gtk_icon_view_select_all_between (icon_view,
3673 icon_view->priv->anchor_item,
3677 gtk_icon_view_scroll_to_item (icon_view, item);
3680 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3684 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3687 GtkIconViewItem *item;
3688 gboolean dirty = FALSE;
3690 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3693 if (!icon_view->priv->cursor_item)
3698 list = icon_view->priv->items;
3700 list = g_list_last (icon_view->priv->items);
3702 item = list ? list->data : NULL;
3705 item = find_item_page_up_down (icon_view,
3706 icon_view->priv->cursor_item,
3709 if (item == icon_view->priv->cursor_item)
3710 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3715 if (icon_view->priv->modify_selection_pressed ||
3716 !icon_view->priv->extend_selection_pressed ||
3717 !icon_view->priv->anchor_item ||
3718 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3719 icon_view->priv->anchor_item = item;
3721 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3723 if (!icon_view->priv->modify_selection_pressed &&
3724 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3726 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3727 dirty = gtk_icon_view_select_all_between (icon_view,
3728 icon_view->priv->anchor_item,
3732 gtk_icon_view_scroll_to_item (icon_view, item);
3735 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3739 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3742 GtkIconViewItem *item;
3743 GtkCellRenderer *cell = NULL;
3744 gboolean dirty = FALSE;
3746 GtkDirectionType direction;
3748 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3751 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3753 if (!icon_view->priv->cursor_item)
3758 list = icon_view->priv->items;
3760 list = g_list_last (icon_view->priv->items);
3766 /* Give focus to the first cell initially */
3767 _gtk_icon_view_set_cell_data (icon_view, item);
3768 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3777 item = icon_view->priv->cursor_item;
3778 step = count > 0 ? 1 : -1;
3780 /* Save the current focus cell in case we hit the edge */
3781 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3785 _gtk_icon_view_set_cell_data (icon_view, item);
3787 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3790 item = find_item (icon_view, item, 0, step);
3796 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3798 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3800 gtk_widget_child_focus (toplevel,
3801 direction == GTK_DIR_LEFT ?
3802 GTK_DIR_TAB_BACKWARD :
3803 GTK_DIR_TAB_FORWARD);
3807 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3811 if (icon_view->priv->modify_selection_pressed ||
3812 !icon_view->priv->extend_selection_pressed ||
3813 !icon_view->priv->anchor_item ||
3814 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3815 icon_view->priv->anchor_item = item;
3817 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3818 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3820 if (!icon_view->priv->modify_selection_pressed &&
3821 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3823 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3824 dirty = gtk_icon_view_select_all_between (icon_view,
3825 icon_view->priv->anchor_item,
3829 gtk_icon_view_scroll_to_item (icon_view, item);
3832 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3836 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3839 GtkIconViewItem *item;
3841 gboolean dirty = FALSE;
3843 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3847 list = icon_view->priv->items;
3849 list = g_list_last (icon_view->priv->items);
3851 item = list ? list->data : NULL;
3853 if (item == icon_view->priv->cursor_item)
3854 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3859 if (icon_view->priv->modify_selection_pressed ||
3860 !icon_view->priv->extend_selection_pressed ||
3861 !icon_view->priv->anchor_item ||
3862 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3863 icon_view->priv->anchor_item = item;
3865 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3867 if (!icon_view->priv->modify_selection_pressed &&
3868 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3870 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3871 dirty = gtk_icon_view_select_all_between (icon_view,
3872 icon_view->priv->anchor_item,
3876 gtk_icon_view_scroll_to_item (icon_view, item);
3879 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3883 * gtk_icon_view_scroll_to_path:
3884 * @icon_view: A #GtkIconView.
3885 * @path: The path of the item to move to.
3886 * @use_align: whether to use alignment arguments, or %FALSE.
3887 * @row_align: The vertical alignment of the item specified by @path.
3888 * @col_align: The horizontal alignment of the item specified by @path.
3890 * Moves the alignments of @icon_view to the position specified by @path.
3891 * @row_align determines where the row is placed, and @col_align determines
3892 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3893 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3896 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3897 * tree does the minimum amount of work to scroll the item onto the screen.
3898 * This means that the item will be scrolled to the edge closest to its current
3899 * position. If the item is currently visible on the screen, nothing is done.
3901 * This function only works if the model is set, and @path is a valid row on
3902 * the model. If the model changes before the @icon_view is realized, the
3903 * centered path will be modified to reflect this change.
3908 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3914 GtkIconViewItem *item = NULL;
3917 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3918 g_return_if_fail (path != NULL);
3919 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3920 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3922 widget = GTK_WIDGET (icon_view);
3924 if (gtk_tree_path_get_depth (path) > 0)
3925 item = g_list_nth_data (icon_view->priv->items,
3926 gtk_tree_path_get_indices(path)[0]);
3928 if (!item || item->cell_area.width < 0 ||
3929 !gtk_widget_get_realized (widget))
3931 if (icon_view->priv->scroll_to_path)
3932 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3934 icon_view->priv->scroll_to_path = NULL;
3937 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3939 icon_view->priv->scroll_to_use_align = use_align;
3940 icon_view->priv->scroll_to_row_align = row_align;
3941 icon_view->priv->scroll_to_col_align = col_align;
3948 GtkAllocation allocation;
3951 GdkRectangle item_area =
3953 item->cell_area.x - icon_view->priv->item_padding,
3954 item->cell_area.y - icon_view->priv->item_padding,
3955 item->cell_area.width + icon_view->priv->item_padding * 2,
3956 item->cell_area.height + icon_view->priv->item_padding * 2
3959 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3961 gtk_widget_get_allocation (widget, &allocation);
3963 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
3965 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3966 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
3968 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
3970 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3971 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
3973 gtk_adjustment_changed (icon_view->priv->hadjustment);
3974 gtk_adjustment_changed (icon_view->priv->vadjustment);
3977 gtk_icon_view_scroll_to_item (icon_view, item);
3982 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
3983 GtkIconViewItem *item)
3985 GtkIconViewPrivate *priv = icon_view->priv;
3986 GtkWidget *widget = GTK_WIDGET (icon_view);
3987 GtkAdjustment *hadj, *vadj;
3988 GtkAllocation allocation;
3990 GdkRectangle item_area;
3992 item_area.x = item->cell_area.x - priv->item_padding;
3993 item_area.y = item->cell_area.y - priv->item_padding;
3994 item_area.width = item->cell_area.width + priv->item_padding * 2;
3995 item_area.height = item->cell_area.height + priv->item_padding * 2;
3997 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3998 gtk_widget_get_allocation (widget, &allocation);
4000 hadj = icon_view->priv->hadjustment;
4001 vadj = icon_view->priv->vadjustment;
4003 if (y + item_area.y < 0)
4004 gtk_adjustment_set_value (vadj,
4005 gtk_adjustment_get_value (vadj)
4007 else if (y + item_area.y + item_area.height > allocation.height)
4008 gtk_adjustment_set_value (vadj,
4009 gtk_adjustment_get_value (vadj)
4010 + y + item_area.y + item_area.height - allocation.height);
4012 if (x + item_area.x < 0)
4013 gtk_adjustment_set_value (hadj,
4014 gtk_adjustment_get_value (hadj)
4016 else if (x + item_area.x + item_area.width > allocation.width)
4017 gtk_adjustment_set_value (hadj,
4018 gtk_adjustment_get_value (hadj)
4019 + x + item_area.x + item_area.width - allocation.width);
4021 gtk_adjustment_changed (hadj);
4022 gtk_adjustment_changed (vadj);
4025 /* GtkCellLayout implementation */
4028 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4029 GtkCellArea *cell_area)
4031 GtkIconViewPrivate *priv = icon_view->priv;
4033 if (priv->cell_area)
4037 priv->cell_area = cell_area;
4039 priv->cell_area = gtk_cell_area_box_new ();
4041 g_object_ref_sink (priv->cell_area);
4043 if (GTK_IS_ORIENTABLE (priv->cell_area))
4044 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4046 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4048 priv->add_editable_id =
4049 g_signal_connect (priv->cell_area, "add-editable",
4050 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4051 priv->remove_editable_id =
4052 g_signal_connect (priv->cell_area, "remove-editable",
4053 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4054 priv->context_changed_id =
4055 g_signal_connect (priv->cell_area_context, "notify",
4056 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4058 update_text_cell (icon_view);
4059 update_pixbuf_cell (icon_view);
4062 static GtkCellArea *
4063 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4065 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4066 GtkIconViewPrivate *priv = icon_view->priv;
4068 if (G_UNLIKELY (!priv->cell_area))
4069 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4071 return icon_view->priv->cell_area;
4075 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4076 GtkIconViewItem *item)
4078 gboolean iters_persist;
4081 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4087 path = gtk_tree_path_new_from_indices (item->index, -1);
4088 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4090 gtk_tree_path_free (path);
4095 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4096 icon_view->priv->model,
4097 &iter, FALSE, FALSE);
4106 * gtk_icon_view_new:
4108 * Creates a new #GtkIconView widget
4110 * Return value: A newly created #GtkIconView widget
4115 gtk_icon_view_new (void)
4117 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4121 * gtk_icon_view_new_with_area:
4122 * @area: the #GtkCellArea to use to layout cells
4124 * Creates a new #GtkIconView widget using the
4125 * specified @area to layout cells inside the icons.
4127 * Return value: A newly created #GtkIconView widget
4132 gtk_icon_view_new_with_area (GtkCellArea *area)
4134 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4138 * gtk_icon_view_new_with_model:
4139 * @model: The model.
4141 * Creates a new #GtkIconView widget with the model @model.
4143 * Return value: A newly created #GtkIconView widget.
4148 gtk_icon_view_new_with_model (GtkTreeModel *model)
4150 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4154 * gtk_icon_view_convert_widget_to_bin_window_coords:
4155 * @icon_view: a #GtkIconView
4156 * @wx: X coordinate relative to the widget
4157 * @wy: Y coordinate relative to the widget
4158 * @bx: (out): return location for bin_window X coordinate
4159 * @by: (out): return location for bin_window Y coordinate
4161 * Converts widget coordinates to coordinates for the bin_window,
4162 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4167 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4175 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4177 if (icon_view->priv->bin_window)
4178 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4189 * gtk_icon_view_get_path_at_pos:
4190 * @icon_view: A #GtkIconView.
4191 * @x: The x position to be identified
4192 * @y: The y position to be identified
4194 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4195 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4196 * the cell at the specified position.
4197 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4198 * widget coordinates to bin_window coordinates.
4200 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4201 * if no icon exists at that position.
4206 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4210 GtkIconViewItem *item;
4213 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4215 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4220 path = gtk_tree_path_new_from_indices (item->index, -1);
4226 * gtk_icon_view_get_item_at_pos:
4227 * @icon_view: A #GtkIconView.
4228 * @x: The x position to be identified
4229 * @y: The y position to be identified
4230 * @path: (out) (allow-none): Return location for the path, or %NULL
4231 * @cell: (out) (allow-none): Return location for the renderer
4232 * responsible for the cell at (@x, @y), or %NULL
4234 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4235 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4236 * obtains the cell at the specified position. The returned path should
4237 * be freed with gtk_tree_path_free().
4238 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4239 * widget coordinates to bin_window coordinates.
4241 * Return value: %TRUE if an item exists at the specified position
4246 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4250 GtkCellRenderer **cell)
4252 GtkIconViewItem *item;
4253 GtkCellRenderer *renderer = NULL;
4255 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4257 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4262 *path = gtk_tree_path_new_from_indices (item->index, -1);
4270 return (item != NULL);
4274 * gtk_icon_view_set_tooltip_item:
4275 * @icon_view: a #GtkIconView
4276 * @tooltip: a #GtkTooltip
4277 * @path: a #GtkTreePath
4279 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4280 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4281 * See also gtk_tooltip_set_tip_area().
4286 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4287 GtkTooltip *tooltip,
4290 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4291 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4293 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4297 * gtk_icon_view_set_tooltip_cell:
4298 * @icon_view: a #GtkIconView
4299 * @tooltip: a #GtkTooltip
4300 * @path: a #GtkTreePath
4301 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4303 * Sets the tip area of @tooltip to the area which @cell occupies in
4304 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4306 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4311 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4312 GtkTooltip *tooltip,
4314 GtkCellRenderer *cell)
4317 GtkIconViewItem *item = NULL;
4320 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4321 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4322 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4324 if (gtk_tree_path_get_depth (path) > 0)
4325 item = g_list_nth_data (icon_view->priv->items,
4326 gtk_tree_path_get_indices(path)[0]);
4333 GtkCellAreaContext *context;
4335 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4336 _gtk_icon_view_set_cell_data (icon_view, item);
4337 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4338 GTK_WIDGET (icon_view),
4339 cell, (GdkRectangle *)item, &rect);
4343 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4344 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4345 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4346 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4349 if (icon_view->priv->bin_window)
4351 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4356 gtk_tooltip_set_tip_area (tooltip, &rect);
4361 * gtk_icon_view_get_tooltip_context:
4362 * @icon_view: an #GtkIconView
4363 * @x: (inout): the x coordinate (relative to widget coordinates)
4364 * @y: (inout): the y coordinate (relative to widget coordinates)
4365 * @keyboard_tip: whether this is a keyboard tooltip or not
4366 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4367 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4368 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4370 * This function is supposed to be used in a #GtkWidget::query-tooltip
4371 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4372 * which are received in the signal handler, should be passed to this
4373 * function without modification.
4375 * The return value indicates whether there is an icon view item at the given
4376 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4377 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4378 * @model, @path and @iter which have been provided will be set to point to
4379 * that row and the corresponding model. @x and @y will always be converted
4380 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4382 * Return value: whether or not the given tooltip context points to a item
4387 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4390 gboolean keyboard_tip,
4391 GtkTreeModel **model,
4395 GtkTreePath *tmppath = NULL;
4397 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4398 g_return_val_if_fail (x != NULL, FALSE);
4399 g_return_val_if_fail (y != NULL, FALSE);
4403 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4410 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4413 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4418 *model = gtk_icon_view_get_model (icon_view);
4421 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4427 gtk_tree_path_free (tmppath);
4433 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4436 gboolean keyboard_tip,
4437 GtkTooltip *tooltip,
4443 GtkTreeModel *model;
4444 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4446 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4449 &model, &path, &iter))
4452 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4456 gtk_tree_path_free (path);
4460 gtk_tooltip_set_markup (tooltip, str);
4461 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4463 gtk_tree_path_free (path);
4471 * gtk_icon_view_set_tooltip_column:
4472 * @icon_view: a #GtkIconView
4473 * @column: an integer, which is a valid column number for @icon_view's model
4475 * If you only plan to have simple (text-only) tooltips on full items, you
4476 * can use this function to have #GtkIconView handle these automatically
4477 * for you. @column should be set to the column in @icon_view's model
4478 * containing the tooltip texts, or -1 to disable this feature.
4480 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4481 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4483 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4484 * so &, <, etc have to be escaped in the text.
4489 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4492 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4494 if (column == icon_view->priv->tooltip_column)
4499 g_signal_handlers_disconnect_by_func (icon_view,
4500 gtk_icon_view_set_tooltip_query_cb,
4502 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4506 if (icon_view->priv->tooltip_column == -1)
4508 g_signal_connect (icon_view, "query-tooltip",
4509 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4510 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4514 icon_view->priv->tooltip_column = column;
4515 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4519 * gtk_icon_view_get_tooltip_column:
4520 * @icon_view: a #GtkIconView
4522 * Returns the column of @icon_view's model which is being used for
4523 * displaying tooltips on @icon_view's rows.
4525 * Return value: the index of the tooltip column that is currently being
4526 * used, or -1 if this is disabled.
4531 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4533 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4535 return icon_view->priv->tooltip_column;
4539 * gtk_icon_view_get_visible_range:
4540 * @icon_view: A #GtkIconView
4541 * @start_path: (out) (allow-none): Return location for start of region,
4543 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4545 * Sets @start_path and @end_path to be the first and last visible path.
4546 * Note that there may be invisible paths in between.
4548 * Both paths should be freed with gtk_tree_path_free() after use.
4550 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4555 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4556 GtkTreePath **start_path,
4557 GtkTreePath **end_path)
4559 gint start_index = -1;
4560 gint end_index = -1;
4563 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4565 if (icon_view->priv->hadjustment == NULL ||
4566 icon_view->priv->vadjustment == NULL)
4569 if (start_path == NULL && end_path == NULL)
4572 for (icons = icon_view->priv->items; icons; icons = icons->next)
4574 GtkIconViewItem *item = icons->data;
4575 GdkRectangle *item_area = (GdkRectangle *)item;
4577 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4578 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4580 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4581 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4583 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4584 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4586 if (start_index == -1)
4587 start_index = item->index;
4588 end_index = item->index;
4592 if (start_path && start_index != -1)
4593 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4594 if (end_path && end_index != -1)
4595 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4597 return start_index != -1;
4601 * gtk_icon_view_selected_foreach:
4602 * @icon_view: A #GtkIconView.
4603 * @func: (scope call): The function to call for each selected icon.
4604 * @data: User data to pass to the function.
4606 * Calls a function for each selected icon. Note that the model or
4607 * selection cannot be modified from within this function.
4612 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4613 GtkIconViewForeachFunc func,
4618 for (list = icon_view->priv->items; list; list = list->next)
4620 GtkIconViewItem *item = list->data;
4621 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4624 (* func) (icon_view, path, data);
4626 gtk_tree_path_free (path);
4631 * gtk_icon_view_set_selection_mode:
4632 * @icon_view: A #GtkIconView.
4633 * @mode: The selection mode
4635 * Sets the selection mode of the @icon_view.
4640 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4641 GtkSelectionMode mode)
4643 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4645 if (mode == icon_view->priv->selection_mode)
4648 if (mode == GTK_SELECTION_NONE ||
4649 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4650 gtk_icon_view_unselect_all (icon_view);
4652 icon_view->priv->selection_mode = mode;
4654 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4658 * gtk_icon_view_get_selection_mode:
4659 * @icon_view: A #GtkIconView.
4661 * Gets the selection mode of the @icon_view.
4663 * Return value: the current selection mode
4668 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4670 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4672 return icon_view->priv->selection_mode;
4676 * gtk_icon_view_set_model:
4677 * @icon_view: A #GtkIconView.
4678 * @model: (allow-none): The model.
4680 * Sets the model for a #GtkIconView.
4681 * If the @icon_view already has a model set, it will remove
4682 * it before setting the new model. If @model is %NULL, then
4683 * it will unset the old model.
4688 gtk_icon_view_set_model (GtkIconView *icon_view,
4689 GtkTreeModel *model)
4691 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4692 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4694 if (icon_view->priv->model == model)
4697 if (icon_view->priv->scroll_to_path)
4699 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4700 icon_view->priv->scroll_to_path = NULL;
4703 /* The area can be NULL while disposing */
4704 if (icon_view->priv->cell_area)
4705 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4711 if (icon_view->priv->pixbuf_column != -1)
4713 column_type = gtk_tree_model_get_column_type (model,
4714 icon_view->priv->pixbuf_column);
4716 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4719 if (icon_view->priv->text_column != -1)
4721 column_type = gtk_tree_model_get_column_type (model,
4722 icon_view->priv->text_column);
4724 g_return_if_fail (column_type == G_TYPE_STRING);
4727 if (icon_view->priv->markup_column != -1)
4729 column_type = gtk_tree_model_get_column_type (model,
4730 icon_view->priv->markup_column);
4732 g_return_if_fail (column_type == G_TYPE_STRING);
4737 if (icon_view->priv->model)
4739 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4740 gtk_icon_view_row_changed,
4742 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4743 gtk_icon_view_row_inserted,
4745 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4746 gtk_icon_view_row_deleted,
4748 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4749 gtk_icon_view_rows_reordered,
4752 g_object_unref (icon_view->priv->model);
4754 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4755 icon_view->priv->items = NULL;
4756 icon_view->priv->anchor_item = NULL;
4757 icon_view->priv->cursor_item = NULL;
4758 icon_view->priv->last_single_clicked = NULL;
4759 icon_view->priv->last_prelight = NULL;
4760 icon_view->priv->width = 0;
4761 icon_view->priv->height = 0;
4764 icon_view->priv->model = model;
4766 if (icon_view->priv->model)
4768 g_object_ref (icon_view->priv->model);
4769 g_signal_connect (icon_view->priv->model,
4771 G_CALLBACK (gtk_icon_view_row_changed),
4773 g_signal_connect (icon_view->priv->model,
4775 G_CALLBACK (gtk_icon_view_row_inserted),
4777 g_signal_connect (icon_view->priv->model,
4779 G_CALLBACK (gtk_icon_view_row_deleted),
4781 g_signal_connect (icon_view->priv->model,
4783 G_CALLBACK (gtk_icon_view_rows_reordered),
4786 gtk_icon_view_build_items (icon_view);
4788 gtk_icon_view_layout (icon_view);
4791 g_object_notify (G_OBJECT (icon_view), "model");
4793 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4794 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4798 * gtk_icon_view_get_model:
4799 * @icon_view: a #GtkIconView
4801 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4804 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4805 * currently being used.
4810 gtk_icon_view_get_model (GtkIconView *icon_view)
4812 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4814 return icon_view->priv->model;
4818 update_text_cell (GtkIconView *icon_view)
4820 if (!icon_view->priv->cell_area)
4823 if (icon_view->priv->text_column == -1 &&
4824 icon_view->priv->markup_column == -1)
4826 if (icon_view->priv->text_cell != NULL)
4828 gtk_cell_area_remove (icon_view->priv->cell_area,
4829 icon_view->priv->text_cell);
4830 icon_view->priv->text_cell = NULL;
4835 if (icon_view->priv->text_cell == NULL)
4837 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4839 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4842 if (icon_view->priv->markup_column != -1)
4843 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4844 icon_view->priv->text_cell,
4845 "markup", icon_view->priv->markup_column,
4848 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4849 icon_view->priv->text_cell,
4850 "text", icon_view->priv->text_column,
4853 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4854 g_object_set (icon_view->priv->text_cell,
4855 "alignment", PANGO_ALIGN_CENTER,
4856 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4861 g_object_set (icon_view->priv->text_cell,
4862 "alignment", PANGO_ALIGN_LEFT,
4863 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4871 update_pixbuf_cell (GtkIconView *icon_view)
4873 if (!icon_view->priv->cell_area)
4876 if (icon_view->priv->pixbuf_column == -1)
4878 if (icon_view->priv->pixbuf_cell != NULL)
4880 gtk_cell_area_remove (icon_view->priv->cell_area,
4881 icon_view->priv->pixbuf_cell);
4883 icon_view->priv->pixbuf_cell = NULL;
4888 if (icon_view->priv->pixbuf_cell == NULL)
4890 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4892 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4895 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4896 icon_view->priv->pixbuf_cell,
4897 "pixbuf", icon_view->priv->pixbuf_column,
4900 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4901 g_object_set (icon_view->priv->pixbuf_cell,
4906 g_object_set (icon_view->priv->pixbuf_cell,
4914 * gtk_icon_view_set_text_column:
4915 * @icon_view: A #GtkIconView.
4916 * @column: A column in the currently used model, or -1 to display no text
4918 * Sets the column with text for @icon_view to be @column. The text
4919 * column must be of type #G_TYPE_STRING.
4924 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4927 if (column == icon_view->priv->text_column)
4931 icon_view->priv->text_column = -1;
4934 if (icon_view->priv->model != NULL)
4938 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4940 g_return_if_fail (column_type == G_TYPE_STRING);
4943 icon_view->priv->text_column = column;
4946 if (icon_view->priv->cell_area)
4947 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4949 update_text_cell (icon_view);
4951 gtk_icon_view_invalidate_sizes (icon_view);
4953 g_object_notify (G_OBJECT (icon_view), "text-column");
4957 * gtk_icon_view_get_text_column:
4958 * @icon_view: A #GtkIconView.
4960 * Returns the column with text for @icon_view.
4962 * Returns: the text column, or -1 if it's unset.
4967 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4969 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4971 return icon_view->priv->text_column;
4975 * gtk_icon_view_set_markup_column:
4976 * @icon_view: A #GtkIconView.
4977 * @column: A column in the currently used model, or -1 to display no text
4979 * Sets the column with markup information for @icon_view to be
4980 * @column. The markup column must be of type #G_TYPE_STRING.
4981 * If the markup column is set to something, it overrides
4982 * the text column set by gtk_icon_view_set_text_column().
4987 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4990 if (column == icon_view->priv->markup_column)
4994 icon_view->priv->markup_column = -1;
4997 if (icon_view->priv->model != NULL)
5001 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5003 g_return_if_fail (column_type == G_TYPE_STRING);
5006 icon_view->priv->markup_column = column;
5009 if (icon_view->priv->cell_area)
5010 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5012 update_text_cell (icon_view);
5014 gtk_icon_view_invalidate_sizes (icon_view);
5016 g_object_notify (G_OBJECT (icon_view), "markup-column");
5020 * gtk_icon_view_get_markup_column:
5021 * @icon_view: A #GtkIconView.
5023 * Returns the column with markup text for @icon_view.
5025 * Returns: the markup column, or -1 if it's unset.
5030 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5032 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5034 return icon_view->priv->markup_column;
5038 * gtk_icon_view_set_pixbuf_column:
5039 * @icon_view: A #GtkIconView.
5040 * @column: A column in the currently used model, or -1 to disable
5042 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5043 * column must be of type #GDK_TYPE_PIXBUF
5048 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5051 if (column == icon_view->priv->pixbuf_column)
5055 icon_view->priv->pixbuf_column = -1;
5058 if (icon_view->priv->model != NULL)
5062 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5064 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5067 icon_view->priv->pixbuf_column = column;
5070 if (icon_view->priv->cell_area)
5071 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5073 update_pixbuf_cell (icon_view);
5075 gtk_icon_view_invalidate_sizes (icon_view);
5077 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5082 * gtk_icon_view_get_pixbuf_column:
5083 * @icon_view: A #GtkIconView.
5085 * Returns the column with pixbufs for @icon_view.
5087 * Returns: the pixbuf column, or -1 if it's unset.
5092 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5094 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5096 return icon_view->priv->pixbuf_column;
5100 * gtk_icon_view_select_path:
5101 * @icon_view: A #GtkIconView.
5102 * @path: The #GtkTreePath to be selected.
5104 * Selects the row at @path.
5109 gtk_icon_view_select_path (GtkIconView *icon_view,
5112 GtkIconViewItem *item = NULL;
5114 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5115 g_return_if_fail (icon_view->priv->model != NULL);
5116 g_return_if_fail (path != NULL);
5118 if (gtk_tree_path_get_depth (path) > 0)
5119 item = g_list_nth_data (icon_view->priv->items,
5120 gtk_tree_path_get_indices(path)[0]);
5123 _gtk_icon_view_select_item (icon_view, item);
5127 * gtk_icon_view_unselect_path:
5128 * @icon_view: A #GtkIconView.
5129 * @path: The #GtkTreePath to be unselected.
5131 * Unselects the row at @path.
5136 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5139 GtkIconViewItem *item;
5141 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5142 g_return_if_fail (icon_view->priv->model != NULL);
5143 g_return_if_fail (path != NULL);
5145 item = g_list_nth_data (icon_view->priv->items,
5146 gtk_tree_path_get_indices(path)[0]);
5151 _gtk_icon_view_unselect_item (icon_view, item);
5155 * gtk_icon_view_get_selected_items:
5156 * @icon_view: A #GtkIconView.
5158 * Creates a list of paths of all selected items. Additionally, if you are
5159 * planning on modifying the model after calling this function, you may
5160 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5161 * To do this, you can use gtk_tree_row_reference_new().
5163 * To free the return value, use:
5165 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5168 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5173 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5176 GList *selected = NULL;
5178 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5180 for (list = icon_view->priv->items; list != NULL; list = list->next)
5182 GtkIconViewItem *item = list->data;
5186 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5188 selected = g_list_prepend (selected, path);
5196 * gtk_icon_view_select_all:
5197 * @icon_view: A #GtkIconView.
5199 * Selects all the icons. @icon_view must has its selection mode set
5200 * to #GTK_SELECTION_MULTIPLE.
5205 gtk_icon_view_select_all (GtkIconView *icon_view)
5208 gboolean dirty = FALSE;
5210 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5212 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5215 for (items = icon_view->priv->items; items; items = items->next)
5217 GtkIconViewItem *item = items->data;
5219 if (!item->selected)
5222 item->selected = TRUE;
5223 gtk_icon_view_queue_draw_item (icon_view, item);
5228 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5232 * gtk_icon_view_unselect_all:
5233 * @icon_view: A #GtkIconView.
5235 * Unselects all the icons.
5240 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5242 gboolean dirty = FALSE;
5244 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5246 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5249 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5252 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5256 * gtk_icon_view_path_is_selected:
5257 * @icon_view: A #GtkIconView.
5258 * @path: A #GtkTreePath to check selection on.
5260 * Returns %TRUE if the icon pointed to by @path is currently
5261 * selected. If @path does not point to a valid location, %FALSE is returned.
5263 * Return value: %TRUE if @path is selected.
5268 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5271 GtkIconViewItem *item;
5273 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5274 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5275 g_return_val_if_fail (path != NULL, FALSE);
5277 item = g_list_nth_data (icon_view->priv->items,
5278 gtk_tree_path_get_indices(path)[0]);
5283 return item->selected;
5287 * gtk_icon_view_get_item_row:
5288 * @icon_view: a #GtkIconView
5289 * @path: the #GtkTreePath of the item
5291 * Gets the row in which the item @path is currently
5292 * displayed. Row numbers start at 0.
5294 * Returns: The row in which the item is displayed
5299 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5302 GtkIconViewItem *item;
5304 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5305 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5306 g_return_val_if_fail (path != NULL, -1);
5308 item = g_list_nth_data (icon_view->priv->items,
5309 gtk_tree_path_get_indices(path)[0]);
5318 * gtk_icon_view_get_item_column:
5319 * @icon_view: a #GtkIconView
5320 * @path: the #GtkTreePath of the item
5322 * Gets the column in which the item @path is currently
5323 * displayed. Column numbers start at 0.
5325 * Returns: The column in which the item is displayed
5330 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5333 GtkIconViewItem *item;
5335 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5336 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5337 g_return_val_if_fail (path != NULL, -1);
5339 item = g_list_nth_data (icon_view->priv->items,
5340 gtk_tree_path_get_indices(path)[0]);
5349 * gtk_icon_view_item_activated:
5350 * @icon_view: A #GtkIconView
5351 * @path: The #GtkTreePath to be activated
5353 * Activates the item determined by @path.
5358 gtk_icon_view_item_activated (GtkIconView *icon_view,
5361 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5362 g_return_if_fail (path != NULL);
5364 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5368 * gtk_icon_view_set_item_orientation:
5369 * @icon_view: a #GtkIconView
5370 * @orientation: the relative position of texts and icons
5372 * Sets the ::item-orientation property which determines whether the labels
5373 * are drawn beside the icons instead of below.
5378 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5379 GtkOrientation orientation)
5381 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5383 if (icon_view->priv->item_orientation != orientation)
5385 icon_view->priv->item_orientation = orientation;
5387 if (icon_view->priv->cell_area)
5389 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5390 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5391 icon_view->priv->item_orientation);
5393 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5396 gtk_icon_view_invalidate_sizes (icon_view);
5398 update_text_cell (icon_view);
5399 update_pixbuf_cell (icon_view);
5401 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5406 * gtk_icon_view_get_item_orientation:
5407 * @icon_view: a #GtkIconView
5409 * Returns the value of the ::item-orientation property which determines
5410 * whether the labels are drawn beside the icons instead of below.
5412 * Return value: the relative position of texts and icons
5417 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5419 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5420 GTK_ORIENTATION_VERTICAL);
5422 return icon_view->priv->item_orientation;
5426 * gtk_icon_view_set_columns:
5427 * @icon_view: a #GtkIconView
5428 * @columns: the number of columns
5430 * Sets the ::columns property which determines in how
5431 * many columns the icons are arranged. If @columns is
5432 * -1, the number of columns will be chosen automatically
5433 * to fill the available area.
5438 gtk_icon_view_set_columns (GtkIconView *icon_view,
5441 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5443 if (icon_view->priv->columns != columns)
5445 icon_view->priv->columns = columns;
5447 if (icon_view->priv->cell_area)
5448 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5450 gtk_icon_view_queue_layout (icon_view);
5452 g_object_notify (G_OBJECT (icon_view), "columns");
5457 * gtk_icon_view_get_columns:
5458 * @icon_view: a #GtkIconView
5460 * Returns the value of the ::columns property.
5462 * Return value: the number of columns, or -1
5467 gtk_icon_view_get_columns (GtkIconView *icon_view)
5469 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5471 return icon_view->priv->columns;
5475 * gtk_icon_view_set_item_width:
5476 * @icon_view: a #GtkIconView
5477 * @item_width: the width for each item
5479 * Sets the ::item-width property which specifies the width
5480 * to use for each item. If it is set to -1, the icon view will
5481 * automatically determine a suitable item size.
5486 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5489 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5491 if (icon_view->priv->item_width != item_width)
5493 icon_view->priv->item_width = item_width;
5495 if (icon_view->priv->cell_area)
5496 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5498 gtk_icon_view_invalidate_sizes (icon_view);
5500 update_text_cell (icon_view);
5502 g_object_notify (G_OBJECT (icon_view), "item-width");
5507 * gtk_icon_view_get_item_width:
5508 * @icon_view: a #GtkIconView
5510 * Returns the value of the ::item-width property.
5512 * Return value: the width of a single item, or -1
5517 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5519 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5521 return icon_view->priv->item_width;
5526 * gtk_icon_view_set_spacing:
5527 * @icon_view: a #GtkIconView
5528 * @spacing: the spacing
5530 * Sets the ::spacing property which specifies the space
5531 * which is inserted between the cells (i.e. the icon and
5532 * the text) of an item.
5537 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5540 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5542 if (icon_view->priv->spacing != spacing)
5544 icon_view->priv->spacing = spacing;
5546 if (icon_view->priv->cell_area)
5547 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5549 gtk_icon_view_invalidate_sizes (icon_view);
5551 g_object_notify (G_OBJECT (icon_view), "spacing");
5556 * gtk_icon_view_get_spacing:
5557 * @icon_view: a #GtkIconView
5559 * Returns the value of the ::spacing property.
5561 * Return value: the space between cells
5566 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5568 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5570 return icon_view->priv->spacing;
5574 * gtk_icon_view_set_row_spacing:
5575 * @icon_view: a #GtkIconView
5576 * @row_spacing: the row spacing
5578 * Sets the ::row-spacing property which specifies the space
5579 * which is inserted between the rows of the icon view.
5584 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5587 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5589 if (icon_view->priv->row_spacing != row_spacing)
5591 icon_view->priv->row_spacing = row_spacing;
5593 if (icon_view->priv->cell_area)
5594 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5596 gtk_icon_view_invalidate_sizes (icon_view);
5598 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5603 * gtk_icon_view_get_row_spacing:
5604 * @icon_view: a #GtkIconView
5606 * Returns the value of the ::row-spacing property.
5608 * Return value: the space between rows
5613 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5615 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5617 return icon_view->priv->row_spacing;
5621 * gtk_icon_view_set_column_spacing:
5622 * @icon_view: a #GtkIconView
5623 * @column_spacing: the column spacing
5625 * Sets the ::column-spacing property which specifies the space
5626 * which is inserted between the columns of the icon view.
5631 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5632 gint column_spacing)
5634 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5636 if (icon_view->priv->column_spacing != column_spacing)
5638 icon_view->priv->column_spacing = column_spacing;
5640 if (icon_view->priv->cell_area)
5641 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5643 gtk_icon_view_invalidate_sizes (icon_view);
5645 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5650 * gtk_icon_view_get_column_spacing:
5651 * @icon_view: a #GtkIconView
5653 * Returns the value of the ::column-spacing property.
5655 * Return value: the space between columns
5660 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5662 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5664 return icon_view->priv->column_spacing;
5668 * gtk_icon_view_set_margin:
5669 * @icon_view: a #GtkIconView
5670 * @margin: the margin
5672 * Sets the ::margin property which specifies the space
5673 * which is inserted at the top, bottom, left and right
5679 gtk_icon_view_set_margin (GtkIconView *icon_view,
5682 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5684 if (icon_view->priv->margin != margin)
5686 icon_view->priv->margin = margin;
5688 if (icon_view->priv->cell_area)
5689 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5691 gtk_icon_view_invalidate_sizes (icon_view);
5693 g_object_notify (G_OBJECT (icon_view), "margin");
5698 * gtk_icon_view_get_margin:
5699 * @icon_view: a #GtkIconView
5701 * Returns the value of the ::margin property.
5703 * Return value: the space at the borders
5708 gtk_icon_view_get_margin (GtkIconView *icon_view)
5710 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5712 return icon_view->priv->margin;
5716 * gtk_icon_view_set_item_padding:
5717 * @icon_view: a #GtkIconView
5718 * @item_padding: the item padding
5720 * Sets the #GtkIconView:item-padding property which specifies the padding
5721 * around each of the icon view's items.
5726 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5729 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5731 if (icon_view->priv->item_padding != item_padding)
5733 icon_view->priv->item_padding = item_padding;
5735 if (icon_view->priv->cell_area)
5736 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5738 gtk_icon_view_invalidate_sizes (icon_view);
5740 g_object_notify (G_OBJECT (icon_view), "item-padding");
5745 * gtk_icon_view_get_item_padding:
5746 * @icon_view: a #GtkIconView
5748 * Returns the value of the ::item-padding property.
5750 * Return value: the padding around items
5755 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5757 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5759 return icon_view->priv->item_padding;
5762 /* Get/set whether drag_motion requested the drag data and
5763 * drag_data_received should thus not actually insert the data,
5764 * since the data doesn't result from a drop.
5767 set_status_pending (GdkDragContext *context,
5768 GdkDragAction suggested_action)
5770 g_object_set_data (G_OBJECT (context),
5771 I_("gtk-icon-view-status-pending"),
5772 GINT_TO_POINTER (suggested_action));
5775 static GdkDragAction
5776 get_status_pending (GdkDragContext *context)
5778 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5779 "gtk-icon-view-status-pending"));
5783 unset_reorderable (GtkIconView *icon_view)
5785 if (icon_view->priv->reorderable)
5787 icon_view->priv->reorderable = FALSE;
5788 g_object_notify (G_OBJECT (icon_view), "reorderable");
5793 set_source_row (GdkDragContext *context,
5794 GtkTreeModel *model,
5795 GtkTreePath *source_row)
5798 g_object_set_data_full (G_OBJECT (context),
5799 I_("gtk-icon-view-source-row"),
5800 gtk_tree_row_reference_new (model, source_row),
5801 (GDestroyNotify) gtk_tree_row_reference_free);
5803 g_object_set_data_full (G_OBJECT (context),
5804 I_("gtk-icon-view-source-row"),
5809 get_source_row (GdkDragContext *context)
5811 GtkTreeRowReference *ref;
5813 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5816 return gtk_tree_row_reference_get_path (ref);
5823 GtkTreeRowReference *dest_row;
5824 gboolean empty_view_drop;
5825 gboolean drop_append_mode;
5829 dest_row_free (gpointer data)
5831 DestRow *dr = (DestRow *)data;
5833 gtk_tree_row_reference_free (dr->dest_row);
5838 set_dest_row (GdkDragContext *context,
5839 GtkTreeModel *model,
5840 GtkTreePath *dest_row,
5841 gboolean empty_view_drop,
5842 gboolean drop_append_mode)
5848 g_object_set_data_full (G_OBJECT (context),
5849 I_("gtk-icon-view-dest-row"),
5854 dr = g_new0 (DestRow, 1);
5856 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5857 dr->empty_view_drop = empty_view_drop;
5858 dr->drop_append_mode = drop_append_mode;
5859 g_object_set_data_full (G_OBJECT (context),
5860 I_("gtk-icon-view-dest-row"),
5861 dr, (GDestroyNotify) dest_row_free);
5865 get_dest_row (GdkDragContext *context)
5869 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5873 GtkTreePath *path = NULL;
5876 path = gtk_tree_row_reference_get_path (dr->dest_row);
5877 else if (dr->empty_view_drop)
5878 path = gtk_tree_path_new_from_indices (0, -1);
5882 if (path && dr->drop_append_mode)
5883 gtk_tree_path_next (path);
5892 check_model_dnd (GtkTreeModel *model,
5893 GType required_iface,
5894 const gchar *signal)
5896 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5898 g_warning ("You must override the default '%s' handler "
5899 "on GtkIconView when using models that don't support "
5900 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5901 "is to connect to '%s' and call "
5902 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5903 "the default handler from running. Look at the source code "
5904 "for the default handler in gtkiconview.c to get an idea what "
5905 "your handler should do. (gtkiconview.c is in the GTK+ source "
5906 "code.) If you're using GTK+ from a language other than C, "
5907 "there may be a more natural way to override default handlers, e.g. via derivation.",
5908 signal, g_type_name (required_iface), signal);
5916 remove_scroll_timeout (GtkIconView *icon_view)
5918 if (icon_view->priv->scroll_timeout_id != 0)
5920 g_source_remove (icon_view->priv->scroll_timeout_id);
5922 icon_view->priv->scroll_timeout_id = 0;
5927 gtk_icon_view_autoscroll (GtkIconView *icon_view,
5931 gint px, py, width, height;
5932 gint hoffset, voffset;
5934 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5936 gdk_window_get_device_position (window, device, &px, &py, NULL);
5937 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
5939 /* see if we are near the edge. */
5940 voffset = py - 2 * SCROLL_EDGE_SIZE;
5942 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
5944 hoffset = px - 2 * SCROLL_EDGE_SIZE;
5946 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
5949 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5950 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5953 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5954 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5958 GtkIconView *icon_view;
5963 drag_scroll_timeout (gpointer datap)
5965 DragScrollData *data = datap;
5967 gtk_icon_view_autoscroll (data->icon_view, data->device);
5973 drag_scroll_data_free (DragScrollData *data)
5975 g_slice_free (DragScrollData, data);
5979 set_destination (GtkIconView *icon_view,
5980 GdkDragContext *context,
5983 GdkDragAction *suggested_action,
5987 GtkTreePath *path = NULL;
5988 GtkIconViewDropPosition pos;
5989 GtkIconViewDropPosition old_pos;
5990 GtkTreePath *old_dest_path = NULL;
5991 gboolean can_drop = FALSE;
5993 widget = GTK_WIDGET (icon_view);
5995 *suggested_action = 0;
5998 if (!icon_view->priv->dest_set)
6000 /* someone unset us as a drag dest, note that if
6001 * we return FALSE drag_leave isn't called
6004 gtk_icon_view_set_drag_dest_item (icon_view,
6006 GTK_ICON_VIEW_DROP_LEFT);
6008 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6010 return FALSE; /* no longer a drop site */
6013 *target = gtk_drag_dest_find_target (widget, context,
6014 gtk_drag_dest_get_target_list (widget));
6015 if (*target == GDK_NONE)
6018 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6021 GtkTreeModel *model;
6023 /* the row got dropped on empty space, let's setup a special case
6027 gtk_tree_path_free (path);
6029 model = gtk_icon_view_get_model (icon_view);
6031 n_children = gtk_tree_model_iter_n_children (model, NULL);
6034 pos = GTK_ICON_VIEW_DROP_BELOW;
6035 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6039 pos = GTK_ICON_VIEW_DROP_ABOVE;
6040 path = gtk_tree_path_new_from_indices (0, -1);
6050 gtk_icon_view_get_drag_dest_item (icon_view,
6055 gtk_tree_path_free (old_dest_path);
6057 if (TRUE /* FIXME if the location droppable predicate */)
6065 GtkWidget *source_widget;
6067 *suggested_action = gdk_drag_context_get_suggested_action (context);
6068 source_widget = gtk_drag_get_source_widget (context);
6070 if (source_widget == widget)
6072 /* Default to MOVE, unless the user has
6073 * pressed ctrl or shift to affect available actions
6075 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6076 *suggested_action = GDK_ACTION_MOVE;
6079 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6084 /* can't drop here */
6085 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6087 GTK_ICON_VIEW_DROP_LEFT);
6091 gtk_tree_path_free (path);
6097 get_logical_destination (GtkIconView *icon_view,
6098 gboolean *drop_append_mode)
6100 /* adjust path to point to the row the drop goes in front of */
6101 GtkTreePath *path = NULL;
6102 GtkIconViewDropPosition pos;
6104 *drop_append_mode = FALSE;
6106 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6111 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6112 pos == GTK_ICON_VIEW_DROP_BELOW)
6115 GtkTreeModel *model = icon_view->priv->model;
6117 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6118 !gtk_tree_model_iter_next (model, &iter))
6119 *drop_append_mode = TRUE;
6122 *drop_append_mode = FALSE;
6123 gtk_tree_path_next (path);
6131 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6132 GdkEventMotion *event)
6134 GtkWidget *widget = GTK_WIDGET (icon_view);
6135 GdkDragContext *context;
6136 GtkTreePath *path = NULL;
6138 GtkTreeModel *model;
6139 gboolean retval = FALSE;
6141 if (!icon_view->priv->source_set)
6144 if (icon_view->priv->pressed_button < 0)
6147 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6148 icon_view->priv->press_start_x,
6149 icon_view->priv->press_start_y,
6150 event->x, event->y))
6153 model = gtk_icon_view_get_model (icon_view);
6158 button = icon_view->priv->pressed_button;
6159 icon_view->priv->pressed_button = -1;
6161 path = gtk_icon_view_get_path_at_pos (icon_view,
6162 icon_view->priv->press_start_x,
6163 icon_view->priv->press_start_y);
6168 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6169 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6173 /* FIXME Check whether we're a start button, if not return FALSE and
6177 /* Now we can begin the drag */
6181 context = gtk_drag_begin (widget,
6182 gtk_drag_source_get_target_list (widget),
6183 icon_view->priv->source_actions,
6187 set_source_row (context, model, path);
6191 gtk_tree_path_free (path);
6196 /* Source side drag signals */
6198 gtk_icon_view_drag_begin (GtkWidget *widget,
6199 GdkDragContext *context)
6201 GtkIconView *icon_view;
6202 GtkIconViewItem *item;
6203 cairo_surface_t *icon;
6207 icon_view = GTK_ICON_VIEW (widget);
6209 /* if the user uses a custom DnD impl, we don't set the icon here */
6210 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6213 item = _gtk_icon_view_get_item_at_coords (icon_view,
6214 icon_view->priv->press_start_x,
6215 icon_view->priv->press_start_y,
6219 g_return_if_fail (item != NULL);
6221 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6222 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6224 path = gtk_tree_path_new_from_indices (item->index, -1);
6225 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6226 gtk_tree_path_free (path);
6228 cairo_surface_set_device_offset (icon, -x, -y);
6230 gtk_drag_set_icon_surface (context, icon);
6232 cairo_surface_destroy (icon);
6236 gtk_icon_view_drag_end (GtkWidget *widget,
6237 GdkDragContext *context)
6243 gtk_icon_view_drag_data_get (GtkWidget *widget,
6244 GdkDragContext *context,
6245 GtkSelectionData *selection_data,
6249 GtkIconView *icon_view;
6250 GtkTreeModel *model;
6251 GtkTreePath *source_row;
6253 icon_view = GTK_ICON_VIEW (widget);
6254 model = gtk_icon_view_get_model (icon_view);
6259 if (!icon_view->priv->source_set)
6262 source_row = get_source_row (context);
6264 if (source_row == NULL)
6267 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6268 * any model; for DragSource models there are some other targets
6272 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6273 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6278 /* If drag_data_get does nothing, try providing row data. */
6279 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6280 gtk_tree_set_row_drag_data (selection_data,
6285 gtk_tree_path_free (source_row);
6289 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6290 GdkDragContext *context)
6292 GtkTreeModel *model;
6293 GtkIconView *icon_view;
6294 GtkTreePath *source_row;
6296 icon_view = GTK_ICON_VIEW (widget);
6297 model = gtk_icon_view_get_model (icon_view);
6299 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6302 if (!icon_view->priv->source_set)
6305 source_row = get_source_row (context);
6307 if (source_row == NULL)
6310 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6313 gtk_tree_path_free (source_row);
6315 set_source_row (context, NULL, NULL);
6318 /* Target side drag signals */
6320 gtk_icon_view_drag_leave (GtkWidget *widget,
6321 GdkDragContext *context,
6324 GtkIconView *icon_view;
6326 icon_view = GTK_ICON_VIEW (widget);
6328 /* unset any highlight row */
6329 gtk_icon_view_set_drag_dest_item (icon_view,
6331 GTK_ICON_VIEW_DROP_LEFT);
6333 remove_scroll_timeout (icon_view);
6337 gtk_icon_view_drag_motion (GtkWidget *widget,
6338 GdkDragContext *context,
6343 GtkTreePath *path = NULL;
6344 GtkIconViewDropPosition pos;
6345 GtkIconView *icon_view;
6346 GdkDragAction suggested_action = 0;
6350 icon_view = GTK_ICON_VIEW (widget);
6352 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6355 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6357 /* we only know this *after* set_desination_row */
6358 empty = icon_view->priv->empty_view_drop;
6360 if (path == NULL && !empty)
6362 /* Can't drop here. */
6363 gdk_drag_status (context, 0, time);
6367 if (icon_view->priv->scroll_timeout_id == 0)
6369 DragScrollData *data = g_slice_new (DragScrollData);
6370 data->icon_view = icon_view;
6371 data->device = gdk_drag_context_get_device (context);
6373 icon_view->priv->scroll_timeout_id =
6374 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6377 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6379 /* Request data so we can use the source row when
6380 * determining whether to accept the drop
6382 set_status_pending (context, suggested_action);
6383 gtk_drag_get_data (widget, context, target, time);
6387 set_status_pending (context, 0);
6388 gdk_drag_status (context, suggested_action, time);
6393 gtk_tree_path_free (path);
6399 gtk_icon_view_drag_drop (GtkWidget *widget,
6400 GdkDragContext *context,
6405 GtkIconView *icon_view;
6407 GdkDragAction suggested_action = 0;
6408 GdkAtom target = GDK_NONE;
6409 GtkTreeModel *model;
6410 gboolean drop_append_mode;
6412 icon_view = GTK_ICON_VIEW (widget);
6413 model = gtk_icon_view_get_model (icon_view);
6415 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6417 if (!icon_view->priv->dest_set)
6420 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6423 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6426 path = get_logical_destination (icon_view, &drop_append_mode);
6428 if (target != GDK_NONE && path != NULL)
6430 /* in case a motion had requested drag data, change things so we
6431 * treat drag data receives as a drop.
6433 set_status_pending (context, 0);
6434 set_dest_row (context, model, path,
6435 icon_view->priv->empty_view_drop, drop_append_mode);
6439 gtk_tree_path_free (path);
6441 /* Unset this thing */
6442 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6444 if (target != GDK_NONE)
6446 gtk_drag_get_data (widget, context, target, time);
6454 gtk_icon_view_drag_data_received (GtkWidget *widget,
6455 GdkDragContext *context,
6458 GtkSelectionData *selection_data,
6463 gboolean accepted = FALSE;
6464 GtkTreeModel *model;
6465 GtkIconView *icon_view;
6466 GtkTreePath *dest_row;
6467 GdkDragAction suggested_action;
6468 gboolean drop_append_mode;
6470 icon_view = GTK_ICON_VIEW (widget);
6471 model = gtk_icon_view_get_model (icon_view);
6473 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6476 if (!icon_view->priv->dest_set)
6479 suggested_action = get_status_pending (context);
6481 if (suggested_action)
6483 /* We are getting this data due to a request in drag_motion,
6484 * rather than due to a request in drag_drop, so we are just
6485 * supposed to call drag_status, not actually paste in the
6488 path = get_logical_destination (icon_view, &drop_append_mode);
6491 suggested_action = 0;
6493 if (suggested_action)
6495 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6498 suggested_action = 0;
6501 gdk_drag_status (context, suggested_action, time);
6504 gtk_tree_path_free (path);
6506 /* If you can't drop, remove user drop indicator until the next motion */
6507 if (suggested_action == 0)
6508 gtk_icon_view_set_drag_dest_item (icon_view,
6510 GTK_ICON_VIEW_DROP_LEFT);
6515 dest_row = get_dest_row (context);
6517 if (dest_row == NULL)
6520 if (gtk_selection_data_get_length (selection_data) >= 0)
6522 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6528 gtk_drag_finish (context,
6530 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6533 gtk_tree_path_free (dest_row);
6536 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6539 /* Drag-and-Drop support */
6541 * gtk_icon_view_enable_model_drag_source:
6542 * @icon_view: a #GtkIconTreeView
6543 * @start_button_mask: Mask of allowed buttons to start drag
6544 * @targets: (array length=n_targets): the table of targets that the drag will
6546 * @n_targets: the number of items in @targets
6547 * @actions: the bitmask of possible actions for a drag from this
6550 * Turns @icon_view into a drag source for automatic DND. Calling this
6551 * method sets #GtkIconView:reorderable to %FALSE.
6556 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6557 GdkModifierType start_button_mask,
6558 const GtkTargetEntry *targets,
6560 GdkDragAction actions)
6562 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6564 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6566 icon_view->priv->start_button_mask = start_button_mask;
6567 icon_view->priv->source_actions = actions;
6569 icon_view->priv->source_set = TRUE;
6571 unset_reorderable (icon_view);
6575 * gtk_icon_view_enable_model_drag_dest:
6576 * @icon_view: a #GtkIconView
6577 * @targets: (array length=n_targets): the table of targets that the drag will
6579 * @n_targets: the number of items in @targets
6580 * @actions: the bitmask of possible actions for a drag to this
6583 * Turns @icon_view into a drop destination for automatic DND. Calling this
6584 * method sets #GtkIconView:reorderable to %FALSE.
6589 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6590 const GtkTargetEntry *targets,
6592 GdkDragAction actions)
6594 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6596 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6598 icon_view->priv->dest_actions = actions;
6600 icon_view->priv->dest_set = TRUE;
6602 unset_reorderable (icon_view);
6606 * gtk_icon_view_unset_model_drag_source:
6607 * @icon_view: a #GtkIconView
6609 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6610 * method sets #GtkIconView:reorderable to %FALSE.
6615 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6617 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6619 if (icon_view->priv->source_set)
6621 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6622 icon_view->priv->source_set = FALSE;
6625 unset_reorderable (icon_view);
6629 * gtk_icon_view_unset_model_drag_dest:
6630 * @icon_view: a #GtkIconView
6632 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6633 * method sets #GtkIconView:reorderable to %FALSE.
6638 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6640 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6642 if (icon_view->priv->dest_set)
6644 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6645 icon_view->priv->dest_set = FALSE;
6648 unset_reorderable (icon_view);
6651 /* These are useful to implement your own custom stuff. */
6653 * gtk_icon_view_set_drag_dest_item:
6654 * @icon_view: a #GtkIconView
6655 * @path: (allow-none): The path of the item to highlight, or %NULL.
6656 * @pos: Specifies where to drop, relative to the item
6658 * Sets the item that is highlighted for feedback.
6663 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6665 GtkIconViewDropPosition pos)
6667 /* Note; this function is exported to allow a custom DND
6668 * implementation, so it can't touch TreeViewDragInfo
6671 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6673 if (icon_view->priv->dest_item)
6675 GtkTreePath *current_path;
6676 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6677 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6678 icon_view->priv->dest_item = NULL;
6680 gtk_icon_view_queue_draw_path (icon_view, current_path);
6681 gtk_tree_path_free (current_path);
6684 /* special case a drop on an empty model */
6685 icon_view->priv->empty_view_drop = FALSE;
6686 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6687 && gtk_tree_path_get_depth (path) == 1
6688 && gtk_tree_path_get_indices (path)[0] == 0)
6692 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6695 if (n_children == 0)
6696 icon_view->priv->empty_view_drop = TRUE;
6699 icon_view->priv->dest_pos = pos;
6703 icon_view->priv->dest_item =
6704 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6705 icon_view->priv->model, path);
6707 gtk_icon_view_queue_draw_path (icon_view, path);
6712 * gtk_icon_view_get_drag_dest_item:
6713 * @icon_view: a #GtkIconView
6714 * @path: (out) (allow-none): Return location for the path of
6715 * the highlighted item, or %NULL.
6716 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6718 * Gets information about the item that is highlighted for feedback.
6723 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6725 GtkIconViewDropPosition *pos)
6727 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6731 if (icon_view->priv->dest_item)
6732 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6738 *pos = icon_view->priv->dest_pos;
6742 * gtk_icon_view_get_dest_item_at_pos:
6743 * @icon_view: a #GtkIconView
6744 * @drag_x: the position to determine the destination item for
6745 * @drag_y: the position to determine the destination item for
6746 * @path: (out) (allow-none): Return location for the path of the item,
6748 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6750 * Determines the destination item for a given position.
6752 * Return value: whether there is an item at the given position.
6757 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6761 GtkIconViewDropPosition *pos)
6763 GtkIconViewItem *item;
6765 /* Note; this function is exported to allow a custom DND
6766 * implementation, so it can't touch TreeViewDragInfo
6769 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6770 g_return_val_if_fail (drag_x >= 0, FALSE);
6771 g_return_val_if_fail (drag_y >= 0, FALSE);
6772 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6778 item = _gtk_icon_view_get_item_at_coords (icon_view,
6779 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6780 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6787 *path = gtk_tree_path_new_from_indices (item->index, -1);
6791 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6792 *pos = GTK_ICON_VIEW_DROP_LEFT;
6793 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6794 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6795 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6796 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6797 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6798 *pos = GTK_ICON_VIEW_DROP_BELOW;
6800 *pos = GTK_ICON_VIEW_DROP_INTO;
6807 * gtk_icon_view_create_drag_icon:
6808 * @icon_view: a #GtkIconView
6809 * @path: a #GtkTreePath in @icon_view
6811 * Creates a #cairo_surface_t representation of the item at @path.
6812 * This image is used for a drag icon.
6814 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6819 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6823 GtkStyleContext *context;
6825 cairo_surface_t *surface;
6829 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6830 g_return_val_if_fail (path != NULL, NULL);
6832 widget = GTK_WIDGET (icon_view);
6833 context = gtk_widget_get_style_context (widget);
6835 if (!gtk_widget_get_realized (widget))
6838 index = gtk_tree_path_get_indices (path)[0];
6840 for (l = icon_view->priv->items; l; l = l->next)
6842 GtkIconViewItem *item = l->data;
6844 if (index == item->index)
6846 GdkRectangle rect = {
6847 item->cell_area.x - icon_view->priv->item_padding,
6848 item->cell_area.y - icon_view->priv->item_padding,
6849 item->cell_area.width + icon_view->priv->item_padding * 2,
6850 item->cell_area.height + icon_view->priv->item_padding * 2
6853 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6854 CAIRO_CONTENT_COLOR,
6858 cr = cairo_create (surface);
6859 cairo_set_line_width (cr, 1.);
6861 gtk_render_background (context, cr, 0, 0,
6862 rect.width + 2, rect.height + 2);
6866 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6869 gtk_icon_view_paint_item (icon_view, cr, item,
6870 icon_view->priv->item_padding + 1,
6871 icon_view->priv->item_padding + 1, FALSE);
6875 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6876 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6889 * gtk_icon_view_get_reorderable:
6890 * @icon_view: a #GtkIconView
6892 * Retrieves whether the user can reorder the list via drag-and-drop.
6893 * See gtk_icon_view_set_reorderable().
6895 * Return value: %TRUE if the list can be reordered.
6900 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6902 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6904 return icon_view->priv->reorderable;
6907 static const GtkTargetEntry item_targets[] = {
6908 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6913 * gtk_icon_view_set_reorderable:
6914 * @icon_view: A #GtkIconView.
6915 * @reorderable: %TRUE, if the list of items can be reordered.
6917 * This function is a convenience function to allow you to reorder models that
6918 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6919 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6920 * the user can reorder the model by dragging and dropping rows. The
6921 * developer can listen to these changes by connecting to the model's
6922 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6923 * the icon view as a drag source and destination. Therefore, drag and
6924 * drop can not be used in a reorderable view for any other purpose.
6926 * This function does not give you any degree of control over the order -- any
6927 * reordering is allowed. If more control is needed, you should probably
6928 * handle drag and drop manually.
6933 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6934 gboolean reorderable)
6936 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6938 reorderable = reorderable != FALSE;
6940 if (icon_view->priv->reorderable == reorderable)
6945 gtk_icon_view_enable_model_drag_source (icon_view,
6948 G_N_ELEMENTS (item_targets),
6950 gtk_icon_view_enable_model_drag_dest (icon_view,
6952 G_N_ELEMENTS (item_targets),
6957 gtk_icon_view_unset_model_drag_source (icon_view);
6958 gtk_icon_view_unset_model_drag_dest (icon_view);
6961 icon_view->priv->reorderable = reorderable;
6963 g_object_notify (G_OBJECT (icon_view), "reorderable");
6967 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
6968 GtkBuilder *builder,
6970 const gchar *tagname,
6971 GMarkupParser *parser,
6974 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
6975 tagname, parser, data))
6978 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
6979 tagname, parser, data);
6983 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
6984 GtkBuilder *builder,
6986 const gchar *tagname,
6989 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
6990 child, tagname, data))
6991 parent_buildable_iface->custom_tag_end (buildable, builder,
6992 child, tagname, data);