2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 #include "gtkiconview.h"
23 #include "gtkiconviewprivate.h"
25 #include "gtkadjustment.h"
26 #include "gtkcelllayout.h"
27 #include "gtkcellrenderer.h"
28 #include "gtkcellareabox.h"
29 #include "gtkcellareacontext.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkorientable.h"
33 #include "gtkmarshalers.h"
34 #include "gtkbindings.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtkscrollable.h"
43 #include "gtksizerequest.h"
44 #include "gtktreednd.h"
45 #include "gtktypebuiltins.h"
46 #include "gtkprivate.h"
47 #include "a11y/gtkiconviewaccessible.h"
52 * @short_description: A widget which displays a list of icons in a grid
54 * #GtkIconView provides an alternative view on a #GtkTreeModel.
55 * It displays the model as a grid of icons with labels. Like
56 * #GtkTreeView, it allows to select one or multiple items
57 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
58 * In addition to selection with the arrow keys, #GtkIconView supports
59 * rubberband selection, which is controlled by dragging the pointer.
61 * Note that if the tree model is backed by an actual tree store (as
62 * opposed to a flat list where the mapping to icons is obvious),
63 * #GtkIconView will only display the first level of the tree and
64 * ignore the tree's branches.
67 #define SCROLL_EDGE_SIZE 15
69 typedef struct _GtkIconViewChild GtkIconViewChild;
70 struct _GtkIconViewChild
98 PROP_ITEM_ORIENTATION,
111 /* For scrollable interface */
119 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
120 static void gtk_icon_view_dispose (GObject *object);
121 static GObject *gtk_icon_view_constructor (GType type,
122 guint n_construct_properties,
123 GObjectConstructParam *construct_properties);
124 static void gtk_icon_view_set_property (GObject *object,
128 static void gtk_icon_view_get_property (GObject *object,
132 /* GtkWidget vfuncs */
133 static void gtk_icon_view_destroy (GtkWidget *widget);
134 static void gtk_icon_view_realize (GtkWidget *widget);
135 static void gtk_icon_view_unrealize (GtkWidget *widget);
136 static void gtk_icon_view_style_updated (GtkWidget *widget);
137 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
138 GtkStateFlags previous_state);
139 static GtkSizeRequestMode gtk_icon_view_get_request_mode (GtkWidget *widget);
140 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
143 static void gtk_icon_view_get_preferred_width_for_height
148 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
151 static void gtk_icon_view_get_preferred_height_for_width
156 static void gtk_icon_view_size_allocate (GtkWidget *widget,
157 GtkAllocation *allocation);
158 static gboolean gtk_icon_view_draw (GtkWidget *widget,
160 static gboolean gtk_icon_view_motion (GtkWidget *widget,
161 GdkEventMotion *event);
162 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
163 GdkEventButton *event);
164 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
165 GdkEventButton *event);
166 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
168 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
172 /* GtkContainer vfuncs */
173 static void gtk_icon_view_remove (GtkContainer *container,
175 static void gtk_icon_view_forall (GtkContainer *container,
176 gboolean include_internals,
177 GtkCallback callback,
178 gpointer callback_data);
180 /* GtkIconView vfuncs */
181 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
182 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
183 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
184 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
185 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
187 /* Internal functions */
188 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
189 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
190 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
191 GtkAdjustment *adjustment);
192 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
193 GtkAdjustment *adjustment);
194 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
195 GtkIconView *icon_view);
196 static void gtk_icon_view_layout (GtkIconView *icon_view);
197 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
199 GtkIconViewItem *item,
202 gboolean draw_focus);
203 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
205 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
207 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
208 GtkIconViewItem *item);
209 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
213 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
214 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
215 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
216 GtkIconViewItem *item,
221 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
222 static void gtk_icon_view_update_rubberband (gpointer data);
223 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
224 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
225 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
228 GtkMovementStep step,
230 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
231 GtkMovementStep step,
233 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
235 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
237 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
239 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
241 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
242 GtkIconViewItem *item);
243 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
244 GtkIconViewItem *anchor,
245 GtkIconViewItem *cursor);
247 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
248 GtkCellArea *cell_area);
250 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
252 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
253 GtkIconViewItem *item);
255 static void gtk_icon_view_add_editable (GtkCellArea *area,
256 GtkCellRenderer *renderer,
257 GtkCellEditable *editable,
258 GdkRectangle *cell_area,
260 GtkIconView *icon_view);
261 static void gtk_icon_view_remove_editable (GtkCellArea *area,
262 GtkCellRenderer *renderer,
263 GtkCellEditable *editable,
264 GtkIconView *icon_view);
265 static void update_text_cell (GtkIconView *icon_view);
266 static void update_pixbuf_cell (GtkIconView *icon_view);
268 /* Source side drag signals */
269 static void gtk_icon_view_drag_begin (GtkWidget *widget,
270 GdkDragContext *context);
271 static void gtk_icon_view_drag_end (GtkWidget *widget,
272 GdkDragContext *context);
273 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
274 GdkDragContext *context,
275 GtkSelectionData *selection_data,
278 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
279 GdkDragContext *context);
281 /* Target side drag signals */
282 static void gtk_icon_view_drag_leave (GtkWidget *widget,
283 GdkDragContext *context,
285 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
286 GdkDragContext *context,
290 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
291 GdkDragContext *context,
295 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
296 GdkDragContext *context,
299 GtkSelectionData *selection_data,
302 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
303 GdkEventMotion *event);
305 static void remove_scroll_timeout (GtkIconView *icon_view);
308 static GtkBuildableIface *parent_buildable_iface;
309 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
310 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
313 const gchar *tagname,
314 GMarkupParser *parser,
316 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
319 const gchar *tagname,
322 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
324 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
325 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
326 gtk_icon_view_cell_layout_init)
327 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
328 gtk_icon_view_buildable_init)
329 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
332 gtk_icon_view_class_init (GtkIconViewClass *klass)
334 GObjectClass *gobject_class;
335 GtkWidgetClass *widget_class;
336 GtkContainerClass *container_class;
337 GtkBindingSet *binding_set;
339 binding_set = gtk_binding_set_by_class (klass);
341 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
343 gobject_class = (GObjectClass *) klass;
344 widget_class = (GtkWidgetClass *) klass;
345 container_class = (GtkContainerClass *) klass;
347 gobject_class->constructor = gtk_icon_view_constructor;
348 gobject_class->dispose = gtk_icon_view_dispose;
349 gobject_class->set_property = gtk_icon_view_set_property;
350 gobject_class->get_property = gtk_icon_view_get_property;
352 widget_class->destroy = gtk_icon_view_destroy;
353 widget_class->realize = gtk_icon_view_realize;
354 widget_class->unrealize = gtk_icon_view_unrealize;
355 widget_class->style_updated = gtk_icon_view_style_updated;
356 widget_class->get_request_mode = gtk_icon_view_get_request_mode;
357 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
358 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
359 widget_class->get_preferred_width_for_height = gtk_icon_view_get_preferred_width_for_height;
360 widget_class->get_preferred_height_for_width = gtk_icon_view_get_preferred_height_for_width;
361 widget_class->size_allocate = gtk_icon_view_size_allocate;
362 widget_class->draw = gtk_icon_view_draw;
363 widget_class->motion_notify_event = gtk_icon_view_motion;
364 widget_class->button_press_event = gtk_icon_view_button_press;
365 widget_class->button_release_event = gtk_icon_view_button_release;
366 widget_class->key_press_event = gtk_icon_view_key_press;
367 widget_class->key_release_event = gtk_icon_view_key_release;
368 widget_class->drag_begin = gtk_icon_view_drag_begin;
369 widget_class->drag_end = gtk_icon_view_drag_end;
370 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
371 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
372 widget_class->drag_leave = gtk_icon_view_drag_leave;
373 widget_class->drag_motion = gtk_icon_view_drag_motion;
374 widget_class->drag_drop = gtk_icon_view_drag_drop;
375 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
376 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
378 container_class->remove = gtk_icon_view_remove;
379 container_class->forall = gtk_icon_view_forall;
381 klass->select_all = gtk_icon_view_real_select_all;
382 klass->unselect_all = gtk_icon_view_real_unselect_all;
383 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
384 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
385 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
386 klass->move_cursor = gtk_icon_view_real_move_cursor;
390 * GtkIconView:selection-mode:
392 * The ::selection-mode property specifies the selection mode of
393 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
394 * is enabled, for the other modes, only keyboard selection is possible.
398 g_object_class_install_property (gobject_class,
400 g_param_spec_enum ("selection-mode",
401 P_("Selection mode"),
402 P_("The selection mode"),
403 GTK_TYPE_SELECTION_MODE,
404 GTK_SELECTION_SINGLE,
405 GTK_PARAM_READWRITE));
408 * GtkIconView:pixbuf-column:
410 * The ::pixbuf-column property contains the number of the model column
411 * containing the pixbufs which are displayed. The pixbuf column must be
412 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
413 * display of pixbufs.
417 g_object_class_install_property (gobject_class,
419 g_param_spec_int ("pixbuf-column",
421 P_("Model column used to retrieve the icon pixbuf from"),
423 GTK_PARAM_READWRITE));
426 * GtkIconView:text-column:
428 * The ::text-column property contains the number of the model column
429 * containing the texts which are displayed. The text column must be
430 * of type #G_TYPE_STRING. If this property and the :markup-column
431 * property are both set to -1, no texts are displayed.
435 g_object_class_install_property (gobject_class,
437 g_param_spec_int ("text-column",
439 P_("Model column used to retrieve the text from"),
441 GTK_PARAM_READWRITE));
445 * GtkIconView:markup-column:
447 * The ::markup-column property contains the number of the model column
448 * containing markup information to be displayed. The markup column must be
449 * of type #G_TYPE_STRING. If this property and the :text-column property
450 * are both set to column numbers, it overrides the text column.
451 * If both are set to -1, no texts are displayed.
455 g_object_class_install_property (gobject_class,
457 g_param_spec_int ("markup-column",
459 P_("Model column used to retrieve the text if using Pango markup"),
461 GTK_PARAM_READWRITE));
463 g_object_class_install_property (gobject_class,
465 g_param_spec_object ("model",
466 P_("Icon View Model"),
467 P_("The model for the icon view"),
469 GTK_PARAM_READWRITE));
472 * GtkIconView:columns:
474 * The columns property contains the number of the columns in which the
475 * items should be displayed. If it is -1, the number of columns will
476 * be chosen automatically to fill the available area.
480 g_object_class_install_property (gobject_class,
482 g_param_spec_int ("columns",
483 P_("Number of columns"),
484 P_("Number of columns to display"),
486 GTK_PARAM_READWRITE));
490 * GtkIconView:item-width:
492 * The item-width property specifies the width to use for each item.
493 * If it is set to -1, the icon view will automatically determine a
494 * suitable item size.
498 g_object_class_install_property (gobject_class,
500 g_param_spec_int ("item-width",
501 P_("Width for each item"),
502 P_("The width used for each item"),
504 GTK_PARAM_READWRITE));
507 * GtkIconView:spacing:
509 * The spacing property specifies the space which is inserted between
510 * the cells (i.e. the icon and the text) of an item.
514 g_object_class_install_property (gobject_class,
516 g_param_spec_int ("spacing",
518 P_("Space which is inserted between cells of an item"),
520 GTK_PARAM_READWRITE));
523 * GtkIconView:row-spacing:
525 * The row-spacing property specifies the space which is inserted between
526 * the rows of the icon view.
530 g_object_class_install_property (gobject_class,
532 g_param_spec_int ("row-spacing",
534 P_("Space which is inserted between grid rows"),
536 GTK_PARAM_READWRITE));
539 * GtkIconView:column-spacing:
541 * The column-spacing property specifies the space which is inserted between
542 * the columns of the icon view.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_int ("column-spacing",
549 P_("Column Spacing"),
550 P_("Space which is inserted between grid columns"),
552 GTK_PARAM_READWRITE));
555 * GtkIconView:margin:
557 * The margin property specifies the space which is inserted
558 * at the edges of the icon view.
562 g_object_class_install_property (gobject_class,
564 g_param_spec_int ("margin",
566 P_("Space which is inserted at the edges of the icon view"),
568 GTK_PARAM_READWRITE));
571 * GtkIconView:item-orientation:
573 * The item-orientation property specifies how the cells (i.e. the icon and
574 * the text) of the item are positioned relative to each other.
578 g_object_class_install_property (gobject_class,
579 PROP_ITEM_ORIENTATION,
580 g_param_spec_enum ("item-orientation",
581 P_("Item Orientation"),
582 P_("How the text and icon of each item are positioned relative to each other"),
583 GTK_TYPE_ORIENTATION,
584 GTK_ORIENTATION_VERTICAL,
585 GTK_PARAM_READWRITE));
588 * GtkIconView:reorderable:
590 * The reorderable property specifies if the items can be reordered
595 g_object_class_install_property (gobject_class,
597 g_param_spec_boolean ("reorderable",
599 P_("View is reorderable"),
603 g_object_class_install_property (gobject_class,
605 g_param_spec_int ("tooltip-column",
606 P_("Tooltip Column"),
607 P_("The column in the model containing the tooltip texts for the items"),
611 GTK_PARAM_READWRITE));
614 * GtkIconView:item-padding:
616 * The item-padding property specifies the padding around each
617 * of the icon view's item.
621 g_object_class_install_property (gobject_class,
623 g_param_spec_int ("item-padding",
625 P_("Padding around icon view items"),
627 GTK_PARAM_READWRITE));
630 * GtkIconView:cell-area:
632 * The #GtkCellArea used to layout cell renderers for this view.
634 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
635 * a #GtkCellAreaBox will be used.
639 g_object_class_install_property (gobject_class,
641 g_param_spec_object ("cell-area",
643 P_("The GtkCellArea used to layout cells"),
645 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
647 /* Scrollable interface properties */
648 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
649 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
650 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
651 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
653 /* Style properties */
654 gtk_widget_class_install_style_property (widget_class,
655 g_param_spec_boxed ("selection-box-color",
656 P_("Selection Box Color"),
657 P_("Color of the selection box"),
659 GTK_PARAM_READABLE));
661 gtk_widget_class_install_style_property (widget_class,
662 g_param_spec_uchar ("selection-box-alpha",
663 P_("Selection Box Alpha"),
664 P_("Opacity of the selection box"),
667 GTK_PARAM_READABLE));
671 * GtkIconView::item-activated:
672 * @iconview: the object on which the signal is emitted
673 * @path: the #GtkTreePath for the activated item
675 * The ::item-activated signal is emitted when the method
676 * gtk_icon_view_item_activated() is called or the user double
677 * clicks an item. It is also emitted when a non-editable item
678 * is selected and one of the keys: Space, Return or Enter is
681 icon_view_signals[ITEM_ACTIVATED] =
682 g_signal_new (I_("item-activated"),
683 G_TYPE_FROM_CLASS (gobject_class),
685 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
687 g_cclosure_marshal_VOID__BOXED,
692 * GtkIconView::selection-changed:
693 * @iconview: the object on which the signal is emitted
695 * The ::selection-changed signal is emitted when the selection
696 * (i.e. the set of selected items) changes.
698 icon_view_signals[SELECTION_CHANGED] =
699 g_signal_new (I_("selection-changed"),
700 G_TYPE_FROM_CLASS (gobject_class),
702 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
704 g_cclosure_marshal_VOID__VOID,
708 * GtkIconView::select-all:
709 * @iconview: the object on which the signal is emitted
711 * A <link linkend="keybinding-signals">keybinding signal</link>
712 * which gets emitted when the user selects all items.
714 * Applications should not connect to it, but may emit it with
715 * g_signal_emit_by_name() if they need to control selection
718 * The default binding for this signal is Ctrl-a.
720 icon_view_signals[SELECT_ALL] =
721 g_signal_new (I_("select-all"),
722 G_TYPE_FROM_CLASS (gobject_class),
723 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
724 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
726 g_cclosure_marshal_VOID__VOID,
730 * GtkIconView::unselect-all:
731 * @iconview: the object on which the signal is emitted
733 * A <link linkend="keybinding-signals">keybinding signal</link>
734 * which gets emitted when the user unselects all items.
736 * Applications should not connect to it, but may emit it with
737 * g_signal_emit_by_name() if they need to control selection
740 * The default binding for this signal is Ctrl-Shift-a.
742 icon_view_signals[UNSELECT_ALL] =
743 g_signal_new (I_("unselect-all"),
744 G_TYPE_FROM_CLASS (gobject_class),
745 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
746 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
748 g_cclosure_marshal_VOID__VOID,
752 * GtkIconView::select-cursor-item:
753 * @iconview: the object on which the signal is emitted
755 * A <link linkend="keybinding-signals">keybinding signal</link>
756 * which gets emitted when the user selects the item that is currently
759 * Applications should not connect to it, but may emit it with
760 * g_signal_emit_by_name() if they need to control selection
763 * There is no default binding for this signal.
765 icon_view_signals[SELECT_CURSOR_ITEM] =
766 g_signal_new (I_("select-cursor-item"),
767 G_TYPE_FROM_CLASS (gobject_class),
768 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
769 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
771 g_cclosure_marshal_VOID__VOID,
775 * GtkIconView::toggle-cursor-item:
776 * @iconview: the object on which the signal is emitted
778 * A <link linkend="keybinding-signals">keybinding signal</link>
779 * which gets emitted when the user toggles whether the currently
780 * focused item is selected or not. The exact effect of this
781 * depend on the selection mode.
783 * Applications should not connect to it, but may emit it with
784 * g_signal_emit_by_name() if they need to control selection
787 * There is no default binding for this signal is Ctrl-Space.
789 icon_view_signals[TOGGLE_CURSOR_ITEM] =
790 g_signal_new (I_("toggle-cursor-item"),
791 G_TYPE_FROM_CLASS (gobject_class),
792 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
793 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
795 g_cclosure_marshal_VOID__VOID,
799 * GtkIconView::activate-cursor-item:
800 * @iconview: the object on which the signal is emitted
802 * A <link linkend="keybinding-signals">keybinding signal</link>
803 * which gets emitted when the user activates the currently
806 * Applications should not connect to it, but may emit it with
807 * g_signal_emit_by_name() if they need to control activation
810 * The default bindings for this signal are Space, Return and Enter.
812 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
813 g_signal_new (I_("activate-cursor-item"),
814 G_TYPE_FROM_CLASS (gobject_class),
815 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
816 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
818 _gtk_marshal_BOOLEAN__VOID,
822 * GtkIconView::move-cursor:
823 * @iconview: the object which received the signal
824 * @step: the granularity of the move, as a #GtkMovementStep
825 * @count: the number of @step units to move
827 * The ::move-cursor signal is a
828 * <link linkend="keybinding-signals">keybinding signal</link>
829 * which gets emitted when the user initiates a cursor movement.
831 * Applications should not connect to it, but may emit it with
832 * g_signal_emit_by_name() if they need to control the cursor
835 * The default bindings for this signal include
837 * <listitem>Arrow keys which move by individual steps</listitem>
838 * <listitem>Home/End keys which move to the first/last item</listitem>
839 * <listitem>PageUp/PageDown which move by "pages"</listitem>
842 * All of these will extend the selection when combined with
843 * the Shift modifier.
845 icon_view_signals[MOVE_CURSOR] =
846 g_signal_new (I_("move-cursor"),
847 G_TYPE_FROM_CLASS (gobject_class),
848 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
849 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
851 _gtk_marshal_BOOLEAN__ENUM_INT,
853 GTK_TYPE_MOVEMENT_STEP,
857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
862 "toggle-cursor-item", 0);
863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
864 "toggle-cursor-item", 0);
866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
867 "activate-cursor-item", 0);
868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
869 "activate-cursor-item", 0);
870 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
871 "activate-cursor-item", 0);
872 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
873 "activate-cursor-item", 0);
874 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
875 "activate-cursor-item", 0);
877 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
878 GTK_MOVEMENT_DISPLAY_LINES, -1);
879 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
880 GTK_MOVEMENT_DISPLAY_LINES, -1);
882 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
883 GTK_MOVEMENT_DISPLAY_LINES, 1);
884 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
885 GTK_MOVEMENT_DISPLAY_LINES, 1);
887 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
888 GTK_MOVEMENT_DISPLAY_LINES, -1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
891 GTK_MOVEMENT_DISPLAY_LINES, 1);
893 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
894 GTK_MOVEMENT_BUFFER_ENDS, -1);
895 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
896 GTK_MOVEMENT_BUFFER_ENDS, -1);
898 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
899 GTK_MOVEMENT_BUFFER_ENDS, 1);
900 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
901 GTK_MOVEMENT_BUFFER_ENDS, 1);
903 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
904 GTK_MOVEMENT_PAGES, -1);
905 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
906 GTK_MOVEMENT_PAGES, -1);
908 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
909 GTK_MOVEMENT_PAGES, 1);
910 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
911 GTK_MOVEMENT_PAGES, 1);
913 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
914 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
915 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
916 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
918 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
919 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
920 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
921 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
923 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
927 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
929 parent_buildable_iface = g_type_interface_peek_parent (iface);
930 iface->add_child = _gtk_cell_layout_buildable_add_child;
931 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
932 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
936 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
938 iface->get_area = gtk_icon_view_cell_layout_get_area;
942 gtk_icon_view_init (GtkIconView *icon_view)
944 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
948 icon_view->priv->width = 0;
949 icon_view->priv->height = 0;
950 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
951 icon_view->priv->pressed_button = -1;
952 icon_view->priv->press_start_x = -1;
953 icon_view->priv->press_start_y = -1;
954 icon_view->priv->text_column = -1;
955 icon_view->priv->markup_column = -1;
956 icon_view->priv->pixbuf_column = -1;
957 icon_view->priv->text_cell = NULL;
958 icon_view->priv->pixbuf_cell = NULL;
959 icon_view->priv->tooltip_column = -1;
961 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
963 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
965 icon_view->priv->columns = -1;
966 icon_view->priv->item_width = -1;
967 icon_view->priv->spacing = 0;
968 icon_view->priv->row_spacing = 6;
969 icon_view->priv->column_spacing = 6;
970 icon_view->priv->margin = 6;
971 icon_view->priv->item_padding = 6;
973 icon_view->priv->draw_focus = TRUE;
975 icon_view->priv->row_contexts =
976 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
979 /* GObject methods */
981 gtk_icon_view_constructor (GType type,
982 guint n_construct_properties,
983 GObjectConstructParam *construct_properties)
985 GtkIconView *icon_view;
988 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
989 (type, n_construct_properties, construct_properties);
991 icon_view = (GtkIconView *) object;
993 gtk_icon_view_ensure_cell_area (icon_view, NULL);
999 gtk_icon_view_dispose (GObject *object)
1001 GtkIconView *icon_view;
1002 GtkIconViewPrivate *priv;
1004 icon_view = GTK_ICON_VIEW (object);
1005 priv = icon_view->priv;
1007 if (priv->cell_area_context)
1009 g_object_unref (priv->cell_area_context);
1010 priv->cell_area_context = NULL;
1013 if (priv->row_contexts)
1015 g_ptr_array_free (priv->row_contexts, TRUE);
1016 priv->row_contexts = NULL;
1019 if (priv->cell_area)
1021 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1023 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1024 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1025 priv->add_editable_id = 0;
1026 priv->remove_editable_id = 0;
1028 g_object_unref (priv->cell_area);
1029 priv->cell_area = NULL;
1032 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1036 gtk_icon_view_set_property (GObject *object,
1038 const GValue *value,
1041 GtkIconView *icon_view;
1044 icon_view = GTK_ICON_VIEW (object);
1048 case PROP_SELECTION_MODE:
1049 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1051 case PROP_PIXBUF_COLUMN:
1052 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1054 case PROP_TEXT_COLUMN:
1055 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1057 case PROP_MARKUP_COLUMN:
1058 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1061 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1063 case PROP_ITEM_ORIENTATION:
1064 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1067 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1069 case PROP_ITEM_WIDTH:
1070 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1073 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1075 case PROP_ROW_SPACING:
1076 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1078 case PROP_COLUMN_SPACING:
1079 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1082 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1084 case PROP_REORDERABLE:
1085 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1088 case PROP_TOOLTIP_COLUMN:
1089 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1092 case PROP_ITEM_PADDING:
1093 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1096 case PROP_CELL_AREA:
1097 /* Construct-only, can only be assigned once */
1098 area = g_value_get_object (value);
1101 if (icon_view->priv->cell_area != NULL)
1103 g_warning ("cell-area has already been set, ignoring construct property");
1104 g_object_ref_sink (area);
1105 g_object_unref (area);
1108 gtk_icon_view_ensure_cell_area (icon_view, area);
1112 case PROP_HADJUSTMENT:
1113 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1115 case PROP_VADJUSTMENT:
1116 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1118 case PROP_HSCROLL_POLICY:
1119 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1120 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1122 case PROP_VSCROLL_POLICY:
1123 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1124 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1134 gtk_icon_view_get_property (GObject *object,
1139 GtkIconView *icon_view;
1141 icon_view = GTK_ICON_VIEW (object);
1145 case PROP_SELECTION_MODE:
1146 g_value_set_enum (value, icon_view->priv->selection_mode);
1148 case PROP_PIXBUF_COLUMN:
1149 g_value_set_int (value, icon_view->priv->pixbuf_column);
1151 case PROP_TEXT_COLUMN:
1152 g_value_set_int (value, icon_view->priv->text_column);
1154 case PROP_MARKUP_COLUMN:
1155 g_value_set_int (value, icon_view->priv->markup_column);
1158 g_value_set_object (value, icon_view->priv->model);
1160 case PROP_ITEM_ORIENTATION:
1161 g_value_set_enum (value, icon_view->priv->item_orientation);
1164 g_value_set_int (value, icon_view->priv->columns);
1166 case PROP_ITEM_WIDTH:
1167 g_value_set_int (value, icon_view->priv->item_width);
1170 g_value_set_int (value, icon_view->priv->spacing);
1172 case PROP_ROW_SPACING:
1173 g_value_set_int (value, icon_view->priv->row_spacing);
1175 case PROP_COLUMN_SPACING:
1176 g_value_set_int (value, icon_view->priv->column_spacing);
1179 g_value_set_int (value, icon_view->priv->margin);
1181 case PROP_REORDERABLE:
1182 g_value_set_boolean (value, icon_view->priv->reorderable);
1184 case PROP_TOOLTIP_COLUMN:
1185 g_value_set_int (value, icon_view->priv->tooltip_column);
1188 case PROP_ITEM_PADDING:
1189 g_value_set_int (value, icon_view->priv->item_padding);
1192 case PROP_CELL_AREA:
1193 g_value_set_object (value, icon_view->priv->cell_area);
1196 case PROP_HADJUSTMENT:
1197 g_value_set_object (value, icon_view->priv->hadjustment);
1199 case PROP_VADJUSTMENT:
1200 g_value_set_object (value, icon_view->priv->vadjustment);
1202 case PROP_HSCROLL_POLICY:
1203 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1205 case PROP_VSCROLL_POLICY:
1206 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1215 /* GtkWidget methods */
1217 gtk_icon_view_destroy (GtkWidget *widget)
1219 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1221 gtk_icon_view_set_model (icon_view, NULL);
1223 if (icon_view->priv->scroll_to_path != NULL)
1225 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1226 icon_view->priv->scroll_to_path = NULL;
1229 remove_scroll_timeout (icon_view);
1231 if (icon_view->priv->hadjustment != NULL)
1233 g_object_unref (icon_view->priv->hadjustment);
1234 icon_view->priv->hadjustment = NULL;
1237 if (icon_view->priv->vadjustment != NULL)
1239 g_object_unref (icon_view->priv->vadjustment);
1240 icon_view->priv->vadjustment = NULL;
1243 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1247 gtk_icon_view_realize (GtkWidget *widget)
1249 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1250 GtkAllocation allocation;
1252 GdkWindowAttr attributes;
1253 gint attributes_mask;
1254 GtkStyleContext *context;
1256 gtk_widget_set_realized (widget, TRUE);
1258 gtk_widget_get_allocation (widget, &allocation);
1260 /* Make the main, clipping window */
1261 attributes.window_type = GDK_WINDOW_CHILD;
1262 attributes.x = allocation.x;
1263 attributes.y = allocation.y;
1264 attributes.width = allocation.width;
1265 attributes.height = allocation.height;
1266 attributes.wclass = GDK_INPUT_OUTPUT;
1267 attributes.visual = gtk_widget_get_visual (widget);
1268 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1270 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1272 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1273 &attributes, attributes_mask);
1274 gtk_widget_set_window (widget, window);
1275 gdk_window_set_user_data (window, widget);
1277 gtk_widget_get_allocation (widget, &allocation);
1279 /* Make the window for the icon view */
1282 attributes.width = MAX (icon_view->priv->width, allocation.width);
1283 attributes.height = MAX (icon_view->priv->height, allocation.height);
1284 attributes.event_mask = (GDK_EXPOSURE_MASK |
1286 GDK_SMOOTH_SCROLL_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_n_items (GtkIconView *icon_view)
1364 GtkIconViewPrivate *priv = icon_view->priv;
1366 if (priv->model == NULL)
1369 return gtk_tree_model_iter_n_children (priv->model, NULL);
1373 adjust_wrap_width (GtkIconView *icon_view)
1375 if (icon_view->priv->text_cell)
1377 gint wrap_width = 50;
1379 /* Here we go with the same old guess, try the icon size and set double
1380 * the size of the first icon found in the list, naive but works much
1382 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
1384 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
1385 GTK_WIDGET (icon_view),
1388 wrap_width = MAX (wrap_width * 2, 50);
1391 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
1392 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
1396 /* General notes about layout
1398 * The icon view is layouted like this:
1400 * +----------+ s +----------+
1401 * | padding | p | padding |
1402 * | +------+ | a | +------+ |
1403 * | | cell | | c | | cell | |
1404 * | +------+ | i | +------+ |
1406 * +----------+ g +----------+
1408 * In size request and allocation code, there are 3 sizes that are used:
1410 * This is the size returned by gtk_cell_area_get_preferred_foo(). In places
1411 * where code is interacting with the cell area and renderers this is useful.
1413 * This is the cell size plus the item padding on each side.
1415 * This is the padded size plus the spacing. This is what's used for most
1416 * calculations because it can (ab)use the following formula:
1417 * iconview_size = 2 * margin + n_items * spaced_size - spacing
1418 * So when reading this code and fixing my bugs where I confuse these two, be
1419 * aware of this distinction.
1422 cell_area_get_preferred_size (GtkIconView *icon_view,
1423 GtkCellAreaContext *context,
1424 GtkOrientation orientation,
1429 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1432 gtk_cell_area_get_preferred_width_for_height (icon_view->priv->cell_area,
1434 GTK_WIDGET (icon_view),
1438 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
1440 GTK_WIDGET (icon_view),
1446 gtk_cell_area_get_preferred_height_for_width (icon_view->priv->cell_area,
1448 GTK_WIDGET (icon_view),
1452 gtk_cell_area_get_preferred_height (icon_view->priv->cell_area,
1454 GTK_WIDGET (icon_view),
1460 gtk_icon_view_get_preferred_item_size (GtkIconView *icon_view,
1461 GtkOrientation orientation,
1466 GtkIconViewPrivate *priv = icon_view->priv;
1467 GtkCellAreaContext *context;
1470 if (priv->items == NULL)
1477 context = gtk_cell_area_create_context (priv->cell_area);
1479 for_size -= 2 * priv->item_padding;
1483 /* This is necessary for the context to work properly */
1484 for (items = priv->items; items; items = items->next)
1486 GtkIconViewItem *item = items->data;
1488 _gtk_icon_view_set_cell_data (icon_view, item);
1489 cell_area_get_preferred_size (icon_view, context, 1 - orientation, -1, NULL, NULL);
1493 for (items = priv->items; items; items = items->next)
1495 GtkIconViewItem *item = items->data;
1497 _gtk_icon_view_set_cell_data (icon_view, item);
1498 if (items == priv->items)
1499 adjust_wrap_width (icon_view);
1500 cell_area_get_preferred_size (icon_view, context, orientation, for_size, NULL, NULL);
1503 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1506 gtk_cell_area_context_get_preferred_width_for_height (context,
1510 gtk_cell_area_context_get_preferred_width (context,
1516 gtk_cell_area_context_get_preferred_height_for_width (context,
1520 gtk_cell_area_context_get_preferred_height (context,
1524 if (orientation == GTK_ORIENTATION_HORIZONTAL && priv->item_width >= 0)
1527 *minimum = MAX (*minimum, priv->item_width);
1529 *natural = *minimum;
1533 *minimum = MAX (1, *minimum + 2 * priv->item_padding);
1535 *natural = MAX (1, *natural + 2 * priv->item_padding);
1537 g_object_unref (context);
1541 gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
1542 GtkOrientation orientation,
1545 gint *min_item_size,
1547 gint *max_item_size)
1549 GtkIconViewPrivate *priv = icon_view->priv;
1550 int minimum, natural, spacing;
1552 g_return_if_fail (min_item_size == NULL || min_items != NULL);
1553 g_return_if_fail (max_item_size == NULL || max_items != NULL);
1555 gtk_icon_view_get_preferred_item_size (icon_view, orientation, -1, &minimum, &natural);
1557 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1558 spacing = priv->column_spacing;
1560 spacing = priv->row_spacing;
1562 size -= 2 * priv->margin;
1567 if (priv->columns > 0)
1569 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1572 *min_items = priv->columns;
1574 *max_items = priv->columns;
1578 int n_items = gtk_icon_view_get_n_items (icon_view);
1581 *min_items = (n_items + priv->columns - 1) / priv->columns;
1583 *max_items = (n_items + priv->columns - 1) / priv->columns;
1590 if (size <= minimum)
1593 *max_items = size / minimum;
1598 if (size <= natural)
1601 *min_items = size / natural;
1607 *min_item_size = size / *min_items;
1608 *min_item_size = CLAMP (*min_item_size, minimum, natural);
1609 *min_item_size -= spacing;
1610 *min_item_size -= 2 * priv->item_padding;
1615 *max_item_size = size / *max_items;
1616 *max_item_size = CLAMP (*max_item_size, minimum, natural);
1617 *max_item_size -= spacing;
1618 *max_item_size -= 2 * priv->item_padding;
1622 static GtkSizeRequestMode
1623 gtk_icon_view_get_request_mode (GtkWidget *widget)
1625 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1629 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1633 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1634 GtkIconViewPrivate *priv = icon_view->priv;
1635 int item_min, item_nat;
1637 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_min, &item_nat);
1639 if (priv->columns > 0)
1641 *minimum = item_min * priv->columns + priv->column_spacing * (priv->columns - 1);
1642 *natural = item_nat * priv->columns + priv->column_spacing * (priv->columns - 1);
1646 int n_items = gtk_icon_view_get_n_items (icon_view);
1655 *minimum = item_min;
1656 *natural = item_nat * n_items + priv->column_spacing * (n_items - 1);
1660 *minimum += 2 * priv->margin;
1661 *natural += 2 * priv->margin;
1665 gtk_icon_view_get_preferred_width_for_height (GtkWidget *widget,
1670 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1671 GtkIconViewPrivate *priv = icon_view->priv;
1672 int item_min, item_nat, rows, row_height, n_items;
1674 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_VERTICAL, height, &rows, &row_height, NULL, NULL);
1675 n_items = gtk_icon_view_get_n_items (icon_view);
1677 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, row_height, &item_min, &item_nat);
1678 *minimum = (item_min + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1679 *natural = (item_nat + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1681 *minimum += 2 * priv->margin;
1682 *natural += 2 * priv->margin;
1686 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1690 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1691 GtkIconViewPrivate *priv = icon_view->priv;
1692 int item_min, item_nat, n_items;
1694 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, -1, &item_min, &item_nat);
1695 n_items = gtk_icon_view_get_n_items (icon_view);
1697 if (priv->columns > 0)
1699 int n_rows = (n_items + priv->columns - 1) / priv->columns;
1701 *minimum = item_min * n_rows + priv->row_spacing * (n_rows - 1);
1702 *natural = item_nat * n_rows + priv->row_spacing * (n_rows - 1);
1713 *minimum = item_min;
1714 *natural = item_nat * n_items + priv->row_spacing * (n_items - 1);
1718 *minimum += 2 * priv->margin;
1719 *natural += 2 * priv->margin;
1723 gtk_icon_view_get_preferred_height_for_width (GtkWidget *widget,
1728 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1729 GtkIconViewPrivate *priv = icon_view->priv;
1730 int item_min, item_nat, columns, column_width, n_items;
1732 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_HORIZONTAL, width, NULL, NULL, &columns, &column_width);
1733 n_items = gtk_icon_view_get_n_items (icon_view);
1735 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, column_width, &item_min, &item_nat);
1736 *minimum = (item_min + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1737 *natural = (item_nat + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1739 *minimum += 2 * priv->margin;
1740 *natural += 2 * priv->margin;
1744 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1748 for (list = icon_view->priv->children; list; list = list->next)
1750 GtkIconViewChild *child = list->data;
1752 /* totally ignore our child's requisition */
1753 gtk_widget_size_allocate (child->widget, &child->area);
1758 gtk_icon_view_size_allocate (GtkWidget *widget,
1759 GtkAllocation *allocation)
1761 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1763 gtk_widget_set_allocation (widget, allocation);
1765 gtk_icon_view_layout (icon_view);
1767 if (gtk_widget_get_realized (widget))
1769 gdk_window_move_resize (gtk_widget_get_window (widget),
1770 allocation->x, allocation->y,
1771 allocation->width, allocation->height);
1772 gdk_window_resize (icon_view->priv->bin_window,
1773 MAX (icon_view->priv->width, allocation->width),
1774 MAX (icon_view->priv->height, allocation->height));
1777 gtk_icon_view_allocate_children (icon_view);
1779 /* Delay signal emission */
1780 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1781 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1783 gtk_icon_view_set_hadjustment_values (icon_view);
1784 gtk_icon_view_set_vadjustment_values (icon_view);
1786 if (gtk_widget_get_realized (widget) &&
1787 icon_view->priv->scroll_to_path)
1790 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1791 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1792 icon_view->priv->scroll_to_path = NULL;
1794 gtk_icon_view_scroll_to_path (icon_view, path,
1795 icon_view->priv->scroll_to_use_align,
1796 icon_view->priv->scroll_to_row_align,
1797 icon_view->priv->scroll_to_col_align);
1798 gtk_tree_path_free (path);
1801 /* Emit any pending signals now */
1802 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1803 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1807 gtk_icon_view_draw (GtkWidget *widget,
1810 GtkIconView *icon_view;
1814 GtkIconViewDropPosition dest_pos;
1815 GtkIconViewItem *dest_item = NULL;
1817 icon_view = GTK_ICON_VIEW (widget);
1819 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1824 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1826 cairo_set_line_width (cr, 1.);
1828 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1832 dest_index = gtk_tree_path_get_indices (path)[0];
1833 gtk_tree_path_free (path);
1838 for (icons = icon_view->priv->items; icons; icons = icons->next)
1840 GtkIconViewItem *item = icons->data;
1841 GdkRectangle paint_area;
1843 paint_area.x = item->cell_area.x - icon_view->priv->item_padding;
1844 paint_area.y = item->cell_area.y - icon_view->priv->item_padding;
1845 paint_area.width = item->cell_area.width + icon_view->priv->item_padding * 2;
1846 paint_area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
1850 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1853 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1855 gtk_icon_view_paint_item (icon_view, cr, item,
1856 item->cell_area.x, item->cell_area.y,
1857 icon_view->priv->draw_focus);
1859 if (dest_index == item->index)
1867 dest_pos != GTK_ICON_VIEW_NO_DROP)
1869 GtkStyleContext *context;
1870 GdkRectangle rect = { 0 };
1872 context = gtk_widget_get_style_context (widget);
1876 case GTK_ICON_VIEW_DROP_INTO:
1877 rect = dest_item->cell_area;
1879 case GTK_ICON_VIEW_DROP_ABOVE:
1880 rect.x = dest_item->cell_area.x;
1881 rect.y = dest_item->cell_area.y - 1;
1882 rect.width = dest_item->cell_area.width;
1885 case GTK_ICON_VIEW_DROP_LEFT:
1886 rect.x = dest_item->cell_area.x - 1;
1887 rect.y = dest_item->cell_area.y;
1889 rect.height = dest_item->cell_area.height;
1891 case GTK_ICON_VIEW_DROP_BELOW:
1892 rect.x = dest_item->cell_area.x;
1893 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1894 rect.width = dest_item->cell_area.width;
1897 case GTK_ICON_VIEW_DROP_RIGHT:
1898 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1899 rect.y = dest_item->cell_area.y;
1901 rect.height = dest_item->cell_area.height;
1902 case GTK_ICON_VIEW_NO_DROP: ;
1906 gtk_render_focus (context, cr,
1908 rect.width, rect.height);
1911 if (icon_view->priv->doing_rubberband)
1912 gtk_icon_view_paint_rubberband (icon_view, cr);
1916 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1920 rubberband_scroll_timeout (gpointer data)
1922 GtkIconView *icon_view = data;
1924 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1925 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1926 icon_view->priv->scroll_value_diff);
1928 gtk_icon_view_update_rubberband (icon_view);
1934 gtk_icon_view_motion (GtkWidget *widget,
1935 GdkEventMotion *event)
1937 GtkAllocation allocation;
1938 GtkIconView *icon_view;
1941 icon_view = GTK_ICON_VIEW (widget);
1943 gtk_icon_view_maybe_begin_drag (icon_view, event);
1945 if (icon_view->priv->doing_rubberband)
1947 gtk_icon_view_update_rubberband (widget);
1949 abs_y = event->y - icon_view->priv->height *
1950 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1951 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1952 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1954 gtk_widget_get_allocation (widget, &allocation);
1956 if (abs_y < 0 || abs_y > allocation.height)
1959 icon_view->priv->scroll_value_diff = abs_y;
1961 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1963 icon_view->priv->event_last_x = event->x;
1964 icon_view->priv->event_last_y = event->y;
1966 if (icon_view->priv->scroll_timeout_id == 0)
1967 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1971 remove_scroll_timeout (icon_view);
1975 GtkIconViewItem *item, *last_prelight_item;
1976 GtkCellRenderer *cell = NULL;
1978 last_prelight_item = icon_view->priv->last_prelight;
1979 item = _gtk_icon_view_get_item_at_coords (icon_view,
1986 item->prelight = TRUE;
1987 gtk_icon_view_queue_draw_item (icon_view, item);
1990 if (last_prelight_item != NULL &&
1991 last_prelight_item != item)
1993 last_prelight_item->prelight = FALSE;
1994 gtk_icon_view_queue_draw_item (icon_view,
1995 icon_view->priv->last_prelight);
1998 icon_view->priv->last_prelight = item;
2005 gtk_icon_view_remove (GtkContainer *container,
2008 GtkIconView *icon_view;
2009 GtkIconViewChild *child = NULL;
2012 icon_view = GTK_ICON_VIEW (container);
2014 tmp_list = icon_view->priv->children;
2017 child = tmp_list->data;
2018 if (child->widget == widget)
2020 gtk_widget_unparent (widget);
2022 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
2023 g_list_free_1 (tmp_list);
2028 tmp_list = tmp_list->next;
2033 gtk_icon_view_forall (GtkContainer *container,
2034 gboolean include_internals,
2035 GtkCallback callback,
2036 gpointer callback_data)
2038 GtkIconView *icon_view;
2039 GtkIconViewChild *child = NULL;
2042 icon_view = GTK_ICON_VIEW (container);
2044 tmp_list = icon_view->priv->children;
2047 child = tmp_list->data;
2048 tmp_list = tmp_list->next;
2050 (* callback) (child->widget, callback_data);
2055 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
2056 GtkIconViewItem *item)
2059 AtkObject *item_obj;
2061 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2064 item_obj = atk_object_ref_accessible_child (obj, item->index);
2065 if (item_obj != NULL)
2067 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
2068 g_object_unref (item_obj);
2074 gtk_icon_view_add_editable (GtkCellArea *area,
2075 GtkCellRenderer *renderer,
2076 GtkCellEditable *editable,
2077 GdkRectangle *cell_area,
2079 GtkIconView *icon_view)
2081 GtkIconViewChild *child;
2082 GtkWidget *widget = GTK_WIDGET (editable);
2084 child = g_new (GtkIconViewChild, 1);
2086 child->widget = widget;
2087 child->area.x = cell_area->x;
2088 child->area.y = cell_area->y;
2089 child->area.width = cell_area->width;
2090 child->area.height = cell_area->height;
2092 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
2094 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2095 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
2097 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
2101 gtk_icon_view_remove_editable (GtkCellArea *area,
2102 GtkCellRenderer *renderer,
2103 GtkCellEditable *editable,
2104 GtkIconView *icon_view)
2108 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
2109 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
2111 gtk_container_remove (GTK_CONTAINER (icon_view),
2112 GTK_WIDGET (editable));
2114 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
2115 gtk_icon_view_queue_draw_path (icon_view, path);
2116 gtk_tree_path_free (path);
2120 * gtk_icon_view_set_cursor:
2121 * @icon_view: A #GtkIconView
2122 * @path: A #GtkTreePath
2123 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2124 * @start_editing: %TRUE if the specified cell should start being edited.
2126 * Sets the current keyboard focus to be at @path, and selects it. This is
2127 * useful when you want to focus the user's attention on a particular item.
2128 * If @cell is not %NULL, then focus is given to the cell specified by
2129 * it. Additionally, if @start_editing is %TRUE, then editing should be
2130 * started in the specified cell.
2132 * This function is often followed by <literal>gtk_widget_grab_focus
2133 * (icon_view)</literal> in order to give keyboard focus to the widget.
2134 * Please note that editing can only happen when the widget is realized.
2139 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2141 GtkCellRenderer *cell,
2142 gboolean start_editing)
2144 GtkIconViewItem *item = NULL;
2146 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2147 g_return_if_fail (path != NULL);
2148 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2150 if (icon_view->priv->cell_area)
2151 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2153 if (gtk_tree_path_get_depth (path) == 1)
2154 item = g_list_nth_data (icon_view->priv->items,
2155 gtk_tree_path_get_indices(path)[0]);
2160 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
2161 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2163 if (start_editing &&
2164 icon_view->priv->cell_area)
2166 GtkCellAreaContext *context;
2168 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2169 _gtk_icon_view_set_cell_data (icon_view, item);
2170 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2171 GTK_WIDGET (icon_view), &item->cell_area,
2172 0 /* XXX flags */, TRUE);
2177 * gtk_icon_view_get_cursor:
2178 * @icon_view: A #GtkIconView
2179 * @path: (out) (allow-none): Return location for the current cursor path,
2181 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
2183 * Fills in @path and @cell with the current cursor path and cell.
2184 * If the cursor isn't currently set, then *@path will be %NULL.
2185 * If no cell currently has focus, then *@cell will be %NULL.
2187 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2189 * Return value: %TRUE if the cursor is set.
2194 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2196 GtkCellRenderer **cell)
2198 GtkIconViewItem *item;
2200 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2202 item = icon_view->priv->cursor_item;
2207 *path = gtk_tree_path_new_from_indices (item->index, -1);
2212 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
2213 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
2215 return (item != NULL);
2219 gtk_icon_view_button_press (GtkWidget *widget,
2220 GdkEventButton *event)
2222 GtkIconView *icon_view;
2223 GtkIconViewItem *item;
2224 gboolean dirty = FALSE;
2225 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2227 icon_view = GTK_ICON_VIEW (widget);
2229 if (event->window != icon_view->priv->bin_window)
2232 if (!gtk_widget_has_focus (widget))
2233 gtk_widget_grab_focus (widget);
2235 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
2237 GdkModifierType extend_mod_mask;
2238 GdkModifierType modify_mod_mask;
2241 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2244 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2246 item = _gtk_icon_view_get_item_at_coords (icon_view,
2252 * We consider only the the cells' area as the item area if the
2253 * item is not selected, but if it *is* selected, the complete
2254 * selection rectangle is considered to be part of the item.
2256 if (item != NULL && (cell != NULL || item->selected))
2260 if (gtk_cell_renderer_is_activatable (cell))
2264 gtk_icon_view_scroll_to_item (icon_view, item);
2266 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2268 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2270 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2271 (event->state & extend_mod_mask))
2273 gtk_icon_view_unselect_all_internal (icon_view);
2275 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2276 if (!icon_view->priv->anchor_item)
2277 icon_view->priv->anchor_item = item;
2279 gtk_icon_view_select_all_between (icon_view,
2280 icon_view->priv->anchor_item,
2286 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2287 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2288 (event->state & modify_mod_mask))
2290 item->selected = !item->selected;
2291 gtk_icon_view_queue_draw_item (icon_view, item);
2296 gtk_icon_view_unselect_all_internal (icon_view);
2298 item->selected = TRUE;
2299 gtk_icon_view_queue_draw_item (icon_view, item);
2302 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2303 icon_view->priv->anchor_item = item;
2306 /* Save press to possibly begin a drag */
2307 if (icon_view->priv->pressed_button < 0)
2309 icon_view->priv->pressed_button = event->button;
2310 icon_view->priv->press_start_x = event->x;
2311 icon_view->priv->press_start_y = event->y;
2314 if (!icon_view->priv->last_single_clicked)
2315 icon_view->priv->last_single_clicked = item;
2317 /* cancel the current editing, if it exists */
2318 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2320 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2322 GtkCellAreaContext *context;
2324 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2326 _gtk_icon_view_set_cell_data (icon_view, item);
2327 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2328 GTK_WIDGET (icon_view),
2329 &item->cell_area, 0/* XXX flags */, FALSE);
2334 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2335 !(event->state & modify_mod_mask))
2337 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2340 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2341 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2344 /* don't draw keyboard focus around an clicked-on item */
2345 icon_view->priv->draw_focus = FALSE;
2348 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
2350 item = _gtk_icon_view_get_item_at_coords (icon_view,
2355 if (item && item == icon_view->priv->last_single_clicked)
2359 path = gtk_tree_path_new_from_indices (item->index, -1);
2360 gtk_icon_view_item_activated (icon_view, path);
2361 gtk_tree_path_free (path);
2364 icon_view->priv->last_single_clicked = NULL;
2365 icon_view->priv->pressed_button = -1;
2369 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2371 return event->button == GDK_BUTTON_PRIMARY;
2375 gtk_icon_view_button_release (GtkWidget *widget,
2376 GdkEventButton *event)
2378 GtkIconView *icon_view;
2380 icon_view = GTK_ICON_VIEW (widget);
2382 if (icon_view->priv->pressed_button == event->button)
2383 icon_view->priv->pressed_button = -1;
2385 gtk_icon_view_stop_rubberbanding (icon_view);
2387 remove_scroll_timeout (icon_view);
2393 gtk_icon_view_key_press (GtkWidget *widget,
2396 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2398 if (icon_view->priv->doing_rubberband)
2400 if (event->keyval == GDK_KEY_Escape)
2401 gtk_icon_view_stop_rubberbanding (icon_view);
2406 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2410 gtk_icon_view_key_release (GtkWidget *widget,
2413 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2415 if (icon_view->priv->doing_rubberband)
2418 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2422 gtk_icon_view_update_rubberband (gpointer data)
2424 GtkIconView *icon_view;
2426 GdkRectangle old_area;
2427 GdkRectangle new_area;
2428 GdkRectangle common;
2429 cairo_region_t *invalid_region;
2431 icon_view = GTK_ICON_VIEW (data);
2433 gdk_window_get_device_position (icon_view->priv->bin_window,
2434 icon_view->priv->rubberband_device,
2440 old_area.x = MIN (icon_view->priv->rubberband_x1,
2441 icon_view->priv->rubberband_x2);
2442 old_area.y = MIN (icon_view->priv->rubberband_y1,
2443 icon_view->priv->rubberband_y2);
2444 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2445 icon_view->priv->rubberband_x1) + 1;
2446 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2447 icon_view->priv->rubberband_y1) + 1;
2449 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2450 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2451 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2452 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2454 invalid_region = cairo_region_create_rectangle (&old_area);
2455 cairo_region_union_rectangle (invalid_region, &new_area);
2457 gdk_rectangle_intersect (&old_area, &new_area, &common);
2458 if (common.width > 2 && common.height > 2)
2460 cairo_region_t *common_region;
2462 /* make sure the border is invalidated */
2468 common_region = cairo_region_create_rectangle (&common);
2470 cairo_region_subtract (invalid_region, common_region);
2471 cairo_region_destroy (common_region);
2474 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2476 cairo_region_destroy (invalid_region);
2478 icon_view->priv->rubberband_x2 = x;
2479 icon_view->priv->rubberband_y2 = y;
2481 gtk_icon_view_update_rubberband_selection (icon_view);
2485 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2492 if (icon_view->priv->rubberband_device)
2495 for (items = icon_view->priv->items; items; items = items->next)
2497 GtkIconViewItem *item = items->data;
2499 item->selected_before_rubberbanding = item->selected;
2502 icon_view->priv->rubberband_x1 = x;
2503 icon_view->priv->rubberband_y1 = y;
2504 icon_view->priv->rubberband_x2 = x;
2505 icon_view->priv->rubberband_y2 = y;
2507 icon_view->priv->doing_rubberband = TRUE;
2508 icon_view->priv->rubberband_device = device;
2510 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2514 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2516 if (!icon_view->priv->doing_rubberband)
2519 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2520 icon_view->priv->rubberband_device);
2522 icon_view->priv->doing_rubberband = FALSE;
2523 icon_view->priv->rubberband_device = NULL;
2525 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2529 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2532 gint x, y, width, height;
2533 gboolean dirty = FALSE;
2535 x = MIN (icon_view->priv->rubberband_x1,
2536 icon_view->priv->rubberband_x2);
2537 y = MIN (icon_view->priv->rubberband_y1,
2538 icon_view->priv->rubberband_y2);
2539 width = ABS (icon_view->priv->rubberband_x1 -
2540 icon_view->priv->rubberband_x2);
2541 height = ABS (icon_view->priv->rubberband_y1 -
2542 icon_view->priv->rubberband_y2);
2544 for (items = icon_view->priv->items; items; items = items->next)
2546 GtkIconViewItem *item = items->data;
2550 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2551 x, y, width, height);
2553 selected = is_in ^ item->selected_before_rubberbanding;
2555 if (item->selected != selected)
2557 item->selected = selected;
2559 gtk_icon_view_queue_draw_item (icon_view, item);
2564 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2569 GdkRectangle hit_rect;
2574 hit_test (GtkCellRenderer *renderer,
2575 const GdkRectangle *cell_area,
2576 const GdkRectangle *cell_background,
2579 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2580 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2581 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2582 MAX (data->hit_rect.y, cell_area->y) > 0)
2585 return (data->hit != FALSE);
2589 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2590 GtkIconViewItem *item,
2596 HitTestData data = { { x, y, width, height }, FALSE };
2597 GtkCellAreaContext *context;
2598 GdkRectangle *item_area = &item->cell_area;
2600 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2601 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2604 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2606 _gtk_icon_view_set_cell_data (icon_view, item);
2607 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2608 GTK_WIDGET (icon_view),
2609 item_area, item_area,
2610 (GtkCellAllocCallback)hit_test, &data);
2616 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2618 gboolean dirty = FALSE;
2621 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2624 for (items = icon_view->priv->items; items; items = items->next)
2626 GtkIconViewItem *item = items->data;
2630 item->selected = FALSE;
2632 gtk_icon_view_queue_draw_item (icon_view, item);
2633 gtk_icon_view_item_selected_changed (icon_view, item);
2641 /* GtkIconView signals */
2643 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2645 gtk_icon_view_select_all (icon_view);
2649 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2651 gtk_icon_view_unselect_all (icon_view);
2655 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2657 gtk_icon_view_unselect_all (icon_view);
2659 if (icon_view->priv->cursor_item != NULL)
2660 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2664 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2667 GtkCellAreaContext *context;
2669 if (!icon_view->priv->cursor_item)
2672 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2674 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2675 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2676 GTK_WIDGET (icon_view),
2677 &icon_view->priv->cursor_item->cell_area,
2681 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2682 gtk_icon_view_item_activated (icon_view, path);
2683 gtk_tree_path_free (path);
2689 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2691 if (!icon_view->priv->cursor_item)
2694 switch (icon_view->priv->selection_mode)
2696 case GTK_SELECTION_NONE:
2698 case GTK_SELECTION_BROWSE:
2699 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2701 case GTK_SELECTION_SINGLE:
2702 if (icon_view->priv->cursor_item->selected)
2703 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2705 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2707 case GTK_SELECTION_MULTIPLE:
2708 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2709 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2711 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2712 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2718 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2720 GtkAllocation allocation;
2721 GtkAdjustment *adj = icon_view->priv->hadjustment;
2722 gdouble old_page_size;
2728 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2730 old_value = gtk_adjustment_get_value (adj);
2731 old_upper = gtk_adjustment_get_upper (adj);
2732 old_page_size = gtk_adjustment_get_page_size (adj);
2733 new_upper = MAX (allocation.width, icon_view->priv->width);
2735 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2737 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2738 /* Quick explanation:
2739 * In LTR locales, leftmost portion of visible rectangle should stay
2740 * fixed, which means left edge of scrollbar thumb should remain fixed
2741 * and thus adjustment's value should stay the same.
2743 * In RTL locales, we want to keep rightmost portion of visible
2744 * rectangle fixed. This means right edge of thumb should remain fixed.
2745 * In this case, upper - value - page_size should remain constant.
2747 new_value = (new_upper - allocation.width) -
2748 (old_upper - old_value - old_page_size);
2749 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2752 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2754 gtk_adjustment_configure (adj,
2758 allocation.width * 0.1,
2759 allocation.width * 0.9,
2764 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2766 GtkAllocation allocation;
2767 GtkAdjustment *adj = icon_view->priv->vadjustment;
2769 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2771 gtk_adjustment_configure (adj,
2772 gtk_adjustment_get_value (adj),
2774 MAX (allocation.height, icon_view->priv->height),
2775 allocation.height * 0.1,
2776 allocation.height * 0.9,
2781 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2782 GtkAdjustment *adjustment)
2784 GtkIconViewPrivate *priv = icon_view->priv;
2786 if (adjustment && priv->hadjustment == adjustment)
2789 if (priv->hadjustment != NULL)
2791 g_signal_handlers_disconnect_matched (priv->hadjustment,
2792 G_SIGNAL_MATCH_DATA,
2793 0, 0, NULL, NULL, icon_view);
2794 g_object_unref (priv->hadjustment);
2798 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2801 g_signal_connect (adjustment, "value-changed",
2802 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2803 priv->hadjustment = g_object_ref_sink (adjustment);
2804 gtk_icon_view_set_hadjustment_values (icon_view);
2806 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2810 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2811 GtkAdjustment *adjustment)
2813 GtkIconViewPrivate *priv = icon_view->priv;
2815 if (adjustment && priv->vadjustment == adjustment)
2818 if (priv->vadjustment != NULL)
2820 g_signal_handlers_disconnect_matched (priv->vadjustment,
2821 G_SIGNAL_MATCH_DATA,
2822 0, 0, NULL, NULL, icon_view);
2823 g_object_unref (priv->vadjustment);
2827 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2830 g_signal_connect (adjustment, "value-changed",
2831 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2832 priv->vadjustment = g_object_ref_sink (adjustment);
2833 gtk_icon_view_set_vadjustment_values (icon_view);
2835 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2839 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2840 GtkIconView *icon_view)
2842 GtkIconViewPrivate *priv = icon_view->priv;
2844 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2846 gdk_window_move (priv->bin_window,
2847 - gtk_adjustment_get_value (priv->hadjustment),
2848 - gtk_adjustment_get_value (priv->vadjustment));
2850 if (icon_view->priv->doing_rubberband)
2851 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2853 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2858 compare_sizes (gconstpointer p1,
2862 return GPOINTER_TO_INT (((const GtkRequestedSize *) p1)->data)
2863 - GPOINTER_TO_INT (((const GtkRequestedSize *) p2)->data);
2867 gtk_icon_view_layout (GtkIconView *icon_view)
2869 GtkIconViewPrivate *priv = icon_view->priv;
2870 GtkWidget *widget = GTK_WIDGET (icon_view);
2872 gint item_width; /* this doesn't include item_padding */
2873 gint n_columns, n_rows, n_items;
2875 GtkRequestedSize *sizes;
2878 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2881 n_items = gtk_icon_view_get_n_items (icon_view);
2883 gtk_icon_view_compute_n_items_for_size (icon_view,
2884 GTK_ORIENTATION_HORIZONTAL,
2885 gtk_widget_get_allocated_width (widget),
2887 &n_columns, &item_width);
2888 n_rows = (n_items + n_columns - 1) / n_columns;
2890 priv->width = n_columns * (item_width + 2 * priv->item_padding + priv->column_spacing) - priv->column_spacing;
2891 priv->width += 2 * priv->margin;
2892 priv->width = MAX (priv->width, gtk_widget_get_allocated_width (widget));
2894 /* Clear the per row contexts */
2895 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2897 gtk_cell_area_context_reset (priv->cell_area_context);
2898 /* because layouting is complicated. We designed an API
2899 * that is O(N²) and nonsensical.
2900 * And we're proud of it. */
2901 for (items = priv->items; items; items = items->next)
2903 _gtk_icon_view_set_cell_data (icon_view, items->data);
2904 gtk_cell_area_get_preferred_width (priv->cell_area,
2905 priv->cell_area_context,
2910 sizes = g_newa (GtkRequestedSize, n_rows);
2911 items = priv->items;
2912 priv->height = priv->margin;
2914 /* Collect the heights for all rows */
2915 for (row = 0; row < n_rows; row++)
2917 GtkCellAreaContext *context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2918 g_ptr_array_add (priv->row_contexts, context);
2920 for (col = 0; col < n_columns && items; col++, items = items->next)
2922 GtkIconViewItem *item = items->data;
2924 _gtk_icon_view_set_cell_data (icon_view, item);
2925 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2932 sizes[row].data = GINT_TO_POINTER (row);
2933 gtk_cell_area_context_get_preferred_height_for_width (context,
2935 &sizes[row].minimum_size,
2936 &sizes[row].natural_size);
2937 priv->height += sizes[row].minimum_size + 2 * priv->item_padding + priv->row_spacing;
2940 priv->height -= priv->row_spacing;
2941 priv->height += priv->margin;
2942 priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget));
2944 gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height,
2948 /* Actually allocate the rows */
2949 g_qsort_with_data (sizes, n_rows, sizeof (GtkRequestedSize), compare_sizes, NULL);
2951 items = priv->items;
2952 priv->height = priv->margin;
2954 for (row = 0; row < n_rows; row++)
2956 GtkCellAreaContext *context = g_ptr_array_index (priv->row_contexts, row);
2957 gtk_cell_area_context_allocate (context, item_width, sizes[row].minimum_size);
2959 priv->height += priv->item_padding;
2961 for (col = 0; col < n_columns && items; col++, items = items->next)
2963 GtkIconViewItem *item = items->data;
2965 item->cell_area.x = priv->margin + (col * 2 + 1) * priv->item_padding + col * (priv->column_spacing + item_width);
2966 item->cell_area.width = item_width;
2967 item->cell_area.y = priv->height;
2968 item->cell_area.height = sizes[row].minimum_size;
2973 item->cell_area.x = priv->width - item_width - item->cell_area.x;
2974 item->col = n_columns - 1 - col;
2978 priv->height += sizes[row].minimum_size + priv->item_padding + priv->row_spacing;
2981 priv->height -= priv->row_spacing;
2982 priv->height += priv->margin;
2983 priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget));
2987 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2989 /* Clear all item sizes */
2990 g_list_foreach (icon_view->priv->items,
2991 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2993 /* Re-layout the items */
2994 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
2998 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3000 item->cell_area.width = -1;
3001 item->cell_area.height = -1;
3005 gtk_icon_view_paint_item (GtkIconView *icon_view,
3007 GtkIconViewItem *item,
3010 gboolean draw_focus)
3012 GdkRectangle cell_area;
3013 GtkStateFlags state = 0;
3014 GtkCellRendererState flags = 0;
3015 GtkStyleContext *style_context;
3016 GtkWidget *widget = GTK_WIDGET (icon_view);
3017 GtkIconViewPrivate *priv = icon_view->priv;
3018 GtkCellAreaContext *context;
3020 if (priv->model == NULL || item->cell_area.width <= 0 || item->cell_area.height <= 0)
3023 _gtk_icon_view_set_cell_data (icon_view, item);
3025 style_context = gtk_widget_get_style_context (widget);
3026 state = gtk_widget_get_state_flags (widget);
3028 gtk_style_context_save (style_context);
3029 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
3030 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
3032 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
3036 if ((state & GTK_STATE_FLAG_FOCUSED) &&
3037 item == icon_view->priv->cursor_item)
3039 flags |= GTK_CELL_RENDERER_FOCUSED;
3042 state |= GTK_STATE_FLAG_SELECTED;
3043 flags |= GTK_CELL_RENDERER_SELECTED;
3048 state |= GTK_STATE_FLAG_PRELIGHT;
3049 flags |= GTK_CELL_RENDERER_PRELIT;
3052 gtk_style_context_set_state (style_context, state);
3056 gtk_render_background (style_context, cr,
3057 x - icon_view->priv->item_padding,
3058 y - icon_view->priv->item_padding,
3059 item->cell_area.width + icon_view->priv->item_padding * 2,
3060 item->cell_area.height + icon_view->priv->item_padding * 2);
3061 gtk_render_frame (style_context, cr,
3062 x - icon_view->priv->item_padding,
3063 y - icon_view->priv->item_padding,
3064 item->cell_area.width + icon_view->priv->item_padding * 2,
3065 item->cell_area.height + icon_view->priv->item_padding * 2);
3070 cell_area.width = item->cell_area.width;
3071 cell_area.height = item->cell_area.height;
3073 context = g_ptr_array_index (priv->row_contexts, item->row);
3074 gtk_cell_area_render (priv->cell_area, context,
3075 widget, cr, &cell_area, &cell_area, flags,
3078 gtk_style_context_restore (style_context);
3082 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3085 GtkStyleContext *context;
3090 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3091 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3092 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3093 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3095 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3097 gtk_style_context_save (context);
3098 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3100 gdk_cairo_rectangle (cr, &rect);
3103 gtk_render_background (context, cr,
3105 rect.width, rect.height);
3106 gtk_render_frame (context, cr,
3108 rect.width, rect.height);
3110 gtk_style_context_restore (context);
3115 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3121 index = gtk_tree_path_get_indices (path)[0];
3123 for (l = icon_view->priv->items; l; l = l->next)
3125 GtkIconViewItem *item = l->data;
3127 if (item->index == index)
3129 gtk_icon_view_queue_draw_item (icon_view, item);
3136 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3137 GtkIconViewItem *item)
3140 GdkRectangle *item_area = &item->cell_area;
3142 rect.x = item_area->x - icon_view->priv->item_padding;
3143 rect.y = item_area->y - icon_view->priv->item_padding;
3144 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3145 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3147 if (icon_view->priv->bin_window)
3148 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3152 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3153 GtkIconViewItem *item,
3154 GtkCellRenderer *cursor_cell)
3157 AtkObject *item_obj;
3158 AtkObject *cursor_item_obj;
3160 /* When hitting this path from keynav, the focus cell is
3161 * already set, we dont need to notify the atk object
3162 * but we still need to queue the draw here (in the case
3163 * that the focus cell changes but not the cursor item).
3165 gtk_icon_view_queue_draw_item (icon_view, item);
3167 if (icon_view->priv->cursor_item == item &&
3168 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3171 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3172 if (icon_view->priv->cursor_item != NULL)
3174 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3177 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3178 if (cursor_item_obj != NULL)
3179 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3182 icon_view->priv->cursor_item = item;
3185 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3188 /* Make sure there is a cell in focus initially */
3189 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3190 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3193 /* Notify that accessible focus object has changed */
3194 item_obj = atk_object_ref_accessible_child (obj, item->index);
3196 if (item_obj != NULL)
3198 atk_focus_tracker_notify (item_obj);
3199 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3200 g_object_unref (item_obj);
3205 static GtkIconViewItem *
3206 gtk_icon_view_item_new (void)
3208 GtkIconViewItem *item;
3210 item = g_slice_new0 (GtkIconViewItem);
3212 item->cell_area.width = -1;
3213 item->cell_area.height = -1;
3219 gtk_icon_view_item_free (GtkIconViewItem *item)
3221 g_return_if_fail (item != NULL);
3223 g_slice_free (GtkIconViewItem, item);
3227 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3230 gboolean only_in_cell,
3231 GtkCellRenderer **cell_at_pos)
3236 *cell_at_pos = NULL;
3238 for (items = icon_view->priv->items; items; items = items->next)
3240 GtkIconViewItem *item = items->data;
3241 GdkRectangle *item_area = &item->cell_area;
3243 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3244 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3245 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3246 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3248 if (only_in_cell || cell_at_pos)
3250 GtkCellRenderer *cell = NULL;
3251 GtkCellAreaContext *context;
3253 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3254 _gtk_icon_view_set_cell_data (icon_view, item);
3256 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3257 y >= item_area->y && y <= item_area->y + item_area->height)
3258 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3259 GTK_WIDGET (icon_view),
3264 *cell_at_pos = cell;
3267 return cell != NULL ? item : NULL;
3278 _gtk_icon_view_select_item (GtkIconView *icon_view,
3279 GtkIconViewItem *item)
3281 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3282 g_return_if_fail (item != NULL);
3287 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3289 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3290 gtk_icon_view_unselect_all_internal (icon_view);
3292 item->selected = TRUE;
3294 gtk_icon_view_item_selected_changed (icon_view, item);
3295 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3297 gtk_icon_view_queue_draw_item (icon_view, item);
3302 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3303 GtkIconViewItem *item)
3305 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3306 g_return_if_fail (item != NULL);
3308 if (!item->selected)
3311 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3312 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3315 item->selected = FALSE;
3317 gtk_icon_view_item_selected_changed (icon_view, item);
3318 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3320 gtk_icon_view_queue_draw_item (icon_view, item);
3324 verify_items (GtkIconView *icon_view)
3329 for (items = icon_view->priv->items; items; items = items->next)
3331 GtkIconViewItem *item = items->data;
3333 if (item->index != i)
3334 g_error ("List item does not match its index: "
3335 "item index %d and list index %d\n", item->index, i);
3342 gtk_icon_view_row_changed (GtkTreeModel *model,
3347 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3349 /* ignore changes in branches */
3350 if (gtk_tree_path_get_depth (path) > 1)
3353 /* An icon view subclass might add it's own model and populate
3354 * things at init() time instead of waiting for the constructor()
3357 if (icon_view->priv->cell_area)
3358 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3360 /* Here we can use a "grow-only" strategy for optimization
3361 * and only invalidate a single item and queue a relayout
3362 * instead of invalidating the whole thing.
3364 * For now GtkIconView still cant deal with huge models
3365 * so just invalidate the whole thing when the model
3368 gtk_icon_view_invalidate_sizes (icon_view);
3370 verify_items (icon_view);
3374 gtk_icon_view_row_inserted (GtkTreeModel *model,
3379 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3381 GtkIconViewItem *item;
3384 /* ignore changes in branches */
3385 if (gtk_tree_path_get_depth (path) > 1)
3388 index = gtk_tree_path_get_indices(path)[0];
3390 item = gtk_icon_view_item_new ();
3392 item->index = index;
3394 /* FIXME: We can be more efficient here,
3395 we can store a tail pointer and use that when
3396 appending (which is a rather common operation)
3398 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3401 list = g_list_nth (icon_view->priv->items, index + 1);
3402 for (; list; list = list->next)
3409 verify_items (icon_view);
3411 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3415 gtk_icon_view_row_deleted (GtkTreeModel *model,
3419 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3421 GtkIconViewItem *item;
3423 gboolean emit = FALSE;
3425 /* ignore changes in branches */
3426 if (gtk_tree_path_get_depth (path) > 1)
3429 index = gtk_tree_path_get_indices(path)[0];
3431 list = g_list_nth (icon_view->priv->items, index);
3434 if (icon_view->priv->cell_area)
3435 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3437 if (item == icon_view->priv->anchor_item)
3438 icon_view->priv->anchor_item = NULL;
3440 if (item == icon_view->priv->cursor_item)
3441 icon_view->priv->cursor_item = NULL;
3443 if (item == icon_view->priv->last_prelight)
3444 icon_view->priv->last_prelight = NULL;
3449 gtk_icon_view_item_free (item);
3451 for (next = list->next; next; next = next->next)
3458 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3460 verify_items (icon_view);
3462 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3465 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3469 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3470 GtkTreePath *parent,
3475 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3478 GList *items = NULL, *list;
3479 GtkIconViewItem **item_array;
3482 /* ignore changes in branches */
3486 if (icon_view->priv->cell_area)
3487 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3489 length = gtk_tree_model_iter_n_children (model, NULL);
3491 order = g_new (gint, length);
3492 for (i = 0; i < length; i++)
3493 order [new_order[i]] = i;
3495 item_array = g_new (GtkIconViewItem *, length);
3496 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3497 item_array[order[i]] = list->data;
3500 for (i = length - 1; i >= 0; i--)
3502 item_array[i]->index = i;
3503 items = g_list_prepend (items, item_array[i]);
3506 g_free (item_array);
3507 g_list_free (icon_view->priv->items);
3508 icon_view->priv->items = items;
3510 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3512 verify_items (icon_view);
3516 gtk_icon_view_build_items (GtkIconView *icon_view)
3520 GList *items = NULL;
3522 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3530 GtkIconViewItem *item = gtk_icon_view_item_new ();
3536 items = g_list_prepend (items, item);
3538 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3540 icon_view->priv->items = g_list_reverse (items);
3544 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3547 GtkMovementStep step,
3551 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3552 I_("move-cursor"), 2,
3556 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3561 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3564 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3569 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3576 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3577 GtkMovementStep step,
3580 GdkModifierType state;
3582 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3583 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3584 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3585 step == GTK_MOVEMENT_DISPLAY_LINES ||
3586 step == GTK_MOVEMENT_PAGES ||
3587 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3589 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3592 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3593 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3595 if (gtk_get_current_event_state (&state))
3597 GdkModifierType extend_mod_mask;
3598 GdkModifierType modify_mod_mask;
3601 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3602 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3604 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3605 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3607 if ((state & modify_mod_mask) == modify_mod_mask)
3608 icon_view->priv->modify_selection_pressed = TRUE;
3609 if ((state & extend_mod_mask) == extend_mod_mask)
3610 icon_view->priv->extend_selection_pressed = TRUE;
3612 /* else we assume not pressed */
3616 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3617 case GTK_MOVEMENT_VISUAL_POSITIONS:
3618 gtk_icon_view_move_cursor_left_right (icon_view, count);
3620 case GTK_MOVEMENT_DISPLAY_LINES:
3621 gtk_icon_view_move_cursor_up_down (icon_view, count);
3623 case GTK_MOVEMENT_PAGES:
3624 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3626 case GTK_MOVEMENT_BUFFER_ENDS:
3627 gtk_icon_view_move_cursor_start_end (icon_view, count);
3630 g_assert_not_reached ();
3633 icon_view->priv->modify_selection_pressed = FALSE;
3634 icon_view->priv->extend_selection_pressed = FALSE;
3636 icon_view->priv->draw_focus = TRUE;
3641 static GtkIconViewItem *
3642 find_item (GtkIconView *icon_view,
3643 GtkIconViewItem *current,
3649 GtkIconViewItem *item;
3651 /* FIXME: this could be more efficient
3653 row = current->row + row_ofs;
3654 col = current->col + col_ofs;
3656 for (items = icon_view->priv->items; items; items = items->next)
3659 if (item->row == row && item->col == col)
3666 static GtkIconViewItem *
3667 find_item_page_up_down (GtkIconView *icon_view,
3668 GtkIconViewItem *current,
3675 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3677 item = g_list_find (icon_view->priv->items, current);
3682 for (next = item->next; next; next = next->next)
3684 if (((GtkIconViewItem *)next->data)->col == col)
3687 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3697 for (next = item->prev; next; next = next->prev)
3699 if (((GtkIconViewItem *)next->data)->col == col)
3702 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3716 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3717 GtkIconViewItem *anchor,
3718 GtkIconViewItem *cursor)
3721 GtkIconViewItem *item;
3722 gint row1, row2, col1, col2;
3723 gboolean dirty = FALSE;
3725 if (anchor->row < cursor->row)
3736 if (anchor->col < cursor->col)
3747 for (items = icon_view->priv->items; items; items = items->next)
3751 if (row1 <= item->row && item->row <= row2 &&
3752 col1 <= item->col && item->col <= col2)
3754 if (!item->selected)
3757 item->selected = TRUE;
3758 gtk_icon_view_item_selected_changed (icon_view, item);
3760 gtk_icon_view_queue_draw_item (icon_view, item);
3768 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3771 GtkIconViewItem *item;
3772 GtkCellRenderer *cell = NULL;
3773 gboolean dirty = FALSE;
3775 GtkDirectionType direction;
3777 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3780 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3782 if (!icon_view->priv->cursor_item)
3787 list = icon_view->priv->items;
3789 list = g_list_last (icon_view->priv->items);
3795 /* Give focus to the first cell initially */
3796 _gtk_icon_view_set_cell_data (icon_view, item);
3797 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3806 item = icon_view->priv->cursor_item;
3807 step = count > 0 ? 1 : -1;
3809 /* Save the current focus cell in case we hit the edge */
3810 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3814 _gtk_icon_view_set_cell_data (icon_view, item);
3816 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3819 item = find_item (icon_view, item, step, 0);
3825 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3827 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3829 gtk_widget_child_focus (toplevel,
3830 direction == GTK_DIR_UP ?
3831 GTK_DIR_TAB_BACKWARD :
3832 GTK_DIR_TAB_FORWARD);
3836 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3840 if (icon_view->priv->modify_selection_pressed ||
3841 !icon_view->priv->extend_selection_pressed ||
3842 !icon_view->priv->anchor_item ||
3843 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3844 icon_view->priv->anchor_item = item;
3846 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3847 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3849 if (!icon_view->priv->modify_selection_pressed &&
3850 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3852 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3853 dirty = gtk_icon_view_select_all_between (icon_view,
3854 icon_view->priv->anchor_item,
3858 gtk_icon_view_scroll_to_item (icon_view, item);
3861 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3865 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3868 GtkIconViewItem *item;
3869 gboolean dirty = FALSE;
3871 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3874 if (!icon_view->priv->cursor_item)
3879 list = icon_view->priv->items;
3881 list = g_list_last (icon_view->priv->items);
3883 item = list ? list->data : NULL;
3886 item = find_item_page_up_down (icon_view,
3887 icon_view->priv->cursor_item,
3890 if (item == icon_view->priv->cursor_item)
3891 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3896 if (icon_view->priv->modify_selection_pressed ||
3897 !icon_view->priv->extend_selection_pressed ||
3898 !icon_view->priv->anchor_item ||
3899 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3900 icon_view->priv->anchor_item = item;
3902 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3904 if (!icon_view->priv->modify_selection_pressed &&
3905 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3907 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3908 dirty = gtk_icon_view_select_all_between (icon_view,
3909 icon_view->priv->anchor_item,
3913 gtk_icon_view_scroll_to_item (icon_view, item);
3916 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3920 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3923 GtkIconViewItem *item;
3924 GtkCellRenderer *cell = NULL;
3925 gboolean dirty = FALSE;
3927 GtkDirectionType direction;
3929 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3932 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3934 if (!icon_view->priv->cursor_item)
3939 list = icon_view->priv->items;
3941 list = g_list_last (icon_view->priv->items);
3947 /* Give focus to the first cell initially */
3948 _gtk_icon_view_set_cell_data (icon_view, item);
3949 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3958 item = icon_view->priv->cursor_item;
3959 step = count > 0 ? 1 : -1;
3961 /* Save the current focus cell in case we hit the edge */
3962 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3966 _gtk_icon_view_set_cell_data (icon_view, item);
3968 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3971 item = find_item (icon_view, item, 0, step);
3977 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3979 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3981 gtk_widget_child_focus (toplevel,
3982 direction == GTK_DIR_LEFT ?
3983 GTK_DIR_TAB_BACKWARD :
3984 GTK_DIR_TAB_FORWARD);
3988 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3992 if (icon_view->priv->modify_selection_pressed ||
3993 !icon_view->priv->extend_selection_pressed ||
3994 !icon_view->priv->anchor_item ||
3995 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3996 icon_view->priv->anchor_item = item;
3998 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3999 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
4001 if (!icon_view->priv->modify_selection_pressed &&
4002 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4004 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4005 dirty = gtk_icon_view_select_all_between (icon_view,
4006 icon_view->priv->anchor_item,
4010 gtk_icon_view_scroll_to_item (icon_view, item);
4013 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4017 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4020 GtkIconViewItem *item;
4022 gboolean dirty = FALSE;
4024 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4028 list = icon_view->priv->items;
4030 list = g_list_last (icon_view->priv->items);
4032 item = list ? list->data : NULL;
4034 if (item == icon_view->priv->cursor_item)
4035 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4040 if (icon_view->priv->modify_selection_pressed ||
4041 !icon_view->priv->extend_selection_pressed ||
4042 !icon_view->priv->anchor_item ||
4043 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4044 icon_view->priv->anchor_item = item;
4046 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
4048 if (!icon_view->priv->modify_selection_pressed &&
4049 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4051 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4052 dirty = gtk_icon_view_select_all_between (icon_view,
4053 icon_view->priv->anchor_item,
4057 gtk_icon_view_scroll_to_item (icon_view, item);
4060 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4064 * gtk_icon_view_scroll_to_path:
4065 * @icon_view: A #GtkIconView.
4066 * @path: The path of the item to move to.
4067 * @use_align: whether to use alignment arguments, or %FALSE.
4068 * @row_align: The vertical alignment of the item specified by @path.
4069 * @col_align: The horizontal alignment of the item specified by @path.
4071 * Moves the alignments of @icon_view to the position specified by @path.
4072 * @row_align determines where the row is placed, and @col_align determines
4073 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4074 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4077 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4078 * tree does the minimum amount of work to scroll the item onto the screen.
4079 * This means that the item will be scrolled to the edge closest to its current
4080 * position. If the item is currently visible on the screen, nothing is done.
4082 * This function only works if the model is set, and @path is a valid row on
4083 * the model. If the model changes before the @icon_view is realized, the
4084 * centered path will be modified to reflect this change.
4089 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4095 GtkIconViewItem *item = NULL;
4098 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4099 g_return_if_fail (path != NULL);
4100 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4101 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4103 widget = GTK_WIDGET (icon_view);
4105 if (gtk_tree_path_get_depth (path) > 0)
4106 item = g_list_nth_data (icon_view->priv->items,
4107 gtk_tree_path_get_indices(path)[0]);
4109 if (!item || item->cell_area.width < 0 ||
4110 !gtk_widget_get_realized (widget))
4112 if (icon_view->priv->scroll_to_path)
4113 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4115 icon_view->priv->scroll_to_path = NULL;
4118 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4120 icon_view->priv->scroll_to_use_align = use_align;
4121 icon_view->priv->scroll_to_row_align = row_align;
4122 icon_view->priv->scroll_to_col_align = col_align;
4129 GtkAllocation allocation;
4132 GdkRectangle item_area =
4134 item->cell_area.x - icon_view->priv->item_padding,
4135 item->cell_area.y - icon_view->priv->item_padding,
4136 item->cell_area.width + icon_view->priv->item_padding * 2,
4137 item->cell_area.height + icon_view->priv->item_padding * 2
4140 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4142 gtk_widget_get_allocation (widget, &allocation);
4144 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4146 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4147 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4149 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4151 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4152 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4154 gtk_adjustment_changed (icon_view->priv->hadjustment);
4155 gtk_adjustment_changed (icon_view->priv->vadjustment);
4158 gtk_icon_view_scroll_to_item (icon_view, item);
4163 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4164 GtkIconViewItem *item)
4166 GtkIconViewPrivate *priv = icon_view->priv;
4167 GtkWidget *widget = GTK_WIDGET (icon_view);
4168 GtkAdjustment *hadj, *vadj;
4169 GtkAllocation allocation;
4171 GdkRectangle item_area;
4173 item_area.x = item->cell_area.x - priv->item_padding;
4174 item_area.y = item->cell_area.y - priv->item_padding;
4175 item_area.width = item->cell_area.width + priv->item_padding * 2;
4176 item_area.height = item->cell_area.height + priv->item_padding * 2;
4178 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4179 gtk_widget_get_allocation (widget, &allocation);
4181 hadj = icon_view->priv->hadjustment;
4182 vadj = icon_view->priv->vadjustment;
4184 if (y + item_area.y < 0)
4185 gtk_adjustment_set_value (vadj,
4186 gtk_adjustment_get_value (vadj)
4188 else if (y + item_area.y + item_area.height > allocation.height)
4189 gtk_adjustment_set_value (vadj,
4190 gtk_adjustment_get_value (vadj)
4191 + y + item_area.y + item_area.height - allocation.height);
4193 if (x + item_area.x < 0)
4194 gtk_adjustment_set_value (hadj,
4195 gtk_adjustment_get_value (hadj)
4197 else if (x + item_area.x + item_area.width > allocation.width)
4198 gtk_adjustment_set_value (hadj,
4199 gtk_adjustment_get_value (hadj)
4200 + x + item_area.x + item_area.width - allocation.width);
4202 gtk_adjustment_changed (hadj);
4203 gtk_adjustment_changed (vadj);
4206 /* GtkCellLayout implementation */
4209 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4210 GtkCellArea *cell_area)
4212 GtkIconViewPrivate *priv = icon_view->priv;
4214 if (priv->cell_area)
4218 priv->cell_area = cell_area;
4220 priv->cell_area = gtk_cell_area_box_new ();
4222 g_object_ref_sink (priv->cell_area);
4224 if (GTK_IS_ORIENTABLE (priv->cell_area))
4225 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4227 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4229 priv->add_editable_id =
4230 g_signal_connect (priv->cell_area, "add-editable",
4231 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4232 priv->remove_editable_id =
4233 g_signal_connect (priv->cell_area, "remove-editable",
4234 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4236 update_text_cell (icon_view);
4237 update_pixbuf_cell (icon_view);
4240 static GtkCellArea *
4241 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4243 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4244 GtkIconViewPrivate *priv = icon_view->priv;
4246 if (G_UNLIKELY (!priv->cell_area))
4247 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4249 return icon_view->priv->cell_area;
4253 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4254 GtkIconViewItem *item)
4259 path = gtk_tree_path_new_from_indices (item->index, -1);
4260 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4262 gtk_tree_path_free (path);
4264 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4265 icon_view->priv->model,
4266 &iter, FALSE, FALSE);
4275 * gtk_icon_view_new:
4277 * Creates a new #GtkIconView widget
4279 * Return value: A newly created #GtkIconView widget
4284 gtk_icon_view_new (void)
4286 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4290 * gtk_icon_view_new_with_area:
4291 * @area: the #GtkCellArea to use to layout cells
4293 * Creates a new #GtkIconView widget using the
4294 * specified @area to layout cells inside the icons.
4296 * Return value: A newly created #GtkIconView widget
4301 gtk_icon_view_new_with_area (GtkCellArea *area)
4303 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4307 * gtk_icon_view_new_with_model:
4308 * @model: The model.
4310 * Creates a new #GtkIconView widget with the model @model.
4312 * Return value: A newly created #GtkIconView widget.
4317 gtk_icon_view_new_with_model (GtkTreeModel *model)
4319 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4323 * gtk_icon_view_convert_widget_to_bin_window_coords:
4324 * @icon_view: a #GtkIconView
4325 * @wx: X coordinate relative to the widget
4326 * @wy: Y coordinate relative to the widget
4327 * @bx: (out): return location for bin_window X coordinate
4328 * @by: (out): return location for bin_window Y coordinate
4330 * Converts widget coordinates to coordinates for the bin_window,
4331 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4336 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4344 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4346 if (icon_view->priv->bin_window)
4347 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4358 * gtk_icon_view_get_path_at_pos:
4359 * @icon_view: A #GtkIconView.
4360 * @x: The x position to be identified
4361 * @y: The y position to be identified
4363 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4364 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4365 * the cell at the specified position.
4366 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4367 * widget coordinates to bin_window coordinates.
4369 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4370 * if no icon exists at that position.
4375 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4379 GtkIconViewItem *item;
4382 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4384 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4389 path = gtk_tree_path_new_from_indices (item->index, -1);
4395 * gtk_icon_view_get_item_at_pos:
4396 * @icon_view: A #GtkIconView.
4397 * @x: The x position to be identified
4398 * @y: The y position to be identified
4399 * @path: (out) (allow-none): Return location for the path, or %NULL
4400 * @cell: (out) (allow-none): Return location for the renderer
4401 * responsible for the cell at (@x, @y), or %NULL
4403 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4404 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4405 * obtains the cell at the specified position. The returned path should
4406 * be freed with gtk_tree_path_free().
4407 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4408 * widget coordinates to bin_window coordinates.
4410 * Return value: %TRUE if an item exists at the specified position
4415 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4419 GtkCellRenderer **cell)
4421 GtkIconViewItem *item;
4422 GtkCellRenderer *renderer = NULL;
4424 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4426 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4431 *path = gtk_tree_path_new_from_indices (item->index, -1);
4439 return (item != NULL);
4443 * gtk_icon_view_set_tooltip_item:
4444 * @icon_view: a #GtkIconView
4445 * @tooltip: a #GtkTooltip
4446 * @path: a #GtkTreePath
4448 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4449 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4450 * See also gtk_tooltip_set_tip_area().
4455 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4456 GtkTooltip *tooltip,
4459 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4460 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4462 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4466 * gtk_icon_view_set_tooltip_cell:
4467 * @icon_view: a #GtkIconView
4468 * @tooltip: a #GtkTooltip
4469 * @path: a #GtkTreePath
4470 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4472 * Sets the tip area of @tooltip to the area which @cell occupies in
4473 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4475 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4480 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4481 GtkTooltip *tooltip,
4483 GtkCellRenderer *cell)
4486 GtkIconViewItem *item = NULL;
4489 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4490 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4491 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4493 if (gtk_tree_path_get_depth (path) > 0)
4494 item = g_list_nth_data (icon_view->priv->items,
4495 gtk_tree_path_get_indices(path)[0]);
4502 GtkCellAreaContext *context;
4504 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4505 _gtk_icon_view_set_cell_data (icon_view, item);
4506 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4507 GTK_WIDGET (icon_view),
4508 cell, &item->cell_area, &rect);
4512 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4513 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4514 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4515 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4518 if (icon_view->priv->bin_window)
4520 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4525 gtk_tooltip_set_tip_area (tooltip, &rect);
4530 * gtk_icon_view_get_tooltip_context:
4531 * @icon_view: an #GtkIconView
4532 * @x: (inout): the x coordinate (relative to widget coordinates)
4533 * @y: (inout): the y coordinate (relative to widget coordinates)
4534 * @keyboard_tip: whether this is a keyboard tooltip or not
4535 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4536 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4537 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4539 * This function is supposed to be used in a #GtkWidget::query-tooltip
4540 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4541 * which are received in the signal handler, should be passed to this
4542 * function without modification.
4544 * The return value indicates whether there is an icon view item at the given
4545 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4546 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4547 * @model, @path and @iter which have been provided will be set to point to
4548 * that row and the corresponding model. @x and @y will always be converted
4549 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4551 * Return value: whether or not the given tooltip context points to a item
4556 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4559 gboolean keyboard_tip,
4560 GtkTreeModel **model,
4564 GtkTreePath *tmppath = NULL;
4566 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4567 g_return_val_if_fail (x != NULL, FALSE);
4568 g_return_val_if_fail (y != NULL, FALSE);
4572 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4579 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4582 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4587 *model = gtk_icon_view_get_model (icon_view);
4590 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4596 gtk_tree_path_free (tmppath);
4602 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4605 gboolean keyboard_tip,
4606 GtkTooltip *tooltip,
4612 GtkTreeModel *model;
4613 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4615 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4618 &model, &path, &iter))
4621 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4625 gtk_tree_path_free (path);
4629 gtk_tooltip_set_markup (tooltip, str);
4630 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4632 gtk_tree_path_free (path);
4640 * gtk_icon_view_set_tooltip_column:
4641 * @icon_view: a #GtkIconView
4642 * @column: an integer, which is a valid column number for @icon_view's model
4644 * If you only plan to have simple (text-only) tooltips on full items, you
4645 * can use this function to have #GtkIconView handle these automatically
4646 * for you. @column should be set to the column in @icon_view's model
4647 * containing the tooltip texts, or -1 to disable this feature.
4649 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4650 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4652 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4653 * so &, <, etc have to be escaped in the text.
4658 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4661 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4663 if (column == icon_view->priv->tooltip_column)
4668 g_signal_handlers_disconnect_by_func (icon_view,
4669 gtk_icon_view_set_tooltip_query_cb,
4671 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4675 if (icon_view->priv->tooltip_column == -1)
4677 g_signal_connect (icon_view, "query-tooltip",
4678 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4679 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4683 icon_view->priv->tooltip_column = column;
4684 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4688 * gtk_icon_view_get_tooltip_column:
4689 * @icon_view: a #GtkIconView
4691 * Returns the column of @icon_view's model which is being used for
4692 * displaying tooltips on @icon_view's rows.
4694 * Return value: the index of the tooltip column that is currently being
4695 * used, or -1 if this is disabled.
4700 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4702 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4704 return icon_view->priv->tooltip_column;
4708 * gtk_icon_view_get_visible_range:
4709 * @icon_view: A #GtkIconView
4710 * @start_path: (out) (allow-none): Return location for start of region,
4712 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4714 * Sets @start_path and @end_path to be the first and last visible path.
4715 * Note that there may be invisible paths in between.
4717 * Both paths should be freed with gtk_tree_path_free() after use.
4719 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4724 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4725 GtkTreePath **start_path,
4726 GtkTreePath **end_path)
4728 gint start_index = -1;
4729 gint end_index = -1;
4732 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4734 if (icon_view->priv->hadjustment == NULL ||
4735 icon_view->priv->vadjustment == NULL)
4738 if (start_path == NULL && end_path == NULL)
4741 for (icons = icon_view->priv->items; icons; icons = icons->next)
4743 GtkIconViewItem *item = icons->data;
4744 GdkRectangle *item_area = &item->cell_area;
4746 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4747 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4749 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4750 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4752 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4753 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4755 if (start_index == -1)
4756 start_index = item->index;
4757 end_index = item->index;
4761 if (start_path && start_index != -1)
4762 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4763 if (end_path && end_index != -1)
4764 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4766 return start_index != -1;
4770 * gtk_icon_view_selected_foreach:
4771 * @icon_view: A #GtkIconView.
4772 * @func: (scope call): The function to call for each selected icon.
4773 * @data: User data to pass to the function.
4775 * Calls a function for each selected icon. Note that the model or
4776 * selection cannot be modified from within this function.
4781 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4782 GtkIconViewForeachFunc func,
4787 for (list = icon_view->priv->items; list; list = list->next)
4789 GtkIconViewItem *item = list->data;
4790 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4793 (* func) (icon_view, path, data);
4795 gtk_tree_path_free (path);
4800 * gtk_icon_view_set_selection_mode:
4801 * @icon_view: A #GtkIconView.
4802 * @mode: The selection mode
4804 * Sets the selection mode of the @icon_view.
4809 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4810 GtkSelectionMode mode)
4812 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4814 if (mode == icon_view->priv->selection_mode)
4817 if (mode == GTK_SELECTION_NONE ||
4818 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4819 gtk_icon_view_unselect_all (icon_view);
4821 icon_view->priv->selection_mode = mode;
4823 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4827 * gtk_icon_view_get_selection_mode:
4828 * @icon_view: A #GtkIconView.
4830 * Gets the selection mode of the @icon_view.
4832 * Return value: the current selection mode
4837 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4839 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4841 return icon_view->priv->selection_mode;
4845 * gtk_icon_view_set_model:
4846 * @icon_view: A #GtkIconView.
4847 * @model: (allow-none): The model.
4849 * Sets the model for a #GtkIconView.
4850 * If the @icon_view already has a model set, it will remove
4851 * it before setting the new model. If @model is %NULL, then
4852 * it will unset the old model.
4857 gtk_icon_view_set_model (GtkIconView *icon_view,
4858 GtkTreeModel *model)
4860 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4861 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4863 if (icon_view->priv->model == model)
4866 if (icon_view->priv->scroll_to_path)
4868 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4869 icon_view->priv->scroll_to_path = NULL;
4872 /* The area can be NULL while disposing */
4873 if (icon_view->priv->cell_area)
4874 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4880 if (icon_view->priv->pixbuf_column != -1)
4882 column_type = gtk_tree_model_get_column_type (model,
4883 icon_view->priv->pixbuf_column);
4885 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4888 if (icon_view->priv->text_column != -1)
4890 column_type = gtk_tree_model_get_column_type (model,
4891 icon_view->priv->text_column);
4893 g_return_if_fail (column_type == G_TYPE_STRING);
4896 if (icon_view->priv->markup_column != -1)
4898 column_type = gtk_tree_model_get_column_type (model,
4899 icon_view->priv->markup_column);
4901 g_return_if_fail (column_type == G_TYPE_STRING);
4906 if (icon_view->priv->model)
4908 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4909 gtk_icon_view_row_changed,
4911 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4912 gtk_icon_view_row_inserted,
4914 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4915 gtk_icon_view_row_deleted,
4917 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4918 gtk_icon_view_rows_reordered,
4921 g_object_unref (icon_view->priv->model);
4923 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4924 icon_view->priv->items = NULL;
4925 icon_view->priv->anchor_item = NULL;
4926 icon_view->priv->cursor_item = NULL;
4927 icon_view->priv->last_single_clicked = NULL;
4928 icon_view->priv->last_prelight = NULL;
4929 icon_view->priv->width = 0;
4930 icon_view->priv->height = 0;
4933 icon_view->priv->model = model;
4935 if (icon_view->priv->model)
4937 g_object_ref (icon_view->priv->model);
4938 g_signal_connect (icon_view->priv->model,
4940 G_CALLBACK (gtk_icon_view_row_changed),
4942 g_signal_connect (icon_view->priv->model,
4944 G_CALLBACK (gtk_icon_view_row_inserted),
4946 g_signal_connect (icon_view->priv->model,
4948 G_CALLBACK (gtk_icon_view_row_deleted),
4950 g_signal_connect (icon_view->priv->model,
4952 G_CALLBACK (gtk_icon_view_rows_reordered),
4955 gtk_icon_view_build_items (icon_view);
4958 g_object_notify (G_OBJECT (icon_view), "model");
4960 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4964 * gtk_icon_view_get_model:
4965 * @icon_view: a #GtkIconView
4967 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4970 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4971 * currently being used.
4976 gtk_icon_view_get_model (GtkIconView *icon_view)
4978 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4980 return icon_view->priv->model;
4984 update_text_cell (GtkIconView *icon_view)
4986 if (!icon_view->priv->cell_area)
4989 if (icon_view->priv->text_column == -1 &&
4990 icon_view->priv->markup_column == -1)
4992 if (icon_view->priv->text_cell != NULL)
4994 gtk_cell_area_remove (icon_view->priv->cell_area,
4995 icon_view->priv->text_cell);
4996 icon_view->priv->text_cell = NULL;
5001 if (icon_view->priv->text_cell == NULL)
5003 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
5005 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
5008 if (icon_view->priv->markup_column != -1)
5009 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5010 icon_view->priv->text_cell,
5011 "markup", icon_view->priv->markup_column,
5014 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5015 icon_view->priv->text_cell,
5016 "text", icon_view->priv->text_column,
5019 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5020 g_object_set (icon_view->priv->text_cell,
5021 "alignment", PANGO_ALIGN_CENTER,
5022 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5027 g_object_set (icon_view->priv->text_cell,
5028 "alignment", PANGO_ALIGN_LEFT,
5029 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5037 update_pixbuf_cell (GtkIconView *icon_view)
5039 if (!icon_view->priv->cell_area)
5042 if (icon_view->priv->pixbuf_column == -1)
5044 if (icon_view->priv->pixbuf_cell != NULL)
5046 gtk_cell_area_remove (icon_view->priv->cell_area,
5047 icon_view->priv->pixbuf_cell);
5049 icon_view->priv->pixbuf_cell = NULL;
5054 if (icon_view->priv->pixbuf_cell == NULL)
5056 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
5058 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
5061 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5062 icon_view->priv->pixbuf_cell,
5063 "pixbuf", icon_view->priv->pixbuf_column,
5066 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5067 g_object_set (icon_view->priv->pixbuf_cell,
5072 g_object_set (icon_view->priv->pixbuf_cell,
5080 * gtk_icon_view_set_text_column:
5081 * @icon_view: A #GtkIconView.
5082 * @column: A column in the currently used model, or -1 to display no text
5084 * Sets the column with text for @icon_view to be @column. The text
5085 * column must be of type #G_TYPE_STRING.
5090 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5093 if (column == icon_view->priv->text_column)
5097 icon_view->priv->text_column = -1;
5100 if (icon_view->priv->model != NULL)
5104 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5106 g_return_if_fail (column_type == G_TYPE_STRING);
5109 icon_view->priv->text_column = column;
5112 if (icon_view->priv->cell_area)
5113 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5115 update_text_cell (icon_view);
5117 gtk_icon_view_invalidate_sizes (icon_view);
5119 g_object_notify (G_OBJECT (icon_view), "text-column");
5123 * gtk_icon_view_get_text_column:
5124 * @icon_view: A #GtkIconView.
5126 * Returns the column with text for @icon_view.
5128 * Returns: the text column, or -1 if it's unset.
5133 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5135 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5137 return icon_view->priv->text_column;
5141 * gtk_icon_view_set_markup_column:
5142 * @icon_view: A #GtkIconView.
5143 * @column: A column in the currently used model, or -1 to display no text
5145 * Sets the column with markup information for @icon_view to be
5146 * @column. The markup column must be of type #G_TYPE_STRING.
5147 * If the markup column is set to something, it overrides
5148 * the text column set by gtk_icon_view_set_text_column().
5153 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5156 if (column == icon_view->priv->markup_column)
5160 icon_view->priv->markup_column = -1;
5163 if (icon_view->priv->model != NULL)
5167 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5169 g_return_if_fail (column_type == G_TYPE_STRING);
5172 icon_view->priv->markup_column = column;
5175 if (icon_view->priv->cell_area)
5176 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5178 update_text_cell (icon_view);
5180 gtk_icon_view_invalidate_sizes (icon_view);
5182 g_object_notify (G_OBJECT (icon_view), "markup-column");
5186 * gtk_icon_view_get_markup_column:
5187 * @icon_view: A #GtkIconView.
5189 * Returns the column with markup text for @icon_view.
5191 * Returns: the markup column, or -1 if it's unset.
5196 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5198 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5200 return icon_view->priv->markup_column;
5204 * gtk_icon_view_set_pixbuf_column:
5205 * @icon_view: A #GtkIconView.
5206 * @column: A column in the currently used model, or -1 to disable
5208 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5209 * column must be of type #GDK_TYPE_PIXBUF
5214 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5217 if (column == icon_view->priv->pixbuf_column)
5221 icon_view->priv->pixbuf_column = -1;
5224 if (icon_view->priv->model != NULL)
5228 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5230 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5233 icon_view->priv->pixbuf_column = column;
5236 if (icon_view->priv->cell_area)
5237 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5239 update_pixbuf_cell (icon_view);
5241 gtk_icon_view_invalidate_sizes (icon_view);
5243 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5248 * gtk_icon_view_get_pixbuf_column:
5249 * @icon_view: A #GtkIconView.
5251 * Returns the column with pixbufs for @icon_view.
5253 * Returns: the pixbuf column, or -1 if it's unset.
5258 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5260 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5262 return icon_view->priv->pixbuf_column;
5266 * gtk_icon_view_select_path:
5267 * @icon_view: A #GtkIconView.
5268 * @path: The #GtkTreePath to be selected.
5270 * Selects the row at @path.
5275 gtk_icon_view_select_path (GtkIconView *icon_view,
5278 GtkIconViewItem *item = NULL;
5280 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5281 g_return_if_fail (icon_view->priv->model != NULL);
5282 g_return_if_fail (path != NULL);
5284 if (gtk_tree_path_get_depth (path) > 0)
5285 item = g_list_nth_data (icon_view->priv->items,
5286 gtk_tree_path_get_indices(path)[0]);
5289 _gtk_icon_view_select_item (icon_view, item);
5293 * gtk_icon_view_unselect_path:
5294 * @icon_view: A #GtkIconView.
5295 * @path: The #GtkTreePath to be unselected.
5297 * Unselects the row at @path.
5302 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5305 GtkIconViewItem *item;
5307 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5308 g_return_if_fail (icon_view->priv->model != NULL);
5309 g_return_if_fail (path != NULL);
5311 item = g_list_nth_data (icon_view->priv->items,
5312 gtk_tree_path_get_indices(path)[0]);
5317 _gtk_icon_view_unselect_item (icon_view, item);
5321 * gtk_icon_view_get_selected_items:
5322 * @icon_view: A #GtkIconView.
5324 * Creates a list of paths of all selected items. Additionally, if you are
5325 * planning on modifying the model after calling this function, you may
5326 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5327 * To do this, you can use gtk_tree_row_reference_new().
5329 * To free the return value, use:
5331 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5334 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5339 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5342 GList *selected = NULL;
5344 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5346 for (list = icon_view->priv->items; list != NULL; list = list->next)
5348 GtkIconViewItem *item = list->data;
5352 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5354 selected = g_list_prepend (selected, path);
5362 * gtk_icon_view_select_all:
5363 * @icon_view: A #GtkIconView.
5365 * Selects all the icons. @icon_view must has its selection mode set
5366 * to #GTK_SELECTION_MULTIPLE.
5371 gtk_icon_view_select_all (GtkIconView *icon_view)
5374 gboolean dirty = FALSE;
5376 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5378 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5381 for (items = icon_view->priv->items; items; items = items->next)
5383 GtkIconViewItem *item = items->data;
5385 if (!item->selected)
5388 item->selected = TRUE;
5389 gtk_icon_view_queue_draw_item (icon_view, item);
5394 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5398 * gtk_icon_view_unselect_all:
5399 * @icon_view: A #GtkIconView.
5401 * Unselects all the icons.
5406 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5408 gboolean dirty = FALSE;
5410 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5412 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5415 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5418 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5422 * gtk_icon_view_path_is_selected:
5423 * @icon_view: A #GtkIconView.
5424 * @path: A #GtkTreePath to check selection on.
5426 * Returns %TRUE if the icon pointed to by @path is currently
5427 * selected. If @path does not point to a valid location, %FALSE is returned.
5429 * Return value: %TRUE if @path is selected.
5434 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5437 GtkIconViewItem *item;
5439 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5440 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5441 g_return_val_if_fail (path != NULL, FALSE);
5443 item = g_list_nth_data (icon_view->priv->items,
5444 gtk_tree_path_get_indices(path)[0]);
5449 return item->selected;
5453 * gtk_icon_view_get_item_row:
5454 * @icon_view: a #GtkIconView
5455 * @path: the #GtkTreePath of the item
5457 * Gets the row in which the item @path is currently
5458 * displayed. Row numbers start at 0.
5460 * Returns: The row in which the item is displayed
5465 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5468 GtkIconViewItem *item;
5470 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5471 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5472 g_return_val_if_fail (path != NULL, -1);
5474 item = g_list_nth_data (icon_view->priv->items,
5475 gtk_tree_path_get_indices(path)[0]);
5484 * gtk_icon_view_get_item_column:
5485 * @icon_view: a #GtkIconView
5486 * @path: the #GtkTreePath of the item
5488 * Gets the column in which the item @path is currently
5489 * displayed. Column numbers start at 0.
5491 * Returns: The column in which the item is displayed
5496 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5499 GtkIconViewItem *item;
5501 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5502 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5503 g_return_val_if_fail (path != NULL, -1);
5505 item = g_list_nth_data (icon_view->priv->items,
5506 gtk_tree_path_get_indices(path)[0]);
5515 * gtk_icon_view_item_activated:
5516 * @icon_view: A #GtkIconView
5517 * @path: The #GtkTreePath to be activated
5519 * Activates the item determined by @path.
5524 gtk_icon_view_item_activated (GtkIconView *icon_view,
5527 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5528 g_return_if_fail (path != NULL);
5530 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5534 * gtk_icon_view_set_item_orientation:
5535 * @icon_view: a #GtkIconView
5536 * @orientation: the relative position of texts and icons
5538 * Sets the ::item-orientation property which determines whether the labels
5539 * are drawn beside the icons instead of below.
5544 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5545 GtkOrientation orientation)
5547 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5549 if (icon_view->priv->item_orientation != orientation)
5551 icon_view->priv->item_orientation = orientation;
5553 if (icon_view->priv->cell_area)
5555 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5556 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5557 icon_view->priv->item_orientation);
5559 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5562 gtk_icon_view_invalidate_sizes (icon_view);
5564 update_text_cell (icon_view);
5565 update_pixbuf_cell (icon_view);
5567 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5572 * gtk_icon_view_get_item_orientation:
5573 * @icon_view: a #GtkIconView
5575 * Returns the value of the ::item-orientation property which determines
5576 * whether the labels are drawn beside the icons instead of below.
5578 * Return value: the relative position of texts and icons
5583 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5585 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5586 GTK_ORIENTATION_VERTICAL);
5588 return icon_view->priv->item_orientation;
5592 * gtk_icon_view_set_columns:
5593 * @icon_view: a #GtkIconView
5594 * @columns: the number of columns
5596 * Sets the ::columns property which determines in how
5597 * many columns the icons are arranged. If @columns is
5598 * -1, the number of columns will be chosen automatically
5599 * to fill the available area.
5604 gtk_icon_view_set_columns (GtkIconView *icon_view,
5607 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5609 if (icon_view->priv->columns != columns)
5611 icon_view->priv->columns = columns;
5613 if (icon_view->priv->cell_area)
5614 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5616 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5618 g_object_notify (G_OBJECT (icon_view), "columns");
5623 * gtk_icon_view_get_columns:
5624 * @icon_view: a #GtkIconView
5626 * Returns the value of the ::columns property.
5628 * Return value: the number of columns, or -1
5633 gtk_icon_view_get_columns (GtkIconView *icon_view)
5635 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5637 return icon_view->priv->columns;
5641 * gtk_icon_view_set_item_width:
5642 * @icon_view: a #GtkIconView
5643 * @item_width: the width for each item
5645 * Sets the ::item-width property which specifies the width
5646 * to use for each item. If it is set to -1, the icon view will
5647 * automatically determine a suitable item size.
5652 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5655 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5657 if (icon_view->priv->item_width != item_width)
5659 icon_view->priv->item_width = item_width;
5661 if (icon_view->priv->cell_area)
5662 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5664 gtk_icon_view_invalidate_sizes (icon_view);
5666 update_text_cell (icon_view);
5668 g_object_notify (G_OBJECT (icon_view), "item-width");
5673 * gtk_icon_view_get_item_width:
5674 * @icon_view: a #GtkIconView
5676 * Returns the value of the ::item-width property.
5678 * Return value: the width of a single item, or -1
5683 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5685 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5687 return icon_view->priv->item_width;
5692 * gtk_icon_view_set_spacing:
5693 * @icon_view: a #GtkIconView
5694 * @spacing: the spacing
5696 * Sets the ::spacing property which specifies the space
5697 * which is inserted between the cells (i.e. the icon and
5698 * the text) of an item.
5703 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5706 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5708 if (icon_view->priv->spacing != spacing)
5710 icon_view->priv->spacing = spacing;
5712 if (icon_view->priv->cell_area)
5713 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5715 gtk_icon_view_invalidate_sizes (icon_view);
5717 g_object_notify (G_OBJECT (icon_view), "spacing");
5722 * gtk_icon_view_get_spacing:
5723 * @icon_view: a #GtkIconView
5725 * Returns the value of the ::spacing property.
5727 * Return value: the space between cells
5732 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5734 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5736 return icon_view->priv->spacing;
5740 * gtk_icon_view_set_row_spacing:
5741 * @icon_view: a #GtkIconView
5742 * @row_spacing: the row spacing
5744 * Sets the ::row-spacing property which specifies the space
5745 * which is inserted between the rows of the icon view.
5750 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5753 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5755 if (icon_view->priv->row_spacing != row_spacing)
5757 icon_view->priv->row_spacing = row_spacing;
5759 if (icon_view->priv->cell_area)
5760 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5762 gtk_icon_view_invalidate_sizes (icon_view);
5764 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5769 * gtk_icon_view_get_row_spacing:
5770 * @icon_view: a #GtkIconView
5772 * Returns the value of the ::row-spacing property.
5774 * Return value: the space between rows
5779 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5781 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5783 return icon_view->priv->row_spacing;
5787 * gtk_icon_view_set_column_spacing:
5788 * @icon_view: a #GtkIconView
5789 * @column_spacing: the column spacing
5791 * Sets the ::column-spacing property which specifies the space
5792 * which is inserted between the columns of the icon view.
5797 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5798 gint column_spacing)
5800 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5802 if (icon_view->priv->column_spacing != column_spacing)
5804 icon_view->priv->column_spacing = column_spacing;
5806 if (icon_view->priv->cell_area)
5807 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5809 gtk_icon_view_invalidate_sizes (icon_view);
5811 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5816 * gtk_icon_view_get_column_spacing:
5817 * @icon_view: a #GtkIconView
5819 * Returns the value of the ::column-spacing property.
5821 * Return value: the space between columns
5826 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5828 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5830 return icon_view->priv->column_spacing;
5834 * gtk_icon_view_set_margin:
5835 * @icon_view: a #GtkIconView
5836 * @margin: the margin
5838 * Sets the ::margin property which specifies the space
5839 * which is inserted at the top, bottom, left and right
5845 gtk_icon_view_set_margin (GtkIconView *icon_view,
5848 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5850 if (icon_view->priv->margin != margin)
5852 icon_view->priv->margin = margin;
5854 if (icon_view->priv->cell_area)
5855 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5857 gtk_icon_view_invalidate_sizes (icon_view);
5859 g_object_notify (G_OBJECT (icon_view), "margin");
5864 * gtk_icon_view_get_margin:
5865 * @icon_view: a #GtkIconView
5867 * Returns the value of the ::margin property.
5869 * Return value: the space at the borders
5874 gtk_icon_view_get_margin (GtkIconView *icon_view)
5876 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5878 return icon_view->priv->margin;
5882 * gtk_icon_view_set_item_padding:
5883 * @icon_view: a #GtkIconView
5884 * @item_padding: the item padding
5886 * Sets the #GtkIconView:item-padding property which specifies the padding
5887 * around each of the icon view's items.
5892 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5895 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5897 if (icon_view->priv->item_padding != item_padding)
5899 icon_view->priv->item_padding = item_padding;
5901 if (icon_view->priv->cell_area)
5902 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5904 gtk_icon_view_invalidate_sizes (icon_view);
5906 g_object_notify (G_OBJECT (icon_view), "item-padding");
5911 * gtk_icon_view_get_item_padding:
5912 * @icon_view: a #GtkIconView
5914 * Returns the value of the ::item-padding property.
5916 * Return value: the padding around items
5921 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5923 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5925 return icon_view->priv->item_padding;
5928 /* Get/set whether drag_motion requested the drag data and
5929 * drag_data_received should thus not actually insert the data,
5930 * since the data doesn't result from a drop.
5933 set_status_pending (GdkDragContext *context,
5934 GdkDragAction suggested_action)
5936 g_object_set_data (G_OBJECT (context),
5937 I_("gtk-icon-view-status-pending"),
5938 GINT_TO_POINTER (suggested_action));
5941 static GdkDragAction
5942 get_status_pending (GdkDragContext *context)
5944 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5945 "gtk-icon-view-status-pending"));
5949 unset_reorderable (GtkIconView *icon_view)
5951 if (icon_view->priv->reorderable)
5953 icon_view->priv->reorderable = FALSE;
5954 g_object_notify (G_OBJECT (icon_view), "reorderable");
5959 set_source_row (GdkDragContext *context,
5960 GtkTreeModel *model,
5961 GtkTreePath *source_row)
5964 g_object_set_data_full (G_OBJECT (context),
5965 I_("gtk-icon-view-source-row"),
5966 gtk_tree_row_reference_new (model, source_row),
5967 (GDestroyNotify) gtk_tree_row_reference_free);
5969 g_object_set_data_full (G_OBJECT (context),
5970 I_("gtk-icon-view-source-row"),
5975 get_source_row (GdkDragContext *context)
5977 GtkTreeRowReference *ref;
5979 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5982 return gtk_tree_row_reference_get_path (ref);
5989 GtkTreeRowReference *dest_row;
5990 gboolean empty_view_drop;
5991 gboolean drop_append_mode;
5995 dest_row_free (gpointer data)
5997 DestRow *dr = (DestRow *)data;
5999 gtk_tree_row_reference_free (dr->dest_row);
6004 set_dest_row (GdkDragContext *context,
6005 GtkTreeModel *model,
6006 GtkTreePath *dest_row,
6007 gboolean empty_view_drop,
6008 gboolean drop_append_mode)
6014 g_object_set_data_full (G_OBJECT (context),
6015 I_("gtk-icon-view-dest-row"),
6020 dr = g_new0 (DestRow, 1);
6022 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6023 dr->empty_view_drop = empty_view_drop;
6024 dr->drop_append_mode = drop_append_mode;
6025 g_object_set_data_full (G_OBJECT (context),
6026 I_("gtk-icon-view-dest-row"),
6027 dr, (GDestroyNotify) dest_row_free);
6031 get_dest_row (GdkDragContext *context)
6035 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6039 GtkTreePath *path = NULL;
6042 path = gtk_tree_row_reference_get_path (dr->dest_row);
6043 else if (dr->empty_view_drop)
6044 path = gtk_tree_path_new_from_indices (0, -1);
6048 if (path && dr->drop_append_mode)
6049 gtk_tree_path_next (path);
6058 check_model_dnd (GtkTreeModel *model,
6059 GType required_iface,
6060 const gchar *signal)
6062 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6064 g_warning ("You must override the default '%s' handler "
6065 "on GtkIconView when using models that don't support "
6066 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6067 "is to connect to '%s' and call "
6068 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6069 "the default handler from running. Look at the source code "
6070 "for the default handler in gtkiconview.c to get an idea what "
6071 "your handler should do. (gtkiconview.c is in the GTK+ source "
6072 "code.) If you're using GTK+ from a language other than C, "
6073 "there may be a more natural way to override default handlers, e.g. via derivation.",
6074 signal, g_type_name (required_iface), signal);
6082 remove_scroll_timeout (GtkIconView *icon_view)
6084 if (icon_view->priv->scroll_timeout_id != 0)
6086 g_source_remove (icon_view->priv->scroll_timeout_id);
6088 icon_view->priv->scroll_timeout_id = 0;
6093 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6097 gint px, py, width, height;
6098 gint hoffset, voffset;
6100 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6102 gdk_window_get_device_position (window, device, &px, &py, NULL);
6103 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
6105 /* see if we are near the edge. */
6106 voffset = py - 2 * SCROLL_EDGE_SIZE;
6108 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
6110 hoffset = px - 2 * SCROLL_EDGE_SIZE;
6112 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
6115 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6116 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6119 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6120 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6124 GtkIconView *icon_view;
6129 drag_scroll_timeout (gpointer datap)
6131 DragScrollData *data = datap;
6133 gtk_icon_view_autoscroll (data->icon_view, data->device);
6139 drag_scroll_data_free (DragScrollData *data)
6141 g_slice_free (DragScrollData, data);
6145 set_destination (GtkIconView *icon_view,
6146 GdkDragContext *context,
6149 GdkDragAction *suggested_action,
6153 GtkTreePath *path = NULL;
6154 GtkIconViewDropPosition pos;
6155 GtkIconViewDropPosition old_pos;
6156 GtkTreePath *old_dest_path = NULL;
6157 gboolean can_drop = FALSE;
6159 widget = GTK_WIDGET (icon_view);
6161 *suggested_action = 0;
6164 if (!icon_view->priv->dest_set)
6166 /* someone unset us as a drag dest, note that if
6167 * we return FALSE drag_leave isn't called
6170 gtk_icon_view_set_drag_dest_item (icon_view,
6172 GTK_ICON_VIEW_DROP_LEFT);
6174 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6176 return FALSE; /* no longer a drop site */
6179 *target = gtk_drag_dest_find_target (widget, context,
6180 gtk_drag_dest_get_target_list (widget));
6181 if (*target == GDK_NONE)
6184 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6187 GtkTreeModel *model;
6189 /* the row got dropped on empty space, let's setup a special case
6193 gtk_tree_path_free (path);
6195 model = gtk_icon_view_get_model (icon_view);
6197 n_children = gtk_tree_model_iter_n_children (model, NULL);
6200 pos = GTK_ICON_VIEW_DROP_BELOW;
6201 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6205 pos = GTK_ICON_VIEW_DROP_ABOVE;
6206 path = gtk_tree_path_new_from_indices (0, -1);
6216 gtk_icon_view_get_drag_dest_item (icon_view,
6221 gtk_tree_path_free (old_dest_path);
6223 if (TRUE /* FIXME if the location droppable predicate */)
6231 GtkWidget *source_widget;
6233 *suggested_action = gdk_drag_context_get_suggested_action (context);
6234 source_widget = gtk_drag_get_source_widget (context);
6236 if (source_widget == widget)
6238 /* Default to MOVE, unless the user has
6239 * pressed ctrl or shift to affect available actions
6241 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6242 *suggested_action = GDK_ACTION_MOVE;
6245 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6250 /* can't drop here */
6251 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6253 GTK_ICON_VIEW_DROP_LEFT);
6257 gtk_tree_path_free (path);
6263 get_logical_destination (GtkIconView *icon_view,
6264 gboolean *drop_append_mode)
6266 /* adjust path to point to the row the drop goes in front of */
6267 GtkTreePath *path = NULL;
6268 GtkIconViewDropPosition pos;
6270 *drop_append_mode = FALSE;
6272 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6277 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6278 pos == GTK_ICON_VIEW_DROP_BELOW)
6281 GtkTreeModel *model = icon_view->priv->model;
6283 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6284 !gtk_tree_model_iter_next (model, &iter))
6285 *drop_append_mode = TRUE;
6288 *drop_append_mode = FALSE;
6289 gtk_tree_path_next (path);
6297 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6298 GdkEventMotion *event)
6300 GtkWidget *widget = GTK_WIDGET (icon_view);
6301 GdkDragContext *context;
6302 GtkTreePath *path = NULL;
6304 GtkTreeModel *model;
6305 gboolean retval = FALSE;
6307 if (!icon_view->priv->source_set)
6310 if (icon_view->priv->pressed_button < 0)
6313 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6314 icon_view->priv->press_start_x,
6315 icon_view->priv->press_start_y,
6316 event->x, event->y))
6319 model = gtk_icon_view_get_model (icon_view);
6324 button = icon_view->priv->pressed_button;
6325 icon_view->priv->pressed_button = -1;
6327 path = gtk_icon_view_get_path_at_pos (icon_view,
6328 icon_view->priv->press_start_x,
6329 icon_view->priv->press_start_y);
6334 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6335 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6339 /* FIXME Check whether we're a start button, if not return FALSE and
6343 /* Now we can begin the drag */
6347 context = gtk_drag_begin (widget,
6348 gtk_drag_source_get_target_list (widget),
6349 icon_view->priv->source_actions,
6353 set_source_row (context, model, path);
6357 gtk_tree_path_free (path);
6362 /* Source side drag signals */
6364 gtk_icon_view_drag_begin (GtkWidget *widget,
6365 GdkDragContext *context)
6367 GtkIconView *icon_view;
6368 GtkIconViewItem *item;
6369 cairo_surface_t *icon;
6373 icon_view = GTK_ICON_VIEW (widget);
6375 /* if the user uses a custom DnD impl, we don't set the icon here */
6376 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6379 item = _gtk_icon_view_get_item_at_coords (icon_view,
6380 icon_view->priv->press_start_x,
6381 icon_view->priv->press_start_y,
6385 g_return_if_fail (item != NULL);
6387 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6388 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6390 path = gtk_tree_path_new_from_indices (item->index, -1);
6391 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6392 gtk_tree_path_free (path);
6394 cairo_surface_set_device_offset (icon, -x, -y);
6396 gtk_drag_set_icon_surface (context, icon);
6398 cairo_surface_destroy (icon);
6402 gtk_icon_view_drag_end (GtkWidget *widget,
6403 GdkDragContext *context)
6409 gtk_icon_view_drag_data_get (GtkWidget *widget,
6410 GdkDragContext *context,
6411 GtkSelectionData *selection_data,
6415 GtkIconView *icon_view;
6416 GtkTreeModel *model;
6417 GtkTreePath *source_row;
6419 icon_view = GTK_ICON_VIEW (widget);
6420 model = gtk_icon_view_get_model (icon_view);
6425 if (!icon_view->priv->source_set)
6428 source_row = get_source_row (context);
6430 if (source_row == NULL)
6433 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6434 * any model; for DragSource models there are some other targets
6438 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6439 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6444 /* If drag_data_get does nothing, try providing row data. */
6445 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6446 gtk_tree_set_row_drag_data (selection_data,
6451 gtk_tree_path_free (source_row);
6455 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6456 GdkDragContext *context)
6458 GtkTreeModel *model;
6459 GtkIconView *icon_view;
6460 GtkTreePath *source_row;
6462 icon_view = GTK_ICON_VIEW (widget);
6463 model = gtk_icon_view_get_model (icon_view);
6465 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6468 if (!icon_view->priv->source_set)
6471 source_row = get_source_row (context);
6473 if (source_row == NULL)
6476 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6479 gtk_tree_path_free (source_row);
6481 set_source_row (context, NULL, NULL);
6484 /* Target side drag signals */
6486 gtk_icon_view_drag_leave (GtkWidget *widget,
6487 GdkDragContext *context,
6490 GtkIconView *icon_view;
6492 icon_view = GTK_ICON_VIEW (widget);
6494 /* unset any highlight row */
6495 gtk_icon_view_set_drag_dest_item (icon_view,
6497 GTK_ICON_VIEW_DROP_LEFT);
6499 remove_scroll_timeout (icon_view);
6503 gtk_icon_view_drag_motion (GtkWidget *widget,
6504 GdkDragContext *context,
6509 GtkTreePath *path = NULL;
6510 GtkIconViewDropPosition pos;
6511 GtkIconView *icon_view;
6512 GdkDragAction suggested_action = 0;
6516 icon_view = GTK_ICON_VIEW (widget);
6518 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6521 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6523 /* we only know this *after* set_desination_row */
6524 empty = icon_view->priv->empty_view_drop;
6526 if (path == NULL && !empty)
6528 /* Can't drop here. */
6529 gdk_drag_status (context, 0, time);
6533 if (icon_view->priv->scroll_timeout_id == 0)
6535 DragScrollData *data = g_slice_new (DragScrollData);
6536 data->icon_view = icon_view;
6537 data->device = gdk_drag_context_get_device (context);
6539 icon_view->priv->scroll_timeout_id =
6540 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6543 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6545 /* Request data so we can use the source row when
6546 * determining whether to accept the drop
6548 set_status_pending (context, suggested_action);
6549 gtk_drag_get_data (widget, context, target, time);
6553 set_status_pending (context, 0);
6554 gdk_drag_status (context, suggested_action, time);
6559 gtk_tree_path_free (path);
6565 gtk_icon_view_drag_drop (GtkWidget *widget,
6566 GdkDragContext *context,
6571 GtkIconView *icon_view;
6573 GdkDragAction suggested_action = 0;
6574 GdkAtom target = GDK_NONE;
6575 GtkTreeModel *model;
6576 gboolean drop_append_mode;
6578 icon_view = GTK_ICON_VIEW (widget);
6579 model = gtk_icon_view_get_model (icon_view);
6581 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6583 if (!icon_view->priv->dest_set)
6586 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6589 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6592 path = get_logical_destination (icon_view, &drop_append_mode);
6594 if (target != GDK_NONE && path != NULL)
6596 /* in case a motion had requested drag data, change things so we
6597 * treat drag data receives as a drop.
6599 set_status_pending (context, 0);
6600 set_dest_row (context, model, path,
6601 icon_view->priv->empty_view_drop, drop_append_mode);
6605 gtk_tree_path_free (path);
6607 /* Unset this thing */
6608 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6610 if (target != GDK_NONE)
6612 gtk_drag_get_data (widget, context, target, time);
6620 gtk_icon_view_drag_data_received (GtkWidget *widget,
6621 GdkDragContext *context,
6624 GtkSelectionData *selection_data,
6629 gboolean accepted = FALSE;
6630 GtkTreeModel *model;
6631 GtkIconView *icon_view;
6632 GtkTreePath *dest_row;
6633 GdkDragAction suggested_action;
6634 gboolean drop_append_mode;
6636 icon_view = GTK_ICON_VIEW (widget);
6637 model = gtk_icon_view_get_model (icon_view);
6639 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6642 if (!icon_view->priv->dest_set)
6645 suggested_action = get_status_pending (context);
6647 if (suggested_action)
6649 /* We are getting this data due to a request in drag_motion,
6650 * rather than due to a request in drag_drop, so we are just
6651 * supposed to call drag_status, not actually paste in the
6654 path = get_logical_destination (icon_view, &drop_append_mode);
6657 suggested_action = 0;
6659 if (suggested_action)
6661 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6664 suggested_action = 0;
6667 gdk_drag_status (context, suggested_action, time);
6670 gtk_tree_path_free (path);
6672 /* If you can't drop, remove user drop indicator until the next motion */
6673 if (suggested_action == 0)
6674 gtk_icon_view_set_drag_dest_item (icon_view,
6676 GTK_ICON_VIEW_DROP_LEFT);
6681 dest_row = get_dest_row (context);
6683 if (dest_row == NULL)
6686 if (gtk_selection_data_get_length (selection_data) >= 0)
6688 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6694 gtk_drag_finish (context,
6696 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6699 gtk_tree_path_free (dest_row);
6702 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6705 /* Drag-and-Drop support */
6707 * gtk_icon_view_enable_model_drag_source:
6708 * @icon_view: a #GtkIconTreeView
6709 * @start_button_mask: Mask of allowed buttons to start drag
6710 * @targets: (array length=n_targets): the table of targets that the drag will
6712 * @n_targets: the number of items in @targets
6713 * @actions: the bitmask of possible actions for a drag from this
6716 * Turns @icon_view into a drag source for automatic DND. Calling this
6717 * method sets #GtkIconView:reorderable to %FALSE.
6722 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6723 GdkModifierType start_button_mask,
6724 const GtkTargetEntry *targets,
6726 GdkDragAction actions)
6728 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6730 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6732 icon_view->priv->start_button_mask = start_button_mask;
6733 icon_view->priv->source_actions = actions;
6735 icon_view->priv->source_set = TRUE;
6737 unset_reorderable (icon_view);
6741 * gtk_icon_view_enable_model_drag_dest:
6742 * @icon_view: a #GtkIconView
6743 * @targets: (array length=n_targets): the table of targets that the drag will
6745 * @n_targets: the number of items in @targets
6746 * @actions: the bitmask of possible actions for a drag to this
6749 * Turns @icon_view into a drop destination for automatic DND. Calling this
6750 * method sets #GtkIconView:reorderable to %FALSE.
6755 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6756 const GtkTargetEntry *targets,
6758 GdkDragAction actions)
6760 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6762 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6764 icon_view->priv->dest_actions = actions;
6766 icon_view->priv->dest_set = TRUE;
6768 unset_reorderable (icon_view);
6772 * gtk_icon_view_unset_model_drag_source:
6773 * @icon_view: a #GtkIconView
6775 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6776 * method sets #GtkIconView:reorderable to %FALSE.
6781 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6783 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6785 if (icon_view->priv->source_set)
6787 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6788 icon_view->priv->source_set = FALSE;
6791 unset_reorderable (icon_view);
6795 * gtk_icon_view_unset_model_drag_dest:
6796 * @icon_view: a #GtkIconView
6798 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6799 * method sets #GtkIconView:reorderable to %FALSE.
6804 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6806 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6808 if (icon_view->priv->dest_set)
6810 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6811 icon_view->priv->dest_set = FALSE;
6814 unset_reorderable (icon_view);
6817 /* These are useful to implement your own custom stuff. */
6819 * gtk_icon_view_set_drag_dest_item:
6820 * @icon_view: a #GtkIconView
6821 * @path: (allow-none): The path of the item to highlight, or %NULL.
6822 * @pos: Specifies where to drop, relative to the item
6824 * Sets the item that is highlighted for feedback.
6829 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6831 GtkIconViewDropPosition pos)
6833 /* Note; this function is exported to allow a custom DND
6834 * implementation, so it can't touch TreeViewDragInfo
6837 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6839 if (icon_view->priv->dest_item)
6841 GtkTreePath *current_path;
6842 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6843 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6844 icon_view->priv->dest_item = NULL;
6846 gtk_icon_view_queue_draw_path (icon_view, current_path);
6847 gtk_tree_path_free (current_path);
6850 /* special case a drop on an empty model */
6851 icon_view->priv->empty_view_drop = FALSE;
6852 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6853 && gtk_tree_path_get_depth (path) == 1
6854 && gtk_tree_path_get_indices (path)[0] == 0)
6858 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6861 if (n_children == 0)
6862 icon_view->priv->empty_view_drop = TRUE;
6865 icon_view->priv->dest_pos = pos;
6869 icon_view->priv->dest_item =
6870 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6871 icon_view->priv->model, path);
6873 gtk_icon_view_queue_draw_path (icon_view, path);
6878 * gtk_icon_view_get_drag_dest_item:
6879 * @icon_view: a #GtkIconView
6880 * @path: (out) (allow-none): Return location for the path of
6881 * the highlighted item, or %NULL.
6882 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6884 * Gets information about the item that is highlighted for feedback.
6889 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6891 GtkIconViewDropPosition *pos)
6893 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6897 if (icon_view->priv->dest_item)
6898 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6904 *pos = icon_view->priv->dest_pos;
6908 * gtk_icon_view_get_dest_item_at_pos:
6909 * @icon_view: a #GtkIconView
6910 * @drag_x: the position to determine the destination item for
6911 * @drag_y: the position to determine the destination item for
6912 * @path: (out) (allow-none): Return location for the path of the item,
6914 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6916 * Determines the destination item for a given position.
6918 * Return value: whether there is an item at the given position.
6923 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6927 GtkIconViewDropPosition *pos)
6929 GtkIconViewItem *item;
6931 /* Note; this function is exported to allow a custom DND
6932 * implementation, so it can't touch TreeViewDragInfo
6935 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6936 g_return_val_if_fail (drag_x >= 0, FALSE);
6937 g_return_val_if_fail (drag_y >= 0, FALSE);
6938 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6944 item = _gtk_icon_view_get_item_at_coords (icon_view,
6945 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6946 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6953 *path = gtk_tree_path_new_from_indices (item->index, -1);
6957 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6958 *pos = GTK_ICON_VIEW_DROP_LEFT;
6959 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6960 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6961 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6962 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6963 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6964 *pos = GTK_ICON_VIEW_DROP_BELOW;
6966 *pos = GTK_ICON_VIEW_DROP_INTO;
6973 * gtk_icon_view_create_drag_icon:
6974 * @icon_view: a #GtkIconView
6975 * @path: a #GtkTreePath in @icon_view
6977 * Creates a #cairo_surface_t representation of the item at @path.
6978 * This image is used for a drag icon.
6980 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6985 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6989 GtkStyleContext *context;
6991 cairo_surface_t *surface;
6995 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6996 g_return_val_if_fail (path != NULL, NULL);
6998 widget = GTK_WIDGET (icon_view);
6999 context = gtk_widget_get_style_context (widget);
7001 if (!gtk_widget_get_realized (widget))
7004 index = gtk_tree_path_get_indices (path)[0];
7006 for (l = icon_view->priv->items; l; l = l->next)
7008 GtkIconViewItem *item = l->data;
7010 if (index == item->index)
7012 GdkRectangle rect = {
7013 item->cell_area.x - icon_view->priv->item_padding,
7014 item->cell_area.y - icon_view->priv->item_padding,
7015 item->cell_area.width + icon_view->priv->item_padding * 2,
7016 item->cell_area.height + icon_view->priv->item_padding * 2
7019 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
7020 CAIRO_CONTENT_COLOR,
7024 cr = cairo_create (surface);
7025 cairo_set_line_width (cr, 1.);
7027 gtk_render_background (context, cr, 0, 0,
7028 rect.width + 2, rect.height + 2);
7032 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
7035 gtk_icon_view_paint_item (icon_view, cr, item,
7036 icon_view->priv->item_padding + 1,
7037 icon_view->priv->item_padding + 1, FALSE);
7041 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7042 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
7055 * gtk_icon_view_get_reorderable:
7056 * @icon_view: a #GtkIconView
7058 * Retrieves whether the user can reorder the list via drag-and-drop.
7059 * See gtk_icon_view_set_reorderable().
7061 * Return value: %TRUE if the list can be reordered.
7066 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7068 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7070 return icon_view->priv->reorderable;
7073 static const GtkTargetEntry item_targets[] = {
7074 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7079 * gtk_icon_view_set_reorderable:
7080 * @icon_view: A #GtkIconView.
7081 * @reorderable: %TRUE, if the list of items can be reordered.
7083 * This function is a convenience function to allow you to reorder models that
7084 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7085 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7086 * the user can reorder the model by dragging and dropping rows. The
7087 * developer can listen to these changes by connecting to the model's
7088 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7089 * the icon view as a drag source and destination. Therefore, drag and
7090 * drop can not be used in a reorderable view for any other purpose.
7092 * This function does not give you any degree of control over the order -- any
7093 * reordering is allowed. If more control is needed, you should probably
7094 * handle drag and drop manually.
7099 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7100 gboolean reorderable)
7102 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7104 reorderable = reorderable != FALSE;
7106 if (icon_view->priv->reorderable == reorderable)
7111 gtk_icon_view_enable_model_drag_source (icon_view,
7114 G_N_ELEMENTS (item_targets),
7116 gtk_icon_view_enable_model_drag_dest (icon_view,
7118 G_N_ELEMENTS (item_targets),
7123 gtk_icon_view_unset_model_drag_source (icon_view);
7124 gtk_icon_view_unset_model_drag_dest (icon_view);
7127 icon_view->priv->reorderable = reorderable;
7129 g_object_notify (G_OBJECT (icon_view), "reorderable");
7133 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7134 GtkBuilder *builder,
7136 const gchar *tagname,
7137 GMarkupParser *parser,
7140 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7141 tagname, parser, data))
7144 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7145 tagname, parser, data);
7149 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7150 GtkBuilder *builder,
7152 const gchar *tagname,
7155 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7156 child, tagname, data))
7157 parent_buildable_iface->custom_tag_end (buildable, builder,
7158 child, tagname, data);