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_set_background (context, window);
1306 gtk_style_context_restore (context);
1308 gdk_window_show (icon_view->priv->bin_window);
1312 gtk_icon_view_unrealize (GtkWidget *widget)
1314 GtkIconView *icon_view;
1316 icon_view = GTK_ICON_VIEW (widget);
1318 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1319 gdk_window_destroy (icon_view->priv->bin_window);
1320 icon_view->priv->bin_window = NULL;
1322 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1326 _gtk_icon_view_update_background (GtkIconView *icon_view)
1328 GtkWidget *widget = GTK_WIDGET (icon_view);
1330 if (gtk_widget_get_realized (widget))
1332 GtkStyleContext *context;
1334 context = gtk_widget_get_style_context (widget);
1336 gtk_style_context_save (context);
1337 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1339 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1340 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1342 gtk_style_context_restore (context);
1347 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1348 GtkStateFlags previous_state)
1350 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1351 gtk_widget_queue_draw (widget);
1355 gtk_icon_view_style_updated (GtkWidget *widget)
1357 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1359 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1360 gtk_widget_queue_resize (widget);
1364 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1368 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1372 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1376 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1380 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1384 for (list = icon_view->priv->children; list; list = list->next)
1386 GtkIconViewChild *child = list->data;
1388 /* totally ignore our child's requisition */
1389 gtk_widget_size_allocate (child->widget, &child->area);
1394 gtk_icon_view_size_allocate (GtkWidget *widget,
1395 GtkAllocation *allocation)
1397 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1399 gtk_widget_set_allocation (widget, allocation);
1401 if (gtk_widget_get_realized (widget))
1403 gdk_window_move_resize (gtk_widget_get_window (widget),
1404 allocation->x, allocation->y,
1405 allocation->width, allocation->height);
1406 gdk_window_resize (icon_view->priv->bin_window,
1407 MAX (icon_view->priv->width, allocation->width),
1408 MAX (icon_view->priv->height, allocation->height));
1411 gtk_icon_view_layout (icon_view);
1413 gtk_icon_view_allocate_children (icon_view);
1415 /* Delay signal emission */
1416 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1417 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1419 gtk_icon_view_set_hadjustment_values (icon_view);
1420 gtk_icon_view_set_vadjustment_values (icon_view);
1422 if (gtk_widget_get_realized (widget) &&
1423 icon_view->priv->scroll_to_path)
1426 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1427 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1428 icon_view->priv->scroll_to_path = NULL;
1430 gtk_icon_view_scroll_to_path (icon_view, path,
1431 icon_view->priv->scroll_to_use_align,
1432 icon_view->priv->scroll_to_row_align,
1433 icon_view->priv->scroll_to_col_align);
1434 gtk_tree_path_free (path);
1437 /* Emit any pending signals now */
1438 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1439 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1443 gtk_icon_view_draw (GtkWidget *widget,
1446 GtkIconView *icon_view;
1450 GtkIconViewDropPosition dest_pos;
1451 GtkIconViewItem *dest_item = NULL;
1453 icon_view = GTK_ICON_VIEW (widget);
1455 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1460 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1462 cairo_set_line_width (cr, 1.);
1464 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1468 dest_index = gtk_tree_path_get_indices (path)[0];
1469 gtk_tree_path_free (path);
1474 for (icons = icon_view->priv->items; icons; icons = icons->next)
1476 GtkIconViewItem *item = icons->data;
1477 GdkRectangle paint_area;
1479 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1480 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1481 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1482 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1486 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1489 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1491 gtk_icon_view_paint_item (icon_view, cr, item,
1492 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1493 icon_view->priv->draw_focus);
1495 if (dest_index == item->index)
1503 dest_pos != GTK_ICON_VIEW_NO_DROP)
1505 GtkStyleContext *context;
1506 GdkRectangle rect = { 0 };
1508 context = gtk_widget_get_style_context (widget);
1512 case GTK_ICON_VIEW_DROP_INTO:
1513 rect = dest_item->cell_area;
1515 case GTK_ICON_VIEW_DROP_ABOVE:
1516 rect.x = dest_item->cell_area.x;
1517 rect.y = dest_item->cell_area.y - 1;
1518 rect.width = dest_item->cell_area.width;
1521 case GTK_ICON_VIEW_DROP_LEFT:
1522 rect.x = dest_item->cell_area.x - 1;
1523 rect.y = dest_item->cell_area.y;
1525 rect.height = dest_item->cell_area.height;
1527 case GTK_ICON_VIEW_DROP_BELOW:
1528 rect.x = dest_item->cell_area.x;
1529 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1530 rect.width = dest_item->cell_area.width;
1533 case GTK_ICON_VIEW_DROP_RIGHT:
1534 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1535 rect.y = dest_item->cell_area.y;
1537 rect.height = dest_item->cell_area.height;
1538 case GTK_ICON_VIEW_NO_DROP: ;
1542 gtk_render_focus (context, cr,
1544 rect.width, rect.height);
1547 if (icon_view->priv->doing_rubberband)
1548 gtk_icon_view_paint_rubberband (icon_view, cr);
1552 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1556 rubberband_scroll_timeout (gpointer data)
1558 GtkIconView *icon_view = data;
1560 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1561 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1562 icon_view->priv->scroll_value_diff);
1564 gtk_icon_view_update_rubberband (icon_view);
1570 gtk_icon_view_motion (GtkWidget *widget,
1571 GdkEventMotion *event)
1573 GtkAllocation allocation;
1574 GtkIconView *icon_view;
1577 icon_view = GTK_ICON_VIEW (widget);
1579 gtk_icon_view_maybe_begin_drag (icon_view, event);
1581 if (icon_view->priv->doing_rubberband)
1583 gtk_icon_view_update_rubberband (widget);
1585 abs_y = event->y - icon_view->priv->height *
1586 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1587 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1588 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1590 gtk_widget_get_allocation (widget, &allocation);
1592 if (abs_y < 0 || abs_y > allocation.height)
1595 icon_view->priv->scroll_value_diff = abs_y;
1597 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1599 icon_view->priv->event_last_x = event->x;
1600 icon_view->priv->event_last_y = event->y;
1602 if (icon_view->priv->scroll_timeout_id == 0)
1603 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1607 remove_scroll_timeout (icon_view);
1611 GtkIconViewItem *item, *last_prelight_item;
1612 GtkCellRenderer *cell = NULL;
1614 last_prelight_item = icon_view->priv->last_prelight;
1615 item = _gtk_icon_view_get_item_at_coords (icon_view,
1622 item->prelight = TRUE;
1623 gtk_icon_view_queue_draw_item (icon_view, item);
1626 if (last_prelight_item != NULL &&
1627 last_prelight_item != item)
1629 last_prelight_item->prelight = FALSE;
1630 gtk_icon_view_queue_draw_item (icon_view,
1631 icon_view->priv->last_prelight);
1634 icon_view->priv->last_prelight = item;
1641 gtk_icon_view_remove (GtkContainer *container,
1644 GtkIconView *icon_view;
1645 GtkIconViewChild *child = NULL;
1648 icon_view = GTK_ICON_VIEW (container);
1650 tmp_list = icon_view->priv->children;
1653 child = tmp_list->data;
1654 if (child->widget == widget)
1656 gtk_widget_unparent (widget);
1658 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1659 g_list_free_1 (tmp_list);
1664 tmp_list = tmp_list->next;
1669 gtk_icon_view_forall (GtkContainer *container,
1670 gboolean include_internals,
1671 GtkCallback callback,
1672 gpointer callback_data)
1674 GtkIconView *icon_view;
1675 GtkIconViewChild *child = NULL;
1678 icon_view = GTK_ICON_VIEW (container);
1680 tmp_list = icon_view->priv->children;
1683 child = tmp_list->data;
1684 tmp_list = tmp_list->next;
1686 (* callback) (child->widget, callback_data);
1691 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1692 GtkIconViewItem *item)
1695 AtkObject *item_obj;
1697 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1700 item_obj = atk_object_ref_accessible_child (obj, item->index);
1701 if (item_obj != NULL)
1703 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1704 g_object_unref (item_obj);
1710 gtk_icon_view_add_editable (GtkCellArea *area,
1711 GtkCellRenderer *renderer,
1712 GtkCellEditable *editable,
1713 GdkRectangle *cell_area,
1715 GtkIconView *icon_view)
1717 GtkIconViewChild *child;
1718 GtkWidget *widget = GTK_WIDGET (editable);
1720 child = g_new (GtkIconViewChild, 1);
1722 child->widget = widget;
1723 child->area.x = cell_area->x;
1724 child->area.y = cell_area->y;
1725 child->area.width = cell_area->width;
1726 child->area.height = cell_area->height;
1728 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1730 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1731 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1733 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1737 gtk_icon_view_remove_editable (GtkCellArea *area,
1738 GtkCellRenderer *renderer,
1739 GtkCellEditable *editable,
1740 GtkIconView *icon_view)
1744 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1745 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1747 gtk_container_remove (GTK_CONTAINER (icon_view),
1748 GTK_WIDGET (editable));
1750 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1751 gtk_icon_view_queue_draw_path (icon_view, path);
1752 gtk_tree_path_free (path);
1756 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1758 GtkIconView *icon_view)
1760 if (!strcmp (pspec->name, "minimum-width") ||
1761 !strcmp (pspec->name, "natural-width") ||
1762 !strcmp (pspec->name, "minimum-height") ||
1763 !strcmp (pspec->name, "natural-height"))
1764 gtk_icon_view_invalidate_sizes (icon_view);
1768 * gtk_icon_view_set_cursor:
1769 * @icon_view: A #GtkIconView
1770 * @path: A #GtkTreePath
1771 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1772 * @start_editing: %TRUE if the specified cell should start being edited.
1774 * Sets the current keyboard focus to be at @path, and selects it. This is
1775 * useful when you want to focus the user's attention on a particular item.
1776 * If @cell is not %NULL, then focus is given to the cell specified by
1777 * it. Additionally, if @start_editing is %TRUE, then editing should be
1778 * started in the specified cell.
1780 * This function is often followed by <literal>gtk_widget_grab_focus
1781 * (icon_view)</literal> in order to give keyboard focus to the widget.
1782 * Please note that editing can only happen when the widget is realized.
1787 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1789 GtkCellRenderer *cell,
1790 gboolean start_editing)
1792 GtkIconViewItem *item = NULL;
1794 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1795 g_return_if_fail (path != NULL);
1796 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1798 if (icon_view->priv->cell_area)
1799 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1801 if (gtk_tree_path_get_depth (path) == 1)
1802 item = g_list_nth_data (icon_view->priv->items,
1803 gtk_tree_path_get_indices(path)[0]);
1808 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
1809 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1811 if (start_editing &&
1812 icon_view->priv->cell_area)
1814 GtkCellAreaContext *context;
1816 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1817 _gtk_icon_view_set_cell_data (icon_view, item);
1818 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1819 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1820 0 /* XXX flags */, TRUE);
1825 * gtk_icon_view_get_cursor:
1826 * @icon_view: A #GtkIconView
1827 * @path: (out) (allow-none): Return location for the current cursor path,
1829 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1831 * Fills in @path and @cell with the current cursor path and cell.
1832 * If the cursor isn't currently set, then *@path will be %NULL.
1833 * If no cell currently has focus, then *@cell will be %NULL.
1835 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1837 * Return value: %TRUE if the cursor is set.
1842 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1844 GtkCellRenderer **cell)
1846 GtkIconViewItem *item;
1848 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1850 item = icon_view->priv->cursor_item;
1855 *path = gtk_tree_path_new_from_indices (item->index, -1);
1860 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1861 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1863 return (item != NULL);
1867 gtk_icon_view_button_press (GtkWidget *widget,
1868 GdkEventButton *event)
1870 GtkIconView *icon_view;
1871 GtkIconViewItem *item;
1872 gboolean dirty = FALSE;
1873 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1875 icon_view = GTK_ICON_VIEW (widget);
1877 if (event->window != icon_view->priv->bin_window)
1880 if (!gtk_widget_has_focus (widget))
1881 gtk_widget_grab_focus (widget);
1883 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
1885 GdkModifierType extend_mod_mask;
1886 GdkModifierType modify_mod_mask;
1889 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
1892 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
1894 item = _gtk_icon_view_get_item_at_coords (icon_view,
1900 * We consider only the the cells' area as the item area if the
1901 * item is not selected, but if it *is* selected, the complete
1902 * selection rectangle is considered to be part of the item.
1904 if (item != NULL && (cell != NULL || item->selected))
1908 if (gtk_cell_renderer_is_activatable (cell))
1912 gtk_icon_view_scroll_to_item (icon_view, item);
1914 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1916 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1918 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1919 (event->state & extend_mod_mask))
1921 gtk_icon_view_unselect_all_internal (icon_view);
1923 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1924 if (!icon_view->priv->anchor_item)
1925 icon_view->priv->anchor_item = item;
1927 gtk_icon_view_select_all_between (icon_view,
1928 icon_view->priv->anchor_item,
1934 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1935 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1936 (event->state & modify_mod_mask))
1938 item->selected = !item->selected;
1939 gtk_icon_view_queue_draw_item (icon_view, item);
1944 gtk_icon_view_unselect_all_internal (icon_view);
1946 item->selected = TRUE;
1947 gtk_icon_view_queue_draw_item (icon_view, item);
1950 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1951 icon_view->priv->anchor_item = item;
1954 /* Save press to possibly begin a drag */
1955 if (icon_view->priv->pressed_button < 0)
1957 icon_view->priv->pressed_button = event->button;
1958 icon_view->priv->press_start_x = event->x;
1959 icon_view->priv->press_start_y = event->y;
1962 if (!icon_view->priv->last_single_clicked)
1963 icon_view->priv->last_single_clicked = item;
1965 /* cancel the current editing, if it exists */
1966 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1968 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
1970 GtkCellAreaContext *context;
1972 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1974 _gtk_icon_view_set_cell_data (icon_view, item);
1975 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1976 GTK_WIDGET (icon_view),
1977 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
1982 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1983 !(event->state & modify_mod_mask))
1985 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1988 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1989 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
1992 /* don't draw keyboard focus around an clicked-on item */
1993 icon_view->priv->draw_focus = FALSE;
1996 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
1998 item = _gtk_icon_view_get_item_at_coords (icon_view,
2003 if (item && item == icon_view->priv->last_single_clicked)
2007 path = gtk_tree_path_new_from_indices (item->index, -1);
2008 gtk_icon_view_item_activated (icon_view, path);
2009 gtk_tree_path_free (path);
2012 icon_view->priv->last_single_clicked = NULL;
2013 icon_view->priv->pressed_button = -1;
2017 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2019 return event->button == GDK_BUTTON_PRIMARY;
2023 gtk_icon_view_button_release (GtkWidget *widget,
2024 GdkEventButton *event)
2026 GtkIconView *icon_view;
2028 icon_view = GTK_ICON_VIEW (widget);
2030 if (icon_view->priv->pressed_button == event->button)
2031 icon_view->priv->pressed_button = -1;
2033 gtk_icon_view_stop_rubberbanding (icon_view);
2035 remove_scroll_timeout (icon_view);
2041 gtk_icon_view_key_press (GtkWidget *widget,
2044 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2046 if (icon_view->priv->doing_rubberband)
2048 if (event->keyval == GDK_KEY_Escape)
2049 gtk_icon_view_stop_rubberbanding (icon_view);
2054 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2058 gtk_icon_view_key_release (GtkWidget *widget,
2061 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2063 if (icon_view->priv->doing_rubberband)
2066 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2070 gtk_icon_view_update_rubberband (gpointer data)
2072 GtkIconView *icon_view;
2074 GdkRectangle old_area;
2075 GdkRectangle new_area;
2076 GdkRectangle common;
2077 cairo_region_t *invalid_region;
2079 icon_view = GTK_ICON_VIEW (data);
2081 gdk_window_get_device_position (icon_view->priv->bin_window,
2082 icon_view->priv->rubberband_device,
2088 old_area.x = MIN (icon_view->priv->rubberband_x1,
2089 icon_view->priv->rubberband_x2);
2090 old_area.y = MIN (icon_view->priv->rubberband_y1,
2091 icon_view->priv->rubberband_y2);
2092 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2093 icon_view->priv->rubberband_x1) + 1;
2094 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2095 icon_view->priv->rubberband_y1) + 1;
2097 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2098 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2099 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2100 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2102 invalid_region = cairo_region_create_rectangle (&old_area);
2103 cairo_region_union_rectangle (invalid_region, &new_area);
2105 gdk_rectangle_intersect (&old_area, &new_area, &common);
2106 if (common.width > 2 && common.height > 2)
2108 cairo_region_t *common_region;
2110 /* make sure the border is invalidated */
2116 common_region = cairo_region_create_rectangle (&common);
2118 cairo_region_subtract (invalid_region, common_region);
2119 cairo_region_destroy (common_region);
2122 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2124 cairo_region_destroy (invalid_region);
2126 icon_view->priv->rubberband_x2 = x;
2127 icon_view->priv->rubberband_y2 = y;
2129 gtk_icon_view_update_rubberband_selection (icon_view);
2133 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2140 if (icon_view->priv->rubberband_device)
2143 for (items = icon_view->priv->items; items; items = items->next)
2145 GtkIconViewItem *item = items->data;
2147 item->selected_before_rubberbanding = item->selected;
2150 icon_view->priv->rubberband_x1 = x;
2151 icon_view->priv->rubberband_y1 = y;
2152 icon_view->priv->rubberband_x2 = x;
2153 icon_view->priv->rubberband_y2 = y;
2155 icon_view->priv->doing_rubberband = TRUE;
2156 icon_view->priv->rubberband_device = device;
2158 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2162 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2164 if (!icon_view->priv->doing_rubberband)
2167 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2168 icon_view->priv->rubberband_device);
2170 icon_view->priv->doing_rubberband = FALSE;
2171 icon_view->priv->rubberband_device = NULL;
2173 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2177 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2180 gint x, y, width, height;
2181 gboolean dirty = FALSE;
2183 x = MIN (icon_view->priv->rubberband_x1,
2184 icon_view->priv->rubberband_x2);
2185 y = MIN (icon_view->priv->rubberband_y1,
2186 icon_view->priv->rubberband_y2);
2187 width = ABS (icon_view->priv->rubberband_x1 -
2188 icon_view->priv->rubberband_x2);
2189 height = ABS (icon_view->priv->rubberband_y1 -
2190 icon_view->priv->rubberband_y2);
2192 for (items = icon_view->priv->items; items; items = items->next)
2194 GtkIconViewItem *item = items->data;
2198 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2199 x, y, width, height);
2201 selected = is_in ^ item->selected_before_rubberbanding;
2203 if (item->selected != selected)
2205 item->selected = selected;
2207 gtk_icon_view_queue_draw_item (icon_view, item);
2212 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2217 GdkRectangle hit_rect;
2222 hit_test (GtkCellRenderer *renderer,
2223 const GdkRectangle *cell_area,
2224 const GdkRectangle *cell_background,
2227 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2228 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2229 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2230 MAX (data->hit_rect.y, cell_area->y) > 0)
2233 return (data->hit != FALSE);
2237 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2238 GtkIconViewItem *item,
2244 HitTestData data = { { x, y, width, height }, FALSE };
2245 GtkCellAreaContext *context;
2246 GdkRectangle *item_area = (GdkRectangle *)item;
2248 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2249 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2252 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2254 _gtk_icon_view_set_cell_data (icon_view, item);
2255 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2256 GTK_WIDGET (icon_view),
2257 item_area, item_area,
2258 (GtkCellAllocCallback)hit_test, &data);
2264 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2266 gboolean dirty = FALSE;
2269 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2272 for (items = icon_view->priv->items; items; items = items->next)
2274 GtkIconViewItem *item = items->data;
2278 item->selected = FALSE;
2280 gtk_icon_view_queue_draw_item (icon_view, item);
2281 gtk_icon_view_item_selected_changed (icon_view, item);
2289 /* GtkIconView signals */
2291 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2293 gtk_icon_view_select_all (icon_view);
2297 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2299 gtk_icon_view_unselect_all (icon_view);
2303 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2305 gtk_icon_view_unselect_all (icon_view);
2307 if (icon_view->priv->cursor_item != NULL)
2308 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2312 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2315 GtkCellAreaContext *context;
2317 if (!icon_view->priv->cursor_item)
2320 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2322 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2323 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2324 GTK_WIDGET (icon_view),
2325 (GdkRectangle *)icon_view->priv->cursor_item,
2329 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2330 gtk_icon_view_item_activated (icon_view, path);
2331 gtk_tree_path_free (path);
2337 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2339 if (!icon_view->priv->cursor_item)
2342 switch (icon_view->priv->selection_mode)
2344 case GTK_SELECTION_NONE:
2346 case GTK_SELECTION_BROWSE:
2347 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2349 case GTK_SELECTION_SINGLE:
2350 if (icon_view->priv->cursor_item->selected)
2351 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2353 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2355 case GTK_SELECTION_MULTIPLE:
2356 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2357 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2359 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2360 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2365 /* Internal functions */
2367 gtk_icon_view_process_updates (GtkIconView *icon_view)
2369 /* Prior to drawing, we check if a layout has been scheduled. If so,
2370 * do it now that all cell view items have valid sizes before we proceeed
2371 * (and resize the bin_window if required).
2373 if (icon_view->priv->layout_idle_id != 0)
2374 gtk_icon_view_layout (icon_view);
2376 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2380 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2382 GtkAllocation allocation;
2383 GtkAdjustment *adj = icon_view->priv->hadjustment;
2384 gdouble old_page_size;
2390 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2392 old_value = gtk_adjustment_get_value (adj);
2393 old_upper = gtk_adjustment_get_upper (adj);
2394 old_page_size = gtk_adjustment_get_page_size (adj);
2395 new_upper = MAX (allocation.width, icon_view->priv->width);
2397 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2399 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2400 /* Quick explanation:
2401 * In LTR locales, leftmost portion of visible rectangle should stay
2402 * fixed, which means left edge of scrollbar thumb should remain fixed
2403 * and thus adjustment's value should stay the same.
2405 * In RTL locales, we want to keep rightmost portion of visible
2406 * rectangle fixed. This means right edge of thumb should remain fixed.
2407 * In this case, upper - value - page_size should remain constant.
2409 new_value = (new_upper - allocation.width) -
2410 (old_upper - old_value - old_page_size);
2411 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2414 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2416 gtk_adjustment_configure (adj,
2420 allocation.width * 0.1,
2421 allocation.width * 0.9,
2426 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2428 GtkAllocation allocation;
2429 GtkAdjustment *adj = icon_view->priv->vadjustment;
2431 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2433 gtk_adjustment_configure (adj,
2434 gtk_adjustment_get_value (adj),
2436 MAX (allocation.height, icon_view->priv->height),
2437 allocation.height * 0.1,
2438 allocation.height * 0.9,
2443 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2444 GtkAdjustment *adjustment)
2446 GtkIconViewPrivate *priv = icon_view->priv;
2448 if (adjustment && priv->hadjustment == adjustment)
2451 if (priv->hadjustment != NULL)
2453 g_signal_handlers_disconnect_matched (priv->hadjustment,
2454 G_SIGNAL_MATCH_DATA,
2455 0, 0, NULL, NULL, icon_view);
2456 g_object_unref (priv->hadjustment);
2460 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2463 g_signal_connect (adjustment, "value-changed",
2464 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2465 priv->hadjustment = g_object_ref_sink (adjustment);
2466 gtk_icon_view_set_hadjustment_values (icon_view);
2468 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2472 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2473 GtkAdjustment *adjustment)
2475 GtkIconViewPrivate *priv = icon_view->priv;
2477 if (adjustment && priv->vadjustment == adjustment)
2480 if (priv->vadjustment != NULL)
2482 g_signal_handlers_disconnect_matched (priv->vadjustment,
2483 G_SIGNAL_MATCH_DATA,
2484 0, 0, NULL, NULL, icon_view);
2485 g_object_unref (priv->vadjustment);
2489 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2492 g_signal_connect (adjustment, "value-changed",
2493 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2494 priv->vadjustment = g_object_ref_sink (adjustment);
2495 gtk_icon_view_set_vadjustment_values (icon_view);
2497 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2501 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2502 GtkIconView *icon_view)
2504 GtkIconViewPrivate *priv = icon_view->priv;
2506 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2508 gdk_window_move (priv->bin_window,
2509 - gtk_adjustment_get_value (priv->hadjustment),
2510 - gtk_adjustment_get_value (priv->vadjustment));
2512 if (icon_view->priv->doing_rubberband)
2513 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2515 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2517 gtk_icon_view_process_updates (icon_view);
2522 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2527 gint *maximum_width)
2529 GtkAllocation allocation;
2530 GtkCellAreaContext *context;
2531 GtkIconViewPrivate *priv = icon_view->priv;
2532 GtkWidget *widget = GTK_WIDGET (icon_view);
2533 gint x, current_width;
2534 GList *items, *last_item;
2536 gint max_height = 0;
2539 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2547 current_width += 2 * priv->margin;
2549 gtk_widget_get_allocation (widget, &allocation);
2551 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2552 g_ptr_array_add (priv->row_contexts, context);
2554 /* In the first loop we iterate horizontally until we hit allocation width
2555 * and collect the aligned height-for-width */
2559 GtkIconViewItem *item = items->data;
2560 GdkRectangle *item_area = (GdkRectangle *)item;
2562 item_area->width = item_width;
2564 current_width += item_area->width + icon_view->priv->item_padding * 2;
2566 if (items != first_item)
2568 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2569 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2573 /* Get this item's particular width & height (all alignments are cached by now) */
2574 _gtk_icon_view_set_cell_data (icon_view, item);
2575 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2580 current_width += icon_view->priv->column_spacing;
2582 item_area->y = *y + icon_view->priv->item_padding;
2583 item_area->x = x + icon_view->priv->item_padding;
2585 x = current_width - icon_view->priv->margin;
2587 if (current_width > *maximum_width)
2588 *maximum_width = current_width;
2594 items = items->next;
2599 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2600 gtk_cell_area_context_allocate (context, item_width, max_height);
2602 /* In the second loop the item height has been aligned and derived and
2603 * we just set the height and handle rtl layout */
2604 for (items = first_item; items != last_item; items = items->next)
2606 GtkIconViewItem *item = items->data;
2607 GdkRectangle *item_area = (GdkRectangle *)item;
2611 item_area->x = *maximum_width - item_area->width - item_area->x;
2612 item->col = col - 1 - item->col;
2615 /* All items in the same row get the same height */
2616 item_area->height = max_height;
2619 /* Adjust the new y coordinate. */
2620 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2626 adjust_wrap_width (GtkIconView *icon_view)
2628 if (icon_view->priv->text_cell)
2630 gint wrap_width = 50;
2632 /* Here we go with the same old guess, try the icon size and set double
2633 * the size of the first icon found in the list, naive but works much
2635 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2637 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2638 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2639 GTK_WIDGET (icon_view),
2642 wrap_width = MAX (wrap_width * 2, 50);
2645 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2646 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2651 gtk_icon_view_layout (GtkIconView *icon_view)
2653 GtkAllocation allocation;
2656 gint y = 0, maximum_width = 0;
2659 gboolean size_changed = FALSE;
2661 if (icon_view->priv->layout_idle_id != 0)
2663 g_source_remove (icon_view->priv->layout_idle_id);
2664 icon_view->priv->layout_idle_id = 0;
2667 if (icon_view->priv->model == NULL)
2670 widget = GTK_WIDGET (icon_view);
2672 item_width = icon_view->priv->item_width;
2674 /* Update the wrap width for the text cell before going and requesting sizes */
2675 adjust_wrap_width (icon_view);
2677 /* Update the context widths for any invalidated items */
2678 gtk_icon_view_cache_widths (icon_view);
2680 /* Fetch the new item width if needed */
2682 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2685 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2687 icons = icon_view->priv->items;
2688 y += icon_view->priv->margin;
2691 /* Clear the per row contexts */
2692 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2696 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2698 &y, &maximum_width);
2701 while (icons != NULL);
2703 if (maximum_width != icon_view->priv->width)
2705 icon_view->priv->width = maximum_width;
2706 size_changed = TRUE;
2709 y += icon_view->priv->margin;
2711 if (y != icon_view->priv->height)
2713 icon_view->priv->height = y;
2714 size_changed = TRUE;
2717 gtk_icon_view_set_hadjustment_values (icon_view);
2718 gtk_icon_view_set_vadjustment_values (icon_view);
2721 gtk_widget_queue_resize_no_redraw (widget);
2723 gtk_widget_get_allocation (widget, &allocation);
2724 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2725 gdk_window_resize (icon_view->priv->bin_window,
2726 MAX (icon_view->priv->width, allocation.width),
2727 MAX (icon_view->priv->height, allocation.height));
2729 if (icon_view->priv->scroll_to_path)
2733 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2734 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2735 icon_view->priv->scroll_to_path = NULL;
2737 gtk_icon_view_scroll_to_path (icon_view, path,
2738 icon_view->priv->scroll_to_use_align,
2739 icon_view->priv->scroll_to_row_align,
2740 icon_view->priv->scroll_to_col_align);
2741 gtk_tree_path_free (path);
2744 gtk_widget_queue_draw (widget);
2747 /* This ensures that all widths have been cached in the
2748 * context and we have proper alignments to go on.
2751 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2755 g_signal_handler_block (icon_view->priv->cell_area_context,
2756 icon_view->priv->context_changed_id);
2758 for (items = icon_view->priv->items; items; items = items->next)
2760 GtkIconViewItem *item = items->data;
2762 /* Only fetch the width of items with invalidated sizes */
2763 if (item->cell_area.width < 0)
2765 _gtk_icon_view_set_cell_data (icon_view, item);
2766 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2767 icon_view->priv->cell_area_context,
2768 GTK_WIDGET (icon_view), NULL, NULL);
2772 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2773 icon_view->priv->context_changed_id);
2777 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2779 /* Clear all item sizes */
2780 g_list_foreach (icon_view->priv->items,
2781 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2783 /* Reset the context */
2784 if (icon_view->priv->cell_area_context)
2786 g_signal_handler_block (icon_view->priv->cell_area_context,
2787 icon_view->priv->context_changed_id);
2788 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2789 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2790 icon_view->priv->context_changed_id);
2793 /* Re-layout the items */
2794 gtk_icon_view_queue_layout (icon_view);
2798 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2800 item->cell_area.width = -1;
2801 item->cell_area.height = -1;
2805 gtk_icon_view_paint_item (GtkIconView *icon_view,
2807 GtkIconViewItem *item,
2810 gboolean draw_focus)
2812 GdkRectangle cell_area;
2813 GtkStateFlags state = 0;
2814 GtkCellRendererState flags = 0;
2815 GtkStyleContext *style_context;
2816 GtkWidget *widget = GTK_WIDGET (icon_view);
2817 GtkIconViewPrivate *priv = icon_view->priv;
2818 GtkCellAreaContext *context;
2820 if (priv->model == NULL)
2823 _gtk_icon_view_set_cell_data (icon_view, item);
2825 style_context = gtk_widget_get_style_context (widget);
2826 state = gtk_widget_get_state_flags (widget);
2828 gtk_style_context_save (style_context);
2829 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2830 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2832 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
2836 if ((state & GTK_STATE_FLAG_FOCUSED) &&
2837 item == icon_view->priv->cursor_item)
2839 flags |= GTK_CELL_RENDERER_FOCUSED;
2842 state |= GTK_STATE_FLAG_SELECTED;
2843 flags |= GTK_CELL_RENDERER_SELECTED;
2848 state |= GTK_STATE_FLAG_PRELIGHT;
2849 flags |= GTK_CELL_RENDERER_PRELIT;
2852 gtk_style_context_set_state (style_context, state);
2856 gtk_render_background (style_context, cr,
2857 x - icon_view->priv->item_padding,
2858 y - icon_view->priv->item_padding,
2859 item->cell_area.width + icon_view->priv->item_padding * 2,
2860 item->cell_area.height + icon_view->priv->item_padding * 2);
2861 gtk_render_frame (style_context, cr,
2862 x - icon_view->priv->item_padding,
2863 y - icon_view->priv->item_padding,
2864 item->cell_area.width + icon_view->priv->item_padding * 2,
2865 item->cell_area.height + icon_view->priv->item_padding * 2);
2870 cell_area.width = item->cell_area.width;
2871 cell_area.height = item->cell_area.height;
2873 context = g_ptr_array_index (priv->row_contexts, item->row);
2874 gtk_cell_area_render (priv->cell_area, context,
2875 widget, cr, &cell_area, &cell_area, flags,
2878 gtk_style_context_restore (style_context);
2882 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2885 GtkStyleContext *context;
2890 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2891 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2892 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2893 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2895 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2897 gtk_style_context_save (context);
2898 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2900 gdk_cairo_rectangle (cr, &rect);
2903 gtk_render_background (context, cr,
2905 rect.width, rect.height);
2906 gtk_render_frame (context, cr,
2908 rect.width, rect.height);
2910 gtk_style_context_restore (context);
2915 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2921 index = gtk_tree_path_get_indices (path)[0];
2923 for (l = icon_view->priv->items; l; l = l->next)
2925 GtkIconViewItem *item = l->data;
2927 if (item->index == index)
2929 gtk_icon_view_queue_draw_item (icon_view, item);
2936 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2937 GtkIconViewItem *item)
2940 GdkRectangle *item_area = (GdkRectangle *)item;
2942 rect.x = item_area->x - icon_view->priv->item_padding;
2943 rect.y = item_area->y - icon_view->priv->item_padding;
2944 rect.width = item_area->width + icon_view->priv->item_padding * 2;
2945 rect.height = item_area->height + icon_view->priv->item_padding * 2;
2947 if (icon_view->priv->bin_window)
2948 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
2952 layout_callback (gpointer user_data)
2954 GtkIconView *icon_view;
2956 icon_view = GTK_ICON_VIEW (user_data);
2958 icon_view->priv->layout_idle_id = 0;
2960 gtk_icon_view_layout (icon_view);
2966 gtk_icon_view_queue_layout (GtkIconView *icon_view)
2968 if (icon_view->priv->layout_idle_id != 0)
2971 icon_view->priv->layout_idle_id =
2972 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
2973 layout_callback, icon_view, NULL);
2977 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
2978 GtkIconViewItem *item,
2979 GtkCellRenderer *cursor_cell)
2982 AtkObject *item_obj;
2983 AtkObject *cursor_item_obj;
2985 /* When hitting this path from keynav, the focus cell is
2986 * already set, we dont need to notify the atk object
2987 * but we still need to queue the draw here (in the case
2988 * that the focus cell changes but not the cursor item).
2990 gtk_icon_view_queue_draw_item (icon_view, item);
2992 if (icon_view->priv->cursor_item == item &&
2993 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
2996 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2997 if (icon_view->priv->cursor_item != NULL)
2999 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3002 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3003 if (cursor_item_obj != NULL)
3004 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3007 icon_view->priv->cursor_item = item;
3010 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3013 /* Make sure there is a cell in focus initially */
3014 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3015 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3018 /* Notify that accessible focus object has changed */
3019 item_obj = atk_object_ref_accessible_child (obj, item->index);
3021 if (item_obj != NULL)
3023 atk_focus_tracker_notify (item_obj);
3024 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3025 g_object_unref (item_obj);
3030 static GtkIconViewItem *
3031 gtk_icon_view_item_new (void)
3033 GtkIconViewItem *item;
3035 item = g_slice_new0 (GtkIconViewItem);
3037 item->cell_area.width = -1;
3038 item->cell_area.height = -1;
3044 gtk_icon_view_item_free (GtkIconViewItem *item)
3046 g_return_if_fail (item != NULL);
3048 g_slice_free (GtkIconViewItem, item);
3052 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3055 gboolean only_in_cell,
3056 GtkCellRenderer **cell_at_pos)
3061 *cell_at_pos = NULL;
3063 for (items = icon_view->priv->items; items; items = items->next)
3065 GtkIconViewItem *item = items->data;
3066 GdkRectangle *item_area = (GdkRectangle *)item;
3068 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3069 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3070 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3071 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3073 if (only_in_cell || cell_at_pos)
3075 GtkCellRenderer *cell = NULL;
3076 GtkCellAreaContext *context;
3078 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3079 _gtk_icon_view_set_cell_data (icon_view, item);
3081 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3082 y >= item_area->y && y <= item_area->y + item_area->height)
3083 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3084 GTK_WIDGET (icon_view),
3089 *cell_at_pos = cell;
3092 return cell != NULL ? item : NULL;
3103 _gtk_icon_view_select_item (GtkIconView *icon_view,
3104 GtkIconViewItem *item)
3106 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3107 g_return_if_fail (item != NULL);
3112 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3114 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3115 gtk_icon_view_unselect_all_internal (icon_view);
3117 item->selected = TRUE;
3119 gtk_icon_view_item_selected_changed (icon_view, item);
3120 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3122 gtk_icon_view_queue_draw_item (icon_view, item);
3127 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3128 GtkIconViewItem *item)
3130 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3131 g_return_if_fail (item != NULL);
3133 if (!item->selected)
3136 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3137 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3140 item->selected = FALSE;
3142 gtk_icon_view_item_selected_changed (icon_view, item);
3143 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3145 gtk_icon_view_queue_draw_item (icon_view, item);
3149 verify_items (GtkIconView *icon_view)
3154 for (items = icon_view->priv->items; items; items = items->next)
3156 GtkIconViewItem *item = items->data;
3158 if (item->index != i)
3159 g_error ("List item does not match its index: "
3160 "item index %d and list index %d\n", item->index, i);
3167 gtk_icon_view_row_changed (GtkTreeModel *model,
3172 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3174 /* ignore changes in branches */
3175 if (gtk_tree_path_get_depth (path) > 1)
3178 /* An icon view subclass might add it's own model and populate
3179 * things at init() time instead of waiting for the constructor()
3182 if (icon_view->priv->cell_area)
3183 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3185 /* Here we can use a "grow-only" strategy for optimization
3186 * and only invalidate a single item and queue a relayout
3187 * instead of invalidating the whole thing.
3189 * For now GtkIconView still cant deal with huge models
3190 * so just invalidate the whole thing when the model
3193 gtk_icon_view_invalidate_sizes (icon_view);
3195 verify_items (icon_view);
3199 gtk_icon_view_row_inserted (GtkTreeModel *model,
3204 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3206 GtkIconViewItem *item;
3207 gboolean iters_persist;
3210 /* ignore changes in branches */
3211 if (gtk_tree_path_get_depth (path) > 1)
3214 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3216 index = gtk_tree_path_get_indices(path)[0];
3218 item = gtk_icon_view_item_new ();
3223 item->index = index;
3225 /* FIXME: We can be more efficient here,
3226 we can store a tail pointer and use that when
3227 appending (which is a rather common operation)
3229 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3232 list = g_list_nth (icon_view->priv->items, index + 1);
3233 for (; list; list = list->next)
3240 verify_items (icon_view);
3242 gtk_icon_view_queue_layout (icon_view);
3246 gtk_icon_view_row_deleted (GtkTreeModel *model,
3250 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3252 GtkIconViewItem *item;
3254 gboolean emit = FALSE;
3256 /* ignore changes in branches */
3257 if (gtk_tree_path_get_depth (path) > 1)
3260 index = gtk_tree_path_get_indices(path)[0];
3262 list = g_list_nth (icon_view->priv->items, index);
3265 if (icon_view->priv->cell_area)
3266 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3268 if (item == icon_view->priv->anchor_item)
3269 icon_view->priv->anchor_item = NULL;
3271 if (item == icon_view->priv->cursor_item)
3272 icon_view->priv->cursor_item = NULL;
3274 if (item == icon_view->priv->last_prelight)
3275 icon_view->priv->last_prelight = NULL;
3280 gtk_icon_view_item_free (item);
3282 for (next = list->next; next; next = next->next)
3289 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3291 verify_items (icon_view);
3293 gtk_icon_view_queue_layout (icon_view);
3296 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3300 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3301 GtkTreePath *parent,
3306 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3309 GList *items = NULL, *list;
3310 GtkIconViewItem **item_array;
3313 /* ignore changes in branches */
3317 if (icon_view->priv->cell_area)
3318 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3320 length = gtk_tree_model_iter_n_children (model, NULL);
3322 order = g_new (gint, length);
3323 for (i = 0; i < length; i++)
3324 order [new_order[i]] = i;
3326 item_array = g_new (GtkIconViewItem *, length);
3327 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3328 item_array[order[i]] = list->data;
3331 for (i = length - 1; i >= 0; i--)
3333 item_array[i]->index = i;
3334 items = g_list_prepend (items, item_array[i]);
3337 g_free (item_array);
3338 g_list_free (icon_view->priv->items);
3339 icon_view->priv->items = items;
3341 gtk_icon_view_queue_layout (icon_view);
3343 verify_items (icon_view);
3347 gtk_icon_view_build_items (GtkIconView *icon_view)
3351 gboolean iters_persist;
3352 GList *items = NULL;
3354 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3356 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3364 GtkIconViewItem *item = gtk_icon_view_item_new ();
3373 items = g_list_prepend (items, item);
3375 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3377 icon_view->priv->items = g_list_reverse (items);
3381 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3384 GtkMovementStep step,
3388 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3389 I_("move-cursor"), 2,
3393 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3398 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3401 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3406 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3413 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3414 GtkMovementStep step,
3417 GdkModifierType state;
3419 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3420 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3421 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3422 step == GTK_MOVEMENT_DISPLAY_LINES ||
3423 step == GTK_MOVEMENT_PAGES ||
3424 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3426 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3429 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3430 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3432 if (gtk_get_current_event_state (&state))
3434 GdkModifierType extend_mod_mask;
3435 GdkModifierType modify_mod_mask;
3438 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3439 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3441 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3442 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3444 if ((state & modify_mod_mask) == modify_mod_mask)
3445 icon_view->priv->modify_selection_pressed = TRUE;
3446 if ((state & extend_mod_mask) == extend_mod_mask)
3447 icon_view->priv->extend_selection_pressed = TRUE;
3449 /* else we assume not pressed */
3453 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3454 case GTK_MOVEMENT_VISUAL_POSITIONS:
3455 gtk_icon_view_move_cursor_left_right (icon_view, count);
3457 case GTK_MOVEMENT_DISPLAY_LINES:
3458 gtk_icon_view_move_cursor_up_down (icon_view, count);
3460 case GTK_MOVEMENT_PAGES:
3461 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3463 case GTK_MOVEMENT_BUFFER_ENDS:
3464 gtk_icon_view_move_cursor_start_end (icon_view, count);
3467 g_assert_not_reached ();
3470 icon_view->priv->modify_selection_pressed = FALSE;
3471 icon_view->priv->extend_selection_pressed = FALSE;
3473 icon_view->priv->draw_focus = TRUE;
3478 static GtkIconViewItem *
3479 find_item (GtkIconView *icon_view,
3480 GtkIconViewItem *current,
3486 GtkIconViewItem *item;
3488 /* FIXME: this could be more efficient
3490 row = current->row + row_ofs;
3491 col = current->col + col_ofs;
3493 for (items = icon_view->priv->items; items; items = items->next)
3496 if (item->row == row && item->col == col)
3503 static GtkIconViewItem *
3504 find_item_page_up_down (GtkIconView *icon_view,
3505 GtkIconViewItem *current,
3512 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3514 item = g_list_find (icon_view->priv->items, current);
3519 for (next = item->next; next; next = next->next)
3521 if (((GtkIconViewItem *)next->data)->col == col)
3524 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3534 for (next = item->prev; next; next = next->prev)
3536 if (((GtkIconViewItem *)next->data)->col == col)
3539 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3553 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3554 GtkIconViewItem *anchor,
3555 GtkIconViewItem *cursor)
3558 GtkIconViewItem *item;
3559 gint row1, row2, col1, col2;
3560 gboolean dirty = FALSE;
3562 if (anchor->row < cursor->row)
3573 if (anchor->col < cursor->col)
3584 for (items = icon_view->priv->items; items; items = items->next)
3588 if (row1 <= item->row && item->row <= row2 &&
3589 col1 <= item->col && item->col <= col2)
3591 if (!item->selected)
3594 item->selected = TRUE;
3595 gtk_icon_view_item_selected_changed (icon_view, item);
3597 gtk_icon_view_queue_draw_item (icon_view, item);
3605 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3608 GtkIconViewItem *item;
3609 GtkCellRenderer *cell = NULL;
3610 gboolean dirty = FALSE;
3612 GtkDirectionType direction;
3614 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3617 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3619 if (!icon_view->priv->cursor_item)
3624 list = icon_view->priv->items;
3626 list = g_list_last (icon_view->priv->items);
3632 /* Give focus to the first cell initially */
3633 _gtk_icon_view_set_cell_data (icon_view, item);
3634 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3643 item = icon_view->priv->cursor_item;
3644 step = count > 0 ? 1 : -1;
3646 /* Save the current focus cell in case we hit the edge */
3647 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3651 _gtk_icon_view_set_cell_data (icon_view, item);
3653 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3656 item = find_item (icon_view, item, step, 0);
3662 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3664 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3666 gtk_widget_child_focus (toplevel,
3667 direction == GTK_DIR_UP ?
3668 GTK_DIR_TAB_BACKWARD :
3669 GTK_DIR_TAB_FORWARD);
3673 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3677 if (icon_view->priv->modify_selection_pressed ||
3678 !icon_view->priv->extend_selection_pressed ||
3679 !icon_view->priv->anchor_item ||
3680 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3681 icon_view->priv->anchor_item = item;
3683 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3684 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3686 if (!icon_view->priv->modify_selection_pressed &&
3687 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3689 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3690 dirty = gtk_icon_view_select_all_between (icon_view,
3691 icon_view->priv->anchor_item,
3695 gtk_icon_view_scroll_to_item (icon_view, item);
3698 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3702 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3705 GtkIconViewItem *item;
3706 gboolean dirty = FALSE;
3708 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3711 if (!icon_view->priv->cursor_item)
3716 list = icon_view->priv->items;
3718 list = g_list_last (icon_view->priv->items);
3720 item = list ? list->data : NULL;
3723 item = find_item_page_up_down (icon_view,
3724 icon_view->priv->cursor_item,
3727 if (item == icon_view->priv->cursor_item)
3728 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3733 if (icon_view->priv->modify_selection_pressed ||
3734 !icon_view->priv->extend_selection_pressed ||
3735 !icon_view->priv->anchor_item ||
3736 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3737 icon_view->priv->anchor_item = item;
3739 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3741 if (!icon_view->priv->modify_selection_pressed &&
3742 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3744 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3745 dirty = gtk_icon_view_select_all_between (icon_view,
3746 icon_view->priv->anchor_item,
3750 gtk_icon_view_scroll_to_item (icon_view, item);
3753 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3757 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3760 GtkIconViewItem *item;
3761 GtkCellRenderer *cell = NULL;
3762 gboolean dirty = FALSE;
3764 GtkDirectionType direction;
3766 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3769 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3771 if (!icon_view->priv->cursor_item)
3776 list = icon_view->priv->items;
3778 list = g_list_last (icon_view->priv->items);
3784 /* Give focus to the first cell initially */
3785 _gtk_icon_view_set_cell_data (icon_view, item);
3786 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3795 item = icon_view->priv->cursor_item;
3796 step = count > 0 ? 1 : -1;
3798 /* Save the current focus cell in case we hit the edge */
3799 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3803 _gtk_icon_view_set_cell_data (icon_view, item);
3805 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3808 item = find_item (icon_view, item, 0, step);
3814 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3816 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3818 gtk_widget_child_focus (toplevel,
3819 direction == GTK_DIR_LEFT ?
3820 GTK_DIR_TAB_BACKWARD :
3821 GTK_DIR_TAB_FORWARD);
3825 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3829 if (icon_view->priv->modify_selection_pressed ||
3830 !icon_view->priv->extend_selection_pressed ||
3831 !icon_view->priv->anchor_item ||
3832 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3833 icon_view->priv->anchor_item = item;
3835 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3836 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3838 if (!icon_view->priv->modify_selection_pressed &&
3839 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3841 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3842 dirty = gtk_icon_view_select_all_between (icon_view,
3843 icon_view->priv->anchor_item,
3847 gtk_icon_view_scroll_to_item (icon_view, item);
3850 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3854 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3857 GtkIconViewItem *item;
3859 gboolean dirty = FALSE;
3861 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3865 list = icon_view->priv->items;
3867 list = g_list_last (icon_view->priv->items);
3869 item = list ? list->data : NULL;
3871 if (item == icon_view->priv->cursor_item)
3872 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3877 if (icon_view->priv->modify_selection_pressed ||
3878 !icon_view->priv->extend_selection_pressed ||
3879 !icon_view->priv->anchor_item ||
3880 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3881 icon_view->priv->anchor_item = item;
3883 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3885 if (!icon_view->priv->modify_selection_pressed &&
3886 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3888 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3889 dirty = gtk_icon_view_select_all_between (icon_view,
3890 icon_view->priv->anchor_item,
3894 gtk_icon_view_scroll_to_item (icon_view, item);
3897 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3901 * gtk_icon_view_scroll_to_path:
3902 * @icon_view: A #GtkIconView.
3903 * @path: The path of the item to move to.
3904 * @use_align: whether to use alignment arguments, or %FALSE.
3905 * @row_align: The vertical alignment of the item specified by @path.
3906 * @col_align: The horizontal alignment of the item specified by @path.
3908 * Moves the alignments of @icon_view to the position specified by @path.
3909 * @row_align determines where the row is placed, and @col_align determines
3910 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3911 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3914 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3915 * tree does the minimum amount of work to scroll the item onto the screen.
3916 * This means that the item will be scrolled to the edge closest to its current
3917 * position. If the item is currently visible on the screen, nothing is done.
3919 * This function only works if the model is set, and @path is a valid row on
3920 * the model. If the model changes before the @icon_view is realized, the
3921 * centered path will be modified to reflect this change.
3926 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3932 GtkIconViewItem *item = NULL;
3935 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3936 g_return_if_fail (path != NULL);
3937 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3938 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3940 widget = GTK_WIDGET (icon_view);
3942 if (gtk_tree_path_get_depth (path) > 0)
3943 item = g_list_nth_data (icon_view->priv->items,
3944 gtk_tree_path_get_indices(path)[0]);
3946 if (!item || item->cell_area.width < 0 ||
3947 !gtk_widget_get_realized (widget))
3949 if (icon_view->priv->scroll_to_path)
3950 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3952 icon_view->priv->scroll_to_path = NULL;
3955 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3957 icon_view->priv->scroll_to_use_align = use_align;
3958 icon_view->priv->scroll_to_row_align = row_align;
3959 icon_view->priv->scroll_to_col_align = col_align;
3966 GtkAllocation allocation;
3969 GdkRectangle item_area =
3971 item->cell_area.x - icon_view->priv->item_padding,
3972 item->cell_area.y - icon_view->priv->item_padding,
3973 item->cell_area.width + icon_view->priv->item_padding * 2,
3974 item->cell_area.height + icon_view->priv->item_padding * 2
3977 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3979 gtk_widget_get_allocation (widget, &allocation);
3981 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
3983 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3984 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
3986 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
3988 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3989 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
3991 gtk_adjustment_changed (icon_view->priv->hadjustment);
3992 gtk_adjustment_changed (icon_view->priv->vadjustment);
3995 gtk_icon_view_scroll_to_item (icon_view, item);
4000 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4001 GtkIconViewItem *item)
4003 GtkIconViewPrivate *priv = icon_view->priv;
4004 GtkWidget *widget = GTK_WIDGET (icon_view);
4005 GtkAdjustment *hadj, *vadj;
4006 GtkAllocation allocation;
4008 GdkRectangle item_area;
4010 item_area.x = item->cell_area.x - priv->item_padding;
4011 item_area.y = item->cell_area.y - priv->item_padding;
4012 item_area.width = item->cell_area.width + priv->item_padding * 2;
4013 item_area.height = item->cell_area.height + priv->item_padding * 2;
4015 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4016 gtk_widget_get_allocation (widget, &allocation);
4018 hadj = icon_view->priv->hadjustment;
4019 vadj = icon_view->priv->vadjustment;
4021 if (y + item_area.y < 0)
4022 gtk_adjustment_set_value (vadj,
4023 gtk_adjustment_get_value (vadj)
4025 else if (y + item_area.y + item_area.height > allocation.height)
4026 gtk_adjustment_set_value (vadj,
4027 gtk_adjustment_get_value (vadj)
4028 + y + item_area.y + item_area.height - allocation.height);
4030 if (x + item_area.x < 0)
4031 gtk_adjustment_set_value (hadj,
4032 gtk_adjustment_get_value (hadj)
4034 else if (x + item_area.x + item_area.width > allocation.width)
4035 gtk_adjustment_set_value (hadj,
4036 gtk_adjustment_get_value (hadj)
4037 + x + item_area.x + item_area.width - allocation.width);
4039 gtk_adjustment_changed (hadj);
4040 gtk_adjustment_changed (vadj);
4043 /* GtkCellLayout implementation */
4046 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4047 GtkCellArea *cell_area)
4049 GtkIconViewPrivate *priv = icon_view->priv;
4051 if (priv->cell_area)
4055 priv->cell_area = cell_area;
4057 priv->cell_area = gtk_cell_area_box_new ();
4059 g_object_ref_sink (priv->cell_area);
4061 if (GTK_IS_ORIENTABLE (priv->cell_area))
4062 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4064 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4066 priv->add_editable_id =
4067 g_signal_connect (priv->cell_area, "add-editable",
4068 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4069 priv->remove_editable_id =
4070 g_signal_connect (priv->cell_area, "remove-editable",
4071 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4072 priv->context_changed_id =
4073 g_signal_connect (priv->cell_area_context, "notify",
4074 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4076 update_text_cell (icon_view);
4077 update_pixbuf_cell (icon_view);
4080 static GtkCellArea *
4081 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4083 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4084 GtkIconViewPrivate *priv = icon_view->priv;
4086 if (G_UNLIKELY (!priv->cell_area))
4087 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4089 return icon_view->priv->cell_area;
4093 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4094 GtkIconViewItem *item)
4096 gboolean iters_persist;
4099 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4105 path = gtk_tree_path_new_from_indices (item->index, -1);
4106 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4108 gtk_tree_path_free (path);
4113 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4114 icon_view->priv->model,
4115 &iter, FALSE, FALSE);
4124 * gtk_icon_view_new:
4126 * Creates a new #GtkIconView widget
4128 * Return value: A newly created #GtkIconView widget
4133 gtk_icon_view_new (void)
4135 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4139 * gtk_icon_view_new_with_area:
4140 * @area: the #GtkCellArea to use to layout cells
4142 * Creates a new #GtkIconView widget using the
4143 * specified @area to layout cells inside the icons.
4145 * Return value: A newly created #GtkIconView widget
4150 gtk_icon_view_new_with_area (GtkCellArea *area)
4152 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4156 * gtk_icon_view_new_with_model:
4157 * @model: The model.
4159 * Creates a new #GtkIconView widget with the model @model.
4161 * Return value: A newly created #GtkIconView widget.
4166 gtk_icon_view_new_with_model (GtkTreeModel *model)
4168 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4172 * gtk_icon_view_convert_widget_to_bin_window_coords:
4173 * @icon_view: a #GtkIconView
4174 * @wx: X coordinate relative to the widget
4175 * @wy: Y coordinate relative to the widget
4176 * @bx: (out): return location for bin_window X coordinate
4177 * @by: (out): return location for bin_window Y coordinate
4179 * Converts widget coordinates to coordinates for the bin_window,
4180 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4185 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4193 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4195 if (icon_view->priv->bin_window)
4196 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4207 * gtk_icon_view_get_path_at_pos:
4208 * @icon_view: A #GtkIconView.
4209 * @x: The x position to be identified
4210 * @y: The y position to be identified
4212 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4213 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4214 * the cell at the specified position.
4215 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4216 * widget coordinates to bin_window coordinates.
4218 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4219 * if no icon exists at that position.
4224 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4228 GtkIconViewItem *item;
4231 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4233 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4238 path = gtk_tree_path_new_from_indices (item->index, -1);
4244 * gtk_icon_view_get_item_at_pos:
4245 * @icon_view: A #GtkIconView.
4246 * @x: The x position to be identified
4247 * @y: The y position to be identified
4248 * @path: (out) (allow-none): Return location for the path, or %NULL
4249 * @cell: (out) (allow-none): Return location for the renderer
4250 * responsible for the cell at (@x, @y), or %NULL
4252 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4253 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4254 * obtains the cell at the specified position. The returned path should
4255 * be freed with gtk_tree_path_free().
4256 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4257 * widget coordinates to bin_window coordinates.
4259 * Return value: %TRUE if an item exists at the specified position
4264 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4268 GtkCellRenderer **cell)
4270 GtkIconViewItem *item;
4271 GtkCellRenderer *renderer = NULL;
4273 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4275 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4280 *path = gtk_tree_path_new_from_indices (item->index, -1);
4288 return (item != NULL);
4292 * gtk_icon_view_set_tooltip_item:
4293 * @icon_view: a #GtkIconView
4294 * @tooltip: a #GtkTooltip
4295 * @path: a #GtkTreePath
4297 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4298 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4299 * See also gtk_tooltip_set_tip_area().
4304 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4305 GtkTooltip *tooltip,
4308 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4309 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4311 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4315 * gtk_icon_view_set_tooltip_cell:
4316 * @icon_view: a #GtkIconView
4317 * @tooltip: a #GtkTooltip
4318 * @path: a #GtkTreePath
4319 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4321 * Sets the tip area of @tooltip to the area which @cell occupies in
4322 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4324 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4329 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4330 GtkTooltip *tooltip,
4332 GtkCellRenderer *cell)
4335 GtkIconViewItem *item = NULL;
4338 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4339 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4340 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4342 if (gtk_tree_path_get_depth (path) > 0)
4343 item = g_list_nth_data (icon_view->priv->items,
4344 gtk_tree_path_get_indices(path)[0]);
4351 GtkCellAreaContext *context;
4353 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4354 _gtk_icon_view_set_cell_data (icon_view, item);
4355 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4356 GTK_WIDGET (icon_view),
4357 cell, (GdkRectangle *)item, &rect);
4361 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4362 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4363 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4364 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4367 if (icon_view->priv->bin_window)
4369 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4374 gtk_tooltip_set_tip_area (tooltip, &rect);
4379 * gtk_icon_view_get_tooltip_context:
4380 * @icon_view: an #GtkIconView
4381 * @x: (inout): the x coordinate (relative to widget coordinates)
4382 * @y: (inout): the y coordinate (relative to widget coordinates)
4383 * @keyboard_tip: whether this is a keyboard tooltip or not
4384 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4385 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4386 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4388 * This function is supposed to be used in a #GtkWidget::query-tooltip
4389 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4390 * which are received in the signal handler, should be passed to this
4391 * function without modification.
4393 * The return value indicates whether there is an icon view item at the given
4394 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4395 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4396 * @model, @path and @iter which have been provided will be set to point to
4397 * that row and the corresponding model. @x and @y will always be converted
4398 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4400 * Return value: whether or not the given tooltip context points to a item
4405 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4408 gboolean keyboard_tip,
4409 GtkTreeModel **model,
4413 GtkTreePath *tmppath = NULL;
4415 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4416 g_return_val_if_fail (x != NULL, FALSE);
4417 g_return_val_if_fail (y != NULL, FALSE);
4421 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4428 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4431 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4436 *model = gtk_icon_view_get_model (icon_view);
4439 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4445 gtk_tree_path_free (tmppath);
4451 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4454 gboolean keyboard_tip,
4455 GtkTooltip *tooltip,
4461 GtkTreeModel *model;
4462 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4464 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4467 &model, &path, &iter))
4470 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4474 gtk_tree_path_free (path);
4478 gtk_tooltip_set_markup (tooltip, str);
4479 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4481 gtk_tree_path_free (path);
4489 * gtk_icon_view_set_tooltip_column:
4490 * @icon_view: a #GtkIconView
4491 * @column: an integer, which is a valid column number for @icon_view's model
4493 * If you only plan to have simple (text-only) tooltips on full items, you
4494 * can use this function to have #GtkIconView handle these automatically
4495 * for you. @column should be set to the column in @icon_view's model
4496 * containing the tooltip texts, or -1 to disable this feature.
4498 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4499 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4501 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4502 * so &, <, etc have to be escaped in the text.
4507 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4510 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4512 if (column == icon_view->priv->tooltip_column)
4517 g_signal_handlers_disconnect_by_func (icon_view,
4518 gtk_icon_view_set_tooltip_query_cb,
4520 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4524 if (icon_view->priv->tooltip_column == -1)
4526 g_signal_connect (icon_view, "query-tooltip",
4527 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4528 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4532 icon_view->priv->tooltip_column = column;
4533 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4537 * gtk_icon_view_get_tooltip_column:
4538 * @icon_view: a #GtkIconView
4540 * Returns the column of @icon_view's model which is being used for
4541 * displaying tooltips on @icon_view's rows.
4543 * Return value: the index of the tooltip column that is currently being
4544 * used, or -1 if this is disabled.
4549 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4551 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4553 return icon_view->priv->tooltip_column;
4557 * gtk_icon_view_get_visible_range:
4558 * @icon_view: A #GtkIconView
4559 * @start_path: (out) (allow-none): Return location for start of region,
4561 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4563 * Sets @start_path and @end_path to be the first and last visible path.
4564 * Note that there may be invisible paths in between.
4566 * Both paths should be freed with gtk_tree_path_free() after use.
4568 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4573 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4574 GtkTreePath **start_path,
4575 GtkTreePath **end_path)
4577 gint start_index = -1;
4578 gint end_index = -1;
4581 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4583 if (icon_view->priv->hadjustment == NULL ||
4584 icon_view->priv->vadjustment == NULL)
4587 if (start_path == NULL && end_path == NULL)
4590 for (icons = icon_view->priv->items; icons; icons = icons->next)
4592 GtkIconViewItem *item = icons->data;
4593 GdkRectangle *item_area = (GdkRectangle *)item;
4595 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4596 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4598 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4599 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4601 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4602 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4604 if (start_index == -1)
4605 start_index = item->index;
4606 end_index = item->index;
4610 if (start_path && start_index != -1)
4611 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4612 if (end_path && end_index != -1)
4613 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4615 return start_index != -1;
4619 * gtk_icon_view_selected_foreach:
4620 * @icon_view: A #GtkIconView.
4621 * @func: (scope call): The function to call for each selected icon.
4622 * @data: User data to pass to the function.
4624 * Calls a function for each selected icon. Note that the model or
4625 * selection cannot be modified from within this function.
4630 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4631 GtkIconViewForeachFunc func,
4636 for (list = icon_view->priv->items; list; list = list->next)
4638 GtkIconViewItem *item = list->data;
4639 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4642 (* func) (icon_view, path, data);
4644 gtk_tree_path_free (path);
4649 * gtk_icon_view_set_selection_mode:
4650 * @icon_view: A #GtkIconView.
4651 * @mode: The selection mode
4653 * Sets the selection mode of the @icon_view.
4658 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4659 GtkSelectionMode mode)
4661 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4663 if (mode == icon_view->priv->selection_mode)
4666 if (mode == GTK_SELECTION_NONE ||
4667 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4668 gtk_icon_view_unselect_all (icon_view);
4670 icon_view->priv->selection_mode = mode;
4672 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4676 * gtk_icon_view_get_selection_mode:
4677 * @icon_view: A #GtkIconView.
4679 * Gets the selection mode of the @icon_view.
4681 * Return value: the current selection mode
4686 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4688 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4690 return icon_view->priv->selection_mode;
4694 * gtk_icon_view_set_model:
4695 * @icon_view: A #GtkIconView.
4696 * @model: (allow-none): The model.
4698 * Sets the model for a #GtkIconView.
4699 * If the @icon_view already has a model set, it will remove
4700 * it before setting the new model. If @model is %NULL, then
4701 * it will unset the old model.
4706 gtk_icon_view_set_model (GtkIconView *icon_view,
4707 GtkTreeModel *model)
4709 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4710 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4712 if (icon_view->priv->model == model)
4715 if (icon_view->priv->scroll_to_path)
4717 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4718 icon_view->priv->scroll_to_path = NULL;
4721 /* The area can be NULL while disposing */
4722 if (icon_view->priv->cell_area)
4723 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4729 if (icon_view->priv->pixbuf_column != -1)
4731 column_type = gtk_tree_model_get_column_type (model,
4732 icon_view->priv->pixbuf_column);
4734 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4737 if (icon_view->priv->text_column != -1)
4739 column_type = gtk_tree_model_get_column_type (model,
4740 icon_view->priv->text_column);
4742 g_return_if_fail (column_type == G_TYPE_STRING);
4745 if (icon_view->priv->markup_column != -1)
4747 column_type = gtk_tree_model_get_column_type (model,
4748 icon_view->priv->markup_column);
4750 g_return_if_fail (column_type == G_TYPE_STRING);
4755 if (icon_view->priv->model)
4757 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4758 gtk_icon_view_row_changed,
4760 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4761 gtk_icon_view_row_inserted,
4763 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4764 gtk_icon_view_row_deleted,
4766 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4767 gtk_icon_view_rows_reordered,
4770 g_object_unref (icon_view->priv->model);
4772 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4773 icon_view->priv->items = NULL;
4774 icon_view->priv->anchor_item = NULL;
4775 icon_view->priv->cursor_item = NULL;
4776 icon_view->priv->last_single_clicked = NULL;
4777 icon_view->priv->last_prelight = NULL;
4778 icon_view->priv->width = 0;
4779 icon_view->priv->height = 0;
4782 icon_view->priv->model = model;
4784 if (icon_view->priv->model)
4786 g_object_ref (icon_view->priv->model);
4787 g_signal_connect (icon_view->priv->model,
4789 G_CALLBACK (gtk_icon_view_row_changed),
4791 g_signal_connect (icon_view->priv->model,
4793 G_CALLBACK (gtk_icon_view_row_inserted),
4795 g_signal_connect (icon_view->priv->model,
4797 G_CALLBACK (gtk_icon_view_row_deleted),
4799 g_signal_connect (icon_view->priv->model,
4801 G_CALLBACK (gtk_icon_view_rows_reordered),
4804 gtk_icon_view_build_items (icon_view);
4806 gtk_icon_view_layout (icon_view);
4809 g_object_notify (G_OBJECT (icon_view), "model");
4811 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4812 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4816 * gtk_icon_view_get_model:
4817 * @icon_view: a #GtkIconView
4819 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4822 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4823 * currently being used.
4828 gtk_icon_view_get_model (GtkIconView *icon_view)
4830 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4832 return icon_view->priv->model;
4836 update_text_cell (GtkIconView *icon_view)
4838 if (!icon_view->priv->cell_area)
4841 if (icon_view->priv->text_column == -1 &&
4842 icon_view->priv->markup_column == -1)
4844 if (icon_view->priv->text_cell != NULL)
4846 gtk_cell_area_remove (icon_view->priv->cell_area,
4847 icon_view->priv->text_cell);
4848 icon_view->priv->text_cell = NULL;
4853 if (icon_view->priv->text_cell == NULL)
4855 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4857 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4860 if (icon_view->priv->markup_column != -1)
4861 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4862 icon_view->priv->text_cell,
4863 "markup", icon_view->priv->markup_column,
4866 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4867 icon_view->priv->text_cell,
4868 "text", icon_view->priv->text_column,
4871 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4872 g_object_set (icon_view->priv->text_cell,
4873 "alignment", PANGO_ALIGN_CENTER,
4874 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4879 g_object_set (icon_view->priv->text_cell,
4880 "alignment", PANGO_ALIGN_LEFT,
4881 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4889 update_pixbuf_cell (GtkIconView *icon_view)
4891 if (!icon_view->priv->cell_area)
4894 if (icon_view->priv->pixbuf_column == -1)
4896 if (icon_view->priv->pixbuf_cell != NULL)
4898 gtk_cell_area_remove (icon_view->priv->cell_area,
4899 icon_view->priv->pixbuf_cell);
4901 icon_view->priv->pixbuf_cell = NULL;
4906 if (icon_view->priv->pixbuf_cell == NULL)
4908 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4910 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4913 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4914 icon_view->priv->pixbuf_cell,
4915 "pixbuf", icon_view->priv->pixbuf_column,
4918 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4919 g_object_set (icon_view->priv->pixbuf_cell,
4924 g_object_set (icon_view->priv->pixbuf_cell,
4932 * gtk_icon_view_set_text_column:
4933 * @icon_view: A #GtkIconView.
4934 * @column: A column in the currently used model, or -1 to display no text
4936 * Sets the column with text for @icon_view to be @column. The text
4937 * column must be of type #G_TYPE_STRING.
4942 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4945 if (column == icon_view->priv->text_column)
4949 icon_view->priv->text_column = -1;
4952 if (icon_view->priv->model != NULL)
4956 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4958 g_return_if_fail (column_type == G_TYPE_STRING);
4961 icon_view->priv->text_column = column;
4964 if (icon_view->priv->cell_area)
4965 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4967 update_text_cell (icon_view);
4969 gtk_icon_view_invalidate_sizes (icon_view);
4971 g_object_notify (G_OBJECT (icon_view), "text-column");
4975 * gtk_icon_view_get_text_column:
4976 * @icon_view: A #GtkIconView.
4978 * Returns the column with text for @icon_view.
4980 * Returns: the text column, or -1 if it's unset.
4985 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4987 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4989 return icon_view->priv->text_column;
4993 * gtk_icon_view_set_markup_column:
4994 * @icon_view: A #GtkIconView.
4995 * @column: A column in the currently used model, or -1 to display no text
4997 * Sets the column with markup information for @icon_view to be
4998 * @column. The markup column must be of type #G_TYPE_STRING.
4999 * If the markup column is set to something, it overrides
5000 * the text column set by gtk_icon_view_set_text_column().
5005 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5008 if (column == icon_view->priv->markup_column)
5012 icon_view->priv->markup_column = -1;
5015 if (icon_view->priv->model != NULL)
5019 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5021 g_return_if_fail (column_type == G_TYPE_STRING);
5024 icon_view->priv->markup_column = column;
5027 if (icon_view->priv->cell_area)
5028 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5030 update_text_cell (icon_view);
5032 gtk_icon_view_invalidate_sizes (icon_view);
5034 g_object_notify (G_OBJECT (icon_view), "markup-column");
5038 * gtk_icon_view_get_markup_column:
5039 * @icon_view: A #GtkIconView.
5041 * Returns the column with markup text for @icon_view.
5043 * Returns: the markup column, or -1 if it's unset.
5048 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5050 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5052 return icon_view->priv->markup_column;
5056 * gtk_icon_view_set_pixbuf_column:
5057 * @icon_view: A #GtkIconView.
5058 * @column: A column in the currently used model, or -1 to disable
5060 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5061 * column must be of type #GDK_TYPE_PIXBUF
5066 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5069 if (column == icon_view->priv->pixbuf_column)
5073 icon_view->priv->pixbuf_column = -1;
5076 if (icon_view->priv->model != NULL)
5080 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5082 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5085 icon_view->priv->pixbuf_column = column;
5088 if (icon_view->priv->cell_area)
5089 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5091 update_pixbuf_cell (icon_view);
5093 gtk_icon_view_invalidate_sizes (icon_view);
5095 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5100 * gtk_icon_view_get_pixbuf_column:
5101 * @icon_view: A #GtkIconView.
5103 * Returns the column with pixbufs for @icon_view.
5105 * Returns: the pixbuf column, or -1 if it's unset.
5110 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5112 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5114 return icon_view->priv->pixbuf_column;
5118 * gtk_icon_view_select_path:
5119 * @icon_view: A #GtkIconView.
5120 * @path: The #GtkTreePath to be selected.
5122 * Selects the row at @path.
5127 gtk_icon_view_select_path (GtkIconView *icon_view,
5130 GtkIconViewItem *item = NULL;
5132 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5133 g_return_if_fail (icon_view->priv->model != NULL);
5134 g_return_if_fail (path != NULL);
5136 if (gtk_tree_path_get_depth (path) > 0)
5137 item = g_list_nth_data (icon_view->priv->items,
5138 gtk_tree_path_get_indices(path)[0]);
5141 _gtk_icon_view_select_item (icon_view, item);
5145 * gtk_icon_view_unselect_path:
5146 * @icon_view: A #GtkIconView.
5147 * @path: The #GtkTreePath to be unselected.
5149 * Unselects the row at @path.
5154 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5157 GtkIconViewItem *item;
5159 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5160 g_return_if_fail (icon_view->priv->model != NULL);
5161 g_return_if_fail (path != NULL);
5163 item = g_list_nth_data (icon_view->priv->items,
5164 gtk_tree_path_get_indices(path)[0]);
5169 _gtk_icon_view_unselect_item (icon_view, item);
5173 * gtk_icon_view_get_selected_items:
5174 * @icon_view: A #GtkIconView.
5176 * Creates a list of paths of all selected items. Additionally, if you are
5177 * planning on modifying the model after calling this function, you may
5178 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5179 * To do this, you can use gtk_tree_row_reference_new().
5181 * To free the return value, use:
5183 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5186 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5191 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5194 GList *selected = NULL;
5196 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5198 for (list = icon_view->priv->items; list != NULL; list = list->next)
5200 GtkIconViewItem *item = list->data;
5204 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5206 selected = g_list_prepend (selected, path);
5214 * gtk_icon_view_select_all:
5215 * @icon_view: A #GtkIconView.
5217 * Selects all the icons. @icon_view must has its selection mode set
5218 * to #GTK_SELECTION_MULTIPLE.
5223 gtk_icon_view_select_all (GtkIconView *icon_view)
5226 gboolean dirty = FALSE;
5228 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5230 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5233 for (items = icon_view->priv->items; items; items = items->next)
5235 GtkIconViewItem *item = items->data;
5237 if (!item->selected)
5240 item->selected = TRUE;
5241 gtk_icon_view_queue_draw_item (icon_view, item);
5246 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5250 * gtk_icon_view_unselect_all:
5251 * @icon_view: A #GtkIconView.
5253 * Unselects all the icons.
5258 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5260 gboolean dirty = FALSE;
5262 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5264 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5267 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5270 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5274 * gtk_icon_view_path_is_selected:
5275 * @icon_view: A #GtkIconView.
5276 * @path: A #GtkTreePath to check selection on.
5278 * Returns %TRUE if the icon pointed to by @path is currently
5279 * selected. If @path does not point to a valid location, %FALSE is returned.
5281 * Return value: %TRUE if @path is selected.
5286 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5289 GtkIconViewItem *item;
5291 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5292 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5293 g_return_val_if_fail (path != NULL, FALSE);
5295 item = g_list_nth_data (icon_view->priv->items,
5296 gtk_tree_path_get_indices(path)[0]);
5301 return item->selected;
5305 * gtk_icon_view_get_item_row:
5306 * @icon_view: a #GtkIconView
5307 * @path: the #GtkTreePath of the item
5309 * Gets the row in which the item @path is currently
5310 * displayed. Row numbers start at 0.
5312 * Returns: The row in which the item is displayed
5317 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5320 GtkIconViewItem *item;
5322 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5323 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5324 g_return_val_if_fail (path != NULL, -1);
5326 item = g_list_nth_data (icon_view->priv->items,
5327 gtk_tree_path_get_indices(path)[0]);
5336 * gtk_icon_view_get_item_column:
5337 * @icon_view: a #GtkIconView
5338 * @path: the #GtkTreePath of the item
5340 * Gets the column in which the item @path is currently
5341 * displayed. Column numbers start at 0.
5343 * Returns: The column in which the item is displayed
5348 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5351 GtkIconViewItem *item;
5353 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5354 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5355 g_return_val_if_fail (path != NULL, -1);
5357 item = g_list_nth_data (icon_view->priv->items,
5358 gtk_tree_path_get_indices(path)[0]);
5367 * gtk_icon_view_item_activated:
5368 * @icon_view: A #GtkIconView
5369 * @path: The #GtkTreePath to be activated
5371 * Activates the item determined by @path.
5376 gtk_icon_view_item_activated (GtkIconView *icon_view,
5379 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5380 g_return_if_fail (path != NULL);
5382 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5386 * gtk_icon_view_set_item_orientation:
5387 * @icon_view: a #GtkIconView
5388 * @orientation: the relative position of texts and icons
5390 * Sets the ::item-orientation property which determines whether the labels
5391 * are drawn beside the icons instead of below.
5396 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5397 GtkOrientation orientation)
5399 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5401 if (icon_view->priv->item_orientation != orientation)
5403 icon_view->priv->item_orientation = orientation;
5405 if (icon_view->priv->cell_area)
5407 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5408 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5409 icon_view->priv->item_orientation);
5411 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5414 gtk_icon_view_invalidate_sizes (icon_view);
5416 update_text_cell (icon_view);
5417 update_pixbuf_cell (icon_view);
5419 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5424 * gtk_icon_view_get_item_orientation:
5425 * @icon_view: a #GtkIconView
5427 * Returns the value of the ::item-orientation property which determines
5428 * whether the labels are drawn beside the icons instead of below.
5430 * Return value: the relative position of texts and icons
5435 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5437 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5438 GTK_ORIENTATION_VERTICAL);
5440 return icon_view->priv->item_orientation;
5444 * gtk_icon_view_set_columns:
5445 * @icon_view: a #GtkIconView
5446 * @columns: the number of columns
5448 * Sets the ::columns property which determines in how
5449 * many columns the icons are arranged. If @columns is
5450 * -1, the number of columns will be chosen automatically
5451 * to fill the available area.
5456 gtk_icon_view_set_columns (GtkIconView *icon_view,
5459 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5461 if (icon_view->priv->columns != columns)
5463 icon_view->priv->columns = columns;
5465 if (icon_view->priv->cell_area)
5466 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5468 gtk_icon_view_queue_layout (icon_view);
5470 g_object_notify (G_OBJECT (icon_view), "columns");
5475 * gtk_icon_view_get_columns:
5476 * @icon_view: a #GtkIconView
5478 * Returns the value of the ::columns property.
5480 * Return value: the number of columns, or -1
5485 gtk_icon_view_get_columns (GtkIconView *icon_view)
5487 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5489 return icon_view->priv->columns;
5493 * gtk_icon_view_set_item_width:
5494 * @icon_view: a #GtkIconView
5495 * @item_width: the width for each item
5497 * Sets the ::item-width property which specifies the width
5498 * to use for each item. If it is set to -1, the icon view will
5499 * automatically determine a suitable item size.
5504 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5507 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5509 if (icon_view->priv->item_width != item_width)
5511 icon_view->priv->item_width = item_width;
5513 if (icon_view->priv->cell_area)
5514 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5516 gtk_icon_view_invalidate_sizes (icon_view);
5518 update_text_cell (icon_view);
5520 g_object_notify (G_OBJECT (icon_view), "item-width");
5525 * gtk_icon_view_get_item_width:
5526 * @icon_view: a #GtkIconView
5528 * Returns the value of the ::item-width property.
5530 * Return value: the width of a single item, or -1
5535 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5537 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5539 return icon_view->priv->item_width;
5544 * gtk_icon_view_set_spacing:
5545 * @icon_view: a #GtkIconView
5546 * @spacing: the spacing
5548 * Sets the ::spacing property which specifies the space
5549 * which is inserted between the cells (i.e. the icon and
5550 * the text) of an item.
5555 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5558 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5560 if (icon_view->priv->spacing != spacing)
5562 icon_view->priv->spacing = spacing;
5564 if (icon_view->priv->cell_area)
5565 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5567 gtk_icon_view_invalidate_sizes (icon_view);
5569 g_object_notify (G_OBJECT (icon_view), "spacing");
5574 * gtk_icon_view_get_spacing:
5575 * @icon_view: a #GtkIconView
5577 * Returns the value of the ::spacing property.
5579 * Return value: the space between cells
5584 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5586 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5588 return icon_view->priv->spacing;
5592 * gtk_icon_view_set_row_spacing:
5593 * @icon_view: a #GtkIconView
5594 * @row_spacing: the row spacing
5596 * Sets the ::row-spacing property which specifies the space
5597 * which is inserted between the rows of the icon view.
5602 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5605 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5607 if (icon_view->priv->row_spacing != row_spacing)
5609 icon_view->priv->row_spacing = row_spacing;
5611 if (icon_view->priv->cell_area)
5612 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5614 gtk_icon_view_invalidate_sizes (icon_view);
5616 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5621 * gtk_icon_view_get_row_spacing:
5622 * @icon_view: a #GtkIconView
5624 * Returns the value of the ::row-spacing property.
5626 * Return value: the space between rows
5631 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5633 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5635 return icon_view->priv->row_spacing;
5639 * gtk_icon_view_set_column_spacing:
5640 * @icon_view: a #GtkIconView
5641 * @column_spacing: the column spacing
5643 * Sets the ::column-spacing property which specifies the space
5644 * which is inserted between the columns of the icon view.
5649 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5650 gint column_spacing)
5652 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5654 if (icon_view->priv->column_spacing != column_spacing)
5656 icon_view->priv->column_spacing = column_spacing;
5658 if (icon_view->priv->cell_area)
5659 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5661 gtk_icon_view_invalidate_sizes (icon_view);
5663 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5668 * gtk_icon_view_get_column_spacing:
5669 * @icon_view: a #GtkIconView
5671 * Returns the value of the ::column-spacing property.
5673 * Return value: the space between columns
5678 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5680 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5682 return icon_view->priv->column_spacing;
5686 * gtk_icon_view_set_margin:
5687 * @icon_view: a #GtkIconView
5688 * @margin: the margin
5690 * Sets the ::margin property which specifies the space
5691 * which is inserted at the top, bottom, left and right
5697 gtk_icon_view_set_margin (GtkIconView *icon_view,
5700 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5702 if (icon_view->priv->margin != margin)
5704 icon_view->priv->margin = margin;
5706 if (icon_view->priv->cell_area)
5707 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5709 gtk_icon_view_invalidate_sizes (icon_view);
5711 g_object_notify (G_OBJECT (icon_view), "margin");
5716 * gtk_icon_view_get_margin:
5717 * @icon_view: a #GtkIconView
5719 * Returns the value of the ::margin property.
5721 * Return value: the space at the borders
5726 gtk_icon_view_get_margin (GtkIconView *icon_view)
5728 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5730 return icon_view->priv->margin;
5734 * gtk_icon_view_set_item_padding:
5735 * @icon_view: a #GtkIconView
5736 * @item_padding: the item padding
5738 * Sets the #GtkIconView:item-padding property which specifies the padding
5739 * around each of the icon view's items.
5744 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5747 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5749 if (icon_view->priv->item_padding != item_padding)
5751 icon_view->priv->item_padding = item_padding;
5753 if (icon_view->priv->cell_area)
5754 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5756 gtk_icon_view_invalidate_sizes (icon_view);
5758 g_object_notify (G_OBJECT (icon_view), "item-padding");
5763 * gtk_icon_view_get_item_padding:
5764 * @icon_view: a #GtkIconView
5766 * Returns the value of the ::item-padding property.
5768 * Return value: the padding around items
5773 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5775 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5777 return icon_view->priv->item_padding;
5780 /* Get/set whether drag_motion requested the drag data and
5781 * drag_data_received should thus not actually insert the data,
5782 * since the data doesn't result from a drop.
5785 set_status_pending (GdkDragContext *context,
5786 GdkDragAction suggested_action)
5788 g_object_set_data (G_OBJECT (context),
5789 I_("gtk-icon-view-status-pending"),
5790 GINT_TO_POINTER (suggested_action));
5793 static GdkDragAction
5794 get_status_pending (GdkDragContext *context)
5796 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5797 "gtk-icon-view-status-pending"));
5801 unset_reorderable (GtkIconView *icon_view)
5803 if (icon_view->priv->reorderable)
5805 icon_view->priv->reorderable = FALSE;
5806 g_object_notify (G_OBJECT (icon_view), "reorderable");
5811 set_source_row (GdkDragContext *context,
5812 GtkTreeModel *model,
5813 GtkTreePath *source_row)
5816 g_object_set_data_full (G_OBJECT (context),
5817 I_("gtk-icon-view-source-row"),
5818 gtk_tree_row_reference_new (model, source_row),
5819 (GDestroyNotify) gtk_tree_row_reference_free);
5821 g_object_set_data_full (G_OBJECT (context),
5822 I_("gtk-icon-view-source-row"),
5827 get_source_row (GdkDragContext *context)
5829 GtkTreeRowReference *ref;
5831 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5834 return gtk_tree_row_reference_get_path (ref);
5841 GtkTreeRowReference *dest_row;
5842 gboolean empty_view_drop;
5843 gboolean drop_append_mode;
5847 dest_row_free (gpointer data)
5849 DestRow *dr = (DestRow *)data;
5851 gtk_tree_row_reference_free (dr->dest_row);
5856 set_dest_row (GdkDragContext *context,
5857 GtkTreeModel *model,
5858 GtkTreePath *dest_row,
5859 gboolean empty_view_drop,
5860 gboolean drop_append_mode)
5866 g_object_set_data_full (G_OBJECT (context),
5867 I_("gtk-icon-view-dest-row"),
5872 dr = g_new0 (DestRow, 1);
5874 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5875 dr->empty_view_drop = empty_view_drop;
5876 dr->drop_append_mode = drop_append_mode;
5877 g_object_set_data_full (G_OBJECT (context),
5878 I_("gtk-icon-view-dest-row"),
5879 dr, (GDestroyNotify) dest_row_free);
5883 get_dest_row (GdkDragContext *context)
5887 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5891 GtkTreePath *path = NULL;
5894 path = gtk_tree_row_reference_get_path (dr->dest_row);
5895 else if (dr->empty_view_drop)
5896 path = gtk_tree_path_new_from_indices (0, -1);
5900 if (path && dr->drop_append_mode)
5901 gtk_tree_path_next (path);
5910 check_model_dnd (GtkTreeModel *model,
5911 GType required_iface,
5912 const gchar *signal)
5914 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5916 g_warning ("You must override the default '%s' handler "
5917 "on GtkIconView when using models that don't support "
5918 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5919 "is to connect to '%s' and call "
5920 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5921 "the default handler from running. Look at the source code "
5922 "for the default handler in gtkiconview.c to get an idea what "
5923 "your handler should do. (gtkiconview.c is in the GTK+ source "
5924 "code.) If you're using GTK+ from a language other than C, "
5925 "there may be a more natural way to override default handlers, e.g. via derivation.",
5926 signal, g_type_name (required_iface), signal);
5934 remove_scroll_timeout (GtkIconView *icon_view)
5936 if (icon_view->priv->scroll_timeout_id != 0)
5938 g_source_remove (icon_view->priv->scroll_timeout_id);
5940 icon_view->priv->scroll_timeout_id = 0;
5945 gtk_icon_view_autoscroll (GtkIconView *icon_view,
5949 gint px, py, x, y, width, height;
5950 gint hoffset, voffset;
5952 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5954 gdk_window_get_device_position (window, device, &px, &py, NULL);
5955 gdk_window_get_geometry (window, &x, &y, &width, &height);
5957 /* see if we are near the edge. */
5958 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5960 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5962 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5964 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5967 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5968 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5971 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5972 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5976 GtkIconView *icon_view;
5981 drag_scroll_timeout (gpointer datap)
5983 DragScrollData *data = datap;
5985 gtk_icon_view_autoscroll (data->icon_view, data->device);
5991 drag_scroll_data_free (DragScrollData *data)
5993 g_slice_free (DragScrollData, data);
5997 set_destination (GtkIconView *icon_view,
5998 GdkDragContext *context,
6001 GdkDragAction *suggested_action,
6005 GtkTreePath *path = NULL;
6006 GtkIconViewDropPosition pos;
6007 GtkIconViewDropPosition old_pos;
6008 GtkTreePath *old_dest_path = NULL;
6009 gboolean can_drop = FALSE;
6011 widget = GTK_WIDGET (icon_view);
6013 *suggested_action = 0;
6016 if (!icon_view->priv->dest_set)
6018 /* someone unset us as a drag dest, note that if
6019 * we return FALSE drag_leave isn't called
6022 gtk_icon_view_set_drag_dest_item (icon_view,
6024 GTK_ICON_VIEW_DROP_LEFT);
6026 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6028 return FALSE; /* no longer a drop site */
6031 *target = gtk_drag_dest_find_target (widget, context,
6032 gtk_drag_dest_get_target_list (widget));
6033 if (*target == GDK_NONE)
6036 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6039 GtkTreeModel *model;
6041 /* the row got dropped on empty space, let's setup a special case
6045 gtk_tree_path_free (path);
6047 model = gtk_icon_view_get_model (icon_view);
6049 n_children = gtk_tree_model_iter_n_children (model, NULL);
6052 pos = GTK_ICON_VIEW_DROP_BELOW;
6053 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6057 pos = GTK_ICON_VIEW_DROP_ABOVE;
6058 path = gtk_tree_path_new_from_indices (0, -1);
6068 gtk_icon_view_get_drag_dest_item (icon_view,
6073 gtk_tree_path_free (old_dest_path);
6075 if (TRUE /* FIXME if the location droppable predicate */)
6083 GtkWidget *source_widget;
6085 *suggested_action = gdk_drag_context_get_suggested_action (context);
6086 source_widget = gtk_drag_get_source_widget (context);
6088 if (source_widget == widget)
6090 /* Default to MOVE, unless the user has
6091 * pressed ctrl or shift to affect available actions
6093 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6094 *suggested_action = GDK_ACTION_MOVE;
6097 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6102 /* can't drop here */
6103 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6105 GTK_ICON_VIEW_DROP_LEFT);
6109 gtk_tree_path_free (path);
6115 get_logical_destination (GtkIconView *icon_view,
6116 gboolean *drop_append_mode)
6118 /* adjust path to point to the row the drop goes in front of */
6119 GtkTreePath *path = NULL;
6120 GtkIconViewDropPosition pos;
6122 *drop_append_mode = FALSE;
6124 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6129 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6130 pos == GTK_ICON_VIEW_DROP_BELOW)
6133 GtkTreeModel *model = icon_view->priv->model;
6135 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6136 !gtk_tree_model_iter_next (model, &iter))
6137 *drop_append_mode = TRUE;
6140 *drop_append_mode = FALSE;
6141 gtk_tree_path_next (path);
6149 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6150 GdkEventMotion *event)
6152 GtkWidget *widget = GTK_WIDGET (icon_view);
6153 GdkDragContext *context;
6154 GtkTreePath *path = NULL;
6156 GtkTreeModel *model;
6157 gboolean retval = FALSE;
6159 if (!icon_view->priv->source_set)
6162 if (icon_view->priv->pressed_button < 0)
6165 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6166 icon_view->priv->press_start_x,
6167 icon_view->priv->press_start_y,
6168 event->x, event->y))
6171 model = gtk_icon_view_get_model (icon_view);
6176 button = icon_view->priv->pressed_button;
6177 icon_view->priv->pressed_button = -1;
6179 path = gtk_icon_view_get_path_at_pos (icon_view,
6180 icon_view->priv->press_start_x,
6181 icon_view->priv->press_start_y);
6186 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6187 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6191 /* FIXME Check whether we're a start button, if not return FALSE and
6195 /* Now we can begin the drag */
6199 context = gtk_drag_begin (widget,
6200 gtk_drag_source_get_target_list (widget),
6201 icon_view->priv->source_actions,
6205 set_source_row (context, model, path);
6209 gtk_tree_path_free (path);
6214 /* Source side drag signals */
6216 gtk_icon_view_drag_begin (GtkWidget *widget,
6217 GdkDragContext *context)
6219 GtkIconView *icon_view;
6220 GtkIconViewItem *item;
6221 cairo_surface_t *icon;
6225 icon_view = GTK_ICON_VIEW (widget);
6227 /* if the user uses a custom DnD impl, we don't set the icon here */
6228 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6231 item = _gtk_icon_view_get_item_at_coords (icon_view,
6232 icon_view->priv->press_start_x,
6233 icon_view->priv->press_start_y,
6237 g_return_if_fail (item != NULL);
6239 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6240 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6242 path = gtk_tree_path_new_from_indices (item->index, -1);
6243 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6244 gtk_tree_path_free (path);
6246 cairo_surface_set_device_offset (icon, -x, -y);
6248 gtk_drag_set_icon_surface (context, icon);
6250 cairo_surface_destroy (icon);
6254 gtk_icon_view_drag_end (GtkWidget *widget,
6255 GdkDragContext *context)
6261 gtk_icon_view_drag_data_get (GtkWidget *widget,
6262 GdkDragContext *context,
6263 GtkSelectionData *selection_data,
6267 GtkIconView *icon_view;
6268 GtkTreeModel *model;
6269 GtkTreePath *source_row;
6271 icon_view = GTK_ICON_VIEW (widget);
6272 model = gtk_icon_view_get_model (icon_view);
6277 if (!icon_view->priv->source_set)
6280 source_row = get_source_row (context);
6282 if (source_row == NULL)
6285 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6286 * any model; for DragSource models there are some other targets
6290 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6291 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6296 /* If drag_data_get does nothing, try providing row data. */
6297 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6298 gtk_tree_set_row_drag_data (selection_data,
6303 gtk_tree_path_free (source_row);
6307 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6308 GdkDragContext *context)
6310 GtkTreeModel *model;
6311 GtkIconView *icon_view;
6312 GtkTreePath *source_row;
6314 icon_view = GTK_ICON_VIEW (widget);
6315 model = gtk_icon_view_get_model (icon_view);
6317 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6320 if (!icon_view->priv->source_set)
6323 source_row = get_source_row (context);
6325 if (source_row == NULL)
6328 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6331 gtk_tree_path_free (source_row);
6333 set_source_row (context, NULL, NULL);
6336 /* Target side drag signals */
6338 gtk_icon_view_drag_leave (GtkWidget *widget,
6339 GdkDragContext *context,
6342 GtkIconView *icon_view;
6344 icon_view = GTK_ICON_VIEW (widget);
6346 /* unset any highlight row */
6347 gtk_icon_view_set_drag_dest_item (icon_view,
6349 GTK_ICON_VIEW_DROP_LEFT);
6351 remove_scroll_timeout (icon_view);
6355 gtk_icon_view_drag_motion (GtkWidget *widget,
6356 GdkDragContext *context,
6361 GtkTreePath *path = NULL;
6362 GtkIconViewDropPosition pos;
6363 GtkIconView *icon_view;
6364 GdkDragAction suggested_action = 0;
6368 icon_view = GTK_ICON_VIEW (widget);
6370 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6373 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6375 /* we only know this *after* set_desination_row */
6376 empty = icon_view->priv->empty_view_drop;
6378 if (path == NULL && !empty)
6380 /* Can't drop here. */
6381 gdk_drag_status (context, 0, time);
6385 if (icon_view->priv->scroll_timeout_id == 0)
6387 DragScrollData *data = g_slice_new (DragScrollData);
6388 data->icon_view = icon_view;
6389 data->device = gdk_drag_context_get_device (context);
6391 icon_view->priv->scroll_timeout_id =
6392 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6395 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6397 /* Request data so we can use the source row when
6398 * determining whether to accept the drop
6400 set_status_pending (context, suggested_action);
6401 gtk_drag_get_data (widget, context, target, time);
6405 set_status_pending (context, 0);
6406 gdk_drag_status (context, suggested_action, time);
6411 gtk_tree_path_free (path);
6417 gtk_icon_view_drag_drop (GtkWidget *widget,
6418 GdkDragContext *context,
6423 GtkIconView *icon_view;
6425 GdkDragAction suggested_action = 0;
6426 GdkAtom target = GDK_NONE;
6427 GtkTreeModel *model;
6428 gboolean drop_append_mode;
6430 icon_view = GTK_ICON_VIEW (widget);
6431 model = gtk_icon_view_get_model (icon_view);
6433 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6435 if (!icon_view->priv->dest_set)
6438 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6441 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6444 path = get_logical_destination (icon_view, &drop_append_mode);
6446 if (target != GDK_NONE && path != NULL)
6448 /* in case a motion had requested drag data, change things so we
6449 * treat drag data receives as a drop.
6451 set_status_pending (context, 0);
6452 set_dest_row (context, model, path,
6453 icon_view->priv->empty_view_drop, drop_append_mode);
6457 gtk_tree_path_free (path);
6459 /* Unset this thing */
6460 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6462 if (target != GDK_NONE)
6464 gtk_drag_get_data (widget, context, target, time);
6472 gtk_icon_view_drag_data_received (GtkWidget *widget,
6473 GdkDragContext *context,
6476 GtkSelectionData *selection_data,
6481 gboolean accepted = FALSE;
6482 GtkTreeModel *model;
6483 GtkIconView *icon_view;
6484 GtkTreePath *dest_row;
6485 GdkDragAction suggested_action;
6486 gboolean drop_append_mode;
6488 icon_view = GTK_ICON_VIEW (widget);
6489 model = gtk_icon_view_get_model (icon_view);
6491 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6494 if (!icon_view->priv->dest_set)
6497 suggested_action = get_status_pending (context);
6499 if (suggested_action)
6501 /* We are getting this data due to a request in drag_motion,
6502 * rather than due to a request in drag_drop, so we are just
6503 * supposed to call drag_status, not actually paste in the
6506 path = get_logical_destination (icon_view, &drop_append_mode);
6509 suggested_action = 0;
6511 if (suggested_action)
6513 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6516 suggested_action = 0;
6519 gdk_drag_status (context, suggested_action, time);
6522 gtk_tree_path_free (path);
6524 /* If you can't drop, remove user drop indicator until the next motion */
6525 if (suggested_action == 0)
6526 gtk_icon_view_set_drag_dest_item (icon_view,
6528 GTK_ICON_VIEW_DROP_LEFT);
6533 dest_row = get_dest_row (context);
6535 if (dest_row == NULL)
6538 if (gtk_selection_data_get_length (selection_data) >= 0)
6540 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6546 gtk_drag_finish (context,
6548 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6551 gtk_tree_path_free (dest_row);
6554 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6557 /* Drag-and-Drop support */
6559 * gtk_icon_view_enable_model_drag_source:
6560 * @icon_view: a #GtkIconTreeView
6561 * @start_button_mask: Mask of allowed buttons to start drag
6562 * @targets: (array length=n_targets): the table of targets that the drag will
6564 * @n_targets: the number of items in @targets
6565 * @actions: the bitmask of possible actions for a drag from this
6568 * Turns @icon_view into a drag source for automatic DND. Calling this
6569 * method sets #GtkIconView:reorderable to %FALSE.
6574 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6575 GdkModifierType start_button_mask,
6576 const GtkTargetEntry *targets,
6578 GdkDragAction actions)
6580 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6582 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6584 icon_view->priv->start_button_mask = start_button_mask;
6585 icon_view->priv->source_actions = actions;
6587 icon_view->priv->source_set = TRUE;
6589 unset_reorderable (icon_view);
6593 * gtk_icon_view_enable_model_drag_dest:
6594 * @icon_view: a #GtkIconView
6595 * @targets: (array length=n_targets): the table of targets that the drag will
6597 * @n_targets: the number of items in @targets
6598 * @actions: the bitmask of possible actions for a drag to this
6601 * Turns @icon_view into a drop destination for automatic DND. Calling this
6602 * method sets #GtkIconView:reorderable to %FALSE.
6607 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6608 const GtkTargetEntry *targets,
6610 GdkDragAction actions)
6612 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6614 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6616 icon_view->priv->dest_actions = actions;
6618 icon_view->priv->dest_set = TRUE;
6620 unset_reorderable (icon_view);
6624 * gtk_icon_view_unset_model_drag_source:
6625 * @icon_view: a #GtkIconView
6627 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6628 * method sets #GtkIconView:reorderable to %FALSE.
6633 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6635 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6637 if (icon_view->priv->source_set)
6639 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6640 icon_view->priv->source_set = FALSE;
6643 unset_reorderable (icon_view);
6647 * gtk_icon_view_unset_model_drag_dest:
6648 * @icon_view: a #GtkIconView
6650 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6651 * method sets #GtkIconView:reorderable to %FALSE.
6656 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6658 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6660 if (icon_view->priv->dest_set)
6662 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6663 icon_view->priv->dest_set = FALSE;
6666 unset_reorderable (icon_view);
6669 /* These are useful to implement your own custom stuff. */
6671 * gtk_icon_view_set_drag_dest_item:
6672 * @icon_view: a #GtkIconView
6673 * @path: (allow-none): The path of the item to highlight, or %NULL.
6674 * @pos: Specifies where to drop, relative to the item
6676 * Sets the item that is highlighted for feedback.
6681 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6683 GtkIconViewDropPosition pos)
6685 /* Note; this function is exported to allow a custom DND
6686 * implementation, so it can't touch TreeViewDragInfo
6689 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6691 if (icon_view->priv->dest_item)
6693 GtkTreePath *current_path;
6694 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6695 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6696 icon_view->priv->dest_item = NULL;
6698 gtk_icon_view_queue_draw_path (icon_view, current_path);
6699 gtk_tree_path_free (current_path);
6702 /* special case a drop on an empty model */
6703 icon_view->priv->empty_view_drop = FALSE;
6704 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6705 && gtk_tree_path_get_depth (path) == 1
6706 && gtk_tree_path_get_indices (path)[0] == 0)
6710 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6713 if (n_children == 0)
6714 icon_view->priv->empty_view_drop = TRUE;
6717 icon_view->priv->dest_pos = pos;
6721 icon_view->priv->dest_item =
6722 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6723 icon_view->priv->model, path);
6725 gtk_icon_view_queue_draw_path (icon_view, path);
6730 * gtk_icon_view_get_drag_dest_item:
6731 * @icon_view: a #GtkIconView
6732 * @path: (out) (allow-none): Return location for the path of
6733 * the highlighted item, or %NULL.
6734 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6736 * Gets information about the item that is highlighted for feedback.
6741 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6743 GtkIconViewDropPosition *pos)
6745 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6749 if (icon_view->priv->dest_item)
6750 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6756 *pos = icon_view->priv->dest_pos;
6760 * gtk_icon_view_get_dest_item_at_pos:
6761 * @icon_view: a #GtkIconView
6762 * @drag_x: the position to determine the destination item for
6763 * @drag_y: the position to determine the destination item for
6764 * @path: (out) (allow-none): Return location for the path of the item,
6766 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6768 * Determines the destination item for a given position.
6770 * Return value: whether there is an item at the given position.
6775 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6779 GtkIconViewDropPosition *pos)
6781 GtkIconViewItem *item;
6783 /* Note; this function is exported to allow a custom DND
6784 * implementation, so it can't touch TreeViewDragInfo
6787 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6788 g_return_val_if_fail (drag_x >= 0, FALSE);
6789 g_return_val_if_fail (drag_y >= 0, FALSE);
6790 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6796 item = _gtk_icon_view_get_item_at_coords (icon_view,
6797 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6798 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6805 *path = gtk_tree_path_new_from_indices (item->index, -1);
6809 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6810 *pos = GTK_ICON_VIEW_DROP_LEFT;
6811 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6812 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6813 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6814 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6815 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6816 *pos = GTK_ICON_VIEW_DROP_BELOW;
6818 *pos = GTK_ICON_VIEW_DROP_INTO;
6825 * gtk_icon_view_create_drag_icon:
6826 * @icon_view: a #GtkIconView
6827 * @path: a #GtkTreePath in @icon_view
6829 * Creates a #cairo_surface_t representation of the item at @path.
6830 * This image is used for a drag icon.
6832 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6837 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6841 GtkStyleContext *context;
6843 cairo_surface_t *surface;
6847 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6848 g_return_val_if_fail (path != NULL, NULL);
6850 widget = GTK_WIDGET (icon_view);
6851 context = gtk_widget_get_style_context (widget);
6853 if (!gtk_widget_get_realized (widget))
6856 index = gtk_tree_path_get_indices (path)[0];
6858 for (l = icon_view->priv->items; l; l = l->next)
6860 GtkIconViewItem *item = l->data;
6862 if (index == item->index)
6864 GdkRectangle rect = {
6865 item->cell_area.x - icon_view->priv->item_padding,
6866 item->cell_area.y - icon_view->priv->item_padding,
6867 item->cell_area.width + icon_view->priv->item_padding * 2,
6868 item->cell_area.height + icon_view->priv->item_padding * 2
6871 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6872 CAIRO_CONTENT_COLOR,
6876 cr = cairo_create (surface);
6877 cairo_set_line_width (cr, 1.);
6879 gtk_render_background (context, cr, 0, 0,
6880 rect.width + 2, rect.height + 2);
6884 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6887 gtk_icon_view_paint_item (icon_view, cr, item,
6888 icon_view->priv->item_padding + 1,
6889 icon_view->priv->item_padding + 1, FALSE);
6893 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6894 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6907 * gtk_icon_view_get_reorderable:
6908 * @icon_view: a #GtkIconView
6910 * Retrieves whether the user can reorder the list via drag-and-drop.
6911 * See gtk_icon_view_set_reorderable().
6913 * Return value: %TRUE if the list can be reordered.
6918 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6920 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6922 return icon_view->priv->reorderable;
6925 static const GtkTargetEntry item_targets[] = {
6926 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6931 * gtk_icon_view_set_reorderable:
6932 * @icon_view: A #GtkIconView.
6933 * @reorderable: %TRUE, if the list of items can be reordered.
6935 * This function is a convenience function to allow you to reorder models that
6936 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6937 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6938 * the user can reorder the model by dragging and dropping rows. The
6939 * developer can listen to these changes by connecting to the model's
6940 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6941 * the icon view as a drag source and destination. Therefore, drag and
6942 * drop can not be used in a reorderable view for any other purpose.
6944 * This function does not give you any degree of control over the order -- any
6945 * reordering is allowed. If more control is needed, you should probably
6946 * handle drag and drop manually.
6951 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6952 gboolean reorderable)
6954 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6956 reorderable = reorderable != FALSE;
6958 if (icon_view->priv->reorderable == reorderable)
6963 gtk_icon_view_enable_model_drag_source (icon_view,
6966 G_N_ELEMENTS (item_targets),
6968 gtk_icon_view_enable_model_drag_dest (icon_view,
6970 G_N_ELEMENTS (item_targets),
6975 gtk_icon_view_unset_model_drag_source (icon_view);
6976 gtk_icon_view_unset_model_drag_dest (icon_view);
6979 icon_view->priv->reorderable = reorderable;
6981 g_object_notify (G_OBJECT (icon_view), "reorderable");
6985 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
6986 GtkBuilder *builder,
6988 const gchar *tagname,
6989 GMarkupParser *parser,
6992 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
6993 tagname, parser, data))
6996 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
6997 tagname, parser, data);
7001 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7002 GtkBuilder *builder,
7004 const gchar *tagname,
7007 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7008 child, tagname, data))
7009 parent_buildable_iface->custom_tag_end (buildable, builder,
7010 child, tagname, data);