2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 #include "gtkiconview.h"
23 #include "gtkiconviewprivate.h"
25 #include "gtkcelllayout.h"
26 #include "gtkcellrenderer.h"
27 #include "gtkcellareabox.h"
28 #include "gtkcellareacontext.h"
29 #include "gtkcellrenderertext.h"
30 #include "gtkcellrendererpixbuf.h"
31 #include "gtkorientable.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
37 #include "gtkaccessible.h"
38 #include "gtkwindow.h"
40 #include "gtkcombobox.h"
41 #include "gtkscrollable.h"
42 #include "gtksizerequest.h"
43 #include "gtktreednd.h"
44 #include "gtktypebuiltins.h"
45 #include "gtkprivate.h"
46 #include "a11y/gtkiconviewaccessible.h"
51 * @short_description: A widget which displays a list of icons in a grid
53 * #GtkIconView provides an alternative view on a #GtkTreeModel.
54 * It displays the model as a grid of icons with labels. Like
55 * #GtkTreeView, it allows to select one or multiple items
56 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
57 * In addition to selection with the arrow keys, #GtkIconView supports
58 * rubberband selection, which is controlled by dragging the pointer.
60 * Note that if the tree model is backed by an actual tree store (as
61 * opposed to a flat list where the mapping to icons is obvious),
62 * #GtkIconView will only display the first level of the tree and
63 * ignore the tree's branches.
66 #define SCROLL_EDGE_SIZE 15
68 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
70 typedef struct _GtkIconViewChild GtkIconViewChild;
71 struct _GtkIconViewChild
99 PROP_ITEM_ORIENTATION,
112 /* For scrollable interface */
120 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
121 static void gtk_icon_view_dispose (GObject *object);
122 static GObject *gtk_icon_view_constructor (GType type,
123 guint n_construct_properties,
124 GObjectConstructParam *construct_properties);
125 static void gtk_icon_view_set_property (GObject *object,
129 static void gtk_icon_view_get_property (GObject *object,
133 /* GtkWidget vfuncs */
134 static void gtk_icon_view_destroy (GtkWidget *widget);
135 static void gtk_icon_view_realize (GtkWidget *widget);
136 static void gtk_icon_view_unrealize (GtkWidget *widget);
137 static void gtk_icon_view_style_updated (GtkWidget *widget);
138 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
139 GtkStateFlags previous_state);
140 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
143 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
146 static void gtk_icon_view_size_allocate (GtkWidget *widget,
147 GtkAllocation *allocation);
148 static gboolean gtk_icon_view_draw (GtkWidget *widget,
150 static gboolean gtk_icon_view_motion (GtkWidget *widget,
151 GdkEventMotion *event);
152 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
153 GdkEventButton *event);
154 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
155 GdkEventButton *event);
156 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
158 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
162 /* GtkContainer vfuncs */
163 static void gtk_icon_view_remove (GtkContainer *container,
165 static void gtk_icon_view_forall (GtkContainer *container,
166 gboolean include_internals,
167 GtkCallback callback,
168 gpointer callback_data);
170 /* GtkIconView vfuncs */
171 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
172 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
173 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
174 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
175 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
177 /* Internal functions */
178 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
179 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
180 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
181 GtkAdjustment *adjustment);
182 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
183 GtkAdjustment *adjustment);
184 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
185 GtkIconView *icon_view);
186 static void gtk_icon_view_layout (GtkIconView *icon_view);
187 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
189 GtkIconViewItem *item,
192 gboolean draw_focus);
193 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
195 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
197 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
198 GtkIconViewItem *item);
199 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
200 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
204 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
205 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
206 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
207 GtkIconViewItem *item,
212 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
213 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
214 static void gtk_icon_view_update_rubberband (gpointer data);
215 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
216 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
217 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
220 GtkMovementStep step,
222 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
223 GtkMovementStep step,
225 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
227 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
229 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
231 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
233 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
234 GtkIconViewItem *item);
235 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
236 GtkIconViewItem *anchor,
237 GtkIconViewItem *cursor);
239 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
240 GtkCellArea *cell_area);
242 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
244 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
245 GtkIconViewItem *item);
247 static void gtk_icon_view_add_editable (GtkCellArea *area,
248 GtkCellRenderer *renderer,
249 GtkCellEditable *editable,
250 GdkRectangle *cell_area,
252 GtkIconView *icon_view);
253 static void gtk_icon_view_remove_editable (GtkCellArea *area,
254 GtkCellRenderer *renderer,
255 GtkCellEditable *editable,
256 GtkIconView *icon_view);
257 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
259 GtkIconView *icon_view);
260 static void update_text_cell (GtkIconView *icon_view);
261 static void update_pixbuf_cell (GtkIconView *icon_view);
263 /* Source side drag signals */
264 static void gtk_icon_view_drag_begin (GtkWidget *widget,
265 GdkDragContext *context);
266 static void gtk_icon_view_drag_end (GtkWidget *widget,
267 GdkDragContext *context);
268 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
269 GdkDragContext *context,
270 GtkSelectionData *selection_data,
273 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
274 GdkDragContext *context);
276 /* Target side drag signals */
277 static void gtk_icon_view_drag_leave (GtkWidget *widget,
278 GdkDragContext *context,
280 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
281 GdkDragContext *context,
285 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
286 GdkDragContext *context,
290 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
291 GdkDragContext *context,
294 GtkSelectionData *selection_data,
297 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
298 GdkEventMotion *event);
300 static void remove_scroll_timeout (GtkIconView *icon_view);
303 static GtkBuildableIface *parent_buildable_iface;
304 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
305 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
308 const gchar *tagname,
309 GMarkupParser *parser,
311 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
314 const gchar *tagname,
317 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
319 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
320 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
321 gtk_icon_view_cell_layout_init)
322 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
323 gtk_icon_view_buildable_init)
324 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
327 gtk_icon_view_class_init (GtkIconViewClass *klass)
329 GObjectClass *gobject_class;
330 GtkWidgetClass *widget_class;
331 GtkContainerClass *container_class;
332 GtkBindingSet *binding_set;
334 binding_set = gtk_binding_set_by_class (klass);
336 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
338 gobject_class = (GObjectClass *) klass;
339 widget_class = (GtkWidgetClass *) klass;
340 container_class = (GtkContainerClass *) klass;
342 gobject_class->constructor = gtk_icon_view_constructor;
343 gobject_class->dispose = gtk_icon_view_dispose;
344 gobject_class->set_property = gtk_icon_view_set_property;
345 gobject_class->get_property = gtk_icon_view_get_property;
347 widget_class->destroy = gtk_icon_view_destroy;
348 widget_class->realize = gtk_icon_view_realize;
349 widget_class->unrealize = gtk_icon_view_unrealize;
350 widget_class->style_updated = gtk_icon_view_style_updated;
351 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
352 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
353 widget_class->size_allocate = gtk_icon_view_size_allocate;
354 widget_class->draw = gtk_icon_view_draw;
355 widget_class->motion_notify_event = gtk_icon_view_motion;
356 widget_class->button_press_event = gtk_icon_view_button_press;
357 widget_class->button_release_event = gtk_icon_view_button_release;
358 widget_class->key_press_event = gtk_icon_view_key_press;
359 widget_class->key_release_event = gtk_icon_view_key_release;
360 widget_class->drag_begin = gtk_icon_view_drag_begin;
361 widget_class->drag_end = gtk_icon_view_drag_end;
362 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
363 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
364 widget_class->drag_leave = gtk_icon_view_drag_leave;
365 widget_class->drag_motion = gtk_icon_view_drag_motion;
366 widget_class->drag_drop = gtk_icon_view_drag_drop;
367 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
368 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
370 container_class->remove = gtk_icon_view_remove;
371 container_class->forall = gtk_icon_view_forall;
373 klass->select_all = gtk_icon_view_real_select_all;
374 klass->unselect_all = gtk_icon_view_real_unselect_all;
375 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
376 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
377 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
378 klass->move_cursor = gtk_icon_view_real_move_cursor;
382 * GtkIconView:selection-mode:
384 * The ::selection-mode property specifies the selection mode of
385 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
386 * is enabled, for the other modes, only keyboard selection is possible.
390 g_object_class_install_property (gobject_class,
392 g_param_spec_enum ("selection-mode",
393 P_("Selection mode"),
394 P_("The selection mode"),
395 GTK_TYPE_SELECTION_MODE,
396 GTK_SELECTION_SINGLE,
397 GTK_PARAM_READWRITE));
400 * GtkIconView:pixbuf-column:
402 * The ::pixbuf-column property contains the number of the model column
403 * containing the pixbufs which are displayed. The pixbuf column must be
404 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
405 * display of pixbufs.
409 g_object_class_install_property (gobject_class,
411 g_param_spec_int ("pixbuf-column",
413 P_("Model column used to retrieve the icon pixbuf from"),
415 GTK_PARAM_READWRITE));
418 * GtkIconView:text-column:
420 * The ::text-column property contains the number of the model column
421 * containing the texts which are displayed. The text column must be
422 * of type #G_TYPE_STRING. If this property and the :markup-column
423 * property are both set to -1, no texts are displayed.
427 g_object_class_install_property (gobject_class,
429 g_param_spec_int ("text-column",
431 P_("Model column used to retrieve the text from"),
433 GTK_PARAM_READWRITE));
437 * GtkIconView:markup-column:
439 * The ::markup-column property contains the number of the model column
440 * containing markup information to be displayed. The markup column must be
441 * of type #G_TYPE_STRING. If this property and the :text-column property
442 * are both set to column numbers, it overrides the text column.
443 * If both are set to -1, no texts are displayed.
447 g_object_class_install_property (gobject_class,
449 g_param_spec_int ("markup-column",
451 P_("Model column used to retrieve the text if using Pango markup"),
453 GTK_PARAM_READWRITE));
455 g_object_class_install_property (gobject_class,
457 g_param_spec_object ("model",
458 P_("Icon View Model"),
459 P_("The model for the icon view"),
461 GTK_PARAM_READWRITE));
464 * GtkIconView:columns:
466 * The columns property contains the number of the columns in which the
467 * items should be displayed. If it is -1, the number of columns will
468 * be chosen automatically to fill the available area.
472 g_object_class_install_property (gobject_class,
474 g_param_spec_int ("columns",
475 P_("Number of columns"),
476 P_("Number of columns to display"),
478 GTK_PARAM_READWRITE));
482 * GtkIconView:item-width:
484 * The item-width property specifies the width to use for each item.
485 * If it is set to -1, the icon view will automatically determine a
486 * suitable item size.
490 g_object_class_install_property (gobject_class,
492 g_param_spec_int ("item-width",
493 P_("Width for each item"),
494 P_("The width used for each item"),
496 GTK_PARAM_READWRITE));
499 * GtkIconView:spacing:
501 * The spacing property specifies the space which is inserted between
502 * the cells (i.e. the icon and the text) of an item.
506 g_object_class_install_property (gobject_class,
508 g_param_spec_int ("spacing",
510 P_("Space which is inserted between cells of an item"),
512 GTK_PARAM_READWRITE));
515 * GtkIconView:row-spacing:
517 * The row-spacing property specifies the space which is inserted between
518 * the rows of the icon view.
522 g_object_class_install_property (gobject_class,
524 g_param_spec_int ("row-spacing",
526 P_("Space which is inserted between grid rows"),
528 GTK_PARAM_READWRITE));
531 * GtkIconView:column-spacing:
533 * The column-spacing property specifies the space which is inserted between
534 * the columns of the icon view.
538 g_object_class_install_property (gobject_class,
540 g_param_spec_int ("column-spacing",
541 P_("Column Spacing"),
542 P_("Space which is inserted between grid columns"),
544 GTK_PARAM_READWRITE));
547 * GtkIconView:margin:
549 * The margin property specifies the space which is inserted
550 * at the edges of the icon view.
554 g_object_class_install_property (gobject_class,
556 g_param_spec_int ("margin",
558 P_("Space which is inserted at the edges of the icon view"),
560 GTK_PARAM_READWRITE));
563 * GtkIconView:item-orientation:
565 * The item-orientation property specifies how the cells (i.e. the icon and
566 * the text) of the item are positioned relative to each other.
570 g_object_class_install_property (gobject_class,
571 PROP_ITEM_ORIENTATION,
572 g_param_spec_enum ("item-orientation",
573 P_("Item Orientation"),
574 P_("How the text and icon of each item are positioned relative to each other"),
575 GTK_TYPE_ORIENTATION,
576 GTK_ORIENTATION_VERTICAL,
577 GTK_PARAM_READWRITE));
580 * GtkIconView:reorderable:
582 * The reorderable property specifies if the items can be reordered
587 g_object_class_install_property (gobject_class,
589 g_param_spec_boolean ("reorderable",
591 P_("View is reorderable"),
595 g_object_class_install_property (gobject_class,
597 g_param_spec_int ("tooltip-column",
598 P_("Tooltip Column"),
599 P_("The column in the model containing the tooltip texts for the items"),
603 GTK_PARAM_READWRITE));
606 * GtkIconView:item-padding:
608 * The item-padding property specifies the padding around each
609 * of the icon view's item.
613 g_object_class_install_property (gobject_class,
615 g_param_spec_int ("item-padding",
617 P_("Padding around icon view items"),
619 GTK_PARAM_READWRITE));
622 * GtkIconView:cell-area:
624 * The #GtkCellArea used to layout cell renderers for this view.
626 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
627 * a #GtkCellAreaBox will be used.
631 g_object_class_install_property (gobject_class,
633 g_param_spec_object ("cell-area",
635 P_("The GtkCellArea used to layout cells"),
637 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
639 /* Scrollable interface properties */
640 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
641 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
642 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
643 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
645 /* Style properties */
646 gtk_widget_class_install_style_property (widget_class,
647 g_param_spec_boxed ("selection-box-color",
648 P_("Selection Box Color"),
649 P_("Color of the selection box"),
651 GTK_PARAM_READABLE));
653 gtk_widget_class_install_style_property (widget_class,
654 g_param_spec_uchar ("selection-box-alpha",
655 P_("Selection Box Alpha"),
656 P_("Opacity of the selection box"),
659 GTK_PARAM_READABLE));
663 * GtkIconView::item-activated:
664 * @iconview: the object on which the signal is emitted
665 * @path: the #GtkTreePath for the activated item
667 * The ::item-activated signal is emitted when the method
668 * gtk_icon_view_item_activated() is called or the user double
669 * clicks an item. It is also emitted when a non-editable item
670 * is selected and one of the keys: Space, Return or Enter is
673 icon_view_signals[ITEM_ACTIVATED] =
674 g_signal_new (I_("item-activated"),
675 G_TYPE_FROM_CLASS (gobject_class),
677 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
679 g_cclosure_marshal_VOID__BOXED,
684 * GtkIconView::selection-changed:
685 * @iconview: the object on which the signal is emitted
687 * The ::selection-changed signal is emitted when the selection
688 * (i.e. the set of selected items) changes.
690 icon_view_signals[SELECTION_CHANGED] =
691 g_signal_new (I_("selection-changed"),
692 G_TYPE_FROM_CLASS (gobject_class),
694 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
696 g_cclosure_marshal_VOID__VOID,
700 * GtkIconView::select-all:
701 * @iconview: the object on which the signal is emitted
703 * A <link linkend="keybinding-signals">keybinding signal</link>
704 * which gets emitted when the user selects all items.
706 * Applications should not connect to it, but may emit it with
707 * g_signal_emit_by_name() if they need to control selection
710 * The default binding for this signal is Ctrl-a.
712 icon_view_signals[SELECT_ALL] =
713 g_signal_new (I_("select-all"),
714 G_TYPE_FROM_CLASS (gobject_class),
715 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
716 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
718 g_cclosure_marshal_VOID__VOID,
722 * GtkIconView::unselect-all:
723 * @iconview: the object on which the signal is emitted
725 * A <link linkend="keybinding-signals">keybinding signal</link>
726 * which gets emitted when the user unselects all items.
728 * Applications should not connect to it, but may emit it with
729 * g_signal_emit_by_name() if they need to control selection
732 * The default binding for this signal is Ctrl-Shift-a.
734 icon_view_signals[UNSELECT_ALL] =
735 g_signal_new (I_("unselect-all"),
736 G_TYPE_FROM_CLASS (gobject_class),
737 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
738 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
740 g_cclosure_marshal_VOID__VOID,
744 * GtkIconView::select-cursor-item:
745 * @iconview: the object on which the signal is emitted
747 * A <link linkend="keybinding-signals">keybinding signal</link>
748 * which gets emitted when the user selects the item that is currently
751 * Applications should not connect to it, but may emit it with
752 * g_signal_emit_by_name() if they need to control selection
755 * There is no default binding for this signal.
757 icon_view_signals[SELECT_CURSOR_ITEM] =
758 g_signal_new (I_("select-cursor-item"),
759 G_TYPE_FROM_CLASS (gobject_class),
760 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
761 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
763 g_cclosure_marshal_VOID__VOID,
767 * GtkIconView::toggle-cursor-item:
768 * @iconview: the object on which the signal is emitted
770 * A <link linkend="keybinding-signals">keybinding signal</link>
771 * which gets emitted when the user toggles whether the currently
772 * focused item is selected or not. The exact effect of this
773 * depend on the selection mode.
775 * Applications should not connect to it, but may emit it with
776 * g_signal_emit_by_name() if they need to control selection
779 * There is no default binding for this signal is Ctrl-Space.
781 icon_view_signals[TOGGLE_CURSOR_ITEM] =
782 g_signal_new (I_("toggle-cursor-item"),
783 G_TYPE_FROM_CLASS (gobject_class),
784 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
785 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
787 g_cclosure_marshal_VOID__VOID,
791 * GtkIconView::activate-cursor-item:
792 * @iconview: the object on which the signal is emitted
794 * A <link linkend="keybinding-signals">keybinding signal</link>
795 * which gets emitted when the user activates the currently
798 * Applications should not connect to it, but may emit it with
799 * g_signal_emit_by_name() if they need to control activation
802 * The default bindings for this signal are Space, Return and Enter.
804 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
805 g_signal_new (I_("activate-cursor-item"),
806 G_TYPE_FROM_CLASS (gobject_class),
807 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
808 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
810 _gtk_marshal_BOOLEAN__VOID,
814 * GtkIconView::move-cursor:
815 * @iconview: the object which received the signal
816 * @step: the granularity of the move, as a #GtkMovementStep
817 * @count: the number of @step units to move
819 * The ::move-cursor signal is a
820 * <link linkend="keybinding-signals">keybinding signal</link>
821 * which gets emitted when the user initiates a cursor movement.
823 * Applications should not connect to it, but may emit it with
824 * g_signal_emit_by_name() if they need to control the cursor
827 * The default bindings for this signal include
829 * <listitem>Arrow keys which move by individual steps</listitem>
830 * <listitem>Home/End keys which move to the first/last item</listitem>
831 * <listitem>PageUp/PageDown which move by "pages"</listitem>
834 * All of these will extend the selection when combined with
835 * the Shift modifier.
837 icon_view_signals[MOVE_CURSOR] =
838 g_signal_new (I_("move-cursor"),
839 G_TYPE_FROM_CLASS (gobject_class),
840 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
841 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
843 _gtk_marshal_BOOLEAN__ENUM_INT,
845 GTK_TYPE_MOVEMENT_STEP,
849 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
854 "toggle-cursor-item", 0);
855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
856 "toggle-cursor-item", 0);
858 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
859 "activate-cursor-item", 0);
860 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
861 "activate-cursor-item", 0);
862 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
863 "activate-cursor-item", 0);
864 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
865 "activate-cursor-item", 0);
866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
867 "activate-cursor-item", 0);
869 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
870 GTK_MOVEMENT_DISPLAY_LINES, -1);
871 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
872 GTK_MOVEMENT_DISPLAY_LINES, -1);
874 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
875 GTK_MOVEMENT_DISPLAY_LINES, 1);
876 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
877 GTK_MOVEMENT_DISPLAY_LINES, 1);
879 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
880 GTK_MOVEMENT_DISPLAY_LINES, -1);
882 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
883 GTK_MOVEMENT_DISPLAY_LINES, 1);
885 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
886 GTK_MOVEMENT_BUFFER_ENDS, -1);
887 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
888 GTK_MOVEMENT_BUFFER_ENDS, -1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
891 GTK_MOVEMENT_BUFFER_ENDS, 1);
892 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
893 GTK_MOVEMENT_BUFFER_ENDS, 1);
895 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
896 GTK_MOVEMENT_PAGES, -1);
897 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
898 GTK_MOVEMENT_PAGES, -1);
900 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
901 GTK_MOVEMENT_PAGES, 1);
902 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
903 GTK_MOVEMENT_PAGES, 1);
905 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
906 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
907 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
908 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
910 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
911 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
912 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
913 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
915 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
919 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
921 parent_buildable_iface = g_type_interface_peek_parent (iface);
922 iface->add_child = _gtk_cell_layout_buildable_add_child;
923 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
924 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
928 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
930 iface->get_area = gtk_icon_view_cell_layout_get_area;
934 gtk_icon_view_init (GtkIconView *icon_view)
936 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
940 icon_view->priv->width = 0;
941 icon_view->priv->height = 0;
942 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
943 icon_view->priv->pressed_button = -1;
944 icon_view->priv->press_start_x = -1;
945 icon_view->priv->press_start_y = -1;
946 icon_view->priv->text_column = -1;
947 icon_view->priv->markup_column = -1;
948 icon_view->priv->pixbuf_column = -1;
949 icon_view->priv->text_cell = NULL;
950 icon_view->priv->pixbuf_cell = NULL;
951 icon_view->priv->tooltip_column = -1;
953 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
955 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
957 icon_view->priv->columns = -1;
958 icon_view->priv->item_width = -1;
959 icon_view->priv->spacing = 0;
960 icon_view->priv->row_spacing = 6;
961 icon_view->priv->column_spacing = 6;
962 icon_view->priv->margin = 6;
963 icon_view->priv->item_padding = 6;
965 icon_view->priv->draw_focus = TRUE;
967 icon_view->priv->row_contexts =
968 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
971 /* GObject methods */
973 gtk_icon_view_constructor (GType type,
974 guint n_construct_properties,
975 GObjectConstructParam *construct_properties)
977 GtkIconView *icon_view;
980 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
981 (type, n_construct_properties, construct_properties);
983 icon_view = (GtkIconView *) object;
985 gtk_icon_view_ensure_cell_area (icon_view, NULL);
991 gtk_icon_view_dispose (GObject *object)
993 GtkIconView *icon_view;
994 GtkIconViewPrivate *priv;
996 icon_view = GTK_ICON_VIEW (object);
997 priv = icon_view->priv;
999 if (priv->cell_area_context)
1001 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1002 priv->context_changed_id = 0;
1004 g_object_unref (priv->cell_area_context);
1005 priv->cell_area_context = NULL;
1008 if (priv->row_contexts)
1010 g_ptr_array_free (priv->row_contexts, TRUE);
1011 priv->row_contexts = NULL;
1014 if (priv->cell_area)
1016 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1018 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1019 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1020 priv->add_editable_id = 0;
1021 priv->remove_editable_id = 0;
1023 g_object_unref (priv->cell_area);
1024 priv->cell_area = NULL;
1027 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1031 gtk_icon_view_set_property (GObject *object,
1033 const GValue *value,
1036 GtkIconView *icon_view;
1039 icon_view = GTK_ICON_VIEW (object);
1043 case PROP_SELECTION_MODE:
1044 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1046 case PROP_PIXBUF_COLUMN:
1047 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1049 case PROP_TEXT_COLUMN:
1050 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1052 case PROP_MARKUP_COLUMN:
1053 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1056 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1058 case PROP_ITEM_ORIENTATION:
1059 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1062 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1064 case PROP_ITEM_WIDTH:
1065 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1068 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1070 case PROP_ROW_SPACING:
1071 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1073 case PROP_COLUMN_SPACING:
1074 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1077 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1079 case PROP_REORDERABLE:
1080 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1083 case PROP_TOOLTIP_COLUMN:
1084 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1087 case PROP_ITEM_PADDING:
1088 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1091 case PROP_CELL_AREA:
1092 /* Construct-only, can only be assigned once */
1093 area = g_value_get_object (value);
1096 if (icon_view->priv->cell_area != NULL)
1098 g_warning ("cell-area has already been set, ignoring construct property");
1099 g_object_ref_sink (area);
1100 g_object_unref (area);
1103 gtk_icon_view_ensure_cell_area (icon_view, area);
1107 case PROP_HADJUSTMENT:
1108 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1110 case PROP_VADJUSTMENT:
1111 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1113 case PROP_HSCROLL_POLICY:
1114 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1115 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1117 case PROP_VSCROLL_POLICY:
1118 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1119 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1129 gtk_icon_view_get_property (GObject *object,
1134 GtkIconView *icon_view;
1136 icon_view = GTK_ICON_VIEW (object);
1140 case PROP_SELECTION_MODE:
1141 g_value_set_enum (value, icon_view->priv->selection_mode);
1143 case PROP_PIXBUF_COLUMN:
1144 g_value_set_int (value, icon_view->priv->pixbuf_column);
1146 case PROP_TEXT_COLUMN:
1147 g_value_set_int (value, icon_view->priv->text_column);
1149 case PROP_MARKUP_COLUMN:
1150 g_value_set_int (value, icon_view->priv->markup_column);
1153 g_value_set_object (value, icon_view->priv->model);
1155 case PROP_ITEM_ORIENTATION:
1156 g_value_set_enum (value, icon_view->priv->item_orientation);
1159 g_value_set_int (value, icon_view->priv->columns);
1161 case PROP_ITEM_WIDTH:
1162 g_value_set_int (value, icon_view->priv->item_width);
1165 g_value_set_int (value, icon_view->priv->spacing);
1167 case PROP_ROW_SPACING:
1168 g_value_set_int (value, icon_view->priv->row_spacing);
1170 case PROP_COLUMN_SPACING:
1171 g_value_set_int (value, icon_view->priv->column_spacing);
1174 g_value_set_int (value, icon_view->priv->margin);
1176 case PROP_REORDERABLE:
1177 g_value_set_boolean (value, icon_view->priv->reorderable);
1179 case PROP_TOOLTIP_COLUMN:
1180 g_value_set_int (value, icon_view->priv->tooltip_column);
1183 case PROP_ITEM_PADDING:
1184 g_value_set_int (value, icon_view->priv->item_padding);
1187 case PROP_CELL_AREA:
1188 g_value_set_object (value, icon_view->priv->cell_area);
1191 case PROP_HADJUSTMENT:
1192 g_value_set_object (value, icon_view->priv->hadjustment);
1194 case PROP_VADJUSTMENT:
1195 g_value_set_object (value, icon_view->priv->vadjustment);
1197 case PROP_HSCROLL_POLICY:
1198 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1200 case PROP_VSCROLL_POLICY:
1201 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1205 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1210 /* GtkWidget methods */
1212 gtk_icon_view_destroy (GtkWidget *widget)
1214 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1216 gtk_icon_view_set_model (icon_view, NULL);
1218 if (icon_view->priv->layout_idle_id != 0)
1220 g_source_remove (icon_view->priv->layout_idle_id);
1221 icon_view->priv->layout_idle_id = 0;
1224 if (icon_view->priv->scroll_to_path != NULL)
1226 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1227 icon_view->priv->scroll_to_path = NULL;
1230 remove_scroll_timeout (icon_view);
1232 if (icon_view->priv->hadjustment != NULL)
1234 g_object_unref (icon_view->priv->hadjustment);
1235 icon_view->priv->hadjustment = NULL;
1238 if (icon_view->priv->vadjustment != NULL)
1240 g_object_unref (icon_view->priv->vadjustment);
1241 icon_view->priv->vadjustment = NULL;
1244 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1248 gtk_icon_view_realize (GtkWidget *widget)
1250 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1251 GtkAllocation allocation;
1253 GdkWindowAttr attributes;
1254 gint attributes_mask;
1255 GtkStyleContext *context;
1257 gtk_widget_set_realized (widget, TRUE);
1259 gtk_widget_get_allocation (widget, &allocation);
1261 /* Make the main, clipping window */
1262 attributes.window_type = GDK_WINDOW_CHILD;
1263 attributes.x = allocation.x;
1264 attributes.y = allocation.y;
1265 attributes.width = allocation.width;
1266 attributes.height = allocation.height;
1267 attributes.wclass = GDK_INPUT_OUTPUT;
1268 attributes.visual = gtk_widget_get_visual (widget);
1269 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1271 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1273 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1274 &attributes, attributes_mask);
1275 gtk_widget_set_window (widget, window);
1276 gdk_window_set_user_data (window, widget);
1278 gtk_widget_get_allocation (widget, &allocation);
1280 /* Make the window for the icon view */
1283 attributes.width = MAX (icon_view->priv->width, allocation.width);
1284 attributes.height = MAX (icon_view->priv->height, allocation.height);
1285 attributes.event_mask = (GDK_EXPOSURE_MASK |
1287 GDK_POINTER_MOTION_MASK |
1288 GDK_BUTTON_PRESS_MASK |
1289 GDK_BUTTON_RELEASE_MASK |
1290 GDK_KEY_PRESS_MASK |
1291 GDK_KEY_RELEASE_MASK) |
1292 gtk_widget_get_events (widget);
1294 icon_view->priv->bin_window = gdk_window_new (window,
1295 &attributes, attributes_mask);
1296 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1298 context = gtk_widget_get_style_context (widget);
1300 gtk_style_context_save (context);
1301 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1302 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1303 gtk_style_context_set_background (context, window);
1304 gtk_style_context_restore (context);
1306 gdk_window_show (icon_view->priv->bin_window);
1310 gtk_icon_view_unrealize (GtkWidget *widget)
1312 GtkIconView *icon_view;
1314 icon_view = GTK_ICON_VIEW (widget);
1316 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1317 gdk_window_destroy (icon_view->priv->bin_window);
1318 icon_view->priv->bin_window = NULL;
1320 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1324 _gtk_icon_view_update_background (GtkIconView *icon_view)
1326 GtkWidget *widget = GTK_WIDGET (icon_view);
1328 if (gtk_widget_get_realized (widget))
1330 GtkStyleContext *context;
1332 context = gtk_widget_get_style_context (widget);
1334 gtk_style_context_save (context);
1335 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1337 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1338 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1340 gtk_style_context_restore (context);
1345 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1346 GtkStateFlags previous_state)
1348 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1349 gtk_widget_queue_draw (widget);
1353 gtk_icon_view_style_updated (GtkWidget *widget)
1355 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1357 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1358 gtk_widget_queue_resize (widget);
1362 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1366 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1370 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1374 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1378 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1382 for (list = icon_view->priv->children; list; list = list->next)
1384 GtkIconViewChild *child = list->data;
1386 /* totally ignore our child's requisition */
1387 gtk_widget_size_allocate (child->widget, &child->area);
1392 gtk_icon_view_size_allocate (GtkWidget *widget,
1393 GtkAllocation *allocation)
1395 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1397 gtk_widget_set_allocation (widget, allocation);
1399 if (gtk_widget_get_realized (widget))
1401 gdk_window_move_resize (gtk_widget_get_window (widget),
1402 allocation->x, allocation->y,
1403 allocation->width, allocation->height);
1404 gdk_window_resize (icon_view->priv->bin_window,
1405 MAX (icon_view->priv->width, allocation->width),
1406 MAX (icon_view->priv->height, allocation->height));
1409 gtk_icon_view_layout (icon_view);
1411 gtk_icon_view_allocate_children (icon_view);
1413 /* Delay signal emission */
1414 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1415 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1417 gtk_icon_view_set_hadjustment_values (icon_view);
1418 gtk_icon_view_set_vadjustment_values (icon_view);
1420 if (gtk_widget_get_realized (widget) &&
1421 icon_view->priv->scroll_to_path)
1424 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1425 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1426 icon_view->priv->scroll_to_path = NULL;
1428 gtk_icon_view_scroll_to_path (icon_view, path,
1429 icon_view->priv->scroll_to_use_align,
1430 icon_view->priv->scroll_to_row_align,
1431 icon_view->priv->scroll_to_col_align);
1432 gtk_tree_path_free (path);
1435 /* Emit any pending signals now */
1436 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1437 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1441 gtk_icon_view_draw (GtkWidget *widget,
1444 GtkIconView *icon_view;
1448 GtkIconViewDropPosition dest_pos;
1449 GtkIconViewItem *dest_item = NULL;
1451 icon_view = GTK_ICON_VIEW (widget);
1453 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1458 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1460 cairo_set_line_width (cr, 1.);
1462 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1466 dest_index = gtk_tree_path_get_indices (path)[0];
1467 gtk_tree_path_free (path);
1472 for (icons = icon_view->priv->items; icons; icons = icons->next)
1474 GtkIconViewItem *item = icons->data;
1475 GdkRectangle paint_area;
1477 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1478 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1479 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1480 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1484 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1487 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1489 gtk_icon_view_paint_item (icon_view, cr, item,
1490 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1491 icon_view->priv->draw_focus);
1493 if (dest_index == item->index)
1501 dest_pos != GTK_ICON_VIEW_NO_DROP)
1503 GtkStyleContext *context;
1504 GdkRectangle rect = { 0 };
1506 context = gtk_widget_get_style_context (widget);
1510 case GTK_ICON_VIEW_DROP_INTO:
1511 rect = dest_item->cell_area;
1513 case GTK_ICON_VIEW_DROP_ABOVE:
1514 rect.x = dest_item->cell_area.x;
1515 rect.y = dest_item->cell_area.y - 1;
1516 rect.width = dest_item->cell_area.width;
1519 case GTK_ICON_VIEW_DROP_LEFT:
1520 rect.x = dest_item->cell_area.x - 1;
1521 rect.y = dest_item->cell_area.y;
1523 rect.height = dest_item->cell_area.height;
1525 case GTK_ICON_VIEW_DROP_BELOW:
1526 rect.x = dest_item->cell_area.x;
1527 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1528 rect.width = dest_item->cell_area.width;
1531 case GTK_ICON_VIEW_DROP_RIGHT:
1532 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1533 rect.y = dest_item->cell_area.y;
1535 rect.height = dest_item->cell_area.height;
1536 case GTK_ICON_VIEW_NO_DROP: ;
1540 gtk_render_focus (context, cr,
1542 rect.width, rect.height);
1545 if (icon_view->priv->doing_rubberband)
1546 gtk_icon_view_paint_rubberband (icon_view, cr);
1550 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1554 rubberband_scroll_timeout (gpointer data)
1556 GtkIconView *icon_view = data;
1558 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1559 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1560 icon_view->priv->scroll_value_diff);
1562 gtk_icon_view_update_rubberband (icon_view);
1568 gtk_icon_view_motion (GtkWidget *widget,
1569 GdkEventMotion *event)
1571 GtkAllocation allocation;
1572 GtkIconView *icon_view;
1575 icon_view = GTK_ICON_VIEW (widget);
1577 gtk_icon_view_maybe_begin_drag (icon_view, event);
1579 if (icon_view->priv->doing_rubberband)
1581 gtk_icon_view_update_rubberband (widget);
1583 abs_y = event->y - icon_view->priv->height *
1584 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1585 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1586 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1588 gtk_widget_get_allocation (widget, &allocation);
1590 if (abs_y < 0 || abs_y > allocation.height)
1593 icon_view->priv->scroll_value_diff = abs_y;
1595 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1597 icon_view->priv->event_last_x = event->x;
1598 icon_view->priv->event_last_y = event->y;
1600 if (icon_view->priv->scroll_timeout_id == 0)
1601 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1605 remove_scroll_timeout (icon_view);
1609 GtkIconViewItem *item, *last_prelight_item;
1610 GtkCellRenderer *cell = NULL;
1612 last_prelight_item = icon_view->priv->last_prelight;
1613 item = _gtk_icon_view_get_item_at_coords (icon_view,
1620 item->prelight = TRUE;
1621 gtk_icon_view_queue_draw_item (icon_view, item);
1624 if (last_prelight_item != NULL &&
1625 last_prelight_item != item)
1627 last_prelight_item->prelight = FALSE;
1628 gtk_icon_view_queue_draw_item (icon_view,
1629 icon_view->priv->last_prelight);
1632 icon_view->priv->last_prelight = item;
1639 gtk_icon_view_remove (GtkContainer *container,
1642 GtkIconView *icon_view;
1643 GtkIconViewChild *child = NULL;
1646 icon_view = GTK_ICON_VIEW (container);
1648 tmp_list = icon_view->priv->children;
1651 child = tmp_list->data;
1652 if (child->widget == widget)
1654 gtk_widget_unparent (widget);
1656 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1657 g_list_free_1 (tmp_list);
1662 tmp_list = tmp_list->next;
1667 gtk_icon_view_forall (GtkContainer *container,
1668 gboolean include_internals,
1669 GtkCallback callback,
1670 gpointer callback_data)
1672 GtkIconView *icon_view;
1673 GtkIconViewChild *child = NULL;
1676 icon_view = GTK_ICON_VIEW (container);
1678 tmp_list = icon_view->priv->children;
1681 child = tmp_list->data;
1682 tmp_list = tmp_list->next;
1684 (* callback) (child->widget, callback_data);
1689 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1690 GtkIconViewItem *item)
1693 AtkObject *item_obj;
1695 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1698 item_obj = atk_object_ref_accessible_child (obj, item->index);
1699 if (item_obj != NULL)
1701 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1702 g_object_unref (item_obj);
1708 gtk_icon_view_add_editable (GtkCellArea *area,
1709 GtkCellRenderer *renderer,
1710 GtkCellEditable *editable,
1711 GdkRectangle *cell_area,
1713 GtkIconView *icon_view)
1715 GtkIconViewChild *child;
1716 GtkWidget *widget = GTK_WIDGET (editable);
1718 child = g_new (GtkIconViewChild, 1);
1720 child->widget = widget;
1721 child->area.x = cell_area->x;
1722 child->area.y = cell_area->y;
1723 child->area.width = cell_area->width;
1724 child->area.height = cell_area->height;
1726 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1728 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1729 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1731 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1735 gtk_icon_view_remove_editable (GtkCellArea *area,
1736 GtkCellRenderer *renderer,
1737 GtkCellEditable *editable,
1738 GtkIconView *icon_view)
1742 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1743 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1745 gtk_container_remove (GTK_CONTAINER (icon_view),
1746 GTK_WIDGET (editable));
1748 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1749 gtk_icon_view_queue_draw_path (icon_view, path);
1750 gtk_tree_path_free (path);
1754 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1756 GtkIconView *icon_view)
1758 if (!strcmp (pspec->name, "minimum-width") ||
1759 !strcmp (pspec->name, "natural-width") ||
1760 !strcmp (pspec->name, "minimum-height") ||
1761 !strcmp (pspec->name, "natural-height"))
1762 gtk_icon_view_invalidate_sizes (icon_view);
1766 * gtk_icon_view_set_cursor:
1767 * @icon_view: A #GtkIconView
1768 * @path: A #GtkTreePath
1769 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1770 * @start_editing: %TRUE if the specified cell should start being edited.
1772 * Sets the current keyboard focus to be at @path, and selects it. This is
1773 * useful when you want to focus the user's attention on a particular item.
1774 * If @cell is not %NULL, then focus is given to the cell specified by
1775 * it. Additionally, if @start_editing is %TRUE, then editing should be
1776 * started in the specified cell.
1778 * This function is often followed by <literal>gtk_widget_grab_focus
1779 * (icon_view)</literal> in order to give keyboard focus to the widget.
1780 * Please note that editing can only happen when the widget is realized.
1785 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1787 GtkCellRenderer *cell,
1788 gboolean start_editing)
1790 GtkIconViewItem *item = NULL;
1792 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1793 g_return_if_fail (path != NULL);
1794 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1796 if (icon_view->priv->cell_area)
1797 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1799 if (gtk_tree_path_get_depth (path) == 1)
1800 item = g_list_nth_data (icon_view->priv->items,
1801 gtk_tree_path_get_indices(path)[0]);
1806 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
1807 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1809 if (start_editing &&
1810 icon_view->priv->cell_area)
1812 GtkCellAreaContext *context;
1814 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1815 _gtk_icon_view_set_cell_data (icon_view, item);
1816 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1817 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1818 0 /* XXX flags */, TRUE);
1823 * gtk_icon_view_get_cursor:
1824 * @icon_view: A #GtkIconView
1825 * @path: (out) (allow-none): Return location for the current cursor path,
1827 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1829 * Fills in @path and @cell with the current cursor path and cell.
1830 * If the cursor isn't currently set, then *@path will be %NULL.
1831 * If no cell currently has focus, then *@cell will be %NULL.
1833 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1835 * Return value: %TRUE if the cursor is set.
1840 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1842 GtkCellRenderer **cell)
1844 GtkIconViewItem *item;
1846 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1848 item = icon_view->priv->cursor_item;
1853 *path = gtk_tree_path_new_from_indices (item->index, -1);
1858 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1859 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1861 return (item != NULL);
1865 gtk_icon_view_button_press (GtkWidget *widget,
1866 GdkEventButton *event)
1868 GtkIconView *icon_view;
1869 GtkIconViewItem *item;
1870 gboolean dirty = FALSE;
1871 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1873 icon_view = GTK_ICON_VIEW (widget);
1875 if (event->window != icon_view->priv->bin_window)
1878 if (!gtk_widget_has_focus (widget))
1879 gtk_widget_grab_focus (widget);
1881 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
1883 GdkModifierType extend_mod_mask;
1884 GdkModifierType modify_mod_mask;
1887 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
1890 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
1892 item = _gtk_icon_view_get_item_at_coords (icon_view,
1898 * We consider only the the cells' area as the item area if the
1899 * item is not selected, but if it *is* selected, the complete
1900 * selection rectangle is considered to be part of the item.
1902 if (item != NULL && (cell != NULL || item->selected))
1906 if (gtk_cell_renderer_is_activatable (cell))
1910 gtk_icon_view_scroll_to_item (icon_view, item);
1912 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1914 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1916 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1917 (event->state & extend_mod_mask))
1919 gtk_icon_view_unselect_all_internal (icon_view);
1921 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1922 if (!icon_view->priv->anchor_item)
1923 icon_view->priv->anchor_item = item;
1925 gtk_icon_view_select_all_between (icon_view,
1926 icon_view->priv->anchor_item,
1932 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1933 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1934 (event->state & modify_mod_mask))
1936 item->selected = !item->selected;
1937 gtk_icon_view_queue_draw_item (icon_view, item);
1942 gtk_icon_view_unselect_all_internal (icon_view);
1944 item->selected = TRUE;
1945 gtk_icon_view_queue_draw_item (icon_view, item);
1948 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1949 icon_view->priv->anchor_item = item;
1952 /* Save press to possibly begin a drag */
1953 if (icon_view->priv->pressed_button < 0)
1955 icon_view->priv->pressed_button = event->button;
1956 icon_view->priv->press_start_x = event->x;
1957 icon_view->priv->press_start_y = event->y;
1960 if (!icon_view->priv->last_single_clicked)
1961 icon_view->priv->last_single_clicked = item;
1963 /* cancel the current editing, if it exists */
1964 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1966 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
1968 GtkCellAreaContext *context;
1970 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1972 _gtk_icon_view_set_cell_data (icon_view, item);
1973 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1974 GTK_WIDGET (icon_view),
1975 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
1980 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1981 !(event->state & modify_mod_mask))
1983 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1986 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1987 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
1990 /* don't draw keyboard focus around an clicked-on item */
1991 icon_view->priv->draw_focus = FALSE;
1994 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
1996 item = _gtk_icon_view_get_item_at_coords (icon_view,
2001 if (item && item == icon_view->priv->last_single_clicked)
2005 path = gtk_tree_path_new_from_indices (item->index, -1);
2006 gtk_icon_view_item_activated (icon_view, path);
2007 gtk_tree_path_free (path);
2010 icon_view->priv->last_single_clicked = NULL;
2011 icon_view->priv->pressed_button = -1;
2015 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2017 return event->button == GDK_BUTTON_PRIMARY;
2021 gtk_icon_view_button_release (GtkWidget *widget,
2022 GdkEventButton *event)
2024 GtkIconView *icon_view;
2026 icon_view = GTK_ICON_VIEW (widget);
2028 if (icon_view->priv->pressed_button == event->button)
2029 icon_view->priv->pressed_button = -1;
2031 gtk_icon_view_stop_rubberbanding (icon_view);
2033 remove_scroll_timeout (icon_view);
2039 gtk_icon_view_key_press (GtkWidget *widget,
2042 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2044 if (icon_view->priv->doing_rubberband)
2046 if (event->keyval == GDK_KEY_Escape)
2047 gtk_icon_view_stop_rubberbanding (icon_view);
2052 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2056 gtk_icon_view_key_release (GtkWidget *widget,
2059 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2061 if (icon_view->priv->doing_rubberband)
2064 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2068 gtk_icon_view_update_rubberband (gpointer data)
2070 GtkIconView *icon_view;
2072 GdkRectangle old_area;
2073 GdkRectangle new_area;
2074 GdkRectangle common;
2075 cairo_region_t *invalid_region;
2077 icon_view = GTK_ICON_VIEW (data);
2079 gdk_window_get_device_position (icon_view->priv->bin_window,
2080 icon_view->priv->rubberband_device,
2086 old_area.x = MIN (icon_view->priv->rubberband_x1,
2087 icon_view->priv->rubberband_x2);
2088 old_area.y = MIN (icon_view->priv->rubberband_y1,
2089 icon_view->priv->rubberband_y2);
2090 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2091 icon_view->priv->rubberband_x1) + 1;
2092 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2093 icon_view->priv->rubberband_y1) + 1;
2095 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2096 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2097 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2098 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2100 invalid_region = cairo_region_create_rectangle (&old_area);
2101 cairo_region_union_rectangle (invalid_region, &new_area);
2103 gdk_rectangle_intersect (&old_area, &new_area, &common);
2104 if (common.width > 2 && common.height > 2)
2106 cairo_region_t *common_region;
2108 /* make sure the border is invalidated */
2114 common_region = cairo_region_create_rectangle (&common);
2116 cairo_region_subtract (invalid_region, common_region);
2117 cairo_region_destroy (common_region);
2120 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2122 cairo_region_destroy (invalid_region);
2124 icon_view->priv->rubberband_x2 = x;
2125 icon_view->priv->rubberband_y2 = y;
2127 gtk_icon_view_update_rubberband_selection (icon_view);
2131 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2138 if (icon_view->priv->rubberband_device)
2141 for (items = icon_view->priv->items; items; items = items->next)
2143 GtkIconViewItem *item = items->data;
2145 item->selected_before_rubberbanding = item->selected;
2148 icon_view->priv->rubberband_x1 = x;
2149 icon_view->priv->rubberband_y1 = y;
2150 icon_view->priv->rubberband_x2 = x;
2151 icon_view->priv->rubberband_y2 = y;
2153 icon_view->priv->doing_rubberband = TRUE;
2154 icon_view->priv->rubberband_device = device;
2156 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2160 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2162 if (!icon_view->priv->doing_rubberband)
2165 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2166 icon_view->priv->rubberband_device);
2168 icon_view->priv->doing_rubberband = FALSE;
2169 icon_view->priv->rubberband_device = NULL;
2171 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2175 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2178 gint x, y, width, height;
2179 gboolean dirty = FALSE;
2181 x = MIN (icon_view->priv->rubberband_x1,
2182 icon_view->priv->rubberband_x2);
2183 y = MIN (icon_view->priv->rubberband_y1,
2184 icon_view->priv->rubberband_y2);
2185 width = ABS (icon_view->priv->rubberband_x1 -
2186 icon_view->priv->rubberband_x2);
2187 height = ABS (icon_view->priv->rubberband_y1 -
2188 icon_view->priv->rubberband_y2);
2190 for (items = icon_view->priv->items; items; items = items->next)
2192 GtkIconViewItem *item = items->data;
2196 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2197 x, y, width, height);
2199 selected = is_in ^ item->selected_before_rubberbanding;
2201 if (item->selected != selected)
2203 item->selected = selected;
2205 gtk_icon_view_queue_draw_item (icon_view, item);
2210 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2215 GdkRectangle hit_rect;
2220 hit_test (GtkCellRenderer *renderer,
2221 const GdkRectangle *cell_area,
2222 const GdkRectangle *cell_background,
2225 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2226 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2227 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2228 MAX (data->hit_rect.y, cell_area->y) > 0)
2231 return (data->hit != FALSE);
2235 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2236 GtkIconViewItem *item,
2242 HitTestData data = { { x, y, width, height }, FALSE };
2243 GtkCellAreaContext *context;
2244 GdkRectangle *item_area = (GdkRectangle *)item;
2246 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2247 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2250 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2252 _gtk_icon_view_set_cell_data (icon_view, item);
2253 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2254 GTK_WIDGET (icon_view),
2255 item_area, item_area,
2256 (GtkCellAllocCallback)hit_test, &data);
2262 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2264 gboolean dirty = FALSE;
2267 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2270 for (items = icon_view->priv->items; items; items = items->next)
2272 GtkIconViewItem *item = items->data;
2276 item->selected = FALSE;
2278 gtk_icon_view_queue_draw_item (icon_view, item);
2279 gtk_icon_view_item_selected_changed (icon_view, item);
2287 /* GtkIconView signals */
2289 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2291 gtk_icon_view_select_all (icon_view);
2295 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2297 gtk_icon_view_unselect_all (icon_view);
2301 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2303 gtk_icon_view_unselect_all (icon_view);
2305 if (icon_view->priv->cursor_item != NULL)
2306 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2310 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2313 GtkCellAreaContext *context;
2315 if (!icon_view->priv->cursor_item)
2318 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2320 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2321 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2322 GTK_WIDGET (icon_view),
2323 (GdkRectangle *)icon_view->priv->cursor_item,
2327 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2328 gtk_icon_view_item_activated (icon_view, path);
2329 gtk_tree_path_free (path);
2335 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2337 if (!icon_view->priv->cursor_item)
2340 switch (icon_view->priv->selection_mode)
2342 case GTK_SELECTION_NONE:
2344 case GTK_SELECTION_BROWSE:
2345 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2347 case GTK_SELECTION_SINGLE:
2348 if (icon_view->priv->cursor_item->selected)
2349 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2351 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2353 case GTK_SELECTION_MULTIPLE:
2354 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2355 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2357 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2358 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2363 /* Internal functions */
2365 gtk_icon_view_process_updates (GtkIconView *icon_view)
2367 /* Prior to drawing, we check if a layout has been scheduled. If so,
2368 * do it now that all cell view items have valid sizes before we proceeed
2369 * (and resize the bin_window if required).
2371 if (icon_view->priv->layout_idle_id != 0)
2372 gtk_icon_view_layout (icon_view);
2374 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2378 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2380 GtkAllocation allocation;
2381 GtkAdjustment *adj = icon_view->priv->hadjustment;
2382 gdouble old_page_size;
2388 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2390 old_value = gtk_adjustment_get_value (adj);
2391 old_upper = gtk_adjustment_get_upper (adj);
2392 old_page_size = gtk_adjustment_get_page_size (adj);
2393 new_upper = MAX (allocation.width, icon_view->priv->width);
2395 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2397 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2398 /* Quick explanation:
2399 * In LTR locales, leftmost portion of visible rectangle should stay
2400 * fixed, which means left edge of scrollbar thumb should remain fixed
2401 * and thus adjustment's value should stay the same.
2403 * In RTL locales, we want to keep rightmost portion of visible
2404 * rectangle fixed. This means right edge of thumb should remain fixed.
2405 * In this case, upper - value - page_size should remain constant.
2407 new_value = (new_upper - allocation.width) -
2408 (old_upper - old_value - old_page_size);
2409 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2412 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2414 gtk_adjustment_configure (adj,
2418 allocation.width * 0.1,
2419 allocation.width * 0.9,
2424 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2426 GtkAllocation allocation;
2427 GtkAdjustment *adj = icon_view->priv->vadjustment;
2429 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2431 gtk_adjustment_configure (adj,
2432 gtk_adjustment_get_value (adj),
2434 MAX (allocation.height, icon_view->priv->height),
2435 allocation.height * 0.1,
2436 allocation.height * 0.9,
2441 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2442 GtkAdjustment *adjustment)
2444 GtkIconViewPrivate *priv = icon_view->priv;
2446 if (adjustment && priv->hadjustment == adjustment)
2449 if (priv->hadjustment != NULL)
2451 g_signal_handlers_disconnect_matched (priv->hadjustment,
2452 G_SIGNAL_MATCH_DATA,
2453 0, 0, NULL, NULL, icon_view);
2454 g_object_unref (priv->hadjustment);
2458 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2461 g_signal_connect (adjustment, "value-changed",
2462 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2463 priv->hadjustment = g_object_ref_sink (adjustment);
2464 gtk_icon_view_set_hadjustment_values (icon_view);
2466 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2470 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2471 GtkAdjustment *adjustment)
2473 GtkIconViewPrivate *priv = icon_view->priv;
2475 if (adjustment && priv->vadjustment == adjustment)
2478 if (priv->vadjustment != NULL)
2480 g_signal_handlers_disconnect_matched (priv->vadjustment,
2481 G_SIGNAL_MATCH_DATA,
2482 0, 0, NULL, NULL, icon_view);
2483 g_object_unref (priv->vadjustment);
2487 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2490 g_signal_connect (adjustment, "value-changed",
2491 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2492 priv->vadjustment = g_object_ref_sink (adjustment);
2493 gtk_icon_view_set_vadjustment_values (icon_view);
2495 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2499 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2500 GtkIconView *icon_view)
2502 GtkIconViewPrivate *priv = icon_view->priv;
2504 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2506 gdk_window_move (priv->bin_window,
2507 - gtk_adjustment_get_value (priv->hadjustment),
2508 - gtk_adjustment_get_value (priv->vadjustment));
2510 if (icon_view->priv->doing_rubberband)
2511 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2513 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2515 gtk_icon_view_process_updates (icon_view);
2520 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2525 gint *maximum_width)
2527 GtkAllocation allocation;
2528 GtkCellAreaContext *context;
2529 GtkIconViewPrivate *priv = icon_view->priv;
2530 GtkWidget *widget = GTK_WIDGET (icon_view);
2531 gint x, current_width;
2532 GList *items, *last_item;
2534 gint max_height = 0;
2537 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2545 current_width += 2 * priv->margin;
2547 gtk_widget_get_allocation (widget, &allocation);
2549 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2550 g_ptr_array_add (priv->row_contexts, context);
2552 /* In the first loop we iterate horizontally until we hit allocation width
2553 * and collect the aligned height-for-width */
2557 GtkIconViewItem *item = items->data;
2558 GdkRectangle *item_area = (GdkRectangle *)item;
2560 item_area->width = item_width;
2562 current_width += item_area->width + icon_view->priv->item_padding * 2;
2564 if (items != first_item)
2566 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2567 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2571 /* Get this item's particular width & height (all alignments are cached by now) */
2572 _gtk_icon_view_set_cell_data (icon_view, item);
2573 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2578 current_width += icon_view->priv->column_spacing;
2580 item_area->y = *y + icon_view->priv->item_padding;
2581 item_area->x = x + icon_view->priv->item_padding;
2583 x = current_width - icon_view->priv->margin;
2585 if (current_width > *maximum_width)
2586 *maximum_width = current_width;
2592 items = items->next;
2597 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2598 gtk_cell_area_context_allocate (context, item_width, max_height);
2600 /* In the second loop the item height has been aligned and derived and
2601 * we just set the height and handle rtl layout */
2602 for (items = first_item; items != last_item; items = items->next)
2604 GtkIconViewItem *item = items->data;
2605 GdkRectangle *item_area = (GdkRectangle *)item;
2609 item_area->x = *maximum_width - item_area->width - item_area->x;
2610 item->col = col - 1 - item->col;
2613 /* All items in the same row get the same height */
2614 item_area->height = max_height;
2617 /* Adjust the new y coordinate. */
2618 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2624 adjust_wrap_width (GtkIconView *icon_view)
2626 if (icon_view->priv->text_cell)
2628 gint wrap_width = 50;
2630 /* Here we go with the same old guess, try the icon size and set double
2631 * the size of the first icon found in the list, naive but works much
2633 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2635 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2636 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2637 GTK_WIDGET (icon_view),
2640 wrap_width = MAX (wrap_width * 2, 50);
2643 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2644 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2649 gtk_icon_view_layout (GtkIconView *icon_view)
2651 GtkAllocation allocation;
2654 gint y = 0, maximum_width = 0;
2657 gboolean size_changed = FALSE;
2659 if (icon_view->priv->layout_idle_id != 0)
2661 g_source_remove (icon_view->priv->layout_idle_id);
2662 icon_view->priv->layout_idle_id = 0;
2665 if (icon_view->priv->model == NULL)
2668 widget = GTK_WIDGET (icon_view);
2670 item_width = icon_view->priv->item_width;
2672 /* Update the wrap width for the text cell before going and requesting sizes */
2673 adjust_wrap_width (icon_view);
2675 /* Update the context widths for any invalidated items */
2676 gtk_icon_view_cache_widths (icon_view);
2678 /* Fetch the new item width if needed */
2680 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2683 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2685 icons = icon_view->priv->items;
2686 y += icon_view->priv->margin;
2689 /* Clear the per row contexts */
2690 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2694 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2696 &y, &maximum_width);
2699 while (icons != NULL);
2701 if (maximum_width != icon_view->priv->width)
2703 icon_view->priv->width = maximum_width;
2704 size_changed = TRUE;
2707 y += icon_view->priv->margin;
2709 if (y != icon_view->priv->height)
2711 icon_view->priv->height = y;
2712 size_changed = TRUE;
2715 gtk_icon_view_set_hadjustment_values (icon_view);
2716 gtk_icon_view_set_vadjustment_values (icon_view);
2719 gtk_widget_queue_resize_no_redraw (widget);
2721 gtk_widget_get_allocation (widget, &allocation);
2722 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2723 gdk_window_resize (icon_view->priv->bin_window,
2724 MAX (icon_view->priv->width, allocation.width),
2725 MAX (icon_view->priv->height, allocation.height));
2727 if (icon_view->priv->scroll_to_path)
2731 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2732 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2733 icon_view->priv->scroll_to_path = NULL;
2735 gtk_icon_view_scroll_to_path (icon_view, path,
2736 icon_view->priv->scroll_to_use_align,
2737 icon_view->priv->scroll_to_row_align,
2738 icon_view->priv->scroll_to_col_align);
2739 gtk_tree_path_free (path);
2742 gtk_widget_queue_draw (widget);
2745 /* This ensures that all widths have been cached in the
2746 * context and we have proper alignments to go on.
2749 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2753 g_signal_handler_block (icon_view->priv->cell_area_context,
2754 icon_view->priv->context_changed_id);
2756 for (items = icon_view->priv->items; items; items = items->next)
2758 GtkIconViewItem *item = items->data;
2760 /* Only fetch the width of items with invalidated sizes */
2761 if (item->cell_area.width < 0)
2763 _gtk_icon_view_set_cell_data (icon_view, item);
2764 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2765 icon_view->priv->cell_area_context,
2766 GTK_WIDGET (icon_view), NULL, NULL);
2770 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2771 icon_view->priv->context_changed_id);
2775 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2777 /* Clear all item sizes */
2778 g_list_foreach (icon_view->priv->items,
2779 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2781 /* Reset the context */
2782 if (icon_view->priv->cell_area_context)
2784 g_signal_handler_block (icon_view->priv->cell_area_context,
2785 icon_view->priv->context_changed_id);
2786 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2787 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2788 icon_view->priv->context_changed_id);
2791 /* Re-layout the items */
2792 gtk_icon_view_queue_layout (icon_view);
2796 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2798 item->cell_area.width = -1;
2799 item->cell_area.height = -1;
2803 gtk_icon_view_paint_item (GtkIconView *icon_view,
2805 GtkIconViewItem *item,
2808 gboolean draw_focus)
2810 GdkRectangle cell_area;
2811 GtkStateFlags state = 0;
2812 GtkCellRendererState flags = 0;
2813 GtkStyleContext *style_context;
2814 GtkWidget *widget = GTK_WIDGET (icon_view);
2815 GtkIconViewPrivate *priv = icon_view->priv;
2816 GtkCellAreaContext *context;
2818 if (priv->model == NULL)
2821 _gtk_icon_view_set_cell_data (icon_view, item);
2823 style_context = gtk_widget_get_style_context (widget);
2824 state = gtk_widget_get_state_flags (widget);
2826 gtk_style_context_save (style_context);
2827 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2828 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2830 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
2834 if ((state & GTK_STATE_FLAG_FOCUSED) &&
2835 item == icon_view->priv->cursor_item)
2837 flags |= GTK_CELL_RENDERER_FOCUSED;
2840 state |= GTK_STATE_FLAG_SELECTED;
2841 flags |= GTK_CELL_RENDERER_SELECTED;
2846 state |= GTK_STATE_FLAG_PRELIGHT;
2847 flags |= GTK_CELL_RENDERER_PRELIT;
2850 gtk_style_context_set_state (style_context, state);
2854 gtk_render_background (style_context, cr,
2855 x - icon_view->priv->item_padding,
2856 y - icon_view->priv->item_padding,
2857 item->cell_area.width + icon_view->priv->item_padding * 2,
2858 item->cell_area.height + icon_view->priv->item_padding * 2);
2859 gtk_render_frame (style_context, cr,
2860 x - icon_view->priv->item_padding,
2861 y - icon_view->priv->item_padding,
2862 item->cell_area.width + icon_view->priv->item_padding * 2,
2863 item->cell_area.height + icon_view->priv->item_padding * 2);
2868 cell_area.width = item->cell_area.width;
2869 cell_area.height = item->cell_area.height;
2871 context = g_ptr_array_index (priv->row_contexts, item->row);
2872 gtk_cell_area_render (priv->cell_area, context,
2873 widget, cr, &cell_area, &cell_area, flags,
2876 gtk_style_context_restore (style_context);
2880 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2883 GtkStyleContext *context;
2888 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2889 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2890 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2891 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2893 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2895 gtk_style_context_save (context);
2896 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2898 gdk_cairo_rectangle (cr, &rect);
2901 gtk_render_background (context, cr,
2903 rect.width, rect.height);
2904 gtk_render_frame (context, cr,
2906 rect.width, rect.height);
2908 gtk_style_context_restore (context);
2913 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2919 index = gtk_tree_path_get_indices (path)[0];
2921 for (l = icon_view->priv->items; l; l = l->next)
2923 GtkIconViewItem *item = l->data;
2925 if (item->index == index)
2927 gtk_icon_view_queue_draw_item (icon_view, item);
2934 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2935 GtkIconViewItem *item)
2938 GdkRectangle *item_area = (GdkRectangle *)item;
2940 rect.x = item_area->x - icon_view->priv->item_padding;
2941 rect.y = item_area->y - icon_view->priv->item_padding;
2942 rect.width = item_area->width + icon_view->priv->item_padding * 2;
2943 rect.height = item_area->height + icon_view->priv->item_padding * 2;
2945 if (icon_view->priv->bin_window)
2946 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
2950 layout_callback (gpointer user_data)
2952 GtkIconView *icon_view;
2954 icon_view = GTK_ICON_VIEW (user_data);
2956 icon_view->priv->layout_idle_id = 0;
2958 gtk_icon_view_layout (icon_view);
2964 gtk_icon_view_queue_layout (GtkIconView *icon_view)
2966 if (icon_view->priv->layout_idle_id != 0)
2969 icon_view->priv->layout_idle_id =
2970 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
2971 layout_callback, icon_view, NULL);
2975 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
2976 GtkIconViewItem *item,
2977 GtkCellRenderer *cursor_cell)
2980 AtkObject *item_obj;
2981 AtkObject *cursor_item_obj;
2983 /* When hitting this path from keynav, the focus cell is
2984 * already set, we dont need to notify the atk object
2985 * but we still need to queue the draw here (in the case
2986 * that the focus cell changes but not the cursor item).
2988 gtk_icon_view_queue_draw_item (icon_view, item);
2990 if (icon_view->priv->cursor_item == item &&
2991 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
2994 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2995 if (icon_view->priv->cursor_item != NULL)
2997 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3000 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3001 if (cursor_item_obj != NULL)
3002 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3005 icon_view->priv->cursor_item = item;
3008 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3011 /* Make sure there is a cell in focus initially */
3012 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3013 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3016 /* Notify that accessible focus object has changed */
3017 item_obj = atk_object_ref_accessible_child (obj, item->index);
3019 if (item_obj != NULL)
3021 atk_focus_tracker_notify (item_obj);
3022 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3023 g_object_unref (item_obj);
3028 static GtkIconViewItem *
3029 gtk_icon_view_item_new (void)
3031 GtkIconViewItem *item;
3033 item = g_slice_new0 (GtkIconViewItem);
3035 item->cell_area.width = -1;
3036 item->cell_area.height = -1;
3042 gtk_icon_view_item_free (GtkIconViewItem *item)
3044 g_return_if_fail (item != NULL);
3046 g_slice_free (GtkIconViewItem, item);
3050 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3053 gboolean only_in_cell,
3054 GtkCellRenderer **cell_at_pos)
3059 *cell_at_pos = NULL;
3061 for (items = icon_view->priv->items; items; items = items->next)
3063 GtkIconViewItem *item = items->data;
3064 GdkRectangle *item_area = (GdkRectangle *)item;
3066 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3067 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3068 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3069 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3071 if (only_in_cell || cell_at_pos)
3073 GtkCellRenderer *cell = NULL;
3074 GtkCellAreaContext *context;
3076 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3077 _gtk_icon_view_set_cell_data (icon_view, item);
3079 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3080 y >= item_area->y && y <= item_area->y + item_area->height)
3081 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3082 GTK_WIDGET (icon_view),
3087 *cell_at_pos = cell;
3090 return cell != NULL ? item : NULL;
3101 _gtk_icon_view_select_item (GtkIconView *icon_view,
3102 GtkIconViewItem *item)
3104 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3105 g_return_if_fail (item != NULL);
3110 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3112 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3113 gtk_icon_view_unselect_all_internal (icon_view);
3115 item->selected = TRUE;
3117 gtk_icon_view_item_selected_changed (icon_view, item);
3118 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3120 gtk_icon_view_queue_draw_item (icon_view, item);
3125 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3126 GtkIconViewItem *item)
3128 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3129 g_return_if_fail (item != NULL);
3131 if (!item->selected)
3134 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3135 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3138 item->selected = FALSE;
3140 gtk_icon_view_item_selected_changed (icon_view, item);
3141 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3143 gtk_icon_view_queue_draw_item (icon_view, item);
3147 verify_items (GtkIconView *icon_view)
3152 for (items = icon_view->priv->items; items; items = items->next)
3154 GtkIconViewItem *item = items->data;
3156 if (item->index != i)
3157 g_error ("List item does not match its index: "
3158 "item index %d and list index %d\n", item->index, i);
3165 gtk_icon_view_row_changed (GtkTreeModel *model,
3170 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3172 /* ignore changes in branches */
3173 if (gtk_tree_path_get_depth (path) > 1)
3176 /* An icon view subclass might add it's own model and populate
3177 * things at init() time instead of waiting for the constructor()
3180 if (icon_view->priv->cell_area)
3181 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3183 /* Here we can use a "grow-only" strategy for optimization
3184 * and only invalidate a single item and queue a relayout
3185 * instead of invalidating the whole thing.
3187 * For now GtkIconView still cant deal with huge models
3188 * so just invalidate the whole thing when the model
3191 gtk_icon_view_invalidate_sizes (icon_view);
3193 verify_items (icon_view);
3197 gtk_icon_view_row_inserted (GtkTreeModel *model,
3202 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3204 GtkIconViewItem *item;
3205 gboolean iters_persist;
3208 /* ignore changes in branches */
3209 if (gtk_tree_path_get_depth (path) > 1)
3212 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3214 index = gtk_tree_path_get_indices(path)[0];
3216 item = gtk_icon_view_item_new ();
3221 item->index = index;
3223 /* FIXME: We can be more efficient here,
3224 we can store a tail pointer and use that when
3225 appending (which is a rather common operation)
3227 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3230 list = g_list_nth (icon_view->priv->items, index + 1);
3231 for (; list; list = list->next)
3238 verify_items (icon_view);
3240 gtk_icon_view_queue_layout (icon_view);
3244 gtk_icon_view_row_deleted (GtkTreeModel *model,
3248 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3250 GtkIconViewItem *item;
3252 gboolean emit = FALSE;
3254 /* ignore changes in branches */
3255 if (gtk_tree_path_get_depth (path) > 1)
3258 index = gtk_tree_path_get_indices(path)[0];
3260 list = g_list_nth (icon_view->priv->items, index);
3263 if (icon_view->priv->cell_area)
3264 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3266 if (item == icon_view->priv->anchor_item)
3267 icon_view->priv->anchor_item = NULL;
3269 if (item == icon_view->priv->cursor_item)
3270 icon_view->priv->cursor_item = NULL;
3272 if (item == icon_view->priv->last_prelight)
3273 icon_view->priv->last_prelight = NULL;
3278 gtk_icon_view_item_free (item);
3280 for (next = list->next; next; next = next->next)
3287 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3289 verify_items (icon_view);
3291 gtk_icon_view_queue_layout (icon_view);
3294 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3298 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3299 GtkTreePath *parent,
3304 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3307 GList *items = NULL, *list;
3308 GtkIconViewItem **item_array;
3311 /* ignore changes in branches */
3315 if (icon_view->priv->cell_area)
3316 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3318 length = gtk_tree_model_iter_n_children (model, NULL);
3320 order = g_new (gint, length);
3321 for (i = 0; i < length; i++)
3322 order [new_order[i]] = i;
3324 item_array = g_new (GtkIconViewItem *, length);
3325 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3326 item_array[order[i]] = list->data;
3329 for (i = length - 1; i >= 0; i--)
3331 item_array[i]->index = i;
3332 items = g_list_prepend (items, item_array[i]);
3335 g_free (item_array);
3336 g_list_free (icon_view->priv->items);
3337 icon_view->priv->items = items;
3339 gtk_icon_view_queue_layout (icon_view);
3341 verify_items (icon_view);
3345 gtk_icon_view_build_items (GtkIconView *icon_view)
3349 gboolean iters_persist;
3350 GList *items = NULL;
3352 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3354 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3362 GtkIconViewItem *item = gtk_icon_view_item_new ();
3371 items = g_list_prepend (items, item);
3373 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3375 icon_view->priv->items = g_list_reverse (items);
3379 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3382 GtkMovementStep step,
3386 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3387 I_("move-cursor"), 2,
3391 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3396 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3399 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3404 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3411 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3412 GtkMovementStep step,
3415 GdkModifierType state;
3417 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3418 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3419 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3420 step == GTK_MOVEMENT_DISPLAY_LINES ||
3421 step == GTK_MOVEMENT_PAGES ||
3422 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3424 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3427 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3428 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3430 if (gtk_get_current_event_state (&state))
3432 GdkModifierType extend_mod_mask;
3433 GdkModifierType modify_mod_mask;
3436 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3437 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3439 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3440 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3442 if ((state & modify_mod_mask) == modify_mod_mask)
3443 icon_view->priv->modify_selection_pressed = TRUE;
3444 if ((state & extend_mod_mask) == extend_mod_mask)
3445 icon_view->priv->extend_selection_pressed = TRUE;
3447 /* else we assume not pressed */
3451 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3452 case GTK_MOVEMENT_VISUAL_POSITIONS:
3453 gtk_icon_view_move_cursor_left_right (icon_view, count);
3455 case GTK_MOVEMENT_DISPLAY_LINES:
3456 gtk_icon_view_move_cursor_up_down (icon_view, count);
3458 case GTK_MOVEMENT_PAGES:
3459 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3461 case GTK_MOVEMENT_BUFFER_ENDS:
3462 gtk_icon_view_move_cursor_start_end (icon_view, count);
3465 g_assert_not_reached ();
3468 icon_view->priv->modify_selection_pressed = FALSE;
3469 icon_view->priv->extend_selection_pressed = FALSE;
3471 icon_view->priv->draw_focus = TRUE;
3476 static GtkIconViewItem *
3477 find_item (GtkIconView *icon_view,
3478 GtkIconViewItem *current,
3484 GtkIconViewItem *item;
3486 /* FIXME: this could be more efficient
3488 row = current->row + row_ofs;
3489 col = current->col + col_ofs;
3491 for (items = icon_view->priv->items; items; items = items->next)
3494 if (item->row == row && item->col == col)
3501 static GtkIconViewItem *
3502 find_item_page_up_down (GtkIconView *icon_view,
3503 GtkIconViewItem *current,
3510 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3512 item = g_list_find (icon_view->priv->items, current);
3517 for (next = item->next; next; next = next->next)
3519 if (((GtkIconViewItem *)next->data)->col == col)
3522 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3532 for (next = item->prev; next; next = next->prev)
3534 if (((GtkIconViewItem *)next->data)->col == col)
3537 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3551 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3552 GtkIconViewItem *anchor,
3553 GtkIconViewItem *cursor)
3556 GtkIconViewItem *item;
3557 gint row1, row2, col1, col2;
3558 gboolean dirty = FALSE;
3560 if (anchor->row < cursor->row)
3571 if (anchor->col < cursor->col)
3582 for (items = icon_view->priv->items; items; items = items->next)
3586 if (row1 <= item->row && item->row <= row2 &&
3587 col1 <= item->col && item->col <= col2)
3589 if (!item->selected)
3592 item->selected = TRUE;
3593 gtk_icon_view_item_selected_changed (icon_view, item);
3595 gtk_icon_view_queue_draw_item (icon_view, item);
3603 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3606 GtkIconViewItem *item;
3607 GtkCellRenderer *cell = NULL;
3608 gboolean dirty = FALSE;
3610 GtkDirectionType direction;
3612 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3615 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3617 if (!icon_view->priv->cursor_item)
3622 list = icon_view->priv->items;
3624 list = g_list_last (icon_view->priv->items);
3630 /* Give focus to the first cell initially */
3631 _gtk_icon_view_set_cell_data (icon_view, item);
3632 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3641 item = icon_view->priv->cursor_item;
3642 step = count > 0 ? 1 : -1;
3644 /* Save the current focus cell in case we hit the edge */
3645 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3649 _gtk_icon_view_set_cell_data (icon_view, item);
3651 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3654 item = find_item (icon_view, item, step, 0);
3660 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3662 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3664 gtk_widget_child_focus (toplevel,
3665 direction == GTK_DIR_UP ?
3666 GTK_DIR_TAB_BACKWARD :
3667 GTK_DIR_TAB_FORWARD);
3671 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3675 if (icon_view->priv->modify_selection_pressed ||
3676 !icon_view->priv->extend_selection_pressed ||
3677 !icon_view->priv->anchor_item ||
3678 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3679 icon_view->priv->anchor_item = item;
3681 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3682 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3684 if (!icon_view->priv->modify_selection_pressed &&
3685 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3687 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3688 dirty = gtk_icon_view_select_all_between (icon_view,
3689 icon_view->priv->anchor_item,
3693 gtk_icon_view_scroll_to_item (icon_view, item);
3696 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3700 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3703 GtkIconViewItem *item;
3704 gboolean dirty = FALSE;
3706 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3709 if (!icon_view->priv->cursor_item)
3714 list = icon_view->priv->items;
3716 list = g_list_last (icon_view->priv->items);
3718 item = list ? list->data : NULL;
3721 item = find_item_page_up_down (icon_view,
3722 icon_view->priv->cursor_item,
3725 if (item == icon_view->priv->cursor_item)
3726 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3731 if (icon_view->priv->modify_selection_pressed ||
3732 !icon_view->priv->extend_selection_pressed ||
3733 !icon_view->priv->anchor_item ||
3734 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3735 icon_view->priv->anchor_item = item;
3737 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3739 if (!icon_view->priv->modify_selection_pressed &&
3740 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3742 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3743 dirty = gtk_icon_view_select_all_between (icon_view,
3744 icon_view->priv->anchor_item,
3748 gtk_icon_view_scroll_to_item (icon_view, item);
3751 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3755 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3758 GtkIconViewItem *item;
3759 GtkCellRenderer *cell = NULL;
3760 gboolean dirty = FALSE;
3762 GtkDirectionType direction;
3764 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3767 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3769 if (!icon_view->priv->cursor_item)
3774 list = icon_view->priv->items;
3776 list = g_list_last (icon_view->priv->items);
3782 /* Give focus to the first cell initially */
3783 _gtk_icon_view_set_cell_data (icon_view, item);
3784 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3793 item = icon_view->priv->cursor_item;
3794 step = count > 0 ? 1 : -1;
3796 /* Save the current focus cell in case we hit the edge */
3797 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3801 _gtk_icon_view_set_cell_data (icon_view, item);
3803 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3806 item = find_item (icon_view, item, 0, step);
3812 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3814 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3816 gtk_widget_child_focus (toplevel,
3817 direction == GTK_DIR_LEFT ?
3818 GTK_DIR_TAB_BACKWARD :
3819 GTK_DIR_TAB_FORWARD);
3823 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3827 if (icon_view->priv->modify_selection_pressed ||
3828 !icon_view->priv->extend_selection_pressed ||
3829 !icon_view->priv->anchor_item ||
3830 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3831 icon_view->priv->anchor_item = item;
3833 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3834 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3836 if (!icon_view->priv->modify_selection_pressed &&
3837 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3839 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3840 dirty = gtk_icon_view_select_all_between (icon_view,
3841 icon_view->priv->anchor_item,
3845 gtk_icon_view_scroll_to_item (icon_view, item);
3848 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3852 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3855 GtkIconViewItem *item;
3857 gboolean dirty = FALSE;
3859 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3863 list = icon_view->priv->items;
3865 list = g_list_last (icon_view->priv->items);
3867 item = list ? list->data : NULL;
3869 if (item == icon_view->priv->cursor_item)
3870 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3875 if (icon_view->priv->modify_selection_pressed ||
3876 !icon_view->priv->extend_selection_pressed ||
3877 !icon_view->priv->anchor_item ||
3878 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3879 icon_view->priv->anchor_item = item;
3881 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3883 if (!icon_view->priv->modify_selection_pressed &&
3884 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3886 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3887 dirty = gtk_icon_view_select_all_between (icon_view,
3888 icon_view->priv->anchor_item,
3892 gtk_icon_view_scroll_to_item (icon_view, item);
3895 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3899 * gtk_icon_view_scroll_to_path:
3900 * @icon_view: A #GtkIconView.
3901 * @path: The path of the item to move to.
3902 * @use_align: whether to use alignment arguments, or %FALSE.
3903 * @row_align: The vertical alignment of the item specified by @path.
3904 * @col_align: The horizontal alignment of the item specified by @path.
3906 * Moves the alignments of @icon_view to the position specified by @path.
3907 * @row_align determines where the row is placed, and @col_align determines
3908 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3909 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3912 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3913 * tree does the minimum amount of work to scroll the item onto the screen.
3914 * This means that the item will be scrolled to the edge closest to its current
3915 * position. If the item is currently visible on the screen, nothing is done.
3917 * This function only works if the model is set, and @path is a valid row on
3918 * the model. If the model changes before the @icon_view is realized, the
3919 * centered path will be modified to reflect this change.
3924 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3930 GtkIconViewItem *item = NULL;
3933 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3934 g_return_if_fail (path != NULL);
3935 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3936 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3938 widget = GTK_WIDGET (icon_view);
3940 if (gtk_tree_path_get_depth (path) > 0)
3941 item = g_list_nth_data (icon_view->priv->items,
3942 gtk_tree_path_get_indices(path)[0]);
3944 if (!item || item->cell_area.width < 0 ||
3945 !gtk_widget_get_realized (widget))
3947 if (icon_view->priv->scroll_to_path)
3948 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3950 icon_view->priv->scroll_to_path = NULL;
3953 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3955 icon_view->priv->scroll_to_use_align = use_align;
3956 icon_view->priv->scroll_to_row_align = row_align;
3957 icon_view->priv->scroll_to_col_align = col_align;
3964 GtkAllocation allocation;
3967 GdkRectangle item_area =
3969 item->cell_area.x - icon_view->priv->item_padding,
3970 item->cell_area.y - icon_view->priv->item_padding,
3971 item->cell_area.width + icon_view->priv->item_padding * 2,
3972 item->cell_area.height + icon_view->priv->item_padding * 2
3975 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3977 gtk_widget_get_allocation (widget, &allocation);
3979 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
3981 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3982 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
3984 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
3986 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3987 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
3989 gtk_adjustment_changed (icon_view->priv->hadjustment);
3990 gtk_adjustment_changed (icon_view->priv->vadjustment);
3993 gtk_icon_view_scroll_to_item (icon_view, item);
3998 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
3999 GtkIconViewItem *item)
4001 GtkIconViewPrivate *priv = icon_view->priv;
4002 GtkWidget *widget = GTK_WIDGET (icon_view);
4003 GtkAdjustment *hadj, *vadj;
4004 GtkAllocation allocation;
4006 GdkRectangle item_area;
4008 item_area.x = item->cell_area.x - priv->item_padding;
4009 item_area.y = item->cell_area.y - priv->item_padding;
4010 item_area.width = item->cell_area.width + priv->item_padding * 2;
4011 item_area.height = item->cell_area.height + priv->item_padding * 2;
4013 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4014 gtk_widget_get_allocation (widget, &allocation);
4016 hadj = icon_view->priv->hadjustment;
4017 vadj = icon_view->priv->vadjustment;
4019 if (y + item_area.y < 0)
4020 gtk_adjustment_set_value (vadj,
4021 gtk_adjustment_get_value (vadj)
4023 else if (y + item_area.y + item_area.height > allocation.height)
4024 gtk_adjustment_set_value (vadj,
4025 gtk_adjustment_get_value (vadj)
4026 + y + item_area.y + item_area.height - allocation.height);
4028 if (x + item_area.x < 0)
4029 gtk_adjustment_set_value (hadj,
4030 gtk_adjustment_get_value (hadj)
4032 else if (x + item_area.x + item_area.width > allocation.width)
4033 gtk_adjustment_set_value (hadj,
4034 gtk_adjustment_get_value (hadj)
4035 + x + item_area.x + item_area.width - allocation.width);
4037 gtk_adjustment_changed (hadj);
4038 gtk_adjustment_changed (vadj);
4041 /* GtkCellLayout implementation */
4044 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4045 GtkCellArea *cell_area)
4047 GtkIconViewPrivate *priv = icon_view->priv;
4049 if (priv->cell_area)
4053 priv->cell_area = cell_area;
4055 priv->cell_area = gtk_cell_area_box_new ();
4057 g_object_ref_sink (priv->cell_area);
4059 if (GTK_IS_ORIENTABLE (priv->cell_area))
4060 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4062 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4064 priv->add_editable_id =
4065 g_signal_connect (priv->cell_area, "add-editable",
4066 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4067 priv->remove_editable_id =
4068 g_signal_connect (priv->cell_area, "remove-editable",
4069 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4070 priv->context_changed_id =
4071 g_signal_connect (priv->cell_area_context, "notify",
4072 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4074 update_text_cell (icon_view);
4075 update_pixbuf_cell (icon_view);
4078 static GtkCellArea *
4079 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4081 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4082 GtkIconViewPrivate *priv = icon_view->priv;
4084 if (G_UNLIKELY (!priv->cell_area))
4085 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4087 return icon_view->priv->cell_area;
4091 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4092 GtkIconViewItem *item)
4094 gboolean iters_persist;
4097 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4103 path = gtk_tree_path_new_from_indices (item->index, -1);
4104 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4106 gtk_tree_path_free (path);
4111 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4112 icon_view->priv->model,
4113 &iter, FALSE, FALSE);
4122 * gtk_icon_view_new:
4124 * Creates a new #GtkIconView widget
4126 * Return value: A newly created #GtkIconView widget
4131 gtk_icon_view_new (void)
4133 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4137 * gtk_icon_view_new_with_area:
4138 * @area: the #GtkCellArea to use to layout cells
4140 * Creates a new #GtkIconView widget using the
4141 * specified @area to layout cells inside the icons.
4143 * Return value: A newly created #GtkIconView widget
4148 gtk_icon_view_new_with_area (GtkCellArea *area)
4150 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4154 * gtk_icon_view_new_with_model:
4155 * @model: The model.
4157 * Creates a new #GtkIconView widget with the model @model.
4159 * Return value: A newly created #GtkIconView widget.
4164 gtk_icon_view_new_with_model (GtkTreeModel *model)
4166 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4170 * gtk_icon_view_convert_widget_to_bin_window_coords:
4171 * @icon_view: a #GtkIconView
4172 * @wx: X coordinate relative to the widget
4173 * @wy: Y coordinate relative to the widget
4174 * @bx: (out): return location for bin_window X coordinate
4175 * @by: (out): return location for bin_window Y coordinate
4177 * Converts widget coordinates to coordinates for the bin_window,
4178 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4183 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4191 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4193 if (icon_view->priv->bin_window)
4194 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4205 * gtk_icon_view_get_path_at_pos:
4206 * @icon_view: A #GtkIconView.
4207 * @x: The x position to be identified
4208 * @y: The y position to be identified
4210 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4211 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4212 * the cell at the specified position.
4213 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4214 * widget coordinates to bin_window coordinates.
4216 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4217 * if no icon exists at that position.
4222 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4226 GtkIconViewItem *item;
4229 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4231 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4236 path = gtk_tree_path_new_from_indices (item->index, -1);
4242 * gtk_icon_view_get_item_at_pos:
4243 * @icon_view: A #GtkIconView.
4244 * @x: The x position to be identified
4245 * @y: The y position to be identified
4246 * @path: (out) (allow-none): Return location for the path, or %NULL
4247 * @cell: (out) (allow-none): Return location for the renderer
4248 * responsible for the cell at (@x, @y), or %NULL
4250 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4251 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4252 * obtains the cell at the specified position. The returned path should
4253 * be freed with gtk_tree_path_free().
4254 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4255 * widget coordinates to bin_window coordinates.
4257 * Return value: %TRUE if an item exists at the specified position
4262 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4266 GtkCellRenderer **cell)
4268 GtkIconViewItem *item;
4269 GtkCellRenderer *renderer = NULL;
4271 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4273 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4278 *path = gtk_tree_path_new_from_indices (item->index, -1);
4286 return (item != NULL);
4290 * gtk_icon_view_set_tooltip_item:
4291 * @icon_view: a #GtkIconView
4292 * @tooltip: a #GtkTooltip
4293 * @path: a #GtkTreePath
4295 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4296 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4297 * See also gtk_tooltip_set_tip_area().
4302 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4303 GtkTooltip *tooltip,
4306 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4307 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4309 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4313 * gtk_icon_view_set_tooltip_cell:
4314 * @icon_view: a #GtkIconView
4315 * @tooltip: a #GtkTooltip
4316 * @path: a #GtkTreePath
4317 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4319 * Sets the tip area of @tooltip to the area which @cell occupies in
4320 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4322 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4327 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4328 GtkTooltip *tooltip,
4330 GtkCellRenderer *cell)
4333 GtkIconViewItem *item = NULL;
4336 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4337 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4338 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4340 if (gtk_tree_path_get_depth (path) > 0)
4341 item = g_list_nth_data (icon_view->priv->items,
4342 gtk_tree_path_get_indices(path)[0]);
4349 GtkCellAreaContext *context;
4351 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4352 _gtk_icon_view_set_cell_data (icon_view, item);
4353 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4354 GTK_WIDGET (icon_view),
4355 cell, (GdkRectangle *)item, &rect);
4359 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4360 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4361 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4362 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4365 if (icon_view->priv->bin_window)
4367 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4372 gtk_tooltip_set_tip_area (tooltip, &rect);
4377 * gtk_icon_view_get_tooltip_context:
4378 * @icon_view: an #GtkIconView
4379 * @x: (inout): the x coordinate (relative to widget coordinates)
4380 * @y: (inout): the y coordinate (relative to widget coordinates)
4381 * @keyboard_tip: whether this is a keyboard tooltip or not
4382 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4383 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4384 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4386 * This function is supposed to be used in a #GtkWidget::query-tooltip
4387 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4388 * which are received in the signal handler, should be passed to this
4389 * function without modification.
4391 * The return value indicates whether there is an icon view item at the given
4392 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4393 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4394 * @model, @path and @iter which have been provided will be set to point to
4395 * that row and the corresponding model. @x and @y will always be converted
4396 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4398 * Return value: whether or not the given tooltip context points to a item
4403 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4406 gboolean keyboard_tip,
4407 GtkTreeModel **model,
4411 GtkTreePath *tmppath = NULL;
4413 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4414 g_return_val_if_fail (x != NULL, FALSE);
4415 g_return_val_if_fail (y != NULL, FALSE);
4419 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4426 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4429 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4434 *model = gtk_icon_view_get_model (icon_view);
4437 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4443 gtk_tree_path_free (tmppath);
4449 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4452 gboolean keyboard_tip,
4453 GtkTooltip *tooltip,
4459 GtkTreeModel *model;
4460 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4462 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4465 &model, &path, &iter))
4468 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4472 gtk_tree_path_free (path);
4476 gtk_tooltip_set_markup (tooltip, str);
4477 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4479 gtk_tree_path_free (path);
4487 * gtk_icon_view_set_tooltip_column:
4488 * @icon_view: a #GtkIconView
4489 * @column: an integer, which is a valid column number for @icon_view's model
4491 * If you only plan to have simple (text-only) tooltips on full items, you
4492 * can use this function to have #GtkIconView handle these automatically
4493 * for you. @column should be set to the column in @icon_view's model
4494 * containing the tooltip texts, or -1 to disable this feature.
4496 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4497 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4499 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4500 * so &, <, etc have to be escaped in the text.
4505 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4508 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4510 if (column == icon_view->priv->tooltip_column)
4515 g_signal_handlers_disconnect_by_func (icon_view,
4516 gtk_icon_view_set_tooltip_query_cb,
4518 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4522 if (icon_view->priv->tooltip_column == -1)
4524 g_signal_connect (icon_view, "query-tooltip",
4525 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4526 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4530 icon_view->priv->tooltip_column = column;
4531 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4535 * gtk_icon_view_get_tooltip_column:
4536 * @icon_view: a #GtkIconView
4538 * Returns the column of @icon_view's model which is being used for
4539 * displaying tooltips on @icon_view's rows.
4541 * Return value: the index of the tooltip column that is currently being
4542 * used, or -1 if this is disabled.
4547 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4549 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4551 return icon_view->priv->tooltip_column;
4555 * gtk_icon_view_get_visible_range:
4556 * @icon_view: A #GtkIconView
4557 * @start_path: (out) (allow-none): Return location for start of region,
4559 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4561 * Sets @start_path and @end_path to be the first and last visible path.
4562 * Note that there may be invisible paths in between.
4564 * Both paths should be freed with gtk_tree_path_free() after use.
4566 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4571 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4572 GtkTreePath **start_path,
4573 GtkTreePath **end_path)
4575 gint start_index = -1;
4576 gint end_index = -1;
4579 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4581 if (icon_view->priv->hadjustment == NULL ||
4582 icon_view->priv->vadjustment == NULL)
4585 if (start_path == NULL && end_path == NULL)
4588 for (icons = icon_view->priv->items; icons; icons = icons->next)
4590 GtkIconViewItem *item = icons->data;
4591 GdkRectangle *item_area = (GdkRectangle *)item;
4593 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4594 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4596 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4597 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4599 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4600 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4602 if (start_index == -1)
4603 start_index = item->index;
4604 end_index = item->index;
4608 if (start_path && start_index != -1)
4609 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4610 if (end_path && end_index != -1)
4611 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4613 return start_index != -1;
4617 * gtk_icon_view_selected_foreach:
4618 * @icon_view: A #GtkIconView.
4619 * @func: (scope call): The function to call for each selected icon.
4620 * @data: User data to pass to the function.
4622 * Calls a function for each selected icon. Note that the model or
4623 * selection cannot be modified from within this function.
4628 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4629 GtkIconViewForeachFunc func,
4634 for (list = icon_view->priv->items; list; list = list->next)
4636 GtkIconViewItem *item = list->data;
4637 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4640 (* func) (icon_view, path, data);
4642 gtk_tree_path_free (path);
4647 * gtk_icon_view_set_selection_mode:
4648 * @icon_view: A #GtkIconView.
4649 * @mode: The selection mode
4651 * Sets the selection mode of the @icon_view.
4656 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4657 GtkSelectionMode mode)
4659 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4661 if (mode == icon_view->priv->selection_mode)
4664 if (mode == GTK_SELECTION_NONE ||
4665 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4666 gtk_icon_view_unselect_all (icon_view);
4668 icon_view->priv->selection_mode = mode;
4670 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4674 * gtk_icon_view_get_selection_mode:
4675 * @icon_view: A #GtkIconView.
4677 * Gets the selection mode of the @icon_view.
4679 * Return value: the current selection mode
4684 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4686 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4688 return icon_view->priv->selection_mode;
4692 * gtk_icon_view_set_model:
4693 * @icon_view: A #GtkIconView.
4694 * @model: (allow-none): The model.
4696 * Sets the model for a #GtkIconView.
4697 * If the @icon_view already has a model set, it will remove
4698 * it before setting the new model. If @model is %NULL, then
4699 * it will unset the old model.
4704 gtk_icon_view_set_model (GtkIconView *icon_view,
4705 GtkTreeModel *model)
4707 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4708 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4710 if (icon_view->priv->model == model)
4713 if (icon_view->priv->scroll_to_path)
4715 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4716 icon_view->priv->scroll_to_path = NULL;
4719 /* The area can be NULL while disposing */
4720 if (icon_view->priv->cell_area)
4721 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4727 if (icon_view->priv->pixbuf_column != -1)
4729 column_type = gtk_tree_model_get_column_type (model,
4730 icon_view->priv->pixbuf_column);
4732 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4735 if (icon_view->priv->text_column != -1)
4737 column_type = gtk_tree_model_get_column_type (model,
4738 icon_view->priv->text_column);
4740 g_return_if_fail (column_type == G_TYPE_STRING);
4743 if (icon_view->priv->markup_column != -1)
4745 column_type = gtk_tree_model_get_column_type (model,
4746 icon_view->priv->markup_column);
4748 g_return_if_fail (column_type == G_TYPE_STRING);
4753 if (icon_view->priv->model)
4755 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4756 gtk_icon_view_row_changed,
4758 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4759 gtk_icon_view_row_inserted,
4761 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4762 gtk_icon_view_row_deleted,
4764 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4765 gtk_icon_view_rows_reordered,
4768 g_object_unref (icon_view->priv->model);
4770 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4771 icon_view->priv->items = NULL;
4772 icon_view->priv->anchor_item = NULL;
4773 icon_view->priv->cursor_item = NULL;
4774 icon_view->priv->last_single_clicked = NULL;
4775 icon_view->priv->last_prelight = NULL;
4776 icon_view->priv->width = 0;
4777 icon_view->priv->height = 0;
4780 icon_view->priv->model = model;
4782 if (icon_view->priv->model)
4784 g_object_ref (icon_view->priv->model);
4785 g_signal_connect (icon_view->priv->model,
4787 G_CALLBACK (gtk_icon_view_row_changed),
4789 g_signal_connect (icon_view->priv->model,
4791 G_CALLBACK (gtk_icon_view_row_inserted),
4793 g_signal_connect (icon_view->priv->model,
4795 G_CALLBACK (gtk_icon_view_row_deleted),
4797 g_signal_connect (icon_view->priv->model,
4799 G_CALLBACK (gtk_icon_view_rows_reordered),
4802 gtk_icon_view_build_items (icon_view);
4804 gtk_icon_view_layout (icon_view);
4807 g_object_notify (G_OBJECT (icon_view), "model");
4809 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4810 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4814 * gtk_icon_view_get_model:
4815 * @icon_view: a #GtkIconView
4817 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4820 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4821 * currently being used.
4826 gtk_icon_view_get_model (GtkIconView *icon_view)
4828 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4830 return icon_view->priv->model;
4834 update_text_cell (GtkIconView *icon_view)
4836 if (!icon_view->priv->cell_area)
4839 if (icon_view->priv->text_column == -1 &&
4840 icon_view->priv->markup_column == -1)
4842 if (icon_view->priv->text_cell != NULL)
4844 gtk_cell_area_remove (icon_view->priv->cell_area,
4845 icon_view->priv->text_cell);
4846 icon_view->priv->text_cell = NULL;
4851 if (icon_view->priv->text_cell == NULL)
4853 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4855 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4858 if (icon_view->priv->markup_column != -1)
4859 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4860 icon_view->priv->text_cell,
4861 "markup", icon_view->priv->markup_column,
4864 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4865 icon_view->priv->text_cell,
4866 "text", icon_view->priv->text_column,
4869 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4870 g_object_set (icon_view->priv->text_cell,
4871 "alignment", PANGO_ALIGN_CENTER,
4872 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4877 g_object_set (icon_view->priv->text_cell,
4878 "alignment", PANGO_ALIGN_LEFT,
4879 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4887 update_pixbuf_cell (GtkIconView *icon_view)
4889 if (!icon_view->priv->cell_area)
4892 if (icon_view->priv->pixbuf_column == -1)
4894 if (icon_view->priv->pixbuf_cell != NULL)
4896 gtk_cell_area_remove (icon_view->priv->cell_area,
4897 icon_view->priv->pixbuf_cell);
4899 icon_view->priv->pixbuf_cell = NULL;
4904 if (icon_view->priv->pixbuf_cell == NULL)
4906 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4908 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4911 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4912 icon_view->priv->pixbuf_cell,
4913 "pixbuf", icon_view->priv->pixbuf_column,
4916 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4917 g_object_set (icon_view->priv->pixbuf_cell,
4922 g_object_set (icon_view->priv->pixbuf_cell,
4930 * gtk_icon_view_set_text_column:
4931 * @icon_view: A #GtkIconView.
4932 * @column: A column in the currently used model, or -1 to display no text
4934 * Sets the column with text for @icon_view to be @column. The text
4935 * column must be of type #G_TYPE_STRING.
4940 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4943 if (column == icon_view->priv->text_column)
4947 icon_view->priv->text_column = -1;
4950 if (icon_view->priv->model != NULL)
4954 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4956 g_return_if_fail (column_type == G_TYPE_STRING);
4959 icon_view->priv->text_column = column;
4962 if (icon_view->priv->cell_area)
4963 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4965 update_text_cell (icon_view);
4967 gtk_icon_view_invalidate_sizes (icon_view);
4969 g_object_notify (G_OBJECT (icon_view), "text-column");
4973 * gtk_icon_view_get_text_column:
4974 * @icon_view: A #GtkIconView.
4976 * Returns the column with text for @icon_view.
4978 * Returns: the text column, or -1 if it's unset.
4983 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4985 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4987 return icon_view->priv->text_column;
4991 * gtk_icon_view_set_markup_column:
4992 * @icon_view: A #GtkIconView.
4993 * @column: A column in the currently used model, or -1 to display no text
4995 * Sets the column with markup information for @icon_view to be
4996 * @column. The markup column must be of type #G_TYPE_STRING.
4997 * If the markup column is set to something, it overrides
4998 * the text column set by gtk_icon_view_set_text_column().
5003 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5006 if (column == icon_view->priv->markup_column)
5010 icon_view->priv->markup_column = -1;
5013 if (icon_view->priv->model != NULL)
5017 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5019 g_return_if_fail (column_type == G_TYPE_STRING);
5022 icon_view->priv->markup_column = column;
5025 if (icon_view->priv->cell_area)
5026 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5028 update_text_cell (icon_view);
5030 gtk_icon_view_invalidate_sizes (icon_view);
5032 g_object_notify (G_OBJECT (icon_view), "markup-column");
5036 * gtk_icon_view_get_markup_column:
5037 * @icon_view: A #GtkIconView.
5039 * Returns the column with markup text for @icon_view.
5041 * Returns: the markup column, or -1 if it's unset.
5046 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5048 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5050 return icon_view->priv->markup_column;
5054 * gtk_icon_view_set_pixbuf_column:
5055 * @icon_view: A #GtkIconView.
5056 * @column: A column in the currently used model, or -1 to disable
5058 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5059 * column must be of type #GDK_TYPE_PIXBUF
5064 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5067 if (column == icon_view->priv->pixbuf_column)
5071 icon_view->priv->pixbuf_column = -1;
5074 if (icon_view->priv->model != NULL)
5078 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5080 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5083 icon_view->priv->pixbuf_column = column;
5086 if (icon_view->priv->cell_area)
5087 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5089 update_pixbuf_cell (icon_view);
5091 gtk_icon_view_invalidate_sizes (icon_view);
5093 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5098 * gtk_icon_view_get_pixbuf_column:
5099 * @icon_view: A #GtkIconView.
5101 * Returns the column with pixbufs for @icon_view.
5103 * Returns: the pixbuf column, or -1 if it's unset.
5108 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5110 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5112 return icon_view->priv->pixbuf_column;
5116 * gtk_icon_view_select_path:
5117 * @icon_view: A #GtkIconView.
5118 * @path: The #GtkTreePath to be selected.
5120 * Selects the row at @path.
5125 gtk_icon_view_select_path (GtkIconView *icon_view,
5128 GtkIconViewItem *item = NULL;
5130 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5131 g_return_if_fail (icon_view->priv->model != NULL);
5132 g_return_if_fail (path != NULL);
5134 if (gtk_tree_path_get_depth (path) > 0)
5135 item = g_list_nth_data (icon_view->priv->items,
5136 gtk_tree_path_get_indices(path)[0]);
5139 _gtk_icon_view_select_item (icon_view, item);
5143 * gtk_icon_view_unselect_path:
5144 * @icon_view: A #GtkIconView.
5145 * @path: The #GtkTreePath to be unselected.
5147 * Unselects the row at @path.
5152 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5155 GtkIconViewItem *item;
5157 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5158 g_return_if_fail (icon_view->priv->model != NULL);
5159 g_return_if_fail (path != NULL);
5161 item = g_list_nth_data (icon_view->priv->items,
5162 gtk_tree_path_get_indices(path)[0]);
5167 _gtk_icon_view_unselect_item (icon_view, item);
5171 * gtk_icon_view_get_selected_items:
5172 * @icon_view: A #GtkIconView.
5174 * Creates a list of paths of all selected items. Additionally, if you are
5175 * planning on modifying the model after calling this function, you may
5176 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5177 * To do this, you can use gtk_tree_row_reference_new().
5179 * To free the return value, use:
5181 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5184 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5189 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5192 GList *selected = NULL;
5194 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5196 for (list = icon_view->priv->items; list != NULL; list = list->next)
5198 GtkIconViewItem *item = list->data;
5202 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5204 selected = g_list_prepend (selected, path);
5212 * gtk_icon_view_select_all:
5213 * @icon_view: A #GtkIconView.
5215 * Selects all the icons. @icon_view must has its selection mode set
5216 * to #GTK_SELECTION_MULTIPLE.
5221 gtk_icon_view_select_all (GtkIconView *icon_view)
5224 gboolean dirty = FALSE;
5226 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5228 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5231 for (items = icon_view->priv->items; items; items = items->next)
5233 GtkIconViewItem *item = items->data;
5235 if (!item->selected)
5238 item->selected = TRUE;
5239 gtk_icon_view_queue_draw_item (icon_view, item);
5244 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5248 * gtk_icon_view_unselect_all:
5249 * @icon_view: A #GtkIconView.
5251 * Unselects all the icons.
5256 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5258 gboolean dirty = FALSE;
5260 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5262 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5265 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5268 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5272 * gtk_icon_view_path_is_selected:
5273 * @icon_view: A #GtkIconView.
5274 * @path: A #GtkTreePath to check selection on.
5276 * Returns %TRUE if the icon pointed to by @path is currently
5277 * selected. If @path does not point to a valid location, %FALSE is returned.
5279 * Return value: %TRUE if @path is selected.
5284 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5287 GtkIconViewItem *item;
5289 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5290 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5291 g_return_val_if_fail (path != NULL, FALSE);
5293 item = g_list_nth_data (icon_view->priv->items,
5294 gtk_tree_path_get_indices(path)[0]);
5299 return item->selected;
5303 * gtk_icon_view_get_item_row:
5304 * @icon_view: a #GtkIconView
5305 * @path: the #GtkTreePath of the item
5307 * Gets the row in which the item @path is currently
5308 * displayed. Row numbers start at 0.
5310 * Returns: The row in which the item is displayed
5315 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5318 GtkIconViewItem *item;
5320 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5321 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5322 g_return_val_if_fail (path != NULL, -1);
5324 item = g_list_nth_data (icon_view->priv->items,
5325 gtk_tree_path_get_indices(path)[0]);
5334 * gtk_icon_view_get_item_column:
5335 * @icon_view: a #GtkIconView
5336 * @path: the #GtkTreePath of the item
5338 * Gets the column in which the item @path is currently
5339 * displayed. Column numbers start at 0.
5341 * Returns: The column in which the item is displayed
5346 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5349 GtkIconViewItem *item;
5351 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5352 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5353 g_return_val_if_fail (path != NULL, -1);
5355 item = g_list_nth_data (icon_view->priv->items,
5356 gtk_tree_path_get_indices(path)[0]);
5365 * gtk_icon_view_item_activated:
5366 * @icon_view: A #GtkIconView
5367 * @path: The #GtkTreePath to be activated
5369 * Activates the item determined by @path.
5374 gtk_icon_view_item_activated (GtkIconView *icon_view,
5377 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5378 g_return_if_fail (path != NULL);
5380 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5384 * gtk_icon_view_set_item_orientation:
5385 * @icon_view: a #GtkIconView
5386 * @orientation: the relative position of texts and icons
5388 * Sets the ::item-orientation property which determines whether the labels
5389 * are drawn beside the icons instead of below.
5394 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5395 GtkOrientation orientation)
5397 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5399 if (icon_view->priv->item_orientation != orientation)
5401 icon_view->priv->item_orientation = orientation;
5403 if (icon_view->priv->cell_area)
5405 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5406 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5407 icon_view->priv->item_orientation);
5409 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5412 gtk_icon_view_invalidate_sizes (icon_view);
5414 update_text_cell (icon_view);
5415 update_pixbuf_cell (icon_view);
5417 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5422 * gtk_icon_view_get_item_orientation:
5423 * @icon_view: a #GtkIconView
5425 * Returns the value of the ::item-orientation property which determines
5426 * whether the labels are drawn beside the icons instead of below.
5428 * Return value: the relative position of texts and icons
5433 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5435 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5436 GTK_ORIENTATION_VERTICAL);
5438 return icon_view->priv->item_orientation;
5442 * gtk_icon_view_set_columns:
5443 * @icon_view: a #GtkIconView
5444 * @columns: the number of columns
5446 * Sets the ::columns property which determines in how
5447 * many columns the icons are arranged. If @columns is
5448 * -1, the number of columns will be chosen automatically
5449 * to fill the available area.
5454 gtk_icon_view_set_columns (GtkIconView *icon_view,
5457 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5459 if (icon_view->priv->columns != columns)
5461 icon_view->priv->columns = columns;
5463 if (icon_view->priv->cell_area)
5464 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5466 gtk_icon_view_queue_layout (icon_view);
5468 g_object_notify (G_OBJECT (icon_view), "columns");
5473 * gtk_icon_view_get_columns:
5474 * @icon_view: a #GtkIconView
5476 * Returns the value of the ::columns property.
5478 * Return value: the number of columns, or -1
5483 gtk_icon_view_get_columns (GtkIconView *icon_view)
5485 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5487 return icon_view->priv->columns;
5491 * gtk_icon_view_set_item_width:
5492 * @icon_view: a #GtkIconView
5493 * @item_width: the width for each item
5495 * Sets the ::item-width property which specifies the width
5496 * to use for each item. If it is set to -1, the icon view will
5497 * automatically determine a suitable item size.
5502 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5505 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5507 if (icon_view->priv->item_width != item_width)
5509 icon_view->priv->item_width = item_width;
5511 if (icon_view->priv->cell_area)
5512 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5514 gtk_icon_view_invalidate_sizes (icon_view);
5516 update_text_cell (icon_view);
5518 g_object_notify (G_OBJECT (icon_view), "item-width");
5523 * gtk_icon_view_get_item_width:
5524 * @icon_view: a #GtkIconView
5526 * Returns the value of the ::item-width property.
5528 * Return value: the width of a single item, or -1
5533 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5535 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5537 return icon_view->priv->item_width;
5542 * gtk_icon_view_set_spacing:
5543 * @icon_view: a #GtkIconView
5544 * @spacing: the spacing
5546 * Sets the ::spacing property which specifies the space
5547 * which is inserted between the cells (i.e. the icon and
5548 * the text) of an item.
5553 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5556 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5558 if (icon_view->priv->spacing != spacing)
5560 icon_view->priv->spacing = spacing;
5562 if (icon_view->priv->cell_area)
5563 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5565 gtk_icon_view_invalidate_sizes (icon_view);
5567 g_object_notify (G_OBJECT (icon_view), "spacing");
5572 * gtk_icon_view_get_spacing:
5573 * @icon_view: a #GtkIconView
5575 * Returns the value of the ::spacing property.
5577 * Return value: the space between cells
5582 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5584 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5586 return icon_view->priv->spacing;
5590 * gtk_icon_view_set_row_spacing:
5591 * @icon_view: a #GtkIconView
5592 * @row_spacing: the row spacing
5594 * Sets the ::row-spacing property which specifies the space
5595 * which is inserted between the rows of the icon view.
5600 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5603 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5605 if (icon_view->priv->row_spacing != row_spacing)
5607 icon_view->priv->row_spacing = row_spacing;
5609 if (icon_view->priv->cell_area)
5610 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5612 gtk_icon_view_invalidate_sizes (icon_view);
5614 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5619 * gtk_icon_view_get_row_spacing:
5620 * @icon_view: a #GtkIconView
5622 * Returns the value of the ::row-spacing property.
5624 * Return value: the space between rows
5629 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5631 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5633 return icon_view->priv->row_spacing;
5637 * gtk_icon_view_set_column_spacing:
5638 * @icon_view: a #GtkIconView
5639 * @column_spacing: the column spacing
5641 * Sets the ::column-spacing property which specifies the space
5642 * which is inserted between the columns of the icon view.
5647 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5648 gint column_spacing)
5650 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5652 if (icon_view->priv->column_spacing != column_spacing)
5654 icon_view->priv->column_spacing = column_spacing;
5656 if (icon_view->priv->cell_area)
5657 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5659 gtk_icon_view_invalidate_sizes (icon_view);
5661 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5666 * gtk_icon_view_get_column_spacing:
5667 * @icon_view: a #GtkIconView
5669 * Returns the value of the ::column-spacing property.
5671 * Return value: the space between columns
5676 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5678 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5680 return icon_view->priv->column_spacing;
5684 * gtk_icon_view_set_margin:
5685 * @icon_view: a #GtkIconView
5686 * @margin: the margin
5688 * Sets the ::margin property which specifies the space
5689 * which is inserted at the top, bottom, left and right
5695 gtk_icon_view_set_margin (GtkIconView *icon_view,
5698 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5700 if (icon_view->priv->margin != margin)
5702 icon_view->priv->margin = margin;
5704 if (icon_view->priv->cell_area)
5705 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5707 gtk_icon_view_invalidate_sizes (icon_view);
5709 g_object_notify (G_OBJECT (icon_view), "margin");
5714 * gtk_icon_view_get_margin:
5715 * @icon_view: a #GtkIconView
5717 * Returns the value of the ::margin property.
5719 * Return value: the space at the borders
5724 gtk_icon_view_get_margin (GtkIconView *icon_view)
5726 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5728 return icon_view->priv->margin;
5732 * gtk_icon_view_set_item_padding:
5733 * @icon_view: a #GtkIconView
5734 * @item_padding: the item padding
5736 * Sets the #GtkIconView:item-padding property which specifies the padding
5737 * around each of the icon view's items.
5742 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5745 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5747 if (icon_view->priv->item_padding != item_padding)
5749 icon_view->priv->item_padding = item_padding;
5751 if (icon_view->priv->cell_area)
5752 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5754 gtk_icon_view_invalidate_sizes (icon_view);
5756 g_object_notify (G_OBJECT (icon_view), "item-padding");
5761 * gtk_icon_view_get_item_padding:
5762 * @icon_view: a #GtkIconView
5764 * Returns the value of the ::item-padding property.
5766 * Return value: the padding around items
5771 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5773 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5775 return icon_view->priv->item_padding;
5778 /* Get/set whether drag_motion requested the drag data and
5779 * drag_data_received should thus not actually insert the data,
5780 * since the data doesn't result from a drop.
5783 set_status_pending (GdkDragContext *context,
5784 GdkDragAction suggested_action)
5786 g_object_set_data (G_OBJECT (context),
5787 I_("gtk-icon-view-status-pending"),
5788 GINT_TO_POINTER (suggested_action));
5791 static GdkDragAction
5792 get_status_pending (GdkDragContext *context)
5794 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5795 "gtk-icon-view-status-pending"));
5799 unset_reorderable (GtkIconView *icon_view)
5801 if (icon_view->priv->reorderable)
5803 icon_view->priv->reorderable = FALSE;
5804 g_object_notify (G_OBJECT (icon_view), "reorderable");
5809 set_source_row (GdkDragContext *context,
5810 GtkTreeModel *model,
5811 GtkTreePath *source_row)
5814 g_object_set_data_full (G_OBJECT (context),
5815 I_("gtk-icon-view-source-row"),
5816 gtk_tree_row_reference_new (model, source_row),
5817 (GDestroyNotify) gtk_tree_row_reference_free);
5819 g_object_set_data_full (G_OBJECT (context),
5820 I_("gtk-icon-view-source-row"),
5825 get_source_row (GdkDragContext *context)
5827 GtkTreeRowReference *ref;
5829 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5832 return gtk_tree_row_reference_get_path (ref);
5839 GtkTreeRowReference *dest_row;
5840 gboolean empty_view_drop;
5841 gboolean drop_append_mode;
5845 dest_row_free (gpointer data)
5847 DestRow *dr = (DestRow *)data;
5849 gtk_tree_row_reference_free (dr->dest_row);
5854 set_dest_row (GdkDragContext *context,
5855 GtkTreeModel *model,
5856 GtkTreePath *dest_row,
5857 gboolean empty_view_drop,
5858 gboolean drop_append_mode)
5864 g_object_set_data_full (G_OBJECT (context),
5865 I_("gtk-icon-view-dest-row"),
5870 dr = g_new0 (DestRow, 1);
5872 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5873 dr->empty_view_drop = empty_view_drop;
5874 dr->drop_append_mode = drop_append_mode;
5875 g_object_set_data_full (G_OBJECT (context),
5876 I_("gtk-icon-view-dest-row"),
5877 dr, (GDestroyNotify) dest_row_free);
5881 get_dest_row (GdkDragContext *context)
5885 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5889 GtkTreePath *path = NULL;
5892 path = gtk_tree_row_reference_get_path (dr->dest_row);
5893 else if (dr->empty_view_drop)
5894 path = gtk_tree_path_new_from_indices (0, -1);
5898 if (path && dr->drop_append_mode)
5899 gtk_tree_path_next (path);
5908 check_model_dnd (GtkTreeModel *model,
5909 GType required_iface,
5910 const gchar *signal)
5912 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5914 g_warning ("You must override the default '%s' handler "
5915 "on GtkIconView when using models that don't support "
5916 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5917 "is to connect to '%s' and call "
5918 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5919 "the default handler from running. Look at the source code "
5920 "for the default handler in gtkiconview.c to get an idea what "
5921 "your handler should do. (gtkiconview.c is in the GTK+ source "
5922 "code.) If you're using GTK+ from a language other than C, "
5923 "there may be a more natural way to override default handlers, e.g. via derivation.",
5924 signal, g_type_name (required_iface), signal);
5932 remove_scroll_timeout (GtkIconView *icon_view)
5934 if (icon_view->priv->scroll_timeout_id != 0)
5936 g_source_remove (icon_view->priv->scroll_timeout_id);
5938 icon_view->priv->scroll_timeout_id = 0;
5943 gtk_icon_view_autoscroll (GtkIconView *icon_view,
5947 gint px, py, x, y, width, height;
5948 gint hoffset, voffset;
5950 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5952 gdk_window_get_device_position (window, device, &px, &py, NULL);
5953 gdk_window_get_geometry (window, &x, &y, &width, &height);
5955 /* see if we are near the edge. */
5956 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5958 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5960 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5962 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5965 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5966 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5969 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5970 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5974 GtkIconView *icon_view;
5979 drag_scroll_timeout (gpointer datap)
5981 DragScrollData *data = datap;
5983 gtk_icon_view_autoscroll (data->icon_view, data->device);
5989 drag_scroll_data_free (DragScrollData *data)
5991 g_slice_free (DragScrollData, data);
5995 set_destination (GtkIconView *icon_view,
5996 GdkDragContext *context,
5999 GdkDragAction *suggested_action,
6003 GtkTreePath *path = NULL;
6004 GtkIconViewDropPosition pos;
6005 GtkIconViewDropPosition old_pos;
6006 GtkTreePath *old_dest_path = NULL;
6007 gboolean can_drop = FALSE;
6009 widget = GTK_WIDGET (icon_view);
6011 *suggested_action = 0;
6014 if (!icon_view->priv->dest_set)
6016 /* someone unset us as a drag dest, note that if
6017 * we return FALSE drag_leave isn't called
6020 gtk_icon_view_set_drag_dest_item (icon_view,
6022 GTK_ICON_VIEW_DROP_LEFT);
6024 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6026 return FALSE; /* no longer a drop site */
6029 *target = gtk_drag_dest_find_target (widget, context,
6030 gtk_drag_dest_get_target_list (widget));
6031 if (*target == GDK_NONE)
6034 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6037 GtkTreeModel *model;
6039 /* the row got dropped on empty space, let's setup a special case
6043 gtk_tree_path_free (path);
6045 model = gtk_icon_view_get_model (icon_view);
6047 n_children = gtk_tree_model_iter_n_children (model, NULL);
6050 pos = GTK_ICON_VIEW_DROP_BELOW;
6051 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6055 pos = GTK_ICON_VIEW_DROP_ABOVE;
6056 path = gtk_tree_path_new_from_indices (0, -1);
6066 gtk_icon_view_get_drag_dest_item (icon_view,
6071 gtk_tree_path_free (old_dest_path);
6073 if (TRUE /* FIXME if the location droppable predicate */)
6081 GtkWidget *source_widget;
6083 *suggested_action = gdk_drag_context_get_suggested_action (context);
6084 source_widget = gtk_drag_get_source_widget (context);
6086 if (source_widget == widget)
6088 /* Default to MOVE, unless the user has
6089 * pressed ctrl or shift to affect available actions
6091 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6092 *suggested_action = GDK_ACTION_MOVE;
6095 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6100 /* can't drop here */
6101 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6103 GTK_ICON_VIEW_DROP_LEFT);
6107 gtk_tree_path_free (path);
6113 get_logical_destination (GtkIconView *icon_view,
6114 gboolean *drop_append_mode)
6116 /* adjust path to point to the row the drop goes in front of */
6117 GtkTreePath *path = NULL;
6118 GtkIconViewDropPosition pos;
6120 *drop_append_mode = FALSE;
6122 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6127 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6128 pos == GTK_ICON_VIEW_DROP_BELOW)
6131 GtkTreeModel *model = icon_view->priv->model;
6133 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6134 !gtk_tree_model_iter_next (model, &iter))
6135 *drop_append_mode = TRUE;
6138 *drop_append_mode = FALSE;
6139 gtk_tree_path_next (path);
6147 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6148 GdkEventMotion *event)
6150 GtkWidget *widget = GTK_WIDGET (icon_view);
6151 GdkDragContext *context;
6152 GtkTreePath *path = NULL;
6154 GtkTreeModel *model;
6155 gboolean retval = FALSE;
6157 if (!icon_view->priv->source_set)
6160 if (icon_view->priv->pressed_button < 0)
6163 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6164 icon_view->priv->press_start_x,
6165 icon_view->priv->press_start_y,
6166 event->x, event->y))
6169 model = gtk_icon_view_get_model (icon_view);
6174 button = icon_view->priv->pressed_button;
6175 icon_view->priv->pressed_button = -1;
6177 path = gtk_icon_view_get_path_at_pos (icon_view,
6178 icon_view->priv->press_start_x,
6179 icon_view->priv->press_start_y);
6184 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6185 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6189 /* FIXME Check whether we're a start button, if not return FALSE and
6193 /* Now we can begin the drag */
6197 context = gtk_drag_begin (widget,
6198 gtk_drag_source_get_target_list (widget),
6199 icon_view->priv->source_actions,
6203 set_source_row (context, model, path);
6207 gtk_tree_path_free (path);
6212 /* Source side drag signals */
6214 gtk_icon_view_drag_begin (GtkWidget *widget,
6215 GdkDragContext *context)
6217 GtkIconView *icon_view;
6218 GtkIconViewItem *item;
6219 cairo_surface_t *icon;
6223 icon_view = GTK_ICON_VIEW (widget);
6225 /* if the user uses a custom DnD impl, we don't set the icon here */
6226 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6229 item = _gtk_icon_view_get_item_at_coords (icon_view,
6230 icon_view->priv->press_start_x,
6231 icon_view->priv->press_start_y,
6235 g_return_if_fail (item != NULL);
6237 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6238 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6240 path = gtk_tree_path_new_from_indices (item->index, -1);
6241 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6242 gtk_tree_path_free (path);
6244 cairo_surface_set_device_offset (icon, -x, -y);
6246 gtk_drag_set_icon_surface (context, icon);
6248 cairo_surface_destroy (icon);
6252 gtk_icon_view_drag_end (GtkWidget *widget,
6253 GdkDragContext *context)
6259 gtk_icon_view_drag_data_get (GtkWidget *widget,
6260 GdkDragContext *context,
6261 GtkSelectionData *selection_data,
6265 GtkIconView *icon_view;
6266 GtkTreeModel *model;
6267 GtkTreePath *source_row;
6269 icon_view = GTK_ICON_VIEW (widget);
6270 model = gtk_icon_view_get_model (icon_view);
6275 if (!icon_view->priv->source_set)
6278 source_row = get_source_row (context);
6280 if (source_row == NULL)
6283 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6284 * any model; for DragSource models there are some other targets
6288 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6289 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6294 /* If drag_data_get does nothing, try providing row data. */
6295 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6296 gtk_tree_set_row_drag_data (selection_data,
6301 gtk_tree_path_free (source_row);
6305 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6306 GdkDragContext *context)
6308 GtkTreeModel *model;
6309 GtkIconView *icon_view;
6310 GtkTreePath *source_row;
6312 icon_view = GTK_ICON_VIEW (widget);
6313 model = gtk_icon_view_get_model (icon_view);
6315 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6318 if (!icon_view->priv->source_set)
6321 source_row = get_source_row (context);
6323 if (source_row == NULL)
6326 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6329 gtk_tree_path_free (source_row);
6331 set_source_row (context, NULL, NULL);
6334 /* Target side drag signals */
6336 gtk_icon_view_drag_leave (GtkWidget *widget,
6337 GdkDragContext *context,
6340 GtkIconView *icon_view;
6342 icon_view = GTK_ICON_VIEW (widget);
6344 /* unset any highlight row */
6345 gtk_icon_view_set_drag_dest_item (icon_view,
6347 GTK_ICON_VIEW_DROP_LEFT);
6349 remove_scroll_timeout (icon_view);
6353 gtk_icon_view_drag_motion (GtkWidget *widget,
6354 GdkDragContext *context,
6359 GtkTreePath *path = NULL;
6360 GtkIconViewDropPosition pos;
6361 GtkIconView *icon_view;
6362 GdkDragAction suggested_action = 0;
6366 icon_view = GTK_ICON_VIEW (widget);
6368 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6371 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6373 /* we only know this *after* set_desination_row */
6374 empty = icon_view->priv->empty_view_drop;
6376 if (path == NULL && !empty)
6378 /* Can't drop here. */
6379 gdk_drag_status (context, 0, time);
6383 if (icon_view->priv->scroll_timeout_id == 0)
6385 DragScrollData *data = g_slice_new (DragScrollData);
6386 data->icon_view = icon_view;
6387 data->device = gdk_drag_context_get_device (context);
6389 icon_view->priv->scroll_timeout_id =
6390 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6393 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6395 /* Request data so we can use the source row when
6396 * determining whether to accept the drop
6398 set_status_pending (context, suggested_action);
6399 gtk_drag_get_data (widget, context, target, time);
6403 set_status_pending (context, 0);
6404 gdk_drag_status (context, suggested_action, time);
6409 gtk_tree_path_free (path);
6415 gtk_icon_view_drag_drop (GtkWidget *widget,
6416 GdkDragContext *context,
6421 GtkIconView *icon_view;
6423 GdkDragAction suggested_action = 0;
6424 GdkAtom target = GDK_NONE;
6425 GtkTreeModel *model;
6426 gboolean drop_append_mode;
6428 icon_view = GTK_ICON_VIEW (widget);
6429 model = gtk_icon_view_get_model (icon_view);
6431 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6433 if (!icon_view->priv->dest_set)
6436 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6439 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6442 path = get_logical_destination (icon_view, &drop_append_mode);
6444 if (target != GDK_NONE && path != NULL)
6446 /* in case a motion had requested drag data, change things so we
6447 * treat drag data receives as a drop.
6449 set_status_pending (context, 0);
6450 set_dest_row (context, model, path,
6451 icon_view->priv->empty_view_drop, drop_append_mode);
6455 gtk_tree_path_free (path);
6457 /* Unset this thing */
6458 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6460 if (target != GDK_NONE)
6462 gtk_drag_get_data (widget, context, target, time);
6470 gtk_icon_view_drag_data_received (GtkWidget *widget,
6471 GdkDragContext *context,
6474 GtkSelectionData *selection_data,
6479 gboolean accepted = FALSE;
6480 GtkTreeModel *model;
6481 GtkIconView *icon_view;
6482 GtkTreePath *dest_row;
6483 GdkDragAction suggested_action;
6484 gboolean drop_append_mode;
6486 icon_view = GTK_ICON_VIEW (widget);
6487 model = gtk_icon_view_get_model (icon_view);
6489 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6492 if (!icon_view->priv->dest_set)
6495 suggested_action = get_status_pending (context);
6497 if (suggested_action)
6499 /* We are getting this data due to a request in drag_motion,
6500 * rather than due to a request in drag_drop, so we are just
6501 * supposed to call drag_status, not actually paste in the
6504 path = get_logical_destination (icon_view, &drop_append_mode);
6507 suggested_action = 0;
6509 if (suggested_action)
6511 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6514 suggested_action = 0;
6517 gdk_drag_status (context, suggested_action, time);
6520 gtk_tree_path_free (path);
6522 /* If you can't drop, remove user drop indicator until the next motion */
6523 if (suggested_action == 0)
6524 gtk_icon_view_set_drag_dest_item (icon_view,
6526 GTK_ICON_VIEW_DROP_LEFT);
6531 dest_row = get_dest_row (context);
6533 if (dest_row == NULL)
6536 if (gtk_selection_data_get_length (selection_data) >= 0)
6538 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6544 gtk_drag_finish (context,
6546 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6549 gtk_tree_path_free (dest_row);
6552 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6555 /* Drag-and-Drop support */
6557 * gtk_icon_view_enable_model_drag_source:
6558 * @icon_view: a #GtkIconTreeView
6559 * @start_button_mask: Mask of allowed buttons to start drag
6560 * @targets: (array length=n_targets): the table of targets that the drag will
6562 * @n_targets: the number of items in @targets
6563 * @actions: the bitmask of possible actions for a drag from this
6566 * Turns @icon_view into a drag source for automatic DND. Calling this
6567 * method sets #GtkIconView:reorderable to %FALSE.
6572 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6573 GdkModifierType start_button_mask,
6574 const GtkTargetEntry *targets,
6576 GdkDragAction actions)
6578 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6580 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6582 icon_view->priv->start_button_mask = start_button_mask;
6583 icon_view->priv->source_actions = actions;
6585 icon_view->priv->source_set = TRUE;
6587 unset_reorderable (icon_view);
6591 * gtk_icon_view_enable_model_drag_dest:
6592 * @icon_view: a #GtkIconView
6593 * @targets: (array length=n_targets): the table of targets that the drag will
6595 * @n_targets: the number of items in @targets
6596 * @actions: the bitmask of possible actions for a drag to this
6599 * Turns @icon_view into a drop destination for automatic DND. Calling this
6600 * method sets #GtkIconView:reorderable to %FALSE.
6605 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6606 const GtkTargetEntry *targets,
6608 GdkDragAction actions)
6610 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6612 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6614 icon_view->priv->dest_actions = actions;
6616 icon_view->priv->dest_set = TRUE;
6618 unset_reorderable (icon_view);
6622 * gtk_icon_view_unset_model_drag_source:
6623 * @icon_view: a #GtkIconView
6625 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6626 * method sets #GtkIconView:reorderable to %FALSE.
6631 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6633 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6635 if (icon_view->priv->source_set)
6637 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6638 icon_view->priv->source_set = FALSE;
6641 unset_reorderable (icon_view);
6645 * gtk_icon_view_unset_model_drag_dest:
6646 * @icon_view: a #GtkIconView
6648 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6649 * method sets #GtkIconView:reorderable to %FALSE.
6654 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6656 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6658 if (icon_view->priv->dest_set)
6660 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6661 icon_view->priv->dest_set = FALSE;
6664 unset_reorderable (icon_view);
6667 /* These are useful to implement your own custom stuff. */
6669 * gtk_icon_view_set_drag_dest_item:
6670 * @icon_view: a #GtkIconView
6671 * @path: (allow-none): The path of the item to highlight, or %NULL.
6672 * @pos: Specifies where to drop, relative to the item
6674 * Sets the item that is highlighted for feedback.
6679 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6681 GtkIconViewDropPosition pos)
6683 /* Note; this function is exported to allow a custom DND
6684 * implementation, so it can't touch TreeViewDragInfo
6687 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6689 if (icon_view->priv->dest_item)
6691 GtkTreePath *current_path;
6692 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6693 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6694 icon_view->priv->dest_item = NULL;
6696 gtk_icon_view_queue_draw_path (icon_view, current_path);
6697 gtk_tree_path_free (current_path);
6700 /* special case a drop on an empty model */
6701 icon_view->priv->empty_view_drop = FALSE;
6702 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6703 && gtk_tree_path_get_depth (path) == 1
6704 && gtk_tree_path_get_indices (path)[0] == 0)
6708 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6711 if (n_children == 0)
6712 icon_view->priv->empty_view_drop = TRUE;
6715 icon_view->priv->dest_pos = pos;
6719 icon_view->priv->dest_item =
6720 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6721 icon_view->priv->model, path);
6723 gtk_icon_view_queue_draw_path (icon_view, path);
6728 * gtk_icon_view_get_drag_dest_item:
6729 * @icon_view: a #GtkIconView
6730 * @path: (out) (allow-none): Return location for the path of
6731 * the highlighted item, or %NULL.
6732 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6734 * Gets information about the item that is highlighted for feedback.
6739 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6741 GtkIconViewDropPosition *pos)
6743 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6747 if (icon_view->priv->dest_item)
6748 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6754 *pos = icon_view->priv->dest_pos;
6758 * gtk_icon_view_get_dest_item_at_pos:
6759 * @icon_view: a #GtkIconView
6760 * @drag_x: the position to determine the destination item for
6761 * @drag_y: the position to determine the destination item for
6762 * @path: (out) (allow-none): Return location for the path of the item,
6764 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6766 * Determines the destination item for a given position.
6768 * Return value: whether there is an item at the given position.
6773 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6777 GtkIconViewDropPosition *pos)
6779 GtkIconViewItem *item;
6781 /* Note; this function is exported to allow a custom DND
6782 * implementation, so it can't touch TreeViewDragInfo
6785 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6786 g_return_val_if_fail (drag_x >= 0, FALSE);
6787 g_return_val_if_fail (drag_y >= 0, FALSE);
6788 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6794 item = _gtk_icon_view_get_item_at_coords (icon_view,
6795 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6796 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6803 *path = gtk_tree_path_new_from_indices (item->index, -1);
6807 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6808 *pos = GTK_ICON_VIEW_DROP_LEFT;
6809 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6810 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6811 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6812 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6813 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6814 *pos = GTK_ICON_VIEW_DROP_BELOW;
6816 *pos = GTK_ICON_VIEW_DROP_INTO;
6823 * gtk_icon_view_create_drag_icon:
6824 * @icon_view: a #GtkIconView
6825 * @path: a #GtkTreePath in @icon_view
6827 * Creates a #cairo_surface_t representation of the item at @path.
6828 * This image is used for a drag icon.
6830 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6835 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6839 GtkStyleContext *context;
6841 cairo_surface_t *surface;
6845 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6846 g_return_val_if_fail (path != NULL, NULL);
6848 widget = GTK_WIDGET (icon_view);
6849 context = gtk_widget_get_style_context (widget);
6851 if (!gtk_widget_get_realized (widget))
6854 index = gtk_tree_path_get_indices (path)[0];
6856 for (l = icon_view->priv->items; l; l = l->next)
6858 GtkIconViewItem *item = l->data;
6860 if (index == item->index)
6862 GdkRectangle rect = {
6863 item->cell_area.x - icon_view->priv->item_padding,
6864 item->cell_area.y - icon_view->priv->item_padding,
6865 item->cell_area.width + icon_view->priv->item_padding * 2,
6866 item->cell_area.height + icon_view->priv->item_padding * 2
6869 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6870 CAIRO_CONTENT_COLOR,
6874 cr = cairo_create (surface);
6875 cairo_set_line_width (cr, 1.);
6877 gtk_render_background (context, cr, 0, 0,
6878 rect.width + 2, rect.height + 2);
6882 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6885 gtk_icon_view_paint_item (icon_view, cr, item,
6886 icon_view->priv->item_padding + 1,
6887 icon_view->priv->item_padding + 1, FALSE);
6891 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6892 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6905 * gtk_icon_view_get_reorderable:
6906 * @icon_view: a #GtkIconView
6908 * Retrieves whether the user can reorder the list via drag-and-drop.
6909 * See gtk_icon_view_set_reorderable().
6911 * Return value: %TRUE if the list can be reordered.
6916 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6918 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6920 return icon_view->priv->reorderable;
6923 static const GtkTargetEntry item_targets[] = {
6924 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6929 * gtk_icon_view_set_reorderable:
6930 * @icon_view: A #GtkIconView.
6931 * @reorderable: %TRUE, if the list of items can be reordered.
6933 * This function is a convenience function to allow you to reorder models that
6934 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6935 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6936 * the user can reorder the model by dragging and dropping rows. The
6937 * developer can listen to these changes by connecting to the model's
6938 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6939 * the icon view as a drag source and destination. Therefore, drag and
6940 * drop can not be used in a reorderable view for any other purpose.
6942 * This function does not give you any degree of control over the order -- any
6943 * reordering is allowed. If more control is needed, you should probably
6944 * handle drag and drop manually.
6949 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6950 gboolean reorderable)
6952 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6954 reorderable = reorderable != FALSE;
6956 if (icon_view->priv->reorderable == reorderable)
6961 gtk_icon_view_enable_model_drag_source (icon_view,
6964 G_N_ELEMENTS (item_targets),
6966 gtk_icon_view_enable_model_drag_dest (icon_view,
6968 G_N_ELEMENTS (item_targets),
6973 gtk_icon_view_unset_model_drag_source (icon_view);
6974 gtk_icon_view_unset_model_drag_dest (icon_view);
6977 icon_view->priv->reorderable = reorderable;
6979 g_object_notify (G_OBJECT (icon_view), "reorderable");
6983 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
6984 GtkBuilder *builder,
6986 const gchar *tagname,
6987 GMarkupParser *parser,
6990 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
6991 tagname, parser, data))
6994 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
6995 tagname, parser, data);
6999 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7000 GtkBuilder *builder,
7002 const gchar *tagname,
7005 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7006 child, tagname, data))
7007 parent_buildable_iface->custom_tag_end (buildable, builder,
7008 child, tagname, data);