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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "gtkiconview.h"
25 #include "gtkiconviewprivate.h"
27 #include "gtkcelllayout.h"
28 #include "gtkcellrenderer.h"
29 #include "gtkcellareabox.h"
30 #include "gtkcellareacontext.h"
31 #include "gtkcellrenderertext.h"
32 #include "gtkcellrendererpixbuf.h"
33 #include "gtkorientable.h"
34 #include "gtkmarshalers.h"
35 #include "gtkbindings.h"
39 #include "gtkaccessible.h"
40 #include "gtkwindow.h"
42 #include "gtkcombobox.h"
43 #include "gtkscrollable.h"
44 #include "gtksizerequest.h"
45 #include "gtktreednd.h"
46 #include "gtktypebuiltins.h"
47 #include "gtkprivate.h"
48 #include "a11y/gtkiconviewaccessible.h"
53 * @short_description: A widget which displays a list of icons in a grid
55 * #GtkIconView provides an alternative view on a #GtkTreeModel.
56 * It displays the model as a grid of icons with labels. Like
57 * #GtkTreeView, it allows to select one or multiple items
58 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
59 * In addition to selection with the arrow keys, #GtkIconView supports
60 * rubberband selection, which is controlled by dragging the pointer.
62 * Note that if the tree model is backed by an actual tree store (as
63 * opposed to a flat list where the mapping to icons is obvious),
64 * #GtkIconView will only display the first level of the tree and
65 * ignore the tree's branches.
68 #define SCROLL_EDGE_SIZE 15
70 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
72 typedef struct _GtkIconViewChild GtkIconViewChild;
73 struct _GtkIconViewChild
101 PROP_ITEM_ORIENTATION,
114 /* For scrollable interface */
122 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
123 static void gtk_icon_view_dispose (GObject *object);
124 static GObject *gtk_icon_view_constructor (GType type,
125 guint n_construct_properties,
126 GObjectConstructParam *construct_properties);
127 static void gtk_icon_view_set_property (GObject *object,
131 static void gtk_icon_view_get_property (GObject *object,
135 /* GtkWidget vfuncs */
136 static void gtk_icon_view_destroy (GtkWidget *widget);
137 static void gtk_icon_view_realize (GtkWidget *widget);
138 static void gtk_icon_view_unrealize (GtkWidget *widget);
139 static void gtk_icon_view_style_updated (GtkWidget *widget);
140 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
141 GtkStateFlags previous_state);
142 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
145 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
148 static void gtk_icon_view_size_allocate (GtkWidget *widget,
149 GtkAllocation *allocation);
150 static gboolean gtk_icon_view_draw (GtkWidget *widget,
152 static gboolean gtk_icon_view_motion (GtkWidget *widget,
153 GdkEventMotion *event);
154 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
155 GdkEventButton *event);
156 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
157 GdkEventButton *event);
158 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
160 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
164 /* GtkContainer vfuncs */
165 static void gtk_icon_view_remove (GtkContainer *container,
167 static void gtk_icon_view_forall (GtkContainer *container,
168 gboolean include_internals,
169 GtkCallback callback,
170 gpointer callback_data);
172 /* GtkIconView vfuncs */
173 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
174 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
175 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
176 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
177 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
179 /* Internal functions */
180 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
181 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
182 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
183 GtkAdjustment *adjustment);
184 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
185 GtkAdjustment *adjustment);
186 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
187 GtkIconView *icon_view);
188 static void gtk_icon_view_layout (GtkIconView *icon_view);
189 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
191 GtkIconViewItem *item,
194 gboolean draw_focus);
195 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
197 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
199 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
200 GtkIconViewItem *item);
201 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
202 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
206 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
207 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
208 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
209 GtkIconViewItem *item,
214 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
215 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
216 static void gtk_icon_view_update_rubberband (gpointer data);
217 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
218 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
219 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
222 GtkMovementStep step,
224 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
225 GtkMovementStep step,
227 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
229 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
231 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
233 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
235 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
236 GtkIconViewItem *item);
237 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
238 GtkIconViewItem *anchor,
239 GtkIconViewItem *cursor);
241 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
242 GtkCellArea *cell_area);
244 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
246 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
247 GtkIconViewItem *item);
249 static void gtk_icon_view_add_editable (GtkCellArea *area,
250 GtkCellRenderer *renderer,
251 GtkCellEditable *editable,
252 GdkRectangle *cell_area,
254 GtkIconView *icon_view);
255 static void gtk_icon_view_remove_editable (GtkCellArea *area,
256 GtkCellRenderer *renderer,
257 GtkCellEditable *editable,
258 GtkIconView *icon_view);
259 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
261 GtkIconView *icon_view);
262 static void update_text_cell (GtkIconView *icon_view);
263 static void update_pixbuf_cell (GtkIconView *icon_view);
265 /* Source side drag signals */
266 static void gtk_icon_view_drag_begin (GtkWidget *widget,
267 GdkDragContext *context);
268 static void gtk_icon_view_drag_end (GtkWidget *widget,
269 GdkDragContext *context);
270 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
271 GdkDragContext *context,
272 GtkSelectionData *selection_data,
275 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
276 GdkDragContext *context);
278 /* Target side drag signals */
279 static void gtk_icon_view_drag_leave (GtkWidget *widget,
280 GdkDragContext *context,
282 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
283 GdkDragContext *context,
287 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
288 GdkDragContext *context,
292 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
293 GdkDragContext *context,
296 GtkSelectionData *selection_data,
299 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
300 GdkEventMotion *event);
302 static void remove_scroll_timeout (GtkIconView *icon_view);
305 static GtkBuildableIface *parent_buildable_iface;
306 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
307 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
310 const gchar *tagname,
311 GMarkupParser *parser,
313 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
316 const gchar *tagname,
319 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
321 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
322 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
323 gtk_icon_view_cell_layout_init)
324 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
325 gtk_icon_view_buildable_init)
326 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
329 gtk_icon_view_class_init (GtkIconViewClass *klass)
331 GObjectClass *gobject_class;
332 GtkWidgetClass *widget_class;
333 GtkContainerClass *container_class;
334 GtkBindingSet *binding_set;
336 binding_set = gtk_binding_set_by_class (klass);
338 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
340 gobject_class = (GObjectClass *) klass;
341 widget_class = (GtkWidgetClass *) klass;
342 container_class = (GtkContainerClass *) klass;
344 gobject_class->constructor = gtk_icon_view_constructor;
345 gobject_class->dispose = gtk_icon_view_dispose;
346 gobject_class->set_property = gtk_icon_view_set_property;
347 gobject_class->get_property = gtk_icon_view_get_property;
349 widget_class->destroy = gtk_icon_view_destroy;
350 widget_class->realize = gtk_icon_view_realize;
351 widget_class->unrealize = gtk_icon_view_unrealize;
352 widget_class->style_updated = gtk_icon_view_style_updated;
353 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
354 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
355 widget_class->size_allocate = gtk_icon_view_size_allocate;
356 widget_class->draw = gtk_icon_view_draw;
357 widget_class->motion_notify_event = gtk_icon_view_motion;
358 widget_class->button_press_event = gtk_icon_view_button_press;
359 widget_class->button_release_event = gtk_icon_view_button_release;
360 widget_class->key_press_event = gtk_icon_view_key_press;
361 widget_class->key_release_event = gtk_icon_view_key_release;
362 widget_class->drag_begin = gtk_icon_view_drag_begin;
363 widget_class->drag_end = gtk_icon_view_drag_end;
364 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
365 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
366 widget_class->drag_leave = gtk_icon_view_drag_leave;
367 widget_class->drag_motion = gtk_icon_view_drag_motion;
368 widget_class->drag_drop = gtk_icon_view_drag_drop;
369 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
370 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
372 container_class->remove = gtk_icon_view_remove;
373 container_class->forall = gtk_icon_view_forall;
375 klass->select_all = gtk_icon_view_real_select_all;
376 klass->unselect_all = gtk_icon_view_real_unselect_all;
377 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
378 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
379 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
380 klass->move_cursor = gtk_icon_view_real_move_cursor;
384 * GtkIconView:selection-mode:
386 * The ::selection-mode property specifies the selection mode of
387 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
388 * is enabled, for the other modes, only keyboard selection is possible.
392 g_object_class_install_property (gobject_class,
394 g_param_spec_enum ("selection-mode",
395 P_("Selection mode"),
396 P_("The selection mode"),
397 GTK_TYPE_SELECTION_MODE,
398 GTK_SELECTION_SINGLE,
399 GTK_PARAM_READWRITE));
402 * GtkIconView:pixbuf-column:
404 * The ::pixbuf-column property contains the number of the model column
405 * containing the pixbufs which are displayed. The pixbuf column must be
406 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
407 * display of pixbufs.
411 g_object_class_install_property (gobject_class,
413 g_param_spec_int ("pixbuf-column",
415 P_("Model column used to retrieve the icon pixbuf from"),
417 GTK_PARAM_READWRITE));
420 * GtkIconView:text-column:
422 * The ::text-column property contains the number of the model column
423 * containing the texts which are displayed. The text column must be
424 * of type #G_TYPE_STRING. If this property and the :markup-column
425 * property are both set to -1, no texts are displayed.
429 g_object_class_install_property (gobject_class,
431 g_param_spec_int ("text-column",
433 P_("Model column used to retrieve the text from"),
435 GTK_PARAM_READWRITE));
439 * GtkIconView:markup-column:
441 * The ::markup-column property contains the number of the model column
442 * containing markup information to be displayed. The markup column must be
443 * of type #G_TYPE_STRING. If this property and the :text-column property
444 * are both set to column numbers, it overrides the text column.
445 * If both are set to -1, no texts are displayed.
449 g_object_class_install_property (gobject_class,
451 g_param_spec_int ("markup-column",
453 P_("Model column used to retrieve the text if using Pango markup"),
455 GTK_PARAM_READWRITE));
457 g_object_class_install_property (gobject_class,
459 g_param_spec_object ("model",
460 P_("Icon View Model"),
461 P_("The model for the icon view"),
463 GTK_PARAM_READWRITE));
466 * GtkIconView:columns:
468 * The columns property contains the number of the columns in which the
469 * items should be displayed. If it is -1, the number of columns will
470 * be chosen automatically to fill the available area.
474 g_object_class_install_property (gobject_class,
476 g_param_spec_int ("columns",
477 P_("Number of columns"),
478 P_("Number of columns to display"),
480 GTK_PARAM_READWRITE));
484 * GtkIconView:item-width:
486 * The item-width property specifies the width to use for each item.
487 * If it is set to -1, the icon view will automatically determine a
488 * suitable item size.
492 g_object_class_install_property (gobject_class,
494 g_param_spec_int ("item-width",
495 P_("Width for each item"),
496 P_("The width used for each item"),
498 GTK_PARAM_READWRITE));
501 * GtkIconView:spacing:
503 * The spacing property specifies the space which is inserted between
504 * the cells (i.e. the icon and the text) of an item.
508 g_object_class_install_property (gobject_class,
510 g_param_spec_int ("spacing",
512 P_("Space which is inserted between cells of an item"),
514 GTK_PARAM_READWRITE));
517 * GtkIconView:row-spacing:
519 * The row-spacing property specifies the space which is inserted between
520 * the rows of the icon view.
524 g_object_class_install_property (gobject_class,
526 g_param_spec_int ("row-spacing",
528 P_("Space which is inserted between grid rows"),
530 GTK_PARAM_READWRITE));
533 * GtkIconView:column-spacing:
535 * The column-spacing property specifies the space which is inserted between
536 * the columns of the icon view.
540 g_object_class_install_property (gobject_class,
542 g_param_spec_int ("column-spacing",
543 P_("Column Spacing"),
544 P_("Space which is inserted between grid columns"),
546 GTK_PARAM_READWRITE));
549 * GtkIconView:margin:
551 * The margin property specifies the space which is inserted
552 * at the edges of the icon view.
556 g_object_class_install_property (gobject_class,
558 g_param_spec_int ("margin",
560 P_("Space which is inserted at the edges of the icon view"),
562 GTK_PARAM_READWRITE));
565 * GtkIconView:item-orientation:
567 * The item-orientation property specifies how the cells (i.e. the icon and
568 * the text) of the item are positioned relative to each other.
572 g_object_class_install_property (gobject_class,
573 PROP_ITEM_ORIENTATION,
574 g_param_spec_enum ("item-orientation",
575 P_("Item Orientation"),
576 P_("How the text and icon of each item are positioned relative to each other"),
577 GTK_TYPE_ORIENTATION,
578 GTK_ORIENTATION_VERTICAL,
579 GTK_PARAM_READWRITE));
582 * GtkIconView:reorderable:
584 * The reorderable property specifies if the items can be reordered
589 g_object_class_install_property (gobject_class,
591 g_param_spec_boolean ("reorderable",
593 P_("View is reorderable"),
597 g_object_class_install_property (gobject_class,
599 g_param_spec_int ("tooltip-column",
600 P_("Tooltip Column"),
601 P_("The column in the model containing the tooltip texts for the items"),
605 GTK_PARAM_READWRITE));
608 * GtkIconView:item-padding:
610 * The item-padding property specifies the padding around each
611 * of the icon view's item.
615 g_object_class_install_property (gobject_class,
617 g_param_spec_int ("item-padding",
619 P_("Padding around icon view items"),
621 GTK_PARAM_READWRITE));
624 * GtkIconView:cell-area:
626 * The #GtkCellArea used to layout cell renderers for this view.
628 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
629 * a #GtkCellAreaBox will be used.
633 g_object_class_install_property (gobject_class,
635 g_param_spec_object ("cell-area",
637 P_("The GtkCellArea used to layout cells"),
639 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
641 /* Scrollable interface properties */
642 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
643 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
644 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
645 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
647 /* Style properties */
648 gtk_widget_class_install_style_property (widget_class,
649 g_param_spec_boxed ("selection-box-color",
650 P_("Selection Box Color"),
651 P_("Color of the selection box"),
653 GTK_PARAM_READABLE));
655 gtk_widget_class_install_style_property (widget_class,
656 g_param_spec_uchar ("selection-box-alpha",
657 P_("Selection Box Alpha"),
658 P_("Opacity of the selection box"),
661 GTK_PARAM_READABLE));
665 * GtkIconView::item-activated:
666 * @iconview: the object on which the signal is emitted
667 * @path: the #GtkTreePath for the activated item
669 * The ::item-activated signal is emitted when the method
670 * gtk_icon_view_item_activated() is called or the user double
671 * clicks an item. It is also emitted when a non-editable item
672 * is selected and one of the keys: Space, Return or Enter is
675 icon_view_signals[ITEM_ACTIVATED] =
676 g_signal_new (I_("item-activated"),
677 G_TYPE_FROM_CLASS (gobject_class),
679 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
681 g_cclosure_marshal_VOID__BOXED,
686 * GtkIconView::selection-changed:
687 * @iconview: the object on which the signal is emitted
689 * The ::selection-changed signal is emitted when the selection
690 * (i.e. the set of selected items) changes.
692 icon_view_signals[SELECTION_CHANGED] =
693 g_signal_new (I_("selection-changed"),
694 G_TYPE_FROM_CLASS (gobject_class),
696 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
698 g_cclosure_marshal_VOID__VOID,
702 * GtkIconView::select-all:
703 * @iconview: the object on which the signal is emitted
705 * A <link linkend="keybinding-signals">keybinding signal</link>
706 * which gets emitted when the user selects all items.
708 * Applications should not connect to it, but may emit it with
709 * g_signal_emit_by_name() if they need to control selection
712 * The default binding for this signal is Ctrl-a.
714 icon_view_signals[SELECT_ALL] =
715 g_signal_new (I_("select-all"),
716 G_TYPE_FROM_CLASS (gobject_class),
717 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
718 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
720 g_cclosure_marshal_VOID__VOID,
724 * GtkIconView::unselect-all:
725 * @iconview: the object on which the signal is emitted
727 * A <link linkend="keybinding-signals">keybinding signal</link>
728 * which gets emitted when the user unselects all items.
730 * Applications should not connect to it, but may emit it with
731 * g_signal_emit_by_name() if they need to control selection
734 * The default binding for this signal is Ctrl-Shift-a.
736 icon_view_signals[UNSELECT_ALL] =
737 g_signal_new (I_("unselect-all"),
738 G_TYPE_FROM_CLASS (gobject_class),
739 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
740 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
742 g_cclosure_marshal_VOID__VOID,
746 * GtkIconView::select-cursor-item:
747 * @iconview: the object on which the signal is emitted
749 * A <link linkend="keybinding-signals">keybinding signal</link>
750 * which gets emitted when the user selects the item that is currently
753 * Applications should not connect to it, but may emit it with
754 * g_signal_emit_by_name() if they need to control selection
757 * There is no default binding for this signal.
759 icon_view_signals[SELECT_CURSOR_ITEM] =
760 g_signal_new (I_("select-cursor-item"),
761 G_TYPE_FROM_CLASS (gobject_class),
762 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
763 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
765 g_cclosure_marshal_VOID__VOID,
769 * GtkIconView::toggle-cursor-item:
770 * @iconview: the object on which the signal is emitted
772 * A <link linkend="keybinding-signals">keybinding signal</link>
773 * which gets emitted when the user toggles whether the currently
774 * focused item is selected or not. The exact effect of this
775 * depend on the selection mode.
777 * Applications should not connect to it, but may emit it with
778 * g_signal_emit_by_name() if they need to control selection
781 * There is no default binding for this signal is Ctrl-Space.
783 icon_view_signals[TOGGLE_CURSOR_ITEM] =
784 g_signal_new (I_("toggle-cursor-item"),
785 G_TYPE_FROM_CLASS (gobject_class),
786 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
787 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
789 g_cclosure_marshal_VOID__VOID,
793 * GtkIconView::activate-cursor-item:
794 * @iconview: the object on which the signal is emitted
796 * A <link linkend="keybinding-signals">keybinding signal</link>
797 * which gets emitted when the user activates the currently
800 * Applications should not connect to it, but may emit it with
801 * g_signal_emit_by_name() if they need to control activation
804 * The default bindings for this signal are Space, Return and Enter.
806 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
807 g_signal_new (I_("activate-cursor-item"),
808 G_TYPE_FROM_CLASS (gobject_class),
809 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
810 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
812 _gtk_marshal_BOOLEAN__VOID,
816 * GtkIconView::move-cursor:
817 * @iconview: the object which received the signal
818 * @step: the granularity of the move, as a #GtkMovementStep
819 * @count: the number of @step units to move
821 * The ::move-cursor signal is a
822 * <link linkend="keybinding-signals">keybinding signal</link>
823 * which gets emitted when the user initiates a cursor movement.
825 * Applications should not connect to it, but may emit it with
826 * g_signal_emit_by_name() if they need to control the cursor
829 * The default bindings for this signal include
831 * <listitem>Arrow keys which move by individual steps</listitem>
832 * <listitem>Home/End keys which move to the first/last item</listitem>
833 * <listitem>PageUp/PageDown which move by "pages"</listitem>
836 * All of these will extend the selection when combined with
837 * the Shift modifier.
839 icon_view_signals[MOVE_CURSOR] =
840 g_signal_new (I_("move-cursor"),
841 G_TYPE_FROM_CLASS (gobject_class),
842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
843 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
845 _gtk_marshal_BOOLEAN__ENUM_INT,
847 GTK_TYPE_MOVEMENT_STEP,
851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
856 "toggle-cursor-item", 0);
857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
858 "toggle-cursor-item", 0);
860 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
861 "activate-cursor-item", 0);
862 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
863 "activate-cursor-item", 0);
864 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
865 "activate-cursor-item", 0);
866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
867 "activate-cursor-item", 0);
868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
869 "activate-cursor-item", 0);
871 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
872 GTK_MOVEMENT_DISPLAY_LINES, -1);
873 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
874 GTK_MOVEMENT_DISPLAY_LINES, -1);
876 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
877 GTK_MOVEMENT_DISPLAY_LINES, 1);
878 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
879 GTK_MOVEMENT_DISPLAY_LINES, 1);
881 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
882 GTK_MOVEMENT_DISPLAY_LINES, -1);
884 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
885 GTK_MOVEMENT_DISPLAY_LINES, 1);
887 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
888 GTK_MOVEMENT_BUFFER_ENDS, -1);
889 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
890 GTK_MOVEMENT_BUFFER_ENDS, -1);
892 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
893 GTK_MOVEMENT_BUFFER_ENDS, 1);
894 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
895 GTK_MOVEMENT_BUFFER_ENDS, 1);
897 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
898 GTK_MOVEMENT_PAGES, -1);
899 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
900 GTK_MOVEMENT_PAGES, -1);
902 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
903 GTK_MOVEMENT_PAGES, 1);
904 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
905 GTK_MOVEMENT_PAGES, 1);
907 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
908 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
909 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
910 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
912 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
913 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
914 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
915 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
917 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
921 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
923 parent_buildable_iface = g_type_interface_peek_parent (iface);
924 iface->add_child = _gtk_cell_layout_buildable_add_child;
925 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
926 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
930 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
932 iface->get_area = gtk_icon_view_cell_layout_get_area;
936 gtk_icon_view_init (GtkIconView *icon_view)
938 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
942 icon_view->priv->width = 0;
943 icon_view->priv->height = 0;
944 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
945 icon_view->priv->pressed_button = -1;
946 icon_view->priv->press_start_x = -1;
947 icon_view->priv->press_start_y = -1;
948 icon_view->priv->text_column = -1;
949 icon_view->priv->markup_column = -1;
950 icon_view->priv->pixbuf_column = -1;
951 icon_view->priv->text_cell = NULL;
952 icon_view->priv->pixbuf_cell = NULL;
953 icon_view->priv->tooltip_column = -1;
955 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
957 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
959 icon_view->priv->columns = -1;
960 icon_view->priv->item_width = -1;
961 icon_view->priv->spacing = 0;
962 icon_view->priv->row_spacing = 6;
963 icon_view->priv->column_spacing = 6;
964 icon_view->priv->margin = 6;
965 icon_view->priv->item_padding = 6;
967 icon_view->priv->draw_focus = TRUE;
969 icon_view->priv->row_contexts =
970 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
973 /* GObject methods */
975 gtk_icon_view_constructor (GType type,
976 guint n_construct_properties,
977 GObjectConstructParam *construct_properties)
979 GtkIconView *icon_view;
982 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
983 (type, n_construct_properties, construct_properties);
985 icon_view = (GtkIconView *) object;
987 gtk_icon_view_ensure_cell_area (icon_view, NULL);
993 gtk_icon_view_dispose (GObject *object)
995 GtkIconView *icon_view;
996 GtkIconViewPrivate *priv;
998 icon_view = GTK_ICON_VIEW (object);
999 priv = icon_view->priv;
1001 if (priv->cell_area_context)
1003 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1004 priv->context_changed_id = 0;
1006 g_object_unref (priv->cell_area_context);
1007 priv->cell_area_context = NULL;
1010 if (priv->row_contexts)
1012 g_ptr_array_free (priv->row_contexts, TRUE);
1013 priv->row_contexts = NULL;
1016 if (priv->cell_area)
1018 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1020 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1021 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1022 priv->add_editable_id = 0;
1023 priv->remove_editable_id = 0;
1025 g_object_unref (priv->cell_area);
1026 priv->cell_area = NULL;
1029 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1033 gtk_icon_view_set_property (GObject *object,
1035 const GValue *value,
1038 GtkIconView *icon_view;
1041 icon_view = GTK_ICON_VIEW (object);
1045 case PROP_SELECTION_MODE:
1046 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1048 case PROP_PIXBUF_COLUMN:
1049 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1051 case PROP_TEXT_COLUMN:
1052 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1054 case PROP_MARKUP_COLUMN:
1055 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1058 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1060 case PROP_ITEM_ORIENTATION:
1061 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1064 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1066 case PROP_ITEM_WIDTH:
1067 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1070 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1072 case PROP_ROW_SPACING:
1073 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1075 case PROP_COLUMN_SPACING:
1076 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1079 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1081 case PROP_REORDERABLE:
1082 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1085 case PROP_TOOLTIP_COLUMN:
1086 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1089 case PROP_ITEM_PADDING:
1090 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1093 case PROP_CELL_AREA:
1094 /* Construct-only, can only be assigned once */
1095 area = g_value_get_object (value);
1098 if (icon_view->priv->cell_area != NULL)
1100 g_warning ("cell-area has already been set, ignoring construct property");
1101 g_object_ref_sink (area);
1102 g_object_unref (area);
1105 gtk_icon_view_ensure_cell_area (icon_view, area);
1109 case PROP_HADJUSTMENT:
1110 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1112 case PROP_VADJUSTMENT:
1113 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1115 case PROP_HSCROLL_POLICY:
1116 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1117 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1119 case PROP_VSCROLL_POLICY:
1120 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1121 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1125 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1131 gtk_icon_view_get_property (GObject *object,
1136 GtkIconView *icon_view;
1138 icon_view = GTK_ICON_VIEW (object);
1142 case PROP_SELECTION_MODE:
1143 g_value_set_enum (value, icon_view->priv->selection_mode);
1145 case PROP_PIXBUF_COLUMN:
1146 g_value_set_int (value, icon_view->priv->pixbuf_column);
1148 case PROP_TEXT_COLUMN:
1149 g_value_set_int (value, icon_view->priv->text_column);
1151 case PROP_MARKUP_COLUMN:
1152 g_value_set_int (value, icon_view->priv->markup_column);
1155 g_value_set_object (value, icon_view->priv->model);
1157 case PROP_ITEM_ORIENTATION:
1158 g_value_set_enum (value, icon_view->priv->item_orientation);
1161 g_value_set_int (value, icon_view->priv->columns);
1163 case PROP_ITEM_WIDTH:
1164 g_value_set_int (value, icon_view->priv->item_width);
1167 g_value_set_int (value, icon_view->priv->spacing);
1169 case PROP_ROW_SPACING:
1170 g_value_set_int (value, icon_view->priv->row_spacing);
1172 case PROP_COLUMN_SPACING:
1173 g_value_set_int (value, icon_view->priv->column_spacing);
1176 g_value_set_int (value, icon_view->priv->margin);
1178 case PROP_REORDERABLE:
1179 g_value_set_boolean (value, icon_view->priv->reorderable);
1181 case PROP_TOOLTIP_COLUMN:
1182 g_value_set_int (value, icon_view->priv->tooltip_column);
1185 case PROP_ITEM_PADDING:
1186 g_value_set_int (value, icon_view->priv->item_padding);
1189 case PROP_CELL_AREA:
1190 g_value_set_object (value, icon_view->priv->cell_area);
1193 case PROP_HADJUSTMENT:
1194 g_value_set_object (value, icon_view->priv->hadjustment);
1196 case PROP_VADJUSTMENT:
1197 g_value_set_object (value, icon_view->priv->vadjustment);
1199 case PROP_HSCROLL_POLICY:
1200 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1202 case PROP_VSCROLL_POLICY:
1203 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1207 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1212 /* GtkWidget methods */
1214 gtk_icon_view_destroy (GtkWidget *widget)
1216 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1218 gtk_icon_view_set_model (icon_view, NULL);
1220 if (icon_view->priv->layout_idle_id != 0)
1222 g_source_remove (icon_view->priv->layout_idle_id);
1223 icon_view->priv->layout_idle_id = 0;
1226 if (icon_view->priv->scroll_to_path != NULL)
1228 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1229 icon_view->priv->scroll_to_path = NULL;
1232 remove_scroll_timeout (icon_view);
1234 if (icon_view->priv->hadjustment != NULL)
1236 g_object_unref (icon_view->priv->hadjustment);
1237 icon_view->priv->hadjustment = NULL;
1240 if (icon_view->priv->vadjustment != NULL)
1242 g_object_unref (icon_view->priv->vadjustment);
1243 icon_view->priv->vadjustment = NULL;
1246 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1250 gtk_icon_view_realize (GtkWidget *widget)
1252 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1253 GtkAllocation allocation;
1255 GdkWindowAttr attributes;
1256 gint attributes_mask;
1257 GtkStyleContext *context;
1259 gtk_widget_set_realized (widget, TRUE);
1261 gtk_widget_get_allocation (widget, &allocation);
1263 /* Make the main, clipping window */
1264 attributes.window_type = GDK_WINDOW_CHILD;
1265 attributes.x = allocation.x;
1266 attributes.y = allocation.y;
1267 attributes.width = allocation.width;
1268 attributes.height = allocation.height;
1269 attributes.wclass = GDK_INPUT_OUTPUT;
1270 attributes.visual = gtk_widget_get_visual (widget);
1271 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1273 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1275 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1276 &attributes, attributes_mask);
1277 gtk_widget_set_window (widget, window);
1278 gdk_window_set_user_data (window, widget);
1280 gtk_widget_get_allocation (widget, &allocation);
1282 /* Make the window for the icon view */
1285 attributes.width = MAX (icon_view->priv->width, allocation.width);
1286 attributes.height = MAX (icon_view->priv->height, allocation.height);
1287 attributes.event_mask = (GDK_EXPOSURE_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_restore (context);
1307 gdk_window_show (icon_view->priv->bin_window);
1311 gtk_icon_view_unrealize (GtkWidget *widget)
1313 GtkIconView *icon_view;
1315 icon_view = GTK_ICON_VIEW (widget);
1317 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1318 gdk_window_destroy (icon_view->priv->bin_window);
1319 icon_view->priv->bin_window = NULL;
1321 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1325 _gtk_icon_view_update_background (GtkIconView *icon_view)
1327 GtkWidget *widget = GTK_WIDGET (icon_view);
1329 if (gtk_widget_get_realized (widget))
1331 GtkStyleContext *context;
1333 context = gtk_widget_get_style_context (widget);
1335 gtk_style_context_save (context);
1336 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1338 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1339 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1341 gtk_style_context_restore (context);
1346 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1347 GtkStateFlags previous_state)
1349 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1350 gtk_widget_queue_draw (widget);
1354 gtk_icon_view_style_updated (GtkWidget *widget)
1356 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1358 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1359 gtk_widget_queue_resize (widget);
1363 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1367 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1371 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1375 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1379 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1383 for (list = icon_view->priv->children; list; list = list->next)
1385 GtkIconViewChild *child = list->data;
1387 /* totally ignore our child's requisition */
1388 gtk_widget_size_allocate (child->widget, &child->area);
1393 gtk_icon_view_size_allocate (GtkWidget *widget,
1394 GtkAllocation *allocation)
1396 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1398 gtk_widget_set_allocation (widget, allocation);
1400 if (gtk_widget_get_realized (widget))
1402 gdk_window_move_resize (gtk_widget_get_window (widget),
1403 allocation->x, allocation->y,
1404 allocation->width, allocation->height);
1405 gdk_window_resize (icon_view->priv->bin_window,
1406 MAX (icon_view->priv->width, allocation->width),
1407 MAX (icon_view->priv->height, allocation->height));
1410 gtk_icon_view_layout (icon_view);
1412 gtk_icon_view_allocate_children (icon_view);
1414 /* Delay signal emission */
1415 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1416 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1418 gtk_icon_view_set_hadjustment_values (icon_view);
1419 gtk_icon_view_set_vadjustment_values (icon_view);
1421 if (gtk_widget_get_realized (widget) &&
1422 icon_view->priv->scroll_to_path)
1425 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1426 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1427 icon_view->priv->scroll_to_path = NULL;
1429 gtk_icon_view_scroll_to_path (icon_view, path,
1430 icon_view->priv->scroll_to_use_align,
1431 icon_view->priv->scroll_to_row_align,
1432 icon_view->priv->scroll_to_col_align);
1433 gtk_tree_path_free (path);
1436 /* Emit any pending signals now */
1437 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1438 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1442 gtk_icon_view_draw (GtkWidget *widget,
1445 GtkIconView *icon_view;
1449 GtkIconViewDropPosition dest_pos;
1450 GtkIconViewItem *dest_item = NULL;
1452 icon_view = GTK_ICON_VIEW (widget);
1454 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1459 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1461 cairo_set_line_width (cr, 1.);
1463 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1467 dest_index = gtk_tree_path_get_indices (path)[0];
1468 gtk_tree_path_free (path);
1473 for (icons = icon_view->priv->items; icons; icons = icons->next)
1475 GtkIconViewItem *item = icons->data;
1476 GdkRectangle paint_area;
1478 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1479 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1480 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1481 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1485 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1488 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1490 gtk_icon_view_paint_item (icon_view, cr, item,
1491 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1492 icon_view->priv->draw_focus);
1494 if (dest_index == item->index)
1502 dest_pos != GTK_ICON_VIEW_NO_DROP)
1504 GtkStyleContext *context;
1505 GdkRectangle rect = { 0 };
1507 context = gtk_widget_get_style_context (widget);
1511 case GTK_ICON_VIEW_DROP_INTO:
1512 rect = dest_item->cell_area;
1514 case GTK_ICON_VIEW_DROP_ABOVE:
1515 rect.x = dest_item->cell_area.x;
1516 rect.y = dest_item->cell_area.y - 1;
1517 rect.width = dest_item->cell_area.width;
1520 case GTK_ICON_VIEW_DROP_LEFT:
1521 rect.x = dest_item->cell_area.x - 1;
1522 rect.y = dest_item->cell_area.y;
1524 rect.height = dest_item->cell_area.height;
1526 case GTK_ICON_VIEW_DROP_BELOW:
1527 rect.x = dest_item->cell_area.x;
1528 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1529 rect.width = dest_item->cell_area.width;
1532 case GTK_ICON_VIEW_DROP_RIGHT:
1533 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1534 rect.y = dest_item->cell_area.y;
1536 rect.height = dest_item->cell_area.height;
1537 case GTK_ICON_VIEW_NO_DROP: ;
1541 gtk_render_focus (context, cr,
1543 rect.width, rect.height);
1546 if (icon_view->priv->doing_rubberband)
1547 gtk_icon_view_paint_rubberband (icon_view, cr);
1551 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1555 rubberband_scroll_timeout (gpointer data)
1557 GtkIconView *icon_view = data;
1559 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1560 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1561 icon_view->priv->scroll_value_diff);
1563 gtk_icon_view_update_rubberband (icon_view);
1569 gtk_icon_view_motion (GtkWidget *widget,
1570 GdkEventMotion *event)
1572 GtkAllocation allocation;
1573 GtkIconView *icon_view;
1576 icon_view = GTK_ICON_VIEW (widget);
1578 gtk_icon_view_maybe_begin_drag (icon_view, event);
1580 if (icon_view->priv->doing_rubberband)
1582 gtk_icon_view_update_rubberband (widget);
1584 abs_y = event->y - icon_view->priv->height *
1585 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1586 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1587 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1589 gtk_widget_get_allocation (widget, &allocation);
1591 if (abs_y < 0 || abs_y > allocation.height)
1594 icon_view->priv->scroll_value_diff = abs_y;
1596 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1598 icon_view->priv->event_last_x = event->x;
1599 icon_view->priv->event_last_y = event->y;
1601 if (icon_view->priv->scroll_timeout_id == 0)
1602 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1606 remove_scroll_timeout (icon_view);
1610 GtkIconViewItem *item, *last_prelight_item;
1611 GtkCellRenderer *cell = NULL;
1613 last_prelight_item = icon_view->priv->last_prelight;
1614 item = _gtk_icon_view_get_item_at_coords (icon_view,
1621 item->prelight = TRUE;
1622 gtk_icon_view_queue_draw_item (icon_view, item);
1625 if (last_prelight_item != NULL &&
1626 last_prelight_item != item)
1628 last_prelight_item->prelight = FALSE;
1629 gtk_icon_view_queue_draw_item (icon_view,
1630 icon_view->priv->last_prelight);
1633 icon_view->priv->last_prelight = item;
1640 gtk_icon_view_remove (GtkContainer *container,
1643 GtkIconView *icon_view;
1644 GtkIconViewChild *child = NULL;
1647 icon_view = GTK_ICON_VIEW (container);
1649 tmp_list = icon_view->priv->children;
1652 child = tmp_list->data;
1653 if (child->widget == widget)
1655 gtk_widget_unparent (widget);
1657 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1658 g_list_free_1 (tmp_list);
1663 tmp_list = tmp_list->next;
1668 gtk_icon_view_forall (GtkContainer *container,
1669 gboolean include_internals,
1670 GtkCallback callback,
1671 gpointer callback_data)
1673 GtkIconView *icon_view;
1674 GtkIconViewChild *child = NULL;
1677 icon_view = GTK_ICON_VIEW (container);
1679 tmp_list = icon_view->priv->children;
1682 child = tmp_list->data;
1683 tmp_list = tmp_list->next;
1685 (* callback) (child->widget, callback_data);
1690 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1691 GtkIconViewItem *item)
1694 AtkObject *item_obj;
1696 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1699 item_obj = atk_object_ref_accessible_child (obj, item->index);
1700 if (item_obj != NULL)
1702 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1703 g_object_unref (item_obj);
1709 gtk_icon_view_add_editable (GtkCellArea *area,
1710 GtkCellRenderer *renderer,
1711 GtkCellEditable *editable,
1712 GdkRectangle *cell_area,
1714 GtkIconView *icon_view)
1716 GtkIconViewChild *child;
1717 GtkWidget *widget = GTK_WIDGET (editable);
1719 child = g_new (GtkIconViewChild, 1);
1721 child->widget = widget;
1722 child->area.x = cell_area->x;
1723 child->area.y = cell_area->y;
1724 child->area.width = cell_area->width;
1725 child->area.height = cell_area->height;
1727 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1729 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1730 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1732 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1736 gtk_icon_view_remove_editable (GtkCellArea *area,
1737 GtkCellRenderer *renderer,
1738 GtkCellEditable *editable,
1739 GtkIconView *icon_view)
1743 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1744 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1746 gtk_container_remove (GTK_CONTAINER (icon_view),
1747 GTK_WIDGET (editable));
1749 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1750 gtk_icon_view_queue_draw_path (icon_view, path);
1751 gtk_tree_path_free (path);
1755 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1757 GtkIconView *icon_view)
1759 if (!strcmp (pspec->name, "minimum-width") ||
1760 !strcmp (pspec->name, "natural-width") ||
1761 !strcmp (pspec->name, "minimum-height") ||
1762 !strcmp (pspec->name, "natural-height"))
1763 gtk_icon_view_invalidate_sizes (icon_view);
1767 * gtk_icon_view_set_cursor:
1768 * @icon_view: A #GtkIconView
1769 * @path: A #GtkTreePath
1770 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1771 * @start_editing: %TRUE if the specified cell should start being edited.
1773 * Sets the current keyboard focus to be at @path, and selects it. This is
1774 * useful when you want to focus the user's attention on a particular item.
1775 * If @cell is not %NULL, then focus is given to the cell specified by
1776 * it. Additionally, if @start_editing is %TRUE, then editing should be
1777 * started in the specified cell.
1779 * This function is often followed by <literal>gtk_widget_grab_focus
1780 * (icon_view)</literal> in order to give keyboard focus to the widget.
1781 * Please note that editing can only happen when the widget is realized.
1786 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1788 GtkCellRenderer *cell,
1789 gboolean start_editing)
1791 GtkIconViewItem *item = NULL;
1793 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1794 g_return_if_fail (path != NULL);
1795 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1797 if (icon_view->priv->cell_area)
1798 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1800 if (gtk_tree_path_get_depth (path) == 1)
1801 item = g_list_nth_data (icon_view->priv->items,
1802 gtk_tree_path_get_indices(path)[0]);
1807 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
1808 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1810 if (start_editing &&
1811 icon_view->priv->cell_area)
1813 GtkCellAreaContext *context;
1815 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1816 _gtk_icon_view_set_cell_data (icon_view, item);
1817 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1818 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1819 0 /* XXX flags */, TRUE);
1824 * gtk_icon_view_get_cursor:
1825 * @icon_view: A #GtkIconView
1826 * @path: (out) (allow-none): Return location for the current cursor path,
1828 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1830 * Fills in @path and @cell with the current cursor path and cell.
1831 * If the cursor isn't currently set, then *@path will be %NULL.
1832 * If no cell currently has focus, then *@cell will be %NULL.
1834 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1836 * Return value: %TRUE if the cursor is set.
1841 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1843 GtkCellRenderer **cell)
1845 GtkIconViewItem *item;
1847 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1849 item = icon_view->priv->cursor_item;
1854 *path = gtk_tree_path_new_from_indices (item->index, -1);
1859 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1860 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1862 return (item != NULL);
1866 gtk_icon_view_button_press (GtkWidget *widget,
1867 GdkEventButton *event)
1869 GtkIconView *icon_view;
1870 GtkIconViewItem *item;
1871 gboolean dirty = FALSE;
1872 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1874 icon_view = GTK_ICON_VIEW (widget);
1876 if (event->window != icon_view->priv->bin_window)
1879 if (!gtk_widget_has_focus (widget))
1880 gtk_widget_grab_focus (widget);
1882 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1884 GdkModifierType extend_mod_mask;
1885 GdkModifierType modify_mod_mask;
1888 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
1891 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
1893 item = _gtk_icon_view_get_item_at_coords (icon_view,
1899 * We consider only the the cells' area as the item area if the
1900 * item is not selected, but if it *is* selected, the complete
1901 * selection rectangle is considered to be part of the item.
1903 if (item != NULL && (cell != NULL || item->selected))
1907 if (gtk_cell_renderer_is_activatable (cell))
1911 gtk_icon_view_scroll_to_item (icon_view, item);
1913 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1915 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1917 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1918 (event->state & extend_mod_mask))
1920 gtk_icon_view_unselect_all_internal (icon_view);
1922 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1923 if (!icon_view->priv->anchor_item)
1924 icon_view->priv->anchor_item = item;
1926 gtk_icon_view_select_all_between (icon_view,
1927 icon_view->priv->anchor_item,
1933 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1934 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1935 (event->state & modify_mod_mask))
1937 item->selected = !item->selected;
1938 gtk_icon_view_queue_draw_item (icon_view, item);
1943 gtk_icon_view_unselect_all_internal (icon_view);
1945 item->selected = TRUE;
1946 gtk_icon_view_queue_draw_item (icon_view, item);
1949 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1950 icon_view->priv->anchor_item = item;
1953 /* Save press to possibly begin a drag */
1954 if (icon_view->priv->pressed_button < 0)
1956 icon_view->priv->pressed_button = event->button;
1957 icon_view->priv->press_start_x = event->x;
1958 icon_view->priv->press_start_y = event->y;
1961 if (!icon_view->priv->last_single_clicked)
1962 icon_view->priv->last_single_clicked = item;
1964 /* cancel the current editing, if it exists */
1965 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1967 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
1969 GtkCellAreaContext *context;
1971 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1973 _gtk_icon_view_set_cell_data (icon_view, item);
1974 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1975 GTK_WIDGET (icon_view),
1976 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
1981 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1982 !(event->state & modify_mod_mask))
1984 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1987 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1988 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
1991 /* don't draw keyboard focus around an clicked-on item */
1992 icon_view->priv->draw_focus = FALSE;
1995 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
1997 item = _gtk_icon_view_get_item_at_coords (icon_view,
2002 if (item && item == icon_view->priv->last_single_clicked)
2006 path = gtk_tree_path_new_from_indices (item->index, -1);
2007 gtk_icon_view_item_activated (icon_view, path);
2008 gtk_tree_path_free (path);
2011 icon_view->priv->last_single_clicked = NULL;
2012 icon_view->priv->pressed_button = -1;
2016 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2018 return event->button == 1;
2022 gtk_icon_view_button_release (GtkWidget *widget,
2023 GdkEventButton *event)
2025 GtkIconView *icon_view;
2027 icon_view = GTK_ICON_VIEW (widget);
2029 if (icon_view->priv->pressed_button == event->button)
2030 icon_view->priv->pressed_button = -1;
2032 gtk_icon_view_stop_rubberbanding (icon_view);
2034 remove_scroll_timeout (icon_view);
2040 gtk_icon_view_key_press (GtkWidget *widget,
2043 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2045 if (icon_view->priv->doing_rubberband)
2047 if (event->keyval == GDK_KEY_Escape)
2048 gtk_icon_view_stop_rubberbanding (icon_view);
2053 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2057 gtk_icon_view_key_release (GtkWidget *widget,
2060 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2062 if (icon_view->priv->doing_rubberband)
2065 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2069 gtk_icon_view_update_rubberband (gpointer data)
2071 GtkIconView *icon_view;
2073 GdkRectangle old_area;
2074 GdkRectangle new_area;
2075 GdkRectangle common;
2076 cairo_region_t *invalid_region;
2078 icon_view = GTK_ICON_VIEW (data);
2080 gdk_window_get_device_position (icon_view->priv->bin_window,
2081 icon_view->priv->rubberband_device,
2087 old_area.x = MIN (icon_view->priv->rubberband_x1,
2088 icon_view->priv->rubberband_x2);
2089 old_area.y = MIN (icon_view->priv->rubberband_y1,
2090 icon_view->priv->rubberband_y2);
2091 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2092 icon_view->priv->rubberband_x1) + 1;
2093 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2094 icon_view->priv->rubberband_y1) + 1;
2096 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2097 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2098 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2099 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2101 invalid_region = cairo_region_create_rectangle (&old_area);
2102 cairo_region_union_rectangle (invalid_region, &new_area);
2104 gdk_rectangle_intersect (&old_area, &new_area, &common);
2105 if (common.width > 2 && common.height > 2)
2107 cairo_region_t *common_region;
2109 /* make sure the border is invalidated */
2115 common_region = cairo_region_create_rectangle (&common);
2117 cairo_region_subtract (invalid_region, common_region);
2118 cairo_region_destroy (common_region);
2121 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2123 cairo_region_destroy (invalid_region);
2125 icon_view->priv->rubberband_x2 = x;
2126 icon_view->priv->rubberband_y2 = y;
2128 gtk_icon_view_update_rubberband_selection (icon_view);
2132 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2139 if (icon_view->priv->rubberband_device)
2142 for (items = icon_view->priv->items; items; items = items->next)
2144 GtkIconViewItem *item = items->data;
2146 item->selected_before_rubberbanding = item->selected;
2149 icon_view->priv->rubberband_x1 = x;
2150 icon_view->priv->rubberband_y1 = y;
2151 icon_view->priv->rubberband_x2 = x;
2152 icon_view->priv->rubberband_y2 = y;
2154 icon_view->priv->doing_rubberband = TRUE;
2155 icon_view->priv->rubberband_device = device;
2157 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2161 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2163 if (!icon_view->priv->doing_rubberband)
2166 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2167 icon_view->priv->rubberband_device);
2169 icon_view->priv->doing_rubberband = FALSE;
2170 icon_view->priv->rubberband_device = NULL;
2172 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2176 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2179 gint x, y, width, height;
2180 gboolean dirty = FALSE;
2182 x = MIN (icon_view->priv->rubberband_x1,
2183 icon_view->priv->rubberband_x2);
2184 y = MIN (icon_view->priv->rubberband_y1,
2185 icon_view->priv->rubberband_y2);
2186 width = ABS (icon_view->priv->rubberband_x1 -
2187 icon_view->priv->rubberband_x2);
2188 height = ABS (icon_view->priv->rubberband_y1 -
2189 icon_view->priv->rubberband_y2);
2191 for (items = icon_view->priv->items; items; items = items->next)
2193 GtkIconViewItem *item = items->data;
2197 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2198 x, y, width, height);
2200 selected = is_in ^ item->selected_before_rubberbanding;
2202 if (item->selected != selected)
2204 item->selected = selected;
2206 gtk_icon_view_queue_draw_item (icon_view, item);
2211 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2216 GdkRectangle hit_rect;
2221 hit_test (GtkCellRenderer *renderer,
2222 const GdkRectangle *cell_area,
2223 const GdkRectangle *cell_background,
2226 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2227 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2228 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2229 MAX (data->hit_rect.y, cell_area->y) > 0)
2232 return (data->hit != FALSE);
2236 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2237 GtkIconViewItem *item,
2243 HitTestData data = { { x, y, width, height }, FALSE };
2244 GtkCellAreaContext *context;
2245 GdkRectangle *item_area = (GdkRectangle *)item;
2247 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2248 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2251 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2253 _gtk_icon_view_set_cell_data (icon_view, item);
2254 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2255 GTK_WIDGET (icon_view),
2256 item_area, item_area,
2257 (GtkCellAllocCallback)hit_test, &data);
2263 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2265 gboolean dirty = FALSE;
2268 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2271 for (items = icon_view->priv->items; items; items = items->next)
2273 GtkIconViewItem *item = items->data;
2277 item->selected = FALSE;
2279 gtk_icon_view_queue_draw_item (icon_view, item);
2280 gtk_icon_view_item_selected_changed (icon_view, item);
2288 /* GtkIconView signals */
2290 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2292 gtk_icon_view_select_all (icon_view);
2296 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2298 gtk_icon_view_unselect_all (icon_view);
2302 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2304 gtk_icon_view_unselect_all (icon_view);
2306 if (icon_view->priv->cursor_item != NULL)
2307 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2311 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2314 GtkCellAreaContext *context;
2316 if (!icon_view->priv->cursor_item)
2319 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2321 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2322 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2323 GTK_WIDGET (icon_view),
2324 (GdkRectangle *)icon_view->priv->cursor_item,
2328 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2329 gtk_icon_view_item_activated (icon_view, path);
2330 gtk_tree_path_free (path);
2336 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2338 if (!icon_view->priv->cursor_item)
2341 switch (icon_view->priv->selection_mode)
2343 case GTK_SELECTION_NONE:
2345 case GTK_SELECTION_BROWSE:
2346 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2348 case GTK_SELECTION_SINGLE:
2349 if (icon_view->priv->cursor_item->selected)
2350 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2352 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2354 case GTK_SELECTION_MULTIPLE:
2355 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2356 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2358 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2359 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2364 /* Internal functions */
2366 gtk_icon_view_process_updates (GtkIconView *icon_view)
2368 /* Prior to drawing, we check if a layout has been scheduled. If so,
2369 * do it now that all cell view items have valid sizes before we proceeed
2370 * (and resize the bin_window if required).
2372 if (icon_view->priv->layout_idle_id != 0)
2373 gtk_icon_view_layout (icon_view);
2375 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2379 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2381 GtkAllocation allocation;
2382 GtkAdjustment *adj = icon_view->priv->hadjustment;
2383 gdouble old_page_size;
2389 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2391 old_value = gtk_adjustment_get_value (adj);
2392 old_upper = gtk_adjustment_get_upper (adj);
2393 old_page_size = gtk_adjustment_get_page_size (adj);
2394 new_upper = MAX (allocation.width, icon_view->priv->width);
2396 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2398 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2399 /* Quick explanation:
2400 * In LTR locales, leftmost portion of visible rectangle should stay
2401 * fixed, which means left edge of scrollbar thumb should remain fixed
2402 * and thus adjustment's value should stay the same.
2404 * In RTL locales, we want to keep rightmost portion of visible
2405 * rectangle fixed. This means right edge of thumb should remain fixed.
2406 * In this case, upper - value - page_size should remain constant.
2408 new_value = (new_upper - allocation.width) -
2409 (old_upper - old_value - old_page_size);
2410 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2413 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2415 gtk_adjustment_configure (adj,
2419 allocation.width * 0.1,
2420 allocation.width * 0.9,
2425 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2427 GtkAllocation allocation;
2428 GtkAdjustment *adj = icon_view->priv->vadjustment;
2430 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2432 gtk_adjustment_configure (adj,
2433 gtk_adjustment_get_value (adj),
2435 MAX (allocation.height, icon_view->priv->height),
2436 allocation.height * 0.1,
2437 allocation.height * 0.9,
2442 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2443 GtkAdjustment *adjustment)
2445 GtkIconViewPrivate *priv = icon_view->priv;
2447 if (adjustment && priv->hadjustment == adjustment)
2450 if (priv->hadjustment != NULL)
2452 g_signal_handlers_disconnect_matched (priv->hadjustment,
2453 G_SIGNAL_MATCH_DATA,
2454 0, 0, NULL, NULL, icon_view);
2455 g_object_unref (priv->hadjustment);
2459 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2462 g_signal_connect (adjustment, "value-changed",
2463 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2464 priv->hadjustment = g_object_ref_sink (adjustment);
2465 gtk_icon_view_set_hadjustment_values (icon_view);
2467 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2471 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2472 GtkAdjustment *adjustment)
2474 GtkIconViewPrivate *priv = icon_view->priv;
2476 if (adjustment && priv->vadjustment == adjustment)
2479 if (priv->vadjustment != NULL)
2481 g_signal_handlers_disconnect_matched (priv->vadjustment,
2482 G_SIGNAL_MATCH_DATA,
2483 0, 0, NULL, NULL, icon_view);
2484 g_object_unref (priv->vadjustment);
2488 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2491 g_signal_connect (adjustment, "value-changed",
2492 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2493 priv->vadjustment = g_object_ref_sink (adjustment);
2494 gtk_icon_view_set_vadjustment_values (icon_view);
2496 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2500 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2501 GtkIconView *icon_view)
2503 GtkIconViewPrivate *priv = icon_view->priv;
2505 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2507 gdk_window_move (priv->bin_window,
2508 - gtk_adjustment_get_value (priv->hadjustment),
2509 - gtk_adjustment_get_value (priv->vadjustment));
2511 if (icon_view->priv->doing_rubberband)
2512 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2514 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2516 gtk_icon_view_process_updates (icon_view);
2521 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2526 gint *maximum_width)
2528 GtkAllocation allocation;
2529 GtkCellAreaContext *context;
2530 GtkIconViewPrivate *priv = icon_view->priv;
2531 GtkWidget *widget = GTK_WIDGET (icon_view);
2532 gint x, current_width;
2533 GList *items, *last_item;
2535 gint max_height = 0;
2538 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2546 current_width += 2 * priv->margin;
2548 gtk_widget_get_allocation (widget, &allocation);
2550 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2551 g_ptr_array_add (priv->row_contexts, context);
2553 /* In the first loop we iterate horizontally until we hit allocation width
2554 * and collect the aligned height-for-width */
2558 GtkIconViewItem *item = items->data;
2559 GdkRectangle *item_area = (GdkRectangle *)item;
2561 item_area->width = item_width;
2563 current_width += item_area->width + icon_view->priv->item_padding * 2;
2565 if (items != first_item)
2567 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2568 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2572 /* Get this item's particular width & height (all alignments are cached by now) */
2573 _gtk_icon_view_set_cell_data (icon_view, item);
2574 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2579 current_width += icon_view->priv->column_spacing;
2581 item_area->y = *y + icon_view->priv->item_padding;
2582 item_area->x = x + icon_view->priv->item_padding;
2584 x = current_width - icon_view->priv->margin;
2586 if (current_width > *maximum_width)
2587 *maximum_width = current_width;
2593 items = items->next;
2598 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2599 gtk_cell_area_context_allocate (context, item_width, max_height);
2601 /* In the second loop the item height has been aligned and derived and
2602 * we just set the height and handle rtl layout */
2603 for (items = first_item; items != last_item; items = items->next)
2605 GtkIconViewItem *item = items->data;
2606 GdkRectangle *item_area = (GdkRectangle *)item;
2610 item_area->x = *maximum_width - item_area->width - item_area->x;
2611 item->col = col - 1 - item->col;
2614 /* All items in the same row get the same height */
2615 item_area->height = max_height;
2618 /* Adjust the new y coordinate. */
2619 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2625 adjust_wrap_width (GtkIconView *icon_view)
2627 if (icon_view->priv->text_cell)
2629 gint wrap_width = 50;
2631 /* Here we go with the same old guess, try the icon size and set double
2632 * the size of the first icon found in the list, naive but works much
2634 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2636 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2637 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2638 GTK_WIDGET (icon_view),
2641 wrap_width = MAX (wrap_width * 2, 50);
2644 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2645 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2650 gtk_icon_view_layout (GtkIconView *icon_view)
2652 GtkAllocation allocation;
2655 gint y = 0, maximum_width = 0;
2658 gboolean size_changed = FALSE;
2660 if (icon_view->priv->layout_idle_id != 0)
2662 g_source_remove (icon_view->priv->layout_idle_id);
2663 icon_view->priv->layout_idle_id = 0;
2666 if (icon_view->priv->model == NULL)
2669 widget = GTK_WIDGET (icon_view);
2671 item_width = icon_view->priv->item_width;
2673 /* Update the wrap width for the text cell before going and requesting sizes */
2674 adjust_wrap_width (icon_view);
2676 /* Update the context widths for any invalidated items */
2677 gtk_icon_view_cache_widths (icon_view);
2679 /* Fetch the new item width if needed */
2681 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2684 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2686 icons = icon_view->priv->items;
2687 y += icon_view->priv->margin;
2690 /* Clear the per row contexts */
2691 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2695 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2697 &y, &maximum_width);
2700 while (icons != NULL);
2702 if (maximum_width != icon_view->priv->width)
2704 icon_view->priv->width = maximum_width;
2705 size_changed = TRUE;
2708 y += icon_view->priv->margin;
2710 if (y != icon_view->priv->height)
2712 icon_view->priv->height = y;
2713 size_changed = TRUE;
2716 gtk_icon_view_set_hadjustment_values (icon_view);
2717 gtk_icon_view_set_vadjustment_values (icon_view);
2720 gtk_widget_queue_resize_no_redraw (widget);
2722 gtk_widget_get_allocation (widget, &allocation);
2723 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2724 gdk_window_resize (icon_view->priv->bin_window,
2725 MAX (icon_view->priv->width, allocation.width),
2726 MAX (icon_view->priv->height, allocation.height));
2728 if (icon_view->priv->scroll_to_path)
2732 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2733 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2734 icon_view->priv->scroll_to_path = NULL;
2736 gtk_icon_view_scroll_to_path (icon_view, path,
2737 icon_view->priv->scroll_to_use_align,
2738 icon_view->priv->scroll_to_row_align,
2739 icon_view->priv->scroll_to_col_align);
2740 gtk_tree_path_free (path);
2743 gtk_widget_queue_draw (widget);
2746 /* This ensures that all widths have been cached in the
2747 * context and we have proper alignments to go on.
2750 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2754 g_signal_handler_block (icon_view->priv->cell_area_context,
2755 icon_view->priv->context_changed_id);
2757 for (items = icon_view->priv->items; items; items = items->next)
2759 GtkIconViewItem *item = items->data;
2761 /* Only fetch the width of items with invalidated sizes */
2762 if (item->cell_area.width < 0)
2764 _gtk_icon_view_set_cell_data (icon_view, item);
2765 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2766 icon_view->priv->cell_area_context,
2767 GTK_WIDGET (icon_view), NULL, NULL);
2771 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2772 icon_view->priv->context_changed_id);
2776 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2778 /* Clear all item sizes */
2779 g_list_foreach (icon_view->priv->items,
2780 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2782 /* Reset the context */
2783 if (icon_view->priv->cell_area_context)
2785 g_signal_handler_block (icon_view->priv->cell_area_context,
2786 icon_view->priv->context_changed_id);
2787 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2788 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2789 icon_view->priv->context_changed_id);
2792 /* Re-layout the items */
2793 gtk_icon_view_queue_layout (icon_view);
2797 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2799 item->cell_area.width = -1;
2800 item->cell_area.height = -1;
2804 gtk_icon_view_paint_item (GtkIconView *icon_view,
2806 GtkIconViewItem *item,
2809 gboolean draw_focus)
2811 GdkRectangle cell_area;
2812 GtkStateFlags state = 0;
2813 GtkCellRendererState flags = 0;
2814 GtkStyleContext *style_context;
2815 GtkWidget *widget = GTK_WIDGET (icon_view);
2816 GtkIconViewPrivate *priv = icon_view->priv;
2817 GtkCellAreaContext *context;
2819 if (priv->model == NULL)
2822 _gtk_icon_view_set_cell_data (icon_view, item);
2824 style_context = gtk_widget_get_style_context (widget);
2825 state = gtk_widget_get_state_flags (widget);
2827 gtk_style_context_save (style_context);
2828 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2829 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2831 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
2835 if ((state & GTK_STATE_FLAG_FOCUSED) &&
2836 item == icon_view->priv->cursor_item)
2838 flags |= GTK_CELL_RENDERER_FOCUSED;
2841 state |= GTK_STATE_FLAG_SELECTED;
2842 flags |= GTK_CELL_RENDERER_SELECTED;
2847 state |= GTK_STATE_FLAG_PRELIGHT;
2848 flags |= GTK_CELL_RENDERER_PRELIT;
2851 gtk_style_context_set_state (style_context, state);
2855 gtk_render_background (style_context, cr,
2856 x - icon_view->priv->item_padding,
2857 y - icon_view->priv->item_padding,
2858 item->cell_area.width + icon_view->priv->item_padding * 2,
2859 item->cell_area.height + icon_view->priv->item_padding * 2);
2860 gtk_render_frame (style_context, cr,
2861 x - icon_view->priv->item_padding,
2862 y - icon_view->priv->item_padding,
2863 item->cell_area.width + icon_view->priv->item_padding * 2,
2864 item->cell_area.height + icon_view->priv->item_padding * 2);
2869 cell_area.width = item->cell_area.width;
2870 cell_area.height = item->cell_area.height;
2872 context = g_ptr_array_index (priv->row_contexts, item->row);
2873 gtk_cell_area_render (priv->cell_area, context,
2874 widget, cr, &cell_area, &cell_area, flags,
2877 gtk_style_context_restore (style_context);
2881 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2884 GtkStyleContext *context;
2889 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2890 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2891 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2892 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2894 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2896 gtk_style_context_save (context);
2897 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2899 gdk_cairo_rectangle (cr, &rect);
2902 gtk_render_background (context, cr,
2904 rect.width, rect.height);
2905 gtk_render_frame (context, cr,
2907 rect.width, rect.height);
2909 gtk_style_context_restore (context);
2914 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2920 index = gtk_tree_path_get_indices (path)[0];
2922 for (l = icon_view->priv->items; l; l = l->next)
2924 GtkIconViewItem *item = l->data;
2926 if (item->index == index)
2928 gtk_icon_view_queue_draw_item (icon_view, item);
2935 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2936 GtkIconViewItem *item)
2939 GdkRectangle *item_area = (GdkRectangle *)item;
2941 rect.x = item_area->x - icon_view->priv->item_padding;
2942 rect.y = item_area->y - icon_view->priv->item_padding;
2943 rect.width = item_area->width + icon_view->priv->item_padding * 2;
2944 rect.height = item_area->height + icon_view->priv->item_padding * 2;
2946 if (icon_view->priv->bin_window)
2947 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
2951 layout_callback (gpointer user_data)
2953 GtkIconView *icon_view;
2955 icon_view = GTK_ICON_VIEW (user_data);
2957 icon_view->priv->layout_idle_id = 0;
2959 gtk_icon_view_layout (icon_view);
2965 gtk_icon_view_queue_layout (GtkIconView *icon_view)
2967 if (icon_view->priv->layout_idle_id != 0)
2970 icon_view->priv->layout_idle_id =
2971 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
2972 layout_callback, icon_view, NULL);
2976 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
2977 GtkIconViewItem *item,
2978 GtkCellRenderer *cursor_cell)
2981 AtkObject *item_obj;
2982 AtkObject *cursor_item_obj;
2984 /* When hitting this path from keynav, the focus cell is
2985 * already set, we dont need to notify the atk object
2986 * but we still need to queue the draw here (in the case
2987 * that the focus cell changes but not the cursor item).
2989 gtk_icon_view_queue_draw_item (icon_view, item);
2991 if (icon_view->priv->cursor_item == item &&
2992 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
2995 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2996 if (icon_view->priv->cursor_item != NULL)
2998 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3001 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3002 if (cursor_item_obj != NULL)
3003 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3006 icon_view->priv->cursor_item = item;
3009 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3012 /* Make sure there is a cell in focus initially */
3013 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3014 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3017 /* Notify that accessible focus object has changed */
3018 item_obj = atk_object_ref_accessible_child (obj, item->index);
3020 if (item_obj != NULL)
3022 atk_focus_tracker_notify (item_obj);
3023 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3024 g_object_unref (item_obj);
3029 static GtkIconViewItem *
3030 gtk_icon_view_item_new (void)
3032 GtkIconViewItem *item;
3034 item = g_slice_new0 (GtkIconViewItem);
3036 item->cell_area.width = -1;
3037 item->cell_area.height = -1;
3043 gtk_icon_view_item_free (GtkIconViewItem *item)
3045 g_return_if_fail (item != NULL);
3047 g_slice_free (GtkIconViewItem, item);
3051 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3054 gboolean only_in_cell,
3055 GtkCellRenderer **cell_at_pos)
3060 *cell_at_pos = NULL;
3062 for (items = icon_view->priv->items; items; items = items->next)
3064 GtkIconViewItem *item = items->data;
3065 GdkRectangle *item_area = (GdkRectangle *)item;
3067 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3068 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3069 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3070 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3072 if (only_in_cell || cell_at_pos)
3074 GtkCellRenderer *cell = NULL;
3075 GtkCellAreaContext *context;
3077 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3078 _gtk_icon_view_set_cell_data (icon_view, item);
3080 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3081 y >= item_area->y && y <= item_area->y + item_area->height)
3082 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3083 GTK_WIDGET (icon_view),
3088 *cell_at_pos = cell;
3091 return cell != NULL ? item : NULL;
3102 _gtk_icon_view_select_item (GtkIconView *icon_view,
3103 GtkIconViewItem *item)
3105 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3106 g_return_if_fail (item != NULL);
3111 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3113 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3114 gtk_icon_view_unselect_all_internal (icon_view);
3116 item->selected = TRUE;
3118 gtk_icon_view_item_selected_changed (icon_view, item);
3119 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3121 gtk_icon_view_queue_draw_item (icon_view, item);
3126 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3127 GtkIconViewItem *item)
3129 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3130 g_return_if_fail (item != NULL);
3132 if (!item->selected)
3135 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3136 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3139 item->selected = FALSE;
3141 gtk_icon_view_item_selected_changed (icon_view, item);
3142 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3144 gtk_icon_view_queue_draw_item (icon_view, item);
3148 verify_items (GtkIconView *icon_view)
3153 for (items = icon_view->priv->items; items; items = items->next)
3155 GtkIconViewItem *item = items->data;
3157 if (item->index != i)
3158 g_error ("List item does not match its index: "
3159 "item index %d and list index %d\n", item->index, i);
3166 gtk_icon_view_row_changed (GtkTreeModel *model,
3171 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3173 /* ignore changes in branches */
3174 if (gtk_tree_path_get_depth (path) > 1)
3177 /* An icon view subclass might add it's own model and populate
3178 * things at init() time instead of waiting for the constructor()
3181 if (icon_view->priv->cell_area)
3182 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3184 /* Here we can use a "grow-only" strategy for optimization
3185 * and only invalidate a single item and queue a relayout
3186 * instead of invalidating the whole thing.
3188 * For now GtkIconView still cant deal with huge models
3189 * so just invalidate the whole thing when the model
3192 gtk_icon_view_invalidate_sizes (icon_view);
3194 verify_items (icon_view);
3198 gtk_icon_view_row_inserted (GtkTreeModel *model,
3203 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3205 GtkIconViewItem *item;
3206 gboolean iters_persist;
3209 /* ignore changes in branches */
3210 if (gtk_tree_path_get_depth (path) > 1)
3213 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3215 index = gtk_tree_path_get_indices(path)[0];
3217 item = gtk_icon_view_item_new ();
3222 item->index = index;
3224 /* FIXME: We can be more efficient here,
3225 we can store a tail pointer and use that when
3226 appending (which is a rather common operation)
3228 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3231 list = g_list_nth (icon_view->priv->items, index + 1);
3232 for (; list; list = list->next)
3239 verify_items (icon_view);
3241 gtk_icon_view_queue_layout (icon_view);
3245 gtk_icon_view_row_deleted (GtkTreeModel *model,
3249 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3251 GtkIconViewItem *item;
3253 gboolean emit = FALSE;
3255 /* ignore changes in branches */
3256 if (gtk_tree_path_get_depth (path) > 1)
3259 index = gtk_tree_path_get_indices(path)[0];
3261 list = g_list_nth (icon_view->priv->items, index);
3264 if (icon_view->priv->cell_area)
3265 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3267 if (item == icon_view->priv->anchor_item)
3268 icon_view->priv->anchor_item = NULL;
3270 if (item == icon_view->priv->cursor_item)
3271 icon_view->priv->cursor_item = NULL;
3273 if (item == icon_view->priv->last_prelight)
3274 icon_view->priv->last_prelight = NULL;
3279 gtk_icon_view_item_free (item);
3281 for (next = list->next; next; next = next->next)
3288 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3290 verify_items (icon_view);
3292 gtk_icon_view_queue_layout (icon_view);
3295 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3299 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3300 GtkTreePath *parent,
3305 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3308 GList *items = NULL, *list;
3309 GtkIconViewItem **item_array;
3312 /* ignore changes in branches */
3316 if (icon_view->priv->cell_area)
3317 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3319 length = gtk_tree_model_iter_n_children (model, NULL);
3321 order = g_new (gint, length);
3322 for (i = 0; i < length; i++)
3323 order [new_order[i]] = i;
3325 item_array = g_new (GtkIconViewItem *, length);
3326 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3327 item_array[order[i]] = list->data;
3330 for (i = length - 1; i >= 0; i--)
3332 item_array[i]->index = i;
3333 items = g_list_prepend (items, item_array[i]);
3336 g_free (item_array);
3337 g_list_free (icon_view->priv->items);
3338 icon_view->priv->items = items;
3340 gtk_icon_view_queue_layout (icon_view);
3342 verify_items (icon_view);
3346 gtk_icon_view_build_items (GtkIconView *icon_view)
3350 gboolean iters_persist;
3351 GList *items = NULL;
3353 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3355 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3363 GtkIconViewItem *item = gtk_icon_view_item_new ();
3372 items = g_list_prepend (items, item);
3374 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3376 icon_view->priv->items = g_list_reverse (items);
3380 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3383 GtkMovementStep step,
3387 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3388 I_("move-cursor"), 2,
3392 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3397 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3400 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3405 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3412 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3413 GtkMovementStep step,
3416 GdkModifierType state;
3418 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3419 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3420 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3421 step == GTK_MOVEMENT_DISPLAY_LINES ||
3422 step == GTK_MOVEMENT_PAGES ||
3423 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3425 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3428 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3429 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3431 if (gtk_get_current_event_state (&state))
3433 GdkModifierType extend_mod_mask;
3434 GdkModifierType modify_mod_mask;
3437 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3438 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3440 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3441 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3443 if ((state & modify_mod_mask) == modify_mod_mask)
3444 icon_view->priv->modify_selection_pressed = TRUE;
3445 if ((state & extend_mod_mask) == extend_mod_mask)
3446 icon_view->priv->extend_selection_pressed = TRUE;
3448 /* else we assume not pressed */
3452 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3453 case GTK_MOVEMENT_VISUAL_POSITIONS:
3454 gtk_icon_view_move_cursor_left_right (icon_view, count);
3456 case GTK_MOVEMENT_DISPLAY_LINES:
3457 gtk_icon_view_move_cursor_up_down (icon_view, count);
3459 case GTK_MOVEMENT_PAGES:
3460 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3462 case GTK_MOVEMENT_BUFFER_ENDS:
3463 gtk_icon_view_move_cursor_start_end (icon_view, count);
3466 g_assert_not_reached ();
3469 icon_view->priv->modify_selection_pressed = FALSE;
3470 icon_view->priv->extend_selection_pressed = FALSE;
3472 icon_view->priv->draw_focus = TRUE;
3477 static GtkIconViewItem *
3478 find_item (GtkIconView *icon_view,
3479 GtkIconViewItem *current,
3485 GtkIconViewItem *item;
3487 /* FIXME: this could be more efficient
3489 row = current->row + row_ofs;
3490 col = current->col + col_ofs;
3492 for (items = icon_view->priv->items; items; items = items->next)
3495 if (item->row == row && item->col == col)
3502 static GtkIconViewItem *
3503 find_item_page_up_down (GtkIconView *icon_view,
3504 GtkIconViewItem *current,
3511 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3513 item = g_list_find (icon_view->priv->items, current);
3518 for (next = item->next; next; next = next->next)
3520 if (((GtkIconViewItem *)next->data)->col == col)
3523 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3533 for (next = item->prev; next; next = next->prev)
3535 if (((GtkIconViewItem *)next->data)->col == col)
3538 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3552 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3553 GtkIconViewItem *anchor,
3554 GtkIconViewItem *cursor)
3557 GtkIconViewItem *item;
3558 gint row1, row2, col1, col2;
3559 gboolean dirty = FALSE;
3561 if (anchor->row < cursor->row)
3572 if (anchor->col < cursor->col)
3583 for (items = icon_view->priv->items; items; items = items->next)
3587 if (row1 <= item->row && item->row <= row2 &&
3588 col1 <= item->col && item->col <= col2)
3590 if (!item->selected)
3593 item->selected = TRUE;
3594 gtk_icon_view_item_selected_changed (icon_view, item);
3596 gtk_icon_view_queue_draw_item (icon_view, item);
3604 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3607 GtkIconViewItem *item;
3608 GtkCellRenderer *cell = NULL;
3609 gboolean dirty = FALSE;
3611 GtkDirectionType direction;
3613 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3616 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3618 if (!icon_view->priv->cursor_item)
3623 list = icon_view->priv->items;
3625 list = g_list_last (icon_view->priv->items);
3631 /* Give focus to the first cell initially */
3632 _gtk_icon_view_set_cell_data (icon_view, item);
3633 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3642 item = icon_view->priv->cursor_item;
3643 step = count > 0 ? 1 : -1;
3645 /* Save the current focus cell in case we hit the edge */
3646 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3650 _gtk_icon_view_set_cell_data (icon_view, item);
3652 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3655 item = find_item (icon_view, item, step, 0);
3661 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3663 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3665 gtk_widget_child_focus (toplevel,
3666 direction == GTK_DIR_UP ?
3667 GTK_DIR_TAB_BACKWARD :
3668 GTK_DIR_TAB_FORWARD);
3672 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3676 if (icon_view->priv->modify_selection_pressed ||
3677 !icon_view->priv->extend_selection_pressed ||
3678 !icon_view->priv->anchor_item ||
3679 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3680 icon_view->priv->anchor_item = item;
3682 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3683 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3685 if (!icon_view->priv->modify_selection_pressed &&
3686 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3688 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3689 dirty = gtk_icon_view_select_all_between (icon_view,
3690 icon_view->priv->anchor_item,
3694 gtk_icon_view_scroll_to_item (icon_view, item);
3697 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3701 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3704 GtkIconViewItem *item;
3705 gboolean dirty = FALSE;
3707 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3710 if (!icon_view->priv->cursor_item)
3715 list = icon_view->priv->items;
3717 list = g_list_last (icon_view->priv->items);
3719 item = list ? list->data : NULL;
3722 item = find_item_page_up_down (icon_view,
3723 icon_view->priv->cursor_item,
3726 if (item == icon_view->priv->cursor_item)
3727 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3732 if (icon_view->priv->modify_selection_pressed ||
3733 !icon_view->priv->extend_selection_pressed ||
3734 !icon_view->priv->anchor_item ||
3735 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3736 icon_view->priv->anchor_item = item;
3738 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3740 if (!icon_view->priv->modify_selection_pressed &&
3741 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3743 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3744 dirty = gtk_icon_view_select_all_between (icon_view,
3745 icon_view->priv->anchor_item,
3749 gtk_icon_view_scroll_to_item (icon_view, item);
3752 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3756 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3759 GtkIconViewItem *item;
3760 GtkCellRenderer *cell = NULL;
3761 gboolean dirty = FALSE;
3763 GtkDirectionType direction;
3765 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3768 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3770 if (!icon_view->priv->cursor_item)
3775 list = icon_view->priv->items;
3777 list = g_list_last (icon_view->priv->items);
3783 /* Give focus to the first cell initially */
3784 _gtk_icon_view_set_cell_data (icon_view, item);
3785 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3794 item = icon_view->priv->cursor_item;
3795 step = count > 0 ? 1 : -1;
3797 /* Save the current focus cell in case we hit the edge */
3798 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3802 _gtk_icon_view_set_cell_data (icon_view, item);
3804 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3807 item = find_item (icon_view, item, 0, step);
3813 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3815 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3817 gtk_widget_child_focus (toplevel,
3818 direction == GTK_DIR_LEFT ?
3819 GTK_DIR_TAB_BACKWARD :
3820 GTK_DIR_TAB_FORWARD);
3824 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3828 if (icon_view->priv->modify_selection_pressed ||
3829 !icon_view->priv->extend_selection_pressed ||
3830 !icon_view->priv->anchor_item ||
3831 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3832 icon_view->priv->anchor_item = item;
3834 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3835 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3837 if (!icon_view->priv->modify_selection_pressed &&
3838 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3840 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3841 dirty = gtk_icon_view_select_all_between (icon_view,
3842 icon_view->priv->anchor_item,
3846 gtk_icon_view_scroll_to_item (icon_view, item);
3849 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3853 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3856 GtkIconViewItem *item;
3858 gboolean dirty = FALSE;
3860 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3864 list = icon_view->priv->items;
3866 list = g_list_last (icon_view->priv->items);
3868 item = list ? list->data : NULL;
3870 if (item == icon_view->priv->cursor_item)
3871 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3876 if (icon_view->priv->modify_selection_pressed ||
3877 !icon_view->priv->extend_selection_pressed ||
3878 !icon_view->priv->anchor_item ||
3879 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3880 icon_view->priv->anchor_item = item;
3882 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3884 if (!icon_view->priv->modify_selection_pressed &&
3885 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3887 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3888 dirty = gtk_icon_view_select_all_between (icon_view,
3889 icon_view->priv->anchor_item,
3893 gtk_icon_view_scroll_to_item (icon_view, item);
3896 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3900 * gtk_icon_view_scroll_to_path:
3901 * @icon_view: A #GtkIconView.
3902 * @path: The path of the item to move to.
3903 * @use_align: whether to use alignment arguments, or %FALSE.
3904 * @row_align: The vertical alignment of the item specified by @path.
3905 * @col_align: The horizontal alignment of the item specified by @path.
3907 * Moves the alignments of @icon_view to the position specified by @path.
3908 * @row_align determines where the row is placed, and @col_align determines
3909 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3910 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3913 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3914 * tree does the minimum amount of work to scroll the item onto the screen.
3915 * This means that the item will be scrolled to the edge closest to its current
3916 * position. If the item is currently visible on the screen, nothing is done.
3918 * This function only works if the model is set, and @path is a valid row on
3919 * the model. If the model changes before the @icon_view is realized, the
3920 * centered path will be modified to reflect this change.
3925 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3931 GtkIconViewItem *item = NULL;
3934 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3935 g_return_if_fail (path != NULL);
3936 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3937 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3939 widget = GTK_WIDGET (icon_view);
3941 if (gtk_tree_path_get_depth (path) > 0)
3942 item = g_list_nth_data (icon_view->priv->items,
3943 gtk_tree_path_get_indices(path)[0]);
3945 if (!item || item->cell_area.width < 0 ||
3946 !gtk_widget_get_realized (widget))
3948 if (icon_view->priv->scroll_to_path)
3949 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3951 icon_view->priv->scroll_to_path = NULL;
3954 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3956 icon_view->priv->scroll_to_use_align = use_align;
3957 icon_view->priv->scroll_to_row_align = row_align;
3958 icon_view->priv->scroll_to_col_align = col_align;
3965 GtkAllocation allocation;
3968 GdkRectangle item_area =
3970 item->cell_area.x - icon_view->priv->item_padding,
3971 item->cell_area.y - icon_view->priv->item_padding,
3972 item->cell_area.width + icon_view->priv->item_padding * 2,
3973 item->cell_area.height + icon_view->priv->item_padding * 2
3976 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3978 gtk_widget_get_allocation (widget, &allocation);
3980 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
3982 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3983 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
3985 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
3987 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3988 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
3990 gtk_adjustment_changed (icon_view->priv->hadjustment);
3991 gtk_adjustment_changed (icon_view->priv->vadjustment);
3994 gtk_icon_view_scroll_to_item (icon_view, item);
3999 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4000 GtkIconViewItem *item)
4002 GtkIconViewPrivate *priv = icon_view->priv;
4003 GtkWidget *widget = GTK_WIDGET (icon_view);
4004 GtkAdjustment *hadj, *vadj;
4005 GtkAllocation allocation;
4007 GdkRectangle item_area;
4009 item_area.x = item->cell_area.x - priv->item_padding;
4010 item_area.y = item->cell_area.y - priv->item_padding;
4011 item_area.width = item->cell_area.width + priv->item_padding * 2;
4012 item_area.height = item->cell_area.height + priv->item_padding * 2;
4014 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4015 gtk_widget_get_allocation (widget, &allocation);
4017 hadj = icon_view->priv->hadjustment;
4018 vadj = icon_view->priv->vadjustment;
4020 if (y + item_area.y < 0)
4021 gtk_adjustment_set_value (vadj,
4022 gtk_adjustment_get_value (vadj)
4024 else if (y + item_area.y + item_area.height > allocation.height)
4025 gtk_adjustment_set_value (vadj,
4026 gtk_adjustment_get_value (vadj)
4027 + y + item_area.y + item_area.height - allocation.height);
4029 if (x + item_area.x < 0)
4030 gtk_adjustment_set_value (hadj,
4031 gtk_adjustment_get_value (hadj)
4033 else if (x + item_area.x + item_area.width > allocation.width)
4034 gtk_adjustment_set_value (hadj,
4035 gtk_adjustment_get_value (hadj)
4036 + x + item_area.x + item_area.width - allocation.width);
4038 gtk_adjustment_changed (hadj);
4039 gtk_adjustment_changed (vadj);
4042 /* GtkCellLayout implementation */
4045 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4046 GtkCellArea *cell_area)
4048 GtkIconViewPrivate *priv = icon_view->priv;
4050 if (priv->cell_area)
4054 priv->cell_area = cell_area;
4056 priv->cell_area = gtk_cell_area_box_new ();
4058 g_object_ref_sink (priv->cell_area);
4060 if (GTK_IS_ORIENTABLE (priv->cell_area))
4061 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4063 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4065 priv->add_editable_id =
4066 g_signal_connect (priv->cell_area, "add-editable",
4067 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4068 priv->remove_editable_id =
4069 g_signal_connect (priv->cell_area, "remove-editable",
4070 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4071 priv->context_changed_id =
4072 g_signal_connect (priv->cell_area_context, "notify",
4073 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4075 update_text_cell (icon_view);
4076 update_pixbuf_cell (icon_view);
4079 static GtkCellArea *
4080 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4082 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4083 GtkIconViewPrivate *priv = icon_view->priv;
4085 if (G_UNLIKELY (!priv->cell_area))
4086 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4088 return icon_view->priv->cell_area;
4092 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4093 GtkIconViewItem *item)
4095 gboolean iters_persist;
4098 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4104 path = gtk_tree_path_new_from_indices (item->index, -1);
4105 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4107 gtk_tree_path_free (path);
4112 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4113 icon_view->priv->model,
4114 &iter, FALSE, FALSE);
4123 * gtk_icon_view_new:
4125 * Creates a new #GtkIconView widget
4127 * Return value: A newly created #GtkIconView widget
4132 gtk_icon_view_new (void)
4134 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4138 * gtk_icon_view_new_with_area:
4139 * @area: the #GtkCellArea to use to layout cells
4141 * Creates a new #GtkIconView widget using the
4142 * specified @area to layout cells inside the icons.
4144 * Return value: A newly created #GtkIconView widget
4149 gtk_icon_view_new_with_area (GtkCellArea *area)
4151 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4155 * gtk_icon_view_new_with_model:
4156 * @model: The model.
4158 * Creates a new #GtkIconView widget with the model @model.
4160 * Return value: A newly created #GtkIconView widget.
4165 gtk_icon_view_new_with_model (GtkTreeModel *model)
4167 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4171 * gtk_icon_view_convert_widget_to_bin_window_coords:
4172 * @icon_view: a #GtkIconView
4173 * @wx: X coordinate relative to the widget
4174 * @wy: Y coordinate relative to the widget
4175 * @bx: (out): return location for bin_window X coordinate
4176 * @by: (out): return location for bin_window Y coordinate
4178 * Converts widget coordinates to coordinates for the bin_window,
4179 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4184 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4192 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4194 if (icon_view->priv->bin_window)
4195 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4206 * gtk_icon_view_get_path_at_pos:
4207 * @icon_view: A #GtkIconView.
4208 * @x: The x position to be identified
4209 * @y: The y position to be identified
4211 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4212 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4213 * the cell at the specified position.
4214 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4215 * widget coordinates to bin_window coordinates.
4217 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4218 * if no icon exists at that position.
4223 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4227 GtkIconViewItem *item;
4230 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4232 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4237 path = gtk_tree_path_new_from_indices (item->index, -1);
4243 * gtk_icon_view_get_item_at_pos:
4244 * @icon_view: A #GtkIconView.
4245 * @x: The x position to be identified
4246 * @y: The y position to be identified
4247 * @path: (out) (allow-none): Return location for the path, or %NULL
4248 * @cell: (out) (allow-none): Return location for the renderer
4249 * responsible for the cell at (@x, @y), or %NULL
4251 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4252 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4253 * obtains the cell at the specified position. The returned path should
4254 * be freed with gtk_tree_path_free().
4255 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4256 * widget coordinates to bin_window coordinates.
4258 * Return value: %TRUE if an item exists at the specified position
4263 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4267 GtkCellRenderer **cell)
4269 GtkIconViewItem *item;
4270 GtkCellRenderer *renderer = NULL;
4272 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4274 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4279 *path = gtk_tree_path_new_from_indices (item->index, -1);
4287 return (item != NULL);
4291 * gtk_icon_view_set_tooltip_item:
4292 * @icon_view: a #GtkIconView
4293 * @tooltip: a #GtkTooltip
4294 * @path: a #GtkTreePath
4296 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4297 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4298 * See also gtk_tooltip_set_tip_area().
4303 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4304 GtkTooltip *tooltip,
4307 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4308 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4310 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4314 * gtk_icon_view_set_tooltip_cell:
4315 * @icon_view: a #GtkIconView
4316 * @tooltip: a #GtkTooltip
4317 * @path: a #GtkTreePath
4318 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4320 * Sets the tip area of @tooltip to the area which @cell occupies in
4321 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4323 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4328 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4329 GtkTooltip *tooltip,
4331 GtkCellRenderer *cell)
4334 GtkIconViewItem *item = NULL;
4337 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4338 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4339 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4341 if (gtk_tree_path_get_depth (path) > 0)
4342 item = g_list_nth_data (icon_view->priv->items,
4343 gtk_tree_path_get_indices(path)[0]);
4350 GtkCellAreaContext *context;
4352 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4353 _gtk_icon_view_set_cell_data (icon_view, item);
4354 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4355 GTK_WIDGET (icon_view),
4356 cell, (GdkRectangle *)item, &rect);
4360 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4361 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4362 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4363 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4366 if (icon_view->priv->bin_window)
4368 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4373 gtk_tooltip_set_tip_area (tooltip, &rect);
4378 * gtk_icon_view_get_tooltip_context:
4379 * @icon_view: an #GtkIconView
4380 * @x: (inout): the x coordinate (relative to widget coordinates)
4381 * @y: (inout): the y coordinate (relative to widget coordinates)
4382 * @keyboard_tip: whether this is a keyboard tooltip or not
4383 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4384 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4385 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4387 * This function is supposed to be used in a #GtkWidget::query-tooltip
4388 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4389 * which are received in the signal handler, should be passed to this
4390 * function without modification.
4392 * The return value indicates whether there is an icon view item at the given
4393 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4394 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4395 * @model, @path and @iter which have been provided will be set to point to
4396 * that row and the corresponding model. @x and @y will always be converted
4397 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4399 * Return value: whether or not the given tooltip context points to a item
4404 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4407 gboolean keyboard_tip,
4408 GtkTreeModel **model,
4412 GtkTreePath *tmppath = NULL;
4414 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4415 g_return_val_if_fail (x != NULL, FALSE);
4416 g_return_val_if_fail (y != NULL, FALSE);
4420 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4427 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4430 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4435 *model = gtk_icon_view_get_model (icon_view);
4438 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4444 gtk_tree_path_free (tmppath);
4450 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4453 gboolean keyboard_tip,
4454 GtkTooltip *tooltip,
4460 GtkTreeModel *model;
4461 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4463 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4466 &model, &path, &iter))
4469 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4473 gtk_tree_path_free (path);
4477 gtk_tooltip_set_markup (tooltip, str);
4478 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4480 gtk_tree_path_free (path);
4488 * gtk_icon_view_set_tooltip_column:
4489 * @icon_view: a #GtkIconView
4490 * @column: an integer, which is a valid column number for @icon_view's model
4492 * If you only plan to have simple (text-only) tooltips on full items, you
4493 * can use this function to have #GtkIconView handle these automatically
4494 * for you. @column should be set to the column in @icon_view's model
4495 * containing the tooltip texts, or -1 to disable this feature.
4497 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4498 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4500 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4501 * so &, <, etc have to be escaped in the text.
4506 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4509 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4511 if (column == icon_view->priv->tooltip_column)
4516 g_signal_handlers_disconnect_by_func (icon_view,
4517 gtk_icon_view_set_tooltip_query_cb,
4519 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4523 if (icon_view->priv->tooltip_column == -1)
4525 g_signal_connect (icon_view, "query-tooltip",
4526 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4527 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4531 icon_view->priv->tooltip_column = column;
4532 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4536 * gtk_icon_view_get_tooltip_column:
4537 * @icon_view: a #GtkIconView
4539 * Returns the column of @icon_view's model which is being used for
4540 * displaying tooltips on @icon_view's rows.
4542 * Return value: the index of the tooltip column that is currently being
4543 * used, or -1 if this is disabled.
4548 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4550 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4552 return icon_view->priv->tooltip_column;
4556 * gtk_icon_view_get_visible_range:
4557 * @icon_view: A #GtkIconView
4558 * @start_path: (out) (allow-none): Return location for start of region,
4560 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4562 * Sets @start_path and @end_path to be the first and last visible path.
4563 * Note that there may be invisible paths in between.
4565 * Both paths should be freed with gtk_tree_path_free() after use.
4567 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4572 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4573 GtkTreePath **start_path,
4574 GtkTreePath **end_path)
4576 gint start_index = -1;
4577 gint end_index = -1;
4580 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4582 if (icon_view->priv->hadjustment == NULL ||
4583 icon_view->priv->vadjustment == NULL)
4586 if (start_path == NULL && end_path == NULL)
4589 for (icons = icon_view->priv->items; icons; icons = icons->next)
4591 GtkIconViewItem *item = icons->data;
4592 GdkRectangle *item_area = (GdkRectangle *)item;
4594 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4595 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4597 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4598 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4600 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4601 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4603 if (start_index == -1)
4604 start_index = item->index;
4605 end_index = item->index;
4609 if (start_path && start_index != -1)
4610 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4611 if (end_path && end_index != -1)
4612 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4614 return start_index != -1;
4618 * gtk_icon_view_selected_foreach:
4619 * @icon_view: A #GtkIconView.
4620 * @func: (scope call): The function to call for each selected icon.
4621 * @data: User data to pass to the function.
4623 * Calls a function for each selected icon. Note that the model or
4624 * selection cannot be modified from within this function.
4629 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4630 GtkIconViewForeachFunc func,
4635 for (list = icon_view->priv->items; list; list = list->next)
4637 GtkIconViewItem *item = list->data;
4638 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4641 (* func) (icon_view, path, data);
4643 gtk_tree_path_free (path);
4648 * gtk_icon_view_set_selection_mode:
4649 * @icon_view: A #GtkIconView.
4650 * @mode: The selection mode
4652 * Sets the selection mode of the @icon_view.
4657 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4658 GtkSelectionMode mode)
4660 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4662 if (mode == icon_view->priv->selection_mode)
4665 if (mode == GTK_SELECTION_NONE ||
4666 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4667 gtk_icon_view_unselect_all (icon_view);
4669 icon_view->priv->selection_mode = mode;
4671 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4675 * gtk_icon_view_get_selection_mode:
4676 * @icon_view: A #GtkIconView.
4678 * Gets the selection mode of the @icon_view.
4680 * Return value: the current selection mode
4685 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4687 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4689 return icon_view->priv->selection_mode;
4693 * gtk_icon_view_set_model:
4694 * @icon_view: A #GtkIconView.
4695 * @model: (allow-none): The model.
4697 * Sets the model for a #GtkIconView.
4698 * If the @icon_view already has a model set, it will remove
4699 * it before setting the new model. If @model is %NULL, then
4700 * it will unset the old model.
4705 gtk_icon_view_set_model (GtkIconView *icon_view,
4706 GtkTreeModel *model)
4708 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4709 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4711 if (icon_view->priv->model == model)
4714 if (icon_view->priv->scroll_to_path)
4716 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4717 icon_view->priv->scroll_to_path = NULL;
4720 /* The area can be NULL while disposing */
4721 if (icon_view->priv->cell_area)
4722 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4728 if (icon_view->priv->pixbuf_column != -1)
4730 column_type = gtk_tree_model_get_column_type (model,
4731 icon_view->priv->pixbuf_column);
4733 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4736 if (icon_view->priv->text_column != -1)
4738 column_type = gtk_tree_model_get_column_type (model,
4739 icon_view->priv->text_column);
4741 g_return_if_fail (column_type == G_TYPE_STRING);
4744 if (icon_view->priv->markup_column != -1)
4746 column_type = gtk_tree_model_get_column_type (model,
4747 icon_view->priv->markup_column);
4749 g_return_if_fail (column_type == G_TYPE_STRING);
4754 if (icon_view->priv->model)
4756 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4757 gtk_icon_view_row_changed,
4759 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4760 gtk_icon_view_row_inserted,
4762 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4763 gtk_icon_view_row_deleted,
4765 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4766 gtk_icon_view_rows_reordered,
4769 g_object_unref (icon_view->priv->model);
4771 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4772 g_list_free (icon_view->priv->items);
4773 icon_view->priv->items = NULL;
4774 icon_view->priv->anchor_item = NULL;
4775 icon_view->priv->cursor_item = NULL;
4776 icon_view->priv->last_single_clicked = NULL;
4777 icon_view->priv->last_prelight = NULL;
4778 icon_view->priv->width = 0;
4779 icon_view->priv->height = 0;
4782 icon_view->priv->model = model;
4784 if (icon_view->priv->model)
4786 g_object_ref (icon_view->priv->model);
4787 g_signal_connect (icon_view->priv->model,
4789 G_CALLBACK (gtk_icon_view_row_changed),
4791 g_signal_connect (icon_view->priv->model,
4793 G_CALLBACK (gtk_icon_view_row_inserted),
4795 g_signal_connect (icon_view->priv->model,
4797 G_CALLBACK (gtk_icon_view_row_deleted),
4799 g_signal_connect (icon_view->priv->model,
4801 G_CALLBACK (gtk_icon_view_rows_reordered),
4804 gtk_icon_view_build_items (icon_view);
4806 gtk_icon_view_layout (icon_view);
4809 g_object_notify (G_OBJECT (icon_view), "model");
4811 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4812 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4816 * gtk_icon_view_get_model:
4817 * @icon_view: a #GtkIconView
4819 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4822 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4823 * currently being used.
4828 gtk_icon_view_get_model (GtkIconView *icon_view)
4830 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4832 return icon_view->priv->model;
4836 update_text_cell (GtkIconView *icon_view)
4838 if (!icon_view->priv->cell_area)
4841 if (icon_view->priv->text_column == -1 &&
4842 icon_view->priv->markup_column == -1)
4844 if (icon_view->priv->text_cell != NULL)
4846 gtk_cell_area_remove (icon_view->priv->cell_area,
4847 icon_view->priv->text_cell);
4848 icon_view->priv->text_cell = NULL;
4853 if (icon_view->priv->text_cell == NULL)
4855 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4857 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4860 if (icon_view->priv->markup_column != -1)
4861 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4862 icon_view->priv->text_cell,
4863 "markup", icon_view->priv->markup_column,
4866 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4867 icon_view->priv->text_cell,
4868 "text", icon_view->priv->text_column,
4871 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4872 g_object_set (icon_view->priv->text_cell,
4873 "alignment", PANGO_ALIGN_CENTER,
4874 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4879 g_object_set (icon_view->priv->text_cell,
4880 "alignment", PANGO_ALIGN_LEFT,
4881 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4889 update_pixbuf_cell (GtkIconView *icon_view)
4891 if (!icon_view->priv->cell_area)
4894 if (icon_view->priv->pixbuf_column == -1)
4896 if (icon_view->priv->pixbuf_cell != NULL)
4898 gtk_cell_area_remove (icon_view->priv->cell_area,
4899 icon_view->priv->pixbuf_cell);
4901 icon_view->priv->pixbuf_cell = NULL;
4906 if (icon_view->priv->pixbuf_cell == NULL)
4908 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4910 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4913 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4914 icon_view->priv->pixbuf_cell,
4915 "pixbuf", icon_view->priv->pixbuf_column,
4918 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4919 g_object_set (icon_view->priv->pixbuf_cell,
4924 g_object_set (icon_view->priv->pixbuf_cell,
4932 * gtk_icon_view_set_text_column:
4933 * @icon_view: A #GtkIconView.
4934 * @column: A column in the currently used model, or -1 to display no text
4936 * Sets the column with text for @icon_view to be @column. The text
4937 * column must be of type #G_TYPE_STRING.
4942 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4945 if (column == icon_view->priv->text_column)
4949 icon_view->priv->text_column = -1;
4952 if (icon_view->priv->model != NULL)
4956 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4958 g_return_if_fail (column_type == G_TYPE_STRING);
4961 icon_view->priv->text_column = column;
4964 if (icon_view->priv->cell_area)
4965 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4967 update_text_cell (icon_view);
4969 gtk_icon_view_invalidate_sizes (icon_view);
4971 g_object_notify (G_OBJECT (icon_view), "text-column");
4975 * gtk_icon_view_get_text_column:
4976 * @icon_view: A #GtkIconView.
4978 * Returns the column with text for @icon_view.
4980 * Returns: the text column, or -1 if it's unset.
4985 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4987 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4989 return icon_view->priv->text_column;
4993 * gtk_icon_view_set_markup_column:
4994 * @icon_view: A #GtkIconView.
4995 * @column: A column in the currently used model, or -1 to display no text
4997 * Sets the column with markup information for @icon_view to be
4998 * @column. The markup column must be of type #G_TYPE_STRING.
4999 * If the markup column is set to something, it overrides
5000 * the text column set by gtk_icon_view_set_text_column().
5005 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5008 if (column == icon_view->priv->markup_column)
5012 icon_view->priv->markup_column = -1;
5015 if (icon_view->priv->model != NULL)
5019 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5021 g_return_if_fail (column_type == G_TYPE_STRING);
5024 icon_view->priv->markup_column = column;
5027 if (icon_view->priv->cell_area)
5028 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5030 update_text_cell (icon_view);
5032 gtk_icon_view_invalidate_sizes (icon_view);
5034 g_object_notify (G_OBJECT (icon_view), "markup-column");
5038 * gtk_icon_view_get_markup_column:
5039 * @icon_view: A #GtkIconView.
5041 * Returns the column with markup text for @icon_view.
5043 * Returns: the markup column, or -1 if it's unset.
5048 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5050 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5052 return icon_view->priv->markup_column;
5056 * gtk_icon_view_set_pixbuf_column:
5057 * @icon_view: A #GtkIconView.
5058 * @column: A column in the currently used model, or -1 to disable
5060 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5061 * column must be of type #GDK_TYPE_PIXBUF
5066 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5069 if (column == icon_view->priv->pixbuf_column)
5073 icon_view->priv->pixbuf_column = -1;
5076 if (icon_view->priv->model != NULL)
5080 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5082 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5085 icon_view->priv->pixbuf_column = column;
5088 if (icon_view->priv->cell_area)
5089 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5091 update_pixbuf_cell (icon_view);
5093 gtk_icon_view_invalidate_sizes (icon_view);
5095 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5100 * gtk_icon_view_get_pixbuf_column:
5101 * @icon_view: A #GtkIconView.
5103 * Returns the column with pixbufs for @icon_view.
5105 * Returns: the pixbuf column, or -1 if it's unset.
5110 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5112 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5114 return icon_view->priv->pixbuf_column;
5118 * gtk_icon_view_select_path:
5119 * @icon_view: A #GtkIconView.
5120 * @path: The #GtkTreePath to be selected.
5122 * Selects the row at @path.
5127 gtk_icon_view_select_path (GtkIconView *icon_view,
5130 GtkIconViewItem *item = NULL;
5132 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5133 g_return_if_fail (icon_view->priv->model != NULL);
5134 g_return_if_fail (path != NULL);
5136 if (gtk_tree_path_get_depth (path) > 0)
5137 item = g_list_nth_data (icon_view->priv->items,
5138 gtk_tree_path_get_indices(path)[0]);
5141 _gtk_icon_view_select_item (icon_view, item);
5145 * gtk_icon_view_unselect_path:
5146 * @icon_view: A #GtkIconView.
5147 * @path: The #GtkTreePath to be unselected.
5149 * Unselects the row at @path.
5154 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5157 GtkIconViewItem *item;
5159 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5160 g_return_if_fail (icon_view->priv->model != NULL);
5161 g_return_if_fail (path != NULL);
5163 item = g_list_nth_data (icon_view->priv->items,
5164 gtk_tree_path_get_indices(path)[0]);
5169 _gtk_icon_view_unselect_item (icon_view, item);
5173 * gtk_icon_view_get_selected_items:
5174 * @icon_view: A #GtkIconView.
5176 * Creates a list of paths of all selected items. Additionally, if you are
5177 * planning on modifying the model after calling this function, you may
5178 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5179 * To do this, you can use gtk_tree_row_reference_new().
5181 * To free the return value, use:
5183 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5184 * g_list_free (list);
5187 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5192 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5195 GList *selected = NULL;
5197 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5199 for (list = icon_view->priv->items; list != NULL; list = list->next)
5201 GtkIconViewItem *item = list->data;
5205 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5207 selected = g_list_prepend (selected, path);
5215 * gtk_icon_view_select_all:
5216 * @icon_view: A #GtkIconView.
5218 * Selects all the icons. @icon_view must has its selection mode set
5219 * to #GTK_SELECTION_MULTIPLE.
5224 gtk_icon_view_select_all (GtkIconView *icon_view)
5227 gboolean dirty = FALSE;
5229 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5231 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5234 for (items = icon_view->priv->items; items; items = items->next)
5236 GtkIconViewItem *item = items->data;
5238 if (!item->selected)
5241 item->selected = TRUE;
5242 gtk_icon_view_queue_draw_item (icon_view, item);
5247 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5251 * gtk_icon_view_unselect_all:
5252 * @icon_view: A #GtkIconView.
5254 * Unselects all the icons.
5259 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5261 gboolean dirty = FALSE;
5263 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5265 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5268 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5271 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5275 * gtk_icon_view_path_is_selected:
5276 * @icon_view: A #GtkIconView.
5277 * @path: A #GtkTreePath to check selection on.
5279 * Returns %TRUE if the icon pointed to by @path is currently
5280 * selected. If @path does not point to a valid location, %FALSE is returned.
5282 * Return value: %TRUE if @path is selected.
5287 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5290 GtkIconViewItem *item;
5292 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5293 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5294 g_return_val_if_fail (path != NULL, FALSE);
5296 item = g_list_nth_data (icon_view->priv->items,
5297 gtk_tree_path_get_indices(path)[0]);
5302 return item->selected;
5306 * gtk_icon_view_get_item_row:
5307 * @icon_view: a #GtkIconView
5308 * @path: the #GtkTreePath of the item
5310 * Gets the row in which the item @path is currently
5311 * displayed. Row numbers start at 0.
5313 * Returns: The row in which the item is displayed
5318 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5321 GtkIconViewItem *item;
5323 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5324 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5325 g_return_val_if_fail (path != NULL, -1);
5327 item = g_list_nth_data (icon_view->priv->items,
5328 gtk_tree_path_get_indices(path)[0]);
5337 * gtk_icon_view_get_item_column:
5338 * @icon_view: a #GtkIconView
5339 * @path: the #GtkTreePath of the item
5341 * Gets the column in which the item @path is currently
5342 * displayed. Column numbers start at 0.
5344 * Returns: The column in which the item is displayed
5349 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5352 GtkIconViewItem *item;
5354 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5355 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5356 g_return_val_if_fail (path != NULL, -1);
5358 item = g_list_nth_data (icon_view->priv->items,
5359 gtk_tree_path_get_indices(path)[0]);
5368 * gtk_icon_view_item_activated:
5369 * @icon_view: A #GtkIconView
5370 * @path: The #GtkTreePath to be activated
5372 * Activates the item determined by @path.
5377 gtk_icon_view_item_activated (GtkIconView *icon_view,
5380 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5381 g_return_if_fail (path != NULL);
5383 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5387 * gtk_icon_view_set_item_orientation:
5388 * @icon_view: a #GtkIconView
5389 * @orientation: the relative position of texts and icons
5391 * Sets the ::item-orientation property which determines whether the labels
5392 * are drawn beside the icons instead of below.
5397 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5398 GtkOrientation orientation)
5400 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5402 if (icon_view->priv->item_orientation != orientation)
5404 icon_view->priv->item_orientation = orientation;
5406 if (icon_view->priv->cell_area)
5408 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5409 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5410 icon_view->priv->item_orientation);
5412 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5415 gtk_icon_view_invalidate_sizes (icon_view);
5417 update_text_cell (icon_view);
5418 update_pixbuf_cell (icon_view);
5420 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5425 * gtk_icon_view_get_item_orientation:
5426 * @icon_view: a #GtkIconView
5428 * Returns the value of the ::item-orientation property which determines
5429 * whether the labels are drawn beside the icons instead of below.
5431 * Return value: the relative position of texts and icons
5436 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5438 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5439 GTK_ORIENTATION_VERTICAL);
5441 return icon_view->priv->item_orientation;
5445 * gtk_icon_view_set_columns:
5446 * @icon_view: a #GtkIconView
5447 * @columns: the number of columns
5449 * Sets the ::columns property which determines in how
5450 * many columns the icons are arranged. If @columns is
5451 * -1, the number of columns will be chosen automatically
5452 * to fill the available area.
5457 gtk_icon_view_set_columns (GtkIconView *icon_view,
5460 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5462 if (icon_view->priv->columns != columns)
5464 icon_view->priv->columns = columns;
5466 if (icon_view->priv->cell_area)
5467 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5469 gtk_icon_view_queue_layout (icon_view);
5471 g_object_notify (G_OBJECT (icon_view), "columns");
5476 * gtk_icon_view_get_columns:
5477 * @icon_view: a #GtkIconView
5479 * Returns the value of the ::columns property.
5481 * Return value: the number of columns, or -1
5486 gtk_icon_view_get_columns (GtkIconView *icon_view)
5488 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5490 return icon_view->priv->columns;
5494 * gtk_icon_view_set_item_width:
5495 * @icon_view: a #GtkIconView
5496 * @item_width: the width for each item
5498 * Sets the ::item-width property which specifies the width
5499 * to use for each item. If it is set to -1, the icon view will
5500 * automatically determine a suitable item size.
5505 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5508 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5510 if (icon_view->priv->item_width != item_width)
5512 icon_view->priv->item_width = item_width;
5514 if (icon_view->priv->cell_area)
5515 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5517 gtk_icon_view_invalidate_sizes (icon_view);
5519 update_text_cell (icon_view);
5521 g_object_notify (G_OBJECT (icon_view), "item-width");
5526 * gtk_icon_view_get_item_width:
5527 * @icon_view: a #GtkIconView
5529 * Returns the value of the ::item-width property.
5531 * Return value: the width of a single item, or -1
5536 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5538 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5540 return icon_view->priv->item_width;
5545 * gtk_icon_view_set_spacing:
5546 * @icon_view: a #GtkIconView
5547 * @spacing: the spacing
5549 * Sets the ::spacing property which specifies the space
5550 * which is inserted between the cells (i.e. the icon and
5551 * the text) of an item.
5556 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5559 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5561 if (icon_view->priv->spacing != spacing)
5563 icon_view->priv->spacing = spacing;
5565 if (icon_view->priv->cell_area)
5566 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5568 gtk_icon_view_invalidate_sizes (icon_view);
5570 g_object_notify (G_OBJECT (icon_view), "spacing");
5575 * gtk_icon_view_get_spacing:
5576 * @icon_view: a #GtkIconView
5578 * Returns the value of the ::spacing property.
5580 * Return value: the space between cells
5585 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5587 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5589 return icon_view->priv->spacing;
5593 * gtk_icon_view_set_row_spacing:
5594 * @icon_view: a #GtkIconView
5595 * @row_spacing: the row spacing
5597 * Sets the ::row-spacing property which specifies the space
5598 * which is inserted between the rows of the icon view.
5603 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5606 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5608 if (icon_view->priv->row_spacing != row_spacing)
5610 icon_view->priv->row_spacing = row_spacing;
5612 if (icon_view->priv->cell_area)
5613 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5615 gtk_icon_view_invalidate_sizes (icon_view);
5617 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5622 * gtk_icon_view_get_row_spacing:
5623 * @icon_view: a #GtkIconView
5625 * Returns the value of the ::row-spacing property.
5627 * Return value: the space between rows
5632 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5634 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5636 return icon_view->priv->row_spacing;
5640 * gtk_icon_view_set_column_spacing:
5641 * @icon_view: a #GtkIconView
5642 * @column_spacing: the column spacing
5644 * Sets the ::column-spacing property which specifies the space
5645 * which is inserted between the columns of the icon view.
5650 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5651 gint column_spacing)
5653 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5655 if (icon_view->priv->column_spacing != column_spacing)
5657 icon_view->priv->column_spacing = column_spacing;
5659 if (icon_view->priv->cell_area)
5660 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5662 gtk_icon_view_invalidate_sizes (icon_view);
5664 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5669 * gtk_icon_view_get_column_spacing:
5670 * @icon_view: a #GtkIconView
5672 * Returns the value of the ::column-spacing property.
5674 * Return value: the space between columns
5679 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5681 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5683 return icon_view->priv->column_spacing;
5687 * gtk_icon_view_set_margin:
5688 * @icon_view: a #GtkIconView
5689 * @margin: the margin
5691 * Sets the ::margin property which specifies the space
5692 * which is inserted at the top, bottom, left and right
5698 gtk_icon_view_set_margin (GtkIconView *icon_view,
5701 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5703 if (icon_view->priv->margin != margin)
5705 icon_view->priv->margin = margin;
5707 if (icon_view->priv->cell_area)
5708 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5710 gtk_icon_view_invalidate_sizes (icon_view);
5712 g_object_notify (G_OBJECT (icon_view), "margin");
5717 * gtk_icon_view_get_margin:
5718 * @icon_view: a #GtkIconView
5720 * Returns the value of the ::margin property.
5722 * Return value: the space at the borders
5727 gtk_icon_view_get_margin (GtkIconView *icon_view)
5729 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5731 return icon_view->priv->margin;
5735 * gtk_icon_view_set_item_padding:
5736 * @icon_view: a #GtkIconView
5737 * @item_padding: the item padding
5739 * Sets the #GtkIconView:item-padding property which specifies the padding
5740 * around each of the icon view's items.
5745 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5748 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5750 if (icon_view->priv->item_padding != item_padding)
5752 icon_view->priv->item_padding = item_padding;
5754 if (icon_view->priv->cell_area)
5755 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5757 gtk_icon_view_invalidate_sizes (icon_view);
5759 g_object_notify (G_OBJECT (icon_view), "item-padding");
5764 * gtk_icon_view_get_item_padding:
5765 * @icon_view: a #GtkIconView
5767 * Returns the value of the ::item-padding property.
5769 * Return value: the padding around items
5774 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5776 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5778 return icon_view->priv->item_padding;
5781 /* Get/set whether drag_motion requested the drag data and
5782 * drag_data_received should thus not actually insert the data,
5783 * since the data doesn't result from a drop.
5786 set_status_pending (GdkDragContext *context,
5787 GdkDragAction suggested_action)
5789 g_object_set_data (G_OBJECT (context),
5790 I_("gtk-icon-view-status-pending"),
5791 GINT_TO_POINTER (suggested_action));
5794 static GdkDragAction
5795 get_status_pending (GdkDragContext *context)
5797 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5798 "gtk-icon-view-status-pending"));
5802 unset_reorderable (GtkIconView *icon_view)
5804 if (icon_view->priv->reorderable)
5806 icon_view->priv->reorderable = FALSE;
5807 g_object_notify (G_OBJECT (icon_view), "reorderable");
5812 set_source_row (GdkDragContext *context,
5813 GtkTreeModel *model,
5814 GtkTreePath *source_row)
5817 g_object_set_data_full (G_OBJECT (context),
5818 I_("gtk-icon-view-source-row"),
5819 gtk_tree_row_reference_new (model, source_row),
5820 (GDestroyNotify) gtk_tree_row_reference_free);
5822 g_object_set_data_full (G_OBJECT (context),
5823 I_("gtk-icon-view-source-row"),
5828 get_source_row (GdkDragContext *context)
5830 GtkTreeRowReference *ref;
5832 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5835 return gtk_tree_row_reference_get_path (ref);
5842 GtkTreeRowReference *dest_row;
5843 gboolean empty_view_drop;
5844 gboolean drop_append_mode;
5848 dest_row_free (gpointer data)
5850 DestRow *dr = (DestRow *)data;
5852 gtk_tree_row_reference_free (dr->dest_row);
5857 set_dest_row (GdkDragContext *context,
5858 GtkTreeModel *model,
5859 GtkTreePath *dest_row,
5860 gboolean empty_view_drop,
5861 gboolean drop_append_mode)
5867 g_object_set_data_full (G_OBJECT (context),
5868 I_("gtk-icon-view-dest-row"),
5873 dr = g_new0 (DestRow, 1);
5875 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5876 dr->empty_view_drop = empty_view_drop;
5877 dr->drop_append_mode = drop_append_mode;
5878 g_object_set_data_full (G_OBJECT (context),
5879 I_("gtk-icon-view-dest-row"),
5880 dr, (GDestroyNotify) dest_row_free);
5884 get_dest_row (GdkDragContext *context)
5888 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5892 GtkTreePath *path = NULL;
5895 path = gtk_tree_row_reference_get_path (dr->dest_row);
5896 else if (dr->empty_view_drop)
5897 path = gtk_tree_path_new_from_indices (0, -1);
5901 if (path && dr->drop_append_mode)
5902 gtk_tree_path_next (path);
5911 check_model_dnd (GtkTreeModel *model,
5912 GType required_iface,
5913 const gchar *signal)
5915 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5917 g_warning ("You must override the default '%s' handler "
5918 "on GtkIconView when using models that don't support "
5919 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5920 "is to connect to '%s' and call "
5921 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5922 "the default handler from running. Look at the source code "
5923 "for the default handler in gtkiconview.c to get an idea what "
5924 "your handler should do. (gtkiconview.c is in the GTK+ source "
5925 "code.) If you're using GTK+ from a language other than C, "
5926 "there may be a more natural way to override default handlers, e.g. via derivation.",
5927 signal, g_type_name (required_iface), signal);
5935 remove_scroll_timeout (GtkIconView *icon_view)
5937 if (icon_view->priv->scroll_timeout_id != 0)
5939 g_source_remove (icon_view->priv->scroll_timeout_id);
5941 icon_view->priv->scroll_timeout_id = 0;
5946 gtk_icon_view_autoscroll (GtkIconView *icon_view,
5950 gint px, py, x, y, width, height;
5951 gint hoffset, voffset;
5953 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5955 gdk_window_get_device_position (window, device, &px, &py, NULL);
5956 gdk_window_get_geometry (window, &x, &y, &width, &height);
5958 /* see if we are near the edge. */
5959 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5961 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5963 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5965 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5968 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5969 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5972 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5973 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5977 GtkIconView *icon_view;
5982 drag_scroll_timeout (gpointer datap)
5984 DragScrollData *data = datap;
5986 gtk_icon_view_autoscroll (data->icon_view, data->device);
5992 drag_scroll_data_free (DragScrollData *data)
5994 g_slice_free (DragScrollData, data);
5998 set_destination (GtkIconView *icon_view,
5999 GdkDragContext *context,
6002 GdkDragAction *suggested_action,
6006 GtkTreePath *path = NULL;
6007 GtkIconViewDropPosition pos;
6008 GtkIconViewDropPosition old_pos;
6009 GtkTreePath *old_dest_path = NULL;
6010 gboolean can_drop = FALSE;
6012 widget = GTK_WIDGET (icon_view);
6014 *suggested_action = 0;
6017 if (!icon_view->priv->dest_set)
6019 /* someone unset us as a drag dest, note that if
6020 * we return FALSE drag_leave isn't called
6023 gtk_icon_view_set_drag_dest_item (icon_view,
6025 GTK_ICON_VIEW_DROP_LEFT);
6027 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6029 return FALSE; /* no longer a drop site */
6032 *target = gtk_drag_dest_find_target (widget, context,
6033 gtk_drag_dest_get_target_list (widget));
6034 if (*target == GDK_NONE)
6037 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6040 GtkTreeModel *model;
6042 /* the row got dropped on empty space, let's setup a special case
6046 gtk_tree_path_free (path);
6048 model = gtk_icon_view_get_model (icon_view);
6050 n_children = gtk_tree_model_iter_n_children (model, NULL);
6053 pos = GTK_ICON_VIEW_DROP_BELOW;
6054 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6058 pos = GTK_ICON_VIEW_DROP_ABOVE;
6059 path = gtk_tree_path_new_from_indices (0, -1);
6069 gtk_icon_view_get_drag_dest_item (icon_view,
6074 gtk_tree_path_free (old_dest_path);
6076 if (TRUE /* FIXME if the location droppable predicate */)
6084 GtkWidget *source_widget;
6086 *suggested_action = gdk_drag_context_get_suggested_action (context);
6087 source_widget = gtk_drag_get_source_widget (context);
6089 if (source_widget == widget)
6091 /* Default to MOVE, unless the user has
6092 * pressed ctrl or shift to affect available actions
6094 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6095 *suggested_action = GDK_ACTION_MOVE;
6098 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6103 /* can't drop here */
6104 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6106 GTK_ICON_VIEW_DROP_LEFT);
6110 gtk_tree_path_free (path);
6116 get_logical_destination (GtkIconView *icon_view,
6117 gboolean *drop_append_mode)
6119 /* adjust path to point to the row the drop goes in front of */
6120 GtkTreePath *path = NULL;
6121 GtkIconViewDropPosition pos;
6123 *drop_append_mode = FALSE;
6125 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6130 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6131 pos == GTK_ICON_VIEW_DROP_BELOW)
6134 GtkTreeModel *model = icon_view->priv->model;
6136 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6137 !gtk_tree_model_iter_next (model, &iter))
6138 *drop_append_mode = TRUE;
6141 *drop_append_mode = FALSE;
6142 gtk_tree_path_next (path);
6150 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6151 GdkEventMotion *event)
6153 GtkWidget *widget = GTK_WIDGET (icon_view);
6154 GdkDragContext *context;
6155 GtkTreePath *path = NULL;
6157 GtkTreeModel *model;
6158 gboolean retval = FALSE;
6160 if (!icon_view->priv->source_set)
6163 if (icon_view->priv->pressed_button < 0)
6166 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6167 icon_view->priv->press_start_x,
6168 icon_view->priv->press_start_y,
6169 event->x, event->y))
6172 model = gtk_icon_view_get_model (icon_view);
6177 button = icon_view->priv->pressed_button;
6178 icon_view->priv->pressed_button = -1;
6180 path = gtk_icon_view_get_path_at_pos (icon_view,
6181 icon_view->priv->press_start_x,
6182 icon_view->priv->press_start_y);
6187 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6188 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6192 /* FIXME Check whether we're a start button, if not return FALSE and
6196 /* Now we can begin the drag */
6200 context = gtk_drag_begin (widget,
6201 gtk_drag_source_get_target_list (widget),
6202 icon_view->priv->source_actions,
6206 set_source_row (context, model, path);
6210 gtk_tree_path_free (path);
6215 /* Source side drag signals */
6217 gtk_icon_view_drag_begin (GtkWidget *widget,
6218 GdkDragContext *context)
6220 GtkIconView *icon_view;
6221 GtkIconViewItem *item;
6222 cairo_surface_t *icon;
6226 icon_view = GTK_ICON_VIEW (widget);
6228 /* if the user uses a custom DnD impl, we don't set the icon here */
6229 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6232 item = _gtk_icon_view_get_item_at_coords (icon_view,
6233 icon_view->priv->press_start_x,
6234 icon_view->priv->press_start_y,
6238 g_return_if_fail (item != NULL);
6240 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6241 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6243 path = gtk_tree_path_new_from_indices (item->index, -1);
6244 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6245 gtk_tree_path_free (path);
6247 cairo_surface_set_device_offset (icon, -x, -y);
6249 gtk_drag_set_icon_surface (context, icon);
6251 cairo_surface_destroy (icon);
6255 gtk_icon_view_drag_end (GtkWidget *widget,
6256 GdkDragContext *context)
6262 gtk_icon_view_drag_data_get (GtkWidget *widget,
6263 GdkDragContext *context,
6264 GtkSelectionData *selection_data,
6268 GtkIconView *icon_view;
6269 GtkTreeModel *model;
6270 GtkTreePath *source_row;
6272 icon_view = GTK_ICON_VIEW (widget);
6273 model = gtk_icon_view_get_model (icon_view);
6278 if (!icon_view->priv->source_set)
6281 source_row = get_source_row (context);
6283 if (source_row == NULL)
6286 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6287 * any model; for DragSource models there are some other targets
6291 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6292 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6297 /* If drag_data_get does nothing, try providing row data. */
6298 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6299 gtk_tree_set_row_drag_data (selection_data,
6304 gtk_tree_path_free (source_row);
6308 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6309 GdkDragContext *context)
6311 GtkTreeModel *model;
6312 GtkIconView *icon_view;
6313 GtkTreePath *source_row;
6315 icon_view = GTK_ICON_VIEW (widget);
6316 model = gtk_icon_view_get_model (icon_view);
6318 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6321 if (!icon_view->priv->source_set)
6324 source_row = get_source_row (context);
6326 if (source_row == NULL)
6329 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6332 gtk_tree_path_free (source_row);
6334 set_source_row (context, NULL, NULL);
6337 /* Target side drag signals */
6339 gtk_icon_view_drag_leave (GtkWidget *widget,
6340 GdkDragContext *context,
6343 GtkIconView *icon_view;
6345 icon_view = GTK_ICON_VIEW (widget);
6347 /* unset any highlight row */
6348 gtk_icon_view_set_drag_dest_item (icon_view,
6350 GTK_ICON_VIEW_DROP_LEFT);
6352 remove_scroll_timeout (icon_view);
6356 gtk_icon_view_drag_motion (GtkWidget *widget,
6357 GdkDragContext *context,
6362 GtkTreePath *path = NULL;
6363 GtkIconViewDropPosition pos;
6364 GtkIconView *icon_view;
6365 GdkDragAction suggested_action = 0;
6369 icon_view = GTK_ICON_VIEW (widget);
6371 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6374 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6376 /* we only know this *after* set_desination_row */
6377 empty = icon_view->priv->empty_view_drop;
6379 if (path == NULL && !empty)
6381 /* Can't drop here. */
6382 gdk_drag_status (context, 0, time);
6386 if (icon_view->priv->scroll_timeout_id == 0)
6388 DragScrollData *data = g_slice_new (DragScrollData);
6389 data->icon_view = icon_view;
6390 data->device = gdk_drag_context_get_device (context);
6392 icon_view->priv->scroll_timeout_id =
6393 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6396 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6398 /* Request data so we can use the source row when
6399 * determining whether to accept the drop
6401 set_status_pending (context, suggested_action);
6402 gtk_drag_get_data (widget, context, target, time);
6406 set_status_pending (context, 0);
6407 gdk_drag_status (context, suggested_action, time);
6412 gtk_tree_path_free (path);
6418 gtk_icon_view_drag_drop (GtkWidget *widget,
6419 GdkDragContext *context,
6424 GtkIconView *icon_view;
6426 GdkDragAction suggested_action = 0;
6427 GdkAtom target = GDK_NONE;
6428 GtkTreeModel *model;
6429 gboolean drop_append_mode;
6431 icon_view = GTK_ICON_VIEW (widget);
6432 model = gtk_icon_view_get_model (icon_view);
6434 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6436 if (!icon_view->priv->dest_set)
6439 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6442 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6445 path = get_logical_destination (icon_view, &drop_append_mode);
6447 if (target != GDK_NONE && path != NULL)
6449 /* in case a motion had requested drag data, change things so we
6450 * treat drag data receives as a drop.
6452 set_status_pending (context, 0);
6453 set_dest_row (context, model, path,
6454 icon_view->priv->empty_view_drop, drop_append_mode);
6458 gtk_tree_path_free (path);
6460 /* Unset this thing */
6461 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6463 if (target != GDK_NONE)
6465 gtk_drag_get_data (widget, context, target, time);
6473 gtk_icon_view_drag_data_received (GtkWidget *widget,
6474 GdkDragContext *context,
6477 GtkSelectionData *selection_data,
6482 gboolean accepted = FALSE;
6483 GtkTreeModel *model;
6484 GtkIconView *icon_view;
6485 GtkTreePath *dest_row;
6486 GdkDragAction suggested_action;
6487 gboolean drop_append_mode;
6489 icon_view = GTK_ICON_VIEW (widget);
6490 model = gtk_icon_view_get_model (icon_view);
6492 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6495 if (!icon_view->priv->dest_set)
6498 suggested_action = get_status_pending (context);
6500 if (suggested_action)
6502 /* We are getting this data due to a request in drag_motion,
6503 * rather than due to a request in drag_drop, so we are just
6504 * supposed to call drag_status, not actually paste in the
6507 path = get_logical_destination (icon_view, &drop_append_mode);
6510 suggested_action = 0;
6512 if (suggested_action)
6514 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6517 suggested_action = 0;
6520 gdk_drag_status (context, suggested_action, time);
6523 gtk_tree_path_free (path);
6525 /* If you can't drop, remove user drop indicator until the next motion */
6526 if (suggested_action == 0)
6527 gtk_icon_view_set_drag_dest_item (icon_view,
6529 GTK_ICON_VIEW_DROP_LEFT);
6534 dest_row = get_dest_row (context);
6536 if (dest_row == NULL)
6539 if (gtk_selection_data_get_length (selection_data) >= 0)
6541 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6547 gtk_drag_finish (context,
6549 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6552 gtk_tree_path_free (dest_row);
6555 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6558 /* Drag-and-Drop support */
6560 * gtk_icon_view_enable_model_drag_source:
6561 * @icon_view: a #GtkIconTreeView
6562 * @start_button_mask: Mask of allowed buttons to start drag
6563 * @targets: (array length=n_targets): the table of targets that the drag will
6565 * @n_targets: the number of items in @targets
6566 * @actions: the bitmask of possible actions for a drag from this
6569 * Turns @icon_view into a drag source for automatic DND. Calling this
6570 * method sets #GtkIconView:reorderable to %FALSE.
6575 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6576 GdkModifierType start_button_mask,
6577 const GtkTargetEntry *targets,
6579 GdkDragAction actions)
6581 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6583 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6585 icon_view->priv->start_button_mask = start_button_mask;
6586 icon_view->priv->source_actions = actions;
6588 icon_view->priv->source_set = TRUE;
6590 unset_reorderable (icon_view);
6594 * gtk_icon_view_enable_model_drag_dest:
6595 * @icon_view: a #GtkIconView
6596 * @targets: (array length=n_targets): the table of targets that the drag will
6598 * @n_targets: the number of items in @targets
6599 * @actions: the bitmask of possible actions for a drag to this
6602 * Turns @icon_view into a drop destination for automatic DND. Calling this
6603 * method sets #GtkIconView:reorderable to %FALSE.
6608 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6609 const GtkTargetEntry *targets,
6611 GdkDragAction actions)
6613 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6615 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6617 icon_view->priv->dest_actions = actions;
6619 icon_view->priv->dest_set = TRUE;
6621 unset_reorderable (icon_view);
6625 * gtk_icon_view_unset_model_drag_source:
6626 * @icon_view: a #GtkIconView
6628 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6629 * method sets #GtkIconView:reorderable to %FALSE.
6634 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6636 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6638 if (icon_view->priv->source_set)
6640 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6641 icon_view->priv->source_set = FALSE;
6644 unset_reorderable (icon_view);
6648 * gtk_icon_view_unset_model_drag_dest:
6649 * @icon_view: a #GtkIconView
6651 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6652 * method sets #GtkIconView:reorderable to %FALSE.
6657 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6659 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6661 if (icon_view->priv->dest_set)
6663 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6664 icon_view->priv->dest_set = FALSE;
6667 unset_reorderable (icon_view);
6670 /* These are useful to implement your own custom stuff. */
6672 * gtk_icon_view_set_drag_dest_item:
6673 * @icon_view: a #GtkIconView
6674 * @path: (allow-none): The path of the item to highlight, or %NULL.
6675 * @pos: Specifies where to drop, relative to the item
6677 * Sets the item that is highlighted for feedback.
6682 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6684 GtkIconViewDropPosition pos)
6686 /* Note; this function is exported to allow a custom DND
6687 * implementation, so it can't touch TreeViewDragInfo
6690 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6692 if (icon_view->priv->dest_item)
6694 GtkTreePath *current_path;
6695 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6696 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6697 icon_view->priv->dest_item = NULL;
6699 gtk_icon_view_queue_draw_path (icon_view, current_path);
6700 gtk_tree_path_free (current_path);
6703 /* special case a drop on an empty model */
6704 icon_view->priv->empty_view_drop = FALSE;
6705 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6706 && gtk_tree_path_get_depth (path) == 1
6707 && gtk_tree_path_get_indices (path)[0] == 0)
6711 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6714 if (n_children == 0)
6715 icon_view->priv->empty_view_drop = TRUE;
6718 icon_view->priv->dest_pos = pos;
6722 icon_view->priv->dest_item =
6723 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6724 icon_view->priv->model, path);
6726 gtk_icon_view_queue_draw_path (icon_view, path);
6731 * gtk_icon_view_get_drag_dest_item:
6732 * @icon_view: a #GtkIconView
6733 * @path: (out) (allow-none): Return location for the path of
6734 * the highlighted item, or %NULL.
6735 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6737 * Gets information about the item that is highlighted for feedback.
6742 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6744 GtkIconViewDropPosition *pos)
6746 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6750 if (icon_view->priv->dest_item)
6751 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6757 *pos = icon_view->priv->dest_pos;
6761 * gtk_icon_view_get_dest_item_at_pos:
6762 * @icon_view: a #GtkIconView
6763 * @drag_x: the position to determine the destination item for
6764 * @drag_y: the position to determine the destination item for
6765 * @path: (out) (allow-none): Return location for the path of the item,
6767 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6769 * Determines the destination item for a given position.
6771 * Return value: whether there is an item at the given position.
6776 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6780 GtkIconViewDropPosition *pos)
6782 GtkIconViewItem *item;
6784 /* Note; this function is exported to allow a custom DND
6785 * implementation, so it can't touch TreeViewDragInfo
6788 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6789 g_return_val_if_fail (drag_x >= 0, FALSE);
6790 g_return_val_if_fail (drag_y >= 0, FALSE);
6791 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6797 item = _gtk_icon_view_get_item_at_coords (icon_view,
6798 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6799 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6806 *path = gtk_tree_path_new_from_indices (item->index, -1);
6810 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6811 *pos = GTK_ICON_VIEW_DROP_LEFT;
6812 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6813 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6814 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6815 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6816 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6817 *pos = GTK_ICON_VIEW_DROP_BELOW;
6819 *pos = GTK_ICON_VIEW_DROP_INTO;
6826 * gtk_icon_view_create_drag_icon:
6827 * @icon_view: a #GtkIconView
6828 * @path: a #GtkTreePath in @icon_view
6830 * Creates a #cairo_surface_t representation of the item at @path.
6831 * This image is used for a drag icon.
6833 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6838 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6842 GtkStyleContext *context;
6844 cairo_surface_t *surface;
6848 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6849 g_return_val_if_fail (path != NULL, NULL);
6851 widget = GTK_WIDGET (icon_view);
6852 context = gtk_widget_get_style_context (widget);
6854 if (!gtk_widget_get_realized (widget))
6857 index = gtk_tree_path_get_indices (path)[0];
6859 for (l = icon_view->priv->items; l; l = l->next)
6861 GtkIconViewItem *item = l->data;
6863 if (index == item->index)
6865 GdkRectangle rect = {
6866 item->cell_area.x - icon_view->priv->item_padding,
6867 item->cell_area.y - icon_view->priv->item_padding,
6868 item->cell_area.width + icon_view->priv->item_padding * 2,
6869 item->cell_area.height + icon_view->priv->item_padding * 2
6872 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6873 CAIRO_CONTENT_COLOR,
6877 cr = cairo_create (surface);
6878 cairo_set_line_width (cr, 1.);
6880 gtk_render_background (context, cr, 0, 0,
6881 rect.width + 2, rect.height + 2);
6885 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6888 gtk_icon_view_paint_item (icon_view, cr, item,
6889 icon_view->priv->item_padding + 1,
6890 icon_view->priv->item_padding + 1, FALSE);
6894 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6895 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6908 * gtk_icon_view_get_reorderable:
6909 * @icon_view: a #GtkIconView
6911 * Retrieves whether the user can reorder the list via drag-and-drop.
6912 * See gtk_icon_view_set_reorderable().
6914 * Return value: %TRUE if the list can be reordered.
6919 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6921 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6923 return icon_view->priv->reorderable;
6926 static const GtkTargetEntry item_targets[] = {
6927 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6932 * gtk_icon_view_set_reorderable:
6933 * @icon_view: A #GtkIconView.
6934 * @reorderable: %TRUE, if the list of items can be reordered.
6936 * This function is a convenience function to allow you to reorder models that
6937 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6938 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6939 * the user can reorder the model by dragging and dropping rows. The
6940 * developer can listen to these changes by connecting to the model's
6941 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6942 * the icon view as a drag source and destination. Therefore, drag and
6943 * drop can not be used in a reorderable view for any other purpose.
6945 * This function does not give you any degree of control over the order -- any
6946 * reordering is allowed. If more control is needed, you should probably
6947 * handle drag and drop manually.
6952 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6953 gboolean reorderable)
6955 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6957 reorderable = reorderable != FALSE;
6959 if (icon_view->priv->reorderable == reorderable)
6964 gtk_icon_view_enable_model_drag_source (icon_view,
6967 G_N_ELEMENTS (item_targets),
6969 gtk_icon_view_enable_model_drag_dest (icon_view,
6971 G_N_ELEMENTS (item_targets),
6976 gtk_icon_view_unset_model_drag_source (icon_view);
6977 gtk_icon_view_unset_model_drag_dest (icon_view);
6980 icon_view->priv->reorderable = reorderable;
6982 g_object_notify (G_OBJECT (icon_view), "reorderable");
6986 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
6987 GtkBuilder *builder,
6989 const gchar *tagname,
6990 GMarkupParser *parser,
6993 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
6994 tagname, parser, data))
6997 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
6998 tagname, parser, data);
7002 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7003 GtkBuilder *builder,
7005 const gchar *tagname,
7008 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7009 child, tagname, data))
7010 parent_buildable_iface->custom_tag_end (buildable, builder,
7011 child, tagname, data);