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 == GDK_BUTTON_PRIMARY && 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 == GDK_BUTTON_PRIMARY && 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 == GDK_BUTTON_PRIMARY;
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_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4772 icon_view->priv->items = NULL;
4773 icon_view->priv->anchor_item = NULL;
4774 icon_view->priv->cursor_item = NULL;
4775 icon_view->priv->last_single_clicked = NULL;
4776 icon_view->priv->last_prelight = NULL;
4777 icon_view->priv->width = 0;
4778 icon_view->priv->height = 0;
4781 icon_view->priv->model = model;
4783 if (icon_view->priv->model)
4785 g_object_ref (icon_view->priv->model);
4786 g_signal_connect (icon_view->priv->model,
4788 G_CALLBACK (gtk_icon_view_row_changed),
4790 g_signal_connect (icon_view->priv->model,
4792 G_CALLBACK (gtk_icon_view_row_inserted),
4794 g_signal_connect (icon_view->priv->model,
4796 G_CALLBACK (gtk_icon_view_row_deleted),
4798 g_signal_connect (icon_view->priv->model,
4800 G_CALLBACK (gtk_icon_view_rows_reordered),
4803 gtk_icon_view_build_items (icon_view);
4805 gtk_icon_view_layout (icon_view);
4808 g_object_notify (G_OBJECT (icon_view), "model");
4810 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4811 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4815 * gtk_icon_view_get_model:
4816 * @icon_view: a #GtkIconView
4818 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4821 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4822 * currently being used.
4827 gtk_icon_view_get_model (GtkIconView *icon_view)
4829 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4831 return icon_view->priv->model;
4835 update_text_cell (GtkIconView *icon_view)
4837 if (!icon_view->priv->cell_area)
4840 if (icon_view->priv->text_column == -1 &&
4841 icon_view->priv->markup_column == -1)
4843 if (icon_view->priv->text_cell != NULL)
4845 gtk_cell_area_remove (icon_view->priv->cell_area,
4846 icon_view->priv->text_cell);
4847 icon_view->priv->text_cell = NULL;
4852 if (icon_view->priv->text_cell == NULL)
4854 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4856 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4859 if (icon_view->priv->markup_column != -1)
4860 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4861 icon_view->priv->text_cell,
4862 "markup", icon_view->priv->markup_column,
4865 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4866 icon_view->priv->text_cell,
4867 "text", icon_view->priv->text_column,
4870 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4871 g_object_set (icon_view->priv->text_cell,
4872 "alignment", PANGO_ALIGN_CENTER,
4873 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4878 g_object_set (icon_view->priv->text_cell,
4879 "alignment", PANGO_ALIGN_LEFT,
4880 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4888 update_pixbuf_cell (GtkIconView *icon_view)
4890 if (!icon_view->priv->cell_area)
4893 if (icon_view->priv->pixbuf_column == -1)
4895 if (icon_view->priv->pixbuf_cell != NULL)
4897 gtk_cell_area_remove (icon_view->priv->cell_area,
4898 icon_view->priv->pixbuf_cell);
4900 icon_view->priv->pixbuf_cell = NULL;
4905 if (icon_view->priv->pixbuf_cell == NULL)
4907 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4909 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4912 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4913 icon_view->priv->pixbuf_cell,
4914 "pixbuf", icon_view->priv->pixbuf_column,
4917 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4918 g_object_set (icon_view->priv->pixbuf_cell,
4923 g_object_set (icon_view->priv->pixbuf_cell,
4931 * gtk_icon_view_set_text_column:
4932 * @icon_view: A #GtkIconView.
4933 * @column: A column in the currently used model, or -1 to display no text
4935 * Sets the column with text for @icon_view to be @column. The text
4936 * column must be of type #G_TYPE_STRING.
4941 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4944 if (column == icon_view->priv->text_column)
4948 icon_view->priv->text_column = -1;
4951 if (icon_view->priv->model != NULL)
4955 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4957 g_return_if_fail (column_type == G_TYPE_STRING);
4960 icon_view->priv->text_column = column;
4963 if (icon_view->priv->cell_area)
4964 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4966 update_text_cell (icon_view);
4968 gtk_icon_view_invalidate_sizes (icon_view);
4970 g_object_notify (G_OBJECT (icon_view), "text-column");
4974 * gtk_icon_view_get_text_column:
4975 * @icon_view: A #GtkIconView.
4977 * Returns the column with text for @icon_view.
4979 * Returns: the text column, or -1 if it's unset.
4984 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4986 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4988 return icon_view->priv->text_column;
4992 * gtk_icon_view_set_markup_column:
4993 * @icon_view: A #GtkIconView.
4994 * @column: A column in the currently used model, or -1 to display no text
4996 * Sets the column with markup information for @icon_view to be
4997 * @column. The markup column must be of type #G_TYPE_STRING.
4998 * If the markup column is set to something, it overrides
4999 * the text column set by gtk_icon_view_set_text_column().
5004 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5007 if (column == icon_view->priv->markup_column)
5011 icon_view->priv->markup_column = -1;
5014 if (icon_view->priv->model != NULL)
5018 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5020 g_return_if_fail (column_type == G_TYPE_STRING);
5023 icon_view->priv->markup_column = column;
5026 if (icon_view->priv->cell_area)
5027 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5029 update_text_cell (icon_view);
5031 gtk_icon_view_invalidate_sizes (icon_view);
5033 g_object_notify (G_OBJECT (icon_view), "markup-column");
5037 * gtk_icon_view_get_markup_column:
5038 * @icon_view: A #GtkIconView.
5040 * Returns the column with markup text for @icon_view.
5042 * Returns: the markup column, or -1 if it's unset.
5047 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5049 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5051 return icon_view->priv->markup_column;
5055 * gtk_icon_view_set_pixbuf_column:
5056 * @icon_view: A #GtkIconView.
5057 * @column: A column in the currently used model, or -1 to disable
5059 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5060 * column must be of type #GDK_TYPE_PIXBUF
5065 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5068 if (column == icon_view->priv->pixbuf_column)
5072 icon_view->priv->pixbuf_column = -1;
5075 if (icon_view->priv->model != NULL)
5079 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5081 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5084 icon_view->priv->pixbuf_column = column;
5087 if (icon_view->priv->cell_area)
5088 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5090 update_pixbuf_cell (icon_view);
5092 gtk_icon_view_invalidate_sizes (icon_view);
5094 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5099 * gtk_icon_view_get_pixbuf_column:
5100 * @icon_view: A #GtkIconView.
5102 * Returns the column with pixbufs for @icon_view.
5104 * Returns: the pixbuf column, or -1 if it's unset.
5109 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5111 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5113 return icon_view->priv->pixbuf_column;
5117 * gtk_icon_view_select_path:
5118 * @icon_view: A #GtkIconView.
5119 * @path: The #GtkTreePath to be selected.
5121 * Selects the row at @path.
5126 gtk_icon_view_select_path (GtkIconView *icon_view,
5129 GtkIconViewItem *item = NULL;
5131 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5132 g_return_if_fail (icon_view->priv->model != NULL);
5133 g_return_if_fail (path != NULL);
5135 if (gtk_tree_path_get_depth (path) > 0)
5136 item = g_list_nth_data (icon_view->priv->items,
5137 gtk_tree_path_get_indices(path)[0]);
5140 _gtk_icon_view_select_item (icon_view, item);
5144 * gtk_icon_view_unselect_path:
5145 * @icon_view: A #GtkIconView.
5146 * @path: The #GtkTreePath to be unselected.
5148 * Unselects the row at @path.
5153 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5156 GtkIconViewItem *item;
5158 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5159 g_return_if_fail (icon_view->priv->model != NULL);
5160 g_return_if_fail (path != NULL);
5162 item = g_list_nth_data (icon_view->priv->items,
5163 gtk_tree_path_get_indices(path)[0]);
5168 _gtk_icon_view_unselect_item (icon_view, item);
5172 * gtk_icon_view_get_selected_items:
5173 * @icon_view: A #GtkIconView.
5175 * Creates a list of paths of all selected items. Additionally, if you are
5176 * planning on modifying the model after calling this function, you may
5177 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5178 * To do this, you can use gtk_tree_row_reference_new().
5180 * To free the return value, use:
5182 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5185 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5190 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5193 GList *selected = NULL;
5195 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5197 for (list = icon_view->priv->items; list != NULL; list = list->next)
5199 GtkIconViewItem *item = list->data;
5203 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5205 selected = g_list_prepend (selected, path);
5213 * gtk_icon_view_select_all:
5214 * @icon_view: A #GtkIconView.
5216 * Selects all the icons. @icon_view must has its selection mode set
5217 * to #GTK_SELECTION_MULTIPLE.
5222 gtk_icon_view_select_all (GtkIconView *icon_view)
5225 gboolean dirty = FALSE;
5227 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5229 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5232 for (items = icon_view->priv->items; items; items = items->next)
5234 GtkIconViewItem *item = items->data;
5236 if (!item->selected)
5239 item->selected = TRUE;
5240 gtk_icon_view_queue_draw_item (icon_view, item);
5245 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5249 * gtk_icon_view_unselect_all:
5250 * @icon_view: A #GtkIconView.
5252 * Unselects all the icons.
5257 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5259 gboolean dirty = FALSE;
5261 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5263 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5266 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5269 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5273 * gtk_icon_view_path_is_selected:
5274 * @icon_view: A #GtkIconView.
5275 * @path: A #GtkTreePath to check selection on.
5277 * Returns %TRUE if the icon pointed to by @path is currently
5278 * selected. If @path does not point to a valid location, %FALSE is returned.
5280 * Return value: %TRUE if @path is selected.
5285 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5288 GtkIconViewItem *item;
5290 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5291 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5292 g_return_val_if_fail (path != NULL, FALSE);
5294 item = g_list_nth_data (icon_view->priv->items,
5295 gtk_tree_path_get_indices(path)[0]);
5300 return item->selected;
5304 * gtk_icon_view_get_item_row:
5305 * @icon_view: a #GtkIconView
5306 * @path: the #GtkTreePath of the item
5308 * Gets the row in which the item @path is currently
5309 * displayed. Row numbers start at 0.
5311 * Returns: The row in which the item is displayed
5316 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5319 GtkIconViewItem *item;
5321 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5322 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5323 g_return_val_if_fail (path != NULL, -1);
5325 item = g_list_nth_data (icon_view->priv->items,
5326 gtk_tree_path_get_indices(path)[0]);
5335 * gtk_icon_view_get_item_column:
5336 * @icon_view: a #GtkIconView
5337 * @path: the #GtkTreePath of the item
5339 * Gets the column in which the item @path is currently
5340 * displayed. Column numbers start at 0.
5342 * Returns: The column in which the item is displayed
5347 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5350 GtkIconViewItem *item;
5352 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5353 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5354 g_return_val_if_fail (path != NULL, -1);
5356 item = g_list_nth_data (icon_view->priv->items,
5357 gtk_tree_path_get_indices(path)[0]);
5366 * gtk_icon_view_item_activated:
5367 * @icon_view: A #GtkIconView
5368 * @path: The #GtkTreePath to be activated
5370 * Activates the item determined by @path.
5375 gtk_icon_view_item_activated (GtkIconView *icon_view,
5378 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5379 g_return_if_fail (path != NULL);
5381 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5385 * gtk_icon_view_set_item_orientation:
5386 * @icon_view: a #GtkIconView
5387 * @orientation: the relative position of texts and icons
5389 * Sets the ::item-orientation property which determines whether the labels
5390 * are drawn beside the icons instead of below.
5395 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5396 GtkOrientation orientation)
5398 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5400 if (icon_view->priv->item_orientation != orientation)
5402 icon_view->priv->item_orientation = orientation;
5404 if (icon_view->priv->cell_area)
5406 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5407 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5408 icon_view->priv->item_orientation);
5410 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5413 gtk_icon_view_invalidate_sizes (icon_view);
5415 update_text_cell (icon_view);
5416 update_pixbuf_cell (icon_view);
5418 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5423 * gtk_icon_view_get_item_orientation:
5424 * @icon_view: a #GtkIconView
5426 * Returns the value of the ::item-orientation property which determines
5427 * whether the labels are drawn beside the icons instead of below.
5429 * Return value: the relative position of texts and icons
5434 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5436 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5437 GTK_ORIENTATION_VERTICAL);
5439 return icon_view->priv->item_orientation;
5443 * gtk_icon_view_set_columns:
5444 * @icon_view: a #GtkIconView
5445 * @columns: the number of columns
5447 * Sets the ::columns property which determines in how
5448 * many columns the icons are arranged. If @columns is
5449 * -1, the number of columns will be chosen automatically
5450 * to fill the available area.
5455 gtk_icon_view_set_columns (GtkIconView *icon_view,
5458 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5460 if (icon_view->priv->columns != columns)
5462 icon_view->priv->columns = columns;
5464 if (icon_view->priv->cell_area)
5465 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5467 gtk_icon_view_queue_layout (icon_view);
5469 g_object_notify (G_OBJECT (icon_view), "columns");
5474 * gtk_icon_view_get_columns:
5475 * @icon_view: a #GtkIconView
5477 * Returns the value of the ::columns property.
5479 * Return value: the number of columns, or -1
5484 gtk_icon_view_get_columns (GtkIconView *icon_view)
5486 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5488 return icon_view->priv->columns;
5492 * gtk_icon_view_set_item_width:
5493 * @icon_view: a #GtkIconView
5494 * @item_width: the width for each item
5496 * Sets the ::item-width property which specifies the width
5497 * to use for each item. If it is set to -1, the icon view will
5498 * automatically determine a suitable item size.
5503 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5506 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5508 if (icon_view->priv->item_width != item_width)
5510 icon_view->priv->item_width = item_width;
5512 if (icon_view->priv->cell_area)
5513 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5515 gtk_icon_view_invalidate_sizes (icon_view);
5517 update_text_cell (icon_view);
5519 g_object_notify (G_OBJECT (icon_view), "item-width");
5524 * gtk_icon_view_get_item_width:
5525 * @icon_view: a #GtkIconView
5527 * Returns the value of the ::item-width property.
5529 * Return value: the width of a single item, or -1
5534 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5536 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5538 return icon_view->priv->item_width;
5543 * gtk_icon_view_set_spacing:
5544 * @icon_view: a #GtkIconView
5545 * @spacing: the spacing
5547 * Sets the ::spacing property which specifies the space
5548 * which is inserted between the cells (i.e. the icon and
5549 * the text) of an item.
5554 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5557 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5559 if (icon_view->priv->spacing != spacing)
5561 icon_view->priv->spacing = spacing;
5563 if (icon_view->priv->cell_area)
5564 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5566 gtk_icon_view_invalidate_sizes (icon_view);
5568 g_object_notify (G_OBJECT (icon_view), "spacing");
5573 * gtk_icon_view_get_spacing:
5574 * @icon_view: a #GtkIconView
5576 * Returns the value of the ::spacing property.
5578 * Return value: the space between cells
5583 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5585 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5587 return icon_view->priv->spacing;
5591 * gtk_icon_view_set_row_spacing:
5592 * @icon_view: a #GtkIconView
5593 * @row_spacing: the row spacing
5595 * Sets the ::row-spacing property which specifies the space
5596 * which is inserted between the rows of the icon view.
5601 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5604 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5606 if (icon_view->priv->row_spacing != row_spacing)
5608 icon_view->priv->row_spacing = row_spacing;
5610 if (icon_view->priv->cell_area)
5611 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5613 gtk_icon_view_invalidate_sizes (icon_view);
5615 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5620 * gtk_icon_view_get_row_spacing:
5621 * @icon_view: a #GtkIconView
5623 * Returns the value of the ::row-spacing property.
5625 * Return value: the space between rows
5630 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5632 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5634 return icon_view->priv->row_spacing;
5638 * gtk_icon_view_set_column_spacing:
5639 * @icon_view: a #GtkIconView
5640 * @column_spacing: the column spacing
5642 * Sets the ::column-spacing property which specifies the space
5643 * which is inserted between the columns of the icon view.
5648 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5649 gint column_spacing)
5651 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5653 if (icon_view->priv->column_spacing != column_spacing)
5655 icon_view->priv->column_spacing = column_spacing;
5657 if (icon_view->priv->cell_area)
5658 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5660 gtk_icon_view_invalidate_sizes (icon_view);
5662 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5667 * gtk_icon_view_get_column_spacing:
5668 * @icon_view: a #GtkIconView
5670 * Returns the value of the ::column-spacing property.
5672 * Return value: the space between columns
5677 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5679 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5681 return icon_view->priv->column_spacing;
5685 * gtk_icon_view_set_margin:
5686 * @icon_view: a #GtkIconView
5687 * @margin: the margin
5689 * Sets the ::margin property which specifies the space
5690 * which is inserted at the top, bottom, left and right
5696 gtk_icon_view_set_margin (GtkIconView *icon_view,
5699 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5701 if (icon_view->priv->margin != margin)
5703 icon_view->priv->margin = margin;
5705 if (icon_view->priv->cell_area)
5706 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5708 gtk_icon_view_invalidate_sizes (icon_view);
5710 g_object_notify (G_OBJECT (icon_view), "margin");
5715 * gtk_icon_view_get_margin:
5716 * @icon_view: a #GtkIconView
5718 * Returns the value of the ::margin property.
5720 * Return value: the space at the borders
5725 gtk_icon_view_get_margin (GtkIconView *icon_view)
5727 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5729 return icon_view->priv->margin;
5733 * gtk_icon_view_set_item_padding:
5734 * @icon_view: a #GtkIconView
5735 * @item_padding: the item padding
5737 * Sets the #GtkIconView:item-padding property which specifies the padding
5738 * around each of the icon view's items.
5743 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5746 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5748 if (icon_view->priv->item_padding != item_padding)
5750 icon_view->priv->item_padding = item_padding;
5752 if (icon_view->priv->cell_area)
5753 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5755 gtk_icon_view_invalidate_sizes (icon_view);
5757 g_object_notify (G_OBJECT (icon_view), "item-padding");
5762 * gtk_icon_view_get_item_padding:
5763 * @icon_view: a #GtkIconView
5765 * Returns the value of the ::item-padding property.
5767 * Return value: the padding around items
5772 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5774 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5776 return icon_view->priv->item_padding;
5779 /* Get/set whether drag_motion requested the drag data and
5780 * drag_data_received should thus not actually insert the data,
5781 * since the data doesn't result from a drop.
5784 set_status_pending (GdkDragContext *context,
5785 GdkDragAction suggested_action)
5787 g_object_set_data (G_OBJECT (context),
5788 I_("gtk-icon-view-status-pending"),
5789 GINT_TO_POINTER (suggested_action));
5792 static GdkDragAction
5793 get_status_pending (GdkDragContext *context)
5795 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5796 "gtk-icon-view-status-pending"));
5800 unset_reorderable (GtkIconView *icon_view)
5802 if (icon_view->priv->reorderable)
5804 icon_view->priv->reorderable = FALSE;
5805 g_object_notify (G_OBJECT (icon_view), "reorderable");
5810 set_source_row (GdkDragContext *context,
5811 GtkTreeModel *model,
5812 GtkTreePath *source_row)
5815 g_object_set_data_full (G_OBJECT (context),
5816 I_("gtk-icon-view-source-row"),
5817 gtk_tree_row_reference_new (model, source_row),
5818 (GDestroyNotify) gtk_tree_row_reference_free);
5820 g_object_set_data_full (G_OBJECT (context),
5821 I_("gtk-icon-view-source-row"),
5826 get_source_row (GdkDragContext *context)
5828 GtkTreeRowReference *ref;
5830 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5833 return gtk_tree_row_reference_get_path (ref);
5840 GtkTreeRowReference *dest_row;
5841 gboolean empty_view_drop;
5842 gboolean drop_append_mode;
5846 dest_row_free (gpointer data)
5848 DestRow *dr = (DestRow *)data;
5850 gtk_tree_row_reference_free (dr->dest_row);
5855 set_dest_row (GdkDragContext *context,
5856 GtkTreeModel *model,
5857 GtkTreePath *dest_row,
5858 gboolean empty_view_drop,
5859 gboolean drop_append_mode)
5865 g_object_set_data_full (G_OBJECT (context),
5866 I_("gtk-icon-view-dest-row"),
5871 dr = g_new0 (DestRow, 1);
5873 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5874 dr->empty_view_drop = empty_view_drop;
5875 dr->drop_append_mode = drop_append_mode;
5876 g_object_set_data_full (G_OBJECT (context),
5877 I_("gtk-icon-view-dest-row"),
5878 dr, (GDestroyNotify) dest_row_free);
5882 get_dest_row (GdkDragContext *context)
5886 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5890 GtkTreePath *path = NULL;
5893 path = gtk_tree_row_reference_get_path (dr->dest_row);
5894 else if (dr->empty_view_drop)
5895 path = gtk_tree_path_new_from_indices (0, -1);
5899 if (path && dr->drop_append_mode)
5900 gtk_tree_path_next (path);
5909 check_model_dnd (GtkTreeModel *model,
5910 GType required_iface,
5911 const gchar *signal)
5913 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5915 g_warning ("You must override the default '%s' handler "
5916 "on GtkIconView when using models that don't support "
5917 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5918 "is to connect to '%s' and call "
5919 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5920 "the default handler from running. Look at the source code "
5921 "for the default handler in gtkiconview.c to get an idea what "
5922 "your handler should do. (gtkiconview.c is in the GTK+ source "
5923 "code.) If you're using GTK+ from a language other than C, "
5924 "there may be a more natural way to override default handlers, e.g. via derivation.",
5925 signal, g_type_name (required_iface), signal);
5933 remove_scroll_timeout (GtkIconView *icon_view)
5935 if (icon_view->priv->scroll_timeout_id != 0)
5937 g_source_remove (icon_view->priv->scroll_timeout_id);
5939 icon_view->priv->scroll_timeout_id = 0;
5944 gtk_icon_view_autoscroll (GtkIconView *icon_view,
5948 gint px, py, x, y, width, height;
5949 gint hoffset, voffset;
5951 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5953 gdk_window_get_device_position (window, device, &px, &py, NULL);
5954 gdk_window_get_geometry (window, &x, &y, &width, &height);
5956 /* see if we are near the edge. */
5957 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5959 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5961 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5963 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5966 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5967 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5970 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5971 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5975 GtkIconView *icon_view;
5980 drag_scroll_timeout (gpointer datap)
5982 DragScrollData *data = datap;
5984 gtk_icon_view_autoscroll (data->icon_view, data->device);
5990 drag_scroll_data_free (DragScrollData *data)
5992 g_slice_free (DragScrollData, data);
5996 set_destination (GtkIconView *icon_view,
5997 GdkDragContext *context,
6000 GdkDragAction *suggested_action,
6004 GtkTreePath *path = NULL;
6005 GtkIconViewDropPosition pos;
6006 GtkIconViewDropPosition old_pos;
6007 GtkTreePath *old_dest_path = NULL;
6008 gboolean can_drop = FALSE;
6010 widget = GTK_WIDGET (icon_view);
6012 *suggested_action = 0;
6015 if (!icon_view->priv->dest_set)
6017 /* someone unset us as a drag dest, note that if
6018 * we return FALSE drag_leave isn't called
6021 gtk_icon_view_set_drag_dest_item (icon_view,
6023 GTK_ICON_VIEW_DROP_LEFT);
6025 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6027 return FALSE; /* no longer a drop site */
6030 *target = gtk_drag_dest_find_target (widget, context,
6031 gtk_drag_dest_get_target_list (widget));
6032 if (*target == GDK_NONE)
6035 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6038 GtkTreeModel *model;
6040 /* the row got dropped on empty space, let's setup a special case
6044 gtk_tree_path_free (path);
6046 model = gtk_icon_view_get_model (icon_view);
6048 n_children = gtk_tree_model_iter_n_children (model, NULL);
6051 pos = GTK_ICON_VIEW_DROP_BELOW;
6052 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6056 pos = GTK_ICON_VIEW_DROP_ABOVE;
6057 path = gtk_tree_path_new_from_indices (0, -1);
6067 gtk_icon_view_get_drag_dest_item (icon_view,
6072 gtk_tree_path_free (old_dest_path);
6074 if (TRUE /* FIXME if the location droppable predicate */)
6082 GtkWidget *source_widget;
6084 *suggested_action = gdk_drag_context_get_suggested_action (context);
6085 source_widget = gtk_drag_get_source_widget (context);
6087 if (source_widget == widget)
6089 /* Default to MOVE, unless the user has
6090 * pressed ctrl or shift to affect available actions
6092 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6093 *suggested_action = GDK_ACTION_MOVE;
6096 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6101 /* can't drop here */
6102 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6104 GTK_ICON_VIEW_DROP_LEFT);
6108 gtk_tree_path_free (path);
6114 get_logical_destination (GtkIconView *icon_view,
6115 gboolean *drop_append_mode)
6117 /* adjust path to point to the row the drop goes in front of */
6118 GtkTreePath *path = NULL;
6119 GtkIconViewDropPosition pos;
6121 *drop_append_mode = FALSE;
6123 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6128 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6129 pos == GTK_ICON_VIEW_DROP_BELOW)
6132 GtkTreeModel *model = icon_view->priv->model;
6134 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6135 !gtk_tree_model_iter_next (model, &iter))
6136 *drop_append_mode = TRUE;
6139 *drop_append_mode = FALSE;
6140 gtk_tree_path_next (path);
6148 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6149 GdkEventMotion *event)
6151 GtkWidget *widget = GTK_WIDGET (icon_view);
6152 GdkDragContext *context;
6153 GtkTreePath *path = NULL;
6155 GtkTreeModel *model;
6156 gboolean retval = FALSE;
6158 if (!icon_view->priv->source_set)
6161 if (icon_view->priv->pressed_button < 0)
6164 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6165 icon_view->priv->press_start_x,
6166 icon_view->priv->press_start_y,
6167 event->x, event->y))
6170 model = gtk_icon_view_get_model (icon_view);
6175 button = icon_view->priv->pressed_button;
6176 icon_view->priv->pressed_button = -1;
6178 path = gtk_icon_view_get_path_at_pos (icon_view,
6179 icon_view->priv->press_start_x,
6180 icon_view->priv->press_start_y);
6185 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6186 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6190 /* FIXME Check whether we're a start button, if not return FALSE and
6194 /* Now we can begin the drag */
6198 context = gtk_drag_begin (widget,
6199 gtk_drag_source_get_target_list (widget),
6200 icon_view->priv->source_actions,
6204 set_source_row (context, model, path);
6208 gtk_tree_path_free (path);
6213 /* Source side drag signals */
6215 gtk_icon_view_drag_begin (GtkWidget *widget,
6216 GdkDragContext *context)
6218 GtkIconView *icon_view;
6219 GtkIconViewItem *item;
6220 cairo_surface_t *icon;
6224 icon_view = GTK_ICON_VIEW (widget);
6226 /* if the user uses a custom DnD impl, we don't set the icon here */
6227 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6230 item = _gtk_icon_view_get_item_at_coords (icon_view,
6231 icon_view->priv->press_start_x,
6232 icon_view->priv->press_start_y,
6236 g_return_if_fail (item != NULL);
6238 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6239 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6241 path = gtk_tree_path_new_from_indices (item->index, -1);
6242 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6243 gtk_tree_path_free (path);
6245 cairo_surface_set_device_offset (icon, -x, -y);
6247 gtk_drag_set_icon_surface (context, icon);
6249 cairo_surface_destroy (icon);
6253 gtk_icon_view_drag_end (GtkWidget *widget,
6254 GdkDragContext *context)
6260 gtk_icon_view_drag_data_get (GtkWidget *widget,
6261 GdkDragContext *context,
6262 GtkSelectionData *selection_data,
6266 GtkIconView *icon_view;
6267 GtkTreeModel *model;
6268 GtkTreePath *source_row;
6270 icon_view = GTK_ICON_VIEW (widget);
6271 model = gtk_icon_view_get_model (icon_view);
6276 if (!icon_view->priv->source_set)
6279 source_row = get_source_row (context);
6281 if (source_row == NULL)
6284 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6285 * any model; for DragSource models there are some other targets
6289 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6290 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6295 /* If drag_data_get does nothing, try providing row data. */
6296 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6297 gtk_tree_set_row_drag_data (selection_data,
6302 gtk_tree_path_free (source_row);
6306 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6307 GdkDragContext *context)
6309 GtkTreeModel *model;
6310 GtkIconView *icon_view;
6311 GtkTreePath *source_row;
6313 icon_view = GTK_ICON_VIEW (widget);
6314 model = gtk_icon_view_get_model (icon_view);
6316 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6319 if (!icon_view->priv->source_set)
6322 source_row = get_source_row (context);
6324 if (source_row == NULL)
6327 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6330 gtk_tree_path_free (source_row);
6332 set_source_row (context, NULL, NULL);
6335 /* Target side drag signals */
6337 gtk_icon_view_drag_leave (GtkWidget *widget,
6338 GdkDragContext *context,
6341 GtkIconView *icon_view;
6343 icon_view = GTK_ICON_VIEW (widget);
6345 /* unset any highlight row */
6346 gtk_icon_view_set_drag_dest_item (icon_view,
6348 GTK_ICON_VIEW_DROP_LEFT);
6350 remove_scroll_timeout (icon_view);
6354 gtk_icon_view_drag_motion (GtkWidget *widget,
6355 GdkDragContext *context,
6360 GtkTreePath *path = NULL;
6361 GtkIconViewDropPosition pos;
6362 GtkIconView *icon_view;
6363 GdkDragAction suggested_action = 0;
6367 icon_view = GTK_ICON_VIEW (widget);
6369 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6372 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6374 /* we only know this *after* set_desination_row */
6375 empty = icon_view->priv->empty_view_drop;
6377 if (path == NULL && !empty)
6379 /* Can't drop here. */
6380 gdk_drag_status (context, 0, time);
6384 if (icon_view->priv->scroll_timeout_id == 0)
6386 DragScrollData *data = g_slice_new (DragScrollData);
6387 data->icon_view = icon_view;
6388 data->device = gdk_drag_context_get_device (context);
6390 icon_view->priv->scroll_timeout_id =
6391 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6394 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6396 /* Request data so we can use the source row when
6397 * determining whether to accept the drop
6399 set_status_pending (context, suggested_action);
6400 gtk_drag_get_data (widget, context, target, time);
6404 set_status_pending (context, 0);
6405 gdk_drag_status (context, suggested_action, time);
6410 gtk_tree_path_free (path);
6416 gtk_icon_view_drag_drop (GtkWidget *widget,
6417 GdkDragContext *context,
6422 GtkIconView *icon_view;
6424 GdkDragAction suggested_action = 0;
6425 GdkAtom target = GDK_NONE;
6426 GtkTreeModel *model;
6427 gboolean drop_append_mode;
6429 icon_view = GTK_ICON_VIEW (widget);
6430 model = gtk_icon_view_get_model (icon_view);
6432 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6434 if (!icon_view->priv->dest_set)
6437 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6440 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6443 path = get_logical_destination (icon_view, &drop_append_mode);
6445 if (target != GDK_NONE && path != NULL)
6447 /* in case a motion had requested drag data, change things so we
6448 * treat drag data receives as a drop.
6450 set_status_pending (context, 0);
6451 set_dest_row (context, model, path,
6452 icon_view->priv->empty_view_drop, drop_append_mode);
6456 gtk_tree_path_free (path);
6458 /* Unset this thing */
6459 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6461 if (target != GDK_NONE)
6463 gtk_drag_get_data (widget, context, target, time);
6471 gtk_icon_view_drag_data_received (GtkWidget *widget,
6472 GdkDragContext *context,
6475 GtkSelectionData *selection_data,
6480 gboolean accepted = FALSE;
6481 GtkTreeModel *model;
6482 GtkIconView *icon_view;
6483 GtkTreePath *dest_row;
6484 GdkDragAction suggested_action;
6485 gboolean drop_append_mode;
6487 icon_view = GTK_ICON_VIEW (widget);
6488 model = gtk_icon_view_get_model (icon_view);
6490 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6493 if (!icon_view->priv->dest_set)
6496 suggested_action = get_status_pending (context);
6498 if (suggested_action)
6500 /* We are getting this data due to a request in drag_motion,
6501 * rather than due to a request in drag_drop, so we are just
6502 * supposed to call drag_status, not actually paste in the
6505 path = get_logical_destination (icon_view, &drop_append_mode);
6508 suggested_action = 0;
6510 if (suggested_action)
6512 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6515 suggested_action = 0;
6518 gdk_drag_status (context, suggested_action, time);
6521 gtk_tree_path_free (path);
6523 /* If you can't drop, remove user drop indicator until the next motion */
6524 if (suggested_action == 0)
6525 gtk_icon_view_set_drag_dest_item (icon_view,
6527 GTK_ICON_VIEW_DROP_LEFT);
6532 dest_row = get_dest_row (context);
6534 if (dest_row == NULL)
6537 if (gtk_selection_data_get_length (selection_data) >= 0)
6539 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6545 gtk_drag_finish (context,
6547 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6550 gtk_tree_path_free (dest_row);
6553 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6556 /* Drag-and-Drop support */
6558 * gtk_icon_view_enable_model_drag_source:
6559 * @icon_view: a #GtkIconTreeView
6560 * @start_button_mask: Mask of allowed buttons to start drag
6561 * @targets: (array length=n_targets): the table of targets that the drag will
6563 * @n_targets: the number of items in @targets
6564 * @actions: the bitmask of possible actions for a drag from this
6567 * Turns @icon_view into a drag source for automatic DND. Calling this
6568 * method sets #GtkIconView:reorderable to %FALSE.
6573 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6574 GdkModifierType start_button_mask,
6575 const GtkTargetEntry *targets,
6577 GdkDragAction actions)
6579 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6581 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6583 icon_view->priv->start_button_mask = start_button_mask;
6584 icon_view->priv->source_actions = actions;
6586 icon_view->priv->source_set = TRUE;
6588 unset_reorderable (icon_view);
6592 * gtk_icon_view_enable_model_drag_dest:
6593 * @icon_view: a #GtkIconView
6594 * @targets: (array length=n_targets): the table of targets that the drag will
6596 * @n_targets: the number of items in @targets
6597 * @actions: the bitmask of possible actions for a drag to this
6600 * Turns @icon_view into a drop destination for automatic DND. Calling this
6601 * method sets #GtkIconView:reorderable to %FALSE.
6606 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6607 const GtkTargetEntry *targets,
6609 GdkDragAction actions)
6611 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6613 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6615 icon_view->priv->dest_actions = actions;
6617 icon_view->priv->dest_set = TRUE;
6619 unset_reorderable (icon_view);
6623 * gtk_icon_view_unset_model_drag_source:
6624 * @icon_view: a #GtkIconView
6626 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6627 * method sets #GtkIconView:reorderable to %FALSE.
6632 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6634 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6636 if (icon_view->priv->source_set)
6638 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6639 icon_view->priv->source_set = FALSE;
6642 unset_reorderable (icon_view);
6646 * gtk_icon_view_unset_model_drag_dest:
6647 * @icon_view: a #GtkIconView
6649 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6650 * method sets #GtkIconView:reorderable to %FALSE.
6655 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6657 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6659 if (icon_view->priv->dest_set)
6661 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6662 icon_view->priv->dest_set = FALSE;
6665 unset_reorderable (icon_view);
6668 /* These are useful to implement your own custom stuff. */
6670 * gtk_icon_view_set_drag_dest_item:
6671 * @icon_view: a #GtkIconView
6672 * @path: (allow-none): The path of the item to highlight, or %NULL.
6673 * @pos: Specifies where to drop, relative to the item
6675 * Sets the item that is highlighted for feedback.
6680 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6682 GtkIconViewDropPosition pos)
6684 /* Note; this function is exported to allow a custom DND
6685 * implementation, so it can't touch TreeViewDragInfo
6688 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6690 if (icon_view->priv->dest_item)
6692 GtkTreePath *current_path;
6693 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6694 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6695 icon_view->priv->dest_item = NULL;
6697 gtk_icon_view_queue_draw_path (icon_view, current_path);
6698 gtk_tree_path_free (current_path);
6701 /* special case a drop on an empty model */
6702 icon_view->priv->empty_view_drop = FALSE;
6703 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6704 && gtk_tree_path_get_depth (path) == 1
6705 && gtk_tree_path_get_indices (path)[0] == 0)
6709 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6712 if (n_children == 0)
6713 icon_view->priv->empty_view_drop = TRUE;
6716 icon_view->priv->dest_pos = pos;
6720 icon_view->priv->dest_item =
6721 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6722 icon_view->priv->model, path);
6724 gtk_icon_view_queue_draw_path (icon_view, path);
6729 * gtk_icon_view_get_drag_dest_item:
6730 * @icon_view: a #GtkIconView
6731 * @path: (out) (allow-none): Return location for the path of
6732 * the highlighted item, or %NULL.
6733 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6735 * Gets information about the item that is highlighted for feedback.
6740 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6742 GtkIconViewDropPosition *pos)
6744 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6748 if (icon_view->priv->dest_item)
6749 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6755 *pos = icon_view->priv->dest_pos;
6759 * gtk_icon_view_get_dest_item_at_pos:
6760 * @icon_view: a #GtkIconView
6761 * @drag_x: the position to determine the destination item for
6762 * @drag_y: the position to determine the destination item for
6763 * @path: (out) (allow-none): Return location for the path of the item,
6765 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6767 * Determines the destination item for a given position.
6769 * Return value: whether there is an item at the given position.
6774 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6778 GtkIconViewDropPosition *pos)
6780 GtkIconViewItem *item;
6782 /* Note; this function is exported to allow a custom DND
6783 * implementation, so it can't touch TreeViewDragInfo
6786 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6787 g_return_val_if_fail (drag_x >= 0, FALSE);
6788 g_return_val_if_fail (drag_y >= 0, FALSE);
6789 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6795 item = _gtk_icon_view_get_item_at_coords (icon_view,
6796 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6797 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6804 *path = gtk_tree_path_new_from_indices (item->index, -1);
6808 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6809 *pos = GTK_ICON_VIEW_DROP_LEFT;
6810 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6811 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6812 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6813 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6814 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6815 *pos = GTK_ICON_VIEW_DROP_BELOW;
6817 *pos = GTK_ICON_VIEW_DROP_INTO;
6824 * gtk_icon_view_create_drag_icon:
6825 * @icon_view: a #GtkIconView
6826 * @path: a #GtkTreePath in @icon_view
6828 * Creates a #cairo_surface_t representation of the item at @path.
6829 * This image is used for a drag icon.
6831 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6836 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6840 GtkStyleContext *context;
6842 cairo_surface_t *surface;
6846 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6847 g_return_val_if_fail (path != NULL, NULL);
6849 widget = GTK_WIDGET (icon_view);
6850 context = gtk_widget_get_style_context (widget);
6852 if (!gtk_widget_get_realized (widget))
6855 index = gtk_tree_path_get_indices (path)[0];
6857 for (l = icon_view->priv->items; l; l = l->next)
6859 GtkIconViewItem *item = l->data;
6861 if (index == item->index)
6863 GdkRectangle rect = {
6864 item->cell_area.x - icon_view->priv->item_padding,
6865 item->cell_area.y - icon_view->priv->item_padding,
6866 item->cell_area.width + icon_view->priv->item_padding * 2,
6867 item->cell_area.height + icon_view->priv->item_padding * 2
6870 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6871 CAIRO_CONTENT_COLOR,
6875 cr = cairo_create (surface);
6876 cairo_set_line_width (cr, 1.);
6878 gtk_render_background (context, cr, 0, 0,
6879 rect.width + 2, rect.height + 2);
6883 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6886 gtk_icon_view_paint_item (icon_view, cr, item,
6887 icon_view->priv->item_padding + 1,
6888 icon_view->priv->item_padding + 1, FALSE);
6892 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6893 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6906 * gtk_icon_view_get_reorderable:
6907 * @icon_view: a #GtkIconView
6909 * Retrieves whether the user can reorder the list via drag-and-drop.
6910 * See gtk_icon_view_set_reorderable().
6912 * Return value: %TRUE if the list can be reordered.
6917 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6919 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6921 return icon_view->priv->reorderable;
6924 static const GtkTargetEntry item_targets[] = {
6925 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6930 * gtk_icon_view_set_reorderable:
6931 * @icon_view: A #GtkIconView.
6932 * @reorderable: %TRUE, if the list of items can be reordered.
6934 * This function is a convenience function to allow you to reorder models that
6935 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6936 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6937 * the user can reorder the model by dragging and dropping rows. The
6938 * developer can listen to these changes by connecting to the model's
6939 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6940 * the icon view as a drag source and destination. Therefore, drag and
6941 * drop can not be used in a reorderable view for any other purpose.
6943 * This function does not give you any degree of control over the order -- any
6944 * reordering is allowed. If more control is needed, you should probably
6945 * handle drag and drop manually.
6950 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6951 gboolean reorderable)
6953 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6955 reorderable = reorderable != FALSE;
6957 if (icon_view->priv->reorderable == reorderable)
6962 gtk_icon_view_enable_model_drag_source (icon_view,
6965 G_N_ELEMENTS (item_targets),
6967 gtk_icon_view_enable_model_drag_dest (icon_view,
6969 G_N_ELEMENTS (item_targets),
6974 gtk_icon_view_unset_model_drag_source (icon_view);
6975 gtk_icon_view_unset_model_drag_dest (icon_view);
6978 icon_view->priv->reorderable = reorderable;
6980 g_object_notify (G_OBJECT (icon_view), "reorderable");
6984 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
6985 GtkBuilder *builder,
6987 const gchar *tagname,
6988 GMarkupParser *parser,
6991 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
6992 tagname, parser, data))
6995 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
6996 tagname, parser, data);
7000 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7001 GtkBuilder *builder,
7003 const gchar *tagname,
7006 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7007 child, tagname, data))
7008 parent_buildable_iface->custom_tag_end (buildable, builder,
7009 child, tagname, data);